2023-04-03 00:55:28 -07:00
|
|
|
/*
|
2023-04-22 19:24:55 -07:00
|
|
|
gencpp: An attempt at simple staged metaprogramming for c/c++.
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
See Readme.md for more information from the project repository.
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
Public Address:
|
|
|
|
https://github.com/Ed94/gencpp
|
2023-04-03 00:55:28 -07:00
|
|
|
*/
|
2023-04-01 19:21:46 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Bloat.hpp"
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
// Temporarily here for debugging purposes.
|
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
2023-04-09 21:38:47 -07:00
|
|
|
// #define GEN_DONT_USE_FATAL
|
2023-06-28 11:43:21 -07:00
|
|
|
// #define GEN_ENFORCE_READONLY_AST
|
2023-04-18 19:47:59 -07:00
|
|
|
|
2023-05-07 12:14:07 -07:00
|
|
|
#define GEN_FEATURE_INCREMENTAL
|
2023-05-07 12:03:24 -07:00
|
|
|
// #define GEN_FEATURE_PARSING
|
|
|
|
// #define GEN_FEATURE_EDITOR
|
|
|
|
// #define GEN_FEATURE_SCANNER
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-10 18:33:06 -07:00
|
|
|
#ifdef gen_time
|
2023-04-01 19:21:46 -07:00
|
|
|
namespace gen
|
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
using LogFailType = sw(*)(char const*, ...);
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-09 21:38:47 -07:00
|
|
|
// By default this library will either crash or exit if an error is detected while generating codes.
|
|
|
|
// Even if set to not use fatal, fatal will still be used for memory failures as the library is unusable when they occur.
|
|
|
|
# ifdef GEN_DONT_USE_FATAL
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr LogFailType log_failure = log_fmt;
|
2023-04-05 23:21:23 -07:00
|
|
|
# else
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr LogFailType log_failure = fatal;
|
2023-04-05 23:21:23 -07:00
|
|
|
# endif
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
namespace ECode
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-05-01 11:12:07 -07:00
|
|
|
# define Define_Types \
|
|
|
|
Entry( Untyped ) \
|
|
|
|
Entry( Comment ) \
|
|
|
|
Entry( Access_Private ) \
|
|
|
|
Entry( Access_Protected ) \
|
|
|
|
Entry( Access_Public ) \
|
|
|
|
Entry( Attributes ) \
|
|
|
|
Entry( Class ) \
|
|
|
|
Entry( Class_Fwd ) \
|
|
|
|
Entry( Class_Body ) \
|
|
|
|
Entry( Enum ) \
|
|
|
|
Entry( Enum_Fwd ) \
|
|
|
|
Entry( Enum_Body ) \
|
|
|
|
Entry( Enum_Class ) \
|
|
|
|
Entry( Enum_Class_Fwd ) \
|
|
|
|
Entry( Execution ) \
|
|
|
|
Entry( Export_Body ) \
|
|
|
|
Entry( Extern_Linkage ) \
|
|
|
|
Entry( Extern_Linkage_Body ) \
|
|
|
|
Entry( Friend ) \
|
|
|
|
Entry( Function ) \
|
|
|
|
Entry( Function_Fwd ) \
|
|
|
|
Entry( Function_Body ) \
|
|
|
|
Entry( Global_Body ) \
|
|
|
|
Entry( Module ) \
|
|
|
|
Entry( Namespace ) \
|
|
|
|
Entry( Namespace_Body ) \
|
|
|
|
Entry( Operator ) \
|
|
|
|
Entry( Operator_Fwd ) \
|
|
|
|
Entry( Operator_Member ) \
|
|
|
|
Entry( Operator_Member_Fwd ) \
|
|
|
|
Entry( Parameters ) \
|
|
|
|
Entry( Preprocessor_Include ) \
|
|
|
|
Entry( Specifiers ) \
|
|
|
|
Entry( Struct ) \
|
|
|
|
Entry( Struct_Fwd ) \
|
|
|
|
Entry( Struct_Body ) \
|
|
|
|
Entry( Typedef ) \
|
|
|
|
Entry( Typename ) \
|
|
|
|
Entry( Union ) \
|
|
|
|
Entry( Union_Body) \
|
|
|
|
Entry( Using ) \
|
2023-05-05 15:10:03 -07:00
|
|
|
Entry( Using_Namespace ) \
|
|
|
|
Entry( Variable )
|
2023-04-07 09:31:50 -07:00
|
|
|
|
|
|
|
enum Type : u32
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
# define Entry( Type ) Type,
|
2023-04-07 09:31:50 -07:00
|
|
|
Define_Types
|
2023-04-22 19:24:55 -07:00
|
|
|
# undef Entry
|
2023-04-07 09:31:50 -07:00
|
|
|
|
|
|
|
Num_Types,
|
|
|
|
Invalid
|
2023-04-01 19:21:46 -07:00
|
|
|
};
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
inline
|
2023-05-06 12:49:43 -07:00
|
|
|
StrC to_str( Type type )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
static
|
2023-05-06 12:49:43 -07:00
|
|
|
StrC lookup[Num_Types] = {
|
|
|
|
# define Entry( Type ) { txt_n_len( Type ) },
|
2023-04-07 09:31:50 -07:00
|
|
|
Define_Types
|
2023-04-22 19:24:55 -07:00
|
|
|
# undef Entry
|
2023-04-03 00:55:28 -07:00
|
|
|
};
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
return lookup[ type ];
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
# undef Define_Types
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
using CodeT = ECode::Type;
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
// Used to indicate if enum definitoin is an enum class or regular enum.
|
|
|
|
enum class EnumT : u8
|
|
|
|
{
|
|
|
|
Regular,
|
|
|
|
Class
|
|
|
|
};
|
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr EnumT EnumClass = EnumT::Class;
|
|
|
|
constexpr EnumT EnumRegular = EnumT::Regular;
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
enum class UsingT : u8
|
|
|
|
{
|
|
|
|
Regular,
|
|
|
|
Namespace
|
|
|
|
};
|
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr UsingT UsingRegular = UsingT::Regular;
|
|
|
|
constexpr UsingT UsingNamespace = UsingT::Namespace;
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
namespace EOperator
|
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
# define Define_Operators \
|
|
|
|
Entry( Assign, = ) \
|
|
|
|
Entry( Assign_Add, += ) \
|
|
|
|
Entry( Assign_Subtract, -= ) \
|
|
|
|
Entry( Assgin_Multiply, *= ) \
|
|
|
|
Entry( Assgin_Divide, /= ) \
|
|
|
|
Entry( Assgin_Modulo, %= ) \
|
|
|
|
Entry( Assgin_BAnd, &= ) \
|
|
|
|
Entry( Assgin_BOr, |= ) \
|
|
|
|
Entry( Assign_BXOr, ^= ) \
|
|
|
|
Entry( Assign_LShift, <<= ) \
|
|
|
|
Entry( Assign_RShift, >>= ) \
|
|
|
|
Entry( Increment, ++ ) \
|
|
|
|
Entry( Decrement, -- ) \
|
|
|
|
Entry( Unary_Plus, + ) \
|
|
|
|
Entry( Unary_Minus, - ) \
|
|
|
|
Entry( Add, + ) \
|
|
|
|
Entry( Subtract, - ) \
|
|
|
|
Entry( Multiply, * ) \
|
|
|
|
Entry( Divide, / ) \
|
|
|
|
Entry( Modulo, % ) \
|
|
|
|
Entry( BNot, ~ ) \
|
|
|
|
Entry( BAnd, & ) \
|
|
|
|
Entry( BOr, | ) \
|
|
|
|
Entry( BXOr, ^ ) \
|
|
|
|
Entry( LShift, << ) \
|
|
|
|
Entry( RShift, >> ) \
|
|
|
|
Entry( LNot, ! ) \
|
|
|
|
Entry( LAnd, && ) \
|
|
|
|
Entry( LOr, || ) \
|
|
|
|
Entry( Equals, == ) \
|
|
|
|
Entry( NotEquals, != ) \
|
|
|
|
Entry( Lesser, < ) \
|
|
|
|
Entry( Greater, > ) \
|
|
|
|
Entry( LesserEqual, <= ) \
|
|
|
|
Entry( GreaterEqual, >= ) \
|
|
|
|
Entry( Subscript, [] ) \
|
|
|
|
Entry( Indirection, * ) \
|
|
|
|
Entry( AddressOf, & ) \
|
|
|
|
Entry( MemberOfPointer, -> ) \
|
|
|
|
Entry( PtrToMemOfPtr, ->* ) \
|
|
|
|
Entry( FunctionCall, () )
|
2023-04-07 09:31:50 -07:00
|
|
|
|
|
|
|
enum Type : u32
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
# define Entry( Type_, Token_ ) Type_,
|
2023-04-07 09:31:50 -07:00
|
|
|
Define_Operators
|
2023-04-22 19:24:55 -07:00
|
|
|
# undef Entry
|
2023-04-07 09:31:50 -07:00
|
|
|
Comma,
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
Num_Ops,
|
|
|
|
Invalid
|
2023-04-03 23:04:19 -07:00
|
|
|
};
|
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
char const* to_str( Type op )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
local_persist
|
2023-04-03 23:04:19 -07:00
|
|
|
char const* lookup[ Num_Ops ] = {
|
2023-04-22 19:24:55 -07:00
|
|
|
# define Entry( Type_, Token_ ) txt(Token_),
|
2023-04-07 09:31:50 -07:00
|
|
|
Define_Operators
|
2023-04-22 19:24:55 -07:00
|
|
|
# undef Entry
|
2023-04-07 09:31:50 -07:00
|
|
|
","
|
2023-04-03 23:04:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[ op ];
|
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
# undef Define_Operators
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
using OperatorT = EOperator::Type;
|
|
|
|
|
|
|
|
namespace ESpecifier
|
|
|
|
{
|
2023-05-01 11:12:07 -07:00
|
|
|
/*
|
|
|
|
Note: The following are handled separately:
|
|
|
|
attributes
|
|
|
|
alignas
|
|
|
|
*/
|
2023-04-22 19:24:55 -07:00
|
|
|
|
|
|
|
#define Define_Specifiers \
|
2023-04-18 19:47:59 -07:00
|
|
|
Entry( Const, const ) \
|
2023-04-07 21:29:09 -07:00
|
|
|
Entry( Consteval, consteval ) \
|
|
|
|
Entry( Constexpr, constexpr ) \
|
|
|
|
Entry( Constinit, constinit ) \
|
|
|
|
Entry( External_Linkage, extern ) \
|
|
|
|
Entry( Inline, inline ) \
|
|
|
|
Entry( Internal_Linkage, static ) \
|
|
|
|
Entry( Local_Persist, static ) \
|
|
|
|
Entry( Mutable, mutable ) \
|
2023-04-10 18:33:06 -07:00
|
|
|
Entry( Ptr, * ) \
|
|
|
|
Entry( Ref, & ) \
|
2023-04-07 21:29:09 -07:00
|
|
|
Entry( Register, register ) \
|
|
|
|
Entry( RValue, && ) \
|
|
|
|
Entry( Static_Member, static ) \
|
2023-04-18 19:47:59 -07:00
|
|
|
Entry( Thread_Local, thread_local ) \
|
2023-04-18 21:56:43 -07:00
|
|
|
Entry( Volatile, volatile ) \
|
|
|
|
Entry( Type_Signed, signed ) \
|
|
|
|
Entry( Type_Unsigned, unsigned ) \
|
|
|
|
Entry( Type_Short, short ) \
|
|
|
|
Entry( Type_Long, long )
|
2023-04-07 09:31:50 -07:00
|
|
|
|
|
|
|
enum Type : u32
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-05-08 17:54:24 -07:00
|
|
|
Invalid,
|
2023-04-22 19:24:55 -07:00
|
|
|
# define Entry( Specifier, Code ) Specifier,
|
2023-04-07 09:31:50 -07:00
|
|
|
Define_Specifiers
|
2023-04-22 19:24:55 -07:00
|
|
|
# undef Entry
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Num_Specifiers,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Specifier to string
|
|
|
|
inline
|
2023-05-06 12:49:43 -07:00
|
|
|
StrC to_str( Type specifier )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
local_persist
|
2023-05-06 12:49:43 -07:00
|
|
|
StrC lookup[ Num_Specifiers ] = {
|
|
|
|
# define Entry( Spec_, Code_ ) { txt_n_len(Code_) },
|
2023-04-07 09:31:50 -07:00
|
|
|
Define_Specifiers
|
2023-04-22 19:24:55 -07:00
|
|
|
# undef Entry
|
2023-04-03 23:04:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[ specifier ];
|
|
|
|
}
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-11 19:18:02 -07:00
|
|
|
inline
|
2023-05-06 12:49:43 -07:00
|
|
|
Type to_type( StrC str )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
local_persist
|
2023-04-03 23:04:19 -07:00
|
|
|
u32 keymap[ Num_Specifiers ];
|
|
|
|
do_once_start
|
|
|
|
for ( u32 index = 0; index < Num_Specifiers; index++ )
|
|
|
|
{
|
2023-05-06 12:49:43 -07:00
|
|
|
StrC enum_str = to_str( (Type)index );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
keymap[index] = crc32( enum_str.Ptr, enum_str.Len);
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
do_once_end
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
u32 hash = crc32( str.Ptr, str.Len );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
for ( u32 index = 0; index < Num_Specifiers; index++ )
|
|
|
|
{
|
|
|
|
if ( keymap[index] == hash )
|
|
|
|
return (Type)index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Invalid;
|
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
#undef Define_Specifiers
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
using SpecifierT = ESpecifier::Type;
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
enum class AccessSpec : u32
|
|
|
|
{
|
2023-05-05 21:18:44 -07:00
|
|
|
Default,
|
2023-05-01 11:12:07 -07:00
|
|
|
Public,
|
|
|
|
Protected,
|
|
|
|
Private,
|
|
|
|
|
|
|
|
Num_AccessSpec,
|
|
|
|
Invalid,
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
char const* to_str( AccessSpec type )
|
|
|
|
{
|
|
|
|
local_persist
|
|
|
|
char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = {
|
2023-05-05 21:18:44 -07:00
|
|
|
"",
|
2023-05-01 11:12:07 -07:00
|
|
|
"private",
|
|
|
|
"protected",
|
|
|
|
"public",
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( type > AccessSpec::Public )
|
2023-05-07 12:03:24 -07:00
|
|
|
return "Invalid";
|
2023-05-01 11:12:07 -07:00
|
|
|
|
|
|
|
return lookup[ (u32)type ];
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class ModuleFlag : u32
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
Export = bit(0),
|
|
|
|
Import = bit(1),
|
2023-06-28 21:20:23 -07:00
|
|
|
// Private = bit(2),
|
2023-05-01 11:12:07 -07:00
|
|
|
|
|
|
|
Num_ModuleFlags,
|
|
|
|
Invalid,
|
|
|
|
};
|
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
|
|
|
|
{
|
|
|
|
return (ModuleFlag)( (u32)A | (u32)B );
|
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
/*
|
|
|
|
Predefined attributes
|
|
|
|
|
|
|
|
Used for the parser constructors to identify non-standard attributes
|
|
|
|
*/
|
|
|
|
namespace Attribute
|
|
|
|
{
|
2023-05-05 15:10:03 -07:00
|
|
|
#if defined(ZPL_SYSTEM_WINDOWS) || defined( __CYGWIN__ )
|
2023-05-01 11:12:07 -07:00
|
|
|
# define GEN_API_
|
|
|
|
# define GEN_API_Export_Code __declspec(dllexport)
|
|
|
|
# define GEN_API_Import_Code __declspec(dllimport)
|
|
|
|
# define GEN_Attribute_Keyword __declspec
|
|
|
|
|
2023-05-05 15:10:03 -07:00
|
|
|
constexpr char const* API_Export = txt( GEN_API_Export_Code );
|
|
|
|
constexpr char const* API_Import = txt( GEN_API_Import_Code );
|
|
|
|
constexpr char const* Keyword = txt( GEN_Attribute_Keyword);
|
2023-05-01 11:12:07 -07:00
|
|
|
|
|
|
|
#elif ZPL_HAS_ATTRIBUTE( visibility ) || ZPL_GCC_VERSION_CHECK( 3, 3, 0 ) || ZPL_INTEL_VERSION_CHECK( 13, 0, 0 )
|
|
|
|
# define GEN_API_Export_Code __attribute__ ((visibility ("default")))
|
|
|
|
# define GEN_API_Import_Code __attribute__ ((visibility ("default")))
|
|
|
|
# define GEN_Attribute_Keyword __attribute__
|
|
|
|
|
|
|
|
constexpr char const* API_Export = txt( GEN_API_Export_Code );
|
|
|
|
constexpr char const* API_Import = txt( GEN_API_Import_Code );
|
2023-05-05 15:10:03 -07:00
|
|
|
constexpr char const* Keyword = txt( GEN_Attribute_Keyword);
|
2023-05-01 11:12:07 -07:00
|
|
|
|
|
|
|
#else
|
|
|
|
# define GEN_API_Export_Code
|
|
|
|
# define GEN_API_Import_Code
|
|
|
|
# define GEN_Attribute_Keyword
|
|
|
|
|
2023-05-05 15:10:03 -07:00
|
|
|
constexpr char const* API_Export = "";
|
|
|
|
constexpr char const* API_Import = "";
|
|
|
|
constexpr char const* Keyword = "";
|
2023-05-01 11:12:07 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma region Data Structures
|
2023-04-10 18:33:06 -07:00
|
|
|
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
|
|
|
ZPL_TABLE_DECLARE( ZPL_EXTERN, StringTable, str_tbl_, String );
|
|
|
|
|
|
|
|
// Represents strings cached with the string table.
|
|
|
|
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
2023-05-06 12:49:43 -07:00
|
|
|
using StringCached = String const;
|
2023-04-10 18:33:06 -07:00
|
|
|
|
|
|
|
// Desired width of the AST data structure.
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr u32 AST_POD_Size = 256;
|
2023-04-10 18:33:06 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
// TODO: If perf needs it, convert layout an SOA format.
|
2023-04-05 23:21:23 -07:00
|
|
|
/*
|
2023-04-03 00:55:28 -07:00
|
|
|
Simple AST POD with functionality to seralize into C++ syntax.
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
ASTs are currently stored as an AOS. They are always reconstructed on demand.
|
|
|
|
Thus redundant AST can easily occur.
|
|
|
|
Not sure if its better to store them in a hashmap.
|
2023-04-10 18:33:06 -07:00
|
|
|
|
|
|
|
Any type specific functions assume the construction of the AST was done correctly.
|
2023-04-03 00:55:28 -07:00
|
|
|
*/
|
|
|
|
struct AST
|
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma region Member Functions
|
2023-04-10 18:33:06 -07:00
|
|
|
void add_entry( AST* other );
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
AST* body()
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-06-28 18:20:29 -07:00
|
|
|
return entry( 0 );
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-10 18:33:06 -07:00
|
|
|
AST* duplicate();
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-06-28 18:20:29 -07:00
|
|
|
AST*& entry( u32 idx )
|
|
|
|
{
|
|
|
|
return DynamicEntries ? ArrDyn[ idx ] : ArrStatic[ idx ];
|
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
bool has_entries()
|
|
|
|
{
|
2023-06-29 19:48:47 -07:00
|
|
|
return num_entries();
|
2023-04-07 09:31:50 -07:00
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
bool is_invalid()
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-10 18:33:06 -07:00
|
|
|
return Type != ECode::Invalid;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
|
|
|
|
2023-06-29 19:48:47 -07:00
|
|
|
inline
|
|
|
|
bool is_equal( AST* other );
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
s32 num_entries()
|
|
|
|
{
|
2023-06-28 18:20:29 -07:00
|
|
|
return DynamicEntries ? array_count( ArrDyn ) : StaticIndex;
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-04-10 18:33:06 -07:00
|
|
|
// Parameter
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
bool add_param( AST* type, StrC name );
|
2023-04-11 19:18:02 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
AST* get_param( s32 index )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-10 18:33:06 -07:00
|
|
|
if ( index <= 0 )
|
|
|
|
return this;
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-06-28 18:20:29 -07:00
|
|
|
return entry( index + 1 );
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
s32 param_count()
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-10 18:33:06 -07:00
|
|
|
// The first entry (which holds the type) represents the first parameter.
|
|
|
|
return num_entries();
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
AST* param_type()
|
|
|
|
{
|
2023-06-28 18:20:29 -07:00
|
|
|
return entry( 0 );
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
|
|
|
|
2023-04-11 19:18:02 -07:00
|
|
|
// Specifiers
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool add_specifier( SpecifierT spec )
|
|
|
|
{
|
|
|
|
if ( StaticIndex == AST::ArrSpecs_Cap )
|
|
|
|
{
|
|
|
|
log_failure("AST::add_specifier: Attempted to add over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrSpecs[ StaticIndex ] = spec;
|
|
|
|
StaticIndex++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2023-05-01 11:12:07 -07:00
|
|
|
s32 has_specifier( SpecifierT spec )
|
2023-04-11 19:18:02 -07:00
|
|
|
{
|
2023-05-01 11:12:07 -07:00
|
|
|
for ( s32 idx = 0; idx < StaticIndex; idx++ )
|
2023-04-11 19:18:02 -07:00
|
|
|
{
|
|
|
|
if ( ArrSpecs[StaticIndex] == spec )
|
2023-05-01 11:12:07 -07:00
|
|
|
return idx;
|
2023-04-11 19:18:02 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
return -1;
|
2023-04-11 19:18:02 -07:00
|
|
|
}
|
|
|
|
|
2023-04-10 18:33:06 -07:00
|
|
|
// Typename
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
bool typename_is_ptr()
|
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
assert_crash("not implemented");
|
2023-05-07 12:03:24 -07:00
|
|
|
return false;
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
bool typename_is_ref()
|
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
assert_crash("not implemented");
|
2023-05-07 12:03:24 -07:00
|
|
|
return false;
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
AST* typename_specifiers()
|
|
|
|
{
|
2023-06-28 18:20:29 -07:00
|
|
|
return entry( 0 );
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Serialization
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
char const* debug_str()
|
2023-04-07 09:31:50 -07:00
|
|
|
{
|
|
|
|
char const* fmt = txt(
|
|
|
|
\nCode Debug:
|
|
|
|
\nType : %s
|
|
|
|
\nReadonly: %s
|
|
|
|
\nParent : %s
|
|
|
|
\nName : %s
|
|
|
|
\nComment : %s
|
|
|
|
);
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
// These should be used immediately in a log.
|
|
|
|
// Thus if its desired to keep the debug str
|
|
|
|
// for multiple calls to bprintf,
|
|
|
|
// allocate this to proper string.
|
2023-04-19 12:40:23 -07:00
|
|
|
return str_fmt_buf( fmt
|
2023-04-07 09:31:50 -07:00
|
|
|
, type_str()
|
|
|
|
, Readonly ? "true" : "false"
|
|
|
|
, Parent ? Parent->Name : ""
|
|
|
|
, Name ? Name : ""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
char const* type_str()
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-10 18:33:06 -07:00
|
|
|
return ECode::to_str( Type );
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-22 21:43:31 -07:00
|
|
|
String to_string();
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma endregion Member Functions
|
|
|
|
|
2023-04-11 19:18:02 -07:00
|
|
|
constexpr static
|
|
|
|
uw ArrS_Cap =
|
2023-04-10 18:33:06 -07:00
|
|
|
( AST_POD_Size
|
2023-05-01 11:12:07 -07:00
|
|
|
- sizeof(AST*) // Parent
|
|
|
|
- sizeof(StringCached) // Name
|
|
|
|
- sizeof(CodeT) // Type
|
|
|
|
- sizeof(OperatorT) // Op
|
|
|
|
- sizeof(ModuleFlag) // ModuleFlags
|
2023-05-05 21:18:44 -07:00
|
|
|
- sizeof(AccessSpec) // ParentAccess
|
2023-05-01 11:12:07 -07:00
|
|
|
- sizeof(u32) // StaticIndex
|
|
|
|
- sizeof(bool) * 2 // Readonly, DynamicEntries
|
2023-05-05 21:18:44 -07:00
|
|
|
- sizeof(u8) * 2 ) // _Align_Pad
|
2023-04-10 18:33:06 -07:00
|
|
|
/ sizeof(AST*);
|
|
|
|
|
2023-04-11 19:18:02 -07:00
|
|
|
constexpr static
|
|
|
|
uw ArrSpecs_Cap = ArrS_Cap * (sizeof(AST*) / sizeof(SpecifierT));
|
|
|
|
|
2023-05-07 12:46:28 -07:00
|
|
|
# define Using_AST_POD \
|
2023-04-11 19:18:02 -07:00
|
|
|
union { \
|
|
|
|
AST* ArrStatic[AST::ArrS_Cap]; \
|
2023-06-28 18:20:29 -07:00
|
|
|
Array(AST*) ArrDyn; \
|
2023-04-11 19:18:02 -07:00
|
|
|
StringCached Content; \
|
|
|
|
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; \
|
|
|
|
}; \
|
|
|
|
AST* Parent; \
|
|
|
|
StringCached Name; \
|
|
|
|
CodeT Type; \
|
|
|
|
OperatorT Op; \
|
2023-05-01 11:12:07 -07:00
|
|
|
ModuleFlag ModuleFlags; \
|
2023-05-05 21:18:44 -07:00
|
|
|
AccessSpec ParentAccess; \
|
2023-05-01 11:12:07 -07:00
|
|
|
u32 StaticIndex; \
|
2023-04-11 19:18:02 -07:00
|
|
|
bool Readonly; \
|
|
|
|
bool DynamicEntries; \
|
2023-05-05 21:18:44 -07:00
|
|
|
u8 _Align_Pad[2];
|
2023-04-10 18:33:06 -07:00
|
|
|
|
2023-05-07 12:46:28 -07:00
|
|
|
Using_AST_POD
|
2023-04-03 00:55:28 -07:00
|
|
|
};
|
|
|
|
|
2023-05-07 12:46:28 -07:00
|
|
|
struct AST_POD
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-05-07 12:46:28 -07:00
|
|
|
Using_AST_POD
|
2023-05-07 12:03:24 -07:00
|
|
|
# undef Using_CodePOD
|
2023-04-03 00:55:28 -07:00
|
|
|
};
|
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr sw size_AST = sizeof(AST);
|
2023-05-07 12:46:28 -07:00
|
|
|
constexpr sw size_POD = sizeof(AST_POD);
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
// Its intended for the AST to have equivalent size to its POD.
|
|
|
|
// All extra functionality within the AST namespace should just be syntatic sugar.
|
2023-05-07 12:46:28 -07:00
|
|
|
static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" );
|
|
|
|
static_assert( sizeof(AST_POD) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
AST* typedef as to not constantly have to add the '*' as this is written often..
|
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
If GEN_ENFORCE_READONLY_AST is defined, readonly assertions will be done on any member dreference,
|
2023-04-03 00:55:28 -07:00
|
|
|
and the 'gen API' related functions. will set their created ASTs to readonly before returning.
|
|
|
|
|
|
|
|
Casting to AST* will bypass.
|
|
|
|
*/
|
|
|
|
struct Code
|
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma region Statics
|
2023-05-01 11:12:07 -07:00
|
|
|
// Used to identify invalid generated code.
|
2023-04-10 18:33:06 -07:00
|
|
|
static Code Invalid;
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma endregion Statics
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma region Member Functions
|
|
|
|
inline
|
2023-04-03 23:04:19 -07:00
|
|
|
Code body()
|
|
|
|
{
|
2023-04-06 16:19:11 -07:00
|
|
|
if ( ast == nullptr )
|
|
|
|
{
|
|
|
|
log_failure("Code::body: AST is null!");
|
|
|
|
return Invalid;
|
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( ast->Type == ECode::Invalid )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
|
|
|
log_failure("Code::body: Type is invalid, cannot get");
|
2023-04-05 23:21:23 -07:00
|
|
|
return Invalid;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-06-28 18:20:29 -07:00
|
|
|
#ifdef GEN_ENFORCE_READONLY_AST
|
2023-04-05 00:03:56 -07:00
|
|
|
if ( ast->Readonly )
|
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
log_failure("Attempted to a body AST from a readonly AST!");
|
|
|
|
return Invalid;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
2023-06-28 18:20:29 -07:00
|
|
|
#endif
|
2023-04-05 00:03:56 -07:00
|
|
|
|
|
|
|
return * (Code*)( ast->body() );
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-03 23:04:19 -07:00
|
|
|
void lock()
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
ast->Readonly = true;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-06-29 19:48:47 -07:00
|
|
|
String to_string() const
|
2023-04-10 18:33:06 -07:00
|
|
|
{
|
|
|
|
return ast->to_string();
|
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-06-29 19:48:47 -07:00
|
|
|
operator bool() const
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-09 21:38:47 -07:00
|
|
|
return ast;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
bool operator ==( Code other )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
return ast == other.ast;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
bool operator !=( Code other )
|
|
|
|
{
|
|
|
|
return ast != other.ast;
|
|
|
|
}
|
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-03 00:55:28 -07:00
|
|
|
operator AST*()
|
|
|
|
{
|
|
|
|
return ast;
|
|
|
|
}
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
Code& operator=( Code other )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
#ifdef GEN_ENFORCE_READONLY_AST
|
2023-05-08 17:54:24 -07:00
|
|
|
if ( ast && ast->Readonly )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
log_failure("Attempted to set a readonly AST!");
|
2023-04-05 00:03:56 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
ast = other.ast;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
inline
|
2023-04-10 18:33:06 -07:00
|
|
|
AST* operator->()
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
|
|
|
if ( ast == nullptr )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
|
|
|
log_failure("Attempt to dereference a nullptr!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-06-28 18:20:29 -07:00
|
|
|
#ifdef GEN_ENFORCE_READONLY_AST
|
2023-04-03 00:55:28 -07:00
|
|
|
if ( ast->Readonly )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
log_failure("Attempted to access a member from a readonly AST!");
|
2023-04-05 00:03:56 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2023-06-28 18:20:29 -07:00
|
|
|
#endif
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
return ast;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma endregion Member Functions
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
AST* ast;
|
2023-04-01 19:21:46 -07:00
|
|
|
};
|
2023-05-07 12:46:28 -07:00
|
|
|
|
|
|
|
struct Code_POD
|
|
|
|
{
|
|
|
|
AST_POD* ast;
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
// Used when the its desired when omission is allowed in a definition.
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr Code NoCode = { nullptr };
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma endregion Data Structures
|
2023-04-02 09:35:14 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma region Gen Interface
|
2023-04-09 21:38:47 -07:00
|
|
|
// Initialize the library.
|
|
|
|
// This currently just initializes the CodePool.
|
2023-04-02 09:35:14 -07:00
|
|
|
void init();
|
|
|
|
|
2023-05-08 17:54:24 -07:00
|
|
|
void deinit();
|
|
|
|
|
2023-04-10 18:33:06 -07:00
|
|
|
/*
|
|
|
|
Use this only if you know you generated the code you needed to a file.
|
|
|
|
And rather get rid of current code asts instead of growing the pool memory.
|
|
|
|
This generally can be done everytime a file is generated
|
|
|
|
TODO: In order for this to work, the type map needs its own arenas so do specifiers.
|
|
|
|
*/
|
|
|
|
void clear_code_memory();
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-09 21:38:47 -07:00
|
|
|
// Used internally to retrive or make string allocations.
|
|
|
|
// Strings are stored in a series of string arenas of fixed size (SizePer_StringArena)
|
2023-05-06 12:49:43 -07:00
|
|
|
StringCached get_cached_string( StrC str );
|
2023-04-07 09:31:50 -07:00
|
|
|
|
|
|
|
/*
|
2023-04-07 21:29:09 -07:00
|
|
|
This provides a fresh Code AST.
|
2023-04-07 09:31:50 -07:00
|
|
|
The gen interface use this as their method from getting a new AST object from the CodePool.
|
|
|
|
Use this if you want to make your own API for formatting the supported Code Types.
|
|
|
|
*/
|
|
|
|
Code make_code();
|
|
|
|
|
2023-04-09 21:38:47 -07:00
|
|
|
// This provides a fresh Code AST array for the entries field of the AST.
|
|
|
|
// This is done separately from the regular CodePool allocator.
|
2023-04-09 10:59:39 -07:00
|
|
|
Array(AST*) make_code_entries();
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
// Set these before calling gen's init() procedure.
|
2023-04-09 21:38:47 -07:00
|
|
|
// Data
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-04-09 21:38:47 -07:00
|
|
|
void set_allocator_data_arrays ( AllocatorInfo data_array_allocator );
|
|
|
|
void set_allocator_code_pool ( AllocatorInfo pool_allocator );
|
|
|
|
void set_allocator_code_enries_arena( AllocatorInfo pool_allocator );
|
|
|
|
void set_allocator_string_arena ( AllocatorInfo string_allocator );
|
|
|
|
void set_allocator_string_table ( AllocatorInfo string_allocator );
|
|
|
|
void set_allocator_type_table ( AllocatorInfo type_reg_allocator );
|
2023-04-05 00:03:56 -07:00
|
|
|
|
|
|
|
# pragma region Upfront
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_attributes( StrC content );
|
2023-06-28 22:37:42 -07:00
|
|
|
Code def_comment ( StrC content );
|
2023-05-01 11:12:07 -07:00
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_class( StrC name
|
2023-05-01 11:12:07 -07:00
|
|
|
, Code body = NoCode
|
2023-05-07 12:14:07 -07:00
|
|
|
, Code parent = NoCode, AccessSpec access = AccessSpec::Default
|
2023-05-05 21:18:44 -07:00
|
|
|
, Code attributes = NoCode
|
2023-05-01 11:12:07 -07:00
|
|
|
, ModuleFlag mflags = ModuleFlag::None );
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_enum( StrC
|
2023-05-01 11:12:07 -07:00
|
|
|
, Code body = NoCode, Code type = NoCode
|
|
|
|
, EnumT specifier = EnumRegular, Code attributes = NoCode
|
|
|
|
, ModuleFlag mflags = ModuleFlag::None );
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_execution ( StrC content );
|
|
|
|
Code def_extern_link( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
|
2023-05-01 11:12:07 -07:00
|
|
|
Code def_friend ( Code symbol );
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_function( StrC name
|
2023-05-01 11:12:07 -07:00
|
|
|
, Code params = NoCode, Code ret_type = NoCode, Code body = NoCode
|
|
|
|
, Code specifiers = NoCode, Code attributes = NoCode
|
|
|
|
, ModuleFlag mflags = ModuleFlag::None );
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_include ( StrC content );
|
|
|
|
Code def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None );
|
|
|
|
Code def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
|
2023-05-01 11:12:07 -07:00
|
|
|
|
|
|
|
Code def_operator( OperatorT op
|
|
|
|
, Code params = NoCode, Code ret_type = NoCode, Code body = NoCode
|
|
|
|
, Code specifiers = NoCode, Code attributes = NoCode
|
|
|
|
, ModuleFlag mflags = ModuleFlag::None );
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_param ( Code type, StrC name, Code value = NoCode );
|
2023-05-01 11:12:07 -07:00
|
|
|
Code def_specifier( SpecifierT specifier );
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_struct( StrC name
|
2023-05-05 21:18:44 -07:00
|
|
|
, Code body
|
2023-05-07 12:14:07 -07:00
|
|
|
, Code parent = NoCode, AccessSpec access = AccessSpec::Default
|
2023-05-05 21:18:44 -07:00
|
|
|
, Code attributes = NoCode
|
|
|
|
, ModuleFlag mflags = ModuleFlag::None );
|
2023-05-01 11:12:07 -07:00
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_type ( StrC name, Code arrayexpr = NoCode, Code specifiers = NoCode );
|
2023-06-28 22:37:42 -07:00
|
|
|
Code def_typedef( StrC name, Code type, Code attributes = NoCode, ModuleFlag mflags = ModuleFlag::None );
|
2023-05-01 11:12:07 -07:00
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
Code def_union( StrC name, Code body, Code attributes = NoCode, ModuleFlag mflags = ModuleFlag::None );
|
2023-05-01 11:12:07 -07:00
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
Code def_using( StrC name, Code type = NoCode
|
2023-05-01 11:12:07 -07:00
|
|
|
, Code attributess = NoCode
|
|
|
|
, ModuleFlag mflags = ModuleFlag::None );
|
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
Code def_using_namespace( StrC name );
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code def_variable( Code type, StrC name, Code value = NoCode
|
2023-05-01 11:12:07 -07:00
|
|
|
, Code specifiers = NoCode, Code attributes = NoCode
|
|
|
|
, ModuleFlag mflags = ModuleFlag::None );
|
|
|
|
|
|
|
|
Code def_class_body ( s32 num, ... );
|
2023-05-07 12:03:24 -07:00
|
|
|
Code def_class_body ( s32 num, Code* codes );
|
2023-05-01 11:12:07 -07:00
|
|
|
Code def_enum_body ( s32 num, ... );
|
|
|
|
Code def_enum_body ( s32 num, Code* codes );
|
|
|
|
Code def_export_body ( s32 num, ... );
|
|
|
|
Code def_export_body ( s32 num, Code* codes);
|
2023-05-05 15:10:03 -07:00
|
|
|
Code def_extern_link_body( s32 num, ... );
|
|
|
|
Code def_extern_link_body( s32 num, Code* codes );
|
2023-05-01 11:12:07 -07:00
|
|
|
Code def_function_body ( s32 num, ... );
|
|
|
|
Code def_function_body ( s32 num, Code* codes );
|
2023-06-28 22:37:42 -07:00
|
|
|
Code def_global_body ( s32 num, ... );
|
|
|
|
Code def_global_body ( s32 num, Code* codes );
|
2023-05-01 11:12:07 -07:00
|
|
|
Code def_namespace_body ( s32 num, ... );
|
|
|
|
Code def_namespace_body ( s32 num, Code* codes );
|
|
|
|
Code def_params ( s32 num, ... );
|
|
|
|
Code def_params ( s32 num, Code* params );
|
|
|
|
Code def_specifiers ( s32 num , ... );
|
|
|
|
Code def_specifiers ( s32 num, SpecifierT* specs );
|
|
|
|
Code def_struct_body ( s32 num, ... );
|
|
|
|
Code def_struct_body ( s32 num, Code* codes );
|
|
|
|
Code def_union_body ( s32 num, ... );
|
|
|
|
Code def_union_body ( s32 num, Code* codes );
|
2023-04-05 00:03:56 -07:00
|
|
|
# pragma endregion Upfront
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma region Parsing
|
|
|
|
#ifdef GEN_FEATURE_PARSING
|
2023-05-06 12:49:43 -07:00
|
|
|
Code parse_class ( StrC class_def );
|
|
|
|
Code parse_enum ( StrC enum_def );
|
|
|
|
Code parse_export_body( StrC export_def );
|
|
|
|
Code parse_exten_link ( StrC exten_link_def);
|
|
|
|
Code parse_friend ( StrC friend_def );
|
|
|
|
Code parse_function ( StrC fn_def );
|
|
|
|
Code parse_global_body( StrC body_def );
|
|
|
|
Code parse_namespace ( StrC namespace_def );
|
|
|
|
Code parse_operator ( StrC operator_def );
|
|
|
|
Code parse_struct ( StrC struct_def );
|
|
|
|
Code parse_type ( StrC type_def );
|
|
|
|
Code parse_typedef ( StrC typedef_def );
|
|
|
|
Code parse_union ( StrC union_def );
|
|
|
|
Code parse_using ( StrC using_def );
|
|
|
|
Code parse_variable ( StrC var_def );
|
2023-04-22 19:24:55 -07:00
|
|
|
#endif
|
|
|
|
#pragma endregion Parsing
|
|
|
|
|
|
|
|
#pragma region Untyped text
|
|
|
|
sw token_fmt_va( char* buf, uw buf_size, char const* fmt, s32 num_tokens, va_list va );
|
|
|
|
|
|
|
|
inline
|
|
|
|
char const* token_fmt( char const* fmt, sw num_tokens, ... )
|
|
|
|
{
|
|
|
|
local_persist thread_local
|
|
|
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
|
|
|
token_fmt_va(buf, ZPL_PRINTF_MAXLEN, fmt, num_tokens, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
Code untyped_str ( StrC content);
|
|
|
|
Code untyped_fmt ( char const* fmt, ... );
|
|
|
|
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
2023-04-22 19:24:55 -07:00
|
|
|
#pragma endregion Untyped text
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
struct Builder
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
FileInfo File;
|
|
|
|
String Buffer;
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
void print( Code );
|
2023-06-28 11:43:21 -07:00
|
|
|
void print_fmt( char const* fmt, ... );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
bool open( char const* path );
|
2023-04-01 19:21:46 -07:00
|
|
|
void write();
|
|
|
|
};
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
#if defined(GEN_FEATURE_EDITOR) || defined(GEN_FEATURE_SCANNER)
|
|
|
|
struct SymbolInfo
|
|
|
|
{
|
|
|
|
StringCached File;
|
|
|
|
char const* Marker;
|
|
|
|
Code Signature;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
#ifdef GEN_FEATURE_EDITOR
|
|
|
|
struct Policy
|
|
|
|
{
|
2023-04-07 21:29:09 -07:00
|
|
|
// Nothing for now.
|
|
|
|
};
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
enum class SymbolType : u32
|
|
|
|
{
|
|
|
|
Code,
|
|
|
|
Line,
|
|
|
|
Marker
|
2023-04-06 16:19:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Editor
|
|
|
|
{
|
|
|
|
enum RequestType : u32
|
|
|
|
{
|
|
|
|
Add,
|
|
|
|
Replace,
|
|
|
|
Remove
|
|
|
|
};
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
struct SymbolData
|
2023-04-06 16:19:11 -07:00
|
|
|
{
|
|
|
|
Policy Policy;
|
2023-04-07 09:31:50 -07:00
|
|
|
SymbolInfo Info;
|
2023-04-06 16:19:11 -07:00
|
|
|
};
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
struct RequestEntry
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
SymbolData Symbol;
|
2023-04-09 10:59:39 -07:00
|
|
|
String Specification;
|
2023-04-07 09:31:50 -07:00
|
|
|
};
|
|
|
|
RequestType Type;
|
|
|
|
};
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
struct Receipt
|
|
|
|
{
|
2023-04-09 21:38:47 -07:00
|
|
|
StringCached File;
|
2023-04-07 21:29:09 -07:00
|
|
|
Code Found;
|
|
|
|
Code Written;
|
|
|
|
bool Result;
|
2023-04-07 09:31:50 -07:00
|
|
|
};
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
static AllocatorInfo Allocator;
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
static void set_allocator( AllocatorInfo allocator );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Array(FileInfo) Files;
|
|
|
|
String Buffer;
|
|
|
|
Array(RequestEntry) Requests;
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
void add_files( s32 num, char const** files );
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
void add ( SymbolInfo definition, Policy policy, Code to_inject );
|
2023-04-07 21:29:09 -07:00
|
|
|
void remove ( SymbolInfo definition, Policy policy );
|
2023-04-07 09:31:50 -07:00
|
|
|
void replace( SymbolInfo definition, Policy policy, Code to_replace);
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
# ifdef GEN_FEATURE_EDITOR_REFACTOR
|
|
|
|
void refactor( char const* file_path, char const* specification_path );
|
2023-04-06 16:19:11 -07:00
|
|
|
# endif
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
bool process_requests( Array(Receipt) out_receipts );
|
2023-04-07 09:31:50 -07:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
# ifdef GEN_FEATURE_SCANNER
|
2023-04-07 09:31:50 -07:00
|
|
|
struct Scanner
|
|
|
|
{
|
|
|
|
struct RequestEntry
|
|
|
|
{
|
|
|
|
SymbolInfo Info;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Receipt
|
|
|
|
{
|
2023-04-09 21:38:47 -07:00
|
|
|
StringCached File;
|
2023-04-07 21:29:09 -07:00
|
|
|
Code Defintion;
|
|
|
|
bool Result;
|
2023-04-07 09:31:50 -07:00
|
|
|
};
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
AllocatorInfo MemAlloc;
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
static void set_allocator( AllocatorInfo allocator );
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Array(FileInfo) Files;
|
|
|
|
String Buffer;
|
|
|
|
Array(RequestEntry) Requests;
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
void add_files( s32 num, char const** files );
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
void add( SymbolInfo signature, Policy policy );
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
bool process_requests( Array(Receipt) out_receipts );
|
2023-04-06 16:19:11 -07:00
|
|
|
};
|
2023-04-22 19:24:55 -07:00
|
|
|
# endif
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma endregion Gen Interface
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
2023-04-01 22:07:44 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
#pragma region Macros
|
2023-04-03 00:55:28 -07:00
|
|
|
# define gen_main main
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-06-29 19:48:47 -07:00
|
|
|
# define __ NoCode
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
// This represents the naming convention for all typename Codes generated.
|
2023-04-07 21:29:09 -07:00
|
|
|
# define type_ns( Name_ ) t_##Name_
|
|
|
|
|
2023-05-09 18:54:54 -07:00
|
|
|
// Convienence for defining any name used with the gen api.
|
2023-04-07 21:29:09 -07:00
|
|
|
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
2023-05-06 12:49:43 -07:00
|
|
|
# define name( Id_ ) { txt_n_len( Id_ ) }
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
// Same as name just used to indicate intention of literal for code instead of names.
|
2023-05-06 12:49:43 -07:00
|
|
|
# define code( Code_ ) { txt_n_len( Code_ ) }
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-06-29 19:48:47 -07:00
|
|
|
# define code_args( num, ... ) num, (Code[num]){ __VA_ARGS__ }
|
|
|
|
|
|
|
|
# define enum_entry( id ) "\t" #id ",\n"
|
2023-04-06 16:19:11 -07:00
|
|
|
#pragma endregion Macros
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
#pragma region Constants
|
2023-04-05 23:21:23 -07:00
|
|
|
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
2023-04-03 00:55:28 -07:00
|
|
|
namespace gen
|
|
|
|
{
|
2023-04-09 21:38:47 -07:00
|
|
|
// Predefined typename codes. Are set to readonly and are setup during gen::init()
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
extern Code type_ns( s8 );
|
|
|
|
extern Code type_ns( s16 );
|
|
|
|
extern Code type_ns( s32 );
|
|
|
|
extern Code type_ns( s64 );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
extern Code type_ns( u8 );
|
|
|
|
extern Code type_ns( u16 );
|
|
|
|
extern Code type_ns( u32 );
|
|
|
|
extern Code type_ns( u64 );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
extern Code type_ns( sw );
|
|
|
|
extern Code type_ns( uw );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
extern Code type_ns( f32 );
|
|
|
|
extern Code type_ns( f64 );
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
#endif
|
2023-04-05 00:03:56 -07:00
|
|
|
|
|
|
|
namespace gen
|
|
|
|
{
|
2023-04-09 21:38:47 -07:00
|
|
|
// These constexprs are used for allocation heavior of data structurs
|
|
|
|
// or string handling while constructing or serializing.
|
|
|
|
// Change them to suit your needs.
|
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr s32 InitSize_DataArrays = 16;
|
|
|
|
constexpr s32 InitSize_StringTable = megabytes(4);
|
|
|
|
constexpr s32 InitSize_TypeTable = megabytes(4);
|
2023-04-09 21:38:47 -07:00
|
|
|
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr s32 CodePool_NumBlocks = 4096;
|
|
|
|
constexpr s32 InitSize_CodeEntiresArray = 512;
|
|
|
|
constexpr s32 SizePer_CodeEntriresArena = megabytes(16);
|
|
|
|
constexpr s32 SizePer_StringArena = megabytes(32);
|
2023-04-09 21:38:47 -07:00
|
|
|
|
2023-05-01 11:12:07 -07:00
|
|
|
constexpr s32 MaxCommentLineLength = 1024;
|
2023-04-22 19:24:55 -07:00
|
|
|
constexpr s32 MaxNameLength = 128;
|
|
|
|
constexpr s32 MaxUntypedStrLength = kilobytes(640);
|
|
|
|
constexpr s32 StringTable_MaxHashLength = kilobytes(1);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-09 21:38:47 -07:00
|
|
|
// Predefined Codes. Are set to readonly and are setup during gen::init()
|
|
|
|
|
2023-04-10 18:33:06 -07:00
|
|
|
extern Code type_ns( void );
|
|
|
|
extern Code type_ns( int );
|
|
|
|
extern Code type_ns( bool );
|
|
|
|
extern Code type_ns( char );
|
|
|
|
extern Code type_ns( wchar_t );
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code access_public;
|
|
|
|
extern Code access_protected;
|
|
|
|
extern Code access_private;
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-06-28 21:20:23 -07:00
|
|
|
extern Code module_global_fragment;
|
|
|
|
extern Code module_private_fragment;
|
|
|
|
|
2023-06-28 22:37:42 -07:00
|
|
|
extern Code pragma_once;
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
extern Code spec_const;
|
2023-05-09 18:54:54 -07:00
|
|
|
extern Code spec_consteval;
|
|
|
|
extern Code spec_constexpr;
|
|
|
|
extern Code spec_constinit;
|
|
|
|
extern Code spec_extern_linkage;
|
2023-04-06 16:19:11 -07:00
|
|
|
extern Code spec_inline;
|
2023-05-09 18:54:54 -07:00
|
|
|
extern Code spec_internal_linkage;
|
|
|
|
extern Code spec_local_persist;
|
|
|
|
extern Code spec_mutable;
|
2023-04-06 16:19:11 -07:00
|
|
|
extern Code spec_ptr;
|
|
|
|
extern Code spec_ref;
|
2023-05-09 18:54:54 -07:00
|
|
|
extern Code spec_register;
|
|
|
|
extern Code spec_rvalue;
|
|
|
|
extern Code spec_static_member;
|
|
|
|
extern Code spec_thread_local;
|
|
|
|
extern Code spec_volatile;
|
|
|
|
extern Code spec_type_signed;
|
|
|
|
extern Code spec_type_unsigned;
|
|
|
|
extern Code spec_type_short;
|
|
|
|
extern Code spec_type_long;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
2023-04-06 16:19:11 -07:00
|
|
|
#pragma endregion Constants
|
|
|
|
|
2023-04-10 18:33:06 -07:00
|
|
|
#pragma region Inlines
|
|
|
|
namespace gen
|
|
|
|
{
|
2023-04-11 19:18:02 -07:00
|
|
|
inline
|
|
|
|
void AST::add_entry( AST* other )
|
2023-04-10 18:33:06 -07:00
|
|
|
{
|
|
|
|
AST* to_add = other->Parent ?
|
|
|
|
other->duplicate() : other;
|
|
|
|
|
|
|
|
if (DynamicEntries)
|
2023-06-28 18:20:29 -07:00
|
|
|
array_append( ArrDyn, to_add );
|
2023-04-10 18:33:06 -07:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( StaticIndex < ArrS_Cap )
|
|
|
|
{
|
|
|
|
ArrStatic[StaticIndex] = to_add;
|
|
|
|
StaticIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-28 18:20:29 -07:00
|
|
|
ArrDyn = make_code_entries();
|
2023-04-10 18:33:06 -07:00
|
|
|
|
|
|
|
s32 index = 0;
|
|
|
|
do
|
|
|
|
{
|
2023-06-28 18:20:29 -07:00
|
|
|
array_append( ArrDyn, ArrStatic[index] );
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
|
|
|
while ( StaticIndex--, StaticIndex );
|
|
|
|
|
2023-06-28 18:20:29 -07:00
|
|
|
array_append( ArrDyn, to_add );
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
to_add->Parent = this;
|
|
|
|
}
|
2023-04-11 19:18:02 -07:00
|
|
|
|
|
|
|
inline
|
2023-05-06 12:49:43 -07:00
|
|
|
bool AST::add_param( AST* type, StrC name )
|
2023-04-11 19:18:02 -07:00
|
|
|
{
|
2023-04-22 19:24:55 -07:00
|
|
|
if ( Type != ECode::Function )
|
|
|
|
{
|
|
|
|
log_failure( "gen::AST::add_param: this AST is not a function - %s", debug_str() );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
2023-05-06 12:49:43 -07:00
|
|
|
if ( name.Len <= 0 )
|
2023-04-11 19:18:02 -07:00
|
|
|
{
|
2023-05-06 12:49:43 -07:00
|
|
|
log_failure( "gen::AST::add_param: Invalid name length provided - %d", name.Len );
|
2023-04-11 19:18:02 -07:00
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( name == nullptr )
|
|
|
|
{
|
|
|
|
log_failure( "gen::AST::add_param: name is null");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32
|
|
|
|
score = 0;
|
|
|
|
score += Name == nullptr;
|
2023-06-28 18:20:29 -07:00
|
|
|
score += entry( 0 ) == nullptr;
|
2023-04-11 19:18:02 -07:00
|
|
|
|
|
|
|
if ( score == 1 )
|
|
|
|
{
|
|
|
|
log_failure("gen::AST::add_param: this AST has bad data - %s", debug_str() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if ( score == 2)
|
|
|
|
{
|
2023-05-06 12:49:43 -07:00
|
|
|
Name = get_cached_string( name );
|
2023-06-28 18:20:29 -07:00
|
|
|
entry( 0 ) = type;
|
2023-04-11 19:18:02 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Type = ECode::Parameters;
|
|
|
|
|
|
|
|
result->add_entry( result );
|
|
|
|
return true;
|
|
|
|
}
|
2023-04-10 18:33:06 -07:00
|
|
|
}
|
|
|
|
#pragma endregion Inlines
|
|
|
|
|
2023-04-11 19:18:02 -07:00
|
|
|
// end: gen_time
|
|
|
|
#endif
|