#include "std-macros.h" #include "parse-tree.h" #include "parser-aux.h" #include "sym.h" #include "parser.h" #include "tokens.h" #include "type.h" #include /* * Malloc a new tree node of the given kind. * This standard version of NewNode assumes that its second arg is a keyword * token */ Node* NewNode(KindOfNode kind, TokenType name, SrcLoc loc) { Node* temp; temp = (Node*) calloc(sizeof(struct node), 1); temp->header.kind = kind; temp->header.name = name; temp->header.loc = loc; temp->header.attachment.count = 0; temp->header.attachment.flags = 0; return (temp); } /** * Construction functions, called primarily for parser.y action routines. */ void SetSpecUnitBody(Node* specunit, Node* body) { Node* newnd; specunit->components.module.body = (newnd = NewNode(SPEC_NODE, null, specunit->header.loc)); newnd->components.spec.entities = FixDeclList(body); } /** * Access functions, called extensively from the type checker, and elsewhere. */ SrcLoc GetNodeSrcLoc(Node* t) { return t->header.loc; } Node* GetModuleName(Node* t) { return t->components.module.name; } Node* GetDeclNext(Node* t) { return t->components.decl.next; } Node* GetArrayBaseType(Node* t) { return t->components.type.kind.arraytype.basetype; } int GetRecordTypeNumFields(Node* t) { return t->components.type.kind.record.numfields; } struct Symt* GetRecordTypeFieldsTab(Node* t) { return t->components.type.kind.record.fieldstab; } Node* GetRecordTypeFields(Node* t) { return t->components.type.kind.record.fields; } Node* GetFieldDeclVars(Node* t) { return t->components.decl.kind.field.vars; } Node* GetFieldDeclType(Node* t) { return t->components.decl.kind.field.type; } Node* GetWhereLHS(Node* t) { return t->components.decl.kind.eq.left_operand; } Node* GetWhereRHS(Node* t) { return t->components.decl.kind.eq.right_operand; } Node* GetIdentTypeName(Node* t) { return t->components.type.kind.ident.type; } char* GetAtomTextVal(Node* t) { return t->components.atom.val.text; } /** * Set functions. */ void SetIdentTypeType(Node* t, Node* type) { t->components.type.kind.ident.type = type; } void SetArrayBaseType(Node* t, Node* type) { t->components.type.kind.arraytype.basetype = type; } void SetRecordType(Node* t, int numfields, Symtab* fieldstab, Node* fields) { t->components.type.kind.record.numfields = numfields; t->components.type.kind.record.fieldstab = fieldstab; t->components.type.kind.record.fields = fields; } /** * Specialized traversal functions. */ Node* ThreadIdentAtoms(Node* t, char* name) { } bool EqualIdentAtoms(Node* t1, Node* t2) { return streq(t1->components.atom.val.text, t2->components.atom.val.text); } /** * Copy functions. */ /* * Shallow copy. */ Node* ShallowCopyNode(Node* t) { Node* rtn = NewNode(t->header.kind, t->header.name, t->header.loc); rtn->header.attachment = t->header.attachment; rtn->components = t->components; return rtn; }