Updated gencpp with latest fixes used in other projects.

This variant can support parsing some Unreal Engine files!!
This commit is contained in:
Edward R. Gonzalez 2024-04-17 17:40:32 -04:00
parent 83d691c65c
commit 36260f6edb
17 changed files with 1281 additions and 579 deletions

View File

@ -333,12 +333,13 @@ struct AST
AST* ValueType; // Parameter, Variable AST* ValueType; // Parameter, Variable
}; };
union { union {
AST* Macro; // Parameter
AST* BitfieldSize; // Variable (Class/Struct Data Member) AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename AST* Params; // Constructor, Function, Operator, Template, Typename
}; };
union { union {
AST* ArrExpr; // Typename AST* ArrExpr; // Typename
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union AST* Body; // Class, Constructr, Destructor, Enum, Friend, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable AST* Value; // Parameter, Variable
}; };
@ -393,12 +394,13 @@ struct AST_POD
AST* ValueType; // Parameter, Variable AST* ValueType; // Parameter, Variable
}; };
union { union {
AST* Macro; // Parameter
AST* BitfieldSize; // Variable (Class/Struct Data Member) AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename AST* Params; // Constructor, Function, Operator, Template, Typename
}; };
union { union {
AST* ArrExpr; // Typename AST* ArrExpr; // Typename
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union AST* Body; // Class, Constructr, Destructor, Enum, Friend, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable AST* Value; // Parameter, Variable
}; };

View File

@ -118,7 +118,7 @@ struct AST_Constructor
Code Next; Code Next;
parser::Token* Tok; parser::Token* Tok;
Code Parent; Code Parent;
char _PAD_NAME_[ sizeof(StringCached) ]; StringCached Name;
CodeT Type; CodeT Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ]; char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
}; };
@ -158,7 +158,7 @@ struct AST_Destructor
Code Next; Code Next;
parser::Token* Tok; parser::Token* Tok;
Code Parent; Code Parent;
char _PAD_NAME_[ sizeof(StringCached) ]; StringCached Name;
CodeT Type; CodeT Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ]; char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
}; };
@ -642,7 +642,7 @@ struct AST_Param
{ {
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ]; char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
CodeType ValueType; CodeType ValueType;
char _PAD_PROPERTIES_[ sizeof(AST*) ]; Code Macro;
Code Value; Code Value;
char _PAD_PROPERTIES_3_[ sizeof(AST*) ]; char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
}; };

View File

@ -96,12 +96,18 @@ String CodeConstructor::to_string()
void CodeConstructor::to_string_def( String& result ) void CodeConstructor::to_string_def( String& result )
{ {
result.append( ast->Parent->Name ); AST* ClassStructParent = ast->Parent->Parent;
if (ClassStructParent) {
result.append( ClassStructParent->Name );
}
else {
result.append( ast->Name );
}
if ( ast->Params ) if ( ast->Params )
result.append_fmt( "( %S )", ast->Params.to_string() ); result.append_fmt( "( %S )", ast->Params.to_string() );
else else
result.append( "(void)" ); result.append( "()" );
if ( ast->InitializerList ) if ( ast->InitializerList )
result.append_fmt( " : %S", ast->InitializerList.to_string() ); result.append_fmt( " : %S", ast->InitializerList.to_string() );
@ -114,17 +120,26 @@ void CodeConstructor::to_string_def( String& result )
void CodeConstructor::to_string_fwd( String& result ) void CodeConstructor::to_string_fwd( String& result )
{ {
result.append( ast->Parent->Name ); AST* ClassStructParent = ast->Parent->Parent;
if (ClassStructParent) {
result.append( ClassStructParent->Name );
}
else {
result.append( ast->Name );
}
if ( ast->Params ) if ( ast->Params )
result.append_fmt( "( %S )", ast->Params.to_string() ); result.append_fmt( "( %S )", ast->Params.to_string() );
else else
{ result.append_fmt("()");
if ( ast->InlineCmt )
result.append_fmt( "(void); // %S\n", ast->InlineCmt->Content ); if (ast->Body)
else result.append_fmt( " = %S", ast->Body.to_string() );
result.append( "(void);\n" );
} if ( ast->InlineCmt )
result.append_fmt( "; // %S\n", ast->InlineCmt->Content );
else
result.append( ";" );
} }
String CodeClass::to_string() String CodeClass::to_string()
@ -159,7 +174,7 @@ void CodeClass::to_string_def( String& result )
{ {
char const* access_level = to_str( ast->ParentAccess ); char const* access_level = to_str( ast->ParentAccess );
result.append_fmt( "%S : %s %S", ast->Name, access_level, ast->ParentType ); result.append_fmt( "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() );
CodeType interface = ast->ParentType->Next->cast< CodeType >(); CodeType interface = ast->ParentType->Next->cast< CodeType >();
if ( interface ) if ( interface )
@ -235,7 +250,11 @@ String CodeDestructor::to_string()
void CodeDestructor::to_string_def( String& result ) void CodeDestructor::to_string_def( String& result )
{ {
if ( ast->Specs ) if ( ast->Name )
{
result.append_fmt( "%S()", ast->Name );
}
else if ( ast->Specs )
{ {
if ( ast->Specs.has( ESpecifier::Virtual ) ) if ( ast->Specs.has( ESpecifier::Virtual ) )
result.append_fmt( "virtual ~%S()", ast->Parent->Name ); result.append_fmt( "virtual ~%S()", ast->Parent->Name );
@ -259,6 +278,8 @@ void CodeDestructor::to_string_fwd( String& result )
if ( ast->Specs.has( ESpecifier::Pure ) ) if ( ast->Specs.has( ESpecifier::Pure ) )
result.append( " = 0;" ); result.append( " = 0;" );
else if (ast->Body)
result.append_fmt( " = %S;", ast->Body.to_string() );
} }
else else
result.append_fmt( "~%S();", ast->Parent->Name ); result.append_fmt( "~%S();", ast->Parent->Name );
@ -424,7 +445,7 @@ void CodeFriend::to_string( String& result )
{ {
result.append_fmt( "friend %S", ast->Declaration->to_string() ); result.append_fmt( "friend %S", ast->Declaration->to_string() );
if ( result[ result.length() -1 ] != ';' ) if ( ast->Declaration->Type != ECode::Function && result[ result.length() - 1 ] != ';' )
{ {
result.append( ";" ); result.append( ";" );
} }
@ -513,7 +534,7 @@ void CodeFn::to_string_fwd( String& result )
{ {
for ( SpecifierT spec : ast->Specs ) for ( SpecifierT spec : ast->Specs )
{ {
if ( ! ESpecifier::is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) && ! (spec != ESpecifier::Pure) )
{ {
StrC spec_str = ESpecifier::to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr ); result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
@ -550,6 +571,11 @@ void CodeFn::to_string_fwd( String& result )
} }
} }
if ( ast->Specs.has( ESpecifier::Pure ) >= 0 )
result.append( " = 0;" );
else if (ast->Body)
result.append_fmt( " = %S;", ast->Body.to_string() );
if ( ast->InlineCmt ) if ( ast->InlineCmt )
result.append_fmt( "; %S", ast->InlineCmt->Content ); result.append_fmt( "; %S", ast->InlineCmt->Content );
else else
@ -797,24 +823,30 @@ String CodeParam::to_string()
void CodeParam::to_string( String& result ) void CodeParam::to_string( String& result )
{ {
if ( ast->ValueType.ast == nullptr ) if ( ast->Macro )
{ {
result.append_fmt( "%S", ast->Name ); // Related to parsing: ( <macro>, ... )
return; result.append( ast->Macro.ast->Content );
// Could also be: ( <macro> <type <name>, ... )
} }
if ( ast->Name ) if ( ast->Name )
result.append_fmt( "%S %S", ast->ValueType.to_string(), ast->Name ); {
if ( ast->ValueType.ast == nullptr )
result.append_fmt( " %S", ast->Name );
else
result.append_fmt( " %S %S", ast->ValueType.to_string(), ast->Name );
else }
result.append_fmt( "%S", ast->ValueType.to_string() ); else if ( ast->ValueType )
result.append_fmt( " %S", ast->ValueType.to_string() );
if ( ast->Value ) if ( ast->Value )
result.append_fmt( "= %S", ast->Value.to_string() ); result.append_fmt( " = %S", ast->Value.to_string() );
if ( ast->NumEntries - 1 > 0) if ( ast->NumEntries - 1 > 0 )
{ {
for ( CodeParam param : ast->Next ) for ( CodeParam param : ast->Next )
{ {
result.append_fmt( ", %S", param.to_string() ); result.append_fmt( ", %S", param.to_string() );
} }
@ -942,7 +974,7 @@ void CodeStruct::to_string_def( String& result )
{ {
char const* access_level = to_str( ast->ParentAccess ); char const* access_level = to_str( ast->ParentAccess );
result.append_fmt( "%S : %s %S", ast->Name, access_level, ast->ParentType ); result.append_fmt( "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() );
CodeType interface = ast->ParentType->Next->cast< CodeType >(); CodeType interface = ast->ParentType->Next->cast< CodeType >();
if ( interface ) if ( interface )

View File

@ -159,7 +159,7 @@ struct CodeSpecifiers
{ {
for ( s32 idx = 0; idx < raw()->NumEntries; idx++ ) for ( s32 idx = 0; idx < raw()->NumEntries; idx++ )
{ {
if ( raw()->ArrSpecs[ raw()->NumEntries ] == spec ) if ( raw()->ArrSpecs[ idx ] == spec )
return idx; return idx;
} }

View File

@ -36,7 +36,7 @@ bool Code::is_equal( Code other )
bool Code::is_valid() bool Code::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void Code::set_global() void Code::set_global()
@ -62,12 +62,12 @@ Code& Code::operator=( Code other )
bool Code::operator==( Code other ) bool Code::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool Code::operator!=( Code other ) bool Code::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
Code::operator bool() Code::operator bool()
@ -104,7 +104,7 @@ bool CodeBody::is_equal( Code other )
bool CodeBody::is_valid() bool CodeBody::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeBody::set_global() void CodeBody::set_global()
@ -130,12 +130,12 @@ CodeBody& CodeBody::operator=( Code other )
bool CodeBody::operator==( Code other ) bool CodeBody::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeBody::operator!=( Code other ) bool CodeBody::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeBody::operator bool() CodeBody::operator bool()
@ -172,7 +172,7 @@ bool CodeAttributes::is_equal( Code other )
bool CodeAttributes::is_valid() bool CodeAttributes::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeAttributes::set_global() void CodeAttributes::set_global()
@ -198,12 +198,12 @@ CodeAttributes& CodeAttributes::operator=( Code other )
bool CodeAttributes::operator==( Code other ) bool CodeAttributes::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeAttributes::operator!=( Code other ) bool CodeAttributes::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeAttributes::operator bool() CodeAttributes::operator bool()
@ -260,7 +260,7 @@ bool CodeComment::is_equal( Code other )
bool CodeComment::is_valid() bool CodeComment::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeComment::set_global() void CodeComment::set_global()
@ -286,12 +286,12 @@ CodeComment& CodeComment::operator=( Code other )
bool CodeComment::operator==( Code other ) bool CodeComment::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeComment::operator!=( Code other ) bool CodeComment::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeComment::operator bool() CodeComment::operator bool()
@ -348,7 +348,7 @@ bool CodeConstructor::is_equal( Code other )
bool CodeConstructor::is_valid() bool CodeConstructor::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeConstructor::set_global() void CodeConstructor::set_global()
@ -374,12 +374,12 @@ CodeConstructor& CodeConstructor::operator=( Code other )
bool CodeConstructor::operator==( Code other ) bool CodeConstructor::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeConstructor::operator!=( Code other ) bool CodeConstructor::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeConstructor::operator bool() CodeConstructor::operator bool()
@ -436,7 +436,7 @@ bool CodeClass::is_equal( Code other )
bool CodeClass::is_valid() bool CodeClass::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeClass::set_global() void CodeClass::set_global()
@ -462,12 +462,12 @@ CodeClass& CodeClass::operator=( Code other )
bool CodeClass::operator==( Code other ) bool CodeClass::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeClass::operator!=( Code other ) bool CodeClass::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeClass::operator bool() CodeClass::operator bool()
@ -504,7 +504,7 @@ bool CodeDefine::is_equal( Code other )
bool CodeDefine::is_valid() bool CodeDefine::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeDefine::set_global() void CodeDefine::set_global()
@ -530,12 +530,12 @@ CodeDefine& CodeDefine::operator=( Code other )
bool CodeDefine::operator==( Code other ) bool CodeDefine::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeDefine::operator!=( Code other ) bool CodeDefine::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeDefine::operator bool() CodeDefine::operator bool()
@ -592,7 +592,7 @@ bool CodeDestructor::is_equal( Code other )
bool CodeDestructor::is_valid() bool CodeDestructor::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeDestructor::set_global() void CodeDestructor::set_global()
@ -618,12 +618,12 @@ CodeDestructor& CodeDestructor::operator=( Code other )
bool CodeDestructor::operator==( Code other ) bool CodeDestructor::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeDestructor::operator!=( Code other ) bool CodeDestructor::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeDestructor::operator bool() CodeDestructor::operator bool()
@ -680,7 +680,7 @@ bool CodeEnum::is_equal( Code other )
bool CodeEnum::is_valid() bool CodeEnum::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeEnum::set_global() void CodeEnum::set_global()
@ -706,12 +706,12 @@ CodeEnum& CodeEnum::operator=( Code other )
bool CodeEnum::operator==( Code other ) bool CodeEnum::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeEnum::operator!=( Code other ) bool CodeEnum::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeEnum::operator bool() CodeEnum::operator bool()
@ -768,7 +768,7 @@ bool CodeExec::is_equal( Code other )
bool CodeExec::is_valid() bool CodeExec::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeExec::set_global() void CodeExec::set_global()
@ -794,12 +794,12 @@ CodeExec& CodeExec::operator=( Code other )
bool CodeExec::operator==( Code other ) bool CodeExec::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeExec::operator!=( Code other ) bool CodeExec::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeExec::operator bool() CodeExec::operator bool()
@ -856,7 +856,7 @@ bool CodeExtern::is_equal( Code other )
bool CodeExtern::is_valid() bool CodeExtern::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeExtern::set_global() void CodeExtern::set_global()
@ -882,12 +882,12 @@ CodeExtern& CodeExtern::operator=( Code other )
bool CodeExtern::operator==( Code other ) bool CodeExtern::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeExtern::operator!=( Code other ) bool CodeExtern::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeExtern::operator bool() CodeExtern::operator bool()
@ -944,7 +944,7 @@ bool CodeFriend::is_equal( Code other )
bool CodeFriend::is_valid() bool CodeFriend::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeFriend::set_global() void CodeFriend::set_global()
@ -970,12 +970,12 @@ CodeFriend& CodeFriend::operator=( Code other )
bool CodeFriend::operator==( Code other ) bool CodeFriend::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeFriend::operator!=( Code other ) bool CodeFriend::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeFriend::operator bool() CodeFriend::operator bool()
@ -1032,7 +1032,7 @@ bool CodeFn::is_equal( Code other )
bool CodeFn::is_valid() bool CodeFn::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeFn::set_global() void CodeFn::set_global()
@ -1058,12 +1058,12 @@ CodeFn& CodeFn::operator=( Code other )
bool CodeFn::operator==( Code other ) bool CodeFn::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeFn::operator!=( Code other ) bool CodeFn::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeFn::operator bool() CodeFn::operator bool()
@ -1120,7 +1120,7 @@ bool CodeInclude::is_equal( Code other )
bool CodeInclude::is_valid() bool CodeInclude::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeInclude::set_global() void CodeInclude::set_global()
@ -1146,12 +1146,12 @@ CodeInclude& CodeInclude::operator=( Code other )
bool CodeInclude::operator==( Code other ) bool CodeInclude::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeInclude::operator!=( Code other ) bool CodeInclude::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeInclude::operator bool() CodeInclude::operator bool()
@ -1208,7 +1208,7 @@ bool CodeModule::is_equal( Code other )
bool CodeModule::is_valid() bool CodeModule::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeModule::set_global() void CodeModule::set_global()
@ -1234,12 +1234,12 @@ CodeModule& CodeModule::operator=( Code other )
bool CodeModule::operator==( Code other ) bool CodeModule::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeModule::operator!=( Code other ) bool CodeModule::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeModule::operator bool() CodeModule::operator bool()
@ -1296,7 +1296,7 @@ bool CodeNS::is_equal( Code other )
bool CodeNS::is_valid() bool CodeNS::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeNS::set_global() void CodeNS::set_global()
@ -1322,12 +1322,12 @@ CodeNS& CodeNS::operator=( Code other )
bool CodeNS::operator==( Code other ) bool CodeNS::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeNS::operator!=( Code other ) bool CodeNS::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeNS::operator bool() CodeNS::operator bool()
@ -1384,7 +1384,7 @@ bool CodeOperator::is_equal( Code other )
bool CodeOperator::is_valid() bool CodeOperator::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeOperator::set_global() void CodeOperator::set_global()
@ -1410,12 +1410,12 @@ CodeOperator& CodeOperator::operator=( Code other )
bool CodeOperator::operator==( Code other ) bool CodeOperator::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeOperator::operator!=( Code other ) bool CodeOperator::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeOperator::operator bool() CodeOperator::operator bool()
@ -1472,7 +1472,7 @@ bool CodeOpCast::is_equal( Code other )
bool CodeOpCast::is_valid() bool CodeOpCast::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeOpCast::set_global() void CodeOpCast::set_global()
@ -1498,12 +1498,12 @@ CodeOpCast& CodeOpCast::operator=( Code other )
bool CodeOpCast::operator==( Code other ) bool CodeOpCast::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeOpCast::operator!=( Code other ) bool CodeOpCast::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeOpCast::operator bool() CodeOpCast::operator bool()
@ -1560,7 +1560,7 @@ bool CodeParam::is_equal( Code other )
bool CodeParam::is_valid() bool CodeParam::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeParam::set_global() void CodeParam::set_global()
@ -1586,12 +1586,12 @@ CodeParam& CodeParam::operator=( Code other )
bool CodeParam::operator==( Code other ) bool CodeParam::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeParam::operator!=( Code other ) bool CodeParam::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeParam::operator bool() CodeParam::operator bool()
@ -1628,7 +1628,7 @@ bool CodePragma::is_equal( Code other )
bool CodePragma::is_valid() bool CodePragma::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodePragma::set_global() void CodePragma::set_global()
@ -1654,12 +1654,12 @@ CodePragma& CodePragma::operator=( Code other )
bool CodePragma::operator==( Code other ) bool CodePragma::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodePragma::operator!=( Code other ) bool CodePragma::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodePragma::operator bool() CodePragma::operator bool()
@ -1716,7 +1716,7 @@ bool CodePreprocessCond::is_equal( Code other )
bool CodePreprocessCond::is_valid() bool CodePreprocessCond::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodePreprocessCond::set_global() void CodePreprocessCond::set_global()
@ -1742,12 +1742,12 @@ CodePreprocessCond& CodePreprocessCond::operator=( Code other )
bool CodePreprocessCond::operator==( Code other ) bool CodePreprocessCond::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodePreprocessCond::operator!=( Code other ) bool CodePreprocessCond::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodePreprocessCond::operator bool() CodePreprocessCond::operator bool()
@ -1804,7 +1804,7 @@ bool CodeSpecifiers::is_equal( Code other )
bool CodeSpecifiers::is_valid() bool CodeSpecifiers::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeSpecifiers::set_global() void CodeSpecifiers::set_global()
@ -1830,12 +1830,12 @@ CodeSpecifiers& CodeSpecifiers::operator=( Code other )
bool CodeSpecifiers::operator==( Code other ) bool CodeSpecifiers::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeSpecifiers::operator!=( Code other ) bool CodeSpecifiers::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeSpecifiers::operator bool() CodeSpecifiers::operator bool()
@ -1872,7 +1872,7 @@ bool CodeStruct::is_equal( Code other )
bool CodeStruct::is_valid() bool CodeStruct::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeStruct::set_global() void CodeStruct::set_global()
@ -1898,12 +1898,12 @@ CodeStruct& CodeStruct::operator=( Code other )
bool CodeStruct::operator==( Code other ) bool CodeStruct::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeStruct::operator!=( Code other ) bool CodeStruct::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeStruct::operator bool() CodeStruct::operator bool()
@ -1940,7 +1940,7 @@ bool CodeTemplate::is_equal( Code other )
bool CodeTemplate::is_valid() bool CodeTemplate::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeTemplate::set_global() void CodeTemplate::set_global()
@ -1966,12 +1966,12 @@ CodeTemplate& CodeTemplate::operator=( Code other )
bool CodeTemplate::operator==( Code other ) bool CodeTemplate::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeTemplate::operator!=( Code other ) bool CodeTemplate::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeTemplate::operator bool() CodeTemplate::operator bool()
@ -2028,7 +2028,7 @@ bool CodeType::is_equal( Code other )
bool CodeType::is_valid() bool CodeType::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeType::set_global() void CodeType::set_global()
@ -2054,12 +2054,12 @@ CodeType& CodeType::operator=( Code other )
bool CodeType::operator==( Code other ) bool CodeType::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeType::operator!=( Code other ) bool CodeType::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeType::operator bool() CodeType::operator bool()
@ -2116,7 +2116,7 @@ bool CodeTypedef::is_equal( Code other )
bool CodeTypedef::is_valid() bool CodeTypedef::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeTypedef::set_global() void CodeTypedef::set_global()
@ -2142,12 +2142,12 @@ CodeTypedef& CodeTypedef::operator=( Code other )
bool CodeTypedef::operator==( Code other ) bool CodeTypedef::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeTypedef::operator!=( Code other ) bool CodeTypedef::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeTypedef::operator bool() CodeTypedef::operator bool()
@ -2204,7 +2204,7 @@ bool CodeUnion::is_equal( Code other )
bool CodeUnion::is_valid() bool CodeUnion::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeUnion::set_global() void CodeUnion::set_global()
@ -2230,12 +2230,12 @@ CodeUnion& CodeUnion::operator=( Code other )
bool CodeUnion::operator==( Code other ) bool CodeUnion::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeUnion::operator!=( Code other ) bool CodeUnion::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeUnion::operator bool() CodeUnion::operator bool()
@ -2292,7 +2292,7 @@ bool CodeUsing::is_equal( Code other )
bool CodeUsing::is_valid() bool CodeUsing::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeUsing::set_global() void CodeUsing::set_global()
@ -2318,12 +2318,12 @@ CodeUsing& CodeUsing::operator=( Code other )
bool CodeUsing::operator==( Code other ) bool CodeUsing::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeUsing::operator!=( Code other ) bool CodeUsing::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeUsing::operator bool() CodeUsing::operator bool()
@ -2380,7 +2380,7 @@ bool CodeVar::is_equal( Code other )
bool CodeVar::is_valid() bool CodeVar::is_valid()
{ {
return ( AST* )ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid; return (AST*)ast != nullptr && rcast( AST*, ast )->Type != CodeT::Invalid;
} }
void CodeVar::set_global() void CodeVar::set_global()
@ -2406,12 +2406,12 @@ CodeVar& CodeVar::operator=( Code other )
bool CodeVar::operator==( Code other ) bool CodeVar::operator==( Code other )
{ {
return ( AST* )ast == other.ast; return (AST*)ast == other.ast;
} }
bool CodeVar::operator!=( Code other ) bool CodeVar::operator!=( Code other )
{ {
return ( AST* )ast != other.ast; return (AST*)ast != other.ast;
} }
CodeVar::operator bool() CodeVar::operator bool()
@ -2450,7 +2450,7 @@ AST::operator CodeBody()
Code::operator CodeBody() const Code::operator CodeBody() const
{ {
return { ( AST_Body* )ast }; return { (AST_Body*)ast };
} }
AST::operator CodeAttributes() AST::operator CodeAttributes()
@ -2460,7 +2460,7 @@ AST::operator CodeAttributes()
Code::operator CodeAttributes() const Code::operator CodeAttributes() const
{ {
return { ( AST_Attributes* )ast }; return { (AST_Attributes*)ast };
} }
AST::operator CodeComment() AST::operator CodeComment()
@ -2470,7 +2470,7 @@ AST::operator CodeComment()
Code::operator CodeComment() const Code::operator CodeComment() const
{ {
return { ( AST_Comment* )ast }; return { (AST_Comment*)ast };
} }
AST::operator CodeConstructor() AST::operator CodeConstructor()
@ -2480,7 +2480,7 @@ AST::operator CodeConstructor()
Code::operator CodeConstructor() const Code::operator CodeConstructor() const
{ {
return { ( AST_Constructor* )ast }; return { (AST_Constructor*)ast };
} }
AST::operator CodeClass() AST::operator CodeClass()
@ -2490,7 +2490,7 @@ AST::operator CodeClass()
Code::operator CodeClass() const Code::operator CodeClass() const
{ {
return { ( AST_Class* )ast }; return { (AST_Class*)ast };
} }
AST::operator CodeDefine() AST::operator CodeDefine()
@ -2500,7 +2500,7 @@ AST::operator CodeDefine()
Code::operator CodeDefine() const Code::operator CodeDefine() const
{ {
return { ( AST_Define* )ast }; return { (AST_Define*)ast };
} }
AST::operator CodeDestructor() AST::operator CodeDestructor()
@ -2510,7 +2510,7 @@ AST::operator CodeDestructor()
Code::operator CodeDestructor() const Code::operator CodeDestructor() const
{ {
return { ( AST_Destructor* )ast }; return { (AST_Destructor*)ast };
} }
AST::operator CodeEnum() AST::operator CodeEnum()
@ -2520,7 +2520,7 @@ AST::operator CodeEnum()
Code::operator CodeEnum() const Code::operator CodeEnum() const
{ {
return { ( AST_Enum* )ast }; return { (AST_Enum*)ast };
} }
AST::operator CodeExec() AST::operator CodeExec()
@ -2530,7 +2530,7 @@ AST::operator CodeExec()
Code::operator CodeExec() const Code::operator CodeExec() const
{ {
return { ( AST_Exec* )ast }; return { (AST_Exec*)ast };
} }
AST::operator CodeExtern() AST::operator CodeExtern()
@ -2540,7 +2540,7 @@ AST::operator CodeExtern()
Code::operator CodeExtern() const Code::operator CodeExtern() const
{ {
return { ( AST_Extern* )ast }; return { (AST_Extern*)ast };
} }
AST::operator CodeFriend() AST::operator CodeFriend()
@ -2550,7 +2550,7 @@ AST::operator CodeFriend()
Code::operator CodeFriend() const Code::operator CodeFriend() const
{ {
return { ( AST_Friend* )ast }; return { (AST_Friend*)ast };
} }
AST::operator CodeFn() AST::operator CodeFn()
@ -2560,7 +2560,7 @@ AST::operator CodeFn()
Code::operator CodeFn() const Code::operator CodeFn() const
{ {
return { ( AST_Fn* )ast }; return { (AST_Fn*)ast };
} }
AST::operator CodeInclude() AST::operator CodeInclude()
@ -2570,7 +2570,7 @@ AST::operator CodeInclude()
Code::operator CodeInclude() const Code::operator CodeInclude() const
{ {
return { ( AST_Include* )ast }; return { (AST_Include*)ast };
} }
AST::operator CodeModule() AST::operator CodeModule()
@ -2580,7 +2580,7 @@ AST::operator CodeModule()
Code::operator CodeModule() const Code::operator CodeModule() const
{ {
return { ( AST_Module* )ast }; return { (AST_Module*)ast };
} }
AST::operator CodeNS() AST::operator CodeNS()
@ -2590,7 +2590,7 @@ AST::operator CodeNS()
Code::operator CodeNS() const Code::operator CodeNS() const
{ {
return { ( AST_NS* )ast }; return { (AST_NS*)ast };
} }
AST::operator CodeOperator() AST::operator CodeOperator()
@ -2600,7 +2600,7 @@ AST::operator CodeOperator()
Code::operator CodeOperator() const Code::operator CodeOperator() const
{ {
return { ( AST_Operator* )ast }; return { (AST_Operator*)ast };
} }
AST::operator CodeOpCast() AST::operator CodeOpCast()
@ -2610,7 +2610,7 @@ AST::operator CodeOpCast()
Code::operator CodeOpCast() const Code::operator CodeOpCast() const
{ {
return { ( AST_OpCast* )ast }; return { (AST_OpCast*)ast };
} }
AST::operator CodeParam() AST::operator CodeParam()
@ -2620,7 +2620,7 @@ AST::operator CodeParam()
Code::operator CodeParam() const Code::operator CodeParam() const
{ {
return { ( AST_Param* )ast }; return { (AST_Param*)ast };
} }
AST::operator CodePragma() AST::operator CodePragma()
@ -2630,7 +2630,7 @@ AST::operator CodePragma()
Code::operator CodePragma() const Code::operator CodePragma() const
{ {
return { ( AST_Pragma* )ast }; return { (AST_Pragma*)ast };
} }
AST::operator CodePreprocessCond() AST::operator CodePreprocessCond()
@ -2640,7 +2640,7 @@ AST::operator CodePreprocessCond()
Code::operator CodePreprocessCond() const Code::operator CodePreprocessCond() const
{ {
return { ( AST_PreprocessCond* )ast }; return { (AST_PreprocessCond*)ast };
} }
AST::operator CodeSpecifiers() AST::operator CodeSpecifiers()
@ -2650,7 +2650,7 @@ AST::operator CodeSpecifiers()
Code::operator CodeSpecifiers() const Code::operator CodeSpecifiers() const
{ {
return { ( AST_Specifiers* )ast }; return { (AST_Specifiers*)ast };
} }
AST::operator CodeStruct() AST::operator CodeStruct()
@ -2660,7 +2660,7 @@ AST::operator CodeStruct()
Code::operator CodeStruct() const Code::operator CodeStruct() const
{ {
return { ( AST_Struct* )ast }; return { (AST_Struct*)ast };
} }
AST::operator CodeTemplate() AST::operator CodeTemplate()
@ -2670,7 +2670,7 @@ AST::operator CodeTemplate()
Code::operator CodeTemplate() const Code::operator CodeTemplate() const
{ {
return { ( AST_Template* )ast }; return { (AST_Template*)ast };
} }
AST::operator CodeType() AST::operator CodeType()
@ -2680,7 +2680,7 @@ AST::operator CodeType()
Code::operator CodeType() const Code::operator CodeType() const
{ {
return { ( AST_Type* )ast }; return { (AST_Type*)ast };
} }
AST::operator CodeTypedef() AST::operator CodeTypedef()
@ -2690,7 +2690,7 @@ AST::operator CodeTypedef()
Code::operator CodeTypedef() const Code::operator CodeTypedef() const
{ {
return { ( AST_Typedef* )ast }; return { (AST_Typedef*)ast };
} }
AST::operator CodeUnion() AST::operator CodeUnion()
@ -2700,7 +2700,7 @@ AST::operator CodeUnion()
Code::operator CodeUnion() const Code::operator CodeUnion() const
{ {
return { ( AST_Union* )ast }; return { (AST_Union*)ast };
} }
AST::operator CodeUsing() AST::operator CodeUsing()
@ -2710,7 +2710,7 @@ AST::operator CodeUsing()
Code::operator CodeUsing() const Code::operator CodeUsing() const
{ {
return { ( AST_Using* )ast }; return { (AST_Using*)ast };
} }
AST::operator CodeVar() AST::operator CodeVar()
@ -2720,7 +2720,7 @@ AST::operator CodeVar()
Code::operator CodeVar() const Code::operator CodeVar() const
{ {
return { ( AST_Var* )ast }; return { (AST_Var*)ast };
} }
#pragma endregion generated AST / Code cast implementation #pragma endregion generated AST / Code cast implementation

View File

@ -136,7 +136,7 @@ namespace ECode
{ sizeof( "Using_Namespace" ), "Using_Namespace" }, { sizeof( "Using_Namespace" ), "Using_Namespace" },
{ sizeof( "Variable" ), "Variable" }, { sizeof( "Variable" ), "Variable" },
}; };
return lookup[ type ]; return lookup[type];
} }
} // namespace ECode } // namespace ECode

View File

@ -52,57 +52,65 @@ namespace EOperator
PtrToMemOfPtr, PtrToMemOfPtr,
FunctionCall, FunctionCall,
Comma, Comma,
New,
NewArray,
Delete,
DeleteArray,
NumOps NumOps
}; };
StrC to_str( Type op ) StrC to_str( Type op )
{ {
local_persist StrC lookup[] { local_persist StrC lookup[] {
{ sizeof( "INVALID" ), "INVALID" }, { sizeof( "INVALID" ), "INVALID" },
{ sizeof( "=" ), "=" }, { sizeof( "=" ), "=" },
{ sizeof( "+=" ), "+=" }, { sizeof( "+=" ), "+=" },
{ sizeof( "-=" ), "-=" }, { sizeof( "-=" ), "-=" },
{ sizeof( "*=" ), "*=" }, { sizeof( "*=" ), "*=" },
{ sizeof( "/=" ), "/=" }, { sizeof( "/=" ), "/=" },
{ sizeof( "%=" ), "%=" }, { sizeof( "%=" ), "%=" },
{ sizeof( "&=" ), "&=" }, { sizeof( "&=" ), "&=" },
{ sizeof( "|=" ), "|=" }, { sizeof( "|=" ), "|=" },
{ sizeof( "^=" ), "^=" }, { sizeof( "^=" ), "^=" },
{ sizeof( "<<=" ), "<<=" }, { sizeof( "<<=" ), "<<=" },
{ sizeof( ">>=" ), ">>=" }, { sizeof( ">>=" ), ">>=" },
{ sizeof( "++" ), "++" }, { sizeof( "++" ), "++" },
{ sizeof( "--" ), "--" }, { sizeof( "--" ), "--" },
{ sizeof( "+" ), "+" }, { sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" }, { sizeof( "-" ), "-" },
{ sizeof( "!" ), "!" }, { sizeof( "!" ), "!" },
{ sizeof( "+" ), "+" }, { sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" }, { sizeof( "-" ), "-" },
{ sizeof( "*" ), "*" }, { sizeof( "*" ), "*" },
{ sizeof( "/" ), "/" }, { sizeof( "/" ), "/" },
{ sizeof( "%" ), "%" }, { sizeof( "%" ), "%" },
{ sizeof( "~" ), "~" }, { sizeof( "~" ), "~" },
{ sizeof( "&" ), "&" }, { sizeof( "&" ), "&" },
{ sizeof( "|" ), "|" }, { sizeof( "|" ), "|" },
{ sizeof( "^" ), "^" }, { sizeof( "^" ), "^" },
{ sizeof( "<<" ), "<<" }, { sizeof( "<<" ), "<<" },
{ sizeof( ">>" ), ">>" }, { sizeof( ">>" ), ">>" },
{ sizeof( "&&" ), "&&" }, { sizeof( "&&" ), "&&" },
{ sizeof( "||" ), "||" }, { sizeof( "||" ), "||" },
{ sizeof( "==" ), "==" }, { sizeof( "==" ), "==" },
{ sizeof( "!=" ), "!=" }, { sizeof( "!=" ), "!=" },
{ sizeof( "<" ), "<" }, { sizeof( "<" ), "<" },
{ sizeof( ">" ), ">" }, { sizeof( ">" ), ">" },
{ sizeof( "<=" ), "<=" }, { sizeof( "<=" ), "<=" },
{ sizeof( ">=" ), ">=" }, { sizeof( ">=" ), ">=" },
{ sizeof( "[]" ), "[]" }, { sizeof( "[]" ), "[]" },
{ sizeof( "*" ), "*" }, { sizeof( "*" ), "*" },
{ sizeof( "&" ), "&" }, { sizeof( "&" ), "&" },
{ sizeof( "->" ), "->" }, { sizeof( "->" ), "->" },
{ sizeof( "->*" ), "->*" }, { sizeof( "->*" ), "->*" },
{ sizeof( "()" ), "()" }, { sizeof( "()" ), "()" },
{ sizeof( "," ), "," }, { sizeof( "," ), "," },
{ sizeof( "new" ), "new" },
{ sizeof( "new[]" ), "new[]" },
{ sizeof( "delete" ), "delete" },
{ sizeof( "delete[]" ), "delete[]" },
}; };
return lookup[ op ]; return lookup[op];
} }
} // namespace EOperator } // namespace EOperator

View File

@ -73,22 +73,22 @@ namespace ESpecifier
{ sizeof( "= 0" ), "= 0" }, { sizeof( "= 0" ), "= 0" },
{ sizeof( "volatile" ), "volatile" }, { sizeof( "volatile" ), "volatile" },
}; };
return lookup[ type ]; return lookup[type];
} }
Type to_type( StrC str ) Type to_type( StrC str )
{ {
local_persist u32 keymap[ NumSpecifiers ]; local_persist u32 keymap[NumSpecifiers];
do_once_start for ( u32 index = 0; index < NumSpecifiers; index++ ) do_once_start for ( u32 index = 0; index < NumSpecifiers; index++ )
{ {
StrC enum_str = to_str( ( Type )index ); StrC enum_str = to_str( (Type)index );
keymap[ index ] = crc32( enum_str.Ptr, enum_str.Len - 1 ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
} }
do_once_end u32 hash = crc32( str.Ptr, str.Len ); do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < NumSpecifiers; index++ ) for ( u32 index = 0; index < NumSpecifiers; index++ )
{ {
if ( keymap[ index ] == hash ) if ( keymap[index] == hash )
return ( Type )index; return (Type)index;
} }
return Invalid; return Invalid;
} }

View File

@ -9,7 +9,7 @@ namespace parser
{ {
namespace ETokType namespace ETokType
{ {
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( API_Export, GEN_API_Export_Code ) Entry( API_Import, GEN_API_Import_Code ) #define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Attribute_API_Import, "GEN_API_Import_Code" )
enum Type : u32 enum Type : u32
{ {
@ -108,8 +108,8 @@ namespace parser
Type_MS_W64, Type_MS_W64,
Varadic_Argument, Varadic_Argument,
__Attributes_Start, __Attributes_Start,
API_Export, Attribute_API_Export,
API_Import, Attribute_API_Import,
NumTokens NumTokens
}; };
@ -214,22 +214,22 @@ namespace parser
{ sizeof( "GEN_API_Export_Code" ), "GEN_API_Export_Code" }, { sizeof( "GEN_API_Export_Code" ), "GEN_API_Export_Code" },
{ sizeof( "GEN_API_Import_Code" ), "GEN_API_Import_Code" }, { sizeof( "GEN_API_Import_Code" ), "GEN_API_Import_Code" },
}; };
return lookup[ type ]; return lookup[type];
} }
Type to_type( StrC str ) Type to_type( StrC str )
{ {
local_persist u32 keymap[ NumTokens ]; local_persist u32 keymap[NumTokens];
do_once_start for ( u32 index = 0; index < NumTokens; index++ ) do_once_start for ( u32 index = 0; index < NumTokens; index++ )
{ {
StrC enum_str = to_str( ( Type )index ); StrC enum_str = to_str( (Type)index );
keymap[ index ] = crc32( enum_str.Ptr, enum_str.Len - 1 ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
} }
do_once_end u32 hash = crc32( str.Ptr, str.Len ); do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < NumTokens; index++ ) for ( u32 index = 0; index < NumTokens; index++ )
{ {
if ( keymap[ index ] == hash ) if ( keymap[index] == hash )
return ( Type )index; return (Type)index;
} }
return Invalid; return Invalid;
} }

View File

@ -33,8 +33,54 @@ CodeConstructor parse_constructor( StrC def )
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
return CodeInvalid; return CodeInvalid;
Context.Tokens = toks; // TODO(Ed): Constructors can have prefix attributes
CodeConstructor result = parse_constructor();
CodeSpecifiers specifiers;
SpecifierT specs_found[ 16 ] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
while ( left && currtok.is_specifier() )
{
SpecifierT spec = ESpecifier::to_type( currtok );
b32 ignore_spec = false;
switch ( spec )
{
case ESpecifier::Constexpr :
case ESpecifier::Explicit:
case ESpecifier::Inline :
case ESpecifier::ForceInline :
case ESpecifier::NeverInline :
break;
case ESpecifier::Const :
ignore_spec = true;
break;
default :
log_failure( "Invalid specifier %s for variable\n%s", ESpecifier::to_str( spec ), Context.to_string() );
Context.pop();
return CodeInvalid;
}
// Every specifier after would be considered part of the type type signature
if (ignore_spec)
break;
specs_found[ NumSpecifiers ] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( NumSpecifiers )
{
specifiers = def_specifiers( NumSpecifiers, specs_found );
// <specifiers> ...
}
Context.Tokens = toks;
CodeConstructor result = parse_constructor( specifiers );
return result; return result;
} }
@ -47,7 +93,10 @@ CodeDestructor parse_destructor( StrC def )
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
return CodeInvalid; return CodeInvalid;
Context.Tokens = toks; // TODO(Ed): Destructors can have prefix attributes
// TODO(Ed): Destructors can have virtual
Context.Tokens = toks;
CodeDestructor result = parse_destructor(); CodeDestructor result = parse_destructor();
return result; return result;
} }

View File

@ -159,7 +159,6 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
case Unary_Plus: case Unary_Plus:
case Unary_Minus: case Unary_Minus:
case BNot:
if ( ! params_code ) if ( ! params_code )
is_member_symbol = true; is_member_symbol = true;
@ -194,6 +193,41 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
} }
break; break;
case BNot:
{
// Some compilers let you do this...
#if 0
if ( ! ret_type.is_equal( t_bool) )
{
log_failure( "gen::def_operator: return type is not a boolean - %s", params_code.debug_str() );
return OpValidateResult::Fail;
}
#endif
if ( ! params_code )
is_member_symbol = true;
else
{
if ( params_code->Type != ECode::Parameters )
{
log_failure( "gen::def_operator: params is not of Parameters type - %s", params_code.debug_str() );
return OpValidateResult::Fail;
}
if ( params_code->NumEntries > 1 )
{
log_failure(
"gen::def_operator: operator%s may not have more than one parameter - param count: %d",
to_str( op ),
params_code->NumEntries
);
return OpValidateResult::Fail;
}
}
break;
}
case Add: case Add:
case Subtract: case Subtract:
case Multiply: case Multiply:
@ -325,6 +359,11 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
case Comma: case Comma:
check_params(); check_params();
break; break;
case New:
case Delete:
// This library doesn't support validating new and delete yet.
break;
# undef specs # undef specs
} }
@ -520,7 +559,7 @@ CodeClass def_class( StrC name
return CodeInvalid; return CodeInvalid;
} }
if ( parent && (parent->Type != Class || parent->Type != Struct || parent->Type != Typename || parent->Type != Untyped) ) if ( parent && ( parent->Type != Class && parent->Type != Struct && parent->Type != Typename && parent->Type != Untyped ) )
{ {
log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", parent.debug_str() ); log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", parent.debug_str() );
return CodeInvalid; return CodeInvalid;
@ -546,6 +585,7 @@ CodeClass def_class( StrC name
result->Type = Class; result->Type = Class;
result->Body = body; result->Body = body;
result->Body->Parent = result; // TODO(Ed): Review this?
} }
else else
{ {
@ -578,17 +618,25 @@ CodeDefine def_define( StrC name, StrC content )
name_check( def_define, name ); name_check( def_define, name );
// Defines can be empty definitions
#if 0
if ( content.Len <= 0 || content.Ptr == nullptr ) if ( content.Len <= 0 || content.Ptr == nullptr )
{ {
log_failure( "gen::def_define: Invalid value provided" ); log_failure( "gen::def_define: Invalid value provided" );
return CodeInvalid; return CodeInvalid;
} }
#endif
CodeDefine CodeDefine
result = (CodeDefine) make_code(); result = (CodeDefine) make_code();
result->Type = Preprocess_Define; result->Type = Preprocess_Define;
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->Content = get_cached_string( content ); if ( content.Len <= 0 || content.Ptr == nullptr )
{
result->Content = get_cached_string( txt("") );
}
else
result->Content = get_cached_string( content );
return result; return result;
} }

View File

@ -13,11 +13,12 @@ enum TokFlags : u32
TF_Preprocess = bit(2), TF_Preprocess = bit(2),
TF_Preprocess_Cond = bit(3), TF_Preprocess_Cond = bit(3),
TF_Attribute = bit(6), TF_Attribute = bit(6),
TF_AccessSpecifier = bit(7), TF_AccessOperator = bit( 7 ),
TF_Specifier = bit(8), TF_AccessSpecifier = bit( 8 ),
TF_EndDefinition = bit(9), // Either ; or } TF_Specifier = bit( 9 ),
TF_Formatting = bit(10), TF_EndDefinition = bit( 10 ), // Either ; or }
TF_Literal = bit(11), TF_Formatting = bit( 11 ),
TF_Literal = bit( 12 ),
TF_Null = 0, TF_Null = 0,
}; };
@ -41,6 +42,11 @@ struct Token
return { Length, Text }; return { Length, Text };
} }
bool is_access_operator()
{
return bitfield_is_equal( u32, Flags, TF_AccessOperator );
}
bool is_access_specifier() bool is_access_specifier()
{ {
return bitfield_is_equal( u32, Flags, TF_AccessSpecifier ); return bitfield_is_equal( u32, Flags, TF_AccessSpecifier );
@ -141,7 +147,7 @@ struct TokArray
while ( Arr[idx].Type == TokType::NewLine ) while ( Arr[idx].Type == TokType::NewLine )
idx++; idx++;
return Arr[idx]; return Arr[idx + 1];
} }
return Arr[idx + 1]; return Arr[idx + 1];
@ -153,7 +159,7 @@ struct TokArray
} }
}; };
global Arena_64KB defines_map_arena; global Arena_128KB defines_map_arena;
global HashTable<StrC> defines; global HashTable<StrC> defines;
global Array<Token> Tokens; global Array<Token> Tokens;
@ -451,6 +457,16 @@ void lex_found_token( StrC& content
TokType type = ETokType::to_type( token ); TokType type = ETokType::to_type( token );
if (type <= TokType::Access_Public && type >= TokType::Access_Private )
{
token.Flags |= TF_AccessSpecifier;
}
if ( type > TokType::__Attributes_Start )
{
token.Flags |= TF_Attribute;
}
if ( type == ETokType::Decl_Extern_Linkage ) if ( type == ETokType::Decl_Extern_Linkage )
{ {
SkipWhitespace(); SkipWhitespace();
@ -565,7 +581,7 @@ TokArray lex( StrC content )
scanner++; scanner++;
length ++; length ++;
} }
if ( scanner[1] == '(' ) if ( scanner[0] == '(' )
{ {
length++; length++;
} }
@ -634,7 +650,7 @@ TokArray lex( StrC content )
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Access_MemberSymbol; token.Type = TokType::Access_MemberSymbol;
token.Flags = TF_AccessSpecifier; token.Flags = TF_AccessOperator;
if (left) { if (left) {
move_forward(); move_forward();
@ -1003,7 +1019,7 @@ TokArray lex( StrC content )
{ {
token.Length++; token.Length++;
// token.Type = TokType::Access_PointerToMemberSymbol; // token.Type = TokType::Access_PointerToMemberSymbol;
token.Flags |= TF_AccessSpecifier; token.Flags |= TF_AccessOperator;
move_forward(); move_forward();
if ( current == '*' ) if ( current == '*' )

File diff suppressed because it is too large Load Diff

View File

@ -16,9 +16,9 @@ using LogFailType = sw(*)(char const*, ...);
enum class AccessSpec : u32 enum class AccessSpec : u32
{ {
Default, Default,
Public,
Protected,
Private, Private,
Protected,
Public,
Num_AccessSpec, Num_AccessSpec,
Invalid, Invalid,
@ -30,9 +30,9 @@ char const* to_str( AccessSpec type )
local_persist local_persist
char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = { char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = {
"", "",
"public",
"protected",
"private", "private",
"protected",
"public",
}; };
if ( type > AccessSpec::Public ) if ( type > AccessSpec::Public )

View File

@ -41,3 +41,7 @@ MemberOfPointer, "->"
PtrToMemOfPtr, "->*" PtrToMemOfPtr, "->*"
FunctionCall, "()" FunctionCall, "()"
Comma, "," Comma, ","
New, "new"
NewArray, "new[]"
Delete, "delete"
DeleteArray, "delete[]"

1 Invalid INVALID
41 PtrToMemOfPtr ->*
42 FunctionCall ()
43 Comma ,
44 New new
45 NewArray new[]
46 Delete delete
47 DeleteArray delete[]

View File

@ -250,9 +250,9 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
char const* attribute_str = attribute_strs[idx].string; char const* attribute_str = attribute_strs[idx].string;
char const* entry_to_str = attribute_str_strs [idx].string; char const* entry_to_str = attribute_str_strs [idx].string;
attribute_entries.append_fmt( "%s,\n", attribute_str ); attribute_entries.append_fmt( "Attribute_%s,\n", attribute_str );
to_str_attributes.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_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 ); attribute_define_entries.append_fmt( "Entry( Attribute_%s, \"%s\" )", attribute_str, entry_to_str );
if ( idx < attribute_strs.num() - 1 ) if ( idx < attribute_strs.num() - 1 )
attribute_define_entries.append( " \\\n"); attribute_define_entries.append( " \\\n");
@ -265,6 +265,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), attribute_define_entries ); CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), attribute_define_entries );
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS") #pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
// We cannot parse this enum, it has Attribute names as enums
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize( CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
enum Type : u32 enum Type : u32
{ {

View File

@ -151,17 +151,17 @@ SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false SpaceBeforeSquareBrackets: false
SpacesBeforeTrailingComments: 4 SpacesBeforeTrailingComments: 4
SpaceInEmptyBlock: true SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false
SpacesInAngles: true SpacesInAngles: false
SpacesInCStyleCastParentheses: true SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: true SpacesInConditionalStatement: false
SpacesInContainerLiterals: true SpacesInContainerLiterals: false
SpacesInLineCommentPrefix: SpacesInLineCommentPrefix:
Minimum: 1 Minimum: 1
Maximum: 20 Maximum: 20
SpacesInParentheses: true SpacesInParentheses: true
SpacesInSquareBrackets: true SpacesInSquareBrackets: false
Standard: c++17 Standard: c++17