2010-10-31 04:36:00 +00:00
|
|
|
#include "dobject.h"
|
|
|
|
#include "sc_man.h"
|
|
|
|
#include "memarena.h"
|
|
|
|
#include "zcc_parser.h"
|
|
|
|
#include "zcc-parse.h"
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
class FLispString;
|
|
|
|
extern void (* const TreeNodePrinter[NUM_AST_NODE_TYPES])(FLispString &, ZCC_TreeNode *);
|
2010-10-31 04:36:00 +00:00
|
|
|
|
|
|
|
static const char *BuiltInTypeNames[] =
|
|
|
|
{
|
|
|
|
"sint8", "uint8",
|
|
|
|
"sint16", "uint16",
|
|
|
|
"sint32", "uint32",
|
|
|
|
"intauto",
|
|
|
|
|
|
|
|
"bool",
|
|
|
|
"float32", "float64", "floatauto",
|
|
|
|
"string",
|
|
|
|
"vector2",
|
|
|
|
"vector3",
|
|
|
|
"vector4",
|
|
|
|
"name",
|
|
|
|
"usertype"
|
|
|
|
};
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
class FLispString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
operator FString &() { return Str; }
|
|
|
|
|
|
|
|
FLispString()
|
|
|
|
{
|
|
|
|
NestDepth = Column = 0;
|
|
|
|
WrapWidth = 72;
|
|
|
|
NeedSpace = false;
|
2013-07-18 04:36:10 +00:00
|
|
|
ConsecOpens = 0;
|
2013-07-18 04:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Open(const char *label)
|
|
|
|
{
|
|
|
|
size_t labellen = label != NULL ? strlen(label) : 0;
|
|
|
|
CheckWrap(labellen + 1 + NeedSpace);
|
|
|
|
if (NeedSpace)
|
|
|
|
{
|
|
|
|
Str << ' ';
|
2013-07-18 04:36:10 +00:00
|
|
|
ConsecOpens = 0;
|
2013-07-18 04:14:06 +00:00
|
|
|
}
|
|
|
|
Str << '(';
|
2013-07-18 04:36:10 +00:00
|
|
|
ConsecOpens++;
|
2013-07-18 04:14:06 +00:00
|
|
|
if (label != NULL)
|
|
|
|
{
|
|
|
|
Str.AppendCStrPart(label, labellen);
|
|
|
|
}
|
|
|
|
Column += labellen + 1 + NeedSpace;
|
|
|
|
NestDepth++;
|
|
|
|
NeedSpace = (label != NULL);
|
|
|
|
}
|
|
|
|
void Close()
|
|
|
|
{
|
|
|
|
assert(NestDepth != 0);
|
|
|
|
Str << ')';
|
|
|
|
Column++;
|
|
|
|
NestDepth--;
|
|
|
|
NeedSpace = true;
|
|
|
|
}
|
|
|
|
void Break()
|
|
|
|
{
|
|
|
|
// Don't break if not needed.
|
|
|
|
if (Column != NestDepth)
|
|
|
|
{
|
2013-07-18 04:36:10 +00:00
|
|
|
if (NeedSpace)
|
|
|
|
{
|
|
|
|
ConsecOpens = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Move hanging ( characters to the new line
|
|
|
|
Str.Truncate(long(Str.Len() - ConsecOpens));
|
|
|
|
NestDepth -= ConsecOpens;
|
|
|
|
}
|
2013-07-18 04:14:06 +00:00
|
|
|
Str << '\n';
|
|
|
|
Column = NestDepth;
|
|
|
|
NeedSpace = false;
|
|
|
|
if (NestDepth > 0)
|
|
|
|
{
|
|
|
|
Str.AppendFormat("%*s", NestDepth, "");
|
|
|
|
}
|
2013-07-18 04:36:10 +00:00
|
|
|
if (ConsecOpens > 0)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < ConsecOpens; ++i)
|
|
|
|
{
|
|
|
|
Str << '(';
|
|
|
|
}
|
|
|
|
NestDepth += ConsecOpens;
|
|
|
|
}
|
2013-07-18 04:14:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool CheckWrap(size_t len)
|
|
|
|
{
|
|
|
|
if (len + Column > WrapWidth)
|
|
|
|
{
|
|
|
|
Break();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void Add(const char *str, size_t len)
|
|
|
|
{
|
|
|
|
CheckWrap(len + NeedSpace);
|
|
|
|
if (NeedSpace)
|
|
|
|
{
|
|
|
|
Str << ' ';
|
|
|
|
}
|
|
|
|
Str.AppendCStrPart(str, len);
|
|
|
|
Column += len + NeedSpace;
|
|
|
|
NeedSpace = true;
|
|
|
|
}
|
|
|
|
void Add(const char *str)
|
|
|
|
{
|
|
|
|
Add(str, strlen(str));
|
|
|
|
}
|
|
|
|
void Add(FString &str)
|
|
|
|
{
|
|
|
|
Add(str.GetChars(), str.Len());
|
|
|
|
}
|
|
|
|
void AddName(FName name)
|
|
|
|
{
|
|
|
|
size_t namelen = strlen(name.GetChars());
|
|
|
|
CheckWrap(namelen + 2 + NeedSpace);
|
|
|
|
if (NeedSpace)
|
|
|
|
{
|
|
|
|
NeedSpace = false;
|
|
|
|
Str << ' ';
|
|
|
|
}
|
|
|
|
Str << '\'' << name.GetChars() << '\'';
|
|
|
|
Column += namelen + 2 + NeedSpace;
|
|
|
|
NeedSpace = true;
|
|
|
|
}
|
|
|
|
void AddChar(char c)
|
|
|
|
{
|
|
|
|
Add(&c, 1);
|
|
|
|
}
|
|
|
|
void AddInt(int i)
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
size_t len = mysnprintf(buf, countof(buf), "%d", i);
|
|
|
|
Add(buf, len);
|
|
|
|
}
|
|
|
|
void AddHex(unsigned x)
|
|
|
|
{
|
|
|
|
char buf[10];
|
|
|
|
size_t len = mysnprintf(buf, countof(buf), "%08x", x);
|
|
|
|
Add(buf, len);
|
|
|
|
}
|
|
|
|
void AddFloat(double f)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
size_t len = mysnprintf(buf, countof(buf), "%g", f);
|
|
|
|
Add(buf, len);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
FString Str;
|
|
|
|
size_t NestDepth;
|
|
|
|
size_t Column;
|
|
|
|
size_t WrapWidth;
|
2013-07-18 04:36:10 +00:00
|
|
|
size_t ConsecOpens;
|
2013-07-18 04:14:06 +00:00
|
|
|
bool NeedSpace;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void PrintNode(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
assert(TreeNodePrinter[NUM_AST_NODE_TYPES-1] != NULL);
|
|
|
|
if (node->NodeType >= 0 && node->NodeType < NUM_AST_NODE_TYPES)
|
|
|
|
{
|
|
|
|
TreeNodePrinter[node->NodeType](out, node);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("unknown-node-type");
|
|
|
|
out.AddInt(node->NodeType);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 02:35:02 +00:00
|
|
|
static void PrintNodes(FLispString &out, ZCC_TreeNode *node, bool newlist=true, bool addbreaks=false)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_TreeNode *p;
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Add("nil", 3);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-25 02:35:02 +00:00
|
|
|
if (newlist)
|
|
|
|
{
|
|
|
|
out.Open(NULL);
|
|
|
|
}
|
2010-10-31 04:36:00 +00:00
|
|
|
p = node;
|
|
|
|
do
|
|
|
|
{
|
2013-07-25 02:35:02 +00:00
|
|
|
if (addbreaks)
|
|
|
|
{
|
|
|
|
out.Break();
|
|
|
|
}
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNode(out, p);
|
|
|
|
p = p->SiblingNext;
|
|
|
|
} while (p != node);
|
2013-07-25 02:35:02 +00:00
|
|
|
if (newlist)
|
|
|
|
{
|
|
|
|
out.Close();
|
|
|
|
}
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintBuiltInType(FLispString &out, EZCCBuiltinType type)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
assert(ZCC_NUM_BUILT_IN_TYPES == countof(BuiltInTypeNames));
|
|
|
|
if (unsigned(type) >= unsigned(ZCC_NUM_BUILT_IN_TYPES))
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
char buf[30];
|
|
|
|
size_t len = mysnprintf(buf, countof(buf), "bad-type-%u", type);
|
|
|
|
out.Add(buf, len);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Add(BuiltInTypeNames[type]);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintIdentifier(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_Identifier *inode = (ZCC_Identifier *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("identifier");
|
|
|
|
out.AddName(inode->Id);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStringConst(FLispString &out, FString str)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
FString outstr;
|
|
|
|
outstr << '"';
|
2010-10-31 04:36:00 +00:00
|
|
|
for (size_t i = 0; i < str.Len(); ++i)
|
|
|
|
{
|
|
|
|
if (str[i] == '"')
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
outstr << "\"";
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
else if (str[i] == '\\')
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
outstr << "\\\\";
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
else if (str[i] >= 32)
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
outstr << str[i];
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
outstr.AppendFormat("\\x%02X", str[i]);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Add(outstr);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintClass(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_Class *cnode = (ZCC_Class *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("class");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, cnode->ClassName);
|
|
|
|
PrintNodes(out, cnode->ParentName);
|
|
|
|
PrintNodes(out, cnode->Replaces);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.AddHex(cnode->Flags);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, cnode->Body, false, true);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStruct(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_Struct *snode = (ZCC_Struct *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Break();
|
|
|
|
out.Open("struct");
|
|
|
|
out.AddName(snode->StructName);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Body, false, true);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintEnum(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_Enum *enode = (ZCC_Enum *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Break();
|
|
|
|
out.Open("enum");
|
|
|
|
out.AddName(enode->EnumName);
|
|
|
|
PrintBuiltInType(out, enode->EnumType);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, enode->Elements, false, true);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintEnumNode(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_EnumNode *enode = (ZCC_EnumNode *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("enum-node");
|
|
|
|
out.AddName(enode->ElemName);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, enode->ElemValue, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStates(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_States *snode = (ZCC_States *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Break();
|
|
|
|
out.Open("states");
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Body, false, true);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStatePart(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-part");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStateLabel(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_StateLabel *snode = (ZCC_StateLabel *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-label");
|
|
|
|
out.AddName(snode->Label);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStateStop(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-stop");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStateWait(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-wait");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStateFail(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-fail");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStateLoop(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-loop");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStateGoto(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_StateGoto *snode = (ZCC_StateGoto *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-goto");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->Label);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, snode->Offset);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStateLine(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_StateLine *snode = (ZCC_StateLine *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("state-line");
|
|
|
|
out.Add(snode->Sprite, 4);
|
|
|
|
if (snode->bBright)
|
|
|
|
{
|
|
|
|
out.Add("bright", 6);
|
|
|
|
}
|
|
|
|
out.Add(*(snode->Frames));
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->Offset);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Action, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintVarName(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_VarName *vnode = (ZCC_VarName *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("var-name");
|
2013-07-24 00:59:47 +00:00
|
|
|
PrintNodes(out, vnode->ArraySize);
|
2013-07-25 02:35:02 +00:00
|
|
|
out.AddName(vnode->Name);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintType(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_Type *tnode = (ZCC_Type *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("bad-type");
|
|
|
|
PrintNodes(out, tnode->ArraySize);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintBasicType(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_BasicType *tnode = (ZCC_BasicType *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("basic-type");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, tnode->ArraySize);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintBuiltInType(out, tnode->Type);
|
2013-07-25 02:35:02 +00:00
|
|
|
if (tnode->Type == ZCC_UserType)
|
|
|
|
{
|
|
|
|
PrintNodes(out, tnode->UserType, false);
|
|
|
|
}
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintMapType(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_MapType *tnode = (ZCC_MapType *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("map-type");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, tnode->ArraySize);
|
|
|
|
PrintNodes(out, tnode->KeyType);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, tnode->ValueType);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintDynArrayType(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_DynArrayType *tnode = (ZCC_DynArrayType *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("dyn-array-type");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, tnode->ArraySize);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, tnode->ElementType);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintClassType(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ClassType *tnode = (ZCC_ClassType *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("class-type");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, tnode->ArraySize);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, tnode->Restriction);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void OpenExprType(FLispString &out, EZCCExprType type)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
static const char *const types[] =
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
"nil",
|
|
|
|
"id",
|
|
|
|
"super",
|
|
|
|
"self",
|
|
|
|
"string-const",
|
|
|
|
"int-const",
|
|
|
|
"uint-const",
|
|
|
|
"float-const",
|
|
|
|
"func-call",
|
|
|
|
"array-access",
|
|
|
|
"member-access",
|
|
|
|
"post-inc",
|
|
|
|
"post-dec",
|
|
|
|
"pre-inc",
|
|
|
|
"pre-dec",
|
|
|
|
"negate",
|
|
|
|
"anti-negate",
|
|
|
|
"bit-not",
|
|
|
|
"bool-not",
|
|
|
|
"size-of",
|
|
|
|
"align-of",
|
|
|
|
"add",
|
|
|
|
"sub",
|
|
|
|
"mul",
|
|
|
|
"div",
|
|
|
|
"mod",
|
|
|
|
"pow",
|
|
|
|
"cross-product",
|
|
|
|
"dot-product",
|
|
|
|
"left-shift",
|
|
|
|
"right-shift",
|
|
|
|
"concat",
|
|
|
|
"lt",
|
|
|
|
"gt",
|
|
|
|
"lteq",
|
|
|
|
"gteq",
|
|
|
|
"ltgteq",
|
|
|
|
"is",
|
|
|
|
"eqeq",
|
|
|
|
"neq",
|
|
|
|
"apreq",
|
|
|
|
"bit-and",
|
|
|
|
"bit-or",
|
|
|
|
"bit-xor",
|
|
|
|
"bool-and",
|
|
|
|
"bool-or",
|
|
|
|
"scope",
|
|
|
|
"trinary",
|
2010-10-31 04:36:00 +00:00
|
|
|
};
|
|
|
|
assert(countof(types) == PEX_COUNT_OF);
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
char buf[32];
|
|
|
|
|
2010-10-31 04:36:00 +00:00
|
|
|
if (unsigned(type) < countof(types))
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
mysnprintf(buf, countof(buf), "expr-%s", types[type]);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
mysnprintf(buf, countof(buf), "bad-pex-%u", type);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open(buf);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExpression(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_Expression *enode = (ZCC_Expression *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
OpenExprType(out, enode->Operation);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprID(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprID *enode = (ZCC_ExprID *)node;
|
|
|
|
assert(enode->Operation == PEX_ID);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("expr-id");
|
|
|
|
out.AddName(enode->Identifier);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprString(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprString *enode = (ZCC_ExprString *)node;
|
|
|
|
assert(enode->Operation == PEX_StringConst);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("expr-string-const");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintStringConst(out, *enode->Value);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprInt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprInt *enode = (ZCC_ExprInt *)node;
|
|
|
|
assert(enode->Operation == PEX_IntConst || enode->Operation == PEX_UIntConst);
|
2013-07-18 04:14:06 +00:00
|
|
|
OpenExprType(out, enode->Operation);
|
|
|
|
out.AddInt(enode->Value);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprFloat(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprFloat *enode = (ZCC_ExprFloat *)node;
|
|
|
|
assert(enode->Operation == PEX_FloatConst);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("expr-float-const");
|
|
|
|
out.AddFloat(enode->Value);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprFuncCall(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprFuncCall *enode = (ZCC_ExprFuncCall *)node;
|
|
|
|
assert(enode->Operation == PEX_FuncCall);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("expr-func-call");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, enode->Function);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, enode->Parameters, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprMemberAccess(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprMemberAccess *enode = (ZCC_ExprMemberAccess *)node;
|
|
|
|
assert(enode->Operation == PEX_MemberAccess);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("expr-member-access");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, enode->Left);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.AddName(enode->Right);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprUnary(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprUnary *enode = (ZCC_ExprUnary *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
OpenExprType(out, enode->Operation);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, enode->Operand, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprBinary(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprBinary *enode = (ZCC_ExprBinary *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
OpenExprType(out, enode->Operation);
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, enode->Left);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, enode->Right);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExprTrinary(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExprTrinary *enode = (ZCC_ExprTrinary *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
OpenExprType(out, enode->Operation);
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, enode->Test);
|
|
|
|
PrintNodes(out, enode->Left);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, enode->Right);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintFuncParam(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_FuncParm *pnode = (ZCC_FuncParm *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("func-parm");
|
|
|
|
out.AddName(pnode->Label);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, pnode->Value, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintStatement(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("statement");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintCompoundStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_CompoundStmt *snode = (ZCC_CompoundStmt *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("compound-stmt");
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Content, false, true);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintContinueStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("continue-stmt");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintBreakStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("break-stmt");
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintReturnStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ReturnStmt *snode = (ZCC_ReturnStmt *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("return-stmt");
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Values, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintExpressionStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ExpressionStmt *snode = (ZCC_ExpressionStmt *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("expression-stmt");
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Expression, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintIterationStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_IterationStmt *snode = (ZCC_IterationStmt *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("iteration-stmt");
|
|
|
|
out.Add((snode->CheckAt == ZCC_IterationStmt::Start) ? "start" : "end");
|
2013-07-25 02:35:02 +00:00
|
|
|
out.Break();
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->LoopCondition);
|
2013-07-25 02:35:02 +00:00
|
|
|
out.Break();
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->LoopBumper);
|
2013-07-25 02:35:02 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, snode->LoopStatement);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintIfStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_IfStmt *snode = (ZCC_IfStmt *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("if-stmt");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->Condition);
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->TruePath);
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, snode->FalsePath);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintSwitchStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_SwitchStmt *snode = (ZCC_SwitchStmt *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("switch-stmt");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->Condition);
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Content, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintCaseStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_CaseStmt *snode = (ZCC_CaseStmt *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("case-stmt");
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, snode->Condition, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void BadAssignOp(FLispString &out, int op)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
size_t len = mysnprintf(buf, countof(buf), "assign-op-%d", op);
|
|
|
|
out.Add(buf, len);
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintAssignStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_AssignStmt *snode = (ZCC_AssignStmt *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("assign-stmt");
|
2010-10-31 04:36:00 +00:00
|
|
|
switch (snode->AssignOp)
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
case ZCC_EQ: out.AddChar('='); break;
|
|
|
|
case ZCC_MULEQ: out.Add("*=", 2); break;
|
|
|
|
case ZCC_DIVEQ: out.Add("/=", 2); break;
|
|
|
|
case ZCC_MODEQ: out.Add("%=", 2); break;
|
|
|
|
case ZCC_ADDEQ: out.Add("+=", 2); break;
|
|
|
|
case ZCC_SUBEQ: out.Add("-=", 2); break;
|
|
|
|
case ZCC_LSHEQ: out.Add("<<=", 2); break;
|
|
|
|
case ZCC_RSHEQ: out.Add(">>=", 2); break;
|
|
|
|
case ZCC_ANDEQ: out.Add("&=", 2); break;
|
|
|
|
case ZCC_OREQ: out.Add("|=", 2); break;
|
|
|
|
case ZCC_XOREQ: out.Add("^=", 2); break;
|
|
|
|
default: BadAssignOp(out, snode->AssignOp); break;
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
PrintNodes(out, snode->Dests);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, snode->Sources);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintLocalVarStmt(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_LocalVarStmt *snode = (ZCC_LocalVarStmt *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("local-var-stmt");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, snode->Type);
|
|
|
|
PrintNodes(out, snode->Vars);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, snode->Inits);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintFuncParamDecl(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_FuncParamDecl *dnode = (ZCC_FuncParamDecl *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("func-param-decl");
|
2010-10-31 04:36:00 +00:00
|
|
|
PrintNodes(out, dnode->Type);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.AddName(dnode->Name);
|
|
|
|
out.AddHex(dnode->Flags);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintConstantDef(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_ConstantDef *dnode = (ZCC_ConstantDef *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("constant-def");
|
|
|
|
out.AddName(dnode->Name);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, dnode->Value, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintDeclarator(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_Declarator *dnode = (ZCC_Declarator *)node;
|
2013-07-18 04:22:13 +00:00
|
|
|
out.Break();
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Open("declarator");
|
|
|
|
out.AddHex(dnode->Flags);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, dnode->Type);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintVarDeclarator(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_VarDeclarator *dnode = (ZCC_VarDeclarator *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Break();
|
|
|
|
out.Open("var-declarator");
|
|
|
|
out.AddHex(dnode->Flags);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, dnode->Type);
|
2013-07-18 04:14:06 +00:00
|
|
|
PrintNodes(out, dnode->Names);
|
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
static void PrintFuncDeclarator(FLispString &out, ZCC_TreeNode *node)
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
ZCC_FuncDeclarator *dnode = (ZCC_FuncDeclarator *)node;
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Break();
|
|
|
|
out.Open("func-declarator");
|
|
|
|
out.AddHex(dnode->Flags);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, dnode->Type);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.AddName(dnode->Name);
|
|
|
|
PrintNodes(out, dnode->Params);
|
2013-07-25 02:35:02 +00:00
|
|
|
PrintNodes(out, dnode->Body, false);
|
2013-07-18 04:14:06 +00:00
|
|
|
out.Close();
|
2010-10-31 04:36:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 04:14:06 +00:00
|
|
|
void (* const TreeNodePrinter[NUM_AST_NODE_TYPES])(FLispString &, ZCC_TreeNode *) =
|
2010-10-31 04:36:00 +00:00
|
|
|
{
|
|
|
|
PrintIdentifier,
|
|
|
|
PrintClass,
|
|
|
|
PrintStruct,
|
|
|
|
PrintEnum,
|
|
|
|
PrintEnumNode,
|
|
|
|
PrintStates,
|
|
|
|
PrintStatePart,
|
|
|
|
PrintStateLabel,
|
|
|
|
PrintStateStop,
|
|
|
|
PrintStateWait,
|
|
|
|
PrintStateFail,
|
|
|
|
PrintStateLoop,
|
|
|
|
PrintStateGoto,
|
|
|
|
PrintStateLine,
|
|
|
|
PrintVarName,
|
|
|
|
PrintType,
|
|
|
|
PrintBasicType,
|
|
|
|
PrintMapType,
|
|
|
|
PrintDynArrayType,
|
|
|
|
PrintClassType,
|
|
|
|
PrintExpression,
|
|
|
|
PrintExprID,
|
|
|
|
PrintExprString,
|
|
|
|
PrintExprInt,
|
|
|
|
PrintExprFloat,
|
|
|
|
PrintExprFuncCall,
|
|
|
|
PrintExprMemberAccess,
|
|
|
|
PrintExprUnary,
|
|
|
|
PrintExprBinary,
|
|
|
|
PrintExprTrinary,
|
|
|
|
PrintFuncParam,
|
|
|
|
PrintStatement,
|
|
|
|
PrintCompoundStmt,
|
|
|
|
PrintContinueStmt,
|
|
|
|
PrintBreakStmt,
|
|
|
|
PrintReturnStmt,
|
|
|
|
PrintExpressionStmt,
|
|
|
|
PrintIterationStmt,
|
|
|
|
PrintIfStmt,
|
|
|
|
PrintSwitchStmt,
|
|
|
|
PrintCaseStmt,
|
|
|
|
PrintAssignStmt,
|
|
|
|
PrintLocalVarStmt,
|
|
|
|
PrintFuncParamDecl,
|
|
|
|
PrintConstantDef,
|
|
|
|
PrintDeclarator,
|
|
|
|
PrintVarDeclarator,
|
|
|
|
PrintFuncDeclarator
|
|
|
|
};
|
|
|
|
|
|
|
|
FString ZCC_PrintAST(ZCC_TreeNode *root)
|
|
|
|
{
|
2013-07-18 04:14:06 +00:00
|
|
|
FLispString out;
|
|
|
|
PrintNodes(out, root);
|
2010-10-31 04:36:00 +00:00
|
|
|
return out;
|
|
|
|
}
|