mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
WIP (Broken): Major changes to handling Strings in ast (StringCached defined as StrC)
This commit is contained in:
@ -621,9 +621,9 @@ bool is_equal( Code self, Code other )
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
, debug_str(self) \
|
||||
,debug_str(other) \
|
||||
,debug_str(other) \
|
||||
); \
|
||||
\
|
||||
\
|
||||
return false; \
|
||||
}
|
||||
|
||||
@ -634,7 +634,7 @@ bool is_equal( Code self, Code other )
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
, debug_str(self) \
|
||||
,debug_str(other) \
|
||||
,debug_str(other) \
|
||||
); \
|
||||
\
|
||||
return false; \
|
||||
@ -647,15 +647,15 @@ bool is_equal( Code self, Code other )
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
, debug_str(self) \
|
||||
,debug_str(other) \
|
||||
,debug_str(other) \
|
||||
); \
|
||||
\
|
||||
log_fmt("Content cannot be trusted to be unique with this check " \
|
||||
"so it must be verified by eye for now\n" \
|
||||
"AST Content:\n%S\n" \
|
||||
"Other Content:\n%S\n" \
|
||||
, visualize_whitespace(self->content) \
|
||||
, visualize_whitespace(other->content) \
|
||||
, visualize_whitespace(self->content, GlobalAllocator) \
|
||||
, visualize_whitespace(other->content, GlobalAllocator) \
|
||||
); \
|
||||
}
|
||||
|
||||
@ -669,14 +669,14 @@ bool is_equal( Code self, Code other )
|
||||
"Other: %s\n" \
|
||||
"For ast member: %s\n" \
|
||||
, debug_str(self) \
|
||||
, debug_str(other) \
|
||||
, debug_str(self->ast) \
|
||||
, debug_str(other) \
|
||||
, debug_str(self->ast) \
|
||||
); \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if ( ! is_equal(self->ast, other->ast ) ) \
|
||||
if ( ! is_equal(self->ast, other->ast ) ) \
|
||||
{ \
|
||||
log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \
|
||||
"AST : %S\n" \
|
||||
@ -684,9 +684,9 @@ bool is_equal( Code self, Code other )
|
||||
"For ast member: %S\n" \
|
||||
"other's ast member: %S\n" \
|
||||
, debug_str(self) \
|
||||
, debug_str(other) \
|
||||
, debug_str(self->ast) \
|
||||
, debug_str(other->ast) \
|
||||
, debug_str(other) \
|
||||
, debug_str(self->ast) \
|
||||
, debug_str(other->ast) \
|
||||
); \
|
||||
\
|
||||
return false; \
|
||||
@ -711,7 +711,6 @@ bool is_equal( Code self, Code other )
|
||||
case CT_Untyped:
|
||||
{
|
||||
check_member_content( Content );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1147,19 +1146,19 @@ bool is_equal( Code self, Code other )
|
||||
|
||||
bool validate_body(Code self)
|
||||
{
|
||||
#define CheckEntries( Unallowed_Types ) \
|
||||
do \
|
||||
{ \
|
||||
for ( Code entry : cast(CodeBody, self) ) \
|
||||
{ \
|
||||
switch ( entry->Type ) \
|
||||
{ \
|
||||
Unallowed_Types \
|
||||
log_failure( "AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry) ); \
|
||||
return false; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
#define CheckEntries( Unallowed_Types ) \
|
||||
do \
|
||||
{ \
|
||||
for ( Code entry : cast(CodeBody, self) ) \
|
||||
{ \
|
||||
switch ( entry->Type ) \
|
||||
{ \
|
||||
Unallowed_Types \
|
||||
log_failure( "AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry) ); \
|
||||
return false; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
while (0);
|
||||
|
||||
switch ( self->Type )
|
||||
|
@ -4,7 +4,7 @@
|
||||
#endif
|
||||
|
||||
String to_string(CodeAttributes attributes) {
|
||||
return GEN_NS duplicate( attributes->Content, GlobalAllocator );
|
||||
return {(char*) duplicate( attributes->Content, GlobalAllocator ).Ptr};
|
||||
}
|
||||
|
||||
String to_string(CodeBody body)
|
||||
@ -68,7 +68,7 @@ void to_string_export( CodeBody body, String* result )
|
||||
|
||||
String to_string(CodeComment comment)
|
||||
{
|
||||
return GEN_NS duplicate( comment->Content, GlobalAllocator );
|
||||
return {(char*) duplicate( comment->Content, GlobalAllocator ).Ptr};
|
||||
}
|
||||
|
||||
String to_string(CodeConstructor self)
|
||||
@ -105,7 +105,7 @@ void to_string_def(CodeConstructor self, String* result )
|
||||
append_fmt( result, " : %S", GEN_NS to_string(self->InitializerList) );
|
||||
|
||||
if ( self->InlineCmt )
|
||||
append_fmt( result, " // %S", self->InlineCmt->Content );
|
||||
append_fmt( result, " // %s", self->InlineCmt->Content.Ptr );
|
||||
|
||||
append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
|
||||
}
|
||||
@ -129,7 +129,7 @@ void to_string_fwd(CodeConstructor self, String* result )
|
||||
append_fmt( result, " = %S", GEN_NS to_string(self->Body) );
|
||||
|
||||
if ( self->InlineCmt )
|
||||
append_fmt( result, "; // %S\n", self->InlineCmt->Content );
|
||||
append_fmt( result, "; // %s\n", self->InlineCmt->Content.ptr );
|
||||
else
|
||||
append( result, ";\n" );
|
||||
}
|
||||
@ -187,7 +187,7 @@ void to_string_def( CodeClass self, String* result )
|
||||
|
||||
if ( ast->InlineCmt )
|
||||
{
|
||||
append_fmt( result, " // %S", ast->InlineCmt->Content );
|
||||
append_fmt( result, " // %s", ast->InlineCmt->Content.Ptr );
|
||||
}
|
||||
|
||||
append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
|
||||
@ -417,7 +417,7 @@ void to_string_class_fwd(CodeEnum self, String* result )
|
||||
|
||||
String to_string(CodeExec exec)
|
||||
{
|
||||
return GEN_NS duplicate( exec->Content, GlobalAllocator );
|
||||
return {(char*) duplicate( exec->Content, GlobalAllocator ).Ptr};
|
||||
}
|
||||
|
||||
void to_string(CodeExtern self, String* result )
|
||||
@ -774,7 +774,7 @@ void to_string_def(CodeOpCast self, String* result )
|
||||
}
|
||||
}
|
||||
|
||||
if ( self->Name && length(self->Name) )
|
||||
if ( self->Name && self->Name.Len )
|
||||
append_fmt( result, "%Soperator %S()", self->Name, to_string(self->ValueType) );
|
||||
else
|
||||
append_fmt( result, "operator %S()", to_string(self->ValueType) );
|
||||
@ -792,7 +792,7 @@ void to_string_def(CodeOpCast self, String* result )
|
||||
return;
|
||||
}
|
||||
|
||||
if ( self->Name && length(self->Name) )
|
||||
if ( self->Name && self->Name.Len )
|
||||
append_fmt( result, "%Soperator %S()\n{\n%S\n}\n", self->Name, to_string(self->ValueType), GEN_NS to_string(self->Body) );
|
||||
else
|
||||
append_fmt( result, "operator %S()\n{\n%S\n}\n", to_string(self->ValueType), GEN_NS to_string(self->Body) );
|
||||
|
@ -211,9 +211,9 @@ struct CodeSpecifiers
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
Using_Code( CodeSpecifiers );
|
||||
|
||||
bool append( SpecifierT spec ) { return GEN_NS append(* this, spec); }
|
||||
s32 has( SpecifierT spec ) { return GEN_NS has(* this, spec); }
|
||||
s32 remove( SpecifierT to_remove ) { return GEN_NS remove(* this, to_remove); }
|
||||
bool append( Specifier spec ) { return GEN_NS append(* this, spec); }
|
||||
s32 has( Specifier spec ) { return GEN_NS has(* this, spec); }
|
||||
s32 remove( Specifier to_remove ) { return GEN_NS remove(* this, to_remove); }
|
||||
String to_string() { return GEN_NS to_string(* this ); }
|
||||
void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
|
||||
#endif
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
typedef enum CodeType_Def CodeType;
|
||||
|
||||
enum CodeType_Def : u32
|
||||
{
|
||||
CT_Invalid,
|
||||
@ -71,6 +69,7 @@ enum CodeType_Def : u32
|
||||
CT_Variable,
|
||||
CT_NumTypes
|
||||
};
|
||||
typedef enum CodeType_Def CodeType;
|
||||
|
||||
inline StrC to_str( CodeType type )
|
||||
{
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
typedef enum Operator_Def Operator;
|
||||
|
||||
enum Operator_Def : u32
|
||||
{
|
||||
Op_Invalid,
|
||||
@ -58,6 +56,7 @@ enum Operator_Def : u32
|
||||
Op_DeleteArray,
|
||||
NumOps
|
||||
};
|
||||
typedef enum Operator_Def Operator;
|
||||
|
||||
inline StrC to_str( Operator op )
|
||||
{
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
typedef enum Specifier_Def Specifier;
|
||||
|
||||
enum Specifier_Def : u32
|
||||
{
|
||||
Spec_Invalid,
|
||||
@ -37,6 +35,7 @@ enum Specifier_Def : u32
|
||||
Spec_Volatile,
|
||||
Spec_NumSpecifiers
|
||||
};
|
||||
typedef enum Specifier_Def Specifier;
|
||||
|
||||
inline bool is_trailing( Specifier specifier )
|
||||
{
|
||||
|
@ -8,8 +8,6 @@
|
||||
GEN_NS_PARSER_BEGIN
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
|
||||
|
||||
typedef enum TokType_Def TokType;
|
||||
|
||||
enum TokType_Def : u32
|
||||
{
|
||||
Tok_Invalid,
|
||||
@ -111,6 +109,7 @@ enum TokType_Def : u32
|
||||
Tok_Attribute_API_Import,
|
||||
Tok_NumTokens
|
||||
};
|
||||
typedef enum TokType_Def TokType;
|
||||
|
||||
inline StrC to_str( TokType type )
|
||||
{
|
||||
|
@ -74,9 +74,9 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
|
||||
internal
|
||||
void define_constants()
|
||||
{
|
||||
Code_Global = make_code();
|
||||
scast(String, Code_Global->Name) = get_cached_string( txt("Global Code") );
|
||||
scast(String, Code_Global->Content) = Code_Global->Name;
|
||||
Code_Global = make_code();
|
||||
Code_Global->Name = get_cached_string( txt("Global Code") );
|
||||
Code_Global->Content = Code_Global->Name;
|
||||
|
||||
Code_Invalid = make_code();
|
||||
set_global(Code_Invalid);
|
||||
@ -403,9 +403,9 @@ StringCached get_cached_string( StrC str )
|
||||
}
|
||||
|
||||
String result = string_make( get_string_allocator( str.Len ), str );
|
||||
set<StringCached>(& StringCache, key, result );
|
||||
set(& StringCache, key, { length(result), result } );
|
||||
|
||||
return result;
|
||||
return { length(result), result };
|
||||
}
|
||||
|
||||
// Used internally to retireve a Code object form the CodePool.
|
||||
|
@ -11,13 +11,13 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
||||
local_persist
|
||||
Arena tok_map_arena;
|
||||
|
||||
HashTable<StrC> tok_map;
|
||||
HashTable(StrC) tok_map;
|
||||
{
|
||||
local_persist
|
||||
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
|
||||
|
||||
tok_map_arena = arena_init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
|
||||
tok_map = hashtable_init<StrC>( allocator_info(& tok_map_arena) );
|
||||
tok_map = hashtable_init(StrC, allocator_info(& tok_map_arena) );
|
||||
|
||||
s32 left = num_tokens - 1;
|
||||
|
||||
|
@ -485,7 +485,7 @@ CodeComment def_comment( StrC content )
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = CT_Comment;
|
||||
result->Name = get_cached_string( cmt_formatted );
|
||||
result->Name = get_cached_string( { length(cmt_formatted), cmt_formatted } );
|
||||
result->Content = result->Name;
|
||||
|
||||
free(& cmt_formatted);
|
||||
|
@ -357,7 +357,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
, current
|
||||
, preprocess_content.Line
|
||||
, preprocess_content.Column
|
||||
, directive_str.Data
|
||||
, (char*) directive_str
|
||||
);
|
||||
return Lex_ReturnNull;
|
||||
}
|
||||
@ -578,11 +578,11 @@ TokArray lex( StrC content )
|
||||
return { {}, 0 };
|
||||
}
|
||||
|
||||
foreach( StringCached, entry, PreprocessorDefines )
|
||||
foreach( StringCached*, entry, PreprocessorDefines )
|
||||
{
|
||||
s32 length = 0;
|
||||
char const* scanner = entry.Data;
|
||||
while ( GEN_NS length(entry) > length && (char_is_alphanumeric( *scanner ) || *scanner == '_') )
|
||||
char const* scanner = * entry;
|
||||
while ( entry->Len > length && (char_is_alphanumeric( *scanner ) || *scanner == '_') )
|
||||
{
|
||||
c.scanner++;
|
||||
length ++;
|
||||
@ -592,8 +592,8 @@ TokArray lex( StrC content )
|
||||
length++;
|
||||
}
|
||||
|
||||
u64 key = crc32( entry.Data, length );
|
||||
set(& c.defines, key, (StrC)entry );
|
||||
u64 key = crc32( * entry, length );
|
||||
set(& c.defines, key, (StrC) * entry );
|
||||
}
|
||||
|
||||
clear(Tokens);
|
||||
|
@ -669,7 +669,7 @@ CodeAttributes parse_attributes()
|
||||
|
||||
Code result = make_code();
|
||||
result->Type = CT_PlatformAttributes;
|
||||
result->Name = get_cached_string( name_stripped );
|
||||
result->Name = get_cached_string( { length(name_stripped), name_stripped } );
|
||||
result->Content = result->Name;
|
||||
// result->Token =
|
||||
|
||||
@ -1047,10 +1047,10 @@ CodeBody parse_class_struct_body( TokType which, Token name )
|
||||
|
||||
if ( attributes )
|
||||
{
|
||||
String fused = string_make_reserve( GlobalAllocator, length(attributes->Content) + length(more_attributes->Content) );
|
||||
String fused = string_make_reserve( GlobalAllocator, attributes->Content.Len + more_attributes->Content.Len );
|
||||
append_fmt( & fused, "%S %S", attributes->Content, more_attributes->Content );
|
||||
|
||||
attributes->Name = get_cached_string(fused);
|
||||
attributes->Name = get_cached_string({ length(fused), fused });
|
||||
attributes->Content = attributes->Name;
|
||||
// <Attributes> <Specifiers> <Attributes>
|
||||
}
|
||||
@ -1344,7 +1344,7 @@ CodeDefine parse_define()
|
||||
return define;
|
||||
}
|
||||
|
||||
define->Content = get_cached_string( strip_formatting( to_str(currtok), strip_formatting_dont_preserve_newlines ) );
|
||||
define->Content = get_cached_string( to_strc( strip_formatting( to_str(currtok), strip_formatting_dont_preserve_newlines )) );
|
||||
eat( Tok_Preprocess_Content );
|
||||
// #define <Name> <Content>
|
||||
|
||||
@ -1494,7 +1494,7 @@ CodeFn parse_function_after_name(
|
||||
|
||||
CodeFn
|
||||
result = (CodeFn) make_code();
|
||||
result->Name = get_cached_string( name_stripped );
|
||||
result->Name = get_cached_string( to_strc(name_stripped) );
|
||||
result->ModuleFlags = mflags;
|
||||
|
||||
if ( body )
|
||||
@ -2730,7 +2730,7 @@ CodeParam parse_params( bool use_template_capture )
|
||||
eat( currtok.Type );
|
||||
}
|
||||
|
||||
value = untyped_str( strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines ) );
|
||||
value = untyped_str( to_strc(strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines )) );
|
||||
// ( <Macro> <ValueType> <Name> = <Expression>
|
||||
}
|
||||
}
|
||||
@ -2845,7 +2845,7 @@ CodeParam parse_params( bool use_template_capture )
|
||||
eat( currtok.Type );
|
||||
}
|
||||
|
||||
value = untyped_str( strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines ) );
|
||||
value = untyped_str( to_strc(strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines )) );
|
||||
// ( <Macro> <ValueType> <Name> = <Expression>, <Macro> <ValueType> <Name> = <Expression>
|
||||
}
|
||||
// ( <Macro> <ValueType> <Name> = <Expression>, <Macro> <ValueType> <Name> = <Expression>, ..
|
||||
@ -4132,7 +4132,7 @@ CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
|
||||
Code type = parse_type();
|
||||
// <Specifiers> <Qualifier> :: ... operator <UnderlyingType>
|
||||
|
||||
Context.Scope->Name = { type->Name.Data, length(type->Name) };
|
||||
Context.Scope->Name = { type->Name.Ptr, type->Name.Len };
|
||||
|
||||
eat( Tok_Capture_Start );
|
||||
eat( Tok_Capture_End );
|
||||
@ -4820,7 +4820,7 @@ else if ( currtok.Type == Tok_DeclType )
|
||||
}
|
||||
#endif
|
||||
|
||||
result->Name = get_cached_string( name_stripped );
|
||||
result->Name = get_cached_string( to_strc(name_stripped) );
|
||||
|
||||
if ( attributes )
|
||||
result->Attributes = attributes;
|
||||
|
Reference in New Issue
Block a user