mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 15:21:51 +00:00
- renamed the symbol tables holding the tree nodes so that the code becomes clearer to read. Necessary because the unclear naming caused:
- fixed: The tree nodes for classes and struct members were stored in the global tree nodes table. - sort variable declarations into their own list for processing.
This commit is contained in:
parent
6bad4809c1
commit
49f18c0a19
4 changed files with 39 additions and 32 deletions
|
@ -150,7 +150,7 @@ class PSymbolTreeNode : public PSymbol
|
||||||
DECLARE_CLASS(PSymbolTreeNode, PSymbol);
|
DECLARE_CLASS(PSymbolTreeNode, PSymbol);
|
||||||
public:
|
public:
|
||||||
struct ZCC_NamedNode *Node;
|
struct ZCC_NamedNode *Node;
|
||||||
PSymbolTable Symbols;
|
PSymbolTable TreeNodes;
|
||||||
|
|
||||||
PSymbolTreeNode(FName name, struct ZCC_NamedNode *node) : PSymbol(name), Node(node) {}
|
PSymbolTreeNode(FName name, struct ZCC_NamedNode *node) : PSymbol(name), Node(node) {}
|
||||||
PSymbolTreeNode() : PSymbol(NAME_None) {}
|
PSymbolTreeNode() : PSymbol(NAME_None) {}
|
||||||
|
|
|
@ -53,12 +53,13 @@
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *tnode)
|
void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode)
|
||||||
{
|
{
|
||||||
Classes.Push(ZCC_ClassWork(static_cast<ZCC_Class *>(cnode), tnode));
|
Classes.Push(ZCC_ClassWork(static_cast<ZCC_Class *>(cnode), treenode));
|
||||||
ZCC_ClassWork &cls = Classes.Last();
|
ZCC_ClassWork &cls = Classes.Last();
|
||||||
|
|
||||||
auto node = cnode->Body;
|
auto node = cnode->Body;
|
||||||
|
PSymbolTreeNode *childnode;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -66,12 +67,14 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *tnode)
|
||||||
{
|
{
|
||||||
case AST_Struct:
|
case AST_Struct:
|
||||||
case AST_ConstantDef:
|
case AST_ConstantDef:
|
||||||
if ((tnode = AddNamedNode(static_cast<ZCC_NamedNode *>(node))))
|
case AST_VarDeclarator:
|
||||||
|
if ((childnode = AddNamedNode(static_cast<ZCC_NamedNode *>(node), &treenode->TreeNodes)))
|
||||||
{
|
{
|
||||||
switch (node->NodeType)
|
switch (node->NodeType)
|
||||||
{
|
{
|
||||||
case AST_Struct: cls.Structs.Push(ZCC_StructWork(static_cast<ZCC_Struct *>(node), tnode)); break;
|
case AST_Struct: cls.Structs.Push(ZCC_StructWork(static_cast<ZCC_Struct *>(node), childnode)); break;
|
||||||
case AST_ConstantDef: cls.Constants.Push(static_cast<ZCC_ConstantDef *>(node)); break;
|
case AST_ConstantDef: cls.Constants.Push(static_cast<ZCC_ConstantDef *>(node)); break;
|
||||||
|
case AST_VarDeclarator: cls.Fields.Push(static_cast<ZCC_VarDeclarator *>(node)); break;
|
||||||
default: assert(0 && "Default case is just here to make GCC happy. It should never be reached");
|
default: assert(0 && "Default case is just here to make GCC happy. It should never be reached");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +85,6 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *tnode)
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
case AST_States:
|
case AST_States:
|
||||||
case AST_VarDeclarator:
|
|
||||||
case AST_FuncDeclarator:
|
case AST_FuncDeclarator:
|
||||||
case AST_Default:
|
case AST_Default:
|
||||||
break;
|
break;
|
||||||
|
@ -102,31 +104,34 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *tnode)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void ZCCCompiler::ProcessStruct(ZCC_Struct *cnode, PSymbolTreeNode *tnode)
|
void ZCCCompiler::ProcessStruct(ZCC_Struct *cnode, PSymbolTreeNode *treenode)
|
||||||
{
|
{
|
||||||
Structs.Push(ZCC_StructWork(static_cast<ZCC_Struct *>(cnode), tnode));
|
Structs.Push(ZCC_StructWork(static_cast<ZCC_Struct *>(cnode), treenode));
|
||||||
ZCC_StructWork &cls = Structs.Last();
|
ZCC_StructWork &cls = Structs.Last();
|
||||||
|
|
||||||
auto node = cnode->Body;
|
auto node = cnode->Body;
|
||||||
|
PSymbolTreeNode *childnode;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
switch (node->NodeType)
|
switch (node->NodeType)
|
||||||
{
|
{
|
||||||
case AST_ConstantDef:
|
case AST_ConstantDef:
|
||||||
if ((tnode = AddNamedNode(static_cast<ZCC_NamedNode *>(node))))
|
case AST_VarDeclarator:
|
||||||
|
if ((childnode = AddNamedNode(static_cast<ZCC_NamedNode *>(node), &treenode->TreeNodes)))
|
||||||
{
|
{
|
||||||
cls.Constants.Push(static_cast<ZCC_ConstantDef *>(node)); break;
|
switch (node->NodeType)
|
||||||
|
{
|
||||||
|
case AST_ConstantDef: cls.Constants.Push(static_cast<ZCC_ConstantDef *>(node)); break;
|
||||||
|
case AST_VarDeclarator: cls.Fields.Push(static_cast<ZCC_VarDeclarator *>(node)); break;
|
||||||
|
default: assert(0 && "Default case is just here to make GCC happy. It should never be reached");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AST_Enum: break;
|
case AST_Enum: break;
|
||||||
case AST_EnumTerminator:break;
|
case AST_EnumTerminator:break;
|
||||||
|
|
||||||
// todo
|
|
||||||
case AST_VarDeclarator:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0 && "Unhandled AST node type");
|
assert(0 && "Unhandled AST node type");
|
||||||
break;
|
break;
|
||||||
|
@ -143,7 +148,7 @@ void ZCCCompiler::ProcessStruct(ZCC_Struct *cnode, PSymbolTreeNode *tnode)
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
ZCCCompiler::ZCCCompiler(ZCC_AST &ast, DObject *_outer, PSymbolTable &_symbols, PSymbolTable &_outsymbols)
|
ZCCCompiler::ZCCCompiler(ZCC_AST &ast, DObject *_outer, PSymbolTable &_symbols, PSymbolTable &_outsymbols)
|
||||||
: Outer(_outer), Symbols(&_symbols), OutputSymbols(&_outsymbols), AST(ast), ErrorCount(0), WarnCount(0)
|
: Outer(_outer), GlobalTreeNodes(&_symbols), OutputSymbols(&_outsymbols), AST(ast), ErrorCount(0), WarnCount(0)
|
||||||
{
|
{
|
||||||
// Group top-level nodes by type
|
// Group top-level nodes by type
|
||||||
if (ast.TopNode != NULL)
|
if (ast.TopNode != NULL)
|
||||||
|
@ -157,7 +162,7 @@ ZCCCompiler::ZCCCompiler(ZCC_AST &ast, DObject *_outer, PSymbolTable &_symbols,
|
||||||
case AST_Class:
|
case AST_Class:
|
||||||
case AST_Struct:
|
case AST_Struct:
|
||||||
case AST_ConstantDef:
|
case AST_ConstantDef:
|
||||||
if ((tnode = AddNamedNode(static_cast<ZCC_NamedNode *>(node), Symbols)))
|
if ((tnode = AddNamedNode(static_cast<ZCC_NamedNode *>(node), GlobalTreeNodes)))
|
||||||
{
|
{
|
||||||
switch (node->NodeType)
|
switch (node->NodeType)
|
||||||
{
|
{
|
||||||
|
@ -191,10 +196,10 @@ ZCCCompiler::ZCCCompiler(ZCC_AST &ast, DObject *_outer, PSymbolTable &_symbols,
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
PSymbolTreeNode *ZCCCompiler::AddNamedNode(ZCC_NamedNode *node, PSymbolTable *parentsym)
|
PSymbolTreeNode *ZCCCompiler::AddNamedNode(ZCC_NamedNode *node, PSymbolTable *treenodes)
|
||||||
{
|
{
|
||||||
FName name = node->NodeName;
|
FName name = node->NodeName;
|
||||||
PSymbol *check = Symbols->FindSymbol(name, false);
|
PSymbol *check = treenodes->FindSymbol(name, false);
|
||||||
if (check != NULL)
|
if (check != NULL)
|
||||||
{
|
{
|
||||||
assert(check->IsA(RUNTIME_CLASS(PSymbolTreeNode)));
|
assert(check->IsA(RUNTIME_CLASS(PSymbolTreeNode)));
|
||||||
|
@ -205,11 +210,10 @@ PSymbolTreeNode *ZCCCompiler::AddNamedNode(ZCC_NamedNode *node, PSymbolTable *pa
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto sy = new PSymbolTreeNode(name, node);
|
auto sy = new PSymbolTreeNode(name, node);
|
||||||
sy->Symbols.SetParentTable(parentsym);
|
|
||||||
FString name;
|
FString name;
|
||||||
name << "nodes - " << FName(node->NodeName);
|
name << "nodes - " << FName(node->NodeName);
|
||||||
sy->Symbols.SetName(name);
|
sy->TreeNodes.SetName(name);
|
||||||
Symbols->AddSymbol(sy);
|
treenodes->AddSymbol(sy);
|
||||||
return sy;
|
return sy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,6 +285,7 @@ int ZCCCompiler::Compile()
|
||||||
CreateClassTypes();
|
CreateClassTypes();
|
||||||
CreateStructTypes();
|
CreateStructTypes();
|
||||||
CompileAllConstants();
|
CompileAllConstants();
|
||||||
|
//CompileAllFields();
|
||||||
return ErrorCount;
|
return ErrorCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,11 +437,11 @@ void ZCCCompiler::CreateClassTypes()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void ZCCCompiler::AddConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PSymbolTable *nt, PSymbolTable *ot)
|
void ZCCCompiler::CopyConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PSymbolTable *ot)
|
||||||
{
|
{
|
||||||
for (auto c : Constants)
|
for (auto c : Constants)
|
||||||
{
|
{
|
||||||
dest.Push({ c, nt, ot });
|
dest.Push({ c, ot });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,18 +460,18 @@ void ZCCCompiler::CompileAllConstants()
|
||||||
// put all constants in one list to make resolving this easier.
|
// put all constants in one list to make resolving this easier.
|
||||||
TArray<ZCC_ConstantWork> constantwork;
|
TArray<ZCC_ConstantWork> constantwork;
|
||||||
|
|
||||||
AddConstants(constantwork, Constants, Symbols, OutputSymbols);
|
CopyConstants(constantwork, Constants, OutputSymbols);
|
||||||
for (auto &c : Classes)
|
for (auto &c : Classes)
|
||||||
{
|
{
|
||||||
AddConstants(constantwork, c.Constants, &c.node->Symbols, &c->Type->Symbols);
|
CopyConstants(constantwork, c.Constants, &c->Type->Symbols);
|
||||||
for (auto &s : c.Structs)
|
for (auto &s : c.Structs)
|
||||||
{
|
{
|
||||||
AddConstants(constantwork, s.Constants, &s.node->Symbols, &s->Type->Symbols);
|
CopyConstants(constantwork, s.Constants, &s->Type->Symbols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto &s : Structs)
|
for (auto &s : Structs)
|
||||||
{
|
{
|
||||||
AddConstants(constantwork, s.Constants, &s.node->Symbols, &s->Type->Symbols);
|
CopyConstants(constantwork, s.Constants, &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.
|
// Before starting to resolve the list, let's create symbols for all already resolved ones first (i.e. all literal constants), to reduce work.
|
||||||
|
|
|
@ -6,6 +6,7 @@ struct ZCC_StructWork
|
||||||
ZCC_Struct *strct;
|
ZCC_Struct *strct;
|
||||||
PSymbolTreeNode *node;
|
PSymbolTreeNode *node;
|
||||||
TArray<ZCC_ConstantDef *> Constants;
|
TArray<ZCC_ConstantDef *> Constants;
|
||||||
|
TArray<ZCC_VarDeclarator *> Fields;
|
||||||
|
|
||||||
ZCC_StructWork(ZCC_Struct * s, PSymbolTreeNode *n)
|
ZCC_StructWork(ZCC_Struct * s, PSymbolTreeNode *n)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +33,7 @@ struct ZCC_ClassWork
|
||||||
PSymbolTreeNode *node;
|
PSymbolTreeNode *node;
|
||||||
TArray<ZCC_ConstantDef *> Constants;
|
TArray<ZCC_ConstantDef *> Constants;
|
||||||
TArray<ZCC_StructWork> Structs;
|
TArray<ZCC_StructWork> Structs;
|
||||||
|
TArray<ZCC_VarDeclarator *> Fields;
|
||||||
|
|
||||||
ZCC_ClassWork(ZCC_Class * s, PSymbolTreeNode *n)
|
ZCC_ClassWork(ZCC_Class * s, PSymbolTreeNode *n)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +56,6 @@ struct ZCC_ClassWork
|
||||||
struct ZCC_ConstantWork
|
struct ZCC_ConstantWork
|
||||||
{
|
{
|
||||||
ZCC_ConstantDef *node;
|
ZCC_ConstantDef *node;
|
||||||
PSymbolTable *nodetable;
|
|
||||||
PSymbolTable *outputtable;
|
PSymbolTable *outputtable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,10 +70,11 @@ private:
|
||||||
void ProcessStruct(ZCC_Struct *node, PSymbolTreeNode *tnode);
|
void ProcessStruct(ZCC_Struct *node, PSymbolTreeNode *tnode);
|
||||||
void CreateStructTypes();
|
void CreateStructTypes();
|
||||||
void CreateClassTypes();
|
void CreateClassTypes();
|
||||||
void AddConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PSymbolTable *nt, PSymbolTable *ot);
|
void CopyConstants(TArray<ZCC_ConstantWork> &dest, TArray<ZCC_ConstantDef*> &Constants, PSymbolTable *ot);
|
||||||
|
void CompileAllFields();
|
||||||
void CompileAllConstants();
|
void CompileAllConstants();
|
||||||
void AddConstant(ZCC_ConstantWork &constant);
|
void AddConstant(ZCC_ConstantWork &constant);
|
||||||
int CompileConstants(const TArray<ZCC_ConstantDef *> &defs, PSymbolTable *Nodes, PSymbolTable *Output);
|
int CompileConstants(const TArray<ZCC_ConstantDef *> &defs, PSymbolTable *Output);
|
||||||
bool CompileConstant(ZCC_ConstantDef *def, PSymbolTable *Symbols);
|
bool CompileConstant(ZCC_ConstantDef *def, PSymbolTable *Symbols);
|
||||||
|
|
||||||
TArray<ZCC_ConstantDef *> Constants;
|
TArray<ZCC_ConstantDef *> Constants;
|
||||||
|
@ -108,7 +110,7 @@ private:
|
||||||
void MessageV(ZCC_TreeNode *node, const char *txtcolor, const char *msg, va_list argptr);
|
void MessageV(ZCC_TreeNode *node, const char *txtcolor, const char *msg, va_list argptr);
|
||||||
|
|
||||||
DObject *Outer;
|
DObject *Outer;
|
||||||
PSymbolTable *Symbols;
|
PSymbolTable *GlobalTreeNodes;
|
||||||
PSymbolTable *OutputSymbols;
|
PSymbolTable *OutputSymbols;
|
||||||
ZCC_AST &AST;
|
ZCC_AST &AST;
|
||||||
int ErrorCount;
|
int ErrorCount;
|
||||||
|
|
|
@ -788,7 +788,7 @@ enum EMaskRotationFlags
|
||||||
VRF_NOPITCH = VRF_NOPITCHSTART|VRF_NOPITCHEND,
|
VRF_NOPITCH = VRF_NOPITCHSTART|VRF_NOPITCHEND,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ERenderStyles
|
enum ERenderStyle
|
||||||
{
|
{
|
||||||
STYLE_None,
|
STYLE_None,
|
||||||
STYLE_Normal,
|
STYLE_Normal,
|
||||||
|
|
Loading…
Reference in a new issue