mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
Heavy refactor..
Isolating large macros to their own directory (components/temp). - Plan is to remove them soon with proper generation. Added additional component files, separating the old data_structures header for a set of ast headers. Header_end also had its inlines extracted out. Necessary to complete the macro isolation. ZPL parser dependencies were removed from the core library along with builder, its now generated in bootstrap as pare of making a gen_builder set of files. Singleheader will be changed in next few commits to reflect this as well (By making builder deps and components a conditional option). Tests are most likely all broken for now.
This commit is contained in:
parent
114f678f1b
commit
5d7dfaf666
@ -373,7 +373,7 @@ String AST::to_string()
|
||||
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
||||
result.append( "export " );
|
||||
|
||||
result.append_fmt( "namespace %s\n{\n%s}"
|
||||
result.append_fmt( "namespace %s\n{\n%s\n}"
|
||||
, Name
|
||||
, Body->to_string()
|
||||
);
|
||||
@ -528,7 +528,7 @@ String AST::to_string()
|
||||
break;
|
||||
|
||||
case Preprocess_Define:
|
||||
result.append_fmt( "#define %s%s", Name, Content );
|
||||
result.append_fmt( "#define %s \\\n%s\n", Name, Content );
|
||||
break;
|
||||
|
||||
case Preprocess_If:
|
||||
@ -544,7 +544,7 @@ String AST::to_string()
|
||||
break;
|
||||
|
||||
case Preprocess_Include:
|
||||
result.append_fmt( "#include \"%s\"", Content );
|
||||
result.append_fmt( "#include \"%s\"\n", Content );
|
||||
break;
|
||||
|
||||
case Preprocess_ElIf:
|
||||
@ -918,3 +918,4 @@ bool AST::validate_body()
|
||||
}
|
||||
|
||||
#pragma endregion AST
|
||||
|
||||
|
577
project/components/ast.hpp
Normal file
577
project/components/ast.hpp
Normal file
@ -0,0 +1,577 @@
|
||||
struct AST;
|
||||
struct AST_Body;
|
||||
struct AST_Attributes;
|
||||
struct AST_Comment;
|
||||
struct AST_Class;
|
||||
struct AST_Define;
|
||||
struct AST_Enum;
|
||||
struct AST_Exec;
|
||||
struct AST_Extern;
|
||||
struct AST_Include;
|
||||
struct AST_Friend;
|
||||
struct AST_Fn;
|
||||
struct AST_Module;
|
||||
struct AST_Namespace;
|
||||
struct AST_Operator;
|
||||
struct AST_OpCast;
|
||||
struct AST_Param;
|
||||
struct AST_Pragma;
|
||||
struct AST_PreprocessCond;
|
||||
struct AST_Specifiers;
|
||||
struct AST_Struct;
|
||||
struct AST_Template;
|
||||
struct AST_Type;
|
||||
struct AST_Typedef;
|
||||
struct AST_Union;
|
||||
struct AST_Using;
|
||||
struct AST_Var;
|
||||
|
||||
struct Code;
|
||||
struct CodeBody;
|
||||
// These are to offer ease of use and optionally strong type safety for the AST.
|
||||
struct CodeAttributes;
|
||||
struct CodeComment;
|
||||
struct CodeClass;
|
||||
struct CodeDefine;
|
||||
struct CodeEnum;
|
||||
struct CodeExec;
|
||||
struct CodeExtern;
|
||||
struct CodeInclude;
|
||||
struct CodeFriend;
|
||||
struct CodeFn;
|
||||
struct CodeModule;
|
||||
struct CodeNamespace;
|
||||
struct CodeOperator;
|
||||
struct CodeOpCast;
|
||||
struct CodeParam;
|
||||
struct CodePreprocessCond;
|
||||
struct CodePragma;
|
||||
struct CodeSpecifiers;
|
||||
struct CodeStruct;
|
||||
struct CodeTemplate;
|
||||
struct CodeType;
|
||||
struct CodeTypedef;
|
||||
struct CodeUnion;
|
||||
struct CodeUsing;
|
||||
struct CodeVar;
|
||||
|
||||
/*
|
||||
AST* wrapper
|
||||
- Not constantly have to append the '*' as this is written often..
|
||||
- Allows for implicit conversion to any of the ASTs (raw or filtered).
|
||||
*/
|
||||
struct Code
|
||||
{
|
||||
# pragma region Statics
|
||||
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
|
||||
static Code Global;
|
||||
|
||||
// Used to identify invalid generated code.
|
||||
static Code Invalid;
|
||||
# pragma endregion Statics
|
||||
|
||||
#define Using_Code( Typename ) \
|
||||
char const* debug_str(); \
|
||||
Code duplicate(); \
|
||||
bool is_equal( Code other ); \
|
||||
bool is_valid(); \
|
||||
void set_global(); \
|
||||
String to_string(); \
|
||||
Typename& operator = ( AST* other ); \
|
||||
Typename& operator = ( Code other ); \
|
||||
bool operator ==( Code other ); \
|
||||
bool operator !=( Code other ); \
|
||||
operator bool();
|
||||
|
||||
Using_Code( Code );
|
||||
|
||||
template< class Type >
|
||||
Type cast()
|
||||
{
|
||||
return * rcast( Type*, this );
|
||||
}
|
||||
|
||||
AST* operator ->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
Code& operator ++();
|
||||
Code& operator*()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
AST* ast;
|
||||
|
||||
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define operator explicit operator
|
||||
#endif
|
||||
operator CodeAttributes() const;
|
||||
operator CodeComment() const;
|
||||
operator CodeClass() const;
|
||||
operator CodeDefine() const;
|
||||
operator CodeExec() const;
|
||||
operator CodeEnum() const;
|
||||
operator CodeExtern() const;
|
||||
operator CodeInclude() const;
|
||||
operator CodeFriend() const;
|
||||
operator CodeFn() const;
|
||||
operator CodeModule() const;
|
||||
operator CodeNamespace() const;
|
||||
operator CodeOperator() const;
|
||||
operator CodeOpCast() const;
|
||||
operator CodeParam() const;
|
||||
operator CodePragma() const;
|
||||
operator CodePreprocessCond() const;
|
||||
operator CodeSpecifiers() const;
|
||||
operator CodeStruct() const;
|
||||
operator CodeTemplate() const;
|
||||
operator CodeType() const;
|
||||
operator CodeTypedef() const;
|
||||
operator CodeUnion() const;
|
||||
operator CodeUsing() const;
|
||||
operator CodeVar() const;
|
||||
operator CodeBody() const;
|
||||
#undef operator
|
||||
};
|
||||
|
||||
struct Code_POD
|
||||
{
|
||||
AST* ast;
|
||||
};
|
||||
|
||||
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
|
||||
|
||||
// Desired width of the AST data structure.
|
||||
constexpr u32 AST_POD_Size = 128;
|
||||
|
||||
/*
|
||||
Simple AST POD with functionality to seralize into C++ syntax.
|
||||
*/
|
||||
struct AST
|
||||
{
|
||||
# pragma region Member Functions
|
||||
void append ( AST* other );
|
||||
char const* debug_str ();
|
||||
AST* duplicate ();
|
||||
Code& entry ( u32 idx );
|
||||
bool has_entries();
|
||||
bool is_equal ( AST* other );
|
||||
String to_string ();
|
||||
char const* type_str();
|
||||
bool validate_body();
|
||||
|
||||
template< class Type >
|
||||
Type cast()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
|
||||
operator Code();
|
||||
operator CodeBody();
|
||||
operator CodeAttributes();
|
||||
operator CodeComment();
|
||||
operator CodeClass();
|
||||
operator CodeDefine();
|
||||
operator CodeEnum();
|
||||
operator CodeExec();
|
||||
operator CodeExtern();
|
||||
operator CodeInclude();
|
||||
operator CodeFriend();
|
||||
operator CodeFn();
|
||||
operator CodeModule();
|
||||
operator CodeNamespace();
|
||||
operator CodeOperator();
|
||||
operator CodeOpCast();
|
||||
operator CodeParam();
|
||||
operator CodePragma();
|
||||
operator CodePreprocessCond();
|
||||
operator CodeSpecifiers();
|
||||
operator CodeStruct();
|
||||
operator CodeTemplate();
|
||||
operator CodeType();
|
||||
operator CodeTypedef();
|
||||
operator CodeUnion();
|
||||
operator CodeUsing();
|
||||
operator CodeVar();
|
||||
# pragma endregion Member Functions
|
||||
|
||||
constexpr static
|
||||
uw ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(AST*) * 3
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(s32)
|
||||
)
|
||||
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes
|
||||
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
union {
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* BitfieldSize; // Varaiable (Class/Struct Data Member)
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
struct AST_POD
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typename, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
union {
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* BitfieldSize; // Varaiable (Class/Struct Data Member)
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
// Its intended for the AST to have equivalent size to its POD.
|
||||
// All extra functionality within the AST namespace should just be syntatic sugar.
|
||||
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" );
|
||||
|
||||
// Used when the its desired when omission is allowed in a definition.
|
||||
#define NoCode { nullptr }
|
||||
#define CodeInvalid (* Code::Invalid.ast) // Uses an implicitly overloaded cast from the AST to the desired code type.
|
||||
|
||||
#pragma region Code Types
|
||||
|
||||
struct CodeBody
|
||||
{
|
||||
Using_Code( CodeBody );
|
||||
|
||||
void append( Code other )
|
||||
{
|
||||
raw()->append( other.ast );
|
||||
}
|
||||
void append( CodeBody body )
|
||||
{
|
||||
for ( Code entry : body )
|
||||
{
|
||||
append( entry );
|
||||
}
|
||||
}
|
||||
bool has_entries()
|
||||
{
|
||||
return rcast( AST*, ast )->has_entries();
|
||||
}
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Body* operator->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
#pragma region Iterator
|
||||
Code begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { rcast( AST*, ast)->Front };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
Code end()
|
||||
{
|
||||
return { rcast(AST*, ast)->Back->Next };
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Body* ast;
|
||||
};
|
||||
|
||||
struct CodeClass
|
||||
{
|
||||
Using_Code( CodeClass );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Class* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Class* ast;
|
||||
};
|
||||
|
||||
struct CodeParam
|
||||
{
|
||||
Using_Code( CodeParam );
|
||||
|
||||
void append( CodeParam other );
|
||||
|
||||
CodeParam get( s32 idx );
|
||||
bool has_entries();
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Param* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*)ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
CodeParam begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { ast };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
CodeParam end()
|
||||
{
|
||||
return { (AST_Param*) rcast( AST*, ast)->Last };
|
||||
}
|
||||
CodeParam& operator++();
|
||||
CodeParam operator*()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Param* ast;
|
||||
};
|
||||
|
||||
struct CodeSpecifiers
|
||||
{
|
||||
Using_Code( CodeSpecifiers );
|
||||
|
||||
bool append( SpecifierT spec )
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( raw()->NumEntries == AST::ArrSpecs_Cap )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap );
|
||||
return false;
|
||||
}
|
||||
|
||||
raw()->ArrSpecs[ raw()->NumEntries ] = spec;
|
||||
raw()->NumEntries++;
|
||||
return true;
|
||||
}
|
||||
s32 has( SpecifierT spec )
|
||||
{
|
||||
for ( s32 idx = 0; idx < raw()->NumEntries; idx++ )
|
||||
{
|
||||
if ( raw()->ArrSpecs[ raw()->NumEntries ] == spec )
|
||||
return idx;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Specifiers* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*) ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
SpecifierT* begin()
|
||||
{
|
||||
if ( ast )
|
||||
return & raw()->ArrSpecs[0];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
SpecifierT* end()
|
||||
{
|
||||
return raw()->ArrSpecs + raw()->NumEntries;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Specifiers* ast;
|
||||
};
|
||||
|
||||
struct CodeStruct
|
||||
{
|
||||
Using_Code( CodeStruct );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Struct* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Struct* ast;
|
||||
};
|
||||
|
||||
#define Define_CodeType( Typename ) \
|
||||
struct Code##Typename \
|
||||
{ \
|
||||
Using_Code( Code##Typename ); \
|
||||
AST* raw() \
|
||||
{ \
|
||||
return rcast( AST*, ast ); \
|
||||
} \
|
||||
operator Code() \
|
||||
{ \
|
||||
return * rcast( Code*, this ); \
|
||||
} \
|
||||
AST_##Typename* operator->() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Attempt to dereference a nullptr!"); \
|
||||
return nullptr; \
|
||||
} \
|
||||
return ast; \
|
||||
} \
|
||||
AST_##Typename* ast; \
|
||||
}
|
||||
|
||||
Define_CodeType( Attributes );
|
||||
Define_CodeType( Comment );
|
||||
Define_CodeType( Define );
|
||||
Define_CodeType( Enum );
|
||||
Define_CodeType( Exec );
|
||||
Define_CodeType( Extern );
|
||||
Define_CodeType( Include );
|
||||
Define_CodeType( Friend );
|
||||
Define_CodeType( Fn );
|
||||
Define_CodeType( Module );
|
||||
Define_CodeType( Namespace );
|
||||
Define_CodeType( Operator );
|
||||
Define_CodeType( OpCast );
|
||||
Define_CodeType( Pragma );
|
||||
Define_CodeType( PreprocessCond );
|
||||
Define_CodeType( Template );
|
||||
Define_CodeType( Type );
|
||||
Define_CodeType( Typedef );
|
||||
Define_CodeType( Union );
|
||||
Define_CodeType( Using );
|
||||
Define_CodeType( Var );
|
||||
|
||||
#undef Define_CodeType
|
||||
#undef Using_Code
|
||||
|
||||
#pragma endregion Code Types
|
||||
|
@ -77,3 +77,4 @@
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
|
||||
|
@ -1,591 +1,4 @@
|
||||
#pragma region Data Structures
|
||||
|
||||
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||
using StringTable = HashTable<String const>;
|
||||
|
||||
// Represents strings cached with the string table.
|
||||
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
||||
using StringCached = String const;
|
||||
|
||||
struct AST;
|
||||
struct AST_Body;
|
||||
struct AST_Attributes;
|
||||
struct AST_Comment;
|
||||
struct AST_Class;
|
||||
struct AST_Define;
|
||||
struct AST_Enum;
|
||||
struct AST_Exec;
|
||||
struct AST_Extern;
|
||||
struct AST_Include;
|
||||
struct AST_Friend;
|
||||
struct AST_Fn;
|
||||
struct AST_Module;
|
||||
struct AST_Namespace;
|
||||
struct AST_Operator;
|
||||
struct AST_OpCast;
|
||||
struct AST_Param;
|
||||
struct AST_Pragma;
|
||||
struct AST_PreprocessCond;
|
||||
struct AST_Specifiers;
|
||||
struct AST_Struct;
|
||||
struct AST_Template;
|
||||
struct AST_Type;
|
||||
struct AST_Typedef;
|
||||
struct AST_Union;
|
||||
struct AST_Using;
|
||||
struct AST_Var;
|
||||
|
||||
struct Code;
|
||||
struct CodeBody;
|
||||
// These are to offer ease of use and optionally strong type safety for the AST.
|
||||
struct CodeAttributes;
|
||||
struct CodeComment;
|
||||
struct CodeClass;
|
||||
struct CodeDefine;
|
||||
struct CodeEnum;
|
||||
struct CodeExec;
|
||||
struct CodeExtern;
|
||||
struct CodeInclude;
|
||||
struct CodeFriend;
|
||||
struct CodeFn;
|
||||
struct CodeModule;
|
||||
struct CodeNamespace;
|
||||
struct CodeOperator;
|
||||
struct CodeOpCast;
|
||||
struct CodeParam;
|
||||
struct CodePreprocessCond;
|
||||
struct CodePragma;
|
||||
struct CodeSpecifiers;
|
||||
struct CodeStruct;
|
||||
struct CodeTemplate;
|
||||
struct CodeType;
|
||||
struct CodeTypedef;
|
||||
struct CodeUnion;
|
||||
struct CodeUsing;
|
||||
struct CodeVar;
|
||||
|
||||
/*
|
||||
AST* wrapper
|
||||
- Not constantly have to append the '*' as this is written often..
|
||||
- Allows for implicit conversion to any of the ASTs (raw or filtered).
|
||||
*/
|
||||
struct Code
|
||||
{
|
||||
# pragma region Statics
|
||||
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
|
||||
static Code Global;
|
||||
|
||||
// Used to identify invalid generated code.
|
||||
static Code Invalid;
|
||||
# pragma endregion Statics
|
||||
|
||||
#define Using_Code( Typename ) \
|
||||
char const* debug_str(); \
|
||||
Code duplicate(); \
|
||||
bool is_equal( Code other ); \
|
||||
bool is_valid(); \
|
||||
void set_global(); \
|
||||
String to_string(); \
|
||||
Typename& operator = ( AST* other ); \
|
||||
Typename& operator = ( Code other ); \
|
||||
bool operator ==( Code other ); \
|
||||
bool operator !=( Code other ); \
|
||||
operator bool() \
|
||||
{ \
|
||||
return ast != nullptr; \
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
Type cast()
|
||||
{
|
||||
return * rcast( Type*, this );
|
||||
}
|
||||
|
||||
AST* operator ->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
Code& operator ++();
|
||||
Code& operator*()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
Using_Code( Code );
|
||||
|
||||
AST* ast;
|
||||
|
||||
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define operator explicit operator
|
||||
#endif
|
||||
operator CodeAttributes() const;
|
||||
operator CodeComment() const;
|
||||
operator CodeClass() const;
|
||||
operator CodeDefine() const;
|
||||
operator CodeExec() const;
|
||||
operator CodeEnum() const;
|
||||
operator CodeExtern() const;
|
||||
operator CodeInclude() const;
|
||||
operator CodeFriend() const;
|
||||
operator CodeFn() const;
|
||||
operator CodeModule() const;
|
||||
operator CodeNamespace() const;
|
||||
operator CodeOperator() const;
|
||||
operator CodeOpCast() const;
|
||||
operator CodeParam() const;
|
||||
operator CodePragma() const;
|
||||
operator CodePreprocessCond() const;
|
||||
operator CodeSpecifiers() const;
|
||||
operator CodeStruct() const;
|
||||
operator CodeTemplate() const;
|
||||
operator CodeType() const;
|
||||
operator CodeTypedef() const;
|
||||
operator CodeUnion() const;
|
||||
operator CodeUsing() const;
|
||||
operator CodeVar() const;
|
||||
operator CodeBody() const;
|
||||
#undef operator
|
||||
};
|
||||
|
||||
struct Code_POD
|
||||
{
|
||||
AST* ast;
|
||||
};
|
||||
|
||||
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
|
||||
|
||||
// Desired width of the AST data structure.
|
||||
constexpr u32 AST_POD_Size = 128;
|
||||
|
||||
/*
|
||||
Simple AST POD with functionality to seralize into C++ syntax.
|
||||
*/
|
||||
struct AST
|
||||
{
|
||||
# pragma region Member Functions
|
||||
void append ( AST* other );
|
||||
char const* debug_str ();
|
||||
AST* duplicate ();
|
||||
Code& entry ( u32 idx );
|
||||
bool has_entries();
|
||||
bool is_equal ( AST* other );
|
||||
String to_string ();
|
||||
char const* type_str();
|
||||
bool validate_body();
|
||||
|
||||
template< class Type >
|
||||
Type cast()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
|
||||
operator Code();
|
||||
operator CodeBody();
|
||||
operator CodeAttributes();
|
||||
operator CodeComment();
|
||||
operator CodeClass();
|
||||
operator CodeDefine();
|
||||
operator CodeEnum();
|
||||
operator CodeExec();
|
||||
operator CodeExtern();
|
||||
operator CodeInclude();
|
||||
operator CodeFriend();
|
||||
operator CodeFn();
|
||||
operator CodeModule();
|
||||
operator CodeNamespace();
|
||||
operator CodeOperator();
|
||||
operator CodeOpCast();
|
||||
operator CodeParam();
|
||||
operator CodePragma();
|
||||
operator CodePreprocessCond();
|
||||
operator CodeSpecifiers();
|
||||
operator CodeStruct();
|
||||
operator CodeTemplate();
|
||||
operator CodeType();
|
||||
operator CodeTypedef();
|
||||
operator CodeUnion();
|
||||
operator CodeUsing();
|
||||
operator CodeVar();
|
||||
# pragma endregion Member Functions
|
||||
|
||||
constexpr static
|
||||
uw ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(AST*) * 3
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(s32)
|
||||
)
|
||||
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes
|
||||
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
union {
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* BitfieldSize; // Varaiable (Class/Struct Data Member)
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
struct AST_POD
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typename, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
union {
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* BitfieldSize; // Varaiable (Class/Struct Data Member)
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
// Its intended for the AST to have equivalent size to its POD.
|
||||
// All extra functionality within the AST namespace should just be syntatic sugar.
|
||||
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" );
|
||||
|
||||
// Used when the its desired when omission is allowed in a definition.
|
||||
#define NoCode { nullptr }
|
||||
#define CodeInvalid (* Code::Invalid.ast) // Uses an implicitly overloaded cast from the AST to the desired code type.
|
||||
|
||||
#pragma region Code Types
|
||||
#define Define_CodeType( Typename ) \
|
||||
struct Code##Typename \
|
||||
{ \
|
||||
Using_Code( Code##Typename ); \
|
||||
AST* raw() \
|
||||
{ \
|
||||
return rcast( AST*, ast ); \
|
||||
} \
|
||||
operator Code() \
|
||||
{ \
|
||||
return * rcast( Code*, this ); \
|
||||
} \
|
||||
AST_##Typename* operator->() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Attempt to dereference a nullptr!"); \
|
||||
return nullptr; \
|
||||
} \
|
||||
return ast; \
|
||||
} \
|
||||
AST_##Typename* ast; \
|
||||
}
|
||||
|
||||
struct CodeBody
|
||||
{
|
||||
Using_Code( CodeBody );
|
||||
|
||||
void append( Code other )
|
||||
{
|
||||
raw()->append( other.ast );
|
||||
}
|
||||
void append( CodeBody body )
|
||||
{
|
||||
for ( Code entry : body )
|
||||
{
|
||||
append( entry );
|
||||
}
|
||||
}
|
||||
bool has_entries()
|
||||
{
|
||||
return rcast( AST*, ast )->has_entries();
|
||||
}
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Body* operator->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
#pragma region Iterator
|
||||
Code begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { rcast( AST*, ast)->Front };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
Code end()
|
||||
{
|
||||
return { rcast(AST*, ast)->Back->Next };
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Body* ast;
|
||||
};
|
||||
|
||||
Define_CodeType( Attributes );
|
||||
Define_CodeType( Comment );
|
||||
Define_CodeType( Define );
|
||||
Define_CodeType( Enum );
|
||||
Define_CodeType( Exec );
|
||||
Define_CodeType( Extern );
|
||||
Define_CodeType( Include );
|
||||
Define_CodeType( Friend );
|
||||
Define_CodeType( Fn );
|
||||
Define_CodeType( Module );
|
||||
Define_CodeType( Namespace );
|
||||
Define_CodeType( Operator );
|
||||
Define_CodeType( OpCast );
|
||||
Define_CodeType( Pragma );
|
||||
Define_CodeType( PreprocessCond );
|
||||
Define_CodeType( Template );
|
||||
Define_CodeType( Type );
|
||||
Define_CodeType( Typedef );
|
||||
Define_CodeType( Union );
|
||||
Define_CodeType( Using );
|
||||
Define_CodeType( Var );
|
||||
|
||||
struct CodeClass
|
||||
{
|
||||
Using_Code( CodeClass );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Class* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Class* ast;
|
||||
};
|
||||
|
||||
struct CodeParam
|
||||
{
|
||||
Using_Code( CodeParam );
|
||||
|
||||
void append( CodeParam other );
|
||||
|
||||
CodeParam get( s32 idx );
|
||||
bool has_entries();
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Param* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*)ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
CodeParam begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { ast };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
CodeParam end()
|
||||
{
|
||||
return { (AST_Param*) rcast( AST*, ast)->Last };
|
||||
}
|
||||
CodeParam& operator++();
|
||||
CodeParam operator*()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Param* ast;
|
||||
};
|
||||
|
||||
struct CodeSpecifiers
|
||||
{
|
||||
Using_Code( CodeSpecifiers );
|
||||
|
||||
bool append( SpecifierT spec )
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( raw()->NumEntries == AST::ArrSpecs_Cap )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap );
|
||||
return false;
|
||||
}
|
||||
|
||||
raw()->ArrSpecs[ raw()->NumEntries ] = spec;
|
||||
raw()->NumEntries++;
|
||||
return true;
|
||||
}
|
||||
s32 has( SpecifierT spec )
|
||||
{
|
||||
for ( s32 idx = 0; idx < raw()->NumEntries; idx++ )
|
||||
{
|
||||
if ( raw()->ArrSpecs[ raw()->NumEntries ] == spec )
|
||||
return idx;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Specifiers* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*) ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
SpecifierT* begin()
|
||||
{
|
||||
if ( ast )
|
||||
return & raw()->ArrSpecs[0];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
SpecifierT* end()
|
||||
{
|
||||
return raw()->ArrSpecs + raw()->NumEntries;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Specifiers* ast;
|
||||
};
|
||||
|
||||
struct CodeStruct
|
||||
{
|
||||
Using_Code( CodeStruct );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Struct* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Struct* ast;
|
||||
};
|
||||
|
||||
#undef Define_CodeType
|
||||
#undef Using_Code
|
||||
#pragma endregion Code Types
|
||||
|
||||
#pragma region Filtered ASTs
|
||||
#pragma region AST Types
|
||||
/*
|
||||
Show only relevant members of the AST for its type.
|
||||
AST* fields are replaced with Code types.
|
||||
@ -1083,6 +496,5 @@ struct AST_Var
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
||||
#pragma endregion Filtered ASTs
|
||||
#pragma endregion AST Types
|
||||
|
||||
#pragma endregion Data Structures
|
@ -1,396 +1,3 @@
|
||||
#pragma region Inlines
|
||||
|
||||
void AST::append( AST* other )
|
||||
{
|
||||
if ( other->Parent )
|
||||
other = other->duplicate();
|
||||
|
||||
other->Parent = this;
|
||||
|
||||
if ( Front == nullptr )
|
||||
{
|
||||
Front = other;
|
||||
Back = other;
|
||||
|
||||
NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
AST*
|
||||
Current = Back;
|
||||
Current->Next = other;
|
||||
other->Prev = Current;
|
||||
Back = other;
|
||||
NumEntries++;
|
||||
}
|
||||
|
||||
char const* AST::debug_str()
|
||||
{
|
||||
if ( Parent )
|
||||
{
|
||||
char const* fmt = stringize(
|
||||
\nType : %s
|
||||
\nParent : %s %s
|
||||
\nName : %s
|
||||
);
|
||||
|
||||
// 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.
|
||||
return str_fmt_buf( fmt
|
||||
, type_str()
|
||||
, Parent->Name
|
||||
, Parent->type_str()
|
||||
, Name ? Name : ""
|
||||
);
|
||||
}
|
||||
|
||||
char const* fmt = stringize(
|
||||
\nType : %s
|
||||
\nName : %s
|
||||
);
|
||||
|
||||
// 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.
|
||||
return str_fmt_buf( fmt
|
||||
, type_str()
|
||||
, Name ? Name : ""
|
||||
);
|
||||
}
|
||||
|
||||
Code& AST::entry( u32 idx )
|
||||
{
|
||||
AST** current = & Front;
|
||||
while ( idx >= 0 && current != nullptr )
|
||||
{
|
||||
if ( idx == 0 )
|
||||
return * rcast( Code*, current);
|
||||
|
||||
current = & ( * current )->Next;
|
||||
idx--;
|
||||
}
|
||||
|
||||
return * rcast( Code*, current);
|
||||
}
|
||||
|
||||
bool AST::has_entries()
|
||||
{
|
||||
return NumEntries;
|
||||
}
|
||||
|
||||
char const* AST::type_str()
|
||||
{
|
||||
return ECode::to_str( Type );
|
||||
}
|
||||
|
||||
AST::operator Code()
|
||||
{
|
||||
return { this };
|
||||
}
|
||||
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
if ( ast )
|
||||
ast = ast->Next;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#pragma region AST & Code Gen Common
|
||||
|
||||
#define Define_CodeImpl( Typename ) \
|
||||
char const* Typename::debug_str() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
return "Code::debug_str: AST is null!"; \
|
||||
\
|
||||
return rcast(AST*, ast)->debug_str(); \
|
||||
} \
|
||||
Code Typename::duplicate() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); \
|
||||
return Code::Invalid; \
|
||||
} \
|
||||
\
|
||||
return { rcast(AST*, ast)->duplicate() }; \
|
||||
} \
|
||||
bool Typename::is_equal( Code other ) \
|
||||
{ \
|
||||
if ( ast == nullptr || other.ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::is_equal: Cannot compare code, AST is null!"); \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->is_equal( other.ast ); \
|
||||
} \
|
||||
bool Typename::is_valid() \
|
||||
{ \
|
||||
return (AST*) ast != nullptr && rcast( AST*, ast)->Type != CodeT::Invalid; \
|
||||
} \
|
||||
void Typename::set_global() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::set_global: Cannot set code as global, AST is null!"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
rcast(AST*, ast)->Parent = Code::Global.ast; \
|
||||
} \
|
||||
String Typename::to_string() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::to_string: Cannot convert code to string, AST is null!"); \
|
||||
return { nullptr }; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->to_string(); \
|
||||
} \
|
||||
Typename& Typename::operator =( Code other ) \
|
||||
{ \
|
||||
if ( other.ast && other->Parent ) \
|
||||
{ \
|
||||
ast = rcast( decltype(ast), other.ast->duplicate() ); \
|
||||
rcast( AST*, ast)->Parent = nullptr; \
|
||||
} \
|
||||
\
|
||||
ast = rcast( decltype(ast), other.ast ); \
|
||||
return *this; \
|
||||
} \
|
||||
bool Typename::operator ==( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast == other.ast; \
|
||||
} \
|
||||
bool Typename::operator !=( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast != other.ast; \
|
||||
}
|
||||
|
||||
Define_CodeImpl( Code );
|
||||
Define_CodeImpl( CodeBody );
|
||||
Define_CodeImpl( CodeAttributes );
|
||||
Define_CodeImpl( CodeComment );
|
||||
Define_CodeImpl( CodeClass );
|
||||
Define_CodeImpl( CodeDefine );
|
||||
Define_CodeImpl( CodeEnum );
|
||||
Define_CodeImpl( CodeExec );
|
||||
Define_CodeImpl( CodeExtern );
|
||||
Define_CodeImpl( CodeInclude );
|
||||
Define_CodeImpl( CodeFriend );
|
||||
Define_CodeImpl( CodeFn );
|
||||
Define_CodeImpl( CodeModule );
|
||||
Define_CodeImpl( CodeNamespace );
|
||||
Define_CodeImpl( CodeOperator );
|
||||
Define_CodeImpl( CodeOpCast );
|
||||
Define_CodeImpl( CodeParam );
|
||||
Define_CodeImpl( CodePragma );
|
||||
Define_CodeImpl( CodePreprocessCond );
|
||||
Define_CodeImpl( CodeSpecifiers );
|
||||
Define_CodeImpl( CodeStruct );
|
||||
Define_CodeImpl( CodeTemplate );
|
||||
Define_CodeImpl( CodeType );
|
||||
Define_CodeImpl( CodeTypedef );
|
||||
Define_CodeImpl( CodeUnion );
|
||||
Define_CodeImpl( CodeUsing );
|
||||
Define_CodeImpl( CodeVar );
|
||||
#undef Define_CodeImpl
|
||||
|
||||
#define Define_AST_Cast( typename ) \
|
||||
AST::operator Code ## typename() \
|
||||
{ \
|
||||
return { rcast( AST_ ## typename*, this ) }; \
|
||||
}
|
||||
|
||||
Define_AST_Cast( Body );
|
||||
Define_AST_Cast( Attributes );
|
||||
Define_AST_Cast( Comment );
|
||||
Define_AST_Cast( Class );
|
||||
Define_AST_Cast( Define );
|
||||
Define_AST_Cast( Enum );
|
||||
Define_AST_Cast( Exec );
|
||||
Define_AST_Cast( Extern );
|
||||
Define_AST_Cast( Include );
|
||||
Define_AST_Cast( Friend );
|
||||
Define_AST_Cast( Fn );
|
||||
Define_AST_Cast( Module );
|
||||
Define_AST_Cast( Namespace );
|
||||
Define_AST_Cast( Operator );
|
||||
Define_AST_Cast( OpCast );
|
||||
Define_AST_Cast( Param );
|
||||
Define_AST_Cast( Pragma );
|
||||
Define_AST_Cast( PreprocessCond );
|
||||
Define_AST_Cast( Struct );
|
||||
Define_AST_Cast( Specifiers );
|
||||
Define_AST_Cast( Template );
|
||||
Define_AST_Cast( Type );
|
||||
Define_AST_Cast( Typedef );
|
||||
Define_AST_Cast( Union );
|
||||
Define_AST_Cast( Using );
|
||||
Define_AST_Cast( Var );
|
||||
#undef Define_AST_Cast
|
||||
|
||||
#define Define_CodeCast( type ) \
|
||||
Code::operator Code ## type() const \
|
||||
{ \
|
||||
return { (AST_ ## type*) ast }; \
|
||||
}
|
||||
|
||||
Define_CodeCast( Attributes );
|
||||
Define_CodeCast( Comment );
|
||||
Define_CodeCast( Class );
|
||||
Define_CodeCast( Define );
|
||||
Define_CodeCast( Exec );
|
||||
Define_CodeCast( Enum );
|
||||
Define_CodeCast( Extern );
|
||||
Define_CodeCast( Include );
|
||||
Define_CodeCast( Friend );
|
||||
Define_CodeCast( Fn );
|
||||
Define_CodeCast( Module );
|
||||
Define_CodeCast( Namespace );
|
||||
Define_CodeCast( Operator );
|
||||
Define_CodeCast( OpCast );
|
||||
Define_CodeCast( Param );
|
||||
Define_CodeCast( Pragma );
|
||||
Define_CodeCast( PreprocessCond );
|
||||
Define_CodeCast( Specifiers );
|
||||
Define_CodeCast( Struct );
|
||||
Define_CodeCast( Template );
|
||||
Define_CodeCast( Type );
|
||||
Define_CodeCast( Typedef );
|
||||
Define_CodeCast( Union );
|
||||
Define_CodeCast( Using );
|
||||
Define_CodeCast( Var );
|
||||
Define_CodeCast( Body);
|
||||
#undef Define_CodeCast
|
||||
|
||||
#pragma endregion AST & Code Gen Common
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
return;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
{
|
||||
AST* self = (AST*) ast;
|
||||
AST* entry = (AST*) other.ast;
|
||||
|
||||
if ( entry->Parent )
|
||||
entry = entry->duplicate();
|
||||
|
||||
entry->Parent = self;
|
||||
|
||||
if ( self->Last == nullptr )
|
||||
{
|
||||
self->Last = entry;
|
||||
self->Next = entry;
|
||||
self->NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
self->Last->Next = entry;
|
||||
self->Last = entry;
|
||||
self->NumEntries++;
|
||||
}
|
||||
|
||||
CodeParam CodeParam::get( s32 idx )
|
||||
{
|
||||
CodeParam param = *this;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
|
||||
return { (AST_Param*) param.raw()->Next };
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
bool CodeParam::has_entries()
|
||||
{
|
||||
return ast->NumEntries > 0;
|
||||
}
|
||||
|
||||
CodeParam& CodeParam::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
return * this;
|
||||
}
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
using namespace ECode;
|
||||
case Class_Body:
|
||||
case Enum_Body:
|
||||
case Export_Body:
|
||||
case Extern_Linkage:
|
||||
case Function_Body:
|
||||
case Global_Body:
|
||||
case Namespace_Body:
|
||||
case Struct_Body:
|
||||
case Union_Body:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
|
||||
return (CodeBody)Code::Invalid;
|
||||
}
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = type;
|
||||
return (CodeBody)result;
|
||||
}
|
||||
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
StrC token_fmt_impl( sw num, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
|
||||
|
||||
va_list va;
|
||||
va_start(va, num );
|
||||
sw result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||
va_end(va);
|
||||
|
||||
return { result, buf };
|
||||
}
|
||||
|
||||
#pragma endregion Inlines
|
||||
|
||||
#pragma region Constants
|
||||
|
||||
#ifndef GEN_GLOBAL_BUCKET_SIZE
|
||||
@ -541,6 +148,7 @@ extern CodeType t_typename;
|
||||
// Global allocator used for data with process lifetime.
|
||||
extern AllocatorInfo GlobalAllocator;
|
||||
extern Array< Arena > Global_AllocatorBuckets;
|
||||
|
||||
extern Array< Pool > CodePools;
|
||||
extern Array< Arena > StringArenas;
|
||||
|
||||
@ -556,3 +164,4 @@ extern CodeType t_typename;
|
||||
extern AllocatorInfo Allocator_TypeTable;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -15,3 +15,12 @@
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
|
||||
|
214
project/components/inlines.hpp
Normal file
214
project/components/inlines.hpp
Normal file
@ -0,0 +1,214 @@
|
||||
void AST::append( AST* other )
|
||||
{
|
||||
if ( other->Parent )
|
||||
other = other->duplicate();
|
||||
|
||||
other->Parent = this;
|
||||
|
||||
if ( Front == nullptr )
|
||||
{
|
||||
Front = other;
|
||||
Back = other;
|
||||
|
||||
NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
AST*
|
||||
Current = Back;
|
||||
Current->Next = other;
|
||||
other->Prev = Current;
|
||||
Back = other;
|
||||
NumEntries++;
|
||||
}
|
||||
|
||||
char const* AST::debug_str()
|
||||
{
|
||||
if ( Parent )
|
||||
{
|
||||
char const* fmt = stringize(
|
||||
\nType : %s
|
||||
\nParent : %s %s
|
||||
\nName : %s
|
||||
);
|
||||
|
||||
// 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.
|
||||
return str_fmt_buf( fmt
|
||||
, type_str()
|
||||
, Parent->Name
|
||||
, Parent->type_str()
|
||||
, Name ? Name : ""
|
||||
);
|
||||
}
|
||||
|
||||
char const* fmt = stringize(
|
||||
\nType : %s
|
||||
\nName : %s
|
||||
);
|
||||
|
||||
// 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.
|
||||
return str_fmt_buf( fmt
|
||||
, type_str()
|
||||
, Name ? Name : ""
|
||||
);
|
||||
}
|
||||
|
||||
Code& AST::entry( u32 idx )
|
||||
{
|
||||
AST** current = & Front;
|
||||
while ( idx >= 0 && current != nullptr )
|
||||
{
|
||||
if ( idx == 0 )
|
||||
return * rcast( Code*, current);
|
||||
|
||||
current = & ( * current )->Next;
|
||||
idx--;
|
||||
}
|
||||
|
||||
return * rcast( Code*, current);
|
||||
}
|
||||
|
||||
bool AST::has_entries()
|
||||
{
|
||||
return NumEntries;
|
||||
}
|
||||
|
||||
char const* AST::type_str()
|
||||
{
|
||||
return ECode::to_str( Type );
|
||||
}
|
||||
|
||||
AST::operator Code()
|
||||
{
|
||||
return { this };
|
||||
}
|
||||
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
if ( ast )
|
||||
ast = ast->Next;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
return;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
{
|
||||
AST* self = (AST*) ast;
|
||||
AST* entry = (AST*) other.ast;
|
||||
|
||||
if ( entry->Parent )
|
||||
entry = entry->duplicate();
|
||||
|
||||
entry->Parent = self;
|
||||
|
||||
if ( self->Last == nullptr )
|
||||
{
|
||||
self->Last = entry;
|
||||
self->Next = entry;
|
||||
self->NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
self->Last->Next = entry;
|
||||
self->Last = entry;
|
||||
self->NumEntries++;
|
||||
}
|
||||
|
||||
CodeParam CodeParam::get( s32 idx )
|
||||
{
|
||||
CodeParam param = *this;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
|
||||
return { (AST_Param*) param.raw()->Next };
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
bool CodeParam::has_entries()
|
||||
{
|
||||
return ast->NumEntries > 0;
|
||||
}
|
||||
|
||||
CodeParam& CodeParam::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
return * this;
|
||||
}
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
using namespace ECode;
|
||||
case Class_Body:
|
||||
case Enum_Body:
|
||||
case Export_Body:
|
||||
case Extern_Linkage:
|
||||
case Function_Body:
|
||||
case Global_Body:
|
||||
case Namespace_Body:
|
||||
case Struct_Body:
|
||||
case Union_Body:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
|
||||
return (CodeBody)Code::Invalid;
|
||||
}
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = type;
|
||||
return (CodeBody)result;
|
||||
}
|
||||
|
||||
StrC token_fmt_impl( sw num, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
|
||||
|
||||
va_list va;
|
||||
va_start(va, num );
|
||||
sw result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||
va_end(va);
|
||||
|
||||
return { result, buf };
|
||||
}
|
||||
|
@ -440,3 +440,4 @@ void set_allocator_string_table( AllocatorInfo allocator )
|
||||
{
|
||||
Allocator_StringArena = allocator;
|
||||
}
|
||||
|
||||
|
@ -159,6 +159,7 @@ CodeVar parse_variable ( StrC var_def );
|
||||
#pragma region Untyped text
|
||||
|
||||
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va );
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
StrC token_fmt_impl( sw, ... );
|
||||
|
||||
Code untyped_str ( StrC content);
|
||||
@ -168,3 +169,4 @@ Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
||||
#pragma endregion Untyped text
|
||||
|
||||
#pragma endregion Gen Interface
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
struct Token
|
||||
@ -4430,3 +4429,4 @@ CodeVar parse_variable( StrC def )
|
||||
# undef left
|
||||
# undef check
|
||||
# undef push_scope
|
||||
|
||||
|
@ -503,6 +503,7 @@ CodeDefine def_define( StrC name, StrC content )
|
||||
|
||||
CodeDefine
|
||||
result = (CodeDefine) make_code();
|
||||
result->Type = Preprocess_Define;
|
||||
result->Name = get_cached_string( name );
|
||||
result->Content = get_cached_string( content );
|
||||
|
||||
@ -1306,27 +1307,6 @@ CodeVar def_variable( CodeType type, StrC name, Code value
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Body related functions typically follow the same implementation pattern.
|
||||
Opted to use inline helper macros to get the implementaiton done.
|
||||
|
||||
The implementation pattern is as follows:
|
||||
* Validate a valid parameter num was provided, or code array
|
||||
def_body_start or def_body_code_array_start( <name of function >)
|
||||
|
||||
* Begin the code entry do-while loop, make sure each entry is valid processing its type in the switc
|
||||
def_body_code_validation_start( <name of function> )
|
||||
|
||||
* Define the switch case statements between the macros.
|
||||
|
||||
* Add the code entry, finish the closing implemenation for the do-while loop.
|
||||
def_body_code_validation_end( <name of function> )
|
||||
|
||||
* Lock the body AST and return it.
|
||||
|
||||
If a function's implementation deviates from the macros then its just writen it out.
|
||||
*/
|
||||
|
||||
#pragma region Helper Macros for def_**_body functions
|
||||
#define def_body_start( Name_ ) \
|
||||
using namespace ECode; \
|
||||
@ -1352,61 +1332,43 @@ if ( codes == nullptr ) \
|
||||
return CodeInvalid; \
|
||||
}
|
||||
|
||||
#define def_body_code_validation_start( Name_ ) \
|
||||
do \
|
||||
{ \
|
||||
Code_POD pod = va_arg(va, Code_POD); \
|
||||
Code entry = pcast(Code, pod); \
|
||||
\
|
||||
if ( ! entry ) \
|
||||
{ \
|
||||
log_failure("gen::" stringize(Name_) ": Provided an null entry"); \
|
||||
return CodeInvalid; \
|
||||
} \
|
||||
\
|
||||
switch ( entry->Type ) \
|
||||
{
|
||||
|
||||
#define def_body_code_array_validation_start( Name_ ) \
|
||||
do \
|
||||
{ \
|
||||
Code entry = *codes; codes++; \
|
||||
\
|
||||
if ( ! entry ) \
|
||||
{ \
|
||||
log_failure("gen::" stringize(Name_) ": Provided an null entry"); \
|
||||
return CodeInvalid; \
|
||||
} \
|
||||
\
|
||||
switch ( entry->Type ) \
|
||||
{
|
||||
|
||||
#define def_body_code_validation_end( Name_ ) \
|
||||
log_failure("gen::" stringize(Name_) ": Entry type is not allowed: %s", entry.debug_str() ); \
|
||||
return CodeInvalid; \
|
||||
\
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
result.append( entry ); \
|
||||
} \
|
||||
while ( num--, num > 0 )
|
||||
#pragma endregion Helper Macros for def_**_body functions
|
||||
|
||||
CodeBody def_class_body( s32 num, ... )
|
||||
{
|
||||
def_body_start( def_class_body );
|
||||
|
||||
CodeBody
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Class_Body;
|
||||
CodeBody result = ( CodeBody )make_code();
|
||||
result->Type = Class_Body;
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_class_body );
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_class_body );
|
||||
va_start( va, num );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::"
|
||||
"def_class_body"
|
||||
": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1420,9 +1382,30 @@ CodeBody def_class_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Function_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_class_body );
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_class_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_class_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1503,9 +1486,30 @@ CodeBody def_export_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_export_body );
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_export_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1519,9 +1523,30 @@ CodeBody def_export_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Export_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_export_body );
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_export_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1536,9 +1561,30 @@ CodeBody def_extern_link_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_extern_linkage_body );
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_extern_linkage_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1552,9 +1598,31 @@ CodeBody def_extern_link_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Extern_Linkage_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_extern_linkage_body );
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_extern_linkage_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1569,9 +1637,31 @@ CodeBody def_function_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_function_body );
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_function_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" stringize(def_function_body) ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1585,9 +1675,29 @@ CodeBody def_function_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Function_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_function_body );
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_function_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_function_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1602,9 +1712,30 @@ CodeBody def_global_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_global_body );
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_global_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return (*Code::Invalid.ast);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1618,9 +1749,30 @@ CodeBody def_global_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Global_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_global_body );
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_global_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1635,9 +1787,30 @@ CodeBody def_namespace_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_namespace_body );
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_namespace_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1651,9 +1824,29 @@ CodeBody def_namespace_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Global_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_namespace_body );
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_namespace_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1803,9 +1996,30 @@ CodeBody def_struct_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_struct_body );
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_struct_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1819,9 +2033,30 @@ CodeBody def_struct_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Struct_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_struct_body );
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_struct_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1895,3 +2130,4 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
|
||||
# undef name_check
|
||||
# undef null_check
|
||||
# undef null_or_invalid_check
|
||||
|
||||
|
@ -7,3 +7,4 @@
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.cpp"
|
||||
#endif
|
||||
|
@ -92,3 +92,4 @@ global CodeType t_f64;
|
||||
#endif
|
||||
|
||||
#pragma endregion Constants
|
||||
|
||||
|
8
project/components/temp/Readme.md
Normal file
8
project/components/temp/Readme.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Temporary Code
|
||||
|
||||
These are heavy macro code used throughout the library thats intended to be replaced with codegen done with the library itself.
|
||||
|
||||
The reason for this is to minimize macro generation to only trivial cases.
|
||||
This makes the library more verbose but makes it easier to debug which is of higher priority.
|
||||
|
||||
Any sort of verbosity cost will be mitigated with better docs and heavy usage of pragma regions.
|
179
project/components/temp/ast_inlines.hpp
Normal file
179
project/components/temp/ast_inlines.hpp
Normal file
@ -0,0 +1,179 @@
|
||||
// This is the non-bootstraped version of the Common AST Implementation. This will be obsolete once bootstrap is stress tested.
|
||||
|
||||
#pragma region AST Common
|
||||
|
||||
#define Define_CodeImpl( Typename ) \
|
||||
char const* Typename::debug_str() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
return "Code::debug_str: AST is null!"; \
|
||||
\
|
||||
return rcast(AST*, ast)->debug_str(); \
|
||||
} \
|
||||
Code Typename::duplicate() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); \
|
||||
return Code::Invalid; \
|
||||
} \
|
||||
\
|
||||
return { rcast(AST*, ast)->duplicate() }; \
|
||||
} \
|
||||
bool Typename::is_equal( Code other ) \
|
||||
{ \
|
||||
if ( ast == nullptr || other.ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::is_equal: Cannot compare code, AST is null!"); \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->is_equal( other.ast ); \
|
||||
} \
|
||||
bool Typename::is_valid() \
|
||||
{ \
|
||||
return (AST*) ast != nullptr && rcast( AST*, ast)->Type != CodeT::Invalid; \
|
||||
} \
|
||||
void Typename::set_global() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::set_global: Cannot set code as global, AST is null!"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
rcast(AST*, ast)->Parent = Code::Global.ast; \
|
||||
} \
|
||||
String Typename::to_string() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::to_string: Cannot convert code to string, AST is null!"); \
|
||||
return { nullptr }; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->to_string(); \
|
||||
} \
|
||||
Typename& Typename::operator =( Code other ) \
|
||||
{ \
|
||||
if ( other.ast && other->Parent ) \
|
||||
{ \
|
||||
ast = rcast( decltype(ast), other.ast->duplicate() ); \
|
||||
rcast( AST*, ast)->Parent = nullptr; \
|
||||
} \
|
||||
\
|
||||
ast = rcast( decltype(ast), other.ast ); \
|
||||
return *this; \
|
||||
} \
|
||||
bool Typename::operator ==( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast == other.ast; \
|
||||
} \
|
||||
bool Typename::operator !=( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast != other.ast; \
|
||||
} \
|
||||
Typename::operator bool() \
|
||||
{ \
|
||||
return ast != nullptr; \
|
||||
}
|
||||
|
||||
Define_CodeImpl( Code );
|
||||
Define_CodeImpl( CodeBody );
|
||||
Define_CodeImpl( CodeAttributes );
|
||||
Define_CodeImpl( CodeComment );
|
||||
Define_CodeImpl( CodeClass );
|
||||
Define_CodeImpl( CodeDefine );
|
||||
Define_CodeImpl( CodeEnum );
|
||||
Define_CodeImpl( CodeExec );
|
||||
Define_CodeImpl( CodeExtern );
|
||||
Define_CodeImpl( CodeInclude );
|
||||
Define_CodeImpl( CodeFriend );
|
||||
Define_CodeImpl( CodeFn );
|
||||
Define_CodeImpl( CodeModule );
|
||||
Define_CodeImpl( CodeNamespace );
|
||||
Define_CodeImpl( CodeOperator );
|
||||
Define_CodeImpl( CodeOpCast );
|
||||
Define_CodeImpl( CodeParam );
|
||||
Define_CodeImpl( CodePragma );
|
||||
Define_CodeImpl( CodePreprocessCond );
|
||||
Define_CodeImpl( CodeSpecifiers );
|
||||
Define_CodeImpl( CodeStruct );
|
||||
Define_CodeImpl( CodeTemplate );
|
||||
Define_CodeImpl( CodeType );
|
||||
Define_CodeImpl( CodeTypedef );
|
||||
Define_CodeImpl( CodeUnion );
|
||||
Define_CodeImpl( CodeUsing );
|
||||
Define_CodeImpl( CodeVar );
|
||||
#undef Define_CodeImpl
|
||||
|
||||
#define Define_AST_Cast( typename ) \
|
||||
AST::operator Code ## typename() \
|
||||
{ \
|
||||
return { rcast( AST_ ## typename*, this ) }; \
|
||||
}
|
||||
|
||||
Define_AST_Cast( Body );
|
||||
Define_AST_Cast( Attributes );
|
||||
Define_AST_Cast( Comment );
|
||||
Define_AST_Cast( Class );
|
||||
Define_AST_Cast( Define );
|
||||
Define_AST_Cast( Enum );
|
||||
Define_AST_Cast( Exec );
|
||||
Define_AST_Cast( Extern );
|
||||
Define_AST_Cast( Include );
|
||||
Define_AST_Cast( Friend );
|
||||
Define_AST_Cast( Fn );
|
||||
Define_AST_Cast( Module );
|
||||
Define_AST_Cast( Namespace );
|
||||
Define_AST_Cast( Operator );
|
||||
Define_AST_Cast( OpCast );
|
||||
Define_AST_Cast( Param );
|
||||
Define_AST_Cast( Pragma );
|
||||
Define_AST_Cast( PreprocessCond );
|
||||
Define_AST_Cast( Struct );
|
||||
Define_AST_Cast( Specifiers );
|
||||
Define_AST_Cast( Template );
|
||||
Define_AST_Cast( Type );
|
||||
Define_AST_Cast( Typedef );
|
||||
Define_AST_Cast( Union );
|
||||
Define_AST_Cast( Using );
|
||||
Define_AST_Cast( Var );
|
||||
#undef Define_AST_Cast
|
||||
|
||||
#define Define_CodeCast( type ) \
|
||||
Code::operator Code ## type() const \
|
||||
{ \
|
||||
return { (AST_ ## type*) ast }; \
|
||||
}
|
||||
|
||||
Define_CodeCast( Attributes );
|
||||
Define_CodeCast( Comment );
|
||||
Define_CodeCast( Class );
|
||||
Define_CodeCast( Define );
|
||||
Define_CodeCast( Exec );
|
||||
Define_CodeCast( Enum );
|
||||
Define_CodeCast( Extern );
|
||||
Define_CodeCast( Include );
|
||||
Define_CodeCast( Friend );
|
||||
Define_CodeCast( Fn );
|
||||
Define_CodeCast( Module );
|
||||
Define_CodeCast( Namespace );
|
||||
Define_CodeCast( Operator );
|
||||
Define_CodeCast( OpCast );
|
||||
Define_CodeCast( Param );
|
||||
Define_CodeCast( Pragma );
|
||||
Define_CodeCast( PreprocessCond );
|
||||
Define_CodeCast( Specifiers );
|
||||
Define_CodeCast( Struct );
|
||||
Define_CodeCast( Template );
|
||||
Define_CodeCast( Type );
|
||||
Define_CodeCast( Typedef );
|
||||
Define_CodeCast( Union );
|
||||
Define_CodeCast( Using );
|
||||
Define_CodeCast( Var );
|
||||
Define_CodeCast( Body);
|
||||
#undef Define_CodeCast
|
||||
|
||||
#pragma endregion AST Common
|
||||
|
@ -84,3 +84,4 @@ namespace ECode
|
||||
# undef Define_Types
|
||||
}
|
||||
using CodeT = ECode::Type;
|
||||
|
@ -73,3 +73,4 @@ namespace EOperator
|
||||
# undef Define_Operators
|
||||
}
|
||||
using OperatorT = EOperator::Type;
|
||||
|
@ -106,3 +106,4 @@ namespace ESpecifier
|
||||
# undef Define_Specifiers
|
||||
}
|
||||
using SpecifierT = ESpecifier::Type;
|
||||
|
@ -162,3 +162,4 @@ namespace Parser
|
||||
using TokType = ETokType::Type;
|
||||
|
||||
} // Parser
|
||||
|
@ -113,4 +113,13 @@ constexpr char const* Attribute_Keyword = stringize( GEN_Attribute_Keyword );
|
||||
#endif
|
||||
|
||||
constexpr char const* Attribute_Keyword = "";
|
||||
|
||||
#endif
|
||||
|
||||
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||
using StringTable = HashTable<String const>;
|
||||
|
||||
// Represents strings cached with the string table.
|
||||
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
||||
using StringCached = String const;
|
||||
|
||||
|
@ -181,3 +181,4 @@ Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -118,3 +118,4 @@ typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
|
||||
#pragma region Basic Types
|
||||
|
||||
|
@ -533,3 +533,4 @@ protected:
|
||||
};
|
||||
|
||||
#pragma endregion Containers
|
||||
|
||||
|
@ -39,3 +39,4 @@ s32 assert_crash( char const* condition )
|
||||
#endif
|
||||
|
||||
#pragma endregion Debug
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#pragma endregion Debug
|
||||
#pragma region Debug
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# if _MSC_VER < 1300
|
||||
@ -34,3 +34,4 @@ s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
|
||||
#pragma endregion Debug
|
||||
|
||||
|
@ -634,3 +634,4 @@ internal GEN_FILE_CLOSE_PROC( _memory_file_close )
|
||||
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };
|
||||
|
||||
#pragma endregion File Handling
|
||||
|
||||
|
@ -370,3 +370,4 @@ u8* file_stream_buf( FileInfo* file, sw* size );
|
||||
extern FileOperations const memory_file_operations;
|
||||
|
||||
#pragma endregion File Handling
|
||||
|
||||
|
@ -83,3 +83,4 @@ u64 crc64( void const* data, sw len )
|
||||
}
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
|
@ -4,3 +4,4 @@ u32 crc32( void const* data, sw len );
|
||||
u64 crc64( void const* data, sw len );
|
||||
|
||||
#pragma endregion Hashing
|
||||
|
||||
|
@ -122,10 +122,21 @@
|
||||
#pragma endregion Platform Detection
|
||||
|
||||
#pragma region Mandatory Includes
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <stddef.h>
|
||||
|
||||
# if defined( GEN_SYSTEM_WINDOWS )
|
||||
# include <intrin.h>
|
||||
# endif
|
||||
|
||||
#pragma endregion Mandatory Includes
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
|
||||
|
||||
// Casting
|
||||
|
||||
#define ccast( Type, Value ) ( * const_cast< Type* >( & (Value) ) )
|
||||
#define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) )
|
||||
#define rcast( Type, Value ) reinterpret_cast< Type >( Value )
|
||||
@ -21,36 +22,43 @@
|
||||
|
||||
// Num Arguments (Varadics)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
// Supports 0-10 arguments
|
||||
// Supports 0-50 arguments
|
||||
#define num_args_impl( _0, \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
N, ... \
|
||||
) N
|
||||
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,
|
||||
|
||||
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
|
||||
#define num_args(...) \
|
||||
num_args_impl(_, ## __VA_ARGS__, \
|
||||
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
|
||||
0 \
|
||||
)
|
||||
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
|
||||
|
||||
#else
|
||||
// Supports 1-10 arguments
|
||||
// Supports 1-50 arguments
|
||||
#define num_args_impl( \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
N, ... \
|
||||
) N
|
||||
|
||||
#define num_args(...) \
|
||||
num_args_impl( __VA_ARGS__, \
|
||||
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
|
||||
)
|
||||
@ -105,3 +113,4 @@ void swap( Type& a, Type& b )
|
||||
}
|
||||
|
||||
#pragma endregion Macros
|
||||
|
||||
|
@ -387,3 +387,4 @@ void Pool::clear()
|
||||
}
|
||||
|
||||
#pragma endregion Memory
|
||||
|
||||
|
@ -484,3 +484,4 @@ struct Pool
|
||||
};
|
||||
|
||||
#pragma endregion Memory
|
||||
|
||||
|
@ -1104,3 +1104,4 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
||||
}
|
||||
|
||||
#pragma endregion CSV
|
||||
|
||||
|
@ -423,3 +423,4 @@ GEN_IMPL_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||
}
|
||||
|
||||
#pragma endregion CSV
|
||||
|
||||
|
@ -562,3 +562,4 @@ sw str_fmt_out_err( char const* fmt, ... )
|
||||
}
|
||||
|
||||
#pragma endregion Printing
|
||||
|
||||
|
@ -13,9 +13,6 @@ sw str_fmt_va ( char* str, sw n, char const* fmt, va_list va );
|
||||
sw str_fmt_out_va ( char const* fmt, va_list va );
|
||||
sw str_fmt_out_err ( char const* fmt, ... );
|
||||
sw str_fmt_out_err_va( char const* fmt, va_list va );
|
||||
|
||||
// TODO : Move these to file handling.
|
||||
|
||||
sw str_fmt_file ( FileInfo* f, char const* fmt, ... );
|
||||
sw str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
|
||||
|
||||
|
@ -78,3 +78,4 @@
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros and Includes
|
||||
|
@ -37,3 +37,4 @@ bool String::append_fmt( char const* fmt, ... )
|
||||
}
|
||||
|
||||
#pragma endregion String
|
||||
|
||||
|
@ -373,3 +373,4 @@ struct String_POD
|
||||
static_assert( sizeof( String_POD ) == sizeof( String ), "String is not a POD" );
|
||||
|
||||
#pragma endregion String
|
||||
|
||||
|
@ -207,3 +207,4 @@ f64 str_to_f64( const char* str, char** end_ptr )
|
||||
}
|
||||
|
||||
#pragma endregion String Ops
|
||||
|
||||
|
@ -260,3 +260,4 @@ GEN_IMPL_INLINE void str_to_upper( char* str )
|
||||
}
|
||||
|
||||
#pragma endregion String Ops
|
||||
|
||||
|
@ -160,3 +160,4 @@
|
||||
#endif
|
||||
|
||||
#pragma endregion Timing
|
||||
|
||||
|
@ -12,3 +12,4 @@ u64 time_rel_ms( void );
|
||||
#endif
|
||||
|
||||
#pragma endregion Timing
|
||||
|
||||
|
@ -1,3 +1,25 @@
|
||||
Builder Builder::open( char const* path )
|
||||
{
|
||||
Builder result;
|
||||
|
||||
FileError error = file_open_mode( & result.File, EFileMode_WRITE, path );
|
||||
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
log_failure( "gen::File::open - Could not open file: %s", path);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Builder::pad_lines( s32 num )
|
||||
{
|
||||
Buffer.append( "\n" );
|
||||
}
|
||||
|
||||
void Builder::print( Code code )
|
||||
{
|
||||
Buffer.append( code->to_string() );
|
||||
@ -16,21 +38,6 @@ void Builder::print_fmt( char const* fmt, ... )
|
||||
Buffer.append( buf, res );
|
||||
}
|
||||
|
||||
bool Builder::open( char const* path )
|
||||
{
|
||||
FileError error = file_open_mode( & File, EFileMode_WRITE, path );
|
||||
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
log_failure( "gen::File::open - Could not open file: %s", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Builder::write()
|
||||
{
|
||||
bool result = file_write( & File, Buffer, Buffer.length() );
|
||||
|
@ -3,9 +3,12 @@ struct Builder
|
||||
FileInfo File;
|
||||
String Buffer;
|
||||
|
||||
static Builder open( char const* path );
|
||||
|
||||
void pad_lines( s32 num );
|
||||
|
||||
void print( Code );
|
||||
void print_fmt( char const* fmt, ... );
|
||||
|
||||
bool open( char const* path );
|
||||
void write();
|
||||
};
|
||||
|
@ -2,32 +2,22 @@
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
#include "file_processors/scanner.hpp"
|
||||
|
||||
#include "helpers/helper.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.cpp"
|
||||
GEN_NS_END
|
||||
|
||||
#include "file_processors/builder.hpp"
|
||||
#include "file_processors/builder.cpp"
|
||||
#include "file_processors/scanner.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
bool namespace_by_default = true;
|
||||
|
||||
constexpr StrC nspace_default = txt_StrC(R"(
|
||||
#if defined(GEN_DONT_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#elif ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
)");
|
||||
|
||||
constexpr StrC nspace_non_default = txt_StrC(R"(
|
||||
#if ! defined(GEN_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#elif ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
)");
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gen.bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
@ -39,7 +29,6 @@ int gen_main()
|
||||
// gen_dep.hpp
|
||||
{
|
||||
Code header_start = scan_file( "dependencies/header_start.hpp" );
|
||||
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
|
||||
Code macros = scan_file( "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( "dependencies/debug.hpp" );
|
||||
@ -49,118 +38,114 @@ int gen_main()
|
||||
Code containers = scan_file( "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.hpp" );
|
||||
Code string = scan_file( "dependencies/string.hpp" );
|
||||
Code parsing = scan_file( "dependencies/parsing.hpp" );
|
||||
Code file_handling = scan_file( "dependencies/file_handling.hpp" );
|
||||
Code timing = scan_file( "dependencies/timing.hpp" );
|
||||
|
||||
// TOOD : Make this optional
|
||||
Code file_handling = scan_file( "dependencies/file_handling.hpp" );
|
||||
|
||||
Builder
|
||||
deps_header;
|
||||
deps_header.open("gen/gen_dep.hpp");
|
||||
deps_header.print_fmt("// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n\n");
|
||||
deps_header.print_fmt("#pragma once\n\n");
|
||||
deps_header.print( header_start );
|
||||
deps_header.print( nspace_macro );
|
||||
deps_header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
deps_header = Builder::open("gen/gen_dep.hpp");
|
||||
deps_header.print_fmt( generation_notice );
|
||||
deps_header.print_fmt("// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n\n");
|
||||
deps_header.print_fmt("#pragma once\n\n");
|
||||
deps_header.print( header_start );
|
||||
deps_header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
|
||||
deps_header.print( macros );
|
||||
deps_header.print( basic_types );
|
||||
deps_header.print( debug );
|
||||
deps_header.print( memory );
|
||||
deps_header.print( string_ops );
|
||||
deps_header.print( printing );
|
||||
deps_header.print( containers );
|
||||
deps_header.print( hashing );
|
||||
deps_header.print( string );
|
||||
deps_header.print( file_handling );
|
||||
deps_header.print( parsing );
|
||||
deps_header.print( timing );
|
||||
deps_header.print( macros );
|
||||
deps_header.print( basic_types );
|
||||
deps_header.print( debug );
|
||||
deps_header.print( memory );
|
||||
deps_header.print( string_ops );
|
||||
deps_header.print( printing );
|
||||
deps_header.print( containers );
|
||||
deps_header.print( hashing );
|
||||
deps_header.print( string );
|
||||
deps_header.print( file_handling );
|
||||
deps_header.print( timing );
|
||||
|
||||
deps_header.print_fmt( "GEN_NS_END\n\n");
|
||||
deps_header.print_fmt( "GEN_NS_END\n\n");
|
||||
deps_header.write();
|
||||
}
|
||||
|
||||
// gen_dep.cpp
|
||||
{
|
||||
CodeInclude header = def_include( txt_StrC("gen_dep.hpp") );
|
||||
Code impl_start = scan_file( "dependencies/impl_start.cpp" );
|
||||
Code debug = scan_file( "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( "dependencies/memory.cpp" );
|
||||
Code parsing = scan_file( "dependencies/parsing.cpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.cpp" );
|
||||
Code string = scan_file( "dependencies/string.cpp" );
|
||||
Code timing = scan_file( "dependencies/timing.cpp" );
|
||||
Code src_start = scan_file( "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.cpp" );
|
||||
Code string = scan_file( "dependencies/string.cpp" );
|
||||
Code file_handling = scan_file( "dependencies/file_handling.cpp" );
|
||||
Code timing = scan_file( "dependencies/timing.cpp" );
|
||||
|
||||
Builder
|
||||
deps_impl;
|
||||
deps_impl.open("gen/gen_dep.cpp");
|
||||
deps_impl.print_fmt("// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n\n");
|
||||
deps_impl.print( impl_start );
|
||||
deps_impl.print( header );
|
||||
deps_impl.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
deps_impl = Builder::open("gen/gen_dep.cpp");
|
||||
deps_impl.print_fmt( generation_notice );
|
||||
deps_impl.print_fmt("// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n\n");
|
||||
deps_impl.print( src_start );
|
||||
deps_impl.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
|
||||
deps_impl.print( debug );
|
||||
deps_impl.print( string_ops );
|
||||
deps_impl.print( printing );
|
||||
deps_impl.print( hashing );
|
||||
deps_impl.print( memory );
|
||||
deps_impl.print( parsing );
|
||||
deps_impl.print( string );
|
||||
deps_impl.print( timing );
|
||||
deps_impl.print( debug );
|
||||
deps_impl.print( string_ops );
|
||||
deps_impl.print( printing );
|
||||
deps_impl.print( hashing );
|
||||
deps_impl.print( memory );
|
||||
deps_impl.print( string );
|
||||
deps_impl.print( file_handling );
|
||||
deps_impl.print( timing );
|
||||
|
||||
deps_impl.print_fmt( "GEN_NS_END\n\n");
|
||||
deps_impl.print_fmt( "GEN_NS_END\n\n");
|
||||
deps_impl.write();
|
||||
}
|
||||
|
||||
// gen.hpp
|
||||
{
|
||||
Code header_start = scan_file( "components/header_start.hpp" );
|
||||
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
|
||||
Code types = scan_file( "components/types.hpp" );
|
||||
Code data_structs = scan_file( "components/data_structures.hpp" );
|
||||
Code ast = scan_file( "components/ast.hpp" );
|
||||
Code ast_types = scan_file( "components/ast_types.hpp" );
|
||||
Code interface = scan_file( "components/interface.hpp" );
|
||||
Code inlines = scan_file( "components/inlines.hpp" );
|
||||
Code ast_inlines = scan_file( "components/temp/ast_inlines.hpp" );
|
||||
Code header_end = scan_file( "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode( "enums/ECode.csv" );
|
||||
CodeBody eoperator = gen_eoperator( "enums/EOperator.csv" );
|
||||
CodeBody ecode = gen_ecode ( "enums/ECode.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" );
|
||||
|
||||
// TODO : Make this optional to include
|
||||
Code builder = scan_file( "file_processors/builder.hpp" );
|
||||
|
||||
Builder
|
||||
header;
|
||||
header.open( "gen/gen.hpp" );
|
||||
header.print_fmt("#pragma once\n\n");
|
||||
header.print( push_ignores );
|
||||
header.print( header_start );
|
||||
header.print( nspace_macro );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
header = Builder::open( "gen/gen.hpp" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt("#pragma once\n\n");
|
||||
header.print( push_ignores );
|
||||
header.print( header_start );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
|
||||
header.print_fmt("#pragma region Types\n\n");
|
||||
header.print( types );
|
||||
header.print( ecode );
|
||||
header.print( eoperator );
|
||||
header.print( especifier );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
header.print_fmt("#pragma region Types\n\n");
|
||||
header.print( types );
|
||||
header.print( ecode );
|
||||
header.print( eoperator );
|
||||
header.print( especifier );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
header.print( data_structs );
|
||||
header.print( interface );
|
||||
header.print( header_end );
|
||||
header.print_fmt("#pragma region AST\n\n");
|
||||
header.print( ast );
|
||||
header.print( ast_types );
|
||||
header.print_fmt("#pragma endregion AST\n\n");
|
||||
|
||||
header.print( builder );
|
||||
header.print( interface );
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n\n");
|
||||
header.print( pop_ignores );
|
||||
header.print( inlines );
|
||||
header.print( ast_inlines );
|
||||
|
||||
header.print( header_end );
|
||||
header.print_fmt( "GEN_NS_END\n\n");
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen.cpp
|
||||
{
|
||||
Code impl_start = scan_file( "components/impl_start.cpp" );
|
||||
Code src_start = scan_file( "components/src_start.cpp" );
|
||||
CodeInclude header = def_include( txt_StrC("gen.hpp") );
|
||||
Code data = scan_file( "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" );
|
||||
@ -170,33 +155,60 @@ int gen_main()
|
||||
Code parsing = scan_file( "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( "components/untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
|
||||
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
|
||||
CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
|
||||
|
||||
// TODO : Make this optional to include
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( push_ignores );
|
||||
src.print( src_start );
|
||||
src.print( header );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n\n");
|
||||
|
||||
src.print( data );
|
||||
src.print( ast_case_macros );
|
||||
src.print( ast );
|
||||
src.print( interface );
|
||||
src.print( upfront );
|
||||
src.print( parser_nspace );
|
||||
src.print( parsing );
|
||||
src.print( untyped );
|
||||
|
||||
src.print_fmt( "GEN_NS_END\n\n");
|
||||
src.print( pop_ignores );
|
||||
src.write();
|
||||
}
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.hpp" );
|
||||
Code builder = scan_file( "file_processors/builder.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen_builder.hpp" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print( def_include( txt_StrC("gen.hpp") ));
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n\n" );
|
||||
header.print( parsing );
|
||||
header.print( builder );
|
||||
header.print_fmt( "\nGEN_NS_END\n\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.cpp" );
|
||||
Code builder = scan_file( "file_processors/builder.cpp" );
|
||||
|
||||
Builder
|
||||
impl;
|
||||
impl.open( "gen/gen.cpp" );
|
||||
impl.print( push_ignores );
|
||||
impl.print( impl_start );
|
||||
impl.print( header );
|
||||
impl.print_fmt( "\nGEN_NS_BEGIN\n\n");
|
||||
|
||||
impl.print( data );
|
||||
impl.print( ast_case_macros );
|
||||
impl.print( ast );
|
||||
impl.print( interface );
|
||||
impl.print( upfront );
|
||||
impl.print( parser_nspace );
|
||||
impl.print( parsing );
|
||||
impl.print( untyped );
|
||||
|
||||
impl.print( builder );
|
||||
impl.print_fmt( "GEN_NS_END\n\n");
|
||||
impl.print( pop_ignores );
|
||||
impl.write();
|
||||
src = Builder::open( "gen/gen_builder.cpp" );
|
||||
src.print( def_include( txt_StrC("gen_builder.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n\n" );
|
||||
src.print( parsing );
|
||||
src.print( builder );
|
||||
src.print_fmt( "\nGEN_NS_END\n\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
gen::deinit();
|
||||
|
@ -23,12 +23,10 @@ GEN_NS_BEGIN
|
||||
|
||||
#include "components/interface.cpp"
|
||||
#include "components/interface.upfront.cpp"
|
||||
#include "components/etoktype.cpp"
|
||||
#include "components/temp/etoktype.cpp"
|
||||
#include "components/interface.parsing.cpp"
|
||||
#include "components/untyped.cpp"
|
||||
|
||||
#include "file_processors/builder.cpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
#include "helpers/pop_ignores.inline.hpp"
|
||||
|
@ -1,17 +1,19 @@
|
||||
// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)
|
||||
#include "gen.dep.hpp"
|
||||
|
||||
#include "dependencies/impl_start.cpp"
|
||||
#include "dependencies/src_start.cpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "dependencies/debug.cpp"
|
||||
|
||||
#include "dependencies/string_ops.cpp"
|
||||
#include "dependencies/printing.cpp"
|
||||
#include "dependencies/memory.cpp"
|
||||
#include "dependencies/parsing.cpp"
|
||||
|
||||
#include "dependencies/hashing.cpp"
|
||||
#include "dependencies/string.cpp"
|
||||
|
||||
#include "dependencies/timing.cpp"
|
||||
|
||||
#include "dependencies/file_handling.cpp"
|
||||
|
@ -3,26 +3,20 @@
|
||||
|
||||
#include "dependencies/header_start.hpp"
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "dependencies/macros.hpp"
|
||||
#include "dependencies/basic_types.hpp"
|
||||
#include "dependencies/debug.hpp"
|
||||
|
||||
#include "dependencies/memory.hpp"
|
||||
#include "dependencies/string_ops.hpp"
|
||||
#include "dependencies/printing.hpp"
|
||||
|
||||
#include "dependencies/containers.hpp"
|
||||
#include "dependencies/hashing.hpp"
|
||||
#include "dependencies/string.hpp"
|
||||
#include "dependencies/parsing.hpp"
|
||||
|
||||
#include "dependencies/timing.hpp"
|
||||
|
||||
#include "dependencies/file_handling.hpp"
|
||||
|
@ -11,25 +11,21 @@
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "components/header_start.hpp"
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "components/types.hpp"
|
||||
#include "components/ecode.hpp"
|
||||
#include "components/eoperator.hpp"
|
||||
#include "components/especifier.hpp"
|
||||
#include "components/data_structures.hpp"
|
||||
#include "components/interface.hpp"
|
||||
#include "components/header_end.hpp"
|
||||
#include "components/temp/ecode.hpp"
|
||||
#include "components/temp/eoperator.hpp"
|
||||
#include "components/temp/especifier.hpp"
|
||||
|
||||
#include "file_processors/builder.hpp"
|
||||
#include "components/ast.hpp"
|
||||
#include "components/ast_types.hpp"
|
||||
|
||||
#include "components/interface.hpp"
|
||||
|
||||
#include "components/inlines.hpp"
|
||||
#include "components/temp/ast_inlines.hpp"
|
||||
#include "components/header_end.hpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
|
1159
project/gen/gen_builder.cpp
Normal file
1159
project/gen/gen_builder.cpp
Normal file
File diff suppressed because it is too large
Load Diff
448
project/gen/gen_builder.hpp
Normal file
448
project/gen/gen_builder.hpp
Normal file
@ -0,0 +1,448 @@
|
||||
// This file was generated automatially by gen.bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#pragma region ADT
|
||||
|
||||
enum ADT_Type : u32
|
||||
{
|
||||
EADT_TYPE_UNINITIALISED, /* node was not initialised, this is a programming error! */
|
||||
EADT_TYPE_ARRAY,
|
||||
EADT_TYPE_OBJECT,
|
||||
EADT_TYPE_STRING,
|
||||
EADT_TYPE_MULTISTRING,
|
||||
EADT_TYPE_INTEGER,
|
||||
EADT_TYPE_REAL,
|
||||
};
|
||||
|
||||
enum ADT_Props : u32
|
||||
{
|
||||
EADT_PROPS_NONE,
|
||||
EADT_PROPS_NAN,
|
||||
EADT_PROPS_NAN_NEG,
|
||||
EADT_PROPS_INFINITY,
|
||||
EADT_PROPS_INFINITY_NEG,
|
||||
EADT_PROPS_FALSE,
|
||||
EADT_PROPS_TRUE,
|
||||
EADT_PROPS_NULL,
|
||||
EADT_PROPS_IS_EXP,
|
||||
EADT_PROPS_IS_HEX,
|
||||
|
||||
// Used internally so that people can fill in real numbers they plan to write.
|
||||
EADT_PROPS_IS_PARSED_REAL,
|
||||
};
|
||||
|
||||
enum ADT_NamingStyle : u32
|
||||
{
|
||||
EADT_NAME_STYLE_DOUBLE_QUOTE,
|
||||
EADT_NAME_STYLE_SINGLE_QUOTE,
|
||||
EADT_NAME_STYLE_NO_QUOTES,
|
||||
};
|
||||
|
||||
enum ADT_AssignStyle : u32
|
||||
{
|
||||
EADT_ASSIGN_STYLE_COLON,
|
||||
EADT_ASSIGN_STYLE_EQUALS,
|
||||
EADT_ASSIGN_STYLE_LINE,
|
||||
};
|
||||
|
||||
enum ADT_DelimStyle : u32
|
||||
{
|
||||
EADT_DELIM_STYLE_COMMA,
|
||||
EADT_DELIM_STYLE_LINE,
|
||||
EADT_DELIM_STYLE_NEWLINE,
|
||||
};
|
||||
|
||||
enum ADT_Error : u32
|
||||
{
|
||||
EADT_ERROR_NONE,
|
||||
EADT_ERROR_INTERNAL,
|
||||
EADT_ERROR_ALREADY_CONVERTED,
|
||||
EADT_ERROR_INVALID_TYPE,
|
||||
EADT_ERROR_OUT_OF_MEMORY,
|
||||
};
|
||||
|
||||
struct ADT_Node
|
||||
{
|
||||
char const* name;
|
||||
struct ADT_Node* parent;
|
||||
|
||||
/* properties */
|
||||
ADT_Type type : 4;
|
||||
u8 props : 4;
|
||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||
u8 cfg_mode : 1;
|
||||
u8 name_style : 2;
|
||||
u8 assign_style : 2;
|
||||
u8 delim_style : 2;
|
||||
u8 delim_line_width : 4;
|
||||
u8 assign_line_width : 4;
|
||||
#endif
|
||||
|
||||
/* adt data */
|
||||
union
|
||||
{
|
||||
char const* string;
|
||||
Array< ADT_Node > nodes; ///< zpl_array
|
||||
|
||||
struct
|
||||
{
|
||||
union
|
||||
{
|
||||
f64 real;
|
||||
s64 integer;
|
||||
};
|
||||
|
||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||
/* number analysis */
|
||||
s32 base;
|
||||
s32 base2;
|
||||
u8 base2_offset : 4;
|
||||
s8 exp : 4;
|
||||
u8 neg_zero : 1;
|
||||
u8 lead_digit : 1;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/* ADT NODE LIMITS
|
||||
* delimiter and assignment segment width is limited to 128 whitespace symbols each.
|
||||
* real number limits decimal position to 128 places.
|
||||
* real number exponent is limited to 64 digits.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialise an ADT object or array
|
||||
*
|
||||
* @param node
|
||||
* @param backing Memory allocator used for descendants
|
||||
* @param name Node's name
|
||||
* @param is_array
|
||||
* @return error code
|
||||
*/
|
||||
u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32 is_array );
|
||||
|
||||
/**
|
||||
* @brief Destroy an ADT branch and its descendants
|
||||
*
|
||||
* @param node
|
||||
* @return error code
|
||||
*/
|
||||
u8 adt_destroy_branch( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Initialise an ADT leaf
|
||||
*
|
||||
* @param node
|
||||
* @param name Node's name
|
||||
* @param type Node's type (use zpl_adt_make_branch for container nodes)
|
||||
* @return error code
|
||||
*/
|
||||
u8 adt_make_leaf( ADT_Node* node, char const* name, ADT_Type type );
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fetch a node using provided URI string.
|
||||
*
|
||||
* This method uses a basic syntax to fetch a node from the ADT. The following features are available
|
||||
* to retrieve the data:
|
||||
*
|
||||
* - "a/b/c" navigates through objects "a" and "b" to get to "c"
|
||||
* - "arr/[foo=123]/bar" iterates over "arr" to find any object with param "foo" that matches the value "123", then gets its field called "bar"
|
||||
* - "arr/3" retrieves the 4th element in "arr"
|
||||
* - "arr/[apple]" retrieves the first element of value "apple" in "arr"
|
||||
*
|
||||
* @param node ADT node
|
||||
* @param uri Locator string as described above
|
||||
* @return zpl_adt_node*
|
||||
*
|
||||
* @see code/apps/examples/json_get.c
|
||||
*/
|
||||
ADT_Node* adt_query( ADT_Node* node, char const* uri );
|
||||
|
||||
/**
|
||||
* @brief Find a field node within an object by the given name.
|
||||
*
|
||||
* @param node
|
||||
* @param name
|
||||
* @param deep_search Perform search recursively
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search );
|
||||
|
||||
/**
|
||||
* @brief Allocate an unitialised node within a container at a specified index.
|
||||
*
|
||||
* @param parent
|
||||
* @param index
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_alloc_at( ADT_Node* parent, sw index );
|
||||
|
||||
/**
|
||||
* @brief Allocate an unitialised node within a container.
|
||||
*
|
||||
* @param parent
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_alloc( ADT_Node* parent );
|
||||
|
||||
/**
|
||||
* @brief Move an existing node to a new container at a specified index.
|
||||
*
|
||||
* @param node
|
||||
* @param new_parent
|
||||
* @param index
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, sw index );
|
||||
|
||||
/**
|
||||
* @brief Move an existing node to a new container.
|
||||
*
|
||||
* @param node
|
||||
* @param new_parent
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent );
|
||||
|
||||
/**
|
||||
* @brief Swap two nodes.
|
||||
*
|
||||
* @param node
|
||||
* @param other_node
|
||||
* @return
|
||||
*/
|
||||
void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node );
|
||||
|
||||
/**
|
||||
* @brief Remove node from container.
|
||||
*
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
void adt_remove_node( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as an object
|
||||
*
|
||||
* @param obj
|
||||
* @param name
|
||||
* @param backing
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as an array
|
||||
*
|
||||
* @param obj
|
||||
* @param name
|
||||
* @param backing
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_arr( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as a string
|
||||
*
|
||||
* @param obj
|
||||
* @param name
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_str( ADT_Node* obj, char const* name, char const* value );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as a float
|
||||
*
|
||||
* @param obj
|
||||
* @param name
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_flt( ADT_Node* obj, char const* name, f64 value );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as a signed integer
|
||||
*
|
||||
* @param obj
|
||||
* @param name
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_int( ADT_Node* obj, char const* name, s64 value );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as an object
|
||||
*
|
||||
* @param parent
|
||||
* @param name
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_obj( ADT_Node* parent, char const* name );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as an array
|
||||
*
|
||||
* @param parent
|
||||
* @param name
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_arr( ADT_Node* parent, char const* name );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as a string
|
||||
*
|
||||
* @param parent
|
||||
* @param name
|
||||
* @param value
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_str( ADT_Node* parent, char const* name, char const* value );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as a float
|
||||
*
|
||||
* @param parent
|
||||
* @param name
|
||||
* @param value
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_flt( ADT_Node* parent, char const* name, f64 value );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as a signed integer
|
||||
*
|
||||
* @param parent
|
||||
* @param name
|
||||
* @param value
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_int( ADT_Node* parent, char const* name, s64 value );
|
||||
|
||||
/* parser helpers */
|
||||
|
||||
/**
|
||||
* @brief Parses a text and stores the result into an unitialised node.
|
||||
*
|
||||
* @param node
|
||||
* @param base
|
||||
* @return*
|
||||
*/
|
||||
char* adt_parse_number( ADT_Node* node, char* base );
|
||||
|
||||
/**
|
||||
* @brief Parses a text and stores the result into an unitialised node.
|
||||
* This function expects the entire input to be a number.
|
||||
*
|
||||
* @param node
|
||||
* @param base
|
||||
* @return*
|
||||
*/
|
||||
char* adt_parse_number_strict( ADT_Node* node, char* base_str );
|
||||
|
||||
/**
|
||||
* @brief Parses and converts an existing string node into a number.
|
||||
*
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_str_to_number( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Parses and converts an existing string node into a number.
|
||||
* This function expects the entire input to be a number.
|
||||
*
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_str_to_number_strict( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Prints a number into a file stream.
|
||||
*
|
||||
* The provided file handle can also be a memory mapped stream.
|
||||
*
|
||||
* @see zpl_file_stream_new
|
||||
* @param file
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_print_number( FileInfo* file, ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Prints a string into a file stream.
|
||||
*
|
||||
* The provided file handle can also be a memory mapped stream.
|
||||
*
|
||||
* @see zpl_file_stream_new
|
||||
* @param file
|
||||
* @param node
|
||||
* @param escaped_chars
|
||||
* @param escape_symbol
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_chars, char const* escape_symbol );
|
||||
|
||||
#pragma endregion ADT
|
||||
|
||||
#pragma region CSV
|
||||
|
||||
enum CSV_Error : u32
|
||||
{
|
||||
ECSV_Error__NONE,
|
||||
ECSV_Error__INTERNAL,
|
||||
ECSV_Error__UNEXPECTED_END_OF_INPUT,
|
||||
ECSV_Error__MISMATCHED_ROWS,
|
||||
};
|
||||
|
||||
typedef ADT_Node CSV_Object;
|
||||
|
||||
GEN_DEF_INLINE u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header );
|
||||
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim );
|
||||
void csv_free( CSV_Object* obj );
|
||||
|
||||
GEN_DEF_INLINE void csv_write( FileInfo* file, CSV_Object* obj );
|
||||
GEN_DEF_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj );
|
||||
void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
|
||||
String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
|
||||
|
||||
/* inline */
|
||||
|
||||
GEN_IMPL_INLINE u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header )
|
||||
{
|
||||
return csv_parse_delimiter( root, text, allocator, has_header, ',' );
|
||||
}
|
||||
|
||||
GEN_IMPL_INLINE void csv_write( FileInfo* file, CSV_Object* obj )
|
||||
{
|
||||
csv_write_delimiter( file, obj, ',' );
|
||||
}
|
||||
|
||||
GEN_IMPL_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||
{
|
||||
return csv_write_string_delimiter( a, obj, ',' );
|
||||
}
|
||||
|
||||
#pragma endregion CSV
|
||||
|
||||
struct Builder
|
||||
{
|
||||
FileInfo File;
|
||||
String Buffer;
|
||||
|
||||
static Builder open( char const* path );
|
||||
|
||||
void pad_lines( s32 num );
|
||||
|
||||
void print( Code );
|
||||
void print_fmt( char const* fmt, ... );
|
||||
|
||||
void write();
|
||||
};
|
||||
|
||||
GEN_NS_END
|
@ -2,6 +2,10 @@
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.hpp"
|
||||
GEN_NS_END
|
||||
|
||||
using namespace gen;
|
||||
|
||||
CodeBody gen_ecode( char const* path )
|
||||
@ -208,7 +212,7 @@ CodeBody gen_especifier( char const* path )
|
||||
|
||||
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
{
|
||||
char scratch_mem[kilobytes(64)];
|
||||
char scratch_mem[kilobytes(16)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
FileContents enum_content = file_read_contents( scratch, zero_terminate, etok_path );
|
||||
@ -226,10 +230,11 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_attributes = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_attributes = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_define_entries = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
|
||||
for (uw idx = 0; idx < enum_strs.num(); idx++)
|
||||
{
|
||||
@ -247,8 +252,17 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
|
||||
attribute_entries.append_fmt( "%s,\n", attribute_str );
|
||||
to_str_attributes.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
attribute_define_entries.append_fmt( "Entry( %s, %s )", attribute_str, entry_to_str );
|
||||
|
||||
if ( idx < attribute_strs.num() - 1 )
|
||||
attribute_define_entries.append( " \\\n");
|
||||
}
|
||||
|
||||
#pragma push_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" )
|
||||
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
|
||||
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), attribute_define_entries );
|
||||
#pragma pop_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" )
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
@ -308,8 +322,13 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
#pragma pop_macro( "do_once_start" )
|
||||
#pragma pop_macro( "do_once_end" )
|
||||
|
||||
CodeNamespace nspace = def_namespace( name(ETokType), def_namespace_body( args( enum_code, to_str, to_type ) ) );
|
||||
CodeNamespace nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
|
||||
CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, td_toktype ) );
|
||||
}
|
||||
|
||||
CodeBody gen_data_structures( char const* data_path, char const* ast_path )
|
||||
{
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
@ -6,16 +6,22 @@ AlignAfterOpenBracket: BlockIndent
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields: AcrossComments
|
||||
AlignConsecutiveDeclarations: AcrossComments
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AcrossComments: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: DontAlign
|
||||
|
||||
@ -62,7 +68,7 @@ BraceWrapping:
|
||||
BeforeWhile: false
|
||||
|
||||
BreakAfterAttributes: Always
|
||||
# BreakArrays: false
|
||||
BreakArrays: true
|
||||
# BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Allman
|
||||
@ -73,7 +79,7 @@ BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakStringLiterals: true
|
||||
|
||||
ColumnLimit: 120
|
||||
ColumnLimit: 160
|
||||
|
||||
CompactNamespaces: true
|
||||
|
||||
@ -92,7 +98,6 @@ FixNamespaceComments: true
|
||||
|
||||
IncludeBlocks: Preserve
|
||||
|
||||
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: AfterExternBlock
|
||||
@ -128,7 +133,7 @@ SeparateDefinitionBlocks: Always
|
||||
ShortNamespaceLines: 40
|
||||
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: true
|
||||
SortUsingDeclarations: false
|
||||
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: true
|
||||
|
@ -22,7 +22,7 @@ write-host "`n`nBuilding gencpp bootstrap`n"
|
||||
|
||||
if ( -not( Test-Path $path_project_build) )
|
||||
{
|
||||
# Generate build files for meta-program
|
||||
# Generate build files for bootstrap
|
||||
Push-Location $path_project
|
||||
$args_meson = @()
|
||||
$args_meson += "setup"
|
||||
@ -32,7 +32,7 @@ Push-Location $path_project
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Compile meta-program
|
||||
# Compile bootstrap
|
||||
Push-Location $path_root
|
||||
$args_ninja = @()
|
||||
$args_ninja += "-C"
|
||||
@ -42,29 +42,36 @@ Push-Location $path_root
|
||||
Pop-Location
|
||||
|
||||
Push-location $path_project
|
||||
if ( -not(Test-Path($path_project_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_project_gen
|
||||
}
|
||||
if ( -not(Test-Path($path_project_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_project_gen
|
||||
}
|
||||
|
||||
# Run meta-program
|
||||
$gencpp_bootstrap = Join-Path $path_project_build gencpp_bootstrap.exe
|
||||
# Run bootstrap
|
||||
$gencpp_bootstrap = Join-Path $path_project_build gencpp_bootstrap.exe
|
||||
|
||||
Write-Host `nRunning gencpp bootstrap...
|
||||
& $gencpp_bootstrap
|
||||
Write-Host `nRunning gencpp bootstrap...
|
||||
& $gencpp_bootstrap
|
||||
|
||||
# Format generated files
|
||||
Write-Host `nBeginning format...
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:../scripts/.clang-format'
|
||||
'-verbose'
|
||||
)
|
||||
# Format generated gencpp
|
||||
Write-Host `nBeginning format...
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:../scripts/.clang-format'
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
$include = @('gen.hpp', 'gen.cpp', 'gen_dep.hpp', 'gen_dep.cpp')
|
||||
$exclude = $null
|
||||
$include = @(
|
||||
'gen.hpp', 'gen.cpp',
|
||||
'gen_dep.hpp', 'gen_dep.cpp',
|
||||
'gen_builder.hpp', 'gen_builder.cpp'
|
||||
)
|
||||
$exclude = $null
|
||||
|
||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||
|
||||
clang-format $formatParams $targetFiles
|
||||
Write-Host "`nFormatting complete"
|
||||
clang-format $formatParams $targetFiles
|
||||
Write-Host "`nFormatting complete"
|
||||
Pop-Location
|
||||
|
||||
# Build and run validation
|
||||
|
||||
|
@ -42,29 +42,32 @@ Push-Location $path_root
|
||||
Pop-Location
|
||||
|
||||
Push-location $path_singleheader
|
||||
if ( -not(Test-Path($path_singleheader_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_singleheader_gen
|
||||
}
|
||||
if ( -not(Test-Path($path_singleheader_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_singleheader_gen
|
||||
}
|
||||
|
||||
# Run meta-program
|
||||
$gencpp_singleheader = Join-Path $path_singleheader_build gencpp_singleheader.exe
|
||||
# Run meta-program
|
||||
$gencpp_singleheader = Join-Path $path_singleheader_build gencpp_singleheader.exe
|
||||
|
||||
Write-Host `nRunning gencpp singleheader...
|
||||
& $gencpp_singleheader
|
||||
Write-Host `nRunning gencpp singleheader...
|
||||
& $gencpp_singleheader
|
||||
|
||||
# Format generated files
|
||||
Write-Host `nBeginning format...
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:../scripts/.clang-format'
|
||||
'-verbose'
|
||||
)
|
||||
# Format generated files
|
||||
Write-Host `nBeginning format...
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:../scripts/.clang-format'
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
$include = @('gen.hpp')
|
||||
$exclude = $null
|
||||
$include = @('gen.hpp')
|
||||
$exclude = $null
|
||||
|
||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||
|
||||
clang-format $formatParams $targetFiles
|
||||
Write-Host "`nFormatting complete"
|
||||
clang-format $formatParams $targetFiles
|
||||
Write-Host "`nFormatting complete"
|
||||
Pop-Location
|
||||
|
||||
# Build and run validation
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
cls
|
||||
|
||||
[string] $type = $null
|
||||
[string] $test = $false
|
||||
|
||||
|
@ -11,4 +11,13 @@
|
||||
*/
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
|
||||
|
@ -7,27 +7,9 @@
|
||||
|
||||
using namespace gen;
|
||||
|
||||
bool namespace_by_default = true;
|
||||
|
||||
constexpr StrC nspace_default = txt_StrC(R"(
|
||||
#if defined(GEN_DONT_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#elif ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
)");
|
||||
|
||||
constexpr StrC nspace_non_default = txt_StrC(R"(
|
||||
#if ! defined(GEN_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#elif ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
)");
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gen.bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
constexpr StrC implementation_guard_start = txt_StrC(R"(
|
||||
#pragma region GENCPP IMPLEMENTATION GUARD
|
||||
@ -50,9 +32,13 @@ constexpr StrC roll_own_dependencies_guard_start = txt_StrC(R"(
|
||||
constexpr StrC roll_own_dependencies_guard_end = txt_StrC(R"(
|
||||
// GEN_ROLL_OWN_DEPENDENCIES
|
||||
#endif
|
||||
|
||||
)");
|
||||
|
||||
global bool generate_gen_dep = true;
|
||||
global bool generate_builder = true;
|
||||
global bool generate_editor = true;
|
||||
global bool generate_scanner = true;
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
@ -63,11 +49,10 @@ int gen_main()
|
||||
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
||||
|
||||
Code header_start = scan_file( "components/header_start.hpp" );
|
||||
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
|
||||
|
||||
Builder
|
||||
header;
|
||||
header.open( "gen/gen.hpp" );
|
||||
header = Builder::open( "gen/gen.hpp" );
|
||||
header.print( generation_notice );
|
||||
header.print( push_ignores );
|
||||
|
||||
header.print_fmt("#pragma once\n\n");
|
||||
@ -75,8 +60,8 @@ int gen_main()
|
||||
// Headers
|
||||
{
|
||||
header.print( header_start );
|
||||
header.print( nspace_macro );
|
||||
|
||||
if ( generate_gen_dep )
|
||||
{
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
|
||||
@ -91,7 +76,6 @@ int gen_main()
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
Code string = scan_file( project_dir "dependencies/string.hpp" );
|
||||
Code file_handling = scan_file( project_dir "dependencies/file_handling.hpp" );
|
||||
Code parsing = scan_file( project_dir "dependencies/parsing.hpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
||||
|
||||
header.print( header_start );
|
||||
@ -106,7 +90,6 @@ int gen_main()
|
||||
header.print( hashing );
|
||||
header.print( string );
|
||||
header.print( file_handling );
|
||||
header.print( parsing );
|
||||
header.print( timing );
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
|
||||
@ -114,16 +97,17 @@ int gen_main()
|
||||
}
|
||||
|
||||
Code types = scan_file( project_dir "components/types.hpp" );
|
||||
Code data_structs = scan_file( project_dir "components/data_structures.hpp" );
|
||||
Code ast = scan_file( project_dir "components/ast.hpp" );
|
||||
Code ast_types = scan_file( project_dir "components/ast_types.hpp" );
|
||||
Code interface = scan_file( project_dir "components/interface.hpp" );
|
||||
Code inlines = scan_file( project_dir "components/inlines.hpp" );
|
||||
Code ast_inlines = scan_file( project_dir "components/temp/ast_inlines.hpp" );
|
||||
Code header_end = scan_file( project_dir "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode( project_dir "enums/ECode.csv" );
|
||||
CodeBody eoperator = gen_eoperator( project_dir "enums/EOperator.csv" );
|
||||
CodeBody ecode = gen_ecode ( project_dir "enums/ECode.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" );
|
||||
|
||||
Code builder = scan_file( project_dir "file_processors/builder.hpp" );
|
||||
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n" );
|
||||
|
||||
header.print_fmt("#pragma region Types\n\n");
|
||||
@ -133,32 +117,40 @@ int gen_main()
|
||||
header.print( especifier );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
header.print( data_structs );
|
||||
header.print_fmt("#pragma region AST\n\n");
|
||||
header.print( ast );
|
||||
header.print( ast_types );
|
||||
header.print_fmt("#pragma endregion AST\n\n");
|
||||
|
||||
header.print( interface );
|
||||
|
||||
header.print_fmt( inlines );
|
||||
header.print_fmt( ast_inlines );
|
||||
|
||||
header.print( header_end );
|
||||
header.print( builder );
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
}
|
||||
|
||||
// Implementation
|
||||
{
|
||||
header.print_fmt( "%s\n", (char const*) implementation_guard_start );
|
||||
|
||||
if ( generate_gen_dep )
|
||||
{
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
|
||||
Code impl_start = scan_file( project_dir "dependencies/impl_start.cpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.cpp" );
|
||||
Code parsing = scan_file( project_dir "dependencies/parsing.cpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
||||
Code string = scan_file( project_dir "dependencies/string.cpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.cpp" );
|
||||
|
||||
Code impl_start = scan_file( project_dir "dependencies/impl_start.cpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.cpp" );
|
||||
Code parsing = scan_file( project_dir "dependencies/parsing.cpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
||||
Code string = scan_file( project_dir "dependencies/string.cpp" );
|
||||
Code file_handling = scan_file( project_dir "dependencies/file_handling.cpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.cpp" );
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
|
||||
header.print( impl_start );
|
||||
header.print( debug );
|
||||
header.print( string_ops );
|
||||
@ -167,12 +159,10 @@ int gen_main()
|
||||
header.print( parsing );
|
||||
header.print( hashing );
|
||||
header.print( string );
|
||||
header.print( file_handling );
|
||||
header.print( timing );
|
||||
|
||||
header.print( file_handling );
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n");
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_end );
|
||||
}
|
||||
|
||||
@ -184,11 +174,9 @@ int gen_main()
|
||||
Code parsing = scan_file( project_dir "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( project_dir "components/untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv" );
|
||||
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv" );
|
||||
CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
|
||||
|
||||
Code builder = scan_file( project_dir "file_processors/builder.cpp" );
|
||||
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
header.print( data );
|
||||
header.print( ast_case_macros );
|
||||
@ -198,7 +186,6 @@ int gen_main()
|
||||
header.print( parser_nspace );
|
||||
header.print( parsing );
|
||||
header.print( untyped );
|
||||
header.print( builder );
|
||||
header.print_fmt( "GEN_NS_END\n");
|
||||
|
||||
header.print_fmt( "%s\n", (char const*) implementation_guard_end );
|
||||
|
3
test/validate_bootstrap.cpp
Normal file
3
test/validate_bootstrap.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
// Constructs an AST from the bootstrap generated gen files, then serializes it to a set of files.
|
||||
// Using the new set of serialized files, reconstructs the AST and then serializes it again.
|
||||
// The two sets of serialized files should be identical. (Verified by comparing the file hashes)
|
3
test/validate_singleheader.cpp
Normal file
3
test/validate_singleheader.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
// Constructs an AST from the singlheader generated gen files, then serializes it to a set of files.
|
||||
// Using the new set of serialized files, reconstructs the AST and then serializes it again (to different set of files).
|
||||
// The two sets of serialized files should be identical. (Verified by comparing the file hashes)
|
Loading…
Reference in New Issue
Block a user