Separate the AST from the parser state.

This commit is contained in:
Randy Heit 2013-10-23 22:49:02 -05:00
commit d0968af9a6
3 changed files with 45 additions and 22 deletions

View file

@ -2,19 +2,9 @@
{
// Allocates a new AST node off the parse state's arena.
#define NEW_AST_NODE(type,name,tok) \
ZCC_##type *name = static_cast<ZCC_##type *>(InitNode(sizeof(ZCC_##type), AST_##type, stat)); \
ZCC_##type *name = static_cast<ZCC_##type *>(stat->InitNode(sizeof(ZCC_##type), AST_##type)); \
SetNodeLine(name, tok)
static ZCC_TreeNode *InitNode(size_t size, EZCCTreeNodeType type, ZCCParseState *stat)
{
ZCC_TreeNode *node = (ZCC_TreeNode *)stat->SyntaxArena.Alloc(size);
node->SiblingNext = node;
node->SiblingPrev = node;
node->NodeType = type;
node->SourceName = stat->Strings.Alloc(stat->sc.ScriptName);
return node;
}
static void SetNodeLine(ZCC_TreeNode *name, ZCCToken &tok)
{
name->SourceLoc = tok.SourceLoc;