first serialization of singlehearder without asserts. (Still failing after around 4k lines.

This commit is contained in:
Edward R. Gonzalez 2023-08-01 16:07:47 -04:00
parent 0f16d1131e
commit 684569750d
6 changed files with 55 additions and 31 deletions

View File

@ -448,7 +448,7 @@ String AST::to_string()
{ {
if ( Specs ) if ( Specs )
{ {
result.append_fmt( "operator %s()" ); result.append_fmt( "operator %s()", EOperator::to_str( Op ) );
CodeSpecifiers specs = cast<CodeSpecifiers>(); CodeSpecifiers specs = cast<CodeSpecifiers>();
@ -488,6 +488,12 @@ String AST::to_string()
case Parameters: case Parameters:
{ {
if ( ValueType == nullptr )
{
result.append_fmt( "%s", Name );
break;
}
if ( Name ) if ( Name )
result.append_fmt( "%s %s", ValueType->to_string(), Name ); result.append_fmt( "%s %s", ValueType->to_string(), Name );
@ -508,39 +514,39 @@ String AST::to_string()
break; break;
case Preprocess_Define: case Preprocess_Define:
result.append_fmt( "#define %s %s\n", Name, Content ); result.append_fmt( "#define %s %s", Name, Content );
break; break;
case Preprocess_If: case Preprocess_If:
result.append_fmt( "#if %s\n", Content ); result.append_fmt( "#if %s", Content );
break; break;
case Preprocess_IfDef: case Preprocess_IfDef:
result.append_fmt( "#ifdef %s\n", Content ); result.append_fmt( "#ifdef %s", Content );
break; break;
case Preprocess_IfNotDef: case Preprocess_IfNotDef:
result.append_fmt( "#ifndef %s\n", Content ); result.append_fmt( "#ifndef %s", Content );
break; break;
case Preprocess_Include: case Preprocess_Include:
result.append_fmt( "#include \"%s\"\n", Content ); result.append_fmt( "#include \"%s\"", Content );
break; break;
case Preprocess_ElIf: case Preprocess_ElIf:
result.append_fmt( "#elif %s\n", Content ); result.append_fmt( "#elif %s", Content );
break; break;
case Preprocess_Else: case Preprocess_Else:
result.append_fmt( "#else\n" ); result.append_fmt( "#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:
result.append_fmt( "#pragma %s\n", Content ); result.append_fmt( "#pragma %s", Content );
break; break;
case Specifiers: case Specifiers:

View File

@ -368,7 +368,7 @@ CodeBody def_body( CodeT type )
} }
Code Code
result = make_code(); result = make_code();
result->Type = type; result->Type = type;
return (CodeBody)result; return (CodeBody)result;
} }

View File

@ -74,6 +74,11 @@ void define_constants()
Code::Invalid = make_code(); Code::Invalid = make_code();
Code::Invalid.set_global(); Code::Invalid.set_global();
t_empty = (CodeType) make_code();
t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt_StrC("") );
t_empty.set_global();
access_private = make_code(); access_private = make_code();
access_private->Type = ECode::Access_Private; access_private->Type = ECode::Access_Private;
access_private->Name = get_cached_string( txt_StrC("private:") ); access_private->Name = get_cached_string( txt_StrC("private:") );
@ -161,11 +166,6 @@ void define_constants()
#endif #endif
# undef def_constant_code_type # undef def_constant_code_type
t_empty = (CodeType) make_code();
t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt_StrC("") );
t_empty.set_global();
# pragma push_macro( "global" ) # pragma push_macro( "global" )
# pragma push_macro( "internal" ) # pragma push_macro( "internal" )
# pragma push_macro( "local_persist" ) # pragma push_macro( "local_persist" )

View File

@ -2036,6 +2036,22 @@ CodeVar parse_variable_after_name(
return result; return result;
} }
internal inline
Code parse_simple_preprocess( Parser::TokType which )
{
using namespace Parser;
push_scope();
Token tok = currtok;
tok.Text = str_fmt_buf( "%.*s\n", tok.Length, tok.Text );
tok.Length++;
Code result = untyped_str( tok );
eat( which );
Context.pop();
return result;
}
internal inline internal inline
Code parse_variable_assignment() Code parse_variable_assignment()
{ {
@ -2070,7 +2086,6 @@ Code parse_variable_assignment()
return expr; return expr;
} }
internal inline internal inline
Code parse_operator_function_or_variable( bool expects_function, CodeAttributes attributes, CodeSpecifiers specifiers ) Code parse_operator_function_or_variable( bool expects_function, CodeAttributes attributes, CodeSpecifiers specifiers )
{ {
@ -2351,8 +2366,7 @@ CodeBody parse_class_struct_body( Parser::TokType which )
break; break;
case TokType::Preprocess_Macro: case TokType::Preprocess_Macro:
member = untyped_str( currtok ); member = parse_simple_preprocess( TokType::Preprocess_Macro );
eat( TokType::Preprocess_Macro );
break; break;
case TokType::Preprocess_Pragma: case TokType::Preprocess_Pragma:
@ -2370,8 +2384,7 @@ CodeBody parse_class_struct_body( Parser::TokType which )
break; break;
case TokType::Preprocess_Unsupported: case TokType::Preprocess_Unsupported:
member = untyped_str( currtok ); member = parse_simple_preprocess( TokType::Preprocess_Unsupported );
eat( TokType::Preprocess_Unsupported );
break; break;
case TokType::StaticAssert: case TokType::StaticAssert:
@ -2687,8 +2700,7 @@ CodeBody parse_global_nspace( CodeT which )
break; break;
case TokType::Preprocess_Macro: case TokType::Preprocess_Macro:
member = untyped_str( currtok ); member = parse_simple_preprocess( TokType::Preprocess_Macro );
eat( TokType::Preprocess_Macro );
break; break;
case TokType::Preprocess_Pragma: case TokType::Preprocess_Pragma:
@ -2706,8 +2718,7 @@ CodeBody parse_global_nspace( CodeT which )
break; break;
case TokType::Preprocess_Unsupported: case TokType::Preprocess_Unsupported:
member = untyped_str( currtok ); member = parse_simple_preprocess( TokType::Preprocess_Unsupported );
eat( TokType::Preprocess_Unsupported );
break; break;
case TokType::StaticAssert: case TokType::StaticAssert:
@ -2892,7 +2903,8 @@ CodeEnum parse_enum( bool inplace_def )
if ( currtok.Type == TokType::BraceCurly_Open ) if ( currtok.Type == TokType::BraceCurly_Open )
{ {
body = (CodeBody) make_code(); body = (CodeBody) make_code();
body->Type = ECode::Enum_Body;
eat( TokType::BraceCurly_Open ); eat( TokType::BraceCurly_Open );
@ -2929,14 +2941,17 @@ CodeEnum parse_enum( bool inplace_def )
break; break;
case TokType::Preprocess_Macro: case TokType::Preprocess_Macro:
member = untyped_str( currtok ); member = parse_simple_preprocess( TokType::Preprocess_Macro );
eat( TokType::Preprocess_Macro );
break; break;
case TokType::Preprocess_Pragma: case TokType::Preprocess_Pragma:
member = parse_pragma(); member = parse_pragma();
break; break;
case TokType::Preprocess_Unsupported:
member = parse_simple_preprocess( TokType::Preprocess_Unsupported );
break;
default: default:
Token entry = currtok; Token entry = currtok;
@ -3986,14 +4001,17 @@ CodeUnion parse_union( bool inplace_def )
break; break;
case TokType::Preprocess_Macro: case TokType::Preprocess_Macro:
member = untyped_str( currtok ); member = parse_simple_preprocess( TokType::Preprocess_Macro );
eat( TokType::Preprocess_Macro );
break; break;
case TokType::Preprocess_Pragma: case TokType::Preprocess_Pragma:
member = parse_pragma(); member = parse_pragma();
break; break;
case TokType::Preprocess_Unsupported:
member = parse_simple_preprocess( TokType::Preprocess_Unsupported );
break;
default: default:
member = parse_variable(); member = parse_variable();
break; break;

View File

@ -28,7 +28,7 @@ void check_singleheader_ast()
} }
Builder builder; Builder builder;
builder.open( "singleheader_copy.hpp" ); builder.open( "singleheader_copy.gen.hpp" );
log_fmt("serializng ast\n"); log_fmt("serializng ast\n");
builder.print( ast ); builder.print( ast );
builder.write(); builder.write();