Library can now construct into AST and serialization itself (singleheader).

Still need to validate if they match.
This commit is contained in:
Edward R. Gonzalez 2023-08-04 16:12:13 -04:00
parent d36c3fa847
commit 34f286d218
23 changed files with 200 additions and 123 deletions

12
.gitignore vendored
View File

@ -6,12 +6,12 @@ build/*
**/*.gen.* **/*.gen.*
**/gen/gen.hpp **/gen/gen.hpp
**/gen/gen.cpp **/gen/gen.cpp
**/gen/gen_dep.hpp **/gen/gen.dep.hpp
**/gen/gen_dep.cpp **/gen/gen.dep.cpp
**/gen/gen_builder.hpp **/gen/gen.builder.hpp
**/gen/gen_builder.cpp **/gen/gen.builder.cpp
**/gen/gen_scanner.hpp **/gen/gen.scanner.hpp
**/gen/gen_scanner.cpp **/gen/gen.scanner.cpp
gencpp.hpp gencpp.hpp
gencpp.cpp gencpp.cpp

View File

@ -14,6 +14,7 @@
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe", "compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
"intelliSenseMode": "windows-clang-x64", "intelliSenseMode": "windows-clang-x64",
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
} }
], ],
"version": 4 "version": 4

View File

@ -29,6 +29,10 @@ String AST::to_string()
log_failure("Attempted to serialize invalid code! - %s", Parent ? Parent->debug_str() : Name ); log_failure("Attempted to serialize invalid code! - %s", Parent ? Parent->debug_str() : Name );
break; break;
case NewLine:
result.append("\n");
break;
case Untyped: case Untyped:
case Execution: case Execution:
result.append( Content ); result.append( Content );
@ -257,7 +261,7 @@ String AST::to_string()
s32 left = NumEntries; s32 left = NumEntries;
while ( left-- ) while ( left-- )
{ {
result.append_fmt( "%s\n", curr.to_string() ); result.append_fmt( "%s", curr.to_string() );
++curr; ++curr;
} }
@ -455,9 +459,9 @@ String AST::to_string()
if ( Specs ) if ( Specs )
{ {
if ( Name && Name.length() ) if ( Name && Name.length() )
result.append_fmt( "%.*soperator %s()", Name.length(), Name, EOperator::to_str( Op )); result.append_fmt( "%.*soperator %s()", Name.length(), Name, ValueType->to_string() );
else else
result.append_fmt( "operator %s()", EOperator::to_str( Op ) ); result.append_fmt( "operator %s()", ValueType->to_string() );
CodeSpecifiers specs = cast<CodeSpecifiers>(); CodeSpecifiers specs = cast<CodeSpecifiers>();
@ -524,9 +528,8 @@ String AST::to_string()
} }
} }
break; break;
case Preprocess_Define: case Preprocess_Define:
result.append_fmt( "#define %s \\\n%s\n", Name, Content ); result.append_fmt( "#define %s %s", Name, Content );
break; break;
case Preprocess_If: case Preprocess_If:
@ -550,11 +553,11 @@ String AST::to_string()
break; break;
case Preprocess_Else: case Preprocess_Else:
result.append_fmt( "#else" ); result.append_fmt( "\n#else" );
break; break;
case Preprocess_EndIf: case Preprocess_EndIf:
result.append_fmt( "#endif\n" ); result.append_fmt( "#endif" );
break; break;
case Preprocess_Pragma: case Preprocess_Pragma:
@ -796,8 +799,21 @@ String AST::to_string()
} }
break; break;
case Class_Body: #if 0
{
Code curr = Front->cast<Code>();
s32 left = NumEntries;
while ( left -- )
{
result.append_fmt( "%s", curr.to_string() );
++curr;
}
}
break;
#endif
case Enum_Body: case Enum_Body:
case Class_Body:
case Extern_Linkage_Body: case Extern_Linkage_Body:
case Function_Body: case Function_Body:
case Global_Body: case Global_Body:
@ -809,7 +825,11 @@ String AST::to_string()
s32 left = NumEntries; s32 left = NumEntries;
while ( left -- ) while ( left -- )
{ {
result.append_fmt( "%s\n", curr.to_string() ); result.append_fmt( "%s", curr.to_string() );
if ( curr->Type != ECode::NewLine )
result.append( "\n" );
++curr; ++curr;
} }
} }

View File

@ -57,6 +57,9 @@ extern CodeAttributes attrib_api_import;
extern Code module_global_fragment; extern Code module_global_fragment;
extern Code module_private_fragment; extern Code module_private_fragment;
// Exposed, but this is really used for parsing.
extern Code fmt_newline;
extern CodePragma pragma_once; extern CodePragma pragma_once;
extern CodeParam param_varadic; extern CodeParam param_varadic;

View File

@ -112,6 +112,10 @@ void define_constants()
module_private_fragment->Content = module_private_fragment->Name; module_private_fragment->Content = module_private_fragment->Name;
module_private_fragment.set_global(); module_private_fragment.set_global();
fmt_newline = make_code();
fmt_newline->Type = ECode::NewLine;
fmt_newline.set_global();
pragma_once = (CodePragma) make_code(); pragma_once = (CodePragma) make_code();
pragma_once->Type = ECode::Untyped; pragma_once->Type = ECode::Untyped;
pragma_once->Name = get_cached_string( txt_StrC("once") ); pragma_once->Name = get_cached_string( txt_StrC("once") );

View File

@ -63,20 +63,29 @@ namespace Parser
bool __eat( TokType type ); bool __eat( TokType type );
Token& current() Token& current( bool skip_new_lines = true )
{ {
while ( Arr[Idx].Type == TokType::Empty_Line ) if ( skip_new_lines )
{
while ( Arr[Idx].Type == TokType::NewLine )
Idx++; Idx++;
}
return Arr[Idx]; return Arr[Idx];
} }
Token& previous() Token& previous( bool skip_new_lines = false )
{ {
s32 idx = this->Idx; s32 idx = this->Idx;
while ( Arr[Idx].Type == TokType::Empty_Line )
if ( skip_new_lines )
{
while ( Arr[idx].Type == TokType::NewLine )
idx--; idx--;
return Arr[idx];
}
return Arr[idx - 1]; return Arr[idx - 1];
} }
@ -86,6 +95,8 @@ namespace Parser
} }
}; };
constexpr bool dont_skip_new_lines = false;
struct StackNode struct StackNode
{ {
StackNode* Prev; StackNode* Prev;
@ -145,7 +156,7 @@ namespace Parser
{ {
if ( curr_scope->Name ) if ( curr_scope->Name )
{ {
result.append_fmt("\t%d: %s, AST Name: %.*s\n", level, curr_scope->ProcName.Ptr, curr_scope->Name.Length, (StrC)curr_scope->Name ); result.append_fmt("\t%d: %s, AST Name: %.*s\n", level, curr_scope->ProcName.Ptr, curr_scope->Name.Length, curr_scope->Name.Text );
} }
else else
{ {
@ -170,19 +181,16 @@ namespace Parser
return false; return false;
} }
if ( Arr[Idx].Type == TokType::Empty_Line && type != TokType::Empty_Line ) if ( Arr[Idx].Type == TokType::NewLine && type != TokType::NewLine )
{ {
Idx++; Idx++;
return log_fmt( "Auto-skipping empty line (%d, %d)\n", current().Line, current().Column );
} }
if ( Arr[Idx].Type != type ) if ( Arr[Idx].Type != type )
{ {
String token_str = String::make( GlobalAllocator, { Arr[Idx].Length, Arr[Idx].Text } ); log_failure( "Parse Error, TokArray::eat, Expected: ' %s ' not ' %.*s ' (%d, %d)`\n%s"
, ETokType::to_str(type).Ptr
log_failure( "Parse Error, TokArray::eat, Expected: ' %s ' not ' %s ' (%d, %d)`\n%s" , Arr[Idx].Length, Arr[Idx].Text
, ETokType::to_str(type)
, token_str
, current().Line , current().Line
, current().Column , current().Column
, Context.to_string() , Context.to_string()
@ -255,27 +263,31 @@ namespace Parser
while (left ) while (left )
{ {
Token token = { nullptr, 0, TokType::Invalid, line, column, false }; Token token = { scanner, 0, TokType::Invalid, line, column, false };
bool is_define = false; bool is_define = false;
if ( column == 1 ) if ( column == 1 )
{ {
token.Text = scanner;
if ( current == '\r') if ( current == '\r')
{
move_forward();
token.Length = 1; token.Length = 1;
}
if ( current == '\n' ) if ( current == '\n' )
{ {
token.Type = TokType::Empty_Line; token.Type = TokType::NewLine;
token.Length ++; token.Length ++;
move_forward();
Tokens.append( token ); Tokens.append( token );
continue; continue;
} }
} }
token.Length = 0;
SkipWhitespace(); SkipWhitespace();
if ( left <= 0 ) if ( left <= 0 )
break; break;
@ -321,27 +333,30 @@ namespace Parser
if ( current == '\r' ) if ( current == '\r' )
{ {
move_forward(); move_forward();
// token.Length++; token.Length++;
} }
if ( current == '\n' ) if ( current == '\n' )
{ {
move_forward(); move_forward();
// token.Length++; token.Length++;
continue; continue;
} }
else else
{ {
String directive_str = String::make_length( GlobalAllocator, token.Text, token.Length );
log_failure( "gen::Parser::lex: Invalid escape sequence '\\%c' (%d, %d)" log_failure( "gen::Parser::lex: Invalid escape sequence '\\%c' (%d, %d)"
" in preprocessor directive (%d, %d)\n%s" " in preprocessor directive (%d, %d)\n%.100s"
, current, line, column , current, line, column
, token.Line, token.Column, directive_str ); , token.Line, token.Column, token.Text );
break; break;
} }
} }
if ( current == '\r' )
{
move_forward();
}
if ( current == '\n' ) if ( current == '\n' )
{ {
move_forward(); move_forward();
@ -353,8 +368,8 @@ namespace Parser
token.Length++; token.Length++;
} }
token.Length = token.Length + token.Text - hash;
token.Text = hash; token.Text = hash;
token.Length = (sptr)token.Text + token.Length - (sptr)hash;
Tokens.append( token ); Tokens.append( token );
continue; // Skip found token, its all handled here. continue; // Skip found token, its all handled here.
} }
@ -817,11 +832,22 @@ namespace Parser
token.Text = scanner; token.Text = scanner;
token.Length = 0; token.Length = 0;
while ( left && current != '\n' ) while ( left && current != '\n' && current != '\r' )
{ {
move_forward(); move_forward();
token.Length++; token.Length++;
} }
if ( current == '\r' )
{
move_forward();
}
if ( current == '\n' )
{
move_forward();
// token.Length++;
}
} }
else if ( current == '*' ) else if ( current == '*' )
{ {
@ -986,6 +1012,17 @@ namespace Parser
move_forward(); move_forward();
token.Length++; token.Length++;
} }
if ( current == '\r' )
{
move_forward();
// token.Length++;
}
if ( current == '\n' )
{
move_forward();
// token.Length++;
}
} }
else else
{ {
@ -1042,16 +1079,14 @@ if ( def.Ptr == nullptr ) \
return CodeInvalid; \ return CodeInvalid; \
} }
# define currtok_noskip Context.Tokens.current( dont_skip_new_lines )
# define currtok Context.Tokens.current() # define currtok Context.Tokens.current()
# define prevtok Context.Tokens.previous() # define prevtok Context.Tokens.previous()
# define eat( Type_ ) Context.Tokens.__eat( Type_ ) # define eat( Type_ ) Context.Tokens.__eat( Type_ )
# define left ( Context.Tokens.Arr.num() - Context.Tokens.Idx ) # define left ( Context.Tokens.Arr.num() - Context.Tokens.Idx )
# define check( Type_ ) \ # define check_noskip( Type_ ) ( left && currtok_noskip.Type == Type_ )
( left \ # define check( Type_ ) ( left && currtok.Type == Type_ )
&& (currtok.Type == TokType::Empty_Line ? \
eat( TokType::Empty_Line) : true) \
&& currtok.Type == Type_ )
# define push_scope() \ # define push_scope() \
StackNode scope { nullptr, currtok, NullToken, txt_StrC( __func__ ) }; \ StackNode scope { nullptr, currtok, NullToken, txt_StrC( __func__ ) }; \
@ -2415,7 +2450,7 @@ CodeBody parse_class_struct_body( Parser::TokType which )
else else
result->Type = Struct_Body; result->Type = Struct_Body;
while ( left && currtok.Type != TokType::BraceCurly_Close ) while ( left && currtok_noskip.Type != TokType::BraceCurly_Close )
{ {
Code member = Code::Invalid; Code member = Code::Invalid;
CodeAttributes attributes = { nullptr }; CodeAttributes attributes = { nullptr };
@ -2423,12 +2458,13 @@ CodeBody parse_class_struct_body( Parser::TokType which )
bool expects_function = false; bool expects_function = false;
switch ( currtok.Type ) Context.Scope->Start = currtok_noskip;
switch ( currtok_noskip.Type )
{ {
case TokType::Empty_Line: case TokType::NewLine:
// Empty lines are auto skipped by Tokens.current() member = fmt_newline;
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] ); eat( TokType::NewLine );
eat( TokType::Empty_Line );
break; break;
case TokType::Comment: case TokType::Comment:
@ -2773,7 +2809,7 @@ CodeBody parse_global_nspace( CodeT which )
result = (CodeBody) make_code(); result = (CodeBody) make_code();
result->Type = which; result->Type = which;
while ( left && currtok.Type != TokType::BraceCurly_Close ) while ( left && currtok_noskip.Type != TokType::BraceCurly_Close )
{ {
Code member = Code::Invalid; Code member = Code::Invalid;
CodeAttributes attributes = { nullptr }; CodeAttributes attributes = { nullptr };
@ -2781,14 +2817,14 @@ CodeBody parse_global_nspace( CodeT which )
bool expects_function = false; bool expects_function = false;
Context.Scope->Start = currtok; Context.Scope->Start = currtok_noskip;
switch ( currtok.Type ) switch ( currtok_noskip.Type )
{ {
case TokType::Empty_Line: case TokType::NewLine:
// Empty lines are auto skipped by Tokens.current() // Empty lines are auto skipped by Tokens.current()
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] ); member = fmt_newline;
eat( TokType::Empty_Line ); eat( TokType::NewLine );
break; break;
case TokType::Comment: case TokType::Comment:
@ -3103,14 +3139,13 @@ CodeEnum parse_enum( bool inplace_def )
Code member = CodeInvalid; Code member = CodeInvalid;
while ( currtok.Type != TokType::BraceCurly_Close ) while ( left && currtok_noskip.Type != TokType::BraceCurly_Close )
{ {
switch ( currtok.Type ) switch ( currtok_noskip.Type )
{ {
case TokType::Empty_Line: case TokType::NewLine:
// Empty lines are auto skipped by Tokens.current() member = untyped_str( currtok_noskip );
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] ); eat( TokType::NewLine );
eat( TokType::Empty_Line );
break; break;
case TokType::Comment: case TokType::Comment:
@ -3160,9 +3195,9 @@ CodeEnum parse_enum( bool inplace_def )
{ {
eat( TokType::Operator ); eat( TokType::Operator );
while ( currtok.Type != TokType::Comma && currtok.Type != TokType::BraceCurly_Close ) while ( currtok_noskip.Type != TokType::Comma && currtok_noskip.Type != TokType::BraceCurly_Close )
{ {
eat( currtok.Type ); eat( currtok_noskip.Type );
} }
} }
@ -3653,15 +3688,15 @@ CodeOpCast parse_operator_cast()
if ( currtok.Type == TokType::BraceCurly_Open ) if ( currtok.Type == TokType::BraceCurly_Open )
level++; level++;
else if ( currtok.Type == TokType::BraceCurly_Close && level > 0 ) else if ( currtok.Type == TokType::BraceCurly_Close )
level--; level--;
eat( currtok.Type ); eat( currtok.Type );
} }
eat( TokType::BraceCurly_Close );
body_str.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body_str.Text; body_str.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body_str.Text;
eat( TokType::BraceCurly_Close );
body = untyped_str( body_str ); body = untyped_str( body_str );
} }
else else
@ -4175,15 +4210,15 @@ CodeUnion parse_union( bool inplace_def )
body = make_code(); body = make_code();
body->Type = ECode::Union_Body; body->Type = ECode::Union_Body;
while ( ! check( TokType::BraceCurly_Close ) ) while ( ! check_noskip( TokType::BraceCurly_Close ) )
{ {
Code member = { nullptr }; Code member = { nullptr };
switch ( currtok.Type ) switch ( currtok_noskip.Type )
{ {
case TokType::Empty_Line: case TokType::NewLine:
// Empty lines are auto skipped by Tokens.current() // Empty lines are auto skipped by Tokens.current()
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] ); member = fmt_newline;
eat( TokType::Empty_Line ); eat( TokType::NewLine );
break; break;
case TokType::Comment: case TokType::Comment:

View File

@ -812,8 +812,13 @@ CodeOperator def_operator( OperatorT op, StrC nspace
return CodeInvalid; return CodeInvalid;
} }
char const* name = str_fmt_buf( "%.*soperator %s", nspace.Len, nspace.Ptr, to_str(op) ); char const* name = nullptr;
StrC op_str = to_str( op );
if ( nspace.Len > 0 )
name = str_fmt_buf( "%.*soperator %.*s", nspace.Len, nspace.Ptr, op_str.Len, op_str.Ptr );
else
name = str_fmt_buf( "operator %.*s", op_str.Len, op_str.Ptr );
CodeOperator CodeOperator
result = (CodeOperator) make_code(); result = (CodeOperator) make_code();
result->Name = get_cached_string( { str_len(name), name } ); result->Name = get_cached_string( { str_len(name), name } );

View File

@ -2,6 +2,8 @@
# error Gen.hpp : GEN_TIME not defined # error Gen.hpp : GEN_TIME not defined
#endif #endif
#include "gen.hpp"
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file. //! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl //! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
#ifndef GEN_ROLL_OWN_DEPENDENCIES #ifndef GEN_ROLL_OWN_DEPENDENCIES

View File

@ -32,6 +32,8 @@ global CodeAttributes attrib_api_import;
global Code module_global_fragment; global Code module_global_fragment;
global Code module_private_fragment; global Code module_private_fragment;
global Code fmt_newline;
global CodeParam param_varadic; global CodeParam param_varadic;
global CodePragma pragma_once; global CodePragma pragma_once;

View File

@ -5,6 +5,7 @@ namespace ECode
# define Define_Types \ # define Define_Types \
Entry( Invalid ) \ Entry( Invalid ) \
Entry( Untyped ) \ Entry( Untyped ) \
Entry( NewLine ) \
Entry( Comment ) \ Entry( Comment ) \
Entry( Access_Private ) \ Entry( Access_Private ) \
Entry( Access_Protected ) \ Entry( Access_Protected ) \

View File

@ -57,14 +57,14 @@ namespace EOperator
}; };
inline inline
char const* to_str( Type op ) StrC to_str( Type op )
{ {
local_persist local_persist
char const* lookup[ Num_Ops ] = { StrC lookup[ Num_Ops ] = {
# define Entry( Type_, Token_ ) stringize(Token_), # define Entry( Type_, Token_ ) { sizeof(stringize(Token_)), stringize(Token_) },
Define_Operators Define_Operators
# undef Entry # undef Entry
"," txt_StrC(",")
}; };
return lookup[ op ]; return lookup[ op ];

View File

@ -50,10 +50,10 @@ namespace Parser
Entry( Decl_Typedef, "typedef" ) \ Entry( Decl_Typedef, "typedef" ) \
Entry( Decl_Using, "using" ) \ Entry( Decl_Using, "using" ) \
Entry( Decl_Union, "union" ) \ Entry( Decl_Union, "union" ) \
Entry( Empty_Line, "__empty_line__" ) \
Entry( Identifier, "__identifier__" ) \ Entry( Identifier, "__identifier__" ) \
Entry( Module_Import, "import" ) \ Entry( Module_Import, "import" ) \
Entry( Module_Export, "export" ) \ Entry( Module_Export, "export" ) \
Entry( NewLine, "__NewLine__" ) \
Entry( Number, "__number__" ) \ Entry( Number, "__number__" ) \
Entry( Operator, "__operator__" ) \ Entry( Operator, "__operator__" ) \
Entry( Preprocess_Define, "define") \ Entry( Preprocess_Define, "define") \
@ -144,12 +144,12 @@ namespace Parser
} }
internal inline internal inline
char const* to_str( Type type ) StrC to_str( Type type )
{ {
local_persist local_persist
char const* lookup[(u32)NumTokens] = StrC lookup[(u32)NumTokens] =
{ {
# define Entry( Name_, Str_ ) Str_, # define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
Define_TokType Define_TokType
GEN_DEFINE_ATTRIBUTE_TOKENS GEN_DEFINE_ATTRIBUTE_TOKENS
# undef Entry # undef Entry

View File

@ -1,5 +1,6 @@
Invalid Invalid
Untyped Untyped
NewLine
Comment Comment
Access_Private Access_Private
Access_Protected Access_Protected

1 Invalid
2 Untyped
3 NewLine
4 Comment
5 Access_Private
6 Access_Protected

View File

@ -26,16 +26,16 @@ Decl_Extern_Linkage, "extern"
Decl_Friend, "friend" Decl_Friend, "friend"
Decl_Module, "module" Decl_Module, "module"
Decl_Namespace, "namespace" Decl_Namespace, "namespace"
Decl_Operator, "__operator__" Decl_Operator, "operator"
Decl_Struct, "struct" Decl_Struct, "struct"
Decl_Template, "template" Decl_Template, "template"
Decl_Typedef, "typedef" Decl_Typedef, "typedef"
Decl_Using, "using" Decl_Using, "using"
Decl_Union, "union" Decl_Union, "union"
Empty_Line, "__empty_line__"
Identifier, "__identifier__" Identifier, "__identifier__"
Module_Import, "import" Module_Import, "import"
Module_Export, "export" Module_Export, "export"
NewLine, "__new_line__"
Number, "__number__" Number, "__number__"
Operator, "__operator__" Operator, "__operator__"
Preprocess_Define, "define" Preprocess_Define, "define"
@ -47,6 +47,7 @@ Preprocess_Else, "else"
Preprocess_EndIf, "endif" Preprocess_EndIf, "endif"
Preprocess_Include, "include" Preprocess_Include, "include"
Preprocess_Pragma, "pragma" Preprocess_Pragma, "pragma"
Preprocess_Content, "__macro_content__"
Preprocess_Macro, "__macro__" Preprocess_Macro, "__macro__"
Preprocess_Unsupported, "__unsupported__" Preprocess_Unsupported, "__unsupported__"
Spec_Alignas, "alignas" Spec_Alignas, "alignas"

1 Invalid __invalid__
26 Decl_Friend friend
27 Decl_Module module
28 Decl_Namespace namespace
29 Decl_Operator __operator__ operator
30 Decl_Struct struct
31 Decl_Template template
32 Decl_Typedef typedef
33 Decl_Using using
34 Decl_Union union
Empty_Line __empty_line__
35 Identifier __identifier__
36 Module_Import import
37 Module_Export export
38 NewLine __new_line__
39 Number __number__
40 Operator __operator__
41 Preprocess_Define define
47 Preprocess_EndIf endif
48 Preprocess_Include include
49 Preprocess_Pragma pragma
50 Preprocess_Content __macro_content__
51 Preprocess_Macro __macro__
52 Preprocess_Unsupported __unsupported__
53 Spec_Alignas alignas

View File

@ -42,10 +42,9 @@ int gen_main()
Code timing = scan_file( "dependencies/timing.hpp" ); Code timing = scan_file( "dependencies/timing.hpp" );
Builder Builder
deps_header = Builder::open("gen/gen_dep.hpp"); deps_header = Builder::open("gen/gen.dep.hpp");
deps_header.print_fmt( generation_notice ); 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( "// 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( header_start );
deps_header.print_fmt( "GEN_NS_BEGIN\n\n" ); deps_header.print_fmt( "GEN_NS_BEGIN\n\n" );
@ -78,7 +77,7 @@ int gen_main()
Code timing = scan_file( "dependencies/timing.cpp" ); Code timing = scan_file( "dependencies/timing.cpp" );
Builder Builder
deps_impl = Builder::open( "gen/gen_dep.cpp" ); deps_impl = Builder::open( "gen/gen.dep.cpp" );
deps_impl.print_fmt( generation_notice ); 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_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( src_start );
@ -148,7 +147,6 @@ int gen_main()
// gen.cpp // gen.cpp
{ {
Code src_start = scan_file( "components/src_start.cpp" ); Code src_start = scan_file( "components/src_start.cpp" );
CodeInclude header = def_include( txt_StrC("gen.hpp") );
Code static_data = scan_file( "components/static_data.cpp" ); Code static_data = scan_file( "components/static_data.cpp" );
Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" ); Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" );
Code ast = scan_file( "components/ast.cpp" ); Code ast = scan_file( "components/ast.cpp" );
@ -165,7 +163,6 @@ int gen_main()
src.print_fmt( generation_notice ); src.print_fmt( generation_notice );
src.print( push_ignores ); src.print( push_ignores );
src.print( src_start ); src.print( src_start );
src.print( header );
src.print_fmt( "\nGEN_NS_BEGIN\n\n"); src.print_fmt( "\nGEN_NS_BEGIN\n\n");
src.print( static_data ); src.print( static_data );
@ -195,8 +192,9 @@ int gen_main()
Code builder = scan_file( "file_processors/builder.hpp" ); Code builder = scan_file( "file_processors/builder.hpp" );
Builder Builder
header = Builder::open( "gen/gen_builder.hpp" ); header = Builder::open( "gen/gen.builder.hpp" );
header.print_fmt( generation_notice ); header.print_fmt( generation_notice );
header.print_fmt( "#pragma once\n\n" );
header.print( def_include( txt_StrC("gen.hpp") )); header.print( def_include( txt_StrC("gen.hpp") ));
header.print_fmt( "\nGEN_NS_BEGIN\n\n" ); header.print_fmt( "\nGEN_NS_BEGIN\n\n" );
header.print( builder ); header.print( builder );
@ -209,9 +207,9 @@ int gen_main()
Code builder = scan_file( "file_processors/builder.cpp" ); Code builder = scan_file( "file_processors/builder.cpp" );
Builder Builder
src = Builder::open( "gen/gen_builder.cpp" ); src = Builder::open( "gen/gen.builder.cpp" );
src.print_fmt( generation_notice ); src.print_fmt( generation_notice );
src.print( def_include( txt_StrC("gen_builder.hpp") ) ); src.print( def_include( txt_StrC("gen.builder.hpp") ) );
src.print_fmt( "\nGEN_NS_BEGIN\n\n" ); src.print_fmt( "\nGEN_NS_BEGIN\n\n" );
src.print( builder ); src.print( builder );
src.print_fmt( "\nGEN_NS_END\n\n" ); src.print_fmt( "\nGEN_NS_END\n\n" );
@ -224,7 +222,9 @@ int gen_main()
Code scanner = scan_file( "file_processors/scanner.hpp" ); Code scanner = scan_file( "file_processors/scanner.hpp" );
Builder Builder
header = Builder::open( "gen/gen_scanner.hpp" ); header = Builder::open( "gen/gen.scanner.hpp" );
header.print_fmt( generation_notice );
header.print_fmt( "#pragma once\n\n" );
header.print( def_include( txt_StrC("gen.hpp") ) ); header.print( def_include( txt_StrC("gen.hpp") ) );
header.print_fmt( "\nGEN_NS_BEGIN\n\n" ); header.print_fmt( "\nGEN_NS_BEGIN\n\n" );
header.print( parsing ); header.print( parsing );
@ -239,8 +239,9 @@ int gen_main()
// Code scanner = scan_file( "file_processors/scanner.cpp" ); // Code scanner = scan_file( "file_processors/scanner.cpp" );
Builder Builder
src = Builder::open( "gen/gen_scanner.cpp" ); src = Builder::open( "gen/gen.scanner.cpp" );
src.print( def_include( txt_StrC("gen_scanner.hpp") ) ); src.print_fmt( generation_notice );
src.print( def_include( txt_StrC("gen.scanner.hpp") ) );
src.print_fmt( "\nGEN_NS_BEGIN\n\n" ); src.print_fmt( "\nGEN_NS_BEGIN\n\n" );
src.print( parsing ); src.print( parsing );
// src.print( scanner ); // src.print( scanner );

View File

@ -6,14 +6,14 @@
# error Gen.hpp : GEN_TIME not defined # error Gen.hpp : GEN_TIME not defined
#endif #endif
#include "gen.hpp"
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file. //! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl //! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
#ifndef GEN_ROLL_OWN_DEPENDENCIES #ifndef GEN_ROLL_OWN_DEPENDENCIES
# include "gen.dep.cpp" # include "gen.dep.cpp"
#endif #endif
#include "gen.hpp"
GEN_NS_BEGIN GEN_NS_BEGIN
#include "components/static_data.cpp" #include "components/static_data.cpp"

View File

@ -256,6 +256,8 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
if ( idx < attribute_strs.num() - 1 ) if ( idx < attribute_strs.num() - 1 )
attribute_define_entries.append( " \\\n"); attribute_define_entries.append( " \\\n");
else
attribute_define_entries.append( "\n");
} }
#pragma push_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" ) #pragma push_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" )

View File

@ -62,9 +62,9 @@ Push-location $path_project
$include = @( $include = @(
'gen.hpp', 'gen.cpp', 'gen.hpp', 'gen.cpp',
'gen_dep.hpp', 'gen_dep.cpp', 'gen.dep.hpp', 'gen.dep.cpp',
'gen_builder.hpp', 'gen_builder.cpp' 'gen.builder.hpp', 'gen.builder.cpp'
'gen_scanner.hpp', 'gen_scanner.cpp' 'gen.scanner.hpp', 'gen.scanner.cpp'
) )
$exclude = $null $exclude = $null

View File

@ -99,9 +99,9 @@ int gen_main()
if ( generate_scanner ) if ( generate_scanner )
{ {
header.print_fmt( "pragma region Parsing\n\n" ); header.print_fmt( "#pragma region Parsing\n\n" );
header.print( scan_file( project_dir "dependencies/parsing.hpp" ) ); header.print( scan_file( project_dir "dependencies/parsing.hpp" ) );
header.print_fmt( "pragma endregion Parsing\n\n" ); header.print_fmt( "#pragma endregion Parsing\n\n" );
} }
header.print_fmt( "GEN_NS_END\n" ); header.print_fmt( "GEN_NS_END\n" );

View File

@ -1,9 +1,9 @@
#if GEN_TIME
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen.hpp" #include "gen/gen.hpp"
#include "gen/gen.builder.hpp"
using namespace gen; using namespace gen;
Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 ) Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 )
@ -118,7 +118,7 @@ void check_SOA()
{ {
log_fmt("\ncheck_SOA:"); log_fmt("\ncheck_SOA:");
gen::init(); gen::init();
Builder soa_test; soa_test.open( "SOA.gen.hpp" ); Builder soa_test = Builder::open( "SOA.gen.hpp" );
soa_test.print( parse_using( code( soa_test.print( parse_using( code(
using u16 = unsigned short; using u16 = unsigned short;
@ -142,4 +142,3 @@ void check_SOA()
gen::deinit(); gen::deinit();
log_fmt(" passed!\n"); log_fmt(" passed!\n");
} }
#endif

View File

@ -1,11 +1,11 @@
// Testing to make sure backend of library is operating properly. // Testing to make sure backend of library is operating properly.
#ifdef GEN_TIME
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen.hpp" #include "gen/gen.hpp"
#include "gen/gen.builder.hpp"
void check_sanity() void check_sanity()
{ {
@ -89,4 +89,3 @@ void check_sanity()
gen::deinit(); gen::deinit();
log_fmt("\nSanity passed!\n"); log_fmt("\nSanity passed!\n");
} }
#endif

View File

@ -2,7 +2,8 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen.cpp" #include "gen/gen.cpp"
#include "gen/gen.builder.cpp"
#include "sanity.cpp" #include "sanity.cpp"
#include "SOA.cpp" #include "SOA.cpp"
#include "test.singleheader_ast.cpp" #include "test.singleheader_ast.cpp"
@ -15,7 +16,7 @@ int gen_main()
// check_sanity(); // check_sanity();
check_SOA(); // check_SOA();
check_singleheader_ast(); check_singleheader_ast();

View File

@ -1,11 +1,10 @@
#pragma once
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK #define GEN_BENCHMARK
#include "gen.hpp" #include "gen/gen.hpp"
#include "file_processors/scanner.hpp" #include "gen/gen.builder.hpp"
#include "gen/gen.scanner.hpp"
using namespace gen; using namespace gen;
void check_singleheader_ast() void check_singleheader_ast()
@ -20,6 +19,7 @@ void check_singleheader_ast()
log_fmt("generated AST!!!\n"); log_fmt("generated AST!!!\n");
#if 0
s32 idx = 0; s32 idx = 0;
for ( Code entry : ast ) for ( Code entry : ast )
{ {
@ -30,9 +30,9 @@ void check_singleheader_ast()
log_fmt("Entry %d: %s\n", idx, entry.to_string() ); log_fmt("Entry %d: %s\n", idx, entry.to_string() );
idx++; idx++;
} }
#endif
Builder builder; Builder builder = Builder::open( "singleheader_copy.gen.hpp" );
builder.open( "singleheader_copy.gen.hpp" );
log_fmt("\n\nserializng ast\n"); log_fmt("\n\nserializng ast\n");
builder.print( ast ); builder.print( ast );
builder.write(); builder.write();