X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fexprnode.h;h=30284f350bc42b92ba95bc47c5cb25923f4ff1b6;hb=b8c4dc9b0661e19e46ba60372db3831cdcf5961f;hp=969ee7506f9a694cf6b4ca3080b2c55da53bc6fe;hpb=2bcb747b585b1a6baef6a1f49ca7f4c965fd78c1;p=cc65 diff --git a/src/cc65/exprnode.h b/src/cc65/exprnode.h index 969ee7506..30284f350 100644 --- a/src/cc65/exprnode.h +++ b/src/cc65/exprnode.h @@ -38,87 +38,115 @@ +/* common */ +#include "coll.h" + +/* cc65 */ #include "datatype.h" /*****************************************************************************/ -/* Forwards */ +/* Forwards */ /*****************************************************************************/ +struct ExprHeap; struct SymEntry; /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ /* Node types */ typedef enum { - NT_NONE, /* None (invalid) op */ - - NT_SYM, /* Symbol */ - NT_CONST, /* A constant of some sort */ - - NT_ICAST, /* Implicit type cast */ - NT_ECAST, /* Explicit type cast */ - - NT_REG_A, /* A register */ - NT_REG_X, /* X register */ - NT_REG_Y, /* Y register */ - NT_REG_AX, /* AX register */ - NT_REG_EAX, /* EAX register */ - - NT_CALLFUNC, /* Function call */ - NT_PUSH, /* Push the value onto the stack */ - NT_POP, /* Pop the value from the stack */ - - NT_NOT, /* ~ */ - NT_PLUS, /* + */ - NT_MINUS, /* - */ - NT_MUL, /* * */ - NT_DIV, /* / */ - NT_SHL, /* << */ - NT_SHR, /* >> */ - NT_AND, /* & */ - NT_OR, /* | */ - NT_XOR, /* ^ */ - - NT_ASSIGN, /* = */ - NT_PLUS_ASSIGN, /* += */ - NT_MINUS_ASSIGN, /* -= */ - NT_MUL_ASSIGN, /* *= */ - NT_DIV_ASSIGN, /* /= */ - NT_SHL_ASSIGN, /* <<= */ - NT_SHR_ASSIGN, /* >>= */ - NT_AND_ASSIGN, /* &= */ - NT_OR_ASSIGN, /* |= */ - NT_XOR_ASSIGN, /* ^= */ - - NT_PRE_DEC, /* -- */ - NT_POST_DEC, /* -- */ - NT_PRE_INC, /* ++ */ - NT_POST_INC, /* ++ */ - - NT_BOOL_NOT, /* ! */ - NT_BOOL_OR, /* || */ - NT_BOOL_AND, /* && */ - - NT_EQ, /* == */ - NT_NE, /* != */ - NT_LT, /* < */ - NT_LE, /* <= */ - NT_GT, /* > */ - NT_GE, /* >= */ - - NT_DEREF, /* * and others */ - - NT_COUNT /* Operation count */ + + /* Bits encoding the type of the objects stored in List for this + * particular node. + */ + NT_LIST_NONE = 0x0000, /* No items */ + NT_LIST_EXPR = 0x0100, /* Items are expression nodes */ + NT_LIST_SYM = 0x0200, /* Items are symbol table entries */ + NT_LIST_STRING = 0x0300, /* List item are character strings */ + NT_MASK_LIST = 0x0300, + + /* Two bits telling if this is a leaf or a branch */ + NT_LEAF = 0x0000, /* Leaf */ + NT_BRANCH = 0x8000, /* Branch */ + NT_MASK_LEAF = 0x8000, + + /* Special node type */ + NT_NONE = 0x0000, /* None (invalid) op */ + + /* Leaves */ + NT_SYM = 0x0001 | NT_LEAF | NT_LIST_SYM, /* Symbol */ + NT_CONST = 0x0002 | NT_LEAF | NT_LIST_NONE, /* A constant of some sort */ + NT_ASM = 0x0003 | NT_LEAF | NT_LIST_STRING, /* Inline assembler */ + + NT_REG_A = 0x0005 | NT_LEAF | NT_LIST_NONE, /* A register */ + NT_REG_X = 0x0006 | NT_LEAF | NT_LIST_NONE, /* X register */ + NT_REG_Y = 0x0007 | NT_LEAF | NT_LIST_NONE, /* Y register */ + NT_REG_AX = 0x0008 | NT_LEAF | NT_LIST_NONE, /* AX register */ + NT_REG_EAX = 0x0009 | NT_LEAF | NT_LIST_NONE, /* EAX register */ + + /* Branches */ + NT_ARRAY_SUBSCRIPT = 0x0010 | NT_BRANCH | NT_LIST_EXPR, /* Array subscript */ + NT_STRUCT_ACCESS = 0x0011 | NT_BRANCH | NT_LIST_EXPR, /* Access of a struct field */ + NT_STRUCTPTR_ACCESS = 0x0012 | NT_BRANCH | NT_LIST_EXPR, /* Access via struct ptr */ + NT_FUNCTION_CALL = 0x0013 | NT_BRANCH | NT_LIST_EXPR, /* Call a function */ + NT_TYPECAST = 0x0014 | NT_BRANCH | NT_LIST_EXPR, /* A cast */ + NT_ADDRESS = 0x0015 | NT_BRANCH | NT_LIST_EXPR, /* Address operator (&) */ + NT_INDIRECT = 0x0016 | NT_BRANCH | NT_LIST_EXPR, /* Indirection operator (*) */ + + NT_UNARY_MINUS = 0x0018 | NT_BRANCH | NT_LIST_EXPR, + NT_COMPLEMENT = 0x0019 | NT_BRANCH | NT_LIST_EXPR, /* ~ */ + NT_BOOL_NOT = 0x001A | NT_BRANCH | NT_LIST_EXPR, /* ! */ + + NT_PLUS = 0x001B | NT_BRANCH | NT_LIST_EXPR, /* + */ + NT_MINUS = 0x001C | NT_BRANCH | NT_LIST_EXPR, /* - */ + NT_MUL = 0x001D | NT_BRANCH | NT_LIST_EXPR, /* * */ + NT_DIV = 0x001E | NT_BRANCH | NT_LIST_EXPR, /* / */ + NT_SHL = 0x001F | NT_BRANCH | NT_LIST_EXPR, /* << */ + NT_SHR = 0x0020 | NT_BRANCH | NT_LIST_EXPR, /* >> */ + NT_AND = 0x0021 | NT_BRANCH | NT_LIST_EXPR, /* & */ + NT_OR = 0x0022 | NT_BRANCH | NT_LIST_EXPR, /* | */ + NT_XOR = 0x0023 | NT_BRANCH | NT_LIST_EXPR, /* ^ */ + + NT_TERNARY = 0x0024 | NT_BRANCH | NT_LIST_EXPR, /* ?: */ + + NT_ASSIGN = 0x0025 | NT_BRANCH | NT_LIST_EXPR, /* = */ + NT_PLUS_ASSIGN = 0x0026 | NT_BRANCH | NT_LIST_EXPR, /* += */ + NT_MINUS_ASSIGN = 0x0027 | NT_BRANCH | NT_LIST_EXPR, /* -= */ + NT_MUL_ASSIGN = 0x0028 | NT_BRANCH | NT_LIST_EXPR, /* *= */ + NT_DIV_ASSIGN = 0x0029 | NT_BRANCH | NT_LIST_EXPR, /* /= */ + NT_SHL_ASSIGN = 0x002A | NT_BRANCH | NT_LIST_EXPR, /* <<= */ + NT_SHR_ASSIGN = 0x002B | NT_BRANCH | NT_LIST_EXPR, /* >>= */ + NT_AND_ASSIGN = 0x002C | NT_BRANCH | NT_LIST_EXPR, /* &= */ + NT_OR_ASSIGN = 0x002D | NT_BRANCH | NT_LIST_EXPR, /* |= */ + NT_XOR_ASSIGN = 0x002E | NT_BRANCH | NT_LIST_EXPR, /* ^= */ + + NT_PRE_DEC = 0x002F | NT_BRANCH | NT_LIST_EXPR, /* -- */ + NT_POST_DEC = 0x0030 | NT_BRANCH | NT_LIST_EXPR, /* -- */ + NT_PRE_INC = 0x0031 | NT_BRANCH | NT_LIST_EXPR, /* ++ */ + NT_POST_INC = 0x0032 | NT_BRANCH | NT_LIST_EXPR, /* ++ */ + + NT_BOOL_OR = 0x0033 | NT_BRANCH | NT_LIST_EXPR, /* || */ + NT_BOOL_AND = 0x0034 | NT_BRANCH | NT_LIST_EXPR, /* && */ + + NT_EQ = 0x0035 | NT_BRANCH | NT_LIST_EXPR, /* == */ + NT_NE = 0x0036 | NT_BRANCH | NT_LIST_EXPR, /* != */ + NT_LT = 0x0037 | NT_BRANCH | NT_LIST_EXPR, /* < */ + NT_LE = 0x0038 | NT_BRANCH | NT_LIST_EXPR, /* <= */ + NT_GT = 0x0039 | NT_BRANCH | NT_LIST_EXPR, /* > */ + NT_GE = 0x003A | NT_BRANCH | NT_LIST_EXPR, /* >= */ + + NT_MASK_TYPE = 0x00FF + } nodetype_t; @@ -127,43 +155,89 @@ typedef enum { typedef struct ExprNode ExprNode; struct ExprNode { - ExprNode* Left; /* Left and right leaves */ - ExprNode* Right; + /* Management data */ + union { + struct ExprHeap* Owner; /* Heap, this node is in */ + struct ExprNode* Next; /* Next in free list */ + } MData; + Collection List; /* List of subexpressions */ nodetype_t NT; /* Node type */ - type* Type; /* Resulting type */ - int LValue; /* True if this is an lvalue */ + type* Type; /* Resulting type */ + int LValue; /* True if this is an lvalue */ - union { - /* Branch data */ - ExprNode* Test; /* Third expr for ternary op */ + /* Attributes */ + long IVal; /* Constant int value if any */ + double FVal; /* Constant float value if any */ +}; - /* Leave data */ - long I; /* Constant int value if any */ - double F; /* Constant float value if any */ - struct SymEntry* Sym; /* Symbol table entry if any */ - } V; + +/* Predefined indices for node items in List */ +enum { + IDX_LEFT = 0, + IDX_RIGHT = 1, + IDX_SYM = 0 +}; + +/* Some other constants for better readability */ +enum { + RVALUE = 0, + LVALUE = 1 }; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ -void InitExprNode (ExprNode* E); +ExprNode* InitExprNode (ExprNode* E, nodetype_t NT, type* Type, + int LValue, struct ExprHeap* Owner); /* Initialize a new expression node */ +void* GetItem (ExprNode* N, unsigned Index); +/* Return one of the items from the nodes item list */ +void AppendItem (ExprNode* N, void* Item); +/* Append an item to the nodes item list */ -/* End of exprnode.h */ +void SetItem (ExprNode* N, void* Item, unsigned Index); +/* Set a specific node item. The item list is filled with null pointers as + * needed. + */ -#endif +ExprNode* GetLeftNode (ExprNode* N); +/* Get the left sub-node from the list */ +void SetLeftNode (ExprNode* Root, ExprNode* Left); +/* Set the left node in Root */ +ExprNode* GetRightNode (ExprNode* N); +/* Get the right sub-node from the list */ + +void SetRightNode (ExprNode* Root, ExprNode* Right); +/* Set the right node in Root */ + +struct SymEntry* GetNodeSym (ExprNode* N); +/* Get the symbol entry for a NT_SYM node */ + +void SetNodeSym (ExprNode* N, struct SymEntry* Sym); +/* Set the symbol entry in a NT_SYM node */ + +int IsLeafNode (const ExprNode* E); +/* Return true if this is a leaf node */ + +int IsBranchNode (const ExprNode* E); +/* Return true if this is a branch node */ + + + +/* End of exprnode.h */ + +#endif