/*
 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-runtime-lib
 * Created on: 31 авг. 2019 г.
 *
 * lsp-runtime-lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * lsp-runtime-lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LSP_PLUG_IN_FMT_JAVA_CONST_H_
#define LSP_PLUG_IN_FMT_JAVA_CONST_H_

#include <lsp-plug.in/runtime/version.h>
#include <lsp-plug.in/common/types.h>

namespace lsp
{
    namespace java
    {
        typedef float               float_t;
        typedef double              double_t;
        typedef uint8_t             bool_t;
        typedef lsp_utf16_t         char_t;
        typedef int8_t              byte_t;
        typedef int16_t             short_t;
        typedef int32_t             int_t;
        typedef int64_t             long_t;

        enum stream_token_t
        {
            JST_NULL,               ///< Null object reference.
            JST_REFERENCE,          ///< Reference to an object already written into the stream.
            JST_CLASS_DESC,         ///< new Class Descriptor.
            JST_OBJECT,             ///< Object.
            JST_STRING,             ///< String.
            JST_ARRAY,              ///< Array.
            JST_CLASS,              ///< Reference to Class.
            JST_BLOCK_DATA,         ///< Block of optional data. Byte following tag indicates number of bytes in this block data.
            JST_END_BLOCK_DATA,     ///< End of block of optional data.
            JST_RESET,              ///< Reset stream context. All handles written into stream are reset.
            JST_EXCEPTION,          ///< Exception during write.
            JST_PROXY_CLASS_DESC,   ///< new Proxy Class Descriptor.
            JST_ENUM,               ///< new Enum constant, since java 1.5

            JST_UNDEFINED  = -1
        };

        enum cflags_t
        {
            JCF_PROXY           = 1 << 0,
            JCF_WRITE_METHOD    = 1 << 1,
            JCF_BLOCK_DATA      = 1 << 2,
            JCF_EXTERNALIZABLE  = 1 << 3,
            JCF_SERIALIZABLE    = 1 << 4,
            JCF_ENUM            = 1 << 5
        };

        enum ftype_t
        {
            JFT_BYTE,
            JFT_CHAR,
            JFT_DOUBLE,
            JFT_FLOAT,
            JFT_INTEGER,
            JFT_LONG,
            JFT_SHORT,
            JFT_BOOL,
            JFT_ARRAY,
            JFT_OBJECT,

            JFT_TOTAL,
            JFT_UNKNOWN = -1
        };

        /**
         * Determine size of primitive type
         * @param type of primitive type
         * @return size of primitive type
         */
        size_t      size_of(ftype_t type);

        /**
         * Compute aligned offset of the typed data
         * @param offset the current offset
         * @param type data type
         * @return aligned offset, greater or equal than passed value
         */
        size_t      aligned_offset(size_t offset, ftype_t type);

        /**
         * Check that type is primitive
         * @param type type
         * @return true if type is primitive
         */
        bool        is_primitive(ftype_t type);

        /**
         * Check that type is reference
         * @param type type
         * @return true if type is reference
         */
        bool        is_reference(ftype_t type);
    }
}

#endif /* LSP_PLUG_IN_FMT_JAVA_CONST_H_ */
