| 1 |
#ifndef TREE_H |
| 2 |
#define TREE_H |
| 3 |
|
| 4 |
/* These are the possible types of parse-tree nodes */ |
| 5 |
typedef enum |
| 6 |
{ |
| 7 |
TREE_METHOD_NODE, |
| 8 |
TREE_UNARY_EXPR, |
| 9 |
TREE_BINARY_EXPR, |
| 10 |
TREE_KEYWORD_EXPR, |
| 11 |
TREE_VARIABLE_NODE, |
| 12 |
TREE_KEYWORD_LIST, |
| 13 |
TREE_VAR_DECL_LIST, |
| 14 |
TREE_VAR_ASSIGN_LIST, |
| 15 |
TREE_STATEMENT_LIST, |
| 16 |
TREE_RETURN_EXPR, |
| 17 |
TREE_ASSIGN_EXPR, |
| 18 |
TREE_CONST_EXPR, |
| 19 |
TREE_SYMBOL_NODE, |
| 20 |
TREE_ARRAY_ELT_LIST, |
| 21 |
TREE_BLOCK_NODE, |
| 22 |
TREE_CASCADE_EXPR, |
| 23 |
TREE_MESSAGE_LIST, |
| 24 |
TREE_DYNAMIC_ARRAY, |
| 25 |
|
| 26 |
TREE_FIRST = TREE_METHOD_NODE, |
| 27 |
TREE_LAST = TREE_DYNAMIC_ARRAY |
| 28 |
} |
| 29 |
node_type; |
| 30 |
|
| 31 |
/* A structure holding a constant for objects having byte-sized |
| 32 |
indexed instance variables(ByteArrays and LargeIntegers). */ |
| 33 |
typedef struct byte_object |
| 34 |
{ |
| 35 |
OOP class; |
| 36 |
int size; |
| 37 |
//gst_uchar body[1]; |
| 38 |
} |
| 39 |
*byte_object; |
| 40 |
|
| 41 |
/* A forward declaration. */ |
| 42 |
typedef struct tree_node *tree_node; |
| 43 |
|
| 44 |
/* A generic kind of parse-tree node that stores a list of nodes. In |
| 45 |
particular, NEXTADDR points to the last NEXT pointer in the list so |
| 46 |
that tail adds are easier. These nodes are also used for variables |
| 47 |
by storing their name in the NAME member and by setting an |
| 48 |
appropriate node type like TREE_VARIABLE_NODE(when the variable is |
| 49 |
an argument or the receiver of a message) or TREE_VAR_DECL_LIST(when |
| 50 |
the nodes is a list of arguments or temporaries). */ |
| 51 |
typedef struct list_node |
| 52 |
{ |
| 53 |
char *name; |
| 54 |
tree_node value; |
| 55 |
tree_node next; |
| 56 |
tree_node *nextAddr; |
| 57 |
} |
| 58 |
list_node; |
| 59 |
|
| 60 |
/* A parse-tree node for a message send. EXPRESSION is a list_node |
| 61 |
containing the arguments. The same data structure is also used for |
| 62 |
assignments(TREE_ASSIGN_EXPR) and in this case RECEIVER is the list |
| 63 |
of assigned-to variables, SELECTOR is dummy and EXPRESSION is the |
| 64 |
assigned value. */ |
| 65 |
typedef struct expr_node |
| 66 |
{ |
| 67 |
tree_node receiver; |
| 68 |
OOP selector; |
| 69 |
tree_node expression; |
| 70 |
} |
| 71 |
expr_node; |
| 72 |
|
| 73 |
/* The different kinds of constants that can be stored in a |
| 74 |
const_node. */ |
| 75 |
typedef enum { |
| 76 |
CONST_INT, |
| 77 |
CONST_LARGE_INT, |
| 78 |
CONST_FLOAT, |
| 79 |
CONST_DECIMAL, |
| 80 |
CONST_STRING, |
| 81 |
CONST_SYMBOL, |
| 82 |
CONST_OOP, |
| 83 |
CONST_BINDING, |
| 84 |
CONST_DATA, |
| 85 |
CONST_URI, |
| 86 |
CONST_ARRAY, |
| 87 |
PSEUDO_TRUE, |
| 88 |
PSEUDO_FALSE, |
| 89 |
PSEUDO_NIL, |
| 90 |
PSEUDO_SELF, |
| 91 |
PSEUDO_SUPER, |
| 92 |
PSEUDO_CONTEXT |
| 93 |
} const_type; |
| 94 |
|
| 95 |
/* A parse-tree node holding a constant. CONSTTYPE identifies which |
| 96 |
kind of constant is stored, the VAL union can include a long, a |
| 97 |
double, a string(char *), an OOP(typically a Symbol, Association |
| 98 |
or ScaledDecimal), an array(stored as a list_node) or a |
| 99 |
byte_object struct(for ByteArrays and LargeIntegers). */ |
| 100 |
typedef struct const_node |
| 101 |
{ |
| 102 |
const_type constType; |
| 103 |
union |
| 104 |
{ |
| 105 |
long iVal; |
| 106 |
long double fVal; |
| 107 |
char *sVal; |
| 108 |
OOP oopVal; |
| 109 |
tree_node aVal; |
| 110 |
} |
| 111 |
val; |
| 112 |
} |
| 113 |
const_node; |
| 114 |
|
| 115 |
/* A parse-tree node defining a method. SELECTOREXPR is an expr_node |
| 116 |
with a nil receiver, holding the selector for the method and |
| 117 |
a list_node(of type TREE_VAR_DECL_LIST) for the arguments. The |
| 118 |
method's temporaries and statements are also held in list_nodes |
| 119 |
(respectively, of course, TEMPORARIES and STATEMENTS). */ |
| 120 |
typedef struct method_node |
| 121 |
{ |
| 122 |
tree_node selectorExpr; |
| 123 |
tree_node temporaries; |
| 124 |
char *primitiveName; |
| 125 |
tree_node statements; |
| 126 |
} |
| 127 |
method_node; |
| 128 |
|
| 129 |
/* A parse-tree node defining a block. Not having a name, blocks |
| 130 |
hold arguments in a simple list_node as well. */ |
| 131 |
typedef struct block_node |
| 132 |
{ |
| 133 |
tree_node arguments; |
| 134 |
tree_node temporaries; |
| 135 |
tree_node statements; |
| 136 |
} |
| 137 |
block_node; |
| 138 |
|
| 139 |
|
| 140 |
/* A generic parse-tree node has a field marking the kind of |
| 141 |
node(NODETYPE) and a union holding the five different |
| 142 |
kinds of node(list_nodes, expr_nodes, const_node, |
| 143 |
method_nodes and block_nodes). */ |
| 144 |
struct tree_node |
| 145 |
{ |
| 146 |
node_type nodeType; |
| 147 |
union |
| 148 |
{ |
| 149 |
list_node nvList; |
| 150 |
expr_node nvExpr; |
| 151 |
const_node nvConst; |
| 152 |
method_node nvMethod; |
| 153 |
block_node nvBlock; |
| 154 |
} |
| 155 |
nodeVal; |
| 156 |
}; |
| 157 |
|
| 158 |
#define v_block nodeVal.nvBlock |
| 159 |
#define v_list nodeVal.nvList |
| 160 |
#define v_expr nodeVal.nvExpr |
| 161 |
#define v_const nodeVal.nvConst |
| 162 |
#define v_method nodeVal.nvMethod |
| 163 |
|
| 164 |
|
| 165 |
/* This is how nil is printed. */ |
| 166 |
extern char *nil_name; |
| 167 |
|
| 168 |
|
| 169 |
/* Create a method_node with the given fields(see description under |
| 170 |
struct method_node). TEMPORARIES can possibly be NULL. If the |
| 171 |
method has a primitive associated with it, then the PRIMITIVENAME |
| 172 |
is not NULL. */ |
| 173 |
extern tree_node make_method(tree_node selectorExpr, |
| 174 |
tree_node temporaries, |
| 175 |
char *primitiveName, |
| 176 |
tree_node statements); |
| 177 |
|
| 178 |
/* Create a const_node for an object, OVAL, which is typically a |
| 179 |
ScaledDecimal. */ |
| 180 |
extern tree_node make_oop_constant(OOP oval); |
| 181 |
|
| 182 |
/* Create a TREE_SYMBOL_NODE describing an identifier(variable, |
| 183 |
unary/binary selector or symbol constant, it doesn't patter) pointed |
| 184 |
to by IDENT. */ |
| 185 |
extern tree_node intern_ident(char *ident); |
| 186 |
|
| 187 |
/* Free the objects on the compilation obstack. */ |
| 188 |
extern void free_tree(); |
| 189 |
|
| 190 |
/* Print the NODE with LEVEL spaces of indentation. */ |
| 191 |
extern void print_tree(tree_node node, |
| 192 |
int level); |
| 193 |
|
| 194 |
|
| 195 |
#endif /* TREE_H */ |