From 5bb6bb31cacc2406c9fb701eb82f8c7ebae03a2e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 8 Oct 2016 15:39:54 +0200 Subject: [PATCH] - added ProcessStruct, analogous to ProcessClass. Now everything should be in place to resolve all constants - inside and outside classes or structs. --- src/zscript/zcc_compile.cpp | 49 +++++++++++++++++++++++++++++++++++-- src/zscript/zcc_compile.h | 1 + 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/zscript/zcc_compile.cpp b/src/zscript/zcc_compile.cpp index d8af55394d..b282c29f3f 100644 --- a/src/zscript/zcc_compile.cpp +++ b/src/zscript/zcc_compile.cpp @@ -82,13 +82,58 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *tnode) case AST_States: case AST_VarDeclarator: case AST_FuncDeclarator: + case AST_Default: break; + + default: + assert(0 && "Unhandled AST node type"); + break; } node = node->SiblingNext; } while (node != cnode->Body); } +//========================================================================== +// +// ZCCCompiler :: ProcessClass +// +//========================================================================== + +void ZCCCompiler::ProcessStruct(ZCC_Struct *cnode, PSymbolTreeNode *tnode) +{ + Structs.Push(ZCC_StructWork(static_cast(cnode), tnode)); + ZCC_StructWork &cls = Structs.Last(); + + auto node = cnode->Body; + + do + { + switch (node->NodeType) + { + case AST_ConstantDef: + if ((tnode = AddNamedNode(static_cast(node)))) + { + cls.Constants.Push(static_cast(node)); break; + } + break; + + case AST_Enum: break; + case AST_EnumTerminator:break; + + // todo + case AST_VarDeclarator: + break; + + default: + assert(0 && "Unhandled AST node type"); + break; + } + node = node->SiblingNext; + } + while (node != cnode->Body); +} + //========================================================================== // // ZCCCompiler Constructor @@ -114,8 +159,8 @@ ZCCCompiler::ZCCCompiler(ZCC_AST &ast, DObject *_outer, PSymbolTable &_symbols, { switch (node->NodeType) { - case AST_Class: ProcessClass(static_cast(node), tnode); break; - case AST_Struct: Structs.Push(ZCC_StructWork(static_cast(node), tnode)); break; + case AST_Class: ProcessClass(static_cast(node), tnode); break; + case AST_Struct: ProcessStruct(static_cast(node), tnode); break; case AST_ConstantDef: Constants.Push(static_cast(node)); break; default: assert(0 && "Default case is just here to make GCC happy. It should never be reached"); } diff --git a/src/zscript/zcc_compile.h b/src/zscript/zcc_compile.h index 8b21f2617e..f92d8ad2dc 100644 --- a/src/zscript/zcc_compile.h +++ b/src/zscript/zcc_compile.h @@ -59,6 +59,7 @@ public: private: void ProcessClass(ZCC_Class *node, PSymbolTreeNode *tnode); + void ProcessStruct(ZCC_Struct *node, PSymbolTreeNode *tnode); void CreateStructTypes(); void CreateClassTypes(); void CompileConstants(const TArray &defs);