Parsing constructors work, finally reached parity.

This commit is contained in:
Edward R. Gonzalez 2023-07-15 23:07:30 -04:00
parent 1e79c9190e
commit 805e69bb40
9 changed files with 74 additions and 58 deletions

View File

@ -2079,6 +2079,9 @@ namespace gen
case Friend: case Friend:
result.append_fmt( "friend %s", Declaration->to_string() ); result.append_fmt( "friend %s", Declaration->to_string() );
if ( result[ result.length() -1 ] != ';' )
result.append( ";" );
break; break;
case Function: case Function:
@ -2221,7 +2224,7 @@ namespace gen
else else
result.append_fmt( "%s", ValueType->to_string() ); result.append_fmt( "%s", ValueType->to_string() );
if ( NumEntries - 1) if ( NumEntries - 1 > 0)
{ {
for ( CodeParam param : Next->cast<CodeParam>() ) for ( CodeParam param : Next->cast<CodeParam>() )
{ {
@ -5382,7 +5385,7 @@ namespace gen
internal CodeType parse_type ( Parser::TokArray& toks, char const* context ); internal CodeType parse_type ( Parser::TokArray& toks, char const* context );
internal CodeTypedef parse_typedef ( Parser::TokArray& toks, char const* context ); internal CodeTypedef parse_typedef ( Parser::TokArray& toks, char const* context );
internal CodeUnion parse_union ( Parser::TokArray& toks, char const* context ); internal CodeUnion parse_union ( Parser::TokArray& toks, char const* context );
internal CodeUsing parse_using ( Parser::TokArray& toks, char const* context ); internal Code parse_using ( Parser::TokArray& toks, char const* context );
internal inline internal inline
Code parse_array_decl( Parser::TokArray& toks, char const* context ) Code parse_array_decl( Parser::TokArray& toks, char const* context )
@ -5535,6 +5538,8 @@ namespace gen
if ( value ) if ( value )
result->Value = value; result->Value = value;
result->NumEntries++;
while ( left while ( left
&& use_template_capture ? && use_template_capture ?
currtok.Type != TokType::Operator && currtok.Text[0] != '>' currtok.Type != TokType::Operator && currtok.Text[0] != '>'
@ -7490,7 +7495,7 @@ namespace gen
} }
internal internal
CodeUsing parse_using( Parser::TokArray& toks, char const* context ) Code parse_using( Parser::TokArray& toks, char const* context )
{ {
using namespace Parser; using namespace Parser;
@ -7531,21 +7536,30 @@ namespace gen
using namespace ECode; using namespace ECode;
CodeUsing Code
result = (CodeUsing) make_code(); result = make_code();
result->Type = is_namespace ? Using_Namespace : Using;
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
if ( type ) if ( is_namespace)
result->UnderlyingType = type; {
result->Type = Using_Namespace;
}
else
{
result->Type = Using;
if ( array_expr ) CodeUsing using_code = (CodeUsing) result;
type->ArrExpr = array_expr;
if ( type )
using_code->UnderlyingType = type;
if ( array_expr )
type->ArrExpr = array_expr;
}
return result; return result;
} }
CodeUsing parse_using( StrC def ) Code parse_using( StrC def )
{ {
check_parse_args( parse_using, def ); check_parse_args( parse_using, def );
using namespace Parser; using namespace Parser;

View File

@ -2683,7 +2683,6 @@ namespace gen
{ \ { \
return ast != nullptr; \ return ast != nullptr; \
} }
// operator AST*();
template< class Type > template< class Type >
Type cast() Type cast()
@ -2696,6 +2695,10 @@ namespace gen
return ast; return ast;
} }
Code& operator ++(); Code& operator ++();
Code& operator*()
{
return *this;
}
Using_Code( Code ); Using_Code( Code );
@ -2841,7 +2844,7 @@ namespace gen
union { union {
OperatorT Op; OperatorT Op;
AccessSpec ParentAccess; AccessSpec ParentAccess;
u32 NumEntries; s32 NumEntries;
}; };
}; };
@ -2896,7 +2899,7 @@ namespace gen
union { union {
OperatorT Op; OperatorT Op;
AccessSpec ParentAccess; AccessSpec ParentAccess;
u32 NumEntries; s32 NumEntries;
}; };
}; };
@ -2966,16 +2969,16 @@ namespace gen
return * rcast( Code*, this ); return * rcast( Code*, this );
} }
#pragma region Iterator #pragma region Iterator
Code* begin() Code begin()
{ {
if ( ast ) if ( ast )
return rcast( Code*, & rcast( AST*, ast)->Front ); return { rcast( AST*, ast)->Front };
return nullptr; return { nullptr };
} }
Code* end() Code end()
{ {
return nullptr; return { rcast(AST*, ast)->Back->Next };
} }
#pragma endregion Iterator #pragma endregion Iterator
@ -3130,7 +3133,8 @@ namespace gen
Code Parent; Code Parent;
StringCached Name; StringCached Name;
CodeT Type; CodeT Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ]; char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
s32 NumEntries;
}; };
static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Filtered is not the same size as AST"); static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Filtered is not the same size as AST");
@ -3399,7 +3403,7 @@ namespace gen
StringCached Name; StringCached Name;
CodeT Type; CodeT Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) ]; char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
u32 NumEntries; s32 NumEntries;
}; };
static_assert( sizeof(AST_Param) == sizeof(AST), "ERROR: AST_Param is not the same size as AST"); static_assert( sizeof(AST_Param) == sizeof(AST), "ERROR: AST_Param is not the same size as AST");
@ -3412,7 +3416,7 @@ namespace gen
StringCached Name; StringCached Name;
CodeT Type; CodeT Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) ]; char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
u32 NumEntries; s32 NumEntries;
}; };
static_assert( sizeof(AST_Specifier) == sizeof(AST), "ERROR: AST_Specifier is not the same size as AST"); static_assert( sizeof(AST_Specifier) == sizeof(AST), "ERROR: AST_Specifier is not the same size as AST");
@ -3721,7 +3725,7 @@ namespace gen
CodeType parse_type ( StrC type_def ); CodeType parse_type ( StrC type_def );
CodeTypedef parse_typedef ( StrC typedef_def ); CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def ); CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def ); Code parse_using ( StrC using_def );
CodeVar parse_variable ( StrC var_def ); CodeVar parse_variable ( StrC var_def );
# endif # endif
# pragma endregion Parsing # pragma endregion Parsing

View File

@ -32,7 +32,7 @@ Code gen__array( StrC type )
name = { name_len, name_str }; name = { name_len, name_str };
}; };
Code array = parse_struct( token_fmt( "ArrayType", name, "type", type, CodeStruct array = parse_struct( token_fmt( "ArrayType", name, "type", type,
stringize( stringize(
struct <ArrayType> struct <ArrayType>
{ {
@ -108,7 +108,7 @@ Code gen__array( StrC type )
void free( void ) void free( void )
{ {
Header& header = get_header(); Header& header = get_header();
zpl::free( header.Allocator, &header ); gen::free( header.Allocator, &header );
} }
Header& get_header( void ) Header& get_header( void )
@ -136,14 +136,14 @@ Code gen__array( StrC type )
{ {
Header& header = get_header(); Header& header = get_header();
ZPL_ASSERT( header.Num > 0 ); GEN_ASSERT( header.Num > 0 );
header.Num--; header.Num--;
} }
void remove_at( uw idx ) void remove_at( uw idx )
{ {
Header* header = &get_header(); 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 ) ); mem_move( header + idx, header + idx + 1, sizeof( Type ) * ( header->Num - idx - 1 ) );
header->Num--; header->Num--;
@ -195,7 +195,7 @@ Code gen__array( StrC type )
new_header->Num = header.Num; new_header->Num = header.Num;
new_header->Capacity = new_capacity; new_header->Capacity = new_capacity;
zpl::free( header.Allocator, &header ); gen::free( header.Allocator, &header );
Data = ( Type* )new_header + 1; Data = ( Type* )new_header + 1;
return true; return true;
@ -251,8 +251,8 @@ u32 gen_array_file()
gen_array_file; gen_array_file;
gen_array_file.open( "array.Parsed.gen.hpp" ); gen_array_file.open( "array.Parsed.gen.hpp" );
Code include_zpl = def_include( txt_StrC("gen.hpp") ); Code include_gen = def_include( txt_StrC("gen.hpp") );
gen_array_file.print( include_zpl ); gen_array_file.print( include_gen );
gen_array_file.print( def_using_namespace( name(gen))); gen_array_file.print( def_using_namespace( name(gen)));

View File

@ -75,7 +75,7 @@ Code gen__buffer( StrC type )
void append( Type* values, sw num ) void append( Type* values, sw num )
{ {
Header& header = get_header(); 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 ) ); mem_copy( Data + header.Num, values, num * sizeof( Type ) );
header.Num += num; header.Num += num;
@ -96,7 +96,7 @@ Code gen__buffer( StrC type )
void free( void ) void free( void )
{ {
Header& header = get_header(); Header& header = get_header();
zpl::free( header.Backing, &header ); gen::free( header.Backing, &header );
} }
Header& get_header( void ) Header& get_header( void )

View File

@ -99,7 +99,7 @@ Code gen__hashtable( StrC type )
void map( MapProc map_proc ) void map( MapProc map_proc )
{ {
ZPL_ASSERT_NOT_NULL( map_proc ); GEN_ASSERT_NOT_NULL( map_proc );
for ( sw idx = 0; idx < Entries.num(); idx++ ) for ( sw idx = 0; idx < Entries.num(); idx++ )
{ {
@ -109,7 +109,7 @@ Code gen__hashtable( StrC type )
void map_mut( MapMutProc map_proc ) void map_mut( MapMutProc map_proc )
{ {
ZPL_ASSERT_NOT_NULL( map_proc ); GEN_ASSERT_NOT_NULL( map_proc );
for ( sw idx = 0; idx < Entries.num(); idx++ ) for ( sw idx = 0; idx < Entries.num(); idx++ )
{ {

View File

@ -16,7 +16,7 @@ u32 gen_sanity()
// Typedef // Typedef
{ {
Code u8_typedef = parse_typedef( code( CodeTypedef u8_typedef = parse_typedef( code(
typedef unsigned char u8; typedef unsigned char u8;
)); ));
@ -46,11 +46,11 @@ u32 gen_sanity()
// Enum // Enum
{ {
Code fwd = parse_enum( code( CodeEnum fwd = parse_enum( code(
enum ETestEnum : u8; enum ETestEnum : u8;
)); ));
Code def = parse_enum( code( CodeEnum def = parse_enum( code(
enum ETestEnum : u8 enum ETestEnum : u8
{ {
A, A,
@ -59,7 +59,7 @@ u32 gen_sanity()
}; };
)); ));
Code fwd_enum_class = parse_enum( code( CodeEnum fwd_enum_class = parse_enum( code(
enum class ETestEnumClass : u8; enum class ETestEnumClass : u8;
)); ));
@ -89,11 +89,11 @@ u32 gen_sanity()
// Friend // Friend
{ {
Code fwd = parse_class( code( CodeClass fwd = parse_class( code(
class TestFriendClass; class TestFriendClass;
)); ));
Code def = parse_class( code( CodeClass def = parse_class( code(
class TestFriend class TestFriend
{ {
friend class TestFriendClass; friend class TestFriendClass;
@ -143,7 +143,7 @@ u32 gen_sanity()
// Operator // Operator
{ {
Code bitflagtest = parse_enum( code( CodeEnum bitflagtest = parse_enum( code(
enum class EBitFlagTest : u8 enum class EBitFlagTest : u8
{ {
A = 1 << 0, A = 1 << 0,
@ -152,11 +152,11 @@ u32 gen_sanity()
}; };
)); ));
Code op_fwd = parse_operator( code( CodeOperator op_fwd = parse_operator( code(
EBitFlagTest operator | ( EBitFlagTest a, EBitFlagTest b ); EBitFlagTest operator | ( EBitFlagTest a, EBitFlagTest b );
)); ));
Code op_or = parse_operator( code( CodeOperator op_or = parse_operator( code(
EBitFlagTest operator | ( EBitFlagTest a, EBitFlagTest b ) EBitFlagTest operator | ( EBitFlagTest a, EBitFlagTest b )
{ {
return EBitFlagTest( (u8)a | (u8)b ); return EBitFlagTest( (u8)a | (u8)b );
@ -211,12 +211,12 @@ u32 gen_sanity()
// Specifiers // Specifiers
{ {
Code fwd_fn = parse_function( code( CodeFn fwd_fn = parse_function( code(
inline inline
void test_function_specifiers(); void test_function_specifiers();
)); ));
Code typedef_u8_ptr = parse_typedef( code( CodeTypedef typedef_u8_ptr = parse_typedef( code(
typedef u8* u8_ptr; typedef u8* u8_ptr;
)); ));
@ -258,7 +258,7 @@ u32 gen_sanity()
gen_sanity_file.print( parse_typedef( code( typedef unsigned short u16; )) ); gen_sanity_file.print( parse_typedef( code( typedef unsigned short u16; )) );
gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) ); gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) );
Code def = parse_union( code( CodeUnion def = parse_union( code(
union TestUnion union TestUnion
{ {
u8 a; u8 a;
@ -275,18 +275,18 @@ u32 gen_sanity()
// Using // Using
{ {
Code reg = parse_using( code( CodeUsing reg = (CodeUsing) parse_using( code(
using TestUsing = u8; using TestUsing = u8;
)); ));
Code nspace = parse_namespace( code( CodeNamespace nspace = parse_namespace( code(
namespace TestNamespace namespace TestNamespace
{ {
}; };
)); ));
Code npspace_using = parse_using( code( CodeUsingNamespace npspace_using = (CodeUsingNamespace) parse_using( code(
using namespace TestNamespace; using namespace TestNamespace;
)); ));
@ -299,11 +299,11 @@ u32 gen_sanity()
// Variable // Variable
{ {
Code bss = parse_variable( code( CodeVar bss = parse_variable( code(
u8 test_variable; u8 test_variable;
)); ));
Code data = parse_variable( code( CodeVar data = parse_variable( code(
u8 test_variable = 0x12; u8 test_variable = 0x12;
)); ));
@ -317,7 +317,7 @@ u32 gen_sanity()
{ {
#pragma push_macro("template") #pragma push_macro("template")
#undef template #undef template
Code tmpl = parse_template( code( CodeTemplate tmpl = parse_template( code(
template< typename Type > template< typename Type >
void test_template( Type a ) void test_template( Type a )
{ {

View File

@ -24,7 +24,7 @@ Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 )
Array<CodeVar> vars = Array<CodeVar>::init( var_arena );; Array<CodeVar> vars = Array<CodeVar>::init( var_arena );;
CodeStruct soa = def_struct( name, def_body( ECode::Struct_Body )); CodeStruct soa = def_struct( name, def_struct_body( args( soa_entry ) ));
{ {
for ( Code struct_mem : struct_def->Body ) for ( Code struct_mem : struct_def->Body )
{ {

View File

@ -11,7 +11,7 @@ includes = include_directories(
# get_sources = files('./get_sources.ps1') # get_sources = files('./get_sources.ps1')
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n')) # sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
sources = [ '../test.Upfront.cpp' ] sources = [ '../test.cpp' ]
if get_option('buildtype').startswith('debug') if get_option('buildtype').startswith('debug')

View File

@ -1,7 +1,6 @@
#ifdef gen_time #ifdef gen_time
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_FEATURE_PARSING #define GEN_FEATURE_PARSING
#include "Upfront\Sanity.Upfront.hpp"
#include "Parsed\Array.Parsed.hpp" #include "Parsed\Array.Parsed.hpp"
#include "Parsed\Buffer.Parsed.hpp" #include "Parsed\Buffer.Parsed.hpp"
#include "Parsed\HashTable.Parsed.hpp" #include "Parsed\HashTable.Parsed.hpp"
@ -42,7 +41,7 @@ int gen_main()
using u16 = unsigned short; using u16 = unsigned short;
))); )));
soa_test.print( def_include( txt_StrC("Bloat.hpp"))); soa_test.print( def_include( txt_StrC("gen.hpp")));
soa_test.print( def_using_namespace( name(gen) ) ); soa_test.print( def_using_namespace( name(gen) ) );
@ -55,8 +54,7 @@ int gen_main()
u32 C; u32 C;
u64 D; u64 D;
}; };
)), ))
128
)); ));
soa_test.write(); soa_test.write();