diff --git a/project/gen.cpp b/project/gen.cpp
index c065ee4..309269d 100644
--- a/project/gen.cpp
+++ b/project/gen.cpp
@@ -1974,9 +1974,10 @@ namespace gen
result.append_fmt( "%s ", Attributes->to_string() );
if ( UnderlyingType )
- result.append_fmt( "%s : %s\n{\n"
+ result.append_fmt( "%s : %s\n{\n%s\n};"
, Name
, UnderlyingType->to_string()
+ , Body->to_string()
);
else result.append_fmt( "%s\n{\n%s\n};"
@@ -2025,7 +2026,7 @@ namespace gen
}
else
{
- result.append_fmt( "%s\n{\n$s\n};"
+ result.append_fmt( "%s\n{\n%s\n};"
, Name
, Body->to_string()
);
@@ -2077,7 +2078,7 @@ namespace gen
break;
case Friend:
- result.append_fmt( "friend %s;", Declaration->to_string() );
+ result.append_fmt( "friend %s", Declaration->to_string() );
break;
case Function:
@@ -2091,7 +2092,7 @@ namespace gen
result.append_fmt( "%s\n", Specs->to_string() );
if ( ReturnType )
- result.append_fmt( "%s %s", ReturnType->to_string(), Name );
+ result.append_fmt( "%s %s(", ReturnType->to_string(), Name );
else
result.append_fmt( "%s(", Name );
@@ -2414,7 +2415,9 @@ namespace gen
result.append_fmt( "[%s]", ValueType->ArrExpr->to_string() );
if ( Value )
- result.append_fmt( " = %s;", Value->to_string() );
+ result.append_fmt( " = %s", Value->to_string() );
+
+ result.append( ";" );
break;
}
@@ -3737,7 +3740,7 @@ namespace gen
result->NumEntries++;
- return (CodeParam) result;
+ return result;
}
CodeSpecifier def_specifier( SpecifierT spec )
@@ -3802,7 +3805,7 @@ namespace gen
result->ParentType = parent;
}
- return (CodeStruct) result;
+ return result;
}
CodeTemplate def_template( CodeParam params, Code declaration, ModuleFlag mflags )
@@ -3835,7 +3838,7 @@ namespace gen
result->Params = params;
result->Declaration = declaration;
- return (CodeTemplate) result;
+ return result;
}
CodeType def_type( StrC name, Code arrayexpr, CodeSpecifier specifiers, CodeAttributes attributes )
@@ -3982,7 +3985,7 @@ namespace gen
if ( attributes )
result->Attributes = attributes;
- return (CodeUsing) result;
+ return result;
}
CodeUsingNamespace def_using_namespace( StrC name )
@@ -4436,7 +4439,7 @@ namespace gen
}
va_end(va);
- return (CodeParam) result;
+ return result;
}
CodeParam def_params( s32 num, CodeParam* codes )
diff --git a/project/gen.hpp b/project/gen.hpp
index c5fbff5..db8dfce 100644
--- a/project/gen.hpp
+++ b/project/gen.hpp
@@ -2826,16 +2826,13 @@ namespace gen
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
};
union {
- // Entry Node
- struct {
- AST* Prev;
- AST* Next;
- };
- // Body Node
- struct {
- AST* Front;
- AST* Back;
- };
+ AST* Prev;
+ AST* Front;
+ AST* Last;
+ };
+ union {
+ AST* Next;
+ AST* Back;
};
AST* Parent;
StringCached Name;
@@ -2884,16 +2881,13 @@ namespace gen
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
};
union {
- // Entry Node
- struct {
- AST* Prev;
- AST* Next;
- };
- // Body Node
- struct {
- AST* Front;
- AST* Back;
- };
+ AST* Prev;
+ AST* Front;
+ AST* Last;
+ };
+ union {
+ AST* Next;
+ AST* Back;
};
AST* Parent;
StringCached Name;
@@ -3014,28 +3008,10 @@ namespace gen
{
Using_Code( CodeParam );
- void append( CodeParam other )
- {
- rcast( AST*, ast )->append( (AST*) other.ast );
- }
- CodeParam get( s32 idx )
- {
- CodeParam param = *this;
- do
- {
- if ( ! ++ param )
- return { nullptr };
+ void append( CodeParam other );
- return { (AST_Param*) param.raw()->Next };
- }
- while ( --idx );
-
- return { nullptr };
- }
- bool has_entries()
- {
- return rcast( AST*, ast )->has_entries();
- }
+ CodeParam get( s32 idx );
+ bool has_entries();
AST* raw()
{
return rcast( AST*, ast );
@@ -3063,13 +3039,9 @@ namespace gen
}
CodeParam end()
{
- return { (AST_Param*) rcast( AST*, ast)->Next };
- }
- CodeParam& operator++()
- {
- ast = (AST_Param*) rcast( AST*, ast )->Next;
- return * this;
+ return { (AST_Param*) rcast( AST*, ast)->Last };
}
+ CodeParam& operator++();
CodeParam operator*()
{
return * this;
@@ -3245,7 +3217,7 @@ namespace gen
struct
{
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
- Code Body;
+ Code Value;
};
};
Code Prev;
@@ -3264,7 +3236,7 @@ namespace gen
struct
{
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
- Code Body;
+ CodeBody Body;
};
};
Code Prev;
@@ -3421,8 +3393,8 @@ namespace gen
Code Value;
};
};
- Code Prev;
- Code Next;
+ CodeParam Last;
+ CodeParam Next;
Code Parent;
StringCached Name;
CodeT Type;
@@ -3473,7 +3445,7 @@ namespace gen
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
struct
{
- char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
+ char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
CodeParam Params;
Code Declaration;
};
@@ -3595,7 +3567,7 @@ namespace gen
CodeAttributes Attributes;
CodeSpecifier Specs;
CodeType ValueType;
- char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
+ char _PAD_PROPERTIES_[ sizeof(AST*) ];
Code Value;
};
};
@@ -3995,6 +3967,8 @@ namespace gen
if ( other->Parent )
other = other->duplicate();
+ other->Parent = this;
+
if ( Front == nullptr )
{
Front = other;
@@ -4071,6 +4045,7 @@ namespace gen
return *this;
}
+#pragma region AST & Code Gen Common
#define Define_CodeImpl( Typename ) \
char const* Typename::debug_str() \
{ \
@@ -4200,7 +4175,6 @@ namespace gen
Define_AST_Cast( Var );
#undef Define_AST_Cast
-#pragma region Code Operator Cast Impj
#define Define_CodeCast( type ) \
Code::operator Code ## type() const \
@@ -4233,7 +4207,56 @@ namespace gen
Define_CodeCast( Var );
Define_CodeCast( Body);
#undef Define_CodeCast
-#pragma endregion Code Operater Cast Impl
+#pragma endregion AST & Code Gen Common
+
+ 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;
+ }
CodeBody def_body( CodeT type )
{
diff --git a/scripts/gencpp.natvis b/scripts/gencpp.natvis
index 9d8dc48..eea3db1 100644
--- a/scripts/gencpp.natvis
+++ b/scripts/gencpp.natvis
@@ -244,7 +244,7 @@
- ValueType
- Value
- Parent
- - Prev
+ - Last
- Next
- NumEntries
@@ -531,7 +531,7 @@
- ast->ValueType
- ast->Value
- ast->Parent
- - ast->Prev
+ - ast->Last
- ast->Next
- ast->NumEntries
@@ -568,6 +568,7 @@
{ast->Name} {ast->Type}
- ast->ModuleFlags
+ - ast->Params
- ast->Declaration
- ast->Parent
- ast->Prev
diff --git a/test/Parsed/Array.Parsed.hpp b/test/Parsed/Array.Parsed.hpp
index baa5b86..e2d9cdc 100644
--- a/test/Parsed/Array.Parsed.hpp
+++ b/test/Parsed/Array.Parsed.hpp
@@ -251,7 +251,7 @@ u32 gen_array_file()
gen_array_file;
gen_array_file.open( "array.Parsed.gen.hpp" );
- Code include_zpl = def_include( txt_StrC("Bloat.hpp") );
+ Code include_zpl = def_include( txt_StrC("gen.hpp") );
gen_array_file.print( include_zpl );
gen_array_file.print( def_using_namespace( name(gen)));
diff --git a/test/Parsed/Buffer.Parsed.hpp b/test/Parsed/Buffer.Parsed.hpp
index 7941e31..1c897e2 100644
--- a/test/Parsed/Buffer.Parsed.hpp
+++ b/test/Parsed/Buffer.Parsed.hpp
@@ -165,7 +165,7 @@ u32 gen_buffer_file()
gen_buffer_file;
gen_buffer_file.open( "buffer.Parsed.gen.hpp" );
- gen_buffer_file.print( def_include( txt_StrC("Bloat.hpp")) );
+ gen_buffer_file.print( def_include( txt_StrC("gen.hpp")) );
gen_buffer_file.print( def_using_namespace( name(gen)));
gen_buffer_file.print( gen__buffer_base() );
diff --git a/test/Parsed/HashTable.Parsed.hpp b/test/Parsed/HashTable.Parsed.hpp
index 45ce7d2..ed63ed8 100644
--- a/test/Parsed/HashTable.Parsed.hpp
+++ b/test/Parsed/HashTable.Parsed.hpp
@@ -316,7 +316,7 @@ u32 gen_hashtable_file()
gen_hashtable_file;
gen_hashtable_file.open( "hashtable.Parsed.gen.hpp" );
- gen_hashtable_file.print( def_include( txt_StrC("Bloat.hpp")) );
+ gen_hashtable_file.print( def_include( txt_StrC("gen.hpp")) );
gen_hashtable_file.print( def_include( txt_StrC("Array.Parsed.hpp")) );
gen_hashtable_file.print( def_include( txt_StrC("array.Parsed.gen.hpp")) );
diff --git a/test/Parsed/Ring.Parsed.hpp b/test/Parsed/Ring.Parsed.hpp
index 5480577..c8a3301 100644
--- a/test/Parsed/Ring.Parsed.hpp
+++ b/test/Parsed/Ring.Parsed.hpp
@@ -134,7 +134,7 @@ u32 gen_ring_file()
gen_ring_file;
gen_ring_file.open( "ring.Parsed.gen.hpp" );
- gen_ring_file.print( def_include( txt_StrC("Bloat.hpp")) );
+ gen_ring_file.print( def_include( txt_StrC("gen.hpp")) );
gen_ring_file.print( def_include( txt_StrC("buffer.Parsed.gen.hpp")) );
// gen_ring_file.print( gen__ring_base() );
diff --git a/test/Upfront/Array.Upfront.hpp b/test/Upfront/Array.Upfront.hpp
index a9fce97..d009d89 100644
--- a/test/Upfront/Array.Upfront.hpp
+++ b/test/Upfront/Array.Upfront.hpp
@@ -128,11 +128,11 @@ Code gen__array( StrC type )
CodeFn fill;
{
- CodeParam params = def_params( 3
- , def_param( t_uw, name(begin) )
+ CodeParam params = def_params( args(
+ def_param( t_uw, name(begin) )
, def_param( t_uw, name(end) )
, def_param( t_alias, name(value) )
- );
+ ));
Code body = untyped_str( code(
Header& header = * get_header();
@@ -187,7 +187,7 @@ Code gen__array( StrC type )
, def_execution( code(
Header& header = * get_header();
- ZPL_ASSERT( header.Num > 0 );
+ GEN_ASSERT( header.Num > 0 );
header.Num--;
))
);
@@ -195,7 +195,7 @@ Code gen__array( StrC type )
CodeFn remove_at = def_function( name(remove_at), def_param( t_uw, name(idx)), t_void
, def_execution( code(
Header* header = get_header();
- ZPL_ASSERT( idx < header->Num );
+ GEN_ASSERT( idx < header->Num );
mem_move( header + idx, header + idx + 1, sizeof( Type ) * ( header->Num - idx - 1 ) );
header->Num--;
@@ -334,8 +334,8 @@ u32 gen_array_file()
gen_array_file;
gen_array_file.open( "array.Upfront.gen.hpp" );
- CodeInclude include_zpl = def_include( txt_StrC("Bloat.hpp") );
- gen_array_file.print( include_zpl );
+ CodeInclude include_gen = def_include( txt_StrC("gen.hpp") );
+ gen_array_file.print( include_gen );
gen_array_file.print( def_using_namespace( name(gen)));
diff --git a/test/Upfront/Buffer.Upfront.hpp b/test/Upfront/Buffer.Upfront.hpp
index 8b55a1e..7f8d5cb 100644
--- a/test/Upfront/Buffer.Upfront.hpp
+++ b/test/Upfront/Buffer.Upfront.hpp
@@ -115,7 +115,7 @@ Code gen__buffer( StrC type, sw type_size )
, def_execution( code(
Header& header = get_header();
- ZPL_ASSERT( header.Num + num <= header.Capacity);
+ GEN_ASSERT( header.Num + num <= header.Capacity);
mem_copy( Data + header.Num, values, num * sizeof( Type ) );
@@ -141,7 +141,7 @@ Code gen__buffer( StrC type, sw type_size )
CodeFn free = def_function( name(free), __, t_void
, def_execution( code(
Header& header = get_header();
- zpl::free( header.Backing, & header );
+ gen::free( header.Backing, & header );
))
);
@@ -238,7 +238,7 @@ u32 gen_buffer_file()
gen_buffer_file;
gen_buffer_file.open( "buffer.Upfront.gen.hpp" );
- gen_buffer_file.print( def_include( txt_StrC("Bloat.hpp")) );
+ gen_buffer_file.print( def_include( txt_StrC("gen.hpp")) );
gen_buffer_file.print( def_using_namespace( name(gen)) );
gen_buffer_file.print( gen__buffer_base() );
diff --git a/test/Upfront/HashTable.Upfront.hpp b/test/Upfront/HashTable.Upfront.hpp
index 7dc392e..e0ea189 100644
--- a/test/Upfront/HashTable.Upfront.hpp
+++ b/test/Upfront/HashTable.Upfront.hpp
@@ -151,7 +151,7 @@ Code gen__hashtable( StrC type )
CodeType t_map_proc = def_type( name(MapProc) );
Code body = def_execution( code(
- ZPL_ASSERT_NOT_NULL( map_proc );
+ GEN_ASSERT_NOT_NULL( map_proc );
for ( sw idx = 0; idx < Entries.num(); idx++ )
{
@@ -177,7 +177,7 @@ Code gen__hashtable( StrC type )
CodeType t_map_mut_proc = def_type( name(MapMutProc));
Code body = def_execution( code(
- ZPL_ASSERT_NOT_NULL( map_proc );
+ GEN_ASSERT_NOT_NULL( map_proc );
for ( sw idx = 0; idx < Entries.num(); idx++ )
{
@@ -447,7 +447,7 @@ u32 gen_hashtable_file()
gen_hashtable_file;
gen_hashtable_file.open( "hashtable.Upfront.gen.hpp" );
- gen_hashtable_file.print( def_include( txt_StrC("Bloat.hpp")) );
+ gen_hashtable_file.print( def_include( txt_StrC("gen.hpp")) );
gen_hashtable_file.print( def_include( txt_StrC("Array.Upfront.hpp")) );
gen_hashtable_file.print( def_include( txt_StrC("array.Upfront.gen.hpp")) );
diff --git a/test/Upfront/Ring.Upfront.hpp b/test/Upfront/Ring.Upfront.hpp
index 147169a..1fbd77d 100644
--- a/test/Upfront/Ring.Upfront.hpp
+++ b/test/Upfront/Ring.Upfront.hpp
@@ -192,7 +192,7 @@ u32 gen_ring_file()
gen_ring_file;
gen_ring_file.open( "ring.Upfront.gen.hpp" );
- gen_ring_file.print( def_include( txt_StrC("Bloat.hpp")) );
+ gen_ring_file.print( def_include( txt_StrC("gen.hpp")) );
gen_ring_file.print( def_include( txt_StrC("buffer.Upfront.gen.hpp")) );
gen_ring_file.print( def_using_namespace( name(gen)));
diff --git a/test/Upfront/Sanity.Upfront.hpp b/test/Upfront/Sanity.Upfront.hpp
index f984f3c..e5de5ae 100644
--- a/test/Upfront/Sanity.Upfront.hpp
+++ b/test/Upfront/Sanity.Upfront.hpp
@@ -11,7 +11,7 @@ u32 gen_sanity_upfront()
// Comment
{
- Code comment_test = def_comment( txt_StrC("Sanity check: def_comment test") );
+ CodeComment comment_test = def_comment( txt_StrC("Sanity check: def_comment test") );
gen_sanity_file.print(comment_test);
}
@@ -50,7 +50,7 @@ u32 gen_sanity_upfront()
// Enum
{
- Code fwd = def_enum( name(ETestEnum), NoCode, t_u8 );
+ CodeEnum fwd = def_enum( name(ETestEnum), NoCode, t_u8 );
CodeEnum def;
{
Code body = untyped_str( code(
@@ -62,7 +62,7 @@ u32 gen_sanity_upfront()
def = def_enum( name(ETestEnum), body, t_u8 );
}
- Code fwd_enum_class = def_enum( name(ETestEnumClass), NoCode, t_u8, EnumClass );
+ CodeEnum fwd_enum_class = def_enum( name(ETestEnumClass), NoCode, t_u8, EnumClass );
gen_sanity_file.print(fwd);
gen_sanity_file.print(def);
@@ -73,7 +73,7 @@ u32 gen_sanity_upfront()
// External Linkage
{
- Code body = def_extern_link_body( 1
+ CodeBody body = def_extern_link_body( 1
, def_comment( txt_StrC("Empty extern body") )
);
@@ -114,7 +114,7 @@ u32 gen_sanity_upfront()
// Include
{
- Code include = def_include( txt_StrC("../DummyInclude.hpp") );
+ CodeInclude include = def_include( txt_StrC("../DummyInclude.hpp") );
gen_sanity_file.print(include);
}
@@ -124,9 +124,9 @@ u32 gen_sanity_upfront()
// Module
if (0)
{
- Code module_export = def_module( name(TestModule), ModuleFlag::Export );
- Code module_import = def_module( name(TestModule), ModuleFlag::Import );
- Code module_both = def_module( name(TestModule), ModuleFlag::Export | ModuleFlag::Import );
+ CodeModule module_export = def_module( name(TestModule), ModuleFlag::Export );
+ CodeModule module_import = def_module( name(TestModule), ModuleFlag::Import );
+ CodeModule module_both = def_module( name(TestModule), ModuleFlag::Export | ModuleFlag::Import );
gen_sanity_file.print(module_global_fragment);
gen_sanity_file.print(module_private_fragment);
@@ -141,7 +141,7 @@ u32 gen_sanity_upfront()
{
CodeNamespace namespace_def;
{
- Code body = def_namespace_body( 1
+ CodeBody body = def_namespace_body( 1
, def_comment( txt_StrC("Empty namespace body") )
);
@@ -157,9 +157,9 @@ u32 gen_sanity_upfront()
{
// Going to make a bit flag set of overloads for this.
- Code bitflagtest;
+ CodeEnum bitflagtest;
{
- Code body = def_enum_body( 1, untyped_str( code(
+ CodeBody body = def_enum_body( 1, untyped_str( code(
A = 1 << 0,
B = 1 << 1,
C = 1 << 2
@@ -192,9 +192,9 @@ u32 gen_sanity_upfront()
{
CodeType t_u8_ptr = def_type( name(u8), __, spec_ptr );
- Code op_ptr = def_operator_cast( t_u8_ptr, __ );
+ CodeOpCast op_ptr = def_operator_cast( t_u8_ptr, __ );
- Code op_class = def_class( name(TestOperatorCast), def_class_body( args( op_ptr) ) );
+ CodeClass op_class = def_class( name(TestOperatorCast), def_class_body( args( op_ptr) ) );
gen_sanity_file.print(op_class);
}
@@ -297,8 +297,8 @@ u32 gen_sanity_upfront()
// Variable
{
- Code bss = def_variable( t_u8, name(test_variable) );
- Code data = def_variable( t_u8, name(test_variable2), untyped_str( code( 0x12 )) );
+ CodeVar bss = def_variable( t_u8, name(test_variable) );
+ CodeVar data = def_variable( t_u8, name(test_variable2), untyped_str( code( 0x12 )) );
gen_sanity_file.print(bss);
gen_sanity_file.print(data);
@@ -310,7 +310,7 @@ u32 gen_sanity_upfront()
{
CodeType t_Type = def_type( name(Type) );
- Code tmpl = def_template( def_param( t_class, name(Type) )
+ CodeTemplate tmpl = def_template( def_param( t_class, name(Type) )
, def_function( name(test_template), def_param( t_Type, name(a) ), __
, def_function_body(1, def_comment( txt_StrC("Empty template function body")))
)