From 08f313d0118151f9641d37867020187c9bb33d65 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 8 Oct 2016 22:16:10 +0200 Subject: [PATCH] - implemented complete resolving of constants - both global and class-local. This uses a different algorithm as the old implementation - instead of recursively resolving unknown symbols it will first collect all constants from all scopes and then process them in one operation, doing multiple passes over the list until no more constants can be resolved anymore. --- src/dobjtype.cpp | 11 + src/dobjtype.h | 15 ++ src/info.cpp | 1 - src/zscript/zcc-parse.lemon | 2 + src/zscript/zcc_compile.cpp | 324 +++++++++++++++++----------- src/zscript/zcc_compile.h | 27 ++- src/zscript/zcc_parser.cpp | 3 +- src/zscript/zcc_parser.h | 2 + wadsrc/static/zscript/constants.txt | 3 +- 9 files changed, 252 insertions(+), 136 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 38c9f6fa2..800416612 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -2647,6 +2647,16 @@ void PClass::StaticInit () // Keep built-in classes in consistant order. I did this before, though // I'm not sure if this is really necessary to maintain any sort of sync. qsort(&AllClasses[0], AllClasses.Size(), sizeof(AllClasses[0]), cregcmp); + + // Set all symbol table relations here so that they are valid right from the start. + for (auto c : AllClasses) + { + if (c->ParentClass != nullptr) + { + c->Symbols.SetParentTable(&c->ParentClass->Symbols); + } + } + } //========================================================================== @@ -3131,6 +3141,7 @@ PClass *PClass::FindClassTentative(FName name, bool fatal) type->ParentClass = this; type->Size = TentativeClass; type->bRuntimeClass = true; + type->Symbols.SetParentTable(&Symbols); TypeTable.AddType(type, RUNTIME_CLASS(PClass), (intptr_t)type->Outer, name, bucket); return type; } diff --git a/src/dobjtype.h b/src/dobjtype.h index d2a8aabf5..1b230452b 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -99,6 +99,10 @@ struct PSymbolTable // Sets the table to use for searches if this one doesn't contain the // requested symbol. void SetParentTable (PSymbolTable *parent); + PSymbolTable *GetParentTable() const + { + return ParentSymbolTable; + } // Finds a symbol in the table, optionally searching parent tables // as well. @@ -108,6 +112,7 @@ struct PSymbolTable // specific symbol table the symbol was found in. PSymbol *FindSymbolInTable(FName symname, PSymbolTable *&symtable); + // Places the symbol in the table and returns a pointer to it or NULL if // a symbol with the same name is already in the table. This symbol is // not copied and will be freed when the symbol table is destroyed. @@ -120,6 +125,15 @@ struct PSymbolTable // Frees all symbols from this table. void ReleaseSymbols(); + // add a name to help debugging. +#ifdef _DEBUG + FString name; + void SetName(const char *nm) { name = nm; } +#else + void SetName(const char *) {} +#endif + + private: typedef TMap MapType; @@ -702,6 +716,7 @@ protected: TArray SpecialInits; virtual void Derive(PClass *newclass); void InitializeSpecials(void *addr) const; + void SetSuper(); public: typedef PClassClass MetaClass; MetaClass *GetClass() const; diff --git a/src/info.cpp b/src/info.cpp index 79c8e4268..ea6701fac 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -361,7 +361,6 @@ size_t PClassActor::PropagateMark() void PClassActor::InitializeNativeDefaults() { - Symbols.SetParentTable(&ParentClass->Symbols); assert(Defaults == NULL); Defaults = (BYTE *)M_Malloc(Size); if (ParentClass->Defaults != NULL) diff --git a/src/zscript/zcc-parse.lemon b/src/zscript/zcc-parse.lemon index 09faf9272..7acc39212 100644 --- a/src/zscript/zcc-parse.lemon +++ b/src/zscript/zcc-parse.lemon @@ -176,6 +176,7 @@ class_head(X) ::= CLASS(T) IDENTIFIER(A) class_ancestry(B) class_flags(C). head->Flags = C.Flags; head->Replaces = C.Replaces; head->Type = nullptr; + head->Symbol = nullptr; X = head; } @@ -249,6 +250,7 @@ struct_def(X) ::= STRUCT(T) IDENTIFIER(A) LBRACE opt_struct_body(B) RBRACE opt_s def->NodeName = A.Name(); def->Body = B; def->Type = nullptr; + def->Symbol = nullptr; X = def; } diff --git a/src/zscript/zcc_compile.cpp b/src/zscript/zcc_compile.cpp index b282c29f3..59fcdf914 100644 --- a/src/zscript/zcc_compile.cpp +++ b/src/zscript/zcc_compile.cpp @@ -3,6 +3,7 @@ ** **--------------------------------------------------------------------------- ** Copyright -2016 Randy Heit +** Copyright 2016 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -41,6 +42,7 @@ #include "zcc_parser.h" #include "zcc_compile.h" #include "v_text.h" +#include "p_lnspec.h" #include "gdtoa.h" #define DEFINING_CONST ((PSymbolConst *)(void *)1) @@ -155,7 +157,7 @@ ZCCCompiler::ZCCCompiler(ZCC_AST &ast, DObject *_outer, PSymbolTable &_symbols, case AST_Class: case AST_Struct: case AST_ConstantDef: - if ((tnode = AddNamedNode(static_cast(node)))) + if ((tnode = AddNamedNode(static_cast(node), Symbols))) { switch (node->NodeType) { @@ -204,6 +206,9 @@ PSymbolTreeNode *ZCCCompiler::AddNamedNode(ZCC_NamedNode *node, PSymbolTable *pa { auto sy = new PSymbolTreeNode(name, node); sy->Symbols.SetParentTable(parentsym); + FString name; + name << "nodes - " << FName(node->NodeName); + sy->Symbols.SetName(name); Symbols->AddSymbol(sy); return sy; } @@ -275,7 +280,7 @@ int ZCCCompiler::Compile() { CreateClassTypes(); CreateStructTypes(); - CompileConstants(Constants); + CompileAllConstants(); return ErrorCount; } @@ -292,6 +297,9 @@ void ZCCCompiler::CreateStructTypes() for(auto s : Structs) { s->Type = NewStruct(s->NodeName, nullptr); + s->Symbol = new PSymbolType(s->NodeName, s->Type); + s->Type->Symbols.SetName(FName(s->NodeName)); + GlobalSymbols.AddSymbol(s->Symbol); } } @@ -366,6 +374,9 @@ void ZCCCompiler::CreateClassTypes() // We will never get here if the name is a duplicate, so we can just do the assignment. c->Type = parent->FindClassTentative(c->NodeName); } + c->Symbol = new PSymbolType(c->NodeName, c->Type); + GlobalSymbols.AddSymbol(c->Symbol); + c->Type->Symbols.SetName(FName(c->NodeName).GetChars()); Classes.Push(c); OrigClasses.Delete(i); i--; @@ -389,6 +400,9 @@ void ZCCCompiler::CreateClassTypes() Error(c, "Class %s has unknown base class %s", FName(c->NodeName).GetChars(), FName(c->ParentName->Id).GetChars()); // create a placeholder so that the compiler can continue looking for errors. c->Type = RUNTIME_CLASS(DObject)->FindClassTentative(c->NodeName); + c->Symbol = new PSymbolType(c->NodeName, c->Type); + GlobalSymbols.AddSymbol(c->Symbol); + c->Type->Symbols.SetName(FName(c->NodeName).GetChars()); Classes.Push(c); OrigClasses.Delete(i); donesomething = true; @@ -403,28 +417,132 @@ void ZCCCompiler::CreateClassTypes() { Error(c, "Class %s has circular inheritance", FName(c->NodeName).GetChars()); c->Type = RUNTIME_CLASS(DObject)->FindClassTentative(c->NodeName); + c->Symbol = new PSymbolType(c->NodeName, c->Type); + c->Type->Symbols.SetName(FName(c->NodeName).GetChars()); + GlobalSymbols.AddSymbol(c->Symbol); Classes.Push(c); } } //========================================================================== // -// ZCCCompiler :: CompileConstants +// ZCCCompiler :: AddConstants // -// Make symbols from every constant defined at this level. +// Helper for CompileAllConstants // //========================================================================== -void ZCCCompiler::CompileConstants(const TArray &defs) +void ZCCCompiler::AddConstants(TArray &dest, TArray &Constants, PSymbolTable *nt, PSymbolTable *ot) { - for (unsigned i = 0; i < defs.Size(); ++i) + for (auto c : Constants) { - ZCC_ConstantDef *def = defs[i]; - if (def->Symbol == NULL) + dest.Push({ c, nt, ot }); + } +} + +//========================================================================== +// +// ZCCCompiler :: CompileAllConstants +// +// Make symbols from every constant defined at all levels. +// Since constants may only depend on other constants this can be done +// without any more involved processing of the AST as a first step. +// +//========================================================================== + +void ZCCCompiler::CompileAllConstants() +{ + // put all constants in one list to make resolving this easier. + TArray constantwork; + + AddConstants(constantwork, Constants, Symbols, OutputSymbols); + for (auto &c : Classes) + { + AddConstants(constantwork, c.Constants, &c.node->Symbols, &c->Type->Symbols); + for (auto &s : c.Structs) { - PSymbolConst *sym = CompileConstant(def); + AddConstants(constantwork, s.Constants, &s.node->Symbols, &s->Type->Symbols); } } + for (auto &s : Structs) + { + AddConstants(constantwork, s.Constants, &s.node->Symbols, &s->Type->Symbols); + } + + // Before starting to resolve the list, let's create symbols for all already resolved ones first (i.e. all literal constants), to reduce work. + for (unsigned i = 0; iValue->NodeType == AST_ExprConstant) + { + AddConstant(constantwork[i]); + // Remove the constant from the list + constantwork.Delete(i); + i--; + } + } + bool donesomething = true; + // Now go through this list until no more constants can be resolved. The remaining ones will be non-constant values. + while (donesomething && constantwork.Size() > 0) + { + donesomething = false; + for (unsigned i = 0; i < constantwork.Size(); i++) + { + if (CompileConstant(constantwork[i].node, constantwork[i].outputtable)) + { + AddConstant(constantwork[i]); + // Remove the constant from the list + constantwork.Delete(i); + i--; + donesomething = true; + } + } + } + for (unsigned i = 0; i < constantwork.Size(); i++) + { + Error(constantwork[i].node, "%s is not a constant", FName(constantwork[i].node->NodeName).GetChars()); + } +} + +//========================================================================== +// +// ZCCCompiler :: AddConstant +// +// Adds a constant to its assigned symbol table +// +//========================================================================== + +void ZCCCompiler::AddConstant(ZCC_ConstantWork &constant) +{ + auto def = constant.node; + auto val = def->Value; + if (val->NodeType == AST_ExprConstant) + { + ZCC_ExprConstant *cval = static_cast(val); + if (cval->Type == TypeString) + { + def->Symbol = new PSymbolConstString(def->NodeName, *(cval->StringVal)); + } + else if (cval->Type->IsA(RUNTIME_CLASS(PInt))) + { + def->Symbol = new PSymbolConstNumeric(def->NodeName, cval->Type, cval->IntVal); + } + else if (cval->Type->IsA(RUNTIME_CLASS(PFloat))) + { + def->Symbol = new PSymbolConstNumeric(def->NodeName, cval->Type, cval->DoubleVal); + } + else + { + Error(def->Value, "Bad type for constant definiton"); + def->Symbol = nullptr; + } + + if (def->Symbol == nullptr) + { + // Create a dummy constant so we don't make any undefined value warnings. + def->Symbol = new PSymbolConstNumeric(def->NodeName, TypeError, 0); + } + constant.outputtable->ReplaceSymbol(def->Symbol); + } } //========================================================================== @@ -432,51 +550,19 @@ void ZCCCompiler::CompileConstants(const TArray &defs) // ZCCCompiler :: CompileConstant // // For every constant definition, evaluate its value (which should result -// in a constant), and create a symbol for it. Simplify() uses recursion -// to resolve constants used before their declarations. +// in a constant), and create a symbol for it. // //========================================================================== -PSymbolConst *ZCCCompiler::CompileConstant(ZCC_ConstantDef *def) +bool ZCCCompiler::CompileConstant(ZCC_ConstantDef *def, PSymbolTable *sym) { - assert(def->Symbol == NULL); + assert(def->Symbol == nullptr); def->Symbol = DEFINING_CONST; // avoid recursion - ZCC_Expression *val = Simplify(def->Value); + ZCC_Expression *val = Simplify(def->Value, sym); def->Value = val; - PSymbolConst *sym = NULL; - if (val->NodeType == AST_ExprConstant) - { - ZCC_ExprConstant *cval = static_cast(val); - if (cval->Type == TypeString) - { - sym = new PSymbolConstString(def->NodeName, *(cval->StringVal)); - } - else if (cval->Type->IsA(RUNTIME_CLASS(PInt))) - { - sym = new PSymbolConstNumeric(def->NodeName, cval->Type, cval->IntVal); - } - else if (cval->Type->IsA(RUNTIME_CLASS(PFloat))) - { - sym = new PSymbolConstNumeric(def->NodeName, cval->Type, cval->DoubleVal); - } - else - { - Error(def->Value, "Bad type for constant definiton"); - } - } - else - { - Error(def->Value, "Constant definition requires a constant value"); - } - if (sym == NULL) - { - // Create a dummy constant so we don't make any undefined value warnings. - sym = new PSymbolConstNumeric(def->NodeName, TypeError, 0); - } - def->Symbol = sym; - OutputSymbols->ReplaceSymbol(sym); - return sym; + if (def->Symbol == DEFINING_CONST) def->Symbol = nullptr; + return (val->NodeType == AST_ExprConstant); } @@ -493,27 +579,27 @@ PSymbolConst *ZCCCompiler::CompileConstant(ZCC_ConstantDef *def) // //========================================================================== -ZCC_Expression *ZCCCompiler::Simplify(ZCC_Expression *root) +ZCC_Expression *ZCCCompiler::Simplify(ZCC_Expression *root, PSymbolTable *sym) { if (root->NodeType == AST_ExprUnary) { - return SimplifyUnary(static_cast(root)); + return SimplifyUnary(static_cast(root), sym); } else if (root->NodeType == AST_ExprBinary) { - return SimplifyBinary(static_cast(root)); + return SimplifyBinary(static_cast(root), sym); } else if (root->Operation == PEX_ID) { - return IdentifyIdentifier(static_cast(root)); + return IdentifyIdentifier(static_cast(root), sym); } else if (root->Operation == PEX_MemberAccess) { - return SimplifyMemberAccess(static_cast(root)); + return SimplifyMemberAccess(static_cast(root), sym); } else if (root->Operation == PEX_FuncCall) { - return SimplifyFunctionCall(static_cast(root)); + return SimplifyFunctionCall(static_cast(root), sym); } return root; } @@ -524,9 +610,13 @@ ZCC_Expression *ZCCCompiler::Simplify(ZCC_Expression *root) // //========================================================================== -ZCC_Expression *ZCCCompiler::SimplifyUnary(ZCC_ExprUnary *unary) +ZCC_Expression *ZCCCompiler::SimplifyUnary(ZCC_ExprUnary *unary, PSymbolTable *sym) { - unary->Operand = Simplify(unary->Operand); + unary->Operand = Simplify(unary->Operand, sym); + if (unary->Operand->Type == nullptr) + { + return unary; + } ZCC_OpProto *op = PromoteUnary(unary->Operation, unary->Operand); if (op == NULL) { // Oh, poo! @@ -545,10 +635,15 @@ ZCC_Expression *ZCCCompiler::SimplifyUnary(ZCC_ExprUnary *unary) // //========================================================================== -ZCC_Expression *ZCCCompiler::SimplifyBinary(ZCC_ExprBinary *binary) +ZCC_Expression *ZCCCompiler::SimplifyBinary(ZCC_ExprBinary *binary, PSymbolTable *sym) { - binary->Left = Simplify(binary->Left); - binary->Right = Simplify(binary->Right); + binary->Left = Simplify(binary->Left, sym); + binary->Right = Simplify(binary->Right, sym); + if (binary->Left->Type == nullptr || binary->Right->Type == nullptr) + { + // We do not know yet what this is so we cannot promote it (yet.) + return binary; + } ZCC_OpProto *op = PromoteBinary(binary->Operation, binary->Left, binary->Right); if (op == NULL) { @@ -569,32 +664,41 @@ ZCC_Expression *ZCCCompiler::SimplifyBinary(ZCC_ExprBinary *binary) // //========================================================================== -ZCC_Expression *ZCCCompiler::SimplifyMemberAccess(ZCC_ExprMemberAccess *dotop) +ZCC_Expression *ZCCCompiler::SimplifyMemberAccess(ZCC_ExprMemberAccess *dotop, PSymbolTable *symt) { - dotop->Left = Simplify(dotop->Left); + PSymbolTable *symtable; + + dotop->Left = Simplify(dotop->Left, symt); if (dotop->Left->Operation == PEX_TypeRef) { // Type refs can be evaluated now. PType *ref = static_cast(dotop->Left)->RefType; - PSymbolTable *symtable; PSymbol *sym = ref->Symbols.FindSymbolInTable(dotop->Right, symtable); - if (sym == NULL) - { - Error(dotop, "'%s' is not a valid member", FName(dotop->Right).GetChars()); - } - else + if (sym != nullptr) { ZCC_Expression *expr = NodeFromSymbol(sym, dotop, symtable); - if (expr == NULL) - { - Error(dotop, "Unhandled symbol type encountered"); - } - else + if (expr != nullptr) { return expr; } } } + else if (dotop->Left->Operation == PEX_Super) + { + symt = symt->GetParentTable(); + if (symt != nullptr) + { + PSymbol *sym = symt->FindSymbolInTable(dotop->Right, symtable); + if (sym != nullptr) + { + ZCC_Expression *expr = NodeFromSymbol(sym, dotop, symtable); + if (expr != nullptr) + { + return expr; + } + } + } + } return dotop; } @@ -607,12 +711,12 @@ ZCC_Expression *ZCCCompiler::SimplifyMemberAccess(ZCC_ExprMemberAccess *dotop) // //========================================================================== -ZCC_Expression *ZCCCompiler::SimplifyFunctionCall(ZCC_ExprFuncCall *callop) +ZCC_Expression *ZCCCompiler::SimplifyFunctionCall(ZCC_ExprFuncCall *callop, PSymbolTable *sym) { ZCC_FuncParm *parm; int parmcount = 0; - callop->Function = Simplify(callop->Function); + callop->Function = Simplify(callop->Function, sym); parm = callop->Parameters; if (parm != NULL) { @@ -620,7 +724,7 @@ ZCC_Expression *ZCCCompiler::SimplifyFunctionCall(ZCC_ExprFuncCall *callop) { parmcount++; assert(parm->NodeType == AST_FuncParm); - parm->Value = Simplify(parm->Value); + parm->Value = Simplify(parm->Value, sym); parm = static_cast(parm->SiblingNext); } while (parm != callop->Parameters); @@ -751,12 +855,14 @@ ZCC_Expression *ZCCCompiler::AddCastNode(PType *type, ZCC_Expression *expr) // //========================================================================== -ZCC_Expression *ZCCCompiler::IdentifyIdentifier(ZCC_ExprID *idnode) +ZCC_Expression *ZCCCompiler::IdentifyIdentifier(ZCC_ExprID *idnode, PSymbolTable *symt) { // Check the symbol table for the identifier. PSymbolTable *table; - PSymbol *sym = Symbols->FindSymbolInTable(idnode->Identifier, table); - if (sym != NULL) + PSymbol *sym = symt->FindSymbolInTable(idnode->Identifier, table); + // GlobalSymbols cannot be the parent of a class's symbol table so we have to look for global symbols explicitly. + if (sym == nullptr && symt != &GlobalSymbols) sym = GlobalSymbols.FindSymbolInTable(idnode->Identifier, table); + if (sym != nullptr) { ZCC_Expression *node = NodeFromSymbol(sym, idnode, table); if (node != NULL) @@ -766,46 +872,26 @@ ZCC_Expression *ZCCCompiler::IdentifyIdentifier(ZCC_ExprID *idnode) } else { + // Also handle line specials. + // To call this like a function this needs to be done differently, but for resolving constants this is ok. + int spec = P_FindLineSpecial(FName(idnode->Identifier).GetChars()); + if (spec != 0) + { + ZCC_ExprConstant *val = static_cast(AST.InitNode(sizeof(*val), AST_ExprConstant, idnode)); + val->Operation = PEX_ConstValue; + val->Type = TypeSInt32; + val->IntVal = spec; + return val; + } + symt->DumpSymbolTable(); + GlobalSymbols.DumpSymbolTable(); + Error(idnode, "Unknown identifier '%s'", FName(idnode->Identifier).GetChars()); + idnode->ToErrorNode(); } - // Identifier didn't refer to anything good, so type error it. - idnode->ToErrorNode(); return idnode; } -//========================================================================== -// -// ZCCCompiler :: CompileNode -// -//========================================================================== - -PSymbol *ZCCCompiler::CompileNode(ZCC_NamedNode *node) -{ - assert(node != NULL); - if (node->NodeType == AST_ConstantDef) - { - ZCC_ConstantDef *def = static_cast(node); - PSymbolConst *sym = def->Symbol; - - if (sym == DEFINING_CONST) - { - Error(node, "Definition of '%s' is infinitely recursive", FName(node->NodeName).GetChars()); - sym = NULL; - } - else - { - assert(sym == NULL); - sym = CompileConstant(def); - } - return sym; - } - else if (node->NodeType == AST_Struct) - { - - } - return NULL; -} - //========================================================================== // // ZCCCompiler :: NodeFromSymbol @@ -814,18 +900,8 @@ PSymbol *ZCCCompiler::CompileNode(ZCC_NamedNode *node) ZCC_Expression *ZCCCompiler::NodeFromSymbol(PSymbol *sym, ZCC_Expression *source, PSymbolTable *table) { - assert(sym != NULL); - if (sym->IsA(RUNTIME_CLASS(PSymbolTreeNode))) - { - PSymbolTable *prevtable = Symbols; - Symbols = table; - sym = CompileNode(static_cast(sym)->Node); - Symbols = prevtable; - if (sym == NULL) - { - return NULL; - } - } + assert(sym != nullptr); + if (sym->IsKindOf(RUNTIME_CLASS(PSymbolConst))) { return NodeFromSymbolConst(static_cast(sym), source); diff --git a/src/zscript/zcc_compile.h b/src/zscript/zcc_compile.h index f92d8ad2d..fd6cdaee4 100644 --- a/src/zscript/zcc_compile.h +++ b/src/zscript/zcc_compile.h @@ -51,6 +51,13 @@ struct ZCC_ClassWork }; +struct ZCC_ConstantWork +{ + ZCC_ConstantDef *node; + PSymbolTable *nodetable; + PSymbolTable *outputtable; +}; + class ZCCCompiler { public: @@ -62,8 +69,11 @@ private: void ProcessStruct(ZCC_Struct *node, PSymbolTreeNode *tnode); void CreateStructTypes(); void CreateClassTypes(); - void CompileConstants(const TArray &defs); - PSymbolConst *CompileConstant(ZCC_ConstantDef *def); + void AddConstants(TArray &dest, TArray &Constants, PSymbolTable *nt, PSymbolTable *ot); + void CompileAllConstants(); + void AddConstant(ZCC_ConstantWork &constant); + int CompileConstants(const TArray &defs, PSymbolTable *Nodes, PSymbolTable *Output); + bool CompileConstant(ZCC_ConstantDef *def, PSymbolTable *Symbols); TArray Constants; TArray Structs; @@ -71,11 +81,11 @@ private: PSymbolTreeNode *AddNamedNode(ZCC_NamedNode *node, PSymbolTable *parentsym = nullptr); - ZCC_Expression *Simplify(ZCC_Expression *root); - ZCC_Expression *SimplifyUnary(ZCC_ExprUnary *unary); - ZCC_Expression *SimplifyBinary(ZCC_ExprBinary *binary); - ZCC_Expression *SimplifyMemberAccess(ZCC_ExprMemberAccess *dotop); - ZCC_Expression *SimplifyFunctionCall(ZCC_ExprFuncCall *callop); + ZCC_Expression *Simplify(ZCC_Expression *root, PSymbolTable *Symbols); + ZCC_Expression *SimplifyUnary(ZCC_ExprUnary *unary, PSymbolTable *Symbols); + ZCC_Expression *SimplifyBinary(ZCC_ExprBinary *binary, PSymbolTable *Symbols); + ZCC_Expression *SimplifyMemberAccess(ZCC_ExprMemberAccess *dotop, PSymbolTable *Symbols); + ZCC_Expression *SimplifyFunctionCall(ZCC_ExprFuncCall *callop, PSymbolTable *Symbols); ZCC_OpProto *PromoteUnary(EZCCExprType op, ZCC_Expression *&expr); ZCC_OpProto *PromoteBinary(EZCCExprType op, ZCC_Expression *&left, ZCC_Expression *&right); @@ -87,11 +97,10 @@ private: ZCC_Expression *ApplyConversion(ZCC_Expression *expr, const PType::Conversion **route, int routelen); ZCC_Expression *AddCastNode(PType *type, ZCC_Expression *expr); - ZCC_Expression *IdentifyIdentifier(ZCC_ExprID *idnode); + ZCC_Expression *IdentifyIdentifier(ZCC_ExprID *idnode, PSymbolTable *sym); ZCC_Expression *NodeFromSymbol(PSymbol *sym, ZCC_Expression *source, PSymbolTable *table); ZCC_ExprConstant *NodeFromSymbolConst(PSymbolConst *sym, ZCC_Expression *idnode); ZCC_ExprTypeRef *NodeFromSymbolType(PSymbolType *sym, ZCC_Expression *idnode); - PSymbol *CompileNode(ZCC_NamedNode *node); void Warn(ZCC_TreeNode *node, const char *msg, ...); diff --git a/src/zscript/zcc_parser.cpp b/src/zscript/zcc_parser.cpp index 4f226f3f9..ba08f91ef 100644 --- a/src/zscript/zcc_parser.cpp +++ b/src/zscript/zcc_parser.cpp @@ -338,7 +338,8 @@ static void DoParse(int lumpnum) #endif } - PSymbolTable symtable(&GlobalSymbols); + PSymbolTable symtable; + symtable.SetName("Global_Node"); ZCCCompiler cc(state, NULL, symtable, GlobalSymbols); cc.Compile(); // ... and another one afterward so we can see what the compiler does with the data. diff --git a/src/zscript/zcc_parser.h b/src/zscript/zcc_parser.h index 8de0c3952..1da9f79ca 100644 --- a/src/zscript/zcc_parser.h +++ b/src/zscript/zcc_parser.h @@ -188,12 +188,14 @@ struct ZCC_Class : ZCC_NamedNode VM_UWORD Flags; ZCC_TreeNode *Body; PClass *Type; + PSymbolType *Symbol; }; struct ZCC_Struct : ZCC_NamedNode { ZCC_TreeNode *Body; PStruct *Type; + PSymbolType *Symbol; }; struct ZCC_Enum : ZCC_NamedNode diff --git a/wadsrc/static/zscript/constants.txt b/wadsrc/static/zscript/constants.txt index da22b4180..fdd1bf977 100644 --- a/wadsrc/static/zscript/constants.txt +++ b/wadsrc/static/zscript/constants.txt @@ -1,4 +1,4 @@ - +/* // Flags for A_PainAttack enum EPainAttackFlags { @@ -806,3 +806,4 @@ enum ERenderStyles STYLE_AddStencil, STYLE_AddShaded, }; +*/ \ No newline at end of file