Fixes for serializations found with last commit's test.

Should be fine to move on to next major feature....
This commit is contained in:
Edward R. Gonzalez 2023-08-06 13:28:19 -04:00
parent 34f286d218
commit 00f6c45f15
4 changed files with 171 additions and 114 deletions

View File

@ -589,7 +589,7 @@ String AST::to_string()
if ( Name == nullptr) if ( Name == nullptr)
{ {
result.append( "struct\n{\n%s\n};", Body->to_string() ); result.append_fmt( "struct\n{\n%s\n};", Body->to_string() );
break; break;
} }

View File

@ -297,6 +297,7 @@ namespace Parser
case '#': case '#':
{ {
char const* hash = scanner; char const* hash = scanner;
Tokens.append( { hash, 1, TokType::Preprocess_Hash, line, column, false } );
move_forward(); move_forward();
SkipWhitespace(); SkipWhitespace();
@ -354,12 +355,13 @@ namespace Parser
if ( current == '\r' ) if ( current == '\r' )
{ {
move_forward(); // move_forward();
// token.Length++;
} }
if ( current == '\n' ) if ( current == '\n' )
{ {
move_forward(); // move_forward();
// token.Length++; // token.Length++;
break; break;
} }
@ -483,9 +485,15 @@ namespace Parser
} }
} }
if ( current == '\r' )
{
// move_forward();
// content.Length++;
}
if ( current == '\n' ) if ( current == '\n' )
{ {
move_forward(); // move_forward();
// content.Length++; // content.Length++;
break; break;
} }
@ -826,36 +834,38 @@ namespace Parser
if ( current == '/' ) if ( current == '/' )
{ {
token.Type = TokType::Comment; token.Type = TokType::Comment_Start;
token.Length = 2;
Tokens.append( token );
move_forward(); move_forward();
token.Text = scanner; Token content = { scanner, 1, TokType::Comment, line, column, false };
token.Length = 0;
while ( left && current != '\n' && current != '\r' ) while ( left && current != '\n' && current != '\r' )
{ {
move_forward(); move_forward();
token.Length++; content.Length++;
} }
Tokens.append( content );
if ( current == '\r' ) if ( current == '\r' )
{ {
move_forward(); move_forward();
} }
if ( current == '\n' ) if ( current == '\n' )
{ {
move_forward(); move_forward();
// token.Length++;
} }
continue;
} }
else if ( current == '*' ) else if ( current == '*' )
{ {
token.Type = TokType::Comment; token.Type = TokType::Comment_Start;
token.Length = 2;
Tokens.append( token );
move_forward(); move_forward();
token.Text = scanner; Token content = { scanner, 1, TokType::Comment, line, column, false };
token.Length = 0;
bool star = current == '*'; bool star = current == '*';
bool slash = scanner[1] == '/'; bool slash = scanner[1] == '/';
@ -863,14 +873,20 @@ namespace Parser
while ( left && ! at_end ) while ( left && ! at_end )
{ {
move_forward(); move_forward();
token.Length++; content.Length++;
star = current == '*'; star = current == '*';
slash = scanner[1] == '/'; slash = scanner[1] == '/';
at_end = star && slash; at_end = star && slash;
} }
Tokens.append( content );
Token end = { scanner, 2, TokType::Comment_End, line, column, false };
move_forward(); move_forward();
move_forward(); move_forward();
Tokens.append( end );
continue;
} }
} }
goto FoundToken; goto FoundToken;
@ -1116,6 +1132,28 @@ internal CodeUsing parse_using ();
constexpr bool inplace_def = true; constexpr bool inplace_def = true;
internal inline
CodeComment parse_comment()
{
using namespace Parser;
push_scope();
eat( TokType::Comment_Start );
CodeComment
result = (CodeComment) make_code();
result->Type = ECode::Comment;
result->Content = get_cached_string( currtok );
result->Name = result->Content;
eat( TokType::Comment );
if ( check( TokType::Comment_End ) )
eat( TokType::Comment_End );
Context.pop();
return result;
}
internal inline internal inline
CodeDefine parse_define() CodeDefine parse_define()
{ {
@ -2460,6 +2498,9 @@ CodeBody parse_class_struct_body( Parser::TokType which )
Context.Scope->Start = currtok_noskip; Context.Scope->Start = currtok_noskip;
if ( currtok.Type == TokType::Preprocess_Hash )
eat( TokType::Preprocess_Hash );
switch ( currtok_noskip.Type ) switch ( currtok_noskip.Type )
{ {
case TokType::NewLine: case TokType::NewLine:
@ -2467,9 +2508,8 @@ CodeBody parse_class_struct_body( Parser::TokType which )
eat( TokType::NewLine ); eat( TokType::NewLine );
break; break;
case TokType::Comment: case TokType::Comment_Start:
member = def_comment( currtok ); member = parse_comment();
eat( TokType::Comment );
break; break;
case TokType::Access_Public: case TokType::Access_Public:
@ -2819,6 +2859,9 @@ CodeBody parse_global_nspace( CodeT which )
Context.Scope->Start = currtok_noskip; Context.Scope->Start = currtok_noskip;
if ( currtok.Type == TokType::Preprocess_Hash )
eat( TokType::Preprocess_Hash );
switch ( currtok_noskip.Type ) switch ( currtok_noskip.Type )
{ {
case TokType::NewLine: case TokType::NewLine:
@ -2827,9 +2870,8 @@ CodeBody parse_global_nspace( CodeT which )
eat( TokType::NewLine ); eat( TokType::NewLine );
break; break;
case TokType::Comment: case TokType::Comment_Start:
member = def_comment( currtok ); member = parse_comment();
eat( TokType::Comment );
break; break;
case TokType::Decl_Class: case TokType::Decl_Class:
@ -3141,6 +3183,9 @@ CodeEnum parse_enum( bool inplace_def )
while ( left && currtok_noskip.Type != TokType::BraceCurly_Close ) while ( left && currtok_noskip.Type != TokType::BraceCurly_Close )
{ {
if ( currtok.Type == TokType::Preprocess_Hash )
eat( TokType::Preprocess_Hash );
switch ( currtok_noskip.Type ) switch ( currtok_noskip.Type )
{ {
case TokType::NewLine: case TokType::NewLine:
@ -3148,9 +3193,8 @@ CodeEnum parse_enum( bool inplace_def )
eat( TokType::NewLine ); eat( TokType::NewLine );
break; break;
case TokType::Comment: case TokType::Comment_Start:
member = def_comment( currtok ); member = parse_comment();
eat( TokType::Comment );
break; break;
case TokType::Preprocess_Define: case TokType::Preprocess_Define:
@ -4212,6 +4256,14 @@ CodeUnion parse_union( bool inplace_def )
while ( ! check_noskip( TokType::BraceCurly_Close ) ) while ( ! check_noskip( TokType::BraceCurly_Close ) )
{ {
if ( currtok.Type == TokType::Preprocess_Hash )
eat( TokType::Preprocess_Hash );
if ( currtok.Line >= 3826 )
{
log_fmt("here");
}
Code member = { nullptr }; Code member = { nullptr };
switch ( currtok_noskip.Type ) switch ( currtok_noskip.Type )
{ {
@ -4221,9 +4273,8 @@ CodeUnion parse_union( bool inplace_def )
eat( TokType::NewLine ); eat( TokType::NewLine );
break; break;
case TokType::Comment: case TokType::Comment_Start:
member = def_comment( currtok ); member = parse_comment();
eat( TokType::Comment );
break; break;
case TokType::Decl_Class: case TokType::Decl_Class:

View File

@ -15,94 +15,97 @@ namespace Parser
Entry( API_Import, "GEN_API_Import_Code" ) Entry( API_Import, "GEN_API_Import_Code" )
#endif #endif
# define Define_TokType \ # define Define_TokType \
Entry( Invalid, "INVALID" ) \ Entry( Invalid, "INVALID" ) \
Entry( Access_Private, "private" ) \ Entry( Access_Private, "private" ) \
Entry( Access_Protected, "protected" ) \ Entry( Access_Protected, "protected" ) \
Entry( Access_Public, "public" ) \ Entry( Access_Public, "public" ) \
Entry( Access_MemberSymbol, "." ) \ Entry( Access_MemberSymbol, "." ) \
Entry( Access_StaticSymbol, "::") \ Entry( Access_StaticSymbol, "::") \
Entry( Ampersand, "&" ) \ Entry( Ampersand, "&" ) \
Entry( Ampersand_DBL, "&&" ) \ Entry( Ampersand_DBL, "&&" ) \
Entry( Assign_Classifer, ":" ) \ Entry( Assign_Classifer, ":" ) \
Entry( Attribute_Open, "[[" ) \ Entry( Attribute_Open, "[[" ) \
Entry( Attribute_Close, "]]" ) \ Entry( Attribute_Close, "]]" ) \
Entry( BraceCurly_Open, "{" ) \ Entry( BraceCurly_Open, "{" ) \
Entry( BraceCurly_Close, "}" ) \ Entry( BraceCurly_Close, "}" ) \
Entry( BraceSquare_Open, "[" ) \ Entry( BraceSquare_Open, "[" ) \
Entry( BraceSquare_Close, "]" ) \ Entry( BraceSquare_Close, "]" ) \
Entry( Capture_Start, "(" ) \ Entry( Capture_Start, "(" ) \
Entry( Capture_End, ")" ) \ Entry( Capture_End, ")" ) \
Entry( Comment, "__comment__" ) \ Entry( Comment, "__comment__" ) \
Entry( Char, "__character__" ) \ Entry( Comment_End, "__comment_end__" ) \
Entry( Comma, "," ) \ Entry( Comment_Start, "__comment start__" ) \
Entry( Decl_Class, "class" ) \ Entry( Char, "__character__" ) \
Entry( Decl_GNU_Attribute, "__attribute__" ) \ Entry( Comma, "," ) \
Entry( Decl_MSVC_Attribute, "__declspec" ) \ Entry( Decl_Class, "class" ) \
Entry( Decl_Enum, "enum" ) \ Entry( Decl_GNU_Attribute, "__attribute__" ) \
Entry( Decl_Extern_Linkage, "extern" ) \ Entry( Decl_MSVC_Attribute, "__declspec" ) \
Entry( Decl_Friend, "friend" ) \ Entry( Decl_Enum, "enum" ) \
Entry( Decl_Module, "module" ) \ Entry( Decl_Extern_Linkage, "extern" ) \
Entry( Decl_Namespace, "namespace" ) \ Entry( Decl_Friend, "friend" ) \
Entry( Decl_Operator, "operator" ) \ Entry( Decl_Module, "module" ) \
Entry( Decl_Struct, "struct" ) \ Entry( Decl_Namespace, "namespace" ) \
Entry( Decl_Template, "template" ) \ Entry( Decl_Operator, "operator" ) \
Entry( Decl_Typedef, "typedef" ) \ Entry( Decl_Struct, "struct" ) \
Entry( Decl_Using, "using" ) \ Entry( Decl_Template, "template" ) \
Entry( Decl_Union, "union" ) \ Entry( Decl_Typedef, "typedef" ) \
Entry( Identifier, "__identifier__" ) \ Entry( Decl_Using, "using" ) \
Entry( Module_Import, "import" ) \ Entry( Decl_Union, "union" ) \
Entry( Module_Export, "export" ) \ Entry( Identifier, "__identifier__" ) \
Entry( NewLine, "__NewLine__" ) \ Entry( Module_Import, "import" ) \
Entry( Number, "__number__" ) \ Entry( Module_Export, "export" ) \
Entry( Operator, "__operator__" ) \ Entry( NewLine, "__NewLine__" ) \
Entry( Preprocess_Define, "define") \ Entry( Number, "__number__" ) \
Entry( Preprocess_If, "if") \ Entry( Operator, "__operator__" ) \
Entry( Preprocess_IfDef, "ifdef") \ Entry( Preprocess_Hash, "#" ) \
Entry( Preprocess_IfNotDef, "ifndef") \ Entry( Preprocess_Define, "define") \
Entry( Preprocess_ElIf, "elif") \ Entry( Preprocess_If, "if") \
Entry( Preprocess_Else, "else") \ Entry( Preprocess_IfDef, "ifdef") \
Entry( Preprocess_EndIf, "endif") \ Entry( Preprocess_IfNotDef, "ifndef") \
Entry( Preprocess_Include, "include" ) \ Entry( Preprocess_ElIf, "elif") \
Entry( Preprocess_Pragma, "pragma") \ Entry( Preprocess_Else, "else") \
Entry( Preprocess_Content, "__macro_content__") \ Entry( Preprocess_EndIf, "endif") \
Entry( Preprocess_Macro, "__macro__") \ Entry( Preprocess_Include, "include" ) \
Entry( Preprocess_Unsupported, "__unsupported__" ) \ Entry( Preprocess_Pragma, "pragma") \
Entry( Spec_Alignas, "alignas" ) \ Entry( Preprocess_Content, "__macro_content__") \
Entry( Spec_Const, "const" ) \ Entry( Preprocess_Macro, "__macro__") \
Entry( Spec_Consteval, "consteval" ) \ Entry( Preprocess_Unsupported, "__unsupported__" ) \
Entry( Spec_Constexpr, "constexpr" ) \ Entry( Spec_Alignas, "alignas" ) \
Entry( Spec_Constinit, "constinit" ) \ Entry( Spec_Const, "const" ) \
Entry( Spec_Explicit, "explicit" ) \ Entry( Spec_Consteval, "consteval" ) \
Entry( Spec_Extern, "extern" ) \ Entry( Spec_Constexpr, "constexpr" ) \
Entry( Spec_Final, "final" ) \ Entry( Spec_Constinit, "constinit" ) \
Entry( Spec_Global, "global" ) \ Entry( Spec_Explicit, "explicit" ) \
Entry( Spec_Inline, "inline" ) \ Entry( Spec_Extern, "extern" ) \
Entry( Spec_Internal_Linkage, "internal" ) \ Entry( Spec_Final, "final" ) \
Entry( Spec_LocalPersist, "local_persist" ) \ Entry( Spec_Global, "global" ) \
Entry( Spec_Mutable, "mutable" ) \ Entry( Spec_Inline, "inline" ) \
Entry( Spec_NeverInline, "neverinline" ) \ Entry( Spec_Internal_Linkage, "internal" ) \
Entry( Spec_Override, "override" ) \ Entry( Spec_LocalPersist, "local_persist" ) \
Entry( Spec_Static, "static" ) \ Entry( Spec_Mutable, "mutable" ) \
Entry( Spec_ThreadLocal, "thread_local" ) \ Entry( Spec_NeverInline, "neverinline" ) \
Entry( Spec_Volatile, "volatile") \ Entry( Spec_Override, "override" ) \
Entry( Star, "*" ) \ Entry( Spec_Static, "static" ) \
Entry( Statement_End, ";" ) \ Entry( Spec_ThreadLocal, "thread_local" ) \
Entry( StaticAssert, "static_assert" ) \ Entry( Spec_Volatile, "volatile") \
Entry( String, "__string__" ) \ Entry( Star, "*" ) \
Entry( Type_Unsigned, "unsigned" ) \ Entry( Statement_End, ";" ) \
Entry( Type_Signed, "signed" ) \ Entry( StaticAssert, "static_assert" ) \
Entry( Type_Short, "short" ) \ Entry( String, "__string__" ) \
Entry( Type_Long, "long" ) \ Entry( Type_Unsigned, "unsigned" ) \
Entry( Type_char, "char" ) \ Entry( Type_Signed, "signed" ) \
Entry( Type_int, "int" ) \ Entry( Type_Short, "short" ) \
Entry( Type_double, "double" ) \ Entry( Type_Long, "long" ) \
Entry( Type_MS_int8, "__int8" ) \ Entry( Type_char, "char" ) \
Entry( Type_MS_int16, "__int16" ) \ Entry( Type_int, "int" ) \
Entry( Type_MS_int32, "__int32" ) \ Entry( Type_double, "double" ) \
Entry( Type_MS_int64, "__int64" ) \ Entry( Type_MS_int8, "__int8" ) \
Entry( Type_MS_W64, "_W64" ) \ Entry( Type_MS_int16, "__int16" ) \
Entry( Varadic_Argument, "..." ) \ Entry( Type_MS_int32, "__int32" ) \
Entry( Type_MS_int64, "__int64" ) \
Entry( Type_MS_W64, "_W64" ) \
Entry( Varadic_Argument, "..." ) \
Entry( __Attributes_Start, "__attrib_start__" ) Entry( __Attributes_Start, "__attrib_start__" )
namespace ETokType namespace ETokType

View File

@ -16,6 +16,8 @@ BraceSquare_Close, "]"
Capture_Start, "(" Capture_Start, "("
Capture_End, ")" Capture_End, ")"
Comment, "__comemnt__" Comment, "__comemnt__"
Comment_End, "__comment_end__"
Comment_Start, "__comment_start__"
Char, "__character__" Char, "__character__"
Comma, "," Comma, ","
Decl_Class, "class" Decl_Class, "class"
@ -38,6 +40,7 @@ Module_Export, "export"
NewLine, "__new_line__" NewLine, "__new_line__"
Number, "__number__" Number, "__number__"
Operator, "__operator__" Operator, "__operator__"
Preprocess_Hash, "#"
Preprocess_Define, "define" Preprocess_Define, "define"
Preprocess_If, "if" Preprocess_If, "if"
Preprocess_IfDef, "ifdef" Preprocess_IfDef, "ifdef"

1 Invalid __invalid__
16 Capture_Start (
17 Capture_End )
18 Comment __comemnt__
19 Comment_End __comment_end__
20 Comment_Start __comment_start__
21 Char __character__
22 Comma ,
23 Decl_Class class
40 NewLine __new_line__
41 Number __number__
42 Operator __operator__
43 Preprocess_Hash #
44 Preprocess_Define define
45 Preprocess_If if
46 Preprocess_IfDef ifdef