mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
progress
This commit is contained in:
@ -10,7 +10,8 @@ Code Code::Invalid;
|
||||
char const* debug_str(AST* self)
|
||||
{
|
||||
GEN_ASSERT(self != nullptr);
|
||||
String result = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String result_stack = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String* result = & result_stack;
|
||||
|
||||
if ( self->Parent )
|
||||
append_fmt( result, "\n\tParent : %S %S", self->Parent->type_str(), self->Name ? self->Name : "" );
|
||||
@ -356,7 +357,7 @@ char const* debug_str(AST* self)
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
return * result;
|
||||
}
|
||||
|
||||
AST* duplicate(AST* self)
|
||||
@ -391,25 +392,25 @@ void AST::to_string( String& result )
|
||||
#ifdef GEN_DONT_ALLOW_INVALID_CODE
|
||||
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->debug_str() : Name );
|
||||
#else
|
||||
append_fmt( result, "Invalid Code!" );
|
||||
GEN_NS append_fmt( & result, "Invalid Code!" );
|
||||
#endif
|
||||
break;
|
||||
|
||||
case NewLine:
|
||||
GEN_NS append( result,"\n");
|
||||
GEN_NS append( & result,"\n");
|
||||
break;
|
||||
|
||||
case Untyped:
|
||||
case Execution:
|
||||
case Comment:
|
||||
case PlatformAttributes:
|
||||
GEN_NS append( result, Content );
|
||||
GEN_NS append( & result, Content );
|
||||
break;
|
||||
|
||||
case Access_Private:
|
||||
case Access_Protected:
|
||||
case Access_Public:
|
||||
GEN_NS append( result, Name );
|
||||
GEN_NS append( & result, Name );
|
||||
break;
|
||||
|
||||
case Class:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -321,7 +321,7 @@ void deinit()
|
||||
}
|
||||
while ( left--, left );
|
||||
|
||||
destroy(StringCache);
|
||||
destroy(& StringCache);
|
||||
|
||||
free( & CodePools);
|
||||
free( & StringArenas);
|
||||
@ -403,7 +403,7 @@ StringCached get_cached_string( StrC str )
|
||||
}
|
||||
|
||||
String result = string_make( get_string_allocator( str.Len ), str );
|
||||
set<StringCached>(StringCache, key, result );
|
||||
set<StringCached>(& StringCache, key, result );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
||||
StrC value = va_arg( va, StrC );
|
||||
|
||||
u32 key = crc32( token, str_len(token) );
|
||||
|
||||
set(tok_map, key, value );
|
||||
set(& tok_map, key, value );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,15 +474,15 @@ CodeComment def_comment( StrC content )
|
||||
length++;
|
||||
|
||||
str_copy( line, scanner, length );
|
||||
append_fmt(cmt_formatted, "//%.*s", length, line );
|
||||
append_fmt(& cmt_formatted, "//%.*s", length, line );
|
||||
mem_set( line, 0, MaxCommentLineLength );
|
||||
|
||||
scanner += length;
|
||||
}
|
||||
while ( scanner <= end );
|
||||
|
||||
if ( back(cmt_formatted) != '\n' )
|
||||
append( cmt_formatted, "\n" );
|
||||
if ( * back(& cmt_formatted) != '\n' )
|
||||
append( & cmt_formatted, "\n" );
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
@ -490,7 +490,7 @@ CodeComment def_comment( StrC content )
|
||||
result->Name = get_cached_string( cmt_formatted );
|
||||
result->Content = result->Name;
|
||||
|
||||
free(cmt_formatted);
|
||||
free(& cmt_formatted);
|
||||
|
||||
return (CodeComment) result;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ struct Token
|
||||
|
||||
StrC type_str = ETokType::to_str( Type );
|
||||
|
||||
append_fmt( result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
|
||||
append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
|
||||
, Line, Column
|
||||
, type_str.Len, type_str.Ptr
|
||||
, Length, Text
|
||||
@ -341,7 +341,7 @@ s32 lex_preprocessor_directive(
|
||||
append( & Tokens, name );
|
||||
|
||||
u64 key = crc32( name.Text, name.Length );
|
||||
set<StrC>(defines, key, name );
|
||||
set<StrC>(& defines, key, name );
|
||||
}
|
||||
|
||||
Token preprocess_content = { scanner, 0, TokType::Preprocess_Content, line, column, TF_Preprocess };
|
||||
@ -597,7 +597,7 @@ TokArray lex( StrC content )
|
||||
}
|
||||
|
||||
u64 key = crc32( entry.Data, length );
|
||||
set<StrC>(defines, key, entry );
|
||||
set<StrC>(& defines, key, entry );
|
||||
}
|
||||
|
||||
clear(Tokens);
|
||||
|
@ -59,17 +59,17 @@ struct ParseContext
|
||||
}
|
||||
|
||||
String line = string_make( GlobalAllocator, { length, scope_start.Text } );
|
||||
append_fmt( result, "\tScope : %s\n", line );
|
||||
free(line);
|
||||
append_fmt( & result, "\tScope : %s\n", line );
|
||||
free(& line);
|
||||
|
||||
sptr dist = (sptr)last_valid.Text - (sptr)scope_start.Text + 2;
|
||||
sptr length_from_err = dist;
|
||||
String line_from_err = string_make( GlobalAllocator, { length_from_err, last_valid.Text } );
|
||||
|
||||
if ( length_from_err < 100 )
|
||||
append_fmt(result, "\t(%d, %d):%*c\n", last_valid.Line, last_valid.Column, length_from_err, '^' );
|
||||
append_fmt(& result, "\t(%d, %d):%*c\n", last_valid.Line, last_valid.Column, length_from_err, '^' );
|
||||
else
|
||||
append_fmt(result, "\t(%d, %d)\n", last_valid.Line, last_valid.Column );
|
||||
append_fmt(& result, "\t(%d, %d)\n", last_valid.Line, last_valid.Column );
|
||||
|
||||
StackNode* curr_scope = Scope;
|
||||
s32 level = 0;
|
||||
@ -77,11 +77,11 @@ struct ParseContext
|
||||
{
|
||||
if ( curr_scope->Name )
|
||||
{
|
||||
append_fmt(result, "\t%d: %s, AST Name: %.*s\n", level, curr_scope->ProcName.Ptr, curr_scope->Name.Length, curr_scope->Name.Text );
|
||||
append_fmt(& result, "\t%d: %s, AST Name: %.*s\n", level, curr_scope->ProcName.Ptr, curr_scope->Name.Length, curr_scope->Name.Text );
|
||||
}
|
||||
else
|
||||
{
|
||||
append_fmt(result, "\t%d: %s\n", level, curr_scope->ProcName.Ptr );
|
||||
append_fmt(& result, "\t%d: %s\n", level, curr_scope->ProcName.Ptr );
|
||||
}
|
||||
|
||||
curr_scope = curr_scope->Prev;
|
||||
@ -290,7 +290,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
if ( tokleft )
|
||||
move_fwd();
|
||||
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
|
||||
continue;
|
||||
}
|
||||
@ -312,7 +312,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
if ( tokleft )
|
||||
move_fwd();
|
||||
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
|
||||
continue;
|
||||
}
|
||||
@ -326,7 +326,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
scanner += 2;
|
||||
tokleft -= 2;
|
||||
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
|
||||
continue;
|
||||
}
|
||||
@ -345,7 +345,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
if (tokleft)
|
||||
move_fwd();
|
||||
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
|
||||
continue;
|
||||
}
|
||||
@ -354,10 +354,10 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
if (scanner[0] == '\t')
|
||||
{
|
||||
if (pos > last_cut)
|
||||
append( content, cut_ptr, cut_length);
|
||||
append( & content, cut_ptr, cut_length);
|
||||
|
||||
if ( back( content ) != ' ' )
|
||||
append( content, ' ');
|
||||
if ( * back( & content ) != ' ' )
|
||||
append( & content, ' ');
|
||||
|
||||
move_fwd();
|
||||
last_cut = sptr(scanner) - sptr(raw_text.Ptr);
|
||||
@ -373,17 +373,17 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
scanner += 2;
|
||||
tokleft -= 2;
|
||||
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( pos > last_cut )
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
|
||||
// Replace with a space
|
||||
if ( back( content ) != ' ' )
|
||||
append( content, ' ' );
|
||||
if ( * back( & content ) != ' ' )
|
||||
append( & content, ' ' );
|
||||
|
||||
scanner += 2;
|
||||
tokleft -= 2;
|
||||
@ -400,17 +400,17 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
|
||||
move_fwd();
|
||||
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( pos > last_cut )
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
|
||||
// Replace with a space
|
||||
if ( back( content ) != ' ' )
|
||||
append( content, ' ' );
|
||||
if ( * back( & content ) != ' ' )
|
||||
append( & content, ' ' );
|
||||
|
||||
move_fwd();
|
||||
|
||||
@ -421,7 +421,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
// Escaped newlines
|
||||
if ( scanner[0] == '\\' )
|
||||
{
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
|
||||
s32 amount_to_skip = 1;
|
||||
if ( tokleft > 1 && scanner[1] == '\n' )
|
||||
@ -448,7 +448,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
// Consectuive spaces
|
||||
if ( tokleft > 1 && char_is_space( scanner[0] ) && char_is_space( scanner[ 1 ] ) )
|
||||
{
|
||||
append( content, cut_ptr, cut_length );
|
||||
append( & content, cut_ptr, cut_length );
|
||||
do
|
||||
{
|
||||
move_fwd();
|
||||
@ -458,8 +458,9 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
|
||||
|
||||
// Preserve only 1 space of formattting
|
||||
if ( back( content ) != ' ' )
|
||||
append( content, ' ' );
|
||||
char* last = back(& content);
|
||||
if ( last == nullptr || * last != ' ' )
|
||||
append( & content, ' ' );
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -469,7 +470,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
|
||||
|
||||
if ( last_cut < raw_text.Len )
|
||||
{
|
||||
append( content, cut_ptr, raw_text.Len - last_cut );
|
||||
append( & content, cut_ptr, raw_text.Len - last_cut );
|
||||
}
|
||||
|
||||
#undef cut_ptr
|
||||
@ -1040,7 +1041,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
|
||||
if ( attributes )
|
||||
{
|
||||
String fused = string_make_reserve( GlobalAllocator, length(attributes->Content) + length(more_attributes->Content) );
|
||||
append_fmt( fused, "%S %S", attributes->Content, more_attributes->Content );
|
||||
append_fmt( & fused, "%S %S", attributes->Content, more_attributes->Content );
|
||||
|
||||
attributes->Name = get_cached_string(fused);
|
||||
attributes->Content = attributes->Name;
|
||||
|
Reference in New Issue
Block a user