File: tree.h

package info (click to toggle)
gnu-smalltalk 3.2.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,688 kB
  • ctags: 14,104
  • sloc: ansic: 87,424; sh: 22,729; asm: 8,465; perl: 4,513; cpp: 3,548; xml: 1,669; awk: 1,581; yacc: 1,357; makefile: 1,237; lisp: 855; lex: 843; sed: 258; objc: 124
file content (448 lines) | stat: -rw-r--r-- 15,079 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/******************************** -*- C -*- ****************************
 *
 *	Semantic Tree information declarations.
 *
 *
 ***********************************************************************/

/***********************************************************************
 *
 * Copyright 1988,89,90,91,92,94,95,99,2000,2001,2002,2003,2006
 * Free Software Foundation, Inc.
 * Written by Steve Byrne.
 *
 * This file is part of GNU Smalltalk.
 *
 * GNU Smalltalk is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2, or (at your option) any later 
 * version.
 * 
 * Linking GNU Smalltalk statically or dynamically with other modules is
 * making a combined work based on GNU Smalltalk.  Thus, the terms and
 * conditions of the GNU General Public License cover the whole
 * combination.
 *
 * In addition, as a special exception, the Free Software Foundation
 * give you permission to combine GNU Smalltalk with free software
 * programs or libraries that are released under the GNU LGPL and with
 * independent programs running under the GNU Smalltalk virtual machine.
 *
 * You may copy and distribute such a system following the terms of the
 * GNU GPL for GNU Smalltalk and the licenses of the other code
 * concerned, provided that you include the source code of that other
 * code when and as the GNU GPL requires distribution of source code.
 *
 * Note that people who make modified versions of GNU Smalltalk are not
 * obligated to grant this special exception for their modified
 * versions; it is their choice whether to do so.  The GNU General
 * Public License gives permission to release a modified version without
 * this exception; this exception also makes it possible to release a
 * modified version which carries forward this exception.
 *
 * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  
 *
 ***********************************************************************/



#ifndef GST_TREE_H
#define GST_TREE_H

/* These are the possible types of parse-tree nodes */
typedef enum
{
  TREE_METHOD_NODE,
  TREE_UNARY_EXPR,
  TREE_BINARY_EXPR,
  TREE_KEYWORD_EXPR,
  TREE_VARIABLE_NODE,
  TREE_ATTRIBUTE_LIST,
  TREE_KEYWORD_LIST,
  TREE_VAR_DECL_LIST,
  TREE_VAR_ASSIGN_LIST,
  TREE_STATEMENT_LIST,
  TREE_RETURN_EXPR,
  TREE_ASSIGN_EXPR,
  TREE_CONST_EXPR,
  TREE_SYMBOL_NODE,
  TREE_ARRAY_ELT_LIST,
  TREE_BLOCK_NODE,
  TREE_CASCADE_EXPR,
  TREE_MESSAGE_LIST,
  TREE_ARRAY_CONSTRUCTOR,

  TREE_FIRST = TREE_METHOD_NODE,
  TREE_LAST = TREE_ARRAY_CONSTRUCTOR
}
node_type;

/* A structure holding a constant for objects having byte-sized
   indexed instance variables (ByteArrays and LargeIntegers).  */
typedef struct byte_object
{
  OOP class;
  int size;
  gst_uchar body[1];
}
 *byte_object;

/* A forward declaration.  */
typedef struct tree_node *tree_node;

#include "gst-parse.h"

/* A generic kind of parse-tree node that stores a list of nodes.  In
   particular, NEXTADDR points to the last NEXT pointer in the list so
   that tail adds are easier.  These nodes are also used for variables
   by storing their name in the NAME member and by setting an
   appropriate node type like TREE_VARIABLE_NODE (when the variable is
   an argument or the receiver of a message) or TREE_VAR_DECL_LIST (when
   the nodes is a list of arguments or temporaries).  */
typedef struct list_node
{
  const char *name;
  tree_node value;
  tree_node next;
  tree_node *nextAddr;
}
list_node;

/* A parse-tree node for a message send.  EXPRESSION is a list_node
   containing the arguments.  The same data structure is also used for
   assignments (TREE_ASSIGN_EXPR) and in this case RECEIVER is the list
   of assigned-to variables, SELECTOR is dummy and EXPRESSION is the
   assigned value.  */
typedef struct expr_node
{
  tree_node receiver;
  OOP selector;
  tree_node expression;
}
expr_node;

/* The different kinds of constants that can be stored in a
   const_node.  */
typedef enum
{
  CONST_BYTE_OBJECT,
  CONST_INT,
  CONST_CHAR,
  CONST_FLOATD,
  CONST_FLOATE,
  CONST_FLOATQ,
  CONST_STRING,
  CONST_OOP,
  CONST_BINDING,
  CONST_DEFERRED_BINDING,
  CONST_ARRAY
}
const_type;

/* A parse-tree node holding a constant.  CONSTTYPE identifies which
   kind of constant is stored, the VAL union can include an intptr_t, a
   double, a string (char *), an OOP (typically a Symbol, Association
   or ScaledDecimal), an array (stored as a list_node) or a
   byte_object struct (for ByteArrays and LargeIntegers).  */
typedef struct const_node
{
  const_type constType;
  union
  {
    intptr_t iVal;
    long double fVal;
    const char *sVal;
    OOP oopVal;
    tree_node aVal;
    byte_object boVal;
  }
  val;
}
const_node;

/* A parse-tree node defining a method.  SELECTOREXPR is an expr_node
   with a nil receiver, holding the selector for the method and
   a list_node (of type TREE_VAR_DECL_LIST) for the arguments.  The
   method's temporaries and statements are also held in list_nodes
   (respectively, of course, TEMPORARIES and STATEMENTS).  The final
   field is the ending position of the method in the current stream,
   or -1 if the stream is not file-based.  */
typedef struct method_node
{
  tree_node selectorExpr;
  tree_node temporaries;
  tree_node attributes;
  tree_node statements;
  int64_t endPos;
  mst_Boolean isOldSyntax;
}
method_node;

/* A parse-tree node defining a block.  Not having a name, blocks
   hold arguments in a simple list_node as well.  */
typedef struct block_node
{
  tree_node arguments;
  tree_node temporaries;
  tree_node statements;
}
block_node;


/* A generic parse-tree node has a field marking the kind of
   node (NODETYPE) and a union holding the five different
   kinds of node (list_nodes, expr_nodes, const_node,
   method_nodes and block_nodes).  */
struct tree_node
{
  node_type nodeType;
  YYLTYPE location;
  union
  {
    list_node nvList;
    expr_node nvExpr;
    const_node nvConst;
    method_node nvMethod;
    block_node nvBlock;
  }
  nodeVal;
};

#define v_block		nodeVal.nvBlock
#define v_list		nodeVal.nvList
#define v_expr		nodeVal.nvExpr
#define v_const		nodeVal.nvConst
#define v_method	nodeVal.nvMethod


/* Create a method_node with the given fields (see description under
   struct method_node).  TEMPORARIES can possibly be NULL.  If the
   method has any attributes associated with it, then they are in
   ATTRIBUTES.  */
extern tree_node _gst_make_method (YYLTYPE *startLocation,
                                   YYLTYPE *endLocation,
				   tree_node selectorExpr,
				   tree_node temporaries,
				   tree_node attributes,
				   tree_node statements,
				   int isOldSyntax)
  ATTRIBUTE_HIDDEN;

/* Create an expr_node to be passed to _gst_make_method for a unary
   selector, or representing a send of a unary message
   UNARYSELECTOREXPR to the object identified by RECEIVER.  */
extern tree_node _gst_make_unary_expr (YYLTYPE *location,
				       tree_node receiver,
				       const char *unarySelectorExpr)
  ATTRIBUTE_HIDDEN;

/* Create an expr_node to be passed to _gst_make_method for
   a binary selector, or representing a send of a binary message
   BINARYOP to the object identified by RECEIVER, with the given
   ARGUMENT.  */
extern tree_node _gst_make_binary_expr (YYLTYPE *location,
				        tree_node receiver,
					const char *binaryOp,
					tree_node argument)
  ATTRIBUTE_HIDDEN;

/* Create an expr_node to be passed to _gst_make_method for a keyword
   selector, or representing a send of a keyword message identified by
   KEYWORDMESSAGE to the object identified by RECEIVER.  The selector
   is split across the different list_nodes making up KEYWORDMESSAGE
   and joined at compilation time.  */
extern tree_node _gst_make_keyword_expr (YYLTYPE *location,
				  	 tree_node receiver,
					 tree_node keywordMessage)
  ATTRIBUTE_HIDDEN;

/* Create a list_node that represents a variable called NAME (it does
   not matter if it is a global, local, or instance variable, or an
   argument).  */
extern tree_node _gst_make_variable (YYLTYPE *location,
				     const char *name)
  ATTRIBUTE_HIDDEN;

/* Create a list_node that represents a part of a keyword selector,
   KEYWORD, together with the corresponding argument EXPRESSION.  */
extern tree_node _gst_make_keyword_list (YYLTYPE *location,
				         const char *keyword,
					 tree_node expression)
  ATTRIBUTE_HIDDEN;

/* Given a keyword list node, modify it in place to make an attribute list
   tree node; evaluate all non-constant arguments and return NULL if
   any evaluation fails.  */
extern tree_node _gst_make_attribute_list (YYLTYPE *location,
					   tree_node keywords)
  ATTRIBUTE_HIDDEN;

/* Given a variable tree node, convert it to a variable list tree node
   with a NULL next link.  */
extern tree_node _gst_make_variable_list (YYLTYPE *location,
				  	  tree_node variable)
  ATTRIBUTE_HIDDEN;

/* Given a variable tree node, convert it to an assignment list tree node
   with a NULL next link.  */
extern tree_node _gst_make_assignment_list (YYLTYPE *location,
				  	    tree_node variable)
  ATTRIBUTE_HIDDEN;

/* Create an expr_node of type TREE_ASSIGN_EXPR.  */
extern tree_node _gst_make_assign (YYLTYPE *location,
				   tree_node variables,
				   tree_node expression)
  ATTRIBUTE_HIDDEN;

/* Create an expr_node of type TREE_RETURN_EXPR where the returned
   EXPRESSION is stored in the RECEIVER field of the node.  */
extern tree_node _gst_make_return (YYLTYPE *location,
				   tree_node expression)
  ATTRIBUTE_HIDDEN;

/* Create a const_node storing an intptr_t, IVAL.  */
extern tree_node _gst_make_int_constant (YYLTYPE *location,
				  	 intptr_t ival)
  ATTRIBUTE_HIDDEN;

/* Create a const_node storing a double, FVAL.  The type (FloatD,
   FloatE, FloatQ) is given by TYPE.  */
extern tree_node _gst_make_float_constant (YYLTYPE *location,
				  	   long double fval,
					   int type)
  ATTRIBUTE_HIDDEN;

/* Create a const_node storing a char, IVAL.  */
extern tree_node _gst_make_char_constant (YYLTYPE *location,
				  	  int ival)
  ATTRIBUTE_HIDDEN;

/* Create a const_node storing a symbol, pointed to by the 
   SYMBOLNODE's NAME member.  The symbol is interned and the
   const_node is created with its OOP.  */
extern tree_node _gst_make_symbol_constant (YYLTYPE *location,
				  	    tree_node symbolNode)
  ATTRIBUTE_HIDDEN;

/* Create a const_node storing a string, pointed to by SVAL.  */
extern tree_node _gst_make_string_constant (YYLTYPE *location,
				  	    const char *sval)
  ATTRIBUTE_HIDDEN;

/* Create a const_node storing a deferred variable binding, whose key
   is the variable VARNODE.  */
extern tree_node _gst_make_deferred_binding_constant (YYLTYPE *location,
						      tree_node varNode)
  ATTRIBUTE_HIDDEN;

/* Create a const_node for an array whose elements are
   described by the nodes in the list, AVAL.  */
extern tree_node _gst_make_array_constant (YYLTYPE *location,
				  	   tree_node aval)
  ATTRIBUTE_HIDDEN;

/* Create a const_node for the byte_object BOVAL (a LargeInteger).  */
extern tree_node _gst_make_byte_object_constant (YYLTYPE *location,
				  	         byte_object boval)
  ATTRIBUTE_HIDDEN;

/* Create a const_node for a ByteArray object, creating a
   byteObjectConst out of the single elements which are stored in AVAL
   as a list_node.  That is, this method converts from CONST_ARRAY
   format to byteObjectConst format and answer the resulting
   const_node.  */
extern tree_node _gst_make_byte_array_constant (YYLTYPE *location,
				  	        tree_node aval)
  ATTRIBUTE_HIDDEN;

/* Create a const_node for an object, OVAL, which is typically a
   Class or ScaledDecimal.  */
extern tree_node _gst_make_oop_constant (YYLTYPE *location,
				  	 OOP oval)
  ATTRIBUTE_HIDDEN;

/* Create an TREE_ARRAY_CONSTRUCTOR node, that is a const_node whose
   aVal does not contain other constants, but rather statements to be
   evaluated at run-time and whose results are to put each in an
   element of the array.  */
extern tree_node _gst_make_array_constructor (YYLTYPE *location,
				  	      tree_node statements)
  ATTRIBUTE_HIDDEN;

/* Resolve the variable binding to an association and create a
   const_node of CONST_OOP type.  */
extern tree_node _gst_make_binding_constant (YYLTYPE *location,
				  	     tree_node variables)
  ATTRIBUTE_HIDDEN;

/* Create a TREE_SYMBOL_NODE describing an identifier (variable,
   unary/binary selector or symbol constant, it doesn't patter) pointed
   to by IDENT.  */
extern tree_node _gst_intern_ident (YYLTYPE *location,
				    const char *ident)
  ATTRIBUTE_HIDDEN;

/* Create an element of an array constant, which is a list type object.
   Return the element with the next field NILed out and pointing to
   the first element, ELT.  */
extern tree_node _gst_make_array_elt (YYLTYPE *location,
				      tree_node elt)
  ATTRIBUTE_HIDDEN;

/* Creates a block tree node with the given ARGUMENTS, TEMPORARIES and
   STATEMENTS.  */
extern tree_node _gst_make_block (YYLTYPE *location,
				  tree_node arguments,
				  tree_node temporaries,
				  tree_node statements)
  ATTRIBUTE_HIDDEN;

/* Creates a node for holding a list of cascaded messages (basically an
   expr_node that isn't using its symbol.  MESSAGEEXPR is the expression
   invoke first as it computes the receiver.  Then the remaining
   CASCADEDMESSAGES are sent to that same receiver.  */
extern tree_node _gst_make_cascaded_message (YYLTYPE *location,
				   	     tree_node messageExpr,
					     tree_node cascadedMessages)
  ATTRIBUTE_HIDDEN;

/* Create a node of type TREE_STATEMENT_LIST, where the first node is
   EXPRESSION.  */
extern tree_node _gst_make_statement_list (YYLTYPE *location,
					   tree_node expression)
  ATTRIBUTE_HIDDEN;

/* Create a TREE_MESSAGE_LIST which is used as the second parameter to
   _gst_make_cascaded_message -- that is, it represents the sends after
   the first.  */
extern tree_node _gst_make_message_list (YYLTYPE *location,
				   	 tree_node messageElt)
  ATTRIBUTE_HIDDEN;

/* Adds node N2 onto a list of nodes headed by N1.  N1 contains the
   address of the last NEXT field in the chain, so storing N2 into
   there indirectly and then making that NEXT field point to N2's NEXT
   field works properly.  */
extern tree_node _gst_add_node (tree_node n1,
				tree_node n2)
  ATTRIBUTE_HIDDEN;

/* Free the objects on the compilation obstack.  */
extern void _gst_free_tree ()
  ATTRIBUTE_HIDDEN;

/* Print the NODE with LEVEL spaces of indentation.  */
extern void _gst_print_tree (tree_node node,
			     int level)
  ATTRIBUTE_HIDDEN;


#endif /* GST_TREE_H */