Cleanup and doc updates

This commit is contained in:
2023-08-23 02:17:47 -04:00
parent c97762ac16
commit c81f4b34ee
5 changed files with 733 additions and 71 deletions

View File

@ -38,49 +38,8 @@ String AST::to_string()
case Untyped:
case Execution:
result.append( Content );
break;
case Comment:
{
// TODO : Move this formmating process to def_comment,
// Were going to preserve as much of the original formatting as possible
// so that the parsed comments don't have any artifacts.
// Just doing what untyped and execution do
#if 0
if ( Prev && Prev->Type != Comment && Prev->Type != NewLine )
result.append( "\n" );
static char line[ MaxCommentLineLength ];
char const* end = & scast(String, Content).back();
char* scanner = Content.Data;
s32 curr = 0;
do
{
char const* next = scanner;
s32 length = 0;
while ( next != end && scanner[ length ] != '\n' )
{
next = scanner + length;
length++;
}
length++;
str_copy( line, scanner, length );
result.append_fmt( "//%.*s", length, line );
mem_set( line, 0, MaxCommentLineLength );
scanner += length;
}
while ( scanner <= end );
if ( result.back() != '\n' )
result.append( "\n" );
#else
result.append( Content );
#endif
}
break;
case Access_Private:
@ -148,7 +107,7 @@ String AST::to_string()
result.append_fmt( "class %S %S", Attributes->to_string(), Name );
else result.append_fmt( "class %S", Name );
// Check if it can have an end-statement
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
{
@ -226,7 +185,7 @@ String AST::to_string()
}
else
result.append_fmt( "~%S();", Parent->Name );
if ( InlineCmt )
result.append_fmt( " %S", InlineCmt->Content );
else
@ -364,7 +323,7 @@ String AST::to_string()
{
result.append( ";" );
}
if ( InlineCmt )
result.append_fmt(" %S", InlineCmt->Content );
else
@ -539,7 +498,7 @@ String AST::to_string()
}
}
}
if ( InlineCmt )
result.append_fmt( "; %S", InlineCmt->Content );
else
@ -552,7 +511,7 @@ String AST::to_string()
if ( Specs )
{
// TODO : Add support for specifies before the operator keyword
if ( Name && Name.length() )
result.append_fmt( "%Soperator %S()", Name, ValueType->to_string() );
else
@ -582,7 +541,7 @@ String AST::to_string()
if ( Specs )
{
// TODO : Add support for specifies before the operator keyword
result.append_fmt( "operator %S()", ValueType->to_string() );
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
@ -795,7 +754,7 @@ String AST::to_string()
{
result.append( ";" );
}
if ( InlineCmt )
result.append_fmt(" %S", InlineCmt->Content);
else
@ -872,7 +831,7 @@ String AST::to_string()
}
else
result.append_fmt( "using %S;", Name );
if ( InlineCmt )
result.append_fmt(" %S\n", InlineCmt->Content );
else
@ -927,7 +886,7 @@ String AST::to_string()
else
result.append_fmt( "%S %S;", UnderlyingType->to_string(), Name );
if ( InlineCmt )
result.append_fmt(" %S", InlineCmt->Content);
else

View File

@ -57,7 +57,7 @@ struct AST_Class
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
struct
{
CodeComment InlineCmt;
CodeComment InlineCmt; // Only supported by forward declarations
CodeAttributes Attributes;
char _PAD_SPECS_ [ sizeof(AST*) ];
CodeType ParentType;
@ -81,11 +81,12 @@ struct AST_Constructor
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
struct
{
CodeComment InlineCmt;
char _PAD_PROPERTIES_ [ sizeof(AST*) * 3 ];
Code InitializerList;
CodeParam Params;
Code Body;
CodeComment InlineCmt; // Only supported by forward declarations
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
CodeSpecifiers Specs;
Code InitializerList;
CodeParam Params;
Code Body;
};
};
Code Prev;

View File

@ -1184,7 +1184,7 @@ CodeComment parse_comment()
using namespace Parser;
StackNode scope { nullptr, currtok_noskip, NullToken, txt( __func__ ) };
Context.push( & scope );
CodeComment
result = (CodeComment) make_code();
result->Type = ECode::Comment;
@ -1812,7 +1812,7 @@ CodeFn parse_function_after_name(
{
Token stmt_end = currtok;
eat( TokType::Statement_End );
if ( currtok_noskip.Type && TokType::Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment();
}
@ -1855,7 +1855,7 @@ CodeFn parse_function_after_name(
if ( params )
result->Params = params;
if ( inline_cmt )
result->InlineCmt = inline_cmt;
@ -2142,7 +2142,7 @@ CodeOperator parse_operator_after_ret_type(
{
Token stmt_end = currtok;
eat( TokType::Statement_End );
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment();
}
@ -2152,7 +2152,7 @@ CodeOperator parse_operator_after_ret_type(
if ( inline_cmt )
result->InlineCmt = inline_cmt;
Context.pop();
return result;
}
@ -2319,7 +2319,7 @@ Code parse_simple_preprocess( Parser::TokType which )
{
Token stmt_end = currtok;
eat( TokType::Statement_End );
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
eat( TokType::Comment );
}
@ -2335,7 +2335,7 @@ Code parse_simple_preprocess( Parser::TokType which )
{
Token stmt_end = currtok;
eat( TokType::Statement_End );
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
eat( TokType::Comment );
}
@ -2361,6 +2361,7 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
Code result = CodeInvalid;
#ifndef GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES
if ( currtok.Type == TokType::Preprocess_Macro )
{
// Were dealing with a macro after attributes/specifiers.
@ -2368,6 +2369,7 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
Context.pop();
return result;
}
#endif
CodeType type = parse_type();
@ -3594,12 +3596,12 @@ CodeEnum parse_enum( bool inplace_def )
}
CodeComment inline_cmt = NoCode;
if ( ! inplace_def )
{
Token stmt_end = currtok;
eat( TokType::Statement_End );
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment();
}
@ -3626,7 +3628,7 @@ CodeEnum parse_enum( bool inplace_def )
if ( type )
result->UnderlyingType = type;
if ( inline_cmt )
result->InlineCmt = inline_cmt;
@ -4518,7 +4520,11 @@ CodeTypedef parse_typedef()
constexpr bool from_typedef = true;
#if GEN_PARSER_DISABLE_MACRO_TYPEDEF
if ( false )
#else
if ( check( TokType::Preprocess_Macro ))
#endif
{
type = t_empty;
name = currtok;
@ -4631,10 +4637,10 @@ CodeTypedef parse_typedef()
}
array_expr = parse_array_decl();
Token stmt_end = currtok;
eat( TokType::Statement_End );
CodeComment inline_cmt = NoCode;
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment();
@ -4661,7 +4667,7 @@ CodeTypedef parse_typedef()
if ( type->Type == Typename && array_expr && array_expr->Type != Invalid )
type.cast<CodeType>()->ArrExpr = array_expr;
if ( inline_cmt )
result->InlineCmt = inline_cmt;