From 5df21998ef4f3453f34ea7892671b7d826737c43 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 23 Jul 2023 23:28:21 -0400 Subject: [PATCH] Should support parsing full definitions within typedef... (need to make tests) --- Readme.md | 1 - project/gen.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 2cdd0db..404bbf5 100644 --- a/Readme.md +++ b/Readme.md @@ -691,7 +691,6 @@ Names or Content fields are interned strings and thus showed be cached using `ge # TODO -* Support defining & parsing full definitions inside a typedef. (For C patterns) * Implement a context stack for the parsing, allows for accurate scope validation for the AST types. * Trailing specifiers ( postfix ) for functions (const, override, final) * Make a more robust test suite. diff --git a/project/gen.cpp b/project/gen.cpp index bb5ff91..b971a32 100644 --- a/project/gen.cpp +++ b/project/gen.cpp @@ -2530,13 +2530,28 @@ CodeType def_type( StrC name, Code arrayexpr, CodeSpecifier specifiers, CodeAttr CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, ModuleFlag mflags ) { + using namespace ECode; + name_check( def_typedef, name ); null_check( def_typedef, type ); - if ( type->Type != ECode::Typename ) + switch ( type->Type ) { - log_failure( "gen::def_typedef: type was not a Typename - %s", type.debug_str() ); - return CodeInvalid; + case Class: + case Class_Fwd: + case Enum: + case Enum_Fwd: + case Enum_Class: + case Enum_Class_Fwd: + case Function_Fwd: + case Struct: + case Struct_Fwd: + case Union: + case Typename: + break; + default: + log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", type.debug_str() ); + return CodeInvalid; } if ( attributes && attributes->Type != ECode::PlatformAttributes ) @@ -6116,8 +6131,11 @@ CodeTypedef parse_typedef( Parser::TokArray& toks, char const* context ) if ( check( TokType::Decl_Enum ) ) type = parse_enum( toks, context ); + else if ( check(TokType::Decl_Class ) ) + type = parse_class( toks, context ); + else if ( check(TokType::Decl_Struct ) ) - type = parse_enum( toks, context ); + type = parse_struct( toks, context ); else if ( check(TokType::Decl_Union) ) type = parse_union( toks, context );