]> git.sur5r.net Git - cc65/blobdiff - src/cc65/exprnode.h
Moved verbose output to a shared module in the common/ directory.
[cc65] / src / cc65 / exprnode.h
index 29dbc74d2eb2f0be5ad3a5370a2443ff11dcfa76..30284f350bc42b92ba95bc47c5cb25923f4ff1b6 100644 (file)
@@ -58,76 +58,95 @@ struct SymEntry;
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                  Data                                    */
 /*****************************************************************************/
 
 
 
 /* Node types */
 typedef enum {
-    NT_NONE,                           /* None (invalid) op */
-
-    NT_SYM,                    /* Symbol */
-    NT_CONST,                          /* A constant of some sort */
-    NT_ASM,                    /* Inline assembler */
-
-    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_ARRAY_SUBSCRIPT,                /* Array subscript */
-    NT_STRUCT_ACCESS,          /* Access of a struct field */
-    NT_STRUCTPTR_ACCESS,               /* Access via struct ptr */
-    NT_FUNCTION_CALL,          /* Call a function */
-    NT_TYPECAST,               /* A cast */
-    NT_ADDRESS,                        /* Address operator (&) */
-    NT_INDIRECT,               /* Indirection operator (*) */
-
-    NT_UNARY_MINUS,
-    NT_COMPLEMENT,             /* ~ */
-    NT_BOOL_NOT,                       /* ! */
-
-    NT_PLUS,                           /* + */
-    NT_MINUS,                          /* - */
-    NT_MUL,                            /* * */
-    NT_DIV,                            /* / */
-    NT_SHL,                            /* << */
-    NT_SHR,                            /* >> */
-    NT_AND,                            /* & */
-    NT_OR,                             /* | */
-    NT_XOR,                            /* ^ */
-
-    NT_TERNARY,                        /* ?: */
-
-    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_OR,                        /* || */
-    NT_BOOL_AND,                       /* && */
-
-    NT_EQ,                             /* == */
-    NT_NE,                             /* != */
-    NT_LT,                             /* < */
-    NT_LE,                             /* <= */
-    NT_GT,                             /* > */
-    NT_GE,                             /* >= */
-
-    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;
 
 
@@ -147,10 +166,9 @@ struct ExprNode {
     type*                      Type;   /* Resulting type */
     int                                LValue; /* True if this is an lvalue */
 
-    union {
-               long                    I;      /* Constant int value if any */
-               double                  F;      /* Constant float value if any */
-    } V;
+    /* Attributes */
+    long                               IVal;   /* Constant int value if any */
+    double                     FVal;   /* Constant float value if any */
 };
 
 
@@ -209,13 +227,17 @@ struct SymEntry* GetNodeSym (ExprNode* N);
 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
 
+/* End of exprnode.h */
 
+#endif