1 // $Id: ast.h,v 1.74 2004/03/25 13:32:26 ericb Exp $ -*- c++ -*-
2 //
3 // This software is subject to the terms of the IBM Jikes Compiler
4 // License Agreement available at the following URL:
5 // http://ibm.com/developerworks/opensource/jikes.
6 // Copyright (C) 1996, 2004 IBM Corporation and others. All Rights Reserved.
7 // You must accept the terms of that agreement to use this software.
8 //
9
10 #ifndef ast_INCLUDED
11 #define ast_INCLUDED
12
13 #include "platform.h"
14 #include "depend.h"
15
16 #ifdef HAVE_JIKES_NAMESPACE
17 namespace Jikes { // Open namespace Jikes block
18 #endif
19
20
21 class Parser;
22 class SemanticEnvironment;
23 class LexStream;
24 class LiteralValue;
25 class Symbol;
26 class BlockSymbol;
27 class VariableSymbol;
28 class MethodSymbol;
29 class TypeSymbol;
30 class StoragePool;
31 struct CaseElement;
32
33 class VariableSymbolArray
34 {
35 typedef VariableSymbol* T;
36
37 T** base;
38 size_t base_size;
39 unsigned top;
40 unsigned size;
41 StoragePool* pool;
42 unsigned short log_blksize;
43 unsigned short base_increment;
44
Blksize()45 inline size_t Blksize() { return 1 << log_blksize; }
46
47 //
48 // Allocate another block of storage for the VariableSymbol array.
49 //
50 void AllocateMoreSpace();
51
52 public:
53 //
54 // This function is used to reset the size of a VariableSymbol array
55 // without allocating or deallocting space. It may be invoked with an
56 // integer argument n which indicates the new size or with no argument
57 // which indicates that the size should be reset to 0.
58 //
59 void Reset(unsigned n = 0)
60 {
61 assert(n <= size);
62 top = n;
63 }
64
65 //
66 // Return length of the VariableSymbol array.
67 //
Length()68 unsigned Length() { return top; }
69
70 //
71 // Return a reference to the ith element of the VariableSymbol array.
72 //
73 // Note that no check is made here to ensure that 0 <= i < top.
74 // Such a check might be useful for debugging and a range exception
75 // should be thrown if it yields true.
76 //
77 T& operator[](unsigned i) { return base[i >> log_blksize][i]; }
78
79 //
80 // Add an element to the VariableSymbol array and return the top index.
81 //
NextIndex()82 unsigned NextIndex()
83 {
84 unsigned i = top++;
85 if (i == size)
86 AllocateMoreSpace();
87 return i;
88 }
89
90 //
91 // Add an element to the VariableSymbol array and return a reference to
92 // that new element.
93 //
Next()94 T& Next()
95 {
96 unsigned i = NextIndex();
97 return base[i >> log_blksize][i];
98 }
99
100 //
101 // Constructor of a VariableSymbol array.
102 //
103 VariableSymbolArray(StoragePool*, unsigned);
104
105 //
106 // Destructor of an VariableSymbol array.
107 //
~VariableSymbolArray()108 ~VariableSymbolArray() { assert(false); }
109 };
110
111
112 //***************************************************************************
113 //
114 // TODO: This documentation is a bit out of date...
115 //
116 // This file contains the definitions of the classes used to construct the
117 // AST representation of a Java program.
118 //
119 // The node Ast is a base class of all other classes. (The name of the other
120 // classes start with the prefix "Ast".) The nodes associated with executable
121 // statements (e.g., AstIfStatement) are subclasses of AstStatement and nodes
122 // associated with expressions (e.g., AstBinaryExpression) are subclasses of
123 // AstExpression.
124 //
125 // The information contained in the AST nodes is described by a grammar where
126 // each rule consists of a left-hand side nonterminal followed by "-->"
127 // followed by a right-hand side symbol or a sequence enclosed in the pair of
128 // symbols "<" and ">". In defining the symbols, the following notation is
129 // used:
130 //
131 // Symbols that are capitalized (e.g., Type) are nonterminals. Symbols that are
132 // in all upper case (e.g., PACKAGE) represent node kinds. Symbols that contain
133 // the substring "_token" represents tokens in the source file. The suffix
134 // "_opt" indicates that a symbol is optional. For example, if Super_opt
135 // appears in a rule, it indicates that either Super or null can be expected.
136 // When a symbol is plural (e.g., Modifiers), it indicates zero or more
137 // instances of such a symbol (a list to be precise) can be expected. Thus,
138 // when "Modifiers" is specified in the right-hand side of a rule either no
139 // Modifier or a sequence of them may appear.
140 //
141 // Implementation Notes:
142 //
143 // A complete AST tree for a Java program always contains an
144 // AstCompilationUnit root node. The kind of that node is
145 // Ast::EMPTY_COMPILATION for a tree with no type declaration,
146 // Ast::COMPILATION for a tree constructed from an otherwise valid program
147 // and Ast::BAD_COMPILATION for a tree constructed from an invalid program.
148 //
149 // All AST tree nodes belong to a StoragePool. When a new node must be
150 // added, it is allocated from the same StoragePool. Thus, you should
151 // never use operator new to construct an AST object, but instead use New*
152 // or Gen* defined in StoragePool. Likewise, AST tree nodes never need
153 // destruction - simply delete the pool to reclaim the entire tree.
154 //
155 // When the preprocessor variable JIKES_DEBUG is defined the user may print
156 // out an AST tree to standard output by calling the virtual function
157 // "Print" for the root node of the tree.
158 //
159 // DynamicArrays are used to implement lists. This representation has the
160 // advantage of being very flexible and easy to use. However, it may be
161 // slightly less time-efficient than a straightforward linked list. My
162 // guess is no more than 10% which justifies this use, but that should be
163 // checked at some point...
164 //
165 //***************************************************************************
166 //
167 // This is a complete list of all Ast nodes declared here to allow
168 // forward references.
169 //
170 class Ast;
171 template <typename T> class AstArray;
172 class AstListNode;
173 class AstDeclared;
174 class AstDeclaredType;
175 class AstStatement;
176 class AstMemberValue;
177 class AstExpression;
178 class AstType;
179
180 class AstBlock;
181 class AstName;
182 class AstPrimitiveType;
183 class AstBrackets;
184 class AstArrayType;
185 class AstWildcard;
186 class AstTypeArguments;
187 class AstTypeName;
188 class AstMemberValuePair;
189 class AstAnnotation;
190 class AstModifierKeyword;
191 class AstModifiers;
192 class AstPackageDeclaration;
193 class AstImportDeclaration;
194 class AstCompilationUnit;
195 class AstEmptyDeclaration;
196 class AstClassBody;
197 class AstTypeParameter;
198 class AstTypeParameters;
199 class AstClassDeclaration;
200 class AstArrayInitializer;
201 class AstVariableDeclaratorId;
202 class AstVariableDeclarator;
203 class AstFieldDeclaration;
204 class AstFormalParameter;
205 class AstMethodDeclarator;
206 class AstMethodBody;
207 class AstMethodDeclaration;
208 class AstInitializerDeclaration;
209 class AstArguments;
210 class AstThisCall;
211 class AstSuperCall;
212 class AstConstructorDeclaration;
213 class AstEnumDeclaration;
214 class AstEnumConstant;
215 class AstInterfaceDeclaration;
216 class AstAnnotationDeclaration;
217 class AstLocalVariableStatement;
218 class AstLocalClassStatement;
219 class AstIfStatement;
220 class AstEmptyStatement;
221 class AstExpressionStatement;
222 class AstSwitchLabel;
223 class AstSwitchBlockStatement;
224 class AstSwitchStatement;
225 class AstWhileStatement;
226 class AstDoStatement;
227 class AstForStatement;
228 class AstForeachStatement;
229 class AstBreakStatement;
230 class AstContinueStatement;
231 class AstReturnStatement;
232 class AstThrowStatement;
233 class AstSynchronizedStatement;
234 class AstAssertStatement;
235 class AstCatchClause;
236 class AstFinallyClause;
237 class AstTryStatement;
238 class AstIntegerLiteral;
239 class AstLongLiteral;
240 class AstFloatLiteral;
241 class AstDoubleLiteral;
242 class AstTrueLiteral;
243 class AstFalseLiteral;
244 class AstStringLiteral;
245 class AstCharacterLiteral;
246 class AstNullLiteral;
247 class AstClassLiteral;
248 class AstThisExpression;
249 class AstSuperExpression;
250 class AstParenthesizedExpression;
251 class AstClassCreationExpression;
252 class AstDimExpr;
253 class AstArrayCreationExpression;
254 class AstFieldAccess;
255 class AstMethodInvocation;
256 class AstArrayAccess;
257 class AstPostUnaryExpression;
258 class AstPreUnaryExpression;
259 class AstCastExpression;
260 class AstBinaryExpression;
261 class AstInstanceofExpression;
262 class AstConditionalExpression;
263 class AstAssignmentExpression;
264
265 //
266 // The Ast base node.
267 //
268 class Ast
269 {
270 public:
271 //
272 // These tags are used to identify nodes that can represent more than
273 // one kind of objects.
274 //
275 enum AstTag
276 {
277 NO_TAG,
278 PRIMITIVE_TYPE,
279 STATEMENT,
280 EXPRESSION,
281
282 _num_tags = EXPRESSION
283 };
284
285 //
286 // These are the different kinds for the Ast objects.
287 //
288 enum AstKind
289 {
290 AST, // must be first
291 // Expressions
292 NAME,
293 DOT,
294 INTEGER_LITERAL,
295 LONG_LITERAL,
296 FLOAT_LITERAL,
297 DOUBLE_LITERAL,
298 TRUE_LITERAL,
299 FALSE_LITERAL,
300 STRING_LITERAL,
301 CHARACTER_LITERAL,
302 NULL_LITERAL,
303 CLASS_LITERAL,
304 THIS_EXPRESSION,
305 SUPER_EXPRESSION,
306 PARENTHESIZED_EXPRESSION,
307 ARRAY_ACCESS,
308 CALL,
309 CLASS_CREATION,
310 ARRAY_CREATION,
311 POST_UNARY,
312 PRE_UNARY,
313 CAST,
314 BINARY,
315 INSTANCEOF,
316 CONDITIONAL,
317 ASSIGNMENT,
318 _num_expression_kinds,
319 // Statements
320 THIS_CALL,
321 SUPER_CALL,
322 BLOCK,
323 IF,
324 EMPTY_STATEMENT,
325 EXPRESSION_STATEMENT,
326 SWITCH,
327 SWITCH_BLOCK,
328 LOCAL_VARIABLE_DECLARATION,
329 LOCAL_CLASS,
330 WHILE,
331 DO,
332 FOR,
333 FOREACH,
334 BREAK,
335 CONTINUE,
336 RETURN,
337 THROW,
338 SYNCHRONIZED_STATEMENT,
339 ASSERT,
340 TRY,
341 _num_expr_or_stmt_kinds,
342 // All others
343 ARGUMENTS = _num_expr_or_stmt_kinds,
344 DIM,
345 LIST_NODE,
346 INT,
347 DOUBLE,
348 CHAR,
349 LONG,
350 FLOAT,
351 BYTE,
352 SHORT,
353 BOOLEAN,
354 VOID_TYPE,
355 ARRAY,
356 WILDCARD,
357 TYPE_ARGUMENTS,
358 TYPE,
359 COMPILATION,
360 MEMBER_VALUE_PAIR,
361 ANNOTATION,
362 MODIFIER_KEYWORD,
363 MODIFIERS,
364 PACKAGE,
365 IMPORT,
366 EMPTY_DECLARATION,
367 CLASS,
368 TYPE_PARAM,
369 PARAM_LIST,
370 CLASS_BODY,
371 FIELD,
372 VARIABLE_DECLARATOR,
373 VARIABLE_DECLARATOR_NAME,
374 BRACKETS,
375 METHOD,
376 METHOD_DECLARATOR,
377 PARAMETER,
378 CONSTRUCTOR,
379 ENUM_TYPE,
380 ENUM,
381 INTERFACE,
382 ANNOTATION_TYPE,
383 ARRAY_INITIALIZER,
384 INITIALIZER,
385 METHOD_BODY,
386 SWITCH_LABEL,
387 CATCH,
388 FINALLY,
389 _num_kinds
390 };
391
392 //
393 // Every node has a unique kind, and class_tag marks groups of similar
394 // nodes. The bit-fields allow smaller Ast objects without sacrificing
395 // type-safety or debug visibility.
396 //
397 const AstKind kind : 8;
398 const AstTag class_tag : 8;
399
400 //
401 // This is a catch-all set of bits free for the use of subclasses.
402 // See CompilationTag, FieldDeclarationTag, InitializerDeclarationTag,
403 // ClassBodyTag, BlockTag, PreUnaryExpressionTag, PostUnaryExpressionTag,
404 // BinaryExpressionTag, AssignmentExpressionTag.
405 //
406 protected:
407 unsigned other_tag : 8;
408
409 //
410 // "generated" is a boolean value that indicates whether or not a node
411 // is associated with a construct in a source file or that is was generated
412 // by the compiler. See functions "gen_ ..." and "new_ ..." below.
413 //
414 public:
415 bool generated;
416
417 #ifdef JIKES_DEBUG
418 const unsigned id;
419 static unsigned count;
420 static bool debug_unparse;
421 #endif // JIKES_DEBUG
422
423 //
424 // Note that ALL fields of an Ast are initialized to 0 unless modified
425 // by the constructor, thanks to the 0-initialization guaranteed by
426 // operator new. This allows for more efficiency by not redundantly
427 // setting a field to 0, false, or NULL.
428 //
429 inline Ast(AstKind k, AstTag t = NO_TAG)
kind(k)430 : kind(k)
431 , class_tag(t)
432 #ifdef JIKES_DEBUG
433 , id(++count)
434 #endif // JIKES_DEBUG
435 {}
436
437 //
438 // Ast nodes should be created from a storage pool. Use the syntax
439 // new (pool) AstSubclass(constructor arguments). The resultant Ast
440 // will be zero-initialized except for what the constructor explicitly
441 // sets, due to the properties of StoragePool. Note that there are
442 // no Ast[]; rather, use AstArray<Ast*>.
443 //
444 inline void* operator new(size_t, StoragePool*);
445 private:
446 void* operator new[](size_t, void* p) { assert(false); return p; }
447 public:
448
449 //
450 // ASTs should not be destructed. Instead, delete the containing
451 // StoragePool.
452 //
~Ast()453 virtual ~Ast() { assert(false && "Use the associated StoragePool"); }
454
455 #ifdef JIKES_DEBUG
456 virtual void Print(LexStream&) = 0;
457 virtual void Unparse(Ostream&, LexStream*) = 0;
458 #endif // JIKES_DEBUG
459
460 //
461 // General queries.
462 //
463 bool IsLeftHandSide();
464 bool IsExplicitConstructorInvocation();
465 bool IsGenerated();
466
467 //
468 // The Conversion functions below are provided as a convenient way to
469 // cast a generic Ast node into a specific node. Note that if one knows
470 // the type of a node for sure, it is more efficient to use a specific
471 // cast expression. For example, if one knows that a "Ast* p" pointer
472 // dereferences a FieldDeclaration then a cast expression should be
473 // used to cast p, as follows:
474 //
475 // AstFieldDeclaration* fp = (FieldDeclaration*) p;
476 //
477 // However, if p points to a ClassBodyDeclaration, it may be a
478 // FieldDeclaration, MethodDeclaration, ConstructorDeclaration,
479 // InitializerDeclaration, ClassDeclaration, EnumDeclaration,
480 // InterfaceDeclaration, or AnnotationDeclaration; and the following
481 // sequence of code may be used:
482 //
483 // AstFieldDeclaration* fp = FieldDeclarationCast();
484 // AstMethodDeclaration* mp = MethodDeclarationCast();
485 // AstConstructorDeclaration* cp = ConstructorDeclarationCast();
486 // AstInitializerDeclaration* sp = InitializerdeclarationCast();
487 // AstClassDeclaration* Cp = ClassDeclarationCast(); // 1.1 only
488 // AstEnumDeclaration* Ep = EnumDeclarationCast(); // 1.5 only
489 // AstInterfaceDeclaration* Ip = InterfaceDeclarationCast(); // 1.1 only
490 // AstAnnotationDeclaration* Ap = AnnotationDeclarationCast(); // 1.5
491 //
492 // if (fp)
493 // ...
494 // else if (mp)
495 // ...
496 // else if (cp)
497 // ...
498 // else if (sp)
499 // ...
500 // else if (Cp)
501 // ...
502 // else if (Ep)
503 // ...
504 // else if (Ip)
505 // ...
506 // else if (Ap)
507 // ...
508 //
509
510 //
511 // These cast functions are used for classes that represent more than
512 // one kind of nodes. The functions must be listed after the subclasses
513 // have been defined.
514 //
515 inline AstStatement* StatementCast();
516 inline AstMemberValue* MemberValueCast();
517 inline AstExpression* ExpressionCast();
518 inline AstPrimitiveType* PrimitiveTypeCast();
519 inline AstFieldDeclaration* StaticFieldCast();
520 inline AstInitializerDeclaration* StaticInitializerCast();
521 inline AstClassBody* UnparsedClassBodyCast();
522 inline AstCompilationUnit* BadCompilationUnitCast();
523 inline AstCompilationUnit* EmptyCompilationUnitCast();
524
525 //
526 // These cast functions are used for classes that represent exactly
527 // one kind of node.
528 //
529 inline AstListNode* ListNodeCast();
530 inline AstBlock* BlockCast();
531 inline AstName* NameCast();
532 inline AstBrackets* BracketsCast();
533 inline AstArrayType* ArrayTypeCast();
534 inline AstWildcard* WildcardCast();
535 inline AstTypeArguments* TypeArgumentsCast();
536 inline AstTypeName* TypeNameCast();
537 inline AstMemberValuePair* MemberValuePairCast();
538 inline AstAnnotation* AnnotationCast();
539 inline AstModifierKeyword* ModifierKeywordCast();
540 inline AstModifiers* ModifiersCast();
541 inline AstPackageDeclaration* PackageDeclarationCast();
542 inline AstImportDeclaration* ImportDeclarationCast();
543 inline AstCompilationUnit* CompilationUnitCast();
544 inline AstEmptyDeclaration* EmptyDeclarationCast();
545 inline AstClassBody* ClassBodyCast();
546 inline AstTypeParameter* TypeParameterCast();
547 inline AstTypeParameters* TypeParametersCast();
548 inline AstClassDeclaration* ClassDeclarationCast();
549 inline AstArrayInitializer* ArrayInitializerCast();
550 inline AstVariableDeclaratorId* VariableDeclaratorIdCast();
551 inline AstVariableDeclarator* VariableDeclaratorCast();
552 inline AstFieldDeclaration* FieldDeclarationCast();
553 inline AstFormalParameter* FormalParameterCast();
554 inline AstMethodDeclarator* MethodDeclaratorCast();
555 inline AstMethodBody* MethodBodyCast();
556 inline AstMethodDeclaration* MethodDeclarationCast();
557 inline AstInitializerDeclaration* InitializerDeclarationCast();
558 inline AstArguments* ArgumentsCast();
559 inline AstThisCall* ThisCallCast();
560 inline AstSuperCall* SuperCallCast();
561 inline AstConstructorDeclaration* ConstructorDeclarationCast();
562 inline AstEnumDeclaration* EnumDeclarationCast();
563 inline AstEnumConstant* EnumConstantCast();
564 inline AstInterfaceDeclaration* InterfaceDeclarationCast();
565 inline AstAnnotationDeclaration* AnnotationDeclarationCast();
566 inline AstLocalVariableStatement* LocalVariableStatementCast();
567 inline AstLocalClassStatement* LocalClassStatementCast();
568 inline AstIfStatement* IfStatementCast();
569 inline AstEmptyStatement* EmptyStatementCast();
570 inline AstExpressionStatement* ExpressionStatementCast();
571 inline AstSwitchLabel* SwitchLabelCast();
572 inline AstSwitchBlockStatement* SwitchBlockStatementCast();
573 inline AstSwitchStatement* SwitchStatementCast();
574 inline AstWhileStatement* WhileStatementCast();
575 inline AstDoStatement* DoStatementCast();
576 inline AstForStatement* ForStatementCast();
577 inline AstForeachStatement* ForeachStatementCast();
578 inline AstBreakStatement* BreakStatementCast();
579 inline AstContinueStatement* ContinueStatementCast();
580 inline AstReturnStatement* ReturnStatementCast();
581 inline AstThrowStatement* ThrowStatementCast();
582 inline AstSynchronizedStatement* SynchronizedStatementCast();
583 inline AstAssertStatement* AssertStatementCast();
584 inline AstCatchClause* CatchClauseCast();
585 inline AstFinallyClause* FinallyClauseCast();
586 inline AstTryStatement* TryStatementCast();
587 inline AstIntegerLiteral* IntegerLiteralCast();
588 inline AstLongLiteral* LongLiteralCast();
589 inline AstFloatLiteral* FloatLiteralCast();
590 inline AstDoubleLiteral* DoubleLiteralCast();
591 inline AstTrueLiteral* TrueLiteralCast();
592 inline AstFalseLiteral* FalseLiteralCast();
593 inline AstStringLiteral* StringLiteralCast();
594 inline AstCharacterLiteral* CharacterLiteralCast();
595 inline AstNullLiteral* NullLiteralCast();
596 inline AstClassLiteral* ClassLiteralCast();
597 inline AstThisExpression* ThisExpressionCast();
598 inline AstSuperExpression* SuperExpressionCast();
599 inline AstParenthesizedExpression* ParenthesizedExpressionCast();
600 inline AstClassCreationExpression* ClassCreationExpressionCast();
601 inline AstDimExpr* DimExprCast();
602 inline AstArrayCreationExpression* ArrayCreationExpressionCast();
603 inline AstFieldAccess* FieldAccessCast();
604 inline AstMethodInvocation* MethodInvocationCast();
605 inline AstArrayAccess* ArrayAccessCast();
606 inline AstPostUnaryExpression* PostUnaryExpressionCast();
607 inline AstPreUnaryExpression* PreUnaryExpressionCast();
608 inline AstCastExpression* CastExpressionCast();
609 inline AstBinaryExpression* BinaryExpressionCast();
610 inline AstInstanceofExpression* InstanceofExpressionCast();
611 inline AstConditionalExpression* ConditionalExpressionCast();
612 inline AstAssignmentExpression* AssignmentExpressionCast();
613
614 //
615 // It would be nice if this could be covariant, as it would allow
616 // less casting. But MSVC++ can't yet handle covariant return
617 // types at all, and both GCC and HP's aCC croak with covariance during
618 // multiple inheritance (bummer). So, there is a bunch of hideous casting
619 // in ast.cpp that could otherwise be avoided if standards were followed.
620 //
621 // Clones are used for various things, such as pre-evaluating final
622 // constant values.
623 //
624 virtual Ast* Clone(StoragePool*) = 0;
625
626 //
627 // These functions return the left and right tokens of this tree branch.
628 //
629 virtual TokenIndex LeftToken() = 0;
630 virtual TokenIndex RightToken() = 0;
631 };
632
633
634 //
635 // This AstArray template class can be used to construct a bounds-checking
636 // array of Ast objects. The size of the array must be known up front, as
637 // it is allocated contiguously from a StoragePool (preferably the pool that
638 // also owns the Ast object which contains this array).
639 //
640 template <typename T>
641 class AstArray
642 {
643 const unsigned size;
644 unsigned top;
645 T* array;
646
647 public:
648 //
649 // Return length of the Ast array.
650 //
Length()651 unsigned Length() { return top; }
652
653 //
654 // Return a reference to the ith element of the Ast array.
655 //
656 T& operator[](unsigned i)
657 {
658 assert(i < top);
659 return array[i];
660 }
661
662 //
663 // Add an element to the Ast array and return a reference to
664 // that new element.
665 //
Next()666 T& Next()
667 {
668 assert(top < size);
669 return array[top++];
670 }
671
672 //
673 // Constructor of an Ast array.
674 //
675 AstArray(StoragePool*, unsigned);
676
677 //
678 // Ast arrays should not be destroyed. Rather, delete the StoragePool
679 // that was passed to the constructor.
680 //
~AstArray()681 ~AstArray() { assert(false && "Use the associated StoragePool"); }
682
683 //
684 // Ast arrays must be created via a StoragePool, and there are no
685 // AstArray[].
686 //
687 inline void* operator new(size_t, StoragePool*);
688 private:
689 void* operator new[](size_t, void* p) { assert(false); return p; }
690 };
691
692
693 //
694 // The Ast list node. This is a temporary object used in constructing lists
695 // while parsing the grammar; once constructed, the contents are extracted
696 // and this list is reclaimed. It is circular to make insertion easy while
697 // maintaining declaration order.
698 //
699 class AstListNode : public Ast
700 {
701 public:
702 AstListNode* next;
703 Ast* element;
704 unsigned index;
705
AstListNode()706 inline AstListNode()
707 : Ast(LIST_NODE)
708 {
709 #ifdef JIKES_DEBUG
710 --count; // don't count these nodes
711 #endif // JIKES_DEBUG
712 }
713
~AstListNode()714 ~AstListNode() {}
715
716 //
717 // These next three functions should never be called, since list nodes
718 // only exist long enough to create the AST tree and then are reclaimed.
719 //
Clone(StoragePool *)720 virtual Ast* Clone(StoragePool*) { assert(false); return NULL; }
721 #ifdef JIKES_DEBUG
Print(LexStream &)722 virtual void Print(LexStream&) { assert(false); }
Unparse(Ostream &,LexStream *)723 virtual void Unparse(Ostream&, LexStream*) { assert(false); }
724 #endif // JIKES_DEBUG
725
LeftToken()726 virtual TokenIndex LeftToken() { return element -> LeftToken(); }
RightToken()727 virtual TokenIndex RightToken() { return element -> RightToken(); }
728 };
729
730
731 //
732 // This class adds some type safety. It represents all member declarations
733 // in types. See DeclaredType, AstFieldDeclaration, AstMethodDeclaration,
734 // AstConstructorDeclaration, AstInitializerDeclaration, and AstEnumConstant.
735 //
736 class AstDeclared : public Ast
737 {
738 public:
739 AstModifiers* modifiers_opt;
740
AstDeclared(AstKind k)741 inline AstDeclared(AstKind k)
742 : Ast(k)
743 {}
~AstDeclared()744 ~AstDeclared() {}
745 };
746
747
748 //
749 // This class adds some type safety. It represents all type declarations.
750 // See AstClassDeclaration, AstEnumDeclaration, AstInterfaceDeclaration,
751 // AstAnnotationDeclaration, and AstEmptyDeclaration.
752 //
753 class AstDeclaredType : public AstDeclared
754 {
755 public:
756 AstClassBody* class_body;
757
AstDeclaredType(AstKind k)758 inline AstDeclaredType(AstKind k)
759 : AstDeclared(k)
760 {}
~AstDeclaredType()761 ~AstDeclaredType() {}
762
763 inline bool IsValid();
764 };
765
766
767 //
768 // This class represents statements.
769 //
770 class AstStatement : public Ast
771 {
772 public:
773 bool is_reachable;
774 bool can_complete_normally;
775
776 inline AstStatement(AstKind k, bool reachable = false,
777 bool can_complete = false)
Ast(k,STATEMENT)778 : Ast(k, STATEMENT)
779 , is_reachable(reachable)
780 , can_complete_normally(can_complete)
781 {}
~AstStatement()782 ~AstStatement() {}
783 };
784
785
786 //
787 // This is the superclass of constructs which can appear in an array
788 // initializer, including annotations added by JSR 175.
789 //
790 class AstMemberValue : public Ast
791 {
792 public:
793 // The field or method this expression resolves to, or the annotation type
794 // that the annotation resolves to.
795 Symbol* symbol;
796
797 inline AstMemberValue(AstKind k, AstTag t = NO_TAG)
Ast(k,t)798 : Ast(k, t)
799 {}
~AstMemberValue()800 ~AstMemberValue() {}
801
802 TypeSymbol* Type();
803 };
804
805
806 //
807 // This is the superclass of constructs which represent an expression.
808 //
809 class AstExpression : public AstMemberValue
810 {
811 public:
812 LiteralValue* value; // The compile-time constant value of the expression.
813
AstExpression(AstKind k)814 inline AstExpression(AstKind k)
815 : AstMemberValue(k, EXPRESSION)
816 {}
~AstExpression()817 ~AstExpression() {}
818
IsConstant()819 inline bool IsConstant() { return value != NULL; }
820 };
821
822
823 //
824 // This is the superclass of constructs which represent a type:
825 // AstPrimitiveType, AstArrayType, AstWildcard, and AstTypeName.
826 //
827 class AstType : public Ast
828 {
829 public:
830 TypeSymbol* symbol;
831
832 inline AstType(AstKind k, AstTag t = NO_TAG)
Ast(k,t)833 : Ast(k, t)
834 {}
~AstType()835 ~AstType() {}
836
837 virtual TokenIndex IdentifierToken() = 0;
838 };
839
840
841 //
842 // Blocks represent both method blocks and compound statements. The parser
843 // creates synthetic blocks around statements where blocks are optional (such
844 // as if statement branches), and around loops.
845 //
846 class AstBlock : public AstStatement
847 {
848 protected:
849 StoragePool* pool;
850
851 private:
852 AstArray<AstStatement*>* block_statements;
853 VariableSymbolArray* defined_variables;
854
855 public:
856 enum BlockTag
857 {
858 NONE,
859 TRY_CLAUSE_WITH_FINALLY,
860 TRY_CLAUSE_WITH_CATCH,
861 ABRUPT_TRY_FINALLY,
862 FINALLY,
863 SYNCHRONIZED,
864 SWITCH
865 };
866
867 BlockSymbol* block_symbol;
868 unsigned nesting_level;
869
870 TokenIndex label_opt;
871 TokenIndex left_brace_token;
872 TokenIndex right_brace_token;
873
874 bool no_braces;
875
876 inline AstBlock(StoragePool* p, AstKind k = BLOCK, bool reachable = false)
AstStatement(k,reachable)877 : AstStatement(k, reachable)
878 , pool(p)
879 {}
~AstBlock()880 ~AstBlock() {}
881
Tag()882 inline BlockTag Tag() { return (BlockTag) other_tag; }
SetTag(BlockTag tag)883 inline void SetTag(BlockTag tag) { other_tag = tag; }
884
Statement(unsigned i)885 inline AstStatement*& Statement(unsigned i)
886 {
887 return (*block_statements)[i];
888 }
NumStatements()889 inline unsigned NumStatements()
890 {
891 return block_statements ? block_statements -> Length() : 0;
892 }
893 inline void AllocateStatements(unsigned estimate = 1);
894 inline void AddStatement(AstStatement*);
895
LocallyDefinedVariable(unsigned i)896 inline VariableSymbol*& LocallyDefinedVariable(unsigned i)
897 {
898 return (*defined_variables)[i];
899 }
NumLocallyDefinedVariables()900 inline unsigned NumLocallyDefinedVariables()
901 {
902 return defined_variables ? defined_variables -> Length() : 0;
903 }
904 inline void AllocateLocallyDefinedVariables(unsigned estimate = 1);
905 inline void AddLocallyDefinedVariable(VariableSymbol*);
906
907 #ifdef JIKES_DEBUG
908 virtual void Print(LexStream&);
909 virtual void Unparse(Ostream&, LexStream*);
910 #endif // JIKES_DEBUG
911
912 virtual Ast* Clone(StoragePool*);
913
LeftToken()914 virtual TokenIndex LeftToken() { return left_brace_token; }
RightToken()915 virtual TokenIndex RightToken() { return right_brace_token; }
916
917 protected:
918 void CloneBlock(StoragePool*, AstBlock*);
919 };
920
921
922 //
923 // Simple and qualified names.
924 //
925 class AstName : public AstExpression
926 {
927 public:
928 AstName* base_opt;
929 TokenIndex identifier_token;
930
931 //
932 // When a name refers to a member in an enclosing scope, it is mapped
933 // into an expression that creates a path to the member in question.
934 //
935 AstExpression* resolution_opt;
936
AstName(TokenIndex token)937 inline AstName(TokenIndex token)
938 : AstExpression(NAME)
939 , identifier_token(token)
940 {}
~AstName()941 ~AstName() {}
942
943 #ifdef JIKES_DEBUG
944 virtual void Print(LexStream&);
945 virtual void Unparse(Ostream&, LexStream*);
946 #endif // JIKES_DEBUG
947
948 virtual Ast* Clone(StoragePool*);
949
LeftToken()950 virtual TokenIndex LeftToken()
951 {
952 return base_opt ? base_opt -> LeftToken() : identifier_token;
953 }
RightToken()954 virtual TokenIndex RightToken() { return identifier_token; }
955 };
956
957
958 //
959 // Type --> PrimitiveType
960 // | ReferenceType
961 //
962 // PrimitiveType --> <PrimitiveKind, PrimitiveName>
963 //
964 // PrimitiveKind --> BYTE | SHORT | INT | LONG | CHAR | FLOAT | DOUBLE |
965 // BOOLEAN | VOID
966 //
967 // PrimitiveName --> byte_token | short_token | int_token | long_token |
968 // char_token | float_token | double_token | boolean_token |
969 // void_token
970 //
971 class AstPrimitiveType : public AstType
972 {
973 public:
974 TokenIndex primitive_kind_token;
975
AstPrimitiveType(AstKind k,TokenIndex token)976 inline AstPrimitiveType(AstKind k, TokenIndex token)
977 : AstType(k, PRIMITIVE_TYPE)
978 , primitive_kind_token(token)
979 {}
~AstPrimitiveType()980 ~AstPrimitiveType() {}
981
982 #ifdef JIKES_DEBUG
983 virtual void Print(LexStream&);
984 virtual void Unparse(Ostream&, LexStream*);
985 #endif // JIKES_DEBUG
986
987 virtual Ast* Clone(StoragePool*);
988
LeftToken()989 virtual TokenIndex LeftToken() { return primitive_kind_token; }
RightToken()990 virtual TokenIndex RightToken() { return primitive_kind_token; }
IdentifierToken()991 virtual TokenIndex IdentifierToken() { return primitive_kind_token; }
992 };
993
994
995 //
996 // Represents one or more pairs of '[' ']'.
997 //
998 class AstBrackets : public Ast
999 {
1000 public:
1001 TokenIndex left_bracket_token;
1002 TokenIndex right_bracket_token;
1003
1004 unsigned dims;
1005
AstBrackets(TokenIndex l,TokenIndex r)1006 inline AstBrackets(TokenIndex l, TokenIndex r)
1007 : Ast(BRACKETS)
1008 , left_bracket_token(l)
1009 , right_bracket_token(r)
1010 , dims(1)
1011 {}
~AstBrackets()1012 ~AstBrackets() {}
1013
1014 #ifdef JIKES_DEBUG
1015 virtual void Print(LexStream&);
1016 virtual void Unparse(Ostream&, LexStream*);
1017 #endif // JIKES_DEBUG
1018
1019 virtual Ast* Clone(StoragePool*);
1020
LeftToken()1021 virtual TokenIndex LeftToken() { return left_bracket_token; }
RightToken()1022 virtual TokenIndex RightToken() { return right_bracket_token; }
1023 };
1024
1025
1026 //
1027 // ReferenceType --> ClassType
1028 // | ArrayType
1029 //
1030 // ClassType --> Name
1031 //
1032 // ArrayType --> <ARRAY, ArrayKind, [_token, ]_token>
1033 //
1034 // ArrayKind --> PrimitiveType
1035 // | Name
1036 // | ArrayType
1037 //
1038 class AstArrayType : public AstType
1039 {
1040 public:
1041 AstType* type; // AstPrimitiveType, AstTypeName
1042 AstBrackets* brackets;
1043
AstArrayType(AstType * t,AstBrackets * b)1044 inline AstArrayType(AstType* t, AstBrackets* b)
1045 : AstType(ARRAY)
1046 , type(t)
1047 , brackets(b)
1048 {}
~AstArrayType()1049 ~AstArrayType() {}
1050
NumBrackets()1051 inline unsigned NumBrackets() { return brackets -> dims; }
1052
1053 #ifdef JIKES_DEBUG
1054 virtual void Print(LexStream&);
1055 virtual void Unparse(Ostream&, LexStream*);
1056 #endif // JIKES_DEBUG
1057
1058 virtual Ast* Clone(StoragePool*);
1059
LeftToken()1060 virtual TokenIndex LeftToken() { return type -> LeftToken(); }
RightToken()1061 virtual TokenIndex RightToken() { return brackets -> right_bracket_token; }
IdentifierToken()1062 virtual TokenIndex IdentifierToken() { return type -> IdentifierToken(); }
1063 };
1064
1065
1066 //
1067 // Represents a wildcard type. Only occurs in type arguments for naming a
1068 // generic type or method (but not in explicit type arguments for invoking
1069 // a method).
1070 //
1071 class AstWildcard : public AstType
1072 {
1073 public:
1074 TokenIndex question_token;
1075 // 0 or 1 of the next two fields, but never both
1076 TokenIndex extends_token_opt;
1077 TokenIndex super_token_opt;
1078 AstType* bounds_opt; // AstArrayType, AstTypeName
1079
AstWildcard(TokenIndex t)1080 inline AstWildcard(TokenIndex t)
1081 : AstType(WILDCARD)
1082 , question_token(t)
1083 {}
~AstWildcard()1084 ~AstWildcard() {}
1085
1086 #ifdef JIKES_DEBUG
1087 virtual void Print(LexStream&);
1088 virtual void Unparse(Ostream&, LexStream*);
1089 #endif // JIKES_DEBUG
1090
1091 virtual Ast* Clone(StoragePool*);
1092
LeftToken()1093 virtual TokenIndex LeftToken() { return question_token; }
RightToken()1094 virtual TokenIndex RightToken()
1095 {
1096 return bounds_opt ? bounds_opt -> RightToken() : question_token;
1097 }
IdentifierToken()1098 virtual TokenIndex IdentifierToken() { return question_token; }
1099 };
1100
1101
1102 //
1103 // Represents the type arguments associated with a TypeName, as well as the
1104 // explicit type arguments of ThisCall, SuperCall,MethodInvocation, and
1105 // ClassCreationExpression. The grammar always allows wildcards, so the
1106 // semantic engine must reject them when they are illegal.
1107 //
1108 class AstTypeArguments : public Ast
1109 {
1110 StoragePool* pool;
1111 // AstTypeName, AstArrayType, AstWildcard
1112 AstArray<AstType*>* type_arguments;
1113
1114 public:
1115 TokenIndex left_angle_token;
1116 TokenIndex right_angle_token;
1117
AstTypeArguments(StoragePool * p,TokenIndex l,TokenIndex r)1118 inline AstTypeArguments(StoragePool* p, TokenIndex l, TokenIndex r)
1119 : Ast(TYPE_ARGUMENTS)
1120 , pool(p)
1121 , left_angle_token(l)
1122 , right_angle_token(r)
1123 {}
~AstTypeArguments()1124 ~AstTypeArguments() {}
1125
TypeArgument(unsigned i)1126 inline AstType*& TypeArgument(unsigned i) { return (*type_arguments)[i]; }
NumTypeArguments()1127 inline unsigned NumTypeArguments()
1128 {
1129 assert(type_arguments);
1130 return type_arguments -> Length();
1131 }
1132 inline void AllocateTypeArguments(unsigned estimate = 1);
1133 inline void AddTypeArgument(AstType*);
1134
1135 #ifdef JIKES_DEBUG
1136 virtual void Print(LexStream&);
1137 virtual void Unparse(Ostream&, LexStream*);
1138 #endif // JIKES_DEBUG
1139
1140 virtual Ast* Clone(StoragePool*);
1141
LeftToken()1142 virtual TokenIndex LeftToken() { return left_angle_token; }
RightToken()1143 virtual TokenIndex RightToken() { return right_angle_token; }
1144 };
1145
1146
1147 //
1148 // Represents a type. Occurs in several contexts - imports; supertypes;
1149 // throws clauses; parameter, field, and method return types; qualified this
1150 // and super; class literals; casts. Some of these uses can be parameterized.
1151 //
1152 class AstTypeName : public AstType
1153 {
1154 public:
1155 AstTypeName* base_opt;
1156 AstName* name;
1157 AstTypeArguments* type_arguments_opt;
1158
AstTypeName(AstName * n)1159 inline AstTypeName(AstName* n)
1160 : AstType(TYPE)
1161 , name(n)
1162 {}
~AstTypeName()1163 ~AstTypeName() {}
1164
TypeArgument(unsigned i)1165 inline AstType*& TypeArgument(unsigned i)
1166 {
1167 return type_arguments_opt -> TypeArgument(i);
1168 }
NumTypeArguments()1169 inline unsigned NumTypeArguments()
1170 {
1171 return type_arguments_opt
1172 ? type_arguments_opt -> NumTypeArguments() : 0;
1173 }
1174
1175 #ifdef JIKES_DEBUG
1176 virtual void Print(LexStream&);
1177 virtual void Unparse(Ostream&, LexStream*);
1178 #endif // JIKES_DEBUG
1179
1180 virtual Ast* Clone(StoragePool*);
1181
LeftToken()1182 virtual TokenIndex LeftToken()
1183 {
1184 return base_opt ? base_opt -> LeftToken() : name -> LeftToken();
1185 }
RightToken()1186 virtual TokenIndex RightToken()
1187 {
1188 return type_arguments_opt ? type_arguments_opt -> right_angle_token
1189 : name -> identifier_token;
1190 }
IdentifierToken()1191 virtual TokenIndex IdentifierToken()
1192 {
1193 return name -> identifier_token;
1194 }
1195 };
1196
1197
1198 //
1199 // MemberValuePair is added by JSR 175. This covers MemberValuePair and
1200 // SingleMemberAnnotation in the grammar.
1201 //
1202 class AstMemberValuePair : public Ast
1203 {
1204 public:
1205 TokenIndex identifier_token_opt;
1206 AstMemberValue* member_value;
1207
1208 MethodSymbol* name_symbol; // The annotation method this value maps to.
1209
AstMemberValuePair()1210 inline AstMemberValuePair()
1211 : Ast(MEMBER_VALUE_PAIR)
1212 {}
~AstMemberValuePair()1213 ~AstMemberValuePair() {}
1214
1215 #ifdef JIKES_DEBUG
1216 virtual void Print(LexStream&);
1217 virtual void Unparse(Ostream&, LexStream*);
1218 #endif // JIKES_DEBUG
1219
1220 virtual Ast* Clone(StoragePool*);
1221
LeftToken()1222 virtual TokenIndex LeftToken()
1223 {
1224 return identifier_token_opt ? identifier_token_opt
1225 : member_value -> LeftToken();
1226 }
RightToken()1227 virtual TokenIndex RightToken() { return member_value -> RightToken(); }
1228 };
1229
1230
1231 //
1232 // Annotation is added by JSR 175. This covers NormalAnnotation,
1233 // MarkerAnnotation, and SingleMemberAnnotation in the grammar.
1234 //
1235 class AstAnnotation : public AstMemberValue
1236 {
1237 StoragePool* pool;
1238 AstArray<AstMemberValuePair*>* member_value_pairs;
1239
1240 public:
1241 TokenIndex at_token;
1242 AstName* name;
1243 TokenIndex right_paren_token_opt;
1244
AstAnnotation(StoragePool * p)1245 inline AstAnnotation(StoragePool* p)
1246 : AstMemberValue(ANNOTATION)
1247 , pool(p)
1248 {}
~AstAnnotation()1249 ~AstAnnotation() {}
1250
MemberValuePair(unsigned i)1251 inline AstMemberValuePair*& MemberValuePair(unsigned i)
1252 {
1253 return (*member_value_pairs)[i];
1254 }
NumMemberValuePairs()1255 inline unsigned NumMemberValuePairs()
1256 {
1257 return member_value_pairs ? member_value_pairs -> Length() : 0;
1258 }
1259 inline void AllocateMemberValuePairs(unsigned estimate = 1);
1260 inline void AddMemberValuePair(AstMemberValuePair*);
1261
1262 #ifdef JIKES_DEBUG
1263 virtual void Print(LexStream&);
1264 virtual void Unparse(Ostream&, LexStream*);
1265 #endif // JIKES_DEBUG
1266
1267 virtual Ast* Clone(StoragePool*);
1268
LeftToken()1269 virtual TokenIndex LeftToken() { return at_token; }
RightToken()1270 virtual TokenIndex RightToken()
1271 {
1272 return right_paren_token_opt ? right_paren_token_opt
1273 : name -> identifier_token;
1274 }
1275 };
1276
1277
1278 // Represents a single modifier keyword ('public', 'protected', 'private',
1279 // 'static', 'abstract', 'final', 'native', 'synchronized', 'transient',
1280 // 'volatile', and 'strictfp').
1281 //
1282 class AstModifierKeyword : public Ast
1283 {
1284 public:
1285 TokenIndex modifier_token;
1286
AstModifierKeyword(TokenIndex token)1287 AstModifierKeyword(TokenIndex token)
1288 : Ast(MODIFIER_KEYWORD)
1289 , modifier_token(token)
1290 {}
~AstModifierKeyword()1291 ~AstModifierKeyword() {}
1292
1293 #ifdef JIKES_DEBUG
1294 virtual void Print(LexStream&);
1295 virtual void Unparse(Ostream&, LexStream*);
1296 #endif // JIKES_DEBUG
1297
1298 virtual Ast* Clone(StoragePool*);
1299
LeftToken()1300 virtual TokenIndex LeftToken() { return modifier_token; }
RightToken()1301 virtual TokenIndex RightToken() { return modifier_token; }
1302 };
1303
1304
1305 //
1306 // Represents one or more modifier keywords, as well as annotations (added in
1307 // JSR 175).
1308 //
1309 class AstModifiers : public Ast
1310 {
1311 StoragePool* pool;
1312 AstArray<Ast*>* modifiers; // AstAnnotation, AstModifierKeyword
1313
1314 public:
1315 // Allows sorting between static and non-static declarations.
1316 TokenIndex static_token_opt;
1317
AstModifiers(StoragePool * p)1318 inline AstModifiers(StoragePool* p)
1319 : Ast(MODIFIERS)
1320 , pool(p)
1321 {}
~AstModifiers()1322 ~AstModifiers() {}
1323
Modifier(unsigned i)1324 inline Ast*& Modifier(unsigned i)
1325 {
1326 return (*modifiers)[i];
1327 }
NumModifiers()1328 inline unsigned NumModifiers()
1329 {
1330 assert(modifiers);
1331 return modifiers -> Length();
1332 }
1333 inline void AllocateModifiers(unsigned estimate = 1);
1334 inline void AddModifier(AstAnnotation*);
1335 inline void AddModifier(AstModifierKeyword*);
1336
1337 #ifdef JIKES_DEBUG
1338 virtual void Print(LexStream&);
1339 virtual void Unparse(Ostream&, LexStream*);
1340 #endif // JIKES_DEBUG
1341
1342 virtual Ast* Clone(StoragePool*);
1343
LeftToken()1344 virtual TokenIndex LeftToken() { return Modifier(0) -> LeftToken(); }
RightToken()1345 virtual TokenIndex RightToken()
1346 {
1347 return Modifier(NumModifiers() - 1) -> RightToken();
1348 }
1349 };
1350
1351
1352 //
1353 // Represents the PackageDeclaration, including the annotations made possible
1354 // in package-info.java by JSR 175.
1355 //
1356 class AstPackageDeclaration : public Ast
1357 {
1358 public:
1359 AstModifiers* modifiers_opt;
1360 TokenIndex package_token;
1361 AstName* name;
1362 TokenIndex semicolon_token;
1363
AstPackageDeclaration()1364 inline AstPackageDeclaration()
1365 : Ast(PACKAGE)
1366 {}
~AstPackageDeclaration()1367 ~AstPackageDeclaration() {}
1368
1369 #ifdef JIKES_DEBUG
1370 virtual void Print(LexStream&);
1371 virtual void Unparse(Ostream&, LexStream*);
1372 #endif // JIKES_DEBUG
1373
1374 virtual Ast* Clone(StoragePool*);
1375
LeftToken()1376 virtual TokenIndex LeftToken()
1377 {
1378 return modifiers_opt ? modifiers_opt -> LeftToken() : package_token;
1379 }
RightToken()1380 virtual TokenIndex RightToken() { return semicolon_token; }
1381 };
1382
1383
1384 //
1385 // ImportDeclaration --> <IMPORT, import_token, Name, *_token_opt, ;_token>
1386 //
1387 class AstImportDeclaration : public Ast
1388 {
1389 public:
1390 TokenIndex import_token;
1391 TokenIndex static_token_opt;
1392 AstName* name;
1393 TokenIndex star_token_opt;
1394 TokenIndex semicolon_token;
1395
AstImportDeclaration()1396 inline AstImportDeclaration()
1397 : Ast(IMPORT)
1398 {}
~AstImportDeclaration()1399 ~AstImportDeclaration() {}
1400
1401 #ifdef JIKES_DEBUG
1402 virtual void Print(LexStream&);
1403 virtual void Unparse(Ostream&, LexStream*);
1404 #endif // JIKES_DEBUG
1405
1406 virtual Ast* Clone(StoragePool*);
1407
LeftToken()1408 virtual TokenIndex LeftToken() { return import_token; }
RightToken()1409 virtual TokenIndex RightToken() { return semicolon_token; }
1410 };
1411
1412
1413 //
1414 // The root node for compilation.
1415 //
1416 class AstCompilationUnit : public Ast
1417 {
1418 AstArray<AstImportDeclaration*>* import_declarations;
1419 AstArray<AstDeclaredType*>* type_declarations;
1420
1421 public:
1422 enum CompilationTag
1423 {
1424 NONE,
1425 BAD_COMPILATION,
1426 EMPTY_COMPILATION
1427 };
1428
1429 StoragePool* ast_pool;
1430
1431 AstPackageDeclaration* package_declaration_opt;
1432
AstCompilationUnit(StoragePool * p)1433 inline AstCompilationUnit(StoragePool* p)
1434 : Ast(COMPILATION)
1435 , ast_pool(p)
1436 {}
~AstCompilationUnit()1437 ~AstCompilationUnit() {}
1438
1439 void FreeAst();
1440
MarkBad()1441 inline void MarkBad() { other_tag = BAD_COMPILATION; }
MarkEmpty()1442 inline void MarkEmpty() { other_tag = EMPTY_COMPILATION; }
1443
ImportDeclaration(unsigned i)1444 inline AstImportDeclaration*& ImportDeclaration(unsigned i)
1445 {
1446 return (*import_declarations)[i];
1447 }
NumImportDeclarations()1448 inline unsigned NumImportDeclarations()
1449 {
1450 return import_declarations ? import_declarations -> Length() : 0;
1451 }
1452 inline void AllocateImportDeclarations(unsigned estimate = 1);
1453 inline void AddImportDeclaration(AstImportDeclaration*);
1454
TypeDeclaration(unsigned i)1455 inline AstDeclaredType*& TypeDeclaration(unsigned i)
1456 {
1457 return (*type_declarations)[i];
1458 }
NumTypeDeclarations()1459 inline unsigned NumTypeDeclarations()
1460 {
1461 return type_declarations ? type_declarations -> Length() : 0;
1462 }
1463 inline void AllocateTypeDeclarations(unsigned estimate = 1);
1464 inline void AddTypeDeclaration(AstDeclaredType*);
1465
1466 #ifdef JIKES_DEBUG
1467 virtual void Print(LexStream&);
1468 virtual void Unparse(Ostream&, LexStream*);
1469
1470 // special forms
1471 virtual void Unparse(LexStream*, const char* const directory);
1472 #endif // JIKES_DEBUG
1473
1474 virtual Ast* Clone(StoragePool*);
1475
LeftToken()1476 virtual TokenIndex LeftToken()
1477 {
1478 if (package_declaration_opt)
1479 return package_declaration_opt -> package_token;
1480 if (NumImportDeclarations())
1481 return ImportDeclaration(0) -> import_token;
1482 if (NumTypeDeclarations())
1483 return TypeDeclaration(0) -> LeftToken();
1484 return 0;
1485 }
RightToken()1486 virtual TokenIndex RightToken()
1487 {
1488 if (NumTypeDeclarations())
1489 return TypeDeclaration(NumTypeDeclarations() - 1) -> RightToken();
1490 if (NumImportDeclarations())
1491 return ImportDeclaration(NumImportDeclarations() - 1) ->
1492 semicolon_token;
1493 if (package_declaration_opt)
1494 return package_declaration_opt -> semicolon_token;
1495 return 0;
1496 }
1497 };
1498
1499
1500 //
1501 // EmptyDeclaration --> <EMPTY_DECLARATION, ;_token>
1502 //
1503 class AstEmptyDeclaration : public AstDeclaredType
1504 {
1505 public:
1506 TokenIndex semicolon_token;
1507
AstEmptyDeclaration(TokenIndex token)1508 inline AstEmptyDeclaration(TokenIndex token)
1509 : AstDeclaredType(EMPTY_DECLARATION)
1510 , semicolon_token(token)
1511 {}
~AstEmptyDeclaration()1512 ~AstEmptyDeclaration() {}
1513
1514 #ifdef JIKES_DEBUG
1515 virtual void Print(LexStream&);
1516 virtual void Unparse(Ostream&, LexStream*);
1517 #endif // JIKES_DEBUG
1518
1519 virtual Ast* Clone(StoragePool*);
1520
LeftToken()1521 virtual TokenIndex LeftToken() { return semicolon_token; }
RightToken()1522 virtual TokenIndex RightToken() { return semicolon_token; }
1523 };
1524
1525
1526 //
1527 // Represents the class body of the following: AstClassDeclaration,
1528 // AstEnumDeclaration, AstInterfaceDeclaration, AstAnnotationDeclaration,
1529 // AstEnumConstant, and AstClassCreationExpression. Not all uses can legally
1530 // have all class body members, so some filtering is in order in the semantic
1531 // pass.
1532 //
1533 class AstClassBody : public Ast
1534 {
1535 friend class Parser;
1536
1537 StoragePool* pool;
1538 AstArray<AstDeclared*>* class_body_declarations;
1539
1540 AstArray<AstFieldDeclaration*>* instance_variables;
1541 AstArray<AstFieldDeclaration*>* class_variables;
1542 AstArray<AstMethodDeclaration*>* methods;
1543 AstArray<AstConstructorDeclaration*>* constructors;
1544 AstArray<AstInitializerDeclaration*>* static_initializers;
1545 AstArray<AstInitializerDeclaration*>* instance_initializers;
1546 AstArray<AstClassDeclaration*>* inner_classes;
1547 AstArray<AstEnumDeclaration*>* inner_enums;
1548 AstArray<AstInterfaceDeclaration*>* inner_interfaces;
1549 AstArray<AstAnnotationDeclaration*>* inner_annotations;
1550 AstArray<AstEmptyDeclaration*>* empty_declarations;
1551
1552 public:
1553 enum ClassBodyTag
1554 {
1555 NONE,
1556 UNPARSED
1557 };
1558
1559 SemanticEnvironment* semantic_environment;
1560 AstConstructorDeclaration* default_constructor;
1561
1562 //
1563 // Filled in by the owning AstClassDeclaration, AstEnumDeclaration,
1564 // AstInterfaceDeclaration, or AstAnnotationDeclaration to allow nicer
1565 // error messages. Note that owner is null for anonymous classes,
1566 // including enum constants.
1567 //
1568 AstDeclaredType* owner;
1569 TokenIndex identifier_token;
1570
1571 //
1572 // The actual delimiters of the class body.
1573 //
1574 TokenIndex left_brace_token;
1575 TokenIndex right_brace_token;
1576
AstClassBody(StoragePool * p)1577 inline AstClassBody(StoragePool* p)
1578 : Ast(CLASS_BODY)
1579 , pool(p)
1580 {}
~AstClassBody()1581 ~AstClassBody() {}
1582
MarkUnparsed()1583 inline void MarkUnparsed() { other_tag = UNPARSED; }
MarkParsed()1584 inline void MarkParsed() { other_tag = NONE; }
1585
ClassBodyDeclaration(unsigned i)1586 inline AstDeclared*& ClassBodyDeclaration(unsigned i)
1587 {
1588 return (*class_body_declarations)[i];
1589 }
NumClassBodyDeclarations()1590 inline unsigned NumClassBodyDeclarations()
1591 {
1592 return class_body_declarations
1593 ? class_body_declarations -> Length() : 0;
1594 }
1595 inline void AllocateClassBodyDeclarations(unsigned estimate = 1);
1596 void AddClassBodyDeclaration(AstDeclared*);
1597
InstanceVariable(unsigned i)1598 inline AstFieldDeclaration*& InstanceVariable(unsigned i)
1599 {
1600 return (*instance_variables)[i];
1601 }
NumInstanceVariables()1602 inline unsigned NumInstanceVariables()
1603 {
1604 return instance_variables ? instance_variables -> Length() : 0;
1605 }
1606 inline void AllocateInstanceVariables(unsigned estimate = 1);
1607 inline void AddInstanceVariable(AstFieldDeclaration*);
1608
ClassVariable(unsigned i)1609 inline AstFieldDeclaration*& ClassVariable(unsigned i)
1610 {
1611 return (*class_variables)[i];
1612 }
NumClassVariables()1613 inline unsigned NumClassVariables()
1614 {
1615 return class_variables ? class_variables -> Length() : 0;
1616 }
1617 inline void AllocateClassVariables(unsigned estimate = 1);
1618 inline void AddClassVariable(AstFieldDeclaration*);
1619
Method(unsigned i)1620 inline AstMethodDeclaration*& Method(unsigned i) { return (*methods)[i]; }
NumMethods()1621 inline unsigned NumMethods()
1622 {
1623 return methods ? methods -> Length() : 0;
1624 }
1625 inline void AllocateMethods(unsigned estimate = 1);
1626 inline void AddMethod(AstMethodDeclaration*);
1627
Constructor(unsigned i)1628 inline AstConstructorDeclaration*& Constructor(unsigned i)
1629 {
1630 return (*constructors)[i];
1631 }
NumConstructors()1632 inline unsigned NumConstructors()
1633 {
1634 return constructors ? constructors -> Length() : 0;
1635 }
1636 inline void AllocateConstructors(unsigned estimate = 1);
1637 inline void AddConstructor(AstConstructorDeclaration*);
1638
StaticInitializer(unsigned i)1639 inline AstInitializerDeclaration*& StaticInitializer(unsigned i)
1640 {
1641 return (*static_initializers)[i];
1642 }
NumStaticInitializers()1643 inline unsigned NumStaticInitializers()
1644 {
1645 return static_initializers ? static_initializers -> Length() : 0;
1646 }
1647 inline void AllocateStaticInitializers(unsigned estimate = 1);
1648 inline void AddStaticInitializer(AstInitializerDeclaration*);
1649
InstanceInitializer(unsigned i)1650 inline AstInitializerDeclaration*& InstanceInitializer(unsigned i)
1651 {
1652 return (*instance_initializers)[i];
1653 }
NumInstanceInitializers()1654 inline unsigned NumInstanceInitializers()
1655 {
1656 return instance_initializers ? instance_initializers -> Length() : 0;
1657 }
1658 inline void AllocateInstanceInitializers(unsigned estimate = 1);
1659 inline void AddInstanceInitializer(AstInitializerDeclaration*);
1660
NestedClass(unsigned i)1661 inline AstClassDeclaration*& NestedClass(unsigned i)
1662 {
1663 return (*inner_classes)[i];
1664 }
NumNestedClasses()1665 inline unsigned NumNestedClasses()
1666 {
1667 return inner_classes ? inner_classes -> Length() : 0;
1668 }
1669 inline void AllocateNestedClasses(unsigned estimate = 1);
1670 inline void AddNestedClass(AstClassDeclaration*);
1671
NestedEnum(unsigned i)1672 inline AstEnumDeclaration*& NestedEnum(unsigned i)
1673 {
1674 return (*inner_enums)[i];
1675 }
NumNestedEnums()1676 inline unsigned NumNestedEnums()
1677 {
1678 return inner_enums ? inner_enums -> Length() : 0;
1679 }
1680 inline void AllocateNestedEnums(unsigned estimate = 1);
1681 inline void AddNestedEnum(AstEnumDeclaration*);
1682
NestedInterface(unsigned i)1683 inline AstInterfaceDeclaration*& NestedInterface(unsigned i)
1684 {
1685 return (*inner_interfaces)[i];
1686 }
NumNestedInterfaces()1687 inline unsigned NumNestedInterfaces()
1688 {
1689 return inner_interfaces ? inner_interfaces -> Length() : 0;
1690 }
1691 inline void AllocateNestedInterfaces(unsigned estimate = 1);
1692 inline void AddNestedInterface(AstInterfaceDeclaration*);
1693
NestedAnnotation(unsigned i)1694 inline AstAnnotationDeclaration*& NestedAnnotation(unsigned i)
1695 {
1696 return (*inner_annotations)[i];
1697 }
NumNestedAnnotations()1698 inline unsigned NumNestedAnnotations()
1699 {
1700 return inner_annotations ? inner_annotations -> Length() : 0;
1701 }
1702 inline void AllocateNestedAnnotations(unsigned estimate = 1);
1703 inline void AddNestedAnnotation(AstAnnotationDeclaration*);
1704
EmptyDeclaration(unsigned i)1705 inline AstEmptyDeclaration*& EmptyDeclaration(unsigned i)
1706 {
1707 return (*empty_declarations)[i];
1708 }
NumEmptyDeclarations()1709 inline unsigned NumEmptyDeclarations()
1710 {
1711 return empty_declarations ? empty_declarations -> Length() : 0;
1712 }
1713 inline void AllocateEmptyDeclarations(unsigned estimate = 1);
1714 inline void AddEmptyDeclaration(AstEmptyDeclaration*);
1715
1716 #ifdef JIKES_DEBUG
1717 virtual void Print(LexStream&);
Unparse(Ostream & o,LexStream * l)1718 virtual void Unparse(Ostream& o, LexStream* l) { Unparse(o, l, false); }
1719 void Unparse(Ostream&, LexStream*, bool);
1720 #endif // JIKES_DEBUG
1721
1722 virtual Ast* Clone(StoragePool*);
1723
LeftToken()1724 virtual TokenIndex LeftToken() { return left_brace_token; }
RightToken()1725 virtual TokenIndex RightToken() { return right_brace_token; }
1726 };
1727
1728
1729 //
1730 // Represents a type parameter, used by AstTypeParameters.
1731 //
1732 class AstTypeParameter : public Ast
1733 {
1734 StoragePool* pool;
1735 AstArray<AstTypeName*>* bounds;
1736
1737 public:
1738 TokenIndex identifier_token;
1739
1740 TypeSymbol* symbol;
1741
AstTypeParameter(StoragePool * p,TokenIndex token)1742 inline AstTypeParameter(StoragePool* p, TokenIndex token)
1743 : Ast(TYPE_PARAM)
1744 , pool(p)
1745 , identifier_token(token)
1746 {}
~AstTypeParameter()1747 ~AstTypeParameter() {}
1748
Bound(unsigned i)1749 inline AstTypeName*& Bound(unsigned i) { return (*bounds)[i]; }
NumBounds()1750 inline unsigned NumBounds() { return bounds ? bounds -> Length() : 0; }
1751 inline void AllocateBounds(unsigned estimate = 1);
1752 inline void AddBound(AstTypeName*);
1753
1754 #ifdef JIKES_DEBUG
1755 virtual void Print(LexStream&);
1756 virtual void Unparse(Ostream&, LexStream*);
1757 #endif // JIKES_DEBUG
1758
1759 virtual Ast* Clone(StoragePool*);
1760
LeftToken()1761 virtual TokenIndex LeftToken() { return identifier_token; }
RightToken()1762 virtual TokenIndex RightToken()
1763 {
1764 return NumBounds() ? Bound(NumBounds() - 1) -> RightToken()
1765 : identifier_token;
1766 }
1767 };
1768
1769
1770 //
1771 // Represents type parameter declarations, used by AstClassDeclaration,
1772 // AstInterfaceDeclaration, AstMethodDeclaration, AstConstructorDeclaration.
1773 //
1774 class AstTypeParameters : public Ast
1775 {
1776 StoragePool* pool;
1777 AstArray<AstTypeParameter*>* parameters;
1778
1779 public:
1780 TokenIndex left_angle_token;
1781 TokenIndex right_angle_token;
1782
AstTypeParameters(StoragePool * p)1783 inline AstTypeParameters(StoragePool* p)
1784 : Ast(PARAM_LIST)
1785 , pool(p)
1786 {}
~AstTypeParameters()1787 ~AstTypeParameters() {}
1788
TypeParameter(unsigned i)1789 inline AstTypeParameter*& TypeParameter(unsigned i)
1790 {
1791 return (*parameters)[i];
1792 }
NumTypeParameters()1793 inline unsigned NumTypeParameters()
1794 {
1795 return parameters ? parameters -> Length() : 0;
1796 }
1797 inline void AllocateTypeParameters(unsigned estimate = 1);
1798 inline void AddTypeParameter(AstTypeParameter*);
1799
1800 #ifdef JIKES_DEBUG
1801 virtual void Print(LexStream&);
1802 virtual void Unparse(Ostream&, LexStream*);
1803 #endif // JIKES_DEBUG
1804
1805 virtual Ast* Clone(StoragePool*);
1806
LeftToken()1807 virtual TokenIndex LeftToken() { return left_angle_token; }
RightToken()1808 virtual TokenIndex RightToken() { return right_angle_token; }
1809 };
1810
1811
1812 //
1813 // Represents a class declaration.
1814 //
1815 class AstClassDeclaration : public AstDeclaredType
1816 {
1817 StoragePool* pool;
1818 AstArray<AstTypeName*>* interfaces;
1819
1820 public:
1821 TokenIndex class_token;
1822 AstTypeParameters* type_parameters_opt;
1823 AstTypeName* super_opt;
1824
AstClassDeclaration(StoragePool * p)1825 inline AstClassDeclaration(StoragePool* p)
1826 : AstDeclaredType(CLASS)
1827 , pool(p)
1828 {}
~AstClassDeclaration()1829 ~AstClassDeclaration() {}
1830
Interface(unsigned i)1831 inline AstTypeName*& Interface(unsigned i) { return (*interfaces)[i]; }
NumInterfaces()1832 inline unsigned NumInterfaces()
1833 {
1834 return interfaces ? interfaces -> Length() : 0;
1835 }
1836 inline void AllocateInterfaces(unsigned estimate = 1);
1837 inline void AddInterface(AstTypeName*);
1838
1839 #ifdef JIKES_DEBUG
1840 virtual void Print(LexStream&);
1841 virtual void Unparse(Ostream&, LexStream*);
1842 #endif // JIKES_DEBUG
1843
1844 virtual Ast* Clone(StoragePool*);
1845
LeftToken()1846 virtual TokenIndex LeftToken()
1847 {
1848 return modifiers_opt ? modifiers_opt -> LeftToken() : class_token;
1849 }
RightToken()1850 virtual TokenIndex RightToken() { return class_body -> right_brace_token; }
1851 };
1852
1853
1854 //
1855 // Covers all array initializer expressions, including those added by JSR 175.
1856 //
1857 class AstArrayInitializer : public AstMemberValue
1858 {
1859 StoragePool* pool;
1860 AstArray<AstMemberValue*>* variable_initializers;
1861
1862 public:
1863 TokenIndex left_brace_token;
1864 TokenIndex right_brace_token;
1865
AstArrayInitializer(StoragePool * p)1866 inline AstArrayInitializer(StoragePool* p)
1867 : AstMemberValue(ARRAY_INITIALIZER)
1868 , pool(p)
1869 {}
~AstArrayInitializer()1870 ~AstArrayInitializer() {}
1871
VariableInitializer(unsigned i)1872 inline AstMemberValue*& VariableInitializer(unsigned i)
1873 {
1874 return (*variable_initializers)[i];
1875 }
NumVariableInitializers()1876 inline unsigned NumVariableInitializers()
1877 {
1878 return variable_initializers ? variable_initializers -> Length() : 0;
1879 }
1880 inline void AllocateVariableInitializers(unsigned estimate = 1);
1881 inline void AddVariableInitializer(AstMemberValue*);
1882
1883 #ifdef JIKES_DEBUG
1884 virtual void Print(LexStream&);
1885 virtual void Unparse(Ostream&, LexStream*);
1886 #endif // JIKES_DEBUG
1887
1888 virtual Ast* Clone(StoragePool*);
1889
LeftToken()1890 virtual TokenIndex LeftToken() { return left_brace_token; }
RightToken()1891 virtual TokenIndex RightToken() { return right_brace_token; }
1892 };
1893
1894
1895 //
1896 // VariableDeclaratorId --> <VARIABLE_DECLARATOR_NAME, identifier_token,
1897 // Brackets>
1898 //
1899 class AstVariableDeclaratorId : public Ast
1900 {
1901 public:
1902 TokenIndex identifier_token;
1903 AstBrackets* brackets_opt;
1904
AstVariableDeclaratorId()1905 inline AstVariableDeclaratorId()
1906 : Ast(VARIABLE_DECLARATOR_NAME)
1907 {}
~AstVariableDeclaratorId()1908 ~AstVariableDeclaratorId() {}
1909
NumBrackets()1910 inline unsigned NumBrackets()
1911 {
1912 return brackets_opt ? brackets_opt -> dims : 0;
1913 }
1914
1915 #ifdef JIKES_DEBUG
1916 virtual void Print(LexStream&);
1917 virtual void Unparse(Ostream&, LexStream*);
1918 #endif // JIKES_DEBUG
1919
1920 virtual Ast* Clone(StoragePool*);
1921
LeftToken()1922 virtual TokenIndex LeftToken() { return identifier_token; }
RightToken()1923 virtual TokenIndex RightToken()
1924 {
1925 return brackets_opt ? brackets_opt -> right_bracket_token
1926 : identifier_token;
1927 }
1928 };
1929
1930
1931 //
1932 // VariableDeclarator --> <VARIABLE_DECLARATOR, VariableDeclaratorId,
1933 // VariableInitializer_opt>
1934 //
1935 // Technically, this is not a statement. But it is similar to local variable
1936 // declarations, which are, and treating it as a statement makes compiling
1937 // initializer blocks more uniform.
1938 //
1939 class AstVariableDeclarator : public AstStatement
1940 {
1941 public:
1942 VariableSymbol* symbol;
1943
1944 // when true, this variable signals that the variable_initializer_opt
1945 // for this variable is currently being evaluated
1946 bool pending;
1947
1948 AstVariableDeclaratorId* variable_declarator_name;
1949 Ast* variable_initializer_opt;
1950
AstVariableDeclarator()1951 inline AstVariableDeclarator()
1952 : AstStatement(VARIABLE_DECLARATOR, true, true)
1953 {}
~AstVariableDeclarator()1954 ~AstVariableDeclarator() {}
1955
1956 #ifdef JIKES_DEBUG
1957 virtual void Print(LexStream&);
1958 virtual void Unparse(Ostream&, LexStream*);
1959 #endif // JIKES_DEBUG
1960
1961 virtual Ast* Clone(StoragePool*);
1962
LeftToken()1963 virtual TokenIndex LeftToken()
1964 {
1965 return variable_declarator_name -> LeftToken();
1966 }
RightToken()1967 virtual TokenIndex RightToken()
1968 {
1969 return variable_initializer_opt
1970 ? variable_initializer_opt -> RightToken()
1971 : variable_declarator_name -> RightToken();
1972 }
1973 };
1974
1975
1976 //
1977 // FieldDeclaration --> <FIELD, VariableModifiers, Type, VariableDeclarators,
1978 // ;_token>
1979 //
1980 // FieldModifier --> Modifier (PUBLIC, PROTECTED, PRIVATE, FINAL, STATIC,
1981 // TRANSIENT or VOLATILE)
1982 //
1983 class AstFieldDeclaration : public AstDeclared
1984 {
1985 StoragePool* pool;
1986 AstArray<AstVariableDeclarator*>* variable_declarators;
1987
1988 public:
1989 enum FieldDeclarationTag
1990 {
1991 NONE,
1992 STATIC
1993 };
1994
1995 AstType* type;
1996 TokenIndex semicolon_token;
1997
AstFieldDeclaration(StoragePool * p)1998 inline AstFieldDeclaration(StoragePool* p)
1999 : AstDeclared(FIELD)
2000 , pool(p)
2001 {}
~AstFieldDeclaration()2002 ~AstFieldDeclaration() {}
2003
MarkStatic()2004 inline void MarkStatic() { other_tag = STATIC; }
2005
VariableDeclarator(unsigned i)2006 inline AstVariableDeclarator*& VariableDeclarator(unsigned i)
2007 {
2008 return (*variable_declarators)[i];
2009 }
NumVariableDeclarators()2010 inline unsigned NumVariableDeclarators()
2011 {
2012 return variable_declarators ? variable_declarators -> Length() : 0;
2013 }
2014 inline void AllocateVariableDeclarators(unsigned estimate = 1);
2015 inline void AddVariableDeclarator(AstVariableDeclarator*);
2016
2017 #ifdef JIKES_DEBUG
2018 virtual void Print(LexStream&);
2019 virtual void Unparse(Ostream&, LexStream*);
2020 #endif // JIKES_DEBUG
2021
2022 virtual Ast* Clone(StoragePool*);
2023
LeftToken()2024 virtual TokenIndex LeftToken()
2025 {
2026 return modifiers_opt ? modifiers_opt -> LeftToken()
2027 : type -> LeftToken();
2028 }
RightToken()2029 virtual TokenIndex RightToken() { return semicolon_token; }
2030 };
2031
2032
2033 //
2034 // FormalParameter --> <PARAMETER, Type, VariableDeclaratorId>
2035 //
2036 class AstFormalParameter : public Ast
2037 {
2038 public:
2039 AstModifiers* modifiers_opt;
2040 AstType* type;
2041 TokenIndex ellipsis_token_opt;
2042 AstVariableDeclarator* formal_declarator;
2043
AstFormalParameter()2044 inline AstFormalParameter()
2045 : Ast(PARAMETER)
2046 {}
~AstFormalParameter()2047 ~AstFormalParameter() {}
2048
2049 #ifdef JIKES_DEBUG
2050 virtual void Print(LexStream&);
2051 virtual void Unparse(Ostream&, LexStream*);
2052 #endif // JIKES_DEBUG
2053
2054 virtual Ast* Clone(StoragePool*);
2055
LeftToken()2056 virtual TokenIndex LeftToken()
2057 {
2058 return modifiers_opt ? modifiers_opt -> LeftToken()
2059 : type -> LeftToken();
2060 }
RightToken()2061 virtual TokenIndex RightToken()
2062 {
2063 return formal_declarator -> RightToken();
2064 }
2065 };
2066
2067
2068 //
2069 // MethodDeclarator --> <METHOD_DECLARATOR, identifier_token, (_token,
2070 // FormalParameters, )_token, Brackets>
2071 //
2072 class AstMethodDeclarator : public Ast
2073 {
2074 StoragePool* pool;
2075 AstArray<AstFormalParameter*>* formal_parameters;
2076
2077 public:
2078 TokenIndex identifier_token;
2079 TokenIndex left_parenthesis_token;
2080 TokenIndex right_parenthesis_token;
2081 AstBrackets* brackets_opt;
2082
AstMethodDeclarator(StoragePool * p)2083 inline AstMethodDeclarator(StoragePool* p)
2084 : Ast(METHOD_DECLARATOR)
2085 , pool(p)
2086 {}
~AstMethodDeclarator()2087 ~AstMethodDeclarator() {}
2088
FormalParameter(unsigned i)2089 inline AstFormalParameter*& FormalParameter(unsigned i)
2090 {
2091 return (*formal_parameters)[i];
2092 }
NumFormalParameters()2093 inline unsigned NumFormalParameters()
2094 {
2095 return formal_parameters ? formal_parameters -> Length() : 0;
2096 }
2097 inline void AllocateFormalParameters(unsigned estimate = 1);
2098 inline void AddFormalParameter(AstFormalParameter*);
2099
NumBrackets()2100 inline unsigned NumBrackets()
2101 {
2102 return brackets_opt ? brackets_opt -> dims : 0;
2103 }
2104
2105 #ifdef JIKES_DEBUG
2106 virtual void Print(LexStream&);
2107 virtual void Unparse(Ostream&, LexStream*);
2108 #endif // JIKES_DEBUG
2109
2110 virtual Ast* Clone(StoragePool*);
2111
LeftToken()2112 virtual TokenIndex LeftToken() { return identifier_token; }
RightToken()2113 virtual TokenIndex RightToken()
2114 {
2115 return brackets_opt ? brackets_opt -> right_bracket_token
2116 : right_parenthesis_token;
2117 }
2118 };
2119
2120
2121 //
2122 // This class represents a method body, for methods, constructors, and
2123 // initializers. It is basically a block, with the addition of an explicit
2124 // constructor invocation (used only in the context of constructors, NULL
2125 // otherwise).
2126 //
2127 class AstMethodBody : public AstBlock
2128 {
2129 public:
2130 AstStatement* explicit_constructor_opt;
2131
AstMethodBody(StoragePool * p)2132 inline AstMethodBody(StoragePool* p)
2133 : AstBlock(p, METHOD_BODY, true)
2134 {
2135 no_braces = true;
2136 }
~AstMethodBody()2137 ~AstMethodBody() {}
2138
2139 #ifdef JIKES_DEBUG
2140 virtual void Print(LexStream&);
2141 virtual void Unparse(Ostream&, LexStream*);
2142 #endif // JIKES_DEBUG
2143
2144 virtual Ast* Clone(StoragePool*);
2145 // Inherited LeftToken(), RightToken() are adequate.
2146 };
2147
2148
2149 //
2150 // Represents MethodDeclaration, AbstractMethodDeclaration, and Annotation
2151 // method declarations added in JSR 175.
2152 //
2153 class AstMethodDeclaration : public AstDeclared
2154 {
2155 StoragePool* pool;
2156 AstArray<AstTypeName*>* throws;
2157
2158 public:
2159 MethodSymbol* method_symbol;
2160
2161 AstTypeParameters* type_parameters_opt;
2162 AstType* type;
2163 AstMethodDeclarator* method_declarator;
2164 AstMemberValue* default_value_opt;
2165 AstMethodBody* method_body_opt;
2166 TokenIndex semicolon_token_opt;
2167
AstMethodDeclaration(StoragePool * p)2168 inline AstMethodDeclaration(StoragePool* p)
2169 : AstDeclared(METHOD)
2170 , pool(p)
2171 {}
~AstMethodDeclaration()2172 ~AstMethodDeclaration() {}
2173
IsValid()2174 bool IsValid() { return method_symbol != NULL; }
2175
IsSignature()2176 bool IsSignature() { return ! method_body_opt; }
2177
Throw(unsigned i)2178 inline AstTypeName*& Throw(unsigned i) { return (*throws)[i]; }
NumThrows()2179 inline unsigned NumThrows() { return throws ? throws -> Length() : 0; }
2180 inline void AllocateThrows(unsigned estimate = 1);
2181 inline void AddThrow(AstTypeName*);
2182
2183 #ifdef JIKES_DEBUG
2184 virtual void Print(LexStream&);
2185 virtual void Unparse(Ostream&, LexStream*);
2186 #endif // JIKES_DEBUG
2187
2188 virtual Ast* Clone(StoragePool*);
2189
LeftToken()2190 virtual TokenIndex LeftToken()
2191 {
2192 return modifiers_opt ? modifiers_opt -> LeftToken()
2193 : type_parameters_opt ? type_parameters_opt -> left_angle_token
2194 : type -> LeftToken();
2195 }
RightToken()2196 virtual TokenIndex RightToken()
2197 {
2198 return method_body_opt ? method_body_opt -> right_brace_token
2199 : semicolon_token_opt;
2200 }
2201 };
2202
2203
2204 //
2205 // This class represents static and instance initializers. It also accepts
2206 // other modifiers, to give a nicer error message.
2207 //
2208 class AstInitializerDeclaration : public AstDeclared
2209 {
2210 public:
2211 enum InitializerDeclarationTag
2212 {
2213 NONE,
2214 STATIC
2215 };
2216
2217 AstMethodBody* block;
2218
AstInitializerDeclaration()2219 inline AstInitializerDeclaration()
2220 : AstDeclared(INITIALIZER)
2221 {}
~AstInitializerDeclaration()2222 ~AstInitializerDeclaration() {}
2223
MarkStatic()2224 inline void MarkStatic() { other_tag = STATIC; }
2225
2226 #ifdef JIKES_DEBUG
2227 virtual void Print(LexStream&);
2228 virtual void Unparse(Ostream&, LexStream*);
2229 #endif // JIKES_DEBUG
2230
2231 virtual Ast* Clone(StoragePool*);
2232
LeftToken()2233 virtual TokenIndex LeftToken()
2234 {
2235 return modifiers_opt ? modifiers_opt -> LeftToken()
2236 : block -> left_brace_token;
2237 }
RightToken()2238 virtual TokenIndex RightToken() { return block -> right_brace_token; }
2239 };
2240
2241
2242 //
2243 // Represents the arguments of AstThisCall, AstSuperCall, AstMethodInvocation,
2244 // AstClassCreationExpression, and AstEnumConstant. For convenience, the need
2245 // to add null argument or pass shadow parameters is contained here, even
2246 // though not all the calling instances can use these features.
2247 //
2248 class AstArguments : public Ast
2249 {
2250 StoragePool* pool;
2251 AstArray<AstExpression*>* arguments;
2252 AstArray<AstName*>* shadow_arguments;
2253
2254 public:
2255 TokenIndex left_parenthesis_token;
2256 TokenIndex right_parenthesis_token;
2257
AstArguments(StoragePool * p,TokenIndex l,TokenIndex r)2258 inline AstArguments(StoragePool* p, TokenIndex l, TokenIndex r)
2259 : Ast(ARGUMENTS)
2260 , pool(p)
2261 , left_parenthesis_token(l)
2262 , right_parenthesis_token(r)
2263 {}
~AstArguments()2264 ~AstArguments() {}
2265
Argument(unsigned i)2266 inline AstExpression*& Argument(unsigned i) { return (*arguments)[i]; }
NumArguments()2267 inline unsigned NumArguments()
2268 {
2269 return arguments ? arguments -> Length() : 0;
2270 }
2271 inline void AllocateArguments(unsigned estimate = 1);
2272 inline void AddArgument(AstExpression*);
2273
LocalArgument(unsigned i)2274 inline AstName*& LocalArgument(unsigned i)
2275 {
2276 return (*shadow_arguments)[i];
2277 }
NumLocalArguments()2278 inline unsigned NumLocalArguments()
2279 {
2280 return shadow_arguments ? shadow_arguments -> Length() : 0;
2281 }
2282 inline void AllocateLocalArguments(unsigned estimate = 1);
2283 inline void AddLocalArgument(AstName*);
2284
AddNullArgument()2285 inline void AddNullArgument() { other_tag = true; }
NeedsExtraNullArgument()2286 inline bool NeedsExtraNullArgument() { return (bool) other_tag; }
2287
2288 #ifdef JIKES_DEBUG
2289 virtual void Print(LexStream&);
2290 virtual void Unparse(Ostream&, LexStream*);
2291 #endif // JIKES_DEBUG
2292
2293 virtual Ast* Clone(StoragePool*);
2294
LeftToken()2295 virtual TokenIndex LeftToken() { return left_parenthesis_token; }
RightToken()2296 virtual TokenIndex RightToken() { return right_parenthesis_token; }
2297 };
2298
2299
2300 //
2301 // Represents an explicit call to another constructor in this class.
2302 //
2303 class AstThisCall : public AstStatement
2304 {
2305 public:
2306 MethodSymbol* symbol;
2307
2308 AstTypeArguments* type_arguments_opt;
2309 TokenIndex this_token;
2310 AstArguments* arguments;
2311 TokenIndex semicolon_token;
2312
AstThisCall()2313 inline AstThisCall()
2314 : AstStatement(THIS_CALL, true, true)
2315 {}
~AstThisCall()2316 ~AstThisCall() {}
2317
2318 #ifdef JIKES_DEBUG
2319 virtual void Print(LexStream&);
2320 virtual void Unparse(Ostream&, LexStream*);
2321 #endif // JIKES_DEBUG
2322
2323 virtual Ast* Clone(StoragePool*);
2324
LeftToken()2325 virtual TokenIndex LeftToken()
2326 {
2327 return type_arguments_opt ? type_arguments_opt -> left_angle_token
2328 : this_token;
2329 }
RightToken()2330 virtual TokenIndex RightToken() { return semicolon_token; }
2331 };
2332
2333
2334 //
2335 // Represents an explicit call to a superconstructor.
2336 //
2337 class AstSuperCall : public AstStatement
2338 {
2339 public:
2340 MethodSymbol* symbol;
2341
2342 AstExpression* base_opt;
2343 AstTypeArguments* type_arguments_opt;
2344 TokenIndex super_token;
2345 AstArguments* arguments;
2346 TokenIndex semicolon_token;
2347
AstSuperCall()2348 inline AstSuperCall()
2349 : AstStatement(SUPER_CALL, true, true)
2350 {}
~AstSuperCall()2351 ~AstSuperCall() {}
2352
2353 #ifdef JIKES_DEBUG
2354 virtual void Print(LexStream&);
2355 virtual void Unparse(Ostream&, LexStream*);
2356 #endif // JIKES_DEBUG
2357
2358 virtual Ast* Clone(StoragePool*);
2359
LeftToken()2360 virtual TokenIndex LeftToken()
2361 {
2362 return base_opt ? base_opt -> LeftToken()
2363 : type_arguments_opt ? type_arguments_opt -> left_angle_token
2364 : super_token;
2365 }
RightToken()2366 virtual TokenIndex RightToken() { return semicolon_token; }
2367 };
2368
2369
2370 //
2371 // ConstructorDeclaration --> <CONSTRUCTOR, ConstructorModifiers,
2372 // MethodDeclarator, Throws, ConstructorBody>
2373 //
2374 // ConstructorBody --> <METHOD_BODY, {_token,
2375 // ExplicitConstructorInvocation, BlockStatements, }_token>
2376 //
2377 // ConstructorModifier --> Modifier (PUBLIC, PROTECTED or PRIVATE)
2378 //
2379 // ExplicitConstructorInvocation --> ThisCall
2380 // | SuperCall
2381 //
2382 // NOTE: We do not actually build ConstructorBodies. Instead, we have
2383 // overloaded MethodBody to store the necessary information. This is
2384 // because this() and super() are treated as Statements in the grammar;
2385 // and in the bytecode, constructors are just methods with a special
2386 // name.
2387 //
2388 class AstConstructorDeclaration : public AstDeclared
2389 {
2390 StoragePool* pool;
2391 AstArray<AstTypeName*>* throws;
2392
2393 public:
2394 MethodSymbol* constructor_symbol;
2395 int index; // Used in depend.cpp to detect cycles.
2396
2397 AstTypeParameters* type_parameters_opt;
2398 AstMethodDeclarator* constructor_declarator;
2399 AstMethodBody* constructor_body;
2400
AstConstructorDeclaration(StoragePool * p)2401 inline AstConstructorDeclaration(StoragePool* p)
2402 : AstDeclared(CONSTRUCTOR)
2403 , pool(p)
2404 , index(ConstructorCycleChecker::OMEGA)
2405 {}
~AstConstructorDeclaration()2406 ~AstConstructorDeclaration() {}
2407
IsValid()2408 bool IsValid() { return constructor_symbol != NULL; }
2409
Throw(unsigned i)2410 inline AstTypeName*& Throw(unsigned i) { return (*throws)[i]; }
NumThrows()2411 inline unsigned NumThrows() { return throws ? throws -> Length() : 0; }
2412 inline void AllocateThrows(unsigned estimate = 1);
2413 inline void AddThrow(AstTypeName*);
2414
2415 #ifdef JIKES_DEBUG
2416 virtual void Print(LexStream&);
2417 virtual void Unparse(Ostream&, LexStream*);
2418 #endif // JIKES_DEBUG
2419
2420 virtual Ast* Clone(StoragePool*);
2421
LeftToken()2422 virtual TokenIndex LeftToken()
2423 {
2424 return modifiers_opt ? modifiers_opt -> LeftToken()
2425 : type_parameters_opt ? type_parameters_opt -> left_angle_token
2426 : constructor_declarator -> identifier_token;
2427 }
RightToken()2428 virtual TokenIndex RightToken()
2429 {
2430 return constructor_body -> right_brace_token;
2431 }
2432 };
2433
2434
2435 //
2436 // Represents an enum type, added by JSR 201.
2437 //
2438 class AstEnumDeclaration : public AstDeclaredType
2439 {
2440 StoragePool* pool;
2441 AstArray<AstTypeName*>* interfaces;
2442 AstArray<AstEnumConstant*>* enum_constants;
2443
2444 public:
2445 TokenIndex enum_token;
2446
AstEnumDeclaration(StoragePool * p)2447 inline AstEnumDeclaration(StoragePool* p)
2448 : AstDeclaredType(ENUM_TYPE)
2449 , pool(p)
2450 {}
~AstEnumDeclaration()2451 ~AstEnumDeclaration() {}
2452
Interface(unsigned i)2453 inline AstTypeName*& Interface(unsigned i)
2454 {
2455 return (*interfaces)[i];
2456 }
NumInterfaces()2457 inline unsigned NumInterfaces()
2458 {
2459 return interfaces ? interfaces -> Length() : 0;
2460 }
2461 inline void AllocateInterfaces(unsigned estimate = 1);
2462 inline void AddInterface(AstTypeName*);
2463
EnumConstant(unsigned i)2464 inline AstEnumConstant*& EnumConstant(unsigned i)
2465 {
2466 return (*enum_constants)[i];
2467 }
NumEnumConstants()2468 inline unsigned NumEnumConstants()
2469 {
2470 return enum_constants ? enum_constants -> Length() : 0;
2471 }
2472 inline void AllocateEnumConstants(unsigned estimate = 1);
2473 inline void AddEnumConstant(AstEnumConstant*);
2474
2475 #ifdef JIKES_DEBUG
2476 virtual void Print(LexStream&);
2477 virtual void Unparse(Ostream&, LexStream*);
2478 #endif // JIKES_DEBUG
2479
2480 virtual Ast* Clone(StoragePool*);
2481
LeftToken()2482 virtual TokenIndex LeftToken()
2483 {
2484 return modifiers_opt ? modifiers_opt -> LeftToken() : enum_token;
2485 }
RightToken()2486 virtual TokenIndex RightToken() { return class_body -> right_brace_token; }
2487 };
2488
2489
2490 //
2491 // Represents an enum constant, added by JSR 201.
2492 //
2493 class AstEnumConstant : public AstDeclared
2494 {
2495 public:
2496 TokenIndex identifier_token;
2497 AstArguments* arguments_opt;
2498 AstClassBody* class_body_opt;
2499
2500 u4 ordinal; // the sequential position of the constant
2501 VariableSymbol* field_symbol; // the field the constant lives in
2502 MethodSymbol* ctor_symbol; // the constructor that builds the constant
2503
AstEnumConstant(TokenIndex t)2504 inline AstEnumConstant(TokenIndex t)
2505 : AstDeclared(ENUM)
2506 , identifier_token(t)
2507 {}
~AstEnumConstant()2508 ~AstEnumConstant() {}
2509
2510 #ifdef JIKES_DEBUG
2511 virtual void Print(LexStream&);
2512 virtual void Unparse(Ostream&, LexStream*);
2513 #endif // JIKES_DEBUG
2514
2515 virtual Ast* Clone(StoragePool*);
2516
LeftToken()2517 virtual TokenIndex LeftToken()
2518 {
2519 return modifiers_opt ? modifiers_opt -> LeftToken() : identifier_token;
2520 }
RightToken()2521 virtual TokenIndex RightToken()
2522 {
2523 return class_body_opt ? class_body_opt -> right_brace_token
2524 : arguments_opt ? arguments_opt -> right_parenthesis_token
2525 : identifier_token;
2526 }
2527 };
2528
2529
2530 //
2531 // Represents an interface type.
2532 //
2533 class AstInterfaceDeclaration : public AstDeclaredType
2534 {
2535 StoragePool* pool;
2536 AstArray<AstTypeName*>* interfaces;
2537
2538 public:
2539 TokenIndex interface_token;
2540 AstTypeParameters* type_parameters_opt;
2541
AstInterfaceDeclaration(StoragePool * p)2542 inline AstInterfaceDeclaration(StoragePool* p)
2543 : AstDeclaredType(INTERFACE)
2544 , pool(p)
2545 {}
~AstInterfaceDeclaration()2546 ~AstInterfaceDeclaration() {}
2547
Interface(unsigned i)2548 inline AstTypeName*& Interface(unsigned i)
2549 {
2550 return (*interfaces)[i];
2551 }
NumInterfaces()2552 inline unsigned NumInterfaces()
2553 {
2554 return interfaces ? interfaces -> Length() : 0;
2555 }
2556 inline void AllocateInterfaces(unsigned estimate = 1);
2557 inline void AddInterface(AstTypeName*);
2558
2559 #ifdef JIKES_DEBUG
2560 virtual void Print(LexStream&);
2561 virtual void Unparse(Ostream&, LexStream*);
2562 #endif // JIKES_DEBUG
2563
2564 virtual Ast* Clone(StoragePool*);
2565
LeftToken()2566 virtual TokenIndex LeftToken()
2567 {
2568 return modifiers_opt ? modifiers_opt -> LeftToken() : interface_token;
2569 }
RightToken()2570 virtual TokenIndex RightToken() { return class_body -> right_brace_token; }
2571 };
2572
2573
2574 //
2575 // Represents an annotation type, added by JSR 175.
2576 //
2577 class AstAnnotationDeclaration : public AstDeclaredType
2578 {
2579 public:
2580 TokenIndex interface_token;
2581
AstAnnotationDeclaration(TokenIndex t)2582 inline AstAnnotationDeclaration(TokenIndex t)
2583 : AstDeclaredType(ANNOTATION_TYPE)
2584 , interface_token(t)
2585 {}
~AstAnnotationDeclaration()2586 ~AstAnnotationDeclaration() {}
2587
2588 #ifdef JIKES_DEBUG
2589 virtual void Print(LexStream&);
2590 virtual void Unparse(Ostream&, LexStream*);
2591 #endif // JIKES_DEBUG
2592
2593 virtual Ast* Clone(StoragePool*);
2594
LeftToken()2595 virtual TokenIndex LeftToken()
2596 {
2597 return modifiers_opt ? modifiers_opt -> LeftToken()
2598 : interface_token - 1;
2599 }
RightToken()2600 virtual TokenIndex RightToken() { return class_body -> right_brace_token; }
2601 };
2602
2603
2604 //
2605 // Represents a local variable declaration statement.
2606 //
2607 class AstLocalVariableStatement : public AstStatement
2608 {
2609 StoragePool* pool;
2610 AstArray<AstVariableDeclarator*>* variable_declarators;
2611
2612 public:
2613 AstModifiers* modifiers_opt;
2614 AstType* type;
2615 TokenIndex semicolon_token_opt;
2616
AstLocalVariableStatement(StoragePool * p)2617 inline AstLocalVariableStatement(StoragePool* p)
2618 : AstStatement(LOCAL_VARIABLE_DECLARATION)
2619 , pool(p)
2620 {}
~AstLocalVariableStatement()2621 ~AstLocalVariableStatement() {}
2622
VariableDeclarator(unsigned i)2623 inline AstVariableDeclarator*& VariableDeclarator(unsigned i)
2624 {
2625 return (*variable_declarators)[i];
2626 }
NumVariableDeclarators()2627 inline unsigned NumVariableDeclarators()
2628 {
2629 return variable_declarators ? variable_declarators -> Length() : 0;
2630 }
2631 inline void AllocateVariableDeclarators(unsigned estimate = 1);
2632 inline void AddVariableDeclarator(AstVariableDeclarator*);
2633
2634 #ifdef JIKES_DEBUG
2635 virtual void Print(LexStream&);
2636 virtual void Unparse(Ostream&, LexStream*);
2637 #endif // JIKES_DEBUG
2638
2639 virtual Ast* Clone(StoragePool*);
2640
LeftToken()2641 virtual TokenIndex LeftToken()
2642 {
2643 return modifiers_opt ? modifiers_opt -> LeftToken()
2644 : type -> LeftToken();
2645 }
RightToken()2646 virtual TokenIndex RightToken()
2647 {
2648 return semicolon_token_opt ? semicolon_token_opt
2649 : (VariableDeclarator(NumVariableDeclarators() - 1) ->
2650 RightToken());
2651 }
2652 };
2653
2654
2655 //
2656 // Represents a local class declaration statement.
2657 //
2658 class AstLocalClassStatement : public AstStatement
2659 {
2660 public:
2661 AstDeclaredType* declaration; // AstClassDeclaration, AstEnumDeclaration
2662
AstLocalClassStatement(AstClassDeclaration * decl)2663 inline AstLocalClassStatement(AstClassDeclaration* decl)
2664 : AstStatement(LOCAL_CLASS, false, true)
2665 , declaration(decl)
2666 {}
AstLocalClassStatement(AstEnumDeclaration * decl)2667 inline AstLocalClassStatement(AstEnumDeclaration* decl)
2668 : AstStatement(LOCAL_CLASS, false, true)
2669 , declaration(decl)
2670 {}
~AstLocalClassStatement()2671 ~AstLocalClassStatement() {}
2672
2673 #ifdef JIKES_DEBUG
2674 virtual void Print(LexStream&);
2675 virtual void Unparse(Ostream&, LexStream*);
2676 #endif // JIKES_DEBUG
2677
2678 virtual Ast* Clone(StoragePool*);
2679
LeftToken()2680 virtual TokenIndex LeftToken() { return declaration -> LeftToken(); }
RightToken()2681 virtual TokenIndex RightToken()
2682 {
2683 return declaration -> class_body -> right_brace_token;
2684 }
2685 };
2686
2687
2688 //
2689 // The parser always makes blocks for the enclosed statements, so we denote
2690 // that here (even though any statement is legal).
2691 //
2692 class AstIfStatement : public AstStatement
2693 {
2694 public:
2695 TokenIndex if_token;
2696 AstExpression* expression;
2697 AstBlock* true_statement;
2698 AstBlock* false_statement_opt;
2699
AstIfStatement()2700 inline AstIfStatement()
2701 : AstStatement(IF)
2702 {}
~AstIfStatement()2703 ~AstIfStatement() {}
2704
2705 #ifdef JIKES_DEBUG
2706 virtual void Print(LexStream&);
2707 virtual void Unparse(Ostream&, LexStream*);
2708 #endif // JIKES_DEBUG
2709
2710 virtual Ast* Clone(StoragePool*);
2711
LeftToken()2712 virtual TokenIndex LeftToken() { return if_token; }
RightToken()2713 virtual TokenIndex RightToken()
2714 {
2715 return false_statement_opt ? false_statement_opt -> RightToken()
2716 : true_statement -> RightToken();
2717 }
2718 };
2719
2720
2721 //
2722 // EmptyStatement --> <EMPTY_STATEMENT, Label_opt, ;_token>
2723 //
2724 class AstEmptyStatement : public AstStatement
2725 {
2726 public:
2727 TokenIndex semicolon_token;
2728
AstEmptyStatement(TokenIndex token)2729 inline AstEmptyStatement(TokenIndex token)
2730 : AstStatement(EMPTY_STATEMENT)
2731 , semicolon_token(token)
2732 {}
~AstEmptyStatement()2733 ~AstEmptyStatement() {}
2734
2735 #ifdef JIKES_DEBUG
2736 virtual void Print(LexStream&);
2737 virtual void Unparse(Ostream&, LexStream*);
2738 #endif // JIKES_DEBUG
2739
2740 virtual Ast* Clone(StoragePool*);
2741
LeftToken()2742 virtual TokenIndex LeftToken() { return semicolon_token; }
RightToken()2743 virtual TokenIndex RightToken() { return semicolon_token; }
2744 };
2745
2746
2747 //
2748 // ExpressionStatement --> <EXPRESSION_STATEMENT, Label_opt, Expression,
2749 // ;_token_opt>
2750 //
2751 class AstExpressionStatement : public AstStatement
2752 {
2753 public:
2754 AstExpression* expression;
2755 TokenIndex semicolon_token_opt;
2756
AstExpressionStatement()2757 inline AstExpressionStatement()
2758 : AstStatement(EXPRESSION_STATEMENT)
2759 {}
~AstExpressionStatement()2760 ~AstExpressionStatement() {}
2761
2762 #ifdef JIKES_DEBUG
2763 virtual void Print(LexStream&);
2764 virtual void Unparse(Ostream&, LexStream*);
2765 #endif // JIKES_DEBUG
2766
2767 virtual Ast* Clone(StoragePool*);
2768
LeftToken()2769 virtual TokenIndex LeftToken() { return expression -> LeftToken(); }
RightToken()2770 virtual TokenIndex RightToken()
2771 {
2772 return semicolon_token_opt ? semicolon_token_opt
2773 : expression -> RightToken();
2774 }
2775 };
2776
2777
2778 //
2779 // Represents "case <constant> :" and "default :".
2780 //
2781 class AstSwitchLabel : public Ast
2782 {
2783 public:
2784 TokenIndex case_token;
2785 AstExpression* expression_opt;
2786 TokenIndex colon_token;
2787
2788 //
2789 // The sorted index of this label in the overall switch. Default cases
2790 // are set to NumCases().
2791 //
2792 unsigned map_index;
2793
AstSwitchLabel()2794 inline AstSwitchLabel()
2795 : Ast(SWITCH_LABEL)
2796 {}
~AstSwitchLabel()2797 ~AstSwitchLabel() {}
2798
2799 #ifdef JIKES_DEBUG
2800 virtual void Print(LexStream&);
2801 virtual void Unparse(Ostream&, LexStream*);
2802 #endif // JIKES_DEBUG
2803
2804 virtual Ast* Clone(StoragePool*);
2805
LeftToken()2806 virtual TokenIndex LeftToken() { return case_token; }
RightToken()2807 virtual TokenIndex RightToken() { return colon_token; }
2808 };
2809
2810
2811 //
2812 // SwitchBlockStatement --> <SWITCH_BLOCK, SwitchLabels, BlockStatements>
2813 //
2814 class AstSwitchBlockStatement : public AstBlock
2815 {
2816 AstArray<AstSwitchLabel*>* switch_labels;
2817
2818 public:
AstSwitchBlockStatement(StoragePool * p)2819 inline AstSwitchBlockStatement(StoragePool* p)
2820 : AstBlock(p, SWITCH_BLOCK)
2821 {
2822 no_braces = true;
2823 }
~AstSwitchBlockStatement()2824 ~AstSwitchBlockStatement() {}
2825
SwitchLabel(unsigned i)2826 inline AstSwitchLabel*& SwitchLabel(unsigned i)
2827 {
2828 return (*switch_labels)[i];
2829 }
NumSwitchLabels()2830 inline unsigned NumSwitchLabels()
2831 {
2832 return switch_labels ? switch_labels -> Length() : 0;
2833 }
2834 inline void AllocateSwitchLabels(unsigned estimate = 1);
2835 inline void AddSwitchLabel(AstSwitchLabel*);
2836
2837 #ifdef JIKES_DEBUG
2838 virtual void Print(LexStream&);
2839 virtual void Unparse(Ostream&, LexStream*);
2840 #endif // JIKES_DEBUG
2841
2842 virtual Ast* Clone(StoragePool*);
LeftToken()2843 virtual TokenIndex LeftToken() { return SwitchLabel(0) -> case_token; }
2844 // Inherited RightToken() is adequate.
2845 };
2846
2847
2848 //
2849 // This structure allows a switch statement to sort its case labels. It should
2850 // be a plain-old-data type (POD) for efficient copying.
2851 //
2852 struct CaseElement
2853 {
2854 unsigned block_index; // which SwitchBlockStatement
2855 unsigned case_index; // which case label within the block
2856 i4 value; // the value of the case's expression
2857
2858 //
2859 // This keeps the sort stable, so that duplicates stay later in the list.
2860 //
2861 inline bool operator<(CaseElement& right)
2862 {
2863 return value < right.value ||
2864 (value == right.value &&
2865 (block_index < right.block_index ||
2866 (block_index == right.block_index &&
2867 case_index < right.case_index)));
2868 }
2869 };
2870
2871
2872 //
2873 // SwitchStatement --> <SWITCH, Label_opt, switch_token, Expression, {_token,
2874 // SwitchBlockStatements, SwitchLabels_opt, }_token>
2875 //
2876 class AstSwitchStatement : public AstStatement
2877 {
2878 StoragePool* pool;
2879 //
2880 // The sorted list of case label values. Index 0 is reserved for the
2881 // default case. Index 1 - size are for the case labels, and get sorted.
2882 //
2883 CaseElement** cases;
2884 unsigned num_cases;
2885 #ifdef JIKES_DEBUG
2886 unsigned max_cases; // bounds check only when debugging
2887 #endif // JIKES_DEBUG
2888
2889 public:
2890 TokenIndex switch_token;
2891 AstExpression* expression;
2892 AstBlock* switch_block;
2893
AstSwitchStatement(StoragePool * p)2894 inline AstSwitchStatement(StoragePool* p)
2895 : AstStatement(SWITCH)
2896 , pool(p)
2897 {}
~AstSwitchStatement()2898 ~AstSwitchStatement() {}
2899
Case(unsigned i)2900 inline CaseElement*& Case(unsigned i)
2901 {
2902 assert(i < num_cases);
2903 return cases[i + 1];
2904 }
DefaultCase()2905 inline CaseElement*& DefaultCase() { return cases[0]; }
NumCases()2906 inline unsigned NumCases() { return num_cases; }
2907 inline void AllocateCases(unsigned estimate = 1);
2908 inline void AddCase(CaseElement*);
2909
Block(unsigned i)2910 inline AstSwitchBlockStatement* Block(unsigned i)
2911 {
2912 return (AstSwitchBlockStatement*) switch_block -> Statement(i);
2913 }
NumBlocks()2914 inline unsigned NumBlocks() { return switch_block -> NumStatements(); }
2915
2916 void SortCases();
2917 CaseElement* CaseForValue(i4 value);
2918
2919 #ifdef JIKES_DEBUG
2920 virtual void Print(LexStream&);
2921 virtual void Unparse(Ostream&, LexStream*);
2922 #endif // JIKES_DEBUG
2923
2924 virtual Ast* Clone(StoragePool*);
2925
LeftToken()2926 virtual TokenIndex LeftToken() { return switch_token; }
RightToken()2927 virtual TokenIndex RightToken()
2928 {
2929 return switch_block -> right_brace_token;
2930 }
2931 };
2932
2933
2934 //
2935 // WhileStatement --> <WHILE, Label_opt, while_token, Expression, Statement>
2936 //
2937 class AstWhileStatement : public AstStatement
2938 {
2939 public:
2940 TokenIndex while_token;
2941 AstExpression* expression;
2942 AstBlock* statement;
2943
AstWhileStatement()2944 inline AstWhileStatement()
2945 : AstStatement(WHILE)
2946 {}
~AstWhileStatement()2947 ~AstWhileStatement() {}
2948
2949 #ifdef JIKES_DEBUG
2950 virtual void Print(LexStream&);
2951 virtual void Unparse(Ostream&, LexStream*);
2952 #endif // JIKES_DEBUG
2953
2954 virtual Ast* Clone(StoragePool*);
2955
LeftToken()2956 virtual TokenIndex LeftToken() { return while_token; }
RightToken()2957 virtual TokenIndex RightToken() { return statement -> right_brace_token; }
2958 };
2959
2960
2961 //
2962 // DoStatement --> <DO, Label_opt, do_token, Expression, Statement, ;_token>
2963 //
2964 class AstDoStatement : public AstStatement
2965 {
2966 public:
2967 TokenIndex do_token;
2968 AstBlock* statement;
2969 TokenIndex while_token;
2970 AstExpression* expression;
2971 TokenIndex semicolon_token;
2972
AstDoStatement()2973 inline AstDoStatement()
2974 : AstStatement(DO)
2975 {}
~AstDoStatement()2976 ~AstDoStatement() {}
2977
2978 #ifdef JIKES_DEBUG
2979 virtual void Print(LexStream&);
2980 virtual void Unparse(Ostream&, LexStream*);
2981 #endif // JIKES_DEBUG
2982
2983 virtual Ast* Clone(StoragePool*);
2984
LeftToken()2985 virtual TokenIndex LeftToken() { return do_token; }
RightToken()2986 virtual TokenIndex RightToken() { return semicolon_token; }
2987 };
2988
2989
2990 //
2991 // Represents the traditional for statement. The parser has already enclosed
2992 // the overall for statement in its own block, as well as the enclosed
2993 // statement.
2994 //
2995 class AstForStatement : public AstStatement
2996 {
2997 StoragePool* pool;
2998 AstArray<AstStatement*>* for_init_statements;
2999 AstArray<AstExpressionStatement*>* for_update_statements;
3000
3001 public:
3002 TokenIndex for_token;
3003 AstExpression* end_expression_opt;
3004 AstBlock* statement;
3005
AstForStatement(StoragePool * p)3006 inline AstForStatement(StoragePool* p)
3007 : AstStatement(FOR)
3008 , pool(p)
3009 {}
~AstForStatement()3010 ~AstForStatement() {}
3011
ForInitStatement(unsigned i)3012 inline AstStatement*& ForInitStatement(unsigned i)
3013 {
3014 return (*for_init_statements)[i];
3015 }
NumForInitStatements()3016 inline unsigned NumForInitStatements()
3017 {
3018 return for_init_statements ? for_init_statements -> Length() : 0;
3019 }
3020 inline void AllocateForInitStatements(unsigned estimate = 1);
3021 inline void AddForInitStatement(AstStatement*);
3022
ForUpdateStatement(unsigned i)3023 inline AstExpressionStatement*& ForUpdateStatement(unsigned i)
3024 {
3025 return (*for_update_statements)[i];
3026 }
NumForUpdateStatements()3027 inline unsigned NumForUpdateStatements()
3028 {
3029 return for_update_statements ? for_update_statements -> Length() : 0;
3030 }
3031 inline void AllocateForUpdateStatements(unsigned estimate = 1);
3032 inline void AddForUpdateStatement(AstExpressionStatement*);
3033
3034 #ifdef JIKES_DEBUG
3035 virtual void Print(LexStream&);
3036 virtual void Unparse(Ostream&, LexStream*);
3037 #endif // JIKES_DEBUG
3038
3039 virtual Ast* Clone(StoragePool*);
3040
LeftToken()3041 virtual TokenIndex LeftToken() { return for_token; }
RightToken()3042 virtual TokenIndex RightToken() { return statement -> right_brace_token; }
3043 };
3044
3045
3046 //
3047 // ForeachStatement is added in JDK 1.5 by JSR 201. It has the syntax
3048 // "for (FormalParameter : expression) statement", where expression must
3049 // be an array type or an instance of java.lang.Iterable. The parser already
3050 // wrapped the statement in a block.
3051 //
3052 class AstForeachStatement : public AstStatement
3053 {
3054 public:
3055 TokenIndex for_token;
3056 AstFormalParameter* formal_parameter;
3057 AstExpression* expression;
3058 AstBlock* statement;
3059
AstForeachStatement()3060 inline AstForeachStatement()
3061 : AstStatement(FOREACH)
3062 {}
~AstForeachStatement()3063 ~AstForeachStatement() {}
3064
3065 #ifdef JIKES_DEBUG
3066 virtual void Print(LexStream&);
3067 virtual void Unparse(Ostream&, LexStream*);
3068 #endif // JIKES_DEBUG
3069
3070 virtual Ast* Clone(StoragePool*);
3071
LeftToken()3072 virtual TokenIndex LeftToken() { return for_token; }
RightToken()3073 virtual TokenIndex RightToken() { return statement -> right_brace_token; }
3074 };
3075
3076
3077 //
3078 // BreakStatement --> <BREAK, Label_opt, break_token, identifier_token_opt,
3079 // ;_token>
3080 //
3081 class AstBreakStatement : public AstStatement
3082 {
3083 public:
3084 TokenIndex break_token;
3085 TokenIndex identifier_token_opt;
3086 TokenIndex semicolon_token;
3087 unsigned nesting_level;
3088
AstBreakStatement()3089 inline AstBreakStatement()
3090 : AstStatement(BREAK)
3091 {}
~AstBreakStatement()3092 ~AstBreakStatement() {}
3093
3094 #ifdef JIKES_DEBUG
3095 virtual void Print(LexStream&);
3096 virtual void Unparse(Ostream&, LexStream*);
3097 #endif // JIKES_DEBUG
3098
3099 virtual Ast* Clone(StoragePool*);
3100
LeftToken()3101 virtual TokenIndex LeftToken() { return break_token; }
RightToken()3102 virtual TokenIndex RightToken() { return semicolon_token; }
3103 };
3104
3105
3106 //
3107 // ContinueStatement --> <CONTINUE, Label_opt, continue_token, SimpleName_opt,
3108 // ;_token>
3109 //
3110 class AstContinueStatement : public AstStatement
3111 {
3112 public:
3113 TokenIndex continue_token;
3114 TokenIndex identifier_token_opt;
3115 TokenIndex semicolon_token;
3116 unsigned nesting_level;
3117
AstContinueStatement()3118 inline AstContinueStatement()
3119 : AstStatement(CONTINUE)
3120 {}
~AstContinueStatement()3121 ~AstContinueStatement() {}
3122
3123 #ifdef JIKES_DEBUG
3124 virtual void Print(LexStream&);
3125 virtual void Unparse(Ostream&, LexStream*);
3126 #endif // JIKES_DEBUG
3127
3128 virtual Ast* Clone(StoragePool*);
3129
LeftToken()3130 virtual TokenIndex LeftToken() { return continue_token; }
RightToken()3131 virtual TokenIndex RightToken() { return semicolon_token; }
3132 };
3133
3134
3135 //
3136 // ReturnStatement --> <RETURN, Label_opt, return_token, Expression_opt,
3137 // ;_token>
3138 //
3139 class AstReturnStatement : public AstStatement
3140 {
3141 public:
3142 TokenIndex return_token;
3143 AstExpression* expression_opt;
3144 TokenIndex semicolon_token;
3145
AstReturnStatement()3146 inline AstReturnStatement()
3147 : AstStatement(RETURN)
3148 {}
~AstReturnStatement()3149 ~AstReturnStatement() {}
3150
3151 #ifdef JIKES_DEBUG
3152 virtual void Print(LexStream&);
3153 virtual void Unparse(Ostream&, LexStream*);
3154 #endif // JIKES_DEBUG
3155
3156 virtual Ast* Clone(StoragePool*);
3157
LeftToken()3158 virtual TokenIndex LeftToken() { return return_token; }
RightToken()3159 virtual TokenIndex RightToken() { return semicolon_token; }
3160 };
3161
3162
3163 //
3164 // ThrowStatement --> <THROW, Label_opt, throw_token, Expression, ;_token>
3165 //
3166 class AstThrowStatement : public AstStatement
3167 {
3168 public:
3169 TokenIndex throw_token;
3170 AstExpression* expression;
3171 TokenIndex semicolon_token;
3172
AstThrowStatement()3173 inline AstThrowStatement()
3174 : AstStatement(THROW)
3175 {}
~AstThrowStatement()3176 ~AstThrowStatement() {}
3177
3178 #ifdef JIKES_DEBUG
3179 virtual void Print(LexStream&);
3180 virtual void Unparse(Ostream&, LexStream*);
3181 #endif // JIKES_DEBUG
3182
3183 virtual Ast* Clone(StoragePool*);
3184
LeftToken()3185 virtual TokenIndex LeftToken() { return throw_token; }
RightToken()3186 virtual TokenIndex RightToken() { return semicolon_token; }
3187 };
3188
3189
3190 //
3191 // SynchronizedStatement --> <SYNCHRONIZED_STATEMENT, Label_opt,
3192 // synchronized_token, Expression, Block>
3193 //
3194 class AstSynchronizedStatement : public AstStatement
3195 {
3196 public:
3197 TokenIndex synchronized_token;
3198 AstExpression* expression;
3199 AstBlock* block;
3200
AstSynchronizedStatement()3201 inline AstSynchronizedStatement()
3202 : AstStatement(SYNCHRONIZED_STATEMENT)
3203 {}
~AstSynchronizedStatement()3204 ~AstSynchronizedStatement() {}
3205
3206 #ifdef JIKES_DEBUG
3207 virtual void Print(LexStream&);
3208 virtual void Unparse(Ostream&, LexStream*);
3209 #endif // JIKES_DEBUG
3210
3211 virtual Ast* Clone(StoragePool*);
3212
LeftToken()3213 virtual TokenIndex LeftToken() { return synchronized_token; }
RightToken()3214 virtual TokenIndex RightToken() { return block -> right_brace_token; }
3215 };
3216
3217
3218 //
3219 // AssertStatement --> <ASSERT, Label_opt, assert_token, Expression, ;_token>
3220 // --> <ASSERT, Label_opt, assert_token, Expression, :_token,
3221 // Expression, ;_token>
3222 //
3223 class AstAssertStatement : public AstStatement
3224 {
3225 public:
3226 TokenIndex assert_token;
3227 TokenIndex semicolon_token;
3228 AstExpression* condition;
3229 AstExpression* message_opt;
3230
3231 VariableSymbol* assert_variable;
3232
AstAssertStatement()3233 inline AstAssertStatement()
3234 : AstStatement(ASSERT)
3235 {}
~AstAssertStatement()3236 ~AstAssertStatement() {}
3237
3238 #ifdef JIKES_DEBUG
3239 virtual void Print(LexStream&);
3240 virtual void Unparse(Ostream&, LexStream*);
3241 #endif // JIKES_DEBUG
3242
3243 virtual Ast* Clone(StoragePool*);
3244
LeftToken()3245 virtual TokenIndex LeftToken() { return assert_token; }
RightToken()3246 virtual TokenIndex RightToken() { return semicolon_token; }
3247 };
3248
3249
3250 //
3251 // CatchClause --> <CATCH, catch_token, FormalParameter, Block>
3252 //
3253 class AstCatchClause : public Ast
3254 {
3255 public:
3256 VariableSymbol* parameter_symbol;
3257
3258 TokenIndex catch_token;
3259 AstFormalParameter* formal_parameter;
3260 AstBlock* block;
3261
AstCatchClause()3262 inline AstCatchClause()
3263 : Ast(CATCH)
3264 {}
~AstCatchClause()3265 ~AstCatchClause() {}
3266
3267 #ifdef JIKES_DEBUG
3268 virtual void Print(LexStream&);
3269 virtual void Unparse(Ostream&, LexStream*);
3270 #endif // JIKES_DEBUG
3271
3272 virtual Ast* Clone(StoragePool*);
3273
LeftToken()3274 virtual TokenIndex LeftToken() { return catch_token; }
RightToken()3275 virtual TokenIndex RightToken() { return block -> right_brace_token; }
3276 };
3277
3278
3279 //
3280 // FinallyClause --> <FINALLY, finally_token, Block>
3281 //
3282 class AstFinallyClause : public Ast
3283 {
3284 public:
3285 TokenIndex finally_token;
3286 AstBlock* block;
3287
AstFinallyClause()3288 inline AstFinallyClause()
3289 : Ast(FINALLY)
3290 {}
~AstFinallyClause()3291 ~AstFinallyClause() {}
3292
3293 #ifdef JIKES_DEBUG
3294 virtual void Print(LexStream&);
3295 virtual void Unparse(Ostream&, LexStream*);
3296 #endif // JIKES_DEBUG
3297
3298 virtual Ast* Clone(StoragePool*);
3299
LeftToken()3300 virtual TokenIndex LeftToken() { return finally_token; }
RightToken()3301 virtual TokenIndex RightToken() { return block -> right_brace_token; }
3302 };
3303
3304
3305 //
3306 // TryStatement --> <TRY, Label_opt, try-token, Block CatchClauses,
3307 // FinallyClause_opt>
3308 //
3309 class AstTryStatement : public AstStatement
3310 {
3311 StoragePool* pool;
3312 AstArray<AstCatchClause*>* catch_clauses;
3313
3314 public:
3315 TokenIndex try_token;
3316 AstBlock* block;
3317 AstFinallyClause* finally_clause_opt;
3318 bool processing_try_block;
3319
AstTryStatement(StoragePool * p)3320 inline AstTryStatement(StoragePool* p)
3321 : AstStatement(TRY)
3322 , pool(p)
3323 {}
~AstTryStatement()3324 ~AstTryStatement() {}
3325
CatchClause(unsigned i)3326 inline AstCatchClause*& CatchClause(unsigned i)
3327 {
3328 return (*catch_clauses)[i];
3329 }
NumCatchClauses()3330 inline unsigned NumCatchClauses()
3331 {
3332 return catch_clauses ? catch_clauses -> Length() : 0;
3333 }
3334 inline void AllocateCatchClauses(unsigned estimate = 1);
3335 inline void AddCatchClause(AstCatchClause*);
3336
3337 #ifdef JIKES_DEBUG
3338 virtual void Print(LexStream&);
3339 virtual void Unparse(Ostream&, LexStream*);
3340 #endif // JIKES_DEBUG
3341
3342 virtual Ast* Clone(StoragePool*);
3343
LeftToken()3344 virtual TokenIndex LeftToken() { return try_token; }
RightToken()3345 virtual TokenIndex RightToken()
3346 {
3347 return finally_clause_opt ? finally_clause_opt -> RightToken()
3348 : CatchClause(NumCatchClauses() - 1) -> RightToken();
3349 }
3350 };
3351
3352
3353 //
3354 // Represents an int literal.
3355 //
3356 class AstIntegerLiteral : public AstExpression
3357 {
3358 public:
3359 TokenIndex integer_literal_token;
3360
AstIntegerLiteral(TokenIndex token)3361 inline AstIntegerLiteral(TokenIndex token)
3362 : AstExpression(INTEGER_LITERAL)
3363 , integer_literal_token(token)
3364 {}
~AstIntegerLiteral()3365 ~AstIntegerLiteral() {}
3366
3367 #ifdef JIKES_DEBUG
3368 virtual void Print(LexStream&);
3369 virtual void Unparse(Ostream&, LexStream*);
3370 #endif // JIKES_DEBUG
3371
3372 virtual Ast* Clone(StoragePool*);
3373
LeftToken()3374 virtual TokenIndex LeftToken() { return integer_literal_token; }
RightToken()3375 virtual TokenIndex RightToken() { return integer_literal_token; }
3376 };
3377
3378
3379 //
3380 // LongLiteral --> <LONG_LITERAL, long_literal_token, value>
3381 //
3382 class AstLongLiteral : public AstExpression
3383 {
3384 public:
3385 TokenIndex long_literal_token;
3386
AstLongLiteral(TokenIndex token)3387 inline AstLongLiteral(TokenIndex token)
3388 : AstExpression(LONG_LITERAL)
3389 , long_literal_token(token)
3390 {}
~AstLongLiteral()3391 ~AstLongLiteral() {}
3392
3393 #ifdef JIKES_DEBUG
3394 virtual void Print(LexStream&);
3395 virtual void Unparse(Ostream&, LexStream*);
3396 #endif // JIKES_DEBUG
3397
3398 virtual Ast* Clone(StoragePool*);
3399
LeftToken()3400 virtual TokenIndex LeftToken() { return long_literal_token; }
RightToken()3401 virtual TokenIndex RightToken() { return long_literal_token; }
3402 };
3403
3404
3405 //
3406 // FloatLiteral --> <FLOAT_LITERAL, Literal, value>
3407 //
3408 class AstFloatLiteral : public AstExpression
3409 {
3410 public:
3411 TokenIndex float_literal_token;
3412
AstFloatLiteral(TokenIndex token)3413 inline AstFloatLiteral(TokenIndex token)
3414 : AstExpression(FLOAT_LITERAL)
3415 , float_literal_token(token)
3416 {}
~AstFloatLiteral()3417 ~AstFloatLiteral() {}
3418
3419 #ifdef JIKES_DEBUG
3420 virtual void Print(LexStream&);
3421 virtual void Unparse(Ostream&, LexStream*);
3422 #endif // JIKES_DEBUG
3423
3424 virtual Ast* Clone(StoragePool*);
3425
LeftToken()3426 virtual TokenIndex LeftToken() { return float_literal_token; }
RightToken()3427 virtual TokenIndex RightToken() { return float_literal_token; }
3428 };
3429
3430
3431 //
3432 // DoubleLiteral --> <DOUBLE_LITERAL, Literal, value>
3433 //
3434 class AstDoubleLiteral : public AstExpression
3435 {
3436 public:
3437 TokenIndex double_literal_token;
3438
AstDoubleLiteral(TokenIndex token)3439 inline AstDoubleLiteral(TokenIndex token)
3440 : AstExpression(DOUBLE_LITERAL)
3441 , double_literal_token(token)
3442 {}
~AstDoubleLiteral()3443 ~AstDoubleLiteral() {}
3444
3445 #ifdef JIKES_DEBUG
3446 virtual void Print(LexStream&);
3447 virtual void Unparse(Ostream&, LexStream*);
3448 #endif // JIKES_DEBUG
3449
3450 virtual Ast* Clone(StoragePool*);
3451
LeftToken()3452 virtual TokenIndex LeftToken() { return double_literal_token; }
RightToken()3453 virtual TokenIndex RightToken() { return double_literal_token; }
3454 };
3455
3456
3457 //
3458 // TrueLiteral --> <TRUE_LITERAL, Literal, value>
3459 //
3460 class AstTrueLiteral : public AstExpression
3461 {
3462 public:
3463 TokenIndex true_literal_token;
3464
AstTrueLiteral(TokenIndex token)3465 inline AstTrueLiteral(TokenIndex token)
3466 : AstExpression(TRUE_LITERAL)
3467 , true_literal_token(token)
3468 {}
~AstTrueLiteral()3469 ~AstTrueLiteral() {}
3470
3471 #ifdef JIKES_DEBUG
3472 virtual void Print(LexStream&);
3473 virtual void Unparse(Ostream&, LexStream*);
3474 #endif // JIKES_DEBUG
3475
3476 virtual Ast* Clone(StoragePool*);
3477
LeftToken()3478 virtual TokenIndex LeftToken() { return true_literal_token; }
RightToken()3479 virtual TokenIndex RightToken() { return true_literal_token; }
3480 };
3481
3482
3483 //
3484 // FalseLiteral --> <FALSE_LITERAL, Literal, value>
3485 //
3486 class AstFalseLiteral : public AstExpression
3487 {
3488 public:
3489 TokenIndex false_literal_token;
3490
AstFalseLiteral(TokenIndex token)3491 inline AstFalseLiteral(TokenIndex token)
3492 : AstExpression(FALSE_LITERAL)
3493 , false_literal_token(token)
3494 {}
~AstFalseLiteral()3495 ~AstFalseLiteral() {}
3496
3497 #ifdef JIKES_DEBUG
3498 virtual void Print(LexStream&);
3499 virtual void Unparse(Ostream&, LexStream*);
3500 #endif // JIKES_DEBUG
3501
3502 virtual Ast* Clone(StoragePool*);
3503
LeftToken()3504 virtual TokenIndex LeftToken() { return false_literal_token; }
RightToken()3505 virtual TokenIndex RightToken() { return false_literal_token; }
3506 };
3507
3508
3509 //
3510 // StringLiteral --> <STRING_LITERAL, Literal, value>
3511 //
3512 class AstStringLiteral : public AstExpression
3513 {
3514 public:
3515 TokenIndex string_literal_token;
3516
AstStringLiteral(TokenIndex token)3517 inline AstStringLiteral(TokenIndex token)
3518 : AstExpression(STRING_LITERAL)
3519 , string_literal_token(token)
3520 {}
~AstStringLiteral()3521 ~AstStringLiteral() {}
3522
3523 #ifdef JIKES_DEBUG
3524 virtual void Print(LexStream&);
3525 virtual void Unparse(Ostream&, LexStream*);
3526 #endif // JIKES_DEBUG
3527
3528 virtual Ast* Clone(StoragePool*);
3529
LeftToken()3530 virtual TokenIndex LeftToken() { return string_literal_token; }
RightToken()3531 virtual TokenIndex RightToken() { return string_literal_token; }
3532 };
3533
3534
3535 //
3536 // CharacterLiteral --> <CHARACTER_LITERAL, literal_token, value>
3537 //
3538 class AstCharacterLiteral : public AstExpression
3539 {
3540 public:
3541 TokenIndex character_literal_token;
3542
AstCharacterLiteral(TokenIndex token)3543 inline AstCharacterLiteral(TokenIndex token)
3544 : AstExpression(CHARACTER_LITERAL)
3545 , character_literal_token(token)
3546 {}
~AstCharacterLiteral()3547 ~AstCharacterLiteral() {}
3548
3549 #ifdef JIKES_DEBUG
3550 virtual void Print(LexStream&);
3551 virtual void Unparse(Ostream&, LexStream*);
3552 #endif // JIKES_DEBUG
3553
3554 virtual Ast* Clone(StoragePool*);
3555
LeftToken()3556 virtual TokenIndex LeftToken() { return character_literal_token; }
RightToken()3557 virtual TokenIndex RightToken() { return character_literal_token; }
3558 };
3559
3560
3561 //
3562 // NullLiteral --> <NULL_EXPRESSION, null_token>
3563 //
3564 class AstNullLiteral : public AstExpression
3565 {
3566 public:
3567 TokenIndex null_token;
3568
AstNullLiteral(TokenIndex token)3569 inline AstNullLiteral(TokenIndex token)
3570 : AstExpression(NULL_LITERAL)
3571 , null_token(token)
3572 {}
~AstNullLiteral()3573 ~AstNullLiteral() {}
3574
3575 #ifdef JIKES_DEBUG
3576 virtual void Print(LexStream&);
3577 virtual void Unparse(Ostream&, LexStream*);
3578 #endif // JIKES_DEBUG
3579
3580 virtual Ast* Clone(StoragePool*);
3581
LeftToken()3582 virtual TokenIndex LeftToken() { return null_token; }
RightToken()3583 virtual TokenIndex RightToken() { return null_token; }
3584 };
3585
3586
3587 //
3588 // Represents class literals.
3589 //
3590 class AstClassLiteral : public AstExpression
3591 {
3592 public:
3593 AstType* type;
3594 TokenIndex class_token;
3595
3596 //
3597 // If this expression requires a caching variable and a call to class$(),
3598 // the resolution holds the needed class$xxx or array$xxx cache.
3599 //
3600 AstExpression* resolution_opt;
3601
AstClassLiteral(TokenIndex token)3602 inline AstClassLiteral(TokenIndex token)
3603 : AstExpression(CLASS_LITERAL)
3604 , class_token(token)
3605 {}
~AstClassLiteral()3606 ~AstClassLiteral() {}
3607
3608 #ifdef JIKES_DEBUG
3609 virtual void Print(LexStream&);
3610 virtual void Unparse(Ostream&, LexStream*);
3611 #endif // JIKES_DEBUG
3612
3613 virtual Ast* Clone(StoragePool*);
3614
LeftToken()3615 virtual TokenIndex LeftToken() { return type -> LeftToken(); }
RightToken()3616 virtual TokenIndex RightToken() { return class_token; }
3617 };
3618
3619
3620 //
3621 // Represents qualified and simple 'this'.
3622 //
3623 class AstThisExpression : public AstExpression
3624 {
3625 public:
3626 AstTypeName* base_opt;
3627 TokenIndex this_token;
3628
3629 //
3630 // If this expression accesses an enclosing instance, the resolution
3631 // holds the needed chain of "this$0" traversals.
3632 //
3633 AstExpression* resolution_opt;
3634
AstThisExpression(TokenIndex token)3635 inline AstThisExpression(TokenIndex token)
3636 : AstExpression(THIS_EXPRESSION)
3637 , this_token(token)
3638 {}
~AstThisExpression()3639 ~AstThisExpression() {}
3640
3641 #ifdef JIKES_DEBUG
3642 virtual void Print(LexStream&);
3643 virtual void Unparse(Ostream&, LexStream*);
3644 #endif // JIKES_DEBUG
3645
3646 virtual Ast* Clone(StoragePool*);
3647
LeftToken()3648 virtual TokenIndex LeftToken()
3649 {
3650 return base_opt ? base_opt -> LeftToken() : this_token;
3651 }
RightToken()3652 virtual TokenIndex RightToken() { return this_token; }
3653 };
3654
3655
3656 //
3657 // Represents qualified and simple 'super'.
3658 //
3659 class AstSuperExpression : public AstExpression
3660 {
3661 public:
3662 AstTypeName* base_opt;
3663 TokenIndex super_token;
3664
3665 //
3666 // If this expression accesses an enclosing instance, the resolution
3667 // holds the needed chain of "this$0" traversals.
3668 //
3669 AstExpression* resolution_opt;
3670
AstSuperExpression(TokenIndex token)3671 inline AstSuperExpression(TokenIndex token)
3672 : AstExpression(SUPER_EXPRESSION)
3673 , super_token(token)
3674 {}
~AstSuperExpression()3675 ~AstSuperExpression() {}
3676
3677 #ifdef JIKES_DEBUG
3678 virtual void Print(LexStream&);
3679 virtual void Unparse(Ostream&, LexStream*);
3680 #endif // JIKES_DEBUG
3681
3682 virtual Ast* Clone(StoragePool*);
3683
LeftToken()3684 virtual TokenIndex LeftToken()
3685 {
3686 return base_opt ? base_opt -> LeftToken() : super_token;
3687 }
RightToken()3688 virtual TokenIndex RightToken() { return super_token; }
3689 };
3690
3691
3692 //
3693 // ParenthesizedExpression --> <PARENTHESIZED_EXPRESSION, (_token, Expression,
3694 // )_token>
3695 //
3696 class AstParenthesizedExpression : public AstExpression
3697 {
3698 public:
3699 TokenIndex left_parenthesis_token;
3700 AstExpression* expression;
3701 TokenIndex right_parenthesis_token;
3702
AstParenthesizedExpression()3703 inline AstParenthesizedExpression()
3704 : AstExpression(PARENTHESIZED_EXPRESSION)
3705 {}
~AstParenthesizedExpression()3706 ~AstParenthesizedExpression() {}
3707
3708 #ifdef JIKES_DEBUG
3709 virtual void Print(LexStream&);
3710 virtual void Unparse(Ostream&, LexStream*);
3711 #endif // JIKES_DEBUG
3712
3713 virtual Ast* Clone(StoragePool*);
3714
LeftToken()3715 virtual TokenIndex LeftToken() { return left_parenthesis_token; }
RightToken()3716 virtual TokenIndex RightToken() { return right_parenthesis_token; }
3717 };
3718
3719
3720 //
3721 // ClassCreationExpression represents a class instance creation (keyword new,
3722 // including anonymous classes). Also see ArrayCreationExpression. Sometimes,
3723 // during semantic analysis an artificial base_opt expression is constructed.
3724 // In such a case, the user can determine this condition by testing
3725 // base_opt -> generated.
3726 //
3727 class AstClassCreationExpression : public AstExpression
3728 {
3729 public:
3730 AstExpression* base_opt;
3731 TokenIndex new_token;
3732 AstTypeArguments* type_arguments_opt;
3733 AstTypeName* class_type;
3734 AstArguments* arguments;
3735 AstClassBody* class_body_opt;
3736
3737 //
3738 // For anonymous classes, we resolve the original statement into a new
3739 // one that does not have a class_body_opt. This is necessary to get
3740 // the parameters called in the correct order.
3741 //
3742 AstClassCreationExpression* resolution_opt;
3743
AstClassCreationExpression()3744 inline AstClassCreationExpression()
3745 : AstExpression(CLASS_CREATION)
3746 {}
~AstClassCreationExpression()3747 ~AstClassCreationExpression() {}
3748
3749 #ifdef JIKES_DEBUG
3750 virtual void Print(LexStream&);
3751 virtual void Unparse(Ostream&, LexStream*);
3752 #endif // JIKES_DEBUG
3753
3754 virtual Ast* Clone(StoragePool*);
3755
LeftToken()3756 virtual TokenIndex LeftToken()
3757 {
3758 return base_opt ? base_opt -> LeftToken() : new_token;
3759 }
RightToken()3760 virtual TokenIndex RightToken()
3761 {
3762 return class_body_opt ? class_body_opt -> right_brace_token
3763 : arguments -> right_parenthesis_token;
3764 }
3765 };
3766
3767
3768 //
3769 // DimExpr --> <DIM, [_token, Expression, ]_token>
3770 //
3771 class AstDimExpr : public Ast
3772 {
3773 public:
3774 TokenIndex left_bracket_token;
3775 AstExpression* expression;
3776 TokenIndex right_bracket_token;
3777
AstDimExpr()3778 inline AstDimExpr()
3779 : Ast(DIM)
3780 {}
~AstDimExpr()3781 ~AstDimExpr() {}
3782
3783 #ifdef JIKES_DEBUG
3784 virtual void Print(LexStream&);
3785 virtual void Unparse(Ostream&, LexStream*);
3786 #endif // JIKES_DEBUG
3787
3788 virtual Ast* Clone(StoragePool*);
3789
LeftToken()3790 virtual TokenIndex LeftToken() { return left_bracket_token; }
RightToken()3791 virtual TokenIndex RightToken() { return right_bracket_token; }
3792 };
3793
3794
3795 //
3796 // ArrayCreationExpression --> <ARRAY_CREATION, new_token, Type, DimExprs,
3797 // Brackets>
3798 //
3799 class AstArrayCreationExpression : public AstExpression
3800 {
3801 StoragePool* pool;
3802 AstArray<AstDimExpr*>* dim_exprs;
3803
3804 public:
3805 TokenIndex new_token;
3806 AstType* array_type;
3807 AstBrackets* brackets_opt;
3808 AstArrayInitializer* array_initializer_opt;
3809
AstArrayCreationExpression(StoragePool * p)3810 inline AstArrayCreationExpression(StoragePool* p)
3811 : AstExpression(ARRAY_CREATION)
3812 , pool(p)
3813 {}
~AstArrayCreationExpression()3814 ~AstArrayCreationExpression() {}
3815
DimExpr(unsigned i)3816 inline AstDimExpr*& DimExpr(unsigned i) { return (*dim_exprs)[i]; }
NumDimExprs()3817 inline unsigned NumDimExprs()
3818 {
3819 return dim_exprs ? dim_exprs -> Length() : 0;
3820 }
3821 inline void AllocateDimExprs(unsigned estimate = 1);
3822 inline void AddDimExpr(AstDimExpr*);
3823
NumBrackets()3824 inline unsigned NumBrackets()
3825 {
3826 return brackets_opt ? brackets_opt -> dims : 0;
3827 }
3828
3829 #ifdef JIKES_DEBUG
3830 virtual void Print(LexStream&);
3831 virtual void Unparse(Ostream&, LexStream*);
3832 #endif // JIKES_DEBUG
3833
3834 virtual Ast* Clone(StoragePool*);
3835
LeftToken()3836 virtual TokenIndex LeftToken() { return new_token; }
RightToken()3837 virtual TokenIndex RightToken()
3838 {
3839 return array_initializer_opt
3840 ? array_initializer_opt -> right_brace_token
3841 : brackets_opt ? brackets_opt -> right_bracket_token
3842 : DimExpr(NumDimExprs() - 1) -> right_bracket_token;
3843 }
3844 };
3845
3846
3847 //
3848 // FieldAccess --> <DOT, Primary, ._token, Identifier>
3849 //
3850 class AstFieldAccess : public AstExpression
3851 {
3852 public:
3853 AstExpression* base; // Not AstName.
3854 TokenIndex identifier_token;
3855
3856 //
3857 // If the base expression of FieldAccess expression is of the form
3858 // type.this.X, where X is a private variable that is a member of an
3859 // outer class, then we resolve it into a method call to the read_mehod
3860 // that gives access to X.
3861 //
3862 AstExpression* resolution_opt;
3863
AstFieldAccess()3864 inline AstFieldAccess()
3865 : AstExpression(DOT)
3866 {}
~AstFieldAccess()3867 ~AstFieldAccess() {}
3868
3869 #ifdef JIKES_DEBUG
3870 virtual void Print(LexStream&);
3871 virtual void Unparse(Ostream&, LexStream*);
3872 #endif // JIKES_DEBUG
3873
3874 virtual Ast* Clone(StoragePool*);
3875
LeftToken()3876 virtual TokenIndex LeftToken() { return base -> LeftToken(); }
RightToken()3877 virtual TokenIndex RightToken() { return identifier_token; }
3878 };
3879
3880
3881 //
3882 // Represents a method call. Sometimes, during semantic analysis an
3883 // artificial base_opt expression is constructed. In such a case, the user
3884 // can determine this condition by testing base_opt -> generated.
3885 //
3886 class AstMethodInvocation : public AstExpression
3887 {
3888 public:
3889 AstExpression* base_opt;
3890 AstTypeArguments* type_arguments_opt;
3891 TokenIndex identifier_token;
3892 AstArguments* arguments;
3893
3894 //
3895 // When a method refers to a member in an enclosing scope,
3896 // it is mapped into a new expression that creates a path to
3897 // the member in question.
3898 //
3899 AstExpression* resolution_opt;
3900
AstMethodInvocation(TokenIndex t)3901 inline AstMethodInvocation(TokenIndex t)
3902 : AstExpression(CALL)
3903 , identifier_token(t)
3904 {}
~AstMethodInvocation()3905 ~AstMethodInvocation() {}
3906
3907 #ifdef JIKES_DEBUG
3908 virtual void Print(LexStream&);
3909 virtual void Unparse(Ostream&, LexStream*);
3910 #endif // JIKES_DEBUG
3911
3912 virtual Ast* Clone(StoragePool*);
3913
LeftToken()3914 virtual TokenIndex LeftToken()
3915 {
3916 if (type_arguments_opt)
3917 assert(base_opt);
3918 return base_opt ? base_opt -> LeftToken() : identifier_token;
3919 }
RightToken()3920 virtual TokenIndex RightToken()
3921 {
3922 return arguments -> right_parenthesis_token;
3923 }
3924 };
3925
3926
3927 //
3928 // ArrayAccess --> <ARRAY_ACCESS, Base, [_token, Expression, ]_token>
3929 //
3930 class AstArrayAccess : public AstExpression
3931 {
3932 public:
3933 AstExpression* base;
3934 TokenIndex left_bracket_token;
3935 AstExpression* expression;
3936 TokenIndex right_bracket_token;
3937
AstArrayAccess()3938 inline AstArrayAccess()
3939 : AstExpression(ARRAY_ACCESS)
3940 {}
~AstArrayAccess()3941 ~AstArrayAccess() {}
3942
3943 #ifdef JIKES_DEBUG
3944 virtual void Print(LexStream&);
3945 virtual void Unparse(Ostream&, LexStream*);
3946 #endif // JIKES_DEBUG
3947
3948 virtual Ast* Clone(StoragePool*);
3949
LeftToken()3950 virtual TokenIndex LeftToken() { return base -> LeftToken(); }
RightToken()3951 virtual TokenIndex RightToken() { return right_bracket_token; }
3952 };
3953
3954
3955 //
3956 // UnaryExpression --> PreUnaryExpression
3957 // | PostUnaryExpression
3958 // | CastExpression
3959 //
3960 // PostUnaryExpression --> <POST_UNARY, PostUnaryTag, Expression, PostOperator>
3961 //
3962 // PostUnaryTag --> PLUSPLUS | MINUSMINUS
3963 //
3964 // PostOperator --> ++_token | --_token
3965 //
3966 class AstPostUnaryExpression : public AstExpression
3967 {
3968 public:
3969 enum PostUnaryExpressionTag
3970 {
3971 NONE,
3972 PLUSPLUS,
3973 MINUSMINUS,
3974
3975 _num_kinds
3976 };
3977
3978 AstExpression* expression;
3979 TokenIndex post_operator_token;
3980
3981 //
3982 // When the left-hand side of an assignment is a name that refers
3983 // to a private field in an enclosing scope, the access method
3984 // that gives write-permission to that field is recorded here.
3985 //
3986 MethodSymbol* write_method;
3987
AstPostUnaryExpression(PostUnaryExpressionTag tag)3988 inline AstPostUnaryExpression(PostUnaryExpressionTag tag)
3989 : AstExpression(POST_UNARY)
3990 {
3991 other_tag = tag;
3992 }
~AstPostUnaryExpression()3993 ~AstPostUnaryExpression() {}
3994
Tag()3995 inline PostUnaryExpressionTag Tag()
3996 {
3997 return (PostUnaryExpressionTag) other_tag;
3998 }
3999
4000 #ifdef JIKES_DEBUG
4001 virtual void Print(LexStream&);
4002 virtual void Unparse(Ostream&, LexStream*);
4003 #endif // JIKES_DEBUG
4004
4005 virtual Ast* Clone(StoragePool*);
4006
LeftToken()4007 virtual TokenIndex LeftToken() { return expression -> LeftToken(); }
RightToken()4008 virtual TokenIndex RightToken() { return post_operator_token; }
4009 };
4010
4011
4012 //
4013 // PreUnaryExpression --> <PRE_UNARY, PreUnaryTag, PreOperator, Expression>
4014 //
4015 // PreUnaryTag --> PLUS | MINUS | TWIDDLE | NOT | PLUSPLUS | MINUSMINUS
4016 //
4017 // PreOperator --> +_token | -_token | ~_token | !_token | ++_token | --_token
4018 //
4019 class AstPreUnaryExpression : public AstExpression
4020 {
4021 public:
4022 enum PreUnaryExpressionTag
4023 {
4024 NONE,
4025 PLUSPLUS,
4026 MINUSMINUS,
4027 PLUS,
4028 MINUS,
4029 TWIDDLE,
4030 NOT,
4031
4032 _num_kinds
4033 };
4034
4035 TokenIndex pre_operator_token;
4036 AstExpression* expression;
4037
4038 //
4039 // When the left-hand side of an assignment is a name that refers
4040 // to a private field in an enclosing scope, the access method
4041 // that gives write-permission to that field is recorded here.
4042 //
4043 MethodSymbol* write_method;
4044
AstPreUnaryExpression(PreUnaryExpressionTag tag)4045 inline AstPreUnaryExpression(PreUnaryExpressionTag tag)
4046 : AstExpression(PRE_UNARY)
4047 {
4048 other_tag = tag;
4049 }
~AstPreUnaryExpression()4050 ~AstPreUnaryExpression() {}
4051
Tag()4052 inline PreUnaryExpressionTag Tag()
4053 {
4054 return (PreUnaryExpressionTag) other_tag;
4055 }
4056
4057 #ifdef JIKES_DEBUG
4058 virtual void Print(LexStream&);
4059 virtual void Unparse(Ostream&, LexStream*);
4060 #endif // JIKES_DEBUG
4061
4062 virtual Ast* Clone(StoragePool*);
4063
LeftToken()4064 virtual TokenIndex LeftToken() { return pre_operator_token; }
RightToken()4065 virtual TokenIndex RightToken() { return expression -> RightToken(); }
4066 };
4067
4068
4069 //
4070 // CastExpression --> <castkind, (_token_opt, Type, )_token_opt, Expression>
4071 //
4072 // NOTE that the optional symbols above are absent only when the compiler
4073 // inserts a CAST conversion node into the program.
4074 //
4075 class AstCastExpression : public AstExpression
4076 {
4077 public:
4078 TokenIndex left_parenthesis_token;
4079 AstType* type;
4080 TokenIndex right_parenthesis_token;
4081 AstExpression* expression;
4082
AstCastExpression()4083 inline AstCastExpression()
4084 : AstExpression(CAST)
4085 {}
~AstCastExpression()4086 ~AstCastExpression() {}
4087
4088 #ifdef JIKES_DEBUG
4089 virtual void Print(LexStream&);
4090 virtual void Unparse(Ostream&, LexStream*);
4091 #endif // JIKES_DEBUG
4092
4093 virtual Ast* Clone(StoragePool*);
4094
LeftToken()4095 virtual TokenIndex LeftToken() { return left_parenthesis_token; }
RightToken()4096 virtual TokenIndex RightToken() { return expression -> RightToken(); }
4097 };
4098
4099
4100 //
4101 // BinaryExpression --> <BINARY, BinaryTag, Expression, BinaryOperator,
4102 // Expression>
4103 //
4104 // BinaryTag --> STAR | SLASH | MOD | PLUS | MINUS | LEFT_SHIFT | RIGHT_SHIFT |
4105 // UNSIGNED_RIGHT_SHIFT | LESS | GREATER |
4106 // LESS_EQUAL | GREATER_EQUAL | EQUAL_EQUAL | NOT_EQUAL |
4107 // AND | XOR | IOR | AND_AND | OR_OR
4108 //
4109 // BinaryOperator --> *_token | /_token | %_token | +_token | -_token |
4110 // <<_token | >>_token | >>>_token | <_token | >_token |
4111 // <=_token | >=_token | ==_token | !=_token | &_token |
4112 // ^_token | |_token | &&_token | ||_token
4113 //
4114 class AstBinaryExpression : public AstExpression
4115 {
4116 public:
4117 enum BinaryExpressionTag
4118 {
4119 NONE,
4120 STAR,
4121 SLASH,
4122 MOD,
4123 PLUS,
4124 MINUS,
4125 LEFT_SHIFT,
4126 RIGHT_SHIFT,
4127 UNSIGNED_RIGHT_SHIFT,
4128 LESS,
4129 GREATER,
4130 AND,
4131 XOR,
4132 IOR,
4133 AND_AND,
4134 OR_OR,
4135
4136 LESS_EQUAL,
4137 GREATER_EQUAL,
4138 EQUAL_EQUAL,
4139 NOT_EQUAL,
4140
4141 _num_kinds
4142 };
4143
4144 AstExpression* left_expression;
4145 TokenIndex binary_operator_token;
4146 AstExpression* right_expression;
4147
AstBinaryExpression(BinaryExpressionTag tag)4148 inline AstBinaryExpression(BinaryExpressionTag tag)
4149 : AstExpression(BINARY)
4150 {
4151 other_tag = tag;
4152 }
~AstBinaryExpression()4153 ~AstBinaryExpression() {}
4154
Tag()4155 inline BinaryExpressionTag Tag()
4156 {
4157 return (BinaryExpressionTag) other_tag;
4158 }
4159
4160 #ifdef JIKES_DEBUG
4161 virtual void Print(LexStream&);
4162 virtual void Unparse(Ostream&, LexStream*);
4163 #endif // JIKES_DEBUG
4164
4165 virtual Ast* Clone(StoragePool*);
4166
LeftToken()4167 virtual TokenIndex LeftToken() { return left_expression -> LeftToken(); }
RightToken()4168 virtual TokenIndex RightToken()
4169 {
4170 return right_expression -> RightToken();
4171 }
4172 };
4173
4174
4175 //
4176 // Represents instanceof expressions.
4177 //
4178 class AstInstanceofExpression : public AstExpression
4179 {
4180 public:
4181 AstExpression* expression;
4182 TokenIndex instanceof_token;
4183 AstType* type; // AstArrayType, AstTypeName
4184
AstInstanceofExpression()4185 inline AstInstanceofExpression()
4186 : AstExpression(INSTANCEOF)
4187 {}
~AstInstanceofExpression()4188 ~AstInstanceofExpression() {}
4189
4190 #ifdef JIKES_DEBUG
4191 virtual void Print(LexStream&);
4192 virtual void Unparse(Ostream&, LexStream*);
4193 #endif // JIKES_DEBUG
4194
4195 virtual Ast* Clone(StoragePool*);
4196
LeftToken()4197 virtual TokenIndex LeftToken() { return expression -> LeftToken(); }
RightToken()4198 virtual TokenIndex RightToken() { return type -> RightToken(); }
4199 };
4200
4201
4202 //
4203 // ConditionalExpression --> <CONDITIONAL, Expression, ?_token, Expression,
4204 // :_token, Expression>
4205 //
4206 class AstConditionalExpression : public AstExpression
4207 {
4208 public:
4209 AstExpression* test_expression;
4210 TokenIndex question_token;
4211 AstExpression* true_expression;
4212 TokenIndex colon_token;
4213 AstExpression* false_expression;
4214
AstConditionalExpression()4215 inline AstConditionalExpression()
4216 : AstExpression(CONDITIONAL)
4217 {}
~AstConditionalExpression()4218 ~AstConditionalExpression() {}
4219
4220 #ifdef JIKES_DEBUG
4221 virtual void Print(LexStream&);
4222 virtual void Unparse(Ostream&, LexStream*);
4223 #endif // JIKES_DEBUG
4224
4225 virtual Ast* Clone(StoragePool*);
4226
LeftToken()4227 virtual TokenIndex LeftToken() { return test_expression -> LeftToken(); }
RightToken()4228 virtual TokenIndex RightToken()
4229 {
4230 return false_expression -> RightToken();
4231 }
4232 };
4233
4234
4235 //
4236 // Assignment --> <ASSIGNMENT, AssignmentTag, LeftHandSide, AssignmentOperator,
4237 // Expression>
4238 //
4239 // AssignmentTag --> EQUAL | STAR_EQUAL | SLASH_EQUAL | MOD_EQUAL |
4240 // PLUS_EQUAL | MINUS_EQUAL | LEFT_SHIFT_EQUAL |
4241 // RIGHT_SHIFT_EQUAL | UNSIGNED_RIGHT_SHIFT_EQUAL |
4242 // AND_EQUAL | XOR_EQUAL | IOR_EQUAL
4243 //
4244 // LeftHandSide --> Name | FieldAccess | ArrayAccess | ParenthesizedExpression
4245 // | CastExpression
4246 //
4247 // NOTE: that a LeftHandSide appears as a cast node only when the
4248 // assignment_operator in question is of the form "op=" and the application
4249 // of the operator requires a casting of the value of the left-hand side.
4250 //
4251 // AssignmentOperator --> =_token | *=_token | /=_token | %=_token | +=_token |
4252 // -=_token | <<=_token | >>=_token | >>>=_token |
4253 // &=_token | ^=_token | |=_token
4254 //
4255 class AstAssignmentExpression : public AstExpression
4256 {
4257 public:
4258 enum AssignmentExpressionTag
4259 {
4260 NONE,
4261 SIMPLE_EQUAL,
4262 STAR_EQUAL,
4263 SLASH_EQUAL,
4264 MOD_EQUAL,
4265 PLUS_EQUAL,
4266 MINUS_EQUAL,
4267 LEFT_SHIFT_EQUAL,
4268 RIGHT_SHIFT_EQUAL,
4269 UNSIGNED_RIGHT_SHIFT_EQUAL,
4270
4271 AND_EQUAL,
4272 XOR_EQUAL,
4273 IOR_EQUAL,
4274
4275 _num_kinds
4276 };
4277
4278 //
4279 // When the left-hand side of an assignment is a name that refers
4280 // to a private field in an enclosing scope, the access method
4281 // that gives write-permission to that field is recorded here.
4282 //
4283 MethodSymbol* write_method;
4284
4285 AstExpression* left_hand_side;
4286 TokenIndex assignment_operator_token;
4287 AstExpression* expression;
4288
AstAssignmentExpression(AssignmentExpressionTag tag,TokenIndex t)4289 inline AstAssignmentExpression(AssignmentExpressionTag tag, TokenIndex t)
4290 : AstExpression(ASSIGNMENT)
4291 , assignment_operator_token(t)
4292 {
4293 other_tag = tag;
4294 }
~AstAssignmentExpression()4295 ~AstAssignmentExpression() {}
4296
Tag()4297 inline AssignmentExpressionTag Tag()
4298 {
4299 return (AssignmentExpressionTag) other_tag;
4300 }
SimpleAssignment()4301 inline bool SimpleAssignment() { return other_tag == SIMPLE_EQUAL; }
4302
4303 #ifdef JIKES_DEBUG
4304 virtual void Print(LexStream&);
4305 virtual void Unparse(Ostream&, LexStream*);
4306 #endif // JIKES_DEBUG
4307
4308 virtual Ast* Clone(StoragePool*);
4309
LeftToken()4310 virtual TokenIndex LeftToken() { return left_hand_side -> LeftToken(); }
RightToken()4311 virtual TokenIndex RightToken() { return expression -> RightToken(); }
4312 };
4313
4314
4315 //
4316 // This Storage pool is similar to dynamic arrays (class Tuple). The
4317 // difference is that instead of a Next() function we have an Alloc(size_t)
4318 // function. The value of the size_t argument represents the size of the
4319 // object to allocate. The allocated memory is guaranteed to be
4320 // zero-initialized.
4321 //
4322 // All AST nodes for a given parse should be allocated from the same storage
4323 // pool, so they have a placement new operator that requires a StoragePool.
4324 // You should never delete an AST object, as all resources they allocate come
4325 // from the same pool. Instead, to reclaim memory when processing is complete,
4326 // simply delete the underlying storage pool.
4327 //
4328 class StoragePool
4329 {
4330 public:
4331 typedef void* Cell;
4332
Blksize()4333 inline size_t Blksize() { return 1U << log_blksize; }
4334
4335 private:
4336 Cell** base;
4337 unsigned base_size; // number of segment slots in base
4338 unsigned base_index; // index of current non-full segment
4339 unsigned offset; // offset to next free pointer in base[base_index]
4340
4341 unsigned log_blksize; // log2(words per segment)
4342 unsigned base_increment; // number of segment slots to add when growing
4343
4344 //
4345 // Allocate another block of storage for the storage pool. block_size
4346 // allows the creation of larger than normal segments, which are rare,
4347 // but are sometimes requested by AstArray.
4348 //
4349 void AllocateMoreSpace(size_t block_size = 0)
4350 {
4351 //
4352 // This advances base_index to the next slot unless this is the first
4353 // allocation. Then it allocates a segment to live in that slot.
4354 // The offset field should only be 0 after construction or after a
4355 // reset, when base_index should stay at 0. All other times, offset
4356 // is nonzero, so we allocate advance base_index.
4357 //
4358 assert(offset ? base != NULL : ! base_index);
4359 if (offset)
4360 base_index++;
4361 if (base_index == base_size)
4362 {
4363 unsigned old_base_size = base_size;
4364 Cell** old_base = base;
4365 base_size += base_increment;
4366 base = new Cell*[base_size];
4367 if (old_base)
4368 {
4369 memcpy(base, old_base, old_base_size * sizeof(Cell*));
4370 delete [] old_base;
4371 }
4372 memset(base + old_base_size, 0, base_increment * sizeof(Cell*));
4373 }
4374 if (block_size)
4375 {
4376 assert(block_size > Blksize());
4377 delete [] base[base_index];
4378 base[base_index] = new Cell[block_size];
4379 }
4380 else if (! base[base_index])
4381 {
4382 block_size = Blksize();
4383 base[base_index] = new Cell[block_size];
4384 }
4385 memset(base[base_index], 0, block_size * sizeof(Cell));
4386 }
4387
4388 public:
4389 //
4390 // Constructor of a storage pool. The parameter is the number of tokens
4391 // which the AST tree will contain.
4392 //
StoragePool(unsigned num_tokens)4393 StoragePool(unsigned num_tokens)
4394 : base(NULL)
4395 , base_size(0)
4396 , base_index(0)
4397 , offset(0)
4398 {
4399 //
4400 // Make a guess on the size that will be required for the ast
4401 // based on the number of tokens. On average, we have about 1 node
4402 // to 2 tokens, but about 10 words (40 bytes) per node. We add some
4403 // fudge factor to avoid reallocations, resulting in num_tokens * 8.
4404 //
4405 unsigned estimate = num_tokens << 3;
4406
4407 //
4408 // Find a block of size 2**log_blksize that is large enough
4409 // to satisfy our estimate.
4410 //
4411 for (log_blksize = 8;
4412 (1U << log_blksize) < estimate && log_blksize < 31;
4413 log_blksize++)
4414 ;
4415
4416 if (log_blksize < 13) // estimate is < 2**(13+2) == 32k
4417 {
4418 base_increment = 1U << (log_blksize - 8);
4419 log_blksize = 8; // fragment in 2**(8+2) == 1k chunks
4420 }
4421 else if (log_blksize < 17) // estimate is < 2**(17+2) == 512k
4422 {
4423 base_increment = 1U << (log_blksize - 10);
4424 log_blksize = 10; // fragment in 2**(10+2) == 4k chunks
4425 }
4426 else // estimate is >= 512k, which is rare
4427 {
4428 base_increment = 1U << (log_blksize - 12);
4429 log_blksize = 12; // fragment in 2**(12+2) == 16k chunks
4430 }
4431
4432 //
4433 // Double the size of the base and add an extra margin to avoid
4434 // reallocating the base, especially for things like Cloning.
4435 //
4436 base_increment += base_increment + 3;
4437 }
4438
4439 //
4440 // Destructor of a storage pool. This frees the memory of all of the AST
4441 // nodes allocated in this pool.
4442 //
~StoragePool()4443 ~StoragePool()
4444 {
4445 if (base)
4446 for (unsigned i = 0; i <= base_index; i++)
4447 delete [] base[i];
4448 delete [] base;
4449 }
4450
4451 //
4452 // Alloc allocates an object of size n in the pool and returns a pointer
4453 // to it. The memory will be zero-initialized.
4454 //
Alloc(size_t n)4455 inline void* Alloc(size_t n)
4456 {
4457 unsigned chunk_size = (n + sizeof(Cell) - 1) / sizeof(Cell);
4458 if (chunk_size > Blksize())
4459 {
4460 //
4461 // Handle large requests separately. These are rare, when an
4462 // AstArray is requested that is larger than a segment. In this
4463 // case, we allocate the extra large segment in the next free
4464 // slot, and swap it with the previous segment if that one still
4465 // had room.
4466 //
4467 AllocateMoreSpace(chunk_size);
4468 Cell result = base[base_index];
4469 if (base_index)
4470 {
4471 Cell* temp = base[base_index];
4472 base[base_index] = base[base_index - 1];
4473 base[base_index - 1] = temp;
4474 }
4475 return result;
4476 }
4477 if (! base || offset + chunk_size > Blksize())
4478 {
4479 //
4480 // Here, we overflow the current segment, but fit in a normal
4481 // next segment.
4482 //
4483 AllocateMoreSpace();
4484 offset = 0;
4485 }
4486 Cell result = base[base_index] + offset;
4487 offset += chunk_size;
4488 return result;
4489 }
4490
4491 //
4492 // This function is used to reset the Storage pool. This action
4493 // automatically invalidates all objects that had been allocated in the
4494 // pool. At least, YOU should assume it does!!!
4495 //
Reset()4496 inline void Reset()
4497 {
4498 base_index = 0;
4499 offset = 0;
4500 }
4501
4502 // ********************************************************************
4503
4504 inline VariableSymbolArray* NewVariableSymbolArray(unsigned size = 0)
4505 {
4506 return new (Alloc(sizeof(VariableSymbolArray)))
4507 VariableSymbolArray(this, size);
4508 }
4509
NewListNode()4510 inline AstListNode* NewListNode()
4511 {
4512 return new (this) AstListNode();
4513 }
4514
NewBlock()4515 inline AstBlock* NewBlock()
4516 {
4517 return new (this) AstBlock(this);
4518 }
4519
NewName(TokenIndex token)4520 inline AstName* NewName(TokenIndex token)
4521 {
4522 return new (this) AstName(token);
4523 }
4524
NewPrimitiveType(Ast::AstKind kind,TokenIndex t)4525 inline AstPrimitiveType* NewPrimitiveType(Ast::AstKind kind, TokenIndex t)
4526 {
4527 return new (this) AstPrimitiveType(kind, t);
4528 }
4529
NewBrackets(TokenIndex left,TokenIndex right)4530 inline AstBrackets* NewBrackets(TokenIndex left, TokenIndex right)
4531 {
4532 return new (this) AstBrackets(left, right);
4533 }
4534
NewArrayType(AstType * type,AstBrackets * brackets)4535 inline AstArrayType* NewArrayType(AstType* type, AstBrackets* brackets)
4536 {
4537 return new (this) AstArrayType(type, brackets);
4538 }
4539
NewWildcard(TokenIndex question)4540 inline AstWildcard* NewWildcard(TokenIndex question)
4541 {
4542 return new (this) AstWildcard(question);
4543 }
4544
NewTypeArguments(TokenIndex l,TokenIndex r)4545 inline AstTypeArguments* NewTypeArguments(TokenIndex l, TokenIndex r)
4546 {
4547 return new (this) AstTypeArguments(this, l, r);
4548 }
4549
NewTypeName(AstName * name)4550 inline AstTypeName* NewTypeName(AstName* name)
4551 {
4552 return new (this) AstTypeName(name);
4553 }
4554
NewMemberValuePair()4555 inline AstMemberValuePair* NewMemberValuePair()
4556 {
4557 return new (this) AstMemberValuePair();
4558 }
4559
NewAnnotation()4560 inline AstAnnotation* NewAnnotation()
4561 {
4562 return new (this) AstAnnotation(this);
4563 }
4564
NewModifierKeyword(TokenIndex token)4565 inline AstModifierKeyword* NewModifierKeyword(TokenIndex token)
4566 {
4567 return new (this) AstModifierKeyword(token);
4568 }
4569
NewModifiers()4570 inline AstModifiers* NewModifiers()
4571 {
4572 return new (this) AstModifiers(this);
4573 }
4574
NewPackageDeclaration()4575 inline AstPackageDeclaration* NewPackageDeclaration()
4576 {
4577 return new (this) AstPackageDeclaration();
4578 }
4579
NewImportDeclaration()4580 inline AstImportDeclaration* NewImportDeclaration()
4581 {
4582 return new (this) AstImportDeclaration();
4583 }
4584
NewCompilationUnit()4585 inline AstCompilationUnit* NewCompilationUnit()
4586 {
4587 return new (this) AstCompilationUnit(this);
4588 }
4589
NewEmptyDeclaration(TokenIndex t)4590 inline AstEmptyDeclaration* NewEmptyDeclaration(TokenIndex t)
4591 {
4592 return new (this) AstEmptyDeclaration(t);
4593 }
4594
NewClassBody()4595 inline AstClassBody* NewClassBody()
4596 {
4597 return new (this) AstClassBody(this);
4598 }
4599
NewTypeParameter(TokenIndex token)4600 inline AstTypeParameter* NewTypeParameter(TokenIndex token)
4601 {
4602 return new (this) AstTypeParameter(this, token);
4603 }
4604
NewTypeParameters()4605 inline AstTypeParameters* NewTypeParameters()
4606 {
4607 return new (this) AstTypeParameters(this);
4608 }
4609
NewClassDeclaration()4610 inline AstClassDeclaration* NewClassDeclaration()
4611 {
4612 return new (this) AstClassDeclaration(this);
4613 }
4614
NewArrayInitializer()4615 inline AstArrayInitializer* NewArrayInitializer()
4616 {
4617 return new (this) AstArrayInitializer(this);
4618 }
4619
NewVariableDeclaratorId()4620 inline AstVariableDeclaratorId* NewVariableDeclaratorId()
4621 {
4622 return new (this) AstVariableDeclaratorId();
4623 }
4624
NewVariableDeclarator()4625 inline AstVariableDeclarator* NewVariableDeclarator()
4626 {
4627 return new (this) AstVariableDeclarator();
4628 }
4629
NewFieldDeclaration()4630 inline AstFieldDeclaration* NewFieldDeclaration()
4631 {
4632 return new (this) AstFieldDeclaration(this);
4633 }
4634
NewFormalParameter()4635 inline AstFormalParameter* NewFormalParameter()
4636 {
4637 return new (this) AstFormalParameter();
4638 }
4639
NewMethodDeclarator()4640 inline AstMethodDeclarator* NewMethodDeclarator()
4641 {
4642 return new (this) AstMethodDeclarator(this);
4643 }
4644
NewMethodBody()4645 inline AstMethodBody* NewMethodBody()
4646 {
4647 return new (this) AstMethodBody(this);
4648 }
4649
NewMethodDeclaration()4650 inline AstMethodDeclaration* NewMethodDeclaration()
4651 {
4652 return new (this) AstMethodDeclaration(this);
4653 }
4654
NewInitializerDeclaration()4655 inline AstInitializerDeclaration* NewInitializerDeclaration()
4656 {
4657 return new (this) AstInitializerDeclaration();
4658 }
4659
NewArguments(TokenIndex left,TokenIndex right)4660 inline AstArguments* NewArguments(TokenIndex left, TokenIndex right)
4661 {
4662 return new (this) AstArguments(this, left, right);
4663 }
4664
NewThisCall()4665 inline AstThisCall* NewThisCall()
4666 {
4667 return new (this) AstThisCall();
4668 }
4669
NewSuperCall()4670 inline AstSuperCall* NewSuperCall()
4671 {
4672 return new (this) AstSuperCall();
4673 }
4674
NewConstructorDeclaration()4675 inline AstConstructorDeclaration* NewConstructorDeclaration()
4676 {
4677 return new (this) AstConstructorDeclaration(this);
4678 }
4679
NewEnumDeclaration()4680 inline AstEnumDeclaration* NewEnumDeclaration()
4681 {
4682 return new (this) AstEnumDeclaration(this);
4683 }
4684
NewEnumConstant(TokenIndex t)4685 inline AstEnumConstant* NewEnumConstant(TokenIndex t)
4686 {
4687 return new (this) AstEnumConstant(t);
4688 }
4689
NewInterfaceDeclaration()4690 inline AstInterfaceDeclaration* NewInterfaceDeclaration()
4691 {
4692 return new (this) AstInterfaceDeclaration(this);
4693 }
4694
NewAnnotationDeclaration(TokenIndex t)4695 inline AstAnnotationDeclaration* NewAnnotationDeclaration(TokenIndex t)
4696 {
4697 return new (this) AstAnnotationDeclaration(t);
4698 }
4699
NewLocalVariableStatement()4700 inline AstLocalVariableStatement* NewLocalVariableStatement()
4701 {
4702 return new (this) AstLocalVariableStatement(this);
4703 }
4704
NewLocalClassStatement(AstClassDeclaration * decl)4705 inline AstLocalClassStatement* NewLocalClassStatement(AstClassDeclaration* decl)
4706 {
4707 return new (this) AstLocalClassStatement(decl);
4708 }
4709
NewLocalClassStatement(AstEnumDeclaration * decl)4710 inline AstLocalClassStatement* NewLocalClassStatement(AstEnumDeclaration* decl)
4711 {
4712 return new (this) AstLocalClassStatement(decl);
4713 }
4714
NewIfStatement()4715 inline AstIfStatement* NewIfStatement()
4716 {
4717 return new (this) AstIfStatement();
4718 }
4719
NewEmptyStatement(TokenIndex token)4720 inline AstEmptyStatement* NewEmptyStatement(TokenIndex token)
4721 {
4722 return new (this) AstEmptyStatement(token);
4723 }
4724
NewExpressionStatement()4725 inline AstExpressionStatement* NewExpressionStatement()
4726 {
4727 return new (this) AstExpressionStatement();
4728 }
4729
NewSwitchLabel()4730 inline AstSwitchLabel* NewSwitchLabel()
4731 {
4732 return new (this) AstSwitchLabel();
4733 }
4734
NewSwitchBlockStatement()4735 inline AstSwitchBlockStatement* NewSwitchBlockStatement()
4736 {
4737 return new (this) AstSwitchBlockStatement(this);
4738 }
4739
NewSwitchStatement()4740 inline AstSwitchStatement* NewSwitchStatement()
4741 {
4742 return new (this) AstSwitchStatement(this);
4743 }
4744
NewWhileStatement()4745 inline AstWhileStatement* NewWhileStatement()
4746 {
4747 return new (this) AstWhileStatement();
4748 }
4749
NewDoStatement()4750 inline AstDoStatement* NewDoStatement()
4751 {
4752 return new (this) AstDoStatement();
4753 }
4754
NewForStatement()4755 inline AstForStatement* NewForStatement()
4756 {
4757 return new (this) AstForStatement(this);
4758 }
4759
NewForeachStatement()4760 inline AstForeachStatement* NewForeachStatement()
4761 {
4762 return new (this) AstForeachStatement();
4763 }
4764
NewBreakStatement()4765 inline AstBreakStatement* NewBreakStatement()
4766 {
4767 return new (this) AstBreakStatement();
4768 }
4769
NewContinueStatement()4770 inline AstContinueStatement* NewContinueStatement()
4771 {
4772 return new (this) AstContinueStatement();
4773 }
4774
NewReturnStatement()4775 inline AstReturnStatement* NewReturnStatement()
4776 {
4777 return new (this) AstReturnStatement();
4778 }
4779
NewThrowStatement()4780 inline AstThrowStatement* NewThrowStatement()
4781 {
4782 return new (this) AstThrowStatement();
4783 }
4784
NewSynchronizedStatement()4785 inline AstSynchronizedStatement* NewSynchronizedStatement()
4786 {
4787 return new (this) AstSynchronizedStatement();
4788 }
4789
NewAssertStatement()4790 inline AstAssertStatement* NewAssertStatement()
4791 {
4792 return new (this) AstAssertStatement();
4793 }
4794
NewCatchClause()4795 inline AstCatchClause* NewCatchClause()
4796 {
4797 return new (this) AstCatchClause();
4798 }
4799
NewFinallyClause()4800 inline AstFinallyClause* NewFinallyClause()
4801 {
4802 return new (this) AstFinallyClause();
4803 }
4804
NewTryStatement()4805 inline AstTryStatement* NewTryStatement()
4806 {
4807 return new (this) AstTryStatement(this);
4808 }
4809
NewIntegerLiteral(TokenIndex token)4810 inline AstIntegerLiteral* NewIntegerLiteral(TokenIndex token)
4811 {
4812 return new (this) AstIntegerLiteral(token);
4813 }
4814
NewLongLiteral(TokenIndex token)4815 inline AstLongLiteral* NewLongLiteral(TokenIndex token)
4816 {
4817 return new (this) AstLongLiteral(token);
4818 }
4819
NewFloatLiteral(TokenIndex token)4820 inline AstFloatLiteral* NewFloatLiteral(TokenIndex token)
4821 {
4822 return new (this) AstFloatLiteral(token);
4823 }
4824
NewDoubleLiteral(TokenIndex token)4825 inline AstDoubleLiteral* NewDoubleLiteral(TokenIndex token)
4826 {
4827 return new (this) AstDoubleLiteral(token);
4828 }
4829
NewTrueLiteral(TokenIndex token)4830 inline AstTrueLiteral* NewTrueLiteral(TokenIndex token)
4831 {
4832 return new (this) AstTrueLiteral(token);
4833 }
4834
NewFalseLiteral(TokenIndex token)4835 inline AstFalseLiteral* NewFalseLiteral(TokenIndex token)
4836 {
4837 return new (this) AstFalseLiteral(token);
4838 }
4839
NewStringLiteral(TokenIndex token)4840 inline AstStringLiteral* NewStringLiteral(TokenIndex token)
4841 {
4842 return new (this) AstStringLiteral(token);
4843 }
4844
NewCharacterLiteral(TokenIndex token)4845 inline AstCharacterLiteral* NewCharacterLiteral(TokenIndex token)
4846 {
4847 return new (this) AstCharacterLiteral(token);
4848 }
4849
NewNullLiteral(TokenIndex token)4850 inline AstNullLiteral* NewNullLiteral(TokenIndex token)
4851 {
4852 return new (this) AstNullLiteral(token);
4853 }
4854
NewClassLiteral(TokenIndex token)4855 inline AstClassLiteral* NewClassLiteral(TokenIndex token)
4856 {
4857 return new (this) AstClassLiteral(token);
4858 }
4859
NewThisExpression(TokenIndex token)4860 inline AstThisExpression* NewThisExpression(TokenIndex token)
4861 {
4862 return new (this) AstThisExpression(token);
4863 }
4864
NewSuperExpression(TokenIndex token)4865 inline AstSuperExpression* NewSuperExpression(TokenIndex token)
4866 {
4867 return new (this) AstSuperExpression(token);
4868 }
4869
NewParenthesizedExpression()4870 inline AstParenthesizedExpression* NewParenthesizedExpression()
4871 {
4872 return new (this) AstParenthesizedExpression();
4873 }
4874
NewClassCreationExpression()4875 inline AstClassCreationExpression* NewClassCreationExpression()
4876 {
4877 return new (this) AstClassCreationExpression();
4878 }
4879
NewDimExpr()4880 inline AstDimExpr* NewDimExpr()
4881 {
4882 return new (this) AstDimExpr();
4883 }
4884
NewArrayCreationExpression()4885 inline AstArrayCreationExpression* NewArrayCreationExpression()
4886 {
4887 return new (this) AstArrayCreationExpression(this);
4888 }
4889
NewFieldAccess()4890 inline AstFieldAccess* NewFieldAccess()
4891 {
4892 return new (this) AstFieldAccess();
4893 }
4894
NewMethodInvocation(TokenIndex t)4895 inline AstMethodInvocation* NewMethodInvocation(TokenIndex t)
4896 {
4897 return new (this) AstMethodInvocation(t);
4898 }
4899
NewArrayAccess()4900 inline AstArrayAccess* NewArrayAccess()
4901 {
4902 return new (this) AstArrayAccess();
4903 }
4904
NewPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)4905 inline AstPostUnaryExpression* NewPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)
4906 {
4907 return new (this) AstPostUnaryExpression(tag);
4908 }
4909
NewPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)4910 inline AstPreUnaryExpression* NewPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)
4911 {
4912 return new (this) AstPreUnaryExpression(tag);
4913 }
4914
NewCastExpression()4915 inline AstCastExpression* NewCastExpression()
4916 {
4917 return new (this) AstCastExpression();
4918 }
4919
NewBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)4920 inline AstBinaryExpression* NewBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)
4921 {
4922 return new (this) AstBinaryExpression(tag);
4923 }
4924
NewInstanceofExpression()4925 inline AstInstanceofExpression* NewInstanceofExpression()
4926 {
4927 return new (this) AstInstanceofExpression();
4928 }
4929
NewConditionalExpression()4930 inline AstConditionalExpression* NewConditionalExpression()
4931 {
4932 return new (this) AstConditionalExpression();
4933 }
4934
NewAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag,TokenIndex token)4935 inline AstAssignmentExpression* NewAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag,
4936 TokenIndex token)
4937 {
4938 return new (this) AstAssignmentExpression(tag, token);
4939 }
4940
4941 // *********************************************************************
4942
4943 //
4944 // Note that CaseElement nodes are always generated. Since they are not
4945 // Ast nodes they do not need to be marked.
4946 //
GenCaseElement(unsigned block_index,unsigned case_index)4947 inline CaseElement* GenCaseElement(unsigned block_index,
4948 unsigned case_index)
4949 {
4950 CaseElement* p = new (Alloc(sizeof(CaseElement))) CaseElement();
4951 p -> block_index = block_index;
4952 p -> case_index = case_index;
4953 return p;
4954 }
4955
GenBlock()4956 inline AstBlock* GenBlock()
4957 {
4958 AstBlock* p = NewBlock();
4959 p -> generated = true;
4960 p -> no_braces = true;
4961 return p;
4962 }
4963
GenName(TokenIndex token)4964 inline AstName* GenName(TokenIndex token)
4965 {
4966 AstName* p = NewName(token);
4967 p -> generated = true;
4968 return p;
4969 }
4970
GenPrimitiveType(Ast::AstKind kind,TokenIndex t)4971 inline AstPrimitiveType* GenPrimitiveType(Ast::AstKind kind, TokenIndex t)
4972 {
4973 AstPrimitiveType* p = NewPrimitiveType(kind, t);
4974 p -> generated = true;
4975 return p;
4976 }
4977
GenBrackets(TokenIndex left,TokenIndex right)4978 inline AstBrackets* GenBrackets(TokenIndex left, TokenIndex right)
4979 {
4980 AstBrackets* p = NewBrackets(left, right);
4981 p -> generated = true;
4982 return p;
4983 }
4984
GenArrayType(AstType * type,AstBrackets * brackets)4985 inline AstArrayType* GenArrayType(AstType* type, AstBrackets* brackets)
4986 {
4987 AstArrayType* p = NewArrayType(type, brackets);
4988 p -> generated = true;
4989 return p;
4990 }
4991
GenWildcard(TokenIndex question)4992 inline AstWildcard* GenWildcard(TokenIndex question)
4993 {
4994 AstWildcard* p = NewWildcard(question);
4995 p -> generated = true;
4996 return p;
4997 }
4998
GenTypeArguments(TokenIndex l,TokenIndex r)4999 inline AstTypeArguments* GenTypeArguments(TokenIndex l, TokenIndex r)
5000 {
5001 AstTypeArguments* p = NewTypeArguments(l, r);
5002 p -> generated = true;
5003 return p;
5004 }
5005
GenTypeName(AstName * type)5006 inline AstTypeName* GenTypeName(AstName* type)
5007 {
5008 AstTypeName* p = NewTypeName(type);
5009 p -> generated = true;
5010 return p;
5011 }
5012
GenMemberValuePair()5013 inline AstMemberValuePair* GenMemberValuePair()
5014 {
5015 AstMemberValuePair* p = NewMemberValuePair();
5016 p -> generated = true;
5017 return p;
5018 }
5019
GenAnnotation()5020 inline AstAnnotation* GenAnnotation()
5021 {
5022 AstAnnotation* p = NewAnnotation();
5023 p -> generated = true;
5024 return p;
5025 }
5026
GenModifierKeyword(TokenIndex token)5027 inline AstModifierKeyword* GenModifierKeyword(TokenIndex token)
5028 {
5029 AstModifierKeyword* p = NewModifierKeyword(token);
5030 p -> generated = true;
5031 return p;
5032 }
5033
GenModifiers()5034 inline AstModifiers* GenModifiers()
5035 {
5036 AstModifiers* p = NewModifiers();
5037 p -> generated = true;
5038 return p;
5039 }
5040
GenPackageDeclaration()5041 inline AstPackageDeclaration* GenPackageDeclaration()
5042 {
5043 AstPackageDeclaration* p = NewPackageDeclaration();
5044 p -> generated = true;
5045 return p;
5046 }
5047
GenImportDeclaration()5048 inline AstImportDeclaration* GenImportDeclaration()
5049 {
5050 AstImportDeclaration* p = NewImportDeclaration();
5051 p -> generated = true;
5052 return p;
5053 }
5054
GenCompilationUnit()5055 inline AstCompilationUnit* GenCompilationUnit()
5056 {
5057 AstCompilationUnit* p = NewCompilationUnit();
5058 p -> generated = true;
5059 return p;
5060 }
5061
GenEmptyDeclaration(TokenIndex t)5062 inline AstEmptyDeclaration* GenEmptyDeclaration(TokenIndex t)
5063 {
5064 AstEmptyDeclaration* p = NewEmptyDeclaration(t);
5065 p -> generated = true;
5066 return p;
5067 }
5068
GenClassBody()5069 inline AstClassBody* GenClassBody()
5070 {
5071 AstClassBody* p = NewClassBody();
5072 p -> generated = true;
5073 return p;
5074 }
5075
GenTypeParameter(TokenIndex token)5076 inline AstTypeParameter* GenTypeParameter(TokenIndex token)
5077 {
5078 AstTypeParameter* p = NewTypeParameter(token);
5079 p -> generated = true;
5080 return p;
5081 }
5082
GenTypeParameters()5083 inline AstTypeParameters* GenTypeParameters()
5084 {
5085 AstTypeParameters* p = NewTypeParameters();
5086 p -> generated = true;
5087 return p;
5088 }
5089
GenClassDeclaration()5090 inline AstClassDeclaration* GenClassDeclaration()
5091 {
5092 AstClassDeclaration* p = NewClassDeclaration();
5093 p -> generated = true;
5094 return p;
5095 }
5096
GenArrayInitializer()5097 inline AstArrayInitializer* GenArrayInitializer()
5098 {
5099 AstArrayInitializer* p = NewArrayInitializer();
5100 p -> generated = true;
5101 return p;
5102 }
5103
GenVariableDeclaratorId()5104 inline AstVariableDeclaratorId* GenVariableDeclaratorId()
5105 {
5106 AstVariableDeclaratorId* p = NewVariableDeclaratorId();
5107 p -> generated = true;
5108 return p;
5109 }
5110
GenVariableDeclarator()5111 inline AstVariableDeclarator* GenVariableDeclarator()
5112 {
5113 AstVariableDeclarator* p = NewVariableDeclarator();
5114 p -> generated = true;
5115 return p;
5116 }
5117
GenFieldDeclaration()5118 inline AstFieldDeclaration* GenFieldDeclaration()
5119 {
5120 AstFieldDeclaration* p = NewFieldDeclaration();
5121 p -> generated = true;
5122 return p;
5123 }
5124
GenFormalParameter()5125 inline AstFormalParameter* GenFormalParameter()
5126 {
5127 AstFormalParameter* p = NewFormalParameter();
5128 p -> generated = true;
5129 return p;
5130 }
5131
GenMethodDeclarator()5132 inline AstMethodDeclarator* GenMethodDeclarator()
5133 {
5134 AstMethodDeclarator* p = NewMethodDeclarator();
5135 p -> generated = true;
5136 return p;
5137 }
5138
GenMethodBody()5139 inline AstMethodBody* GenMethodBody()
5140 {
5141 AstMethodBody* p = NewMethodBody();
5142 p -> generated = true;
5143 return p;
5144 }
5145
GenMethodDeclaration()5146 inline AstMethodDeclaration* GenMethodDeclaration()
5147 {
5148 AstMethodDeclaration* p = NewMethodDeclaration();
5149 p -> generated = true;
5150 return p;
5151 }
5152
GenInitializerDeclaration()5153 inline AstInitializerDeclaration* GenInitializerDeclaration()
5154 {
5155 AstInitializerDeclaration* p = NewInitializerDeclaration();
5156 p -> generated = true;
5157 return p;
5158 }
5159
GenArguments(TokenIndex left,TokenIndex right)5160 inline AstArguments* GenArguments(TokenIndex left, TokenIndex right)
5161 {
5162 AstArguments* p = NewArguments(left, right);
5163 p -> generated = true;
5164 return p;
5165 }
5166
GenThisCall()5167 inline AstThisCall* GenThisCall()
5168 {
5169 AstThisCall* p = NewThisCall();
5170 p -> generated = true;
5171 return p;
5172 }
5173
GenSuperCall()5174 inline AstSuperCall* GenSuperCall()
5175 {
5176 AstSuperCall* p = NewSuperCall();
5177 p -> generated = true;
5178 return p;
5179 }
5180
GenConstructorDeclaration()5181 inline AstConstructorDeclaration* GenConstructorDeclaration()
5182 {
5183 AstConstructorDeclaration* p = NewConstructorDeclaration();
5184 p -> generated = true;
5185 return p;
5186 }
5187
GenEnumDeclaration()5188 inline AstEnumDeclaration* GenEnumDeclaration()
5189 {
5190 AstEnumDeclaration* p = NewEnumDeclaration();
5191 p -> generated = true;
5192 return p;
5193 }
5194
GenEnumConstant(TokenIndex t)5195 inline AstEnumConstant* GenEnumConstant(TokenIndex t)
5196 {
5197 AstEnumConstant* p = NewEnumConstant(t);
5198 p -> generated = true;
5199 return p;
5200 }
5201
GenInterfaceDeclaration()5202 inline AstInterfaceDeclaration* GenInterfaceDeclaration()
5203 {
5204 AstInterfaceDeclaration* p = NewInterfaceDeclaration();
5205 p -> generated = true;
5206 return p;
5207 }
5208
GenAnnotationDeclaration(TokenIndex t)5209 inline AstAnnotationDeclaration* GenAnnotationDeclaration(TokenIndex t)
5210 {
5211 AstAnnotationDeclaration* p = NewAnnotationDeclaration(t);
5212 p -> generated = true;
5213 return p;
5214 }
5215
GenLocalVariableStatement()5216 inline AstLocalVariableStatement* GenLocalVariableStatement()
5217 {
5218 AstLocalVariableStatement* p = NewLocalVariableStatement();
5219 p -> generated = true;
5220 return p;
5221 }
5222
GenLocalClassStatement(AstClassDeclaration * decl)5223 inline AstLocalClassStatement* GenLocalClassStatement(AstClassDeclaration* decl)
5224 {
5225 AstLocalClassStatement* p = NewLocalClassStatement(decl);
5226 p -> generated = true;
5227 return p;
5228 }
5229
GenLocalClassStatement(AstEnumDeclaration * decl)5230 inline AstLocalClassStatement* GenLocalClassStatement(AstEnumDeclaration* decl)
5231 {
5232 AstLocalClassStatement* p = NewLocalClassStatement(decl);
5233 p -> generated = true;
5234 return p;
5235 }
5236
GenIfStatement()5237 inline AstIfStatement* GenIfStatement()
5238 {
5239 AstIfStatement* p = NewIfStatement();
5240 p -> generated = true;
5241 return p;
5242 }
5243
GenEmptyStatement(TokenIndex token)5244 inline AstEmptyStatement* GenEmptyStatement(TokenIndex token)
5245 {
5246 AstEmptyStatement* p = NewEmptyStatement(token);
5247 p -> generated = true;
5248 return p;
5249 }
5250
GenExpressionStatement()5251 inline AstExpressionStatement* GenExpressionStatement()
5252 {
5253 AstExpressionStatement* p = NewExpressionStatement();
5254 p -> generated = true;
5255 return p;
5256 }
5257
GenSwitchLabel()5258 inline AstSwitchLabel* GenSwitchLabel()
5259 {
5260 AstSwitchLabel* p = NewSwitchLabel();
5261 p -> generated = true;
5262 return p;
5263 }
5264
GenSwitchBlockStatement()5265 inline AstSwitchBlockStatement* GenSwitchBlockStatement()
5266 {
5267 AstSwitchBlockStatement* p = NewSwitchBlockStatement();
5268 p -> generated = true;
5269 return p;
5270 }
5271
GenSwitchStatement()5272 inline AstSwitchStatement* GenSwitchStatement()
5273 {
5274 AstSwitchStatement* p = NewSwitchStatement();
5275 p -> generated = true;
5276 return p;
5277 }
5278
GenWhileStatement()5279 inline AstWhileStatement* GenWhileStatement()
5280 {
5281 AstWhileStatement* p = NewWhileStatement();
5282 p -> generated = true;
5283 return p;
5284 }
5285
GenDoStatement()5286 inline AstDoStatement* GenDoStatement()
5287 {
5288 AstDoStatement* p = NewDoStatement();
5289 p -> generated = true;
5290 return p;
5291 }
5292
GenForStatement()5293 inline AstForStatement* GenForStatement()
5294 {
5295 AstForStatement* p = NewForStatement();
5296 p -> generated = true;
5297 return p;
5298 }
5299
GenForeachStatement()5300 inline AstForeachStatement* GenForeachStatement()
5301 {
5302 AstForeachStatement* p = NewForeachStatement();
5303 p -> generated = true;
5304 return p;
5305 }
5306
GenBreakStatement()5307 inline AstBreakStatement* GenBreakStatement()
5308 {
5309 AstBreakStatement* p = NewBreakStatement();
5310 p -> generated = true;
5311 return p;
5312 }
5313
GenContinueStatement()5314 inline AstContinueStatement* GenContinueStatement()
5315 {
5316 AstContinueStatement* p = NewContinueStatement();
5317 p -> generated = true;
5318 return p;
5319 }
5320
GenReturnStatement()5321 inline AstReturnStatement* GenReturnStatement()
5322 {
5323 AstReturnStatement* p = NewReturnStatement();
5324 p -> generated = true;
5325 return p;
5326 }
5327
GenThrowStatement()5328 inline AstThrowStatement* GenThrowStatement()
5329 {
5330 AstThrowStatement* p = NewThrowStatement();
5331 p -> generated = true;
5332 return p;
5333 }
5334
GenSynchronizedStatement()5335 inline AstSynchronizedStatement* GenSynchronizedStatement()
5336 {
5337 AstSynchronizedStatement* p = NewSynchronizedStatement();
5338 p -> generated = true;
5339 return p;
5340 }
5341
GenAssertStatement()5342 inline AstAssertStatement* GenAssertStatement()
5343 {
5344 AstAssertStatement* p = NewAssertStatement();
5345 p -> generated = true;
5346 return p;
5347 }
5348
GenCatchClause()5349 inline AstCatchClause* GenCatchClause()
5350 {
5351 AstCatchClause* p = NewCatchClause();
5352 p -> generated = true;
5353 return p;
5354 }
5355
GenFinallyClause()5356 inline AstFinallyClause* GenFinallyClause()
5357 {
5358 AstFinallyClause* p = NewFinallyClause();
5359 p -> generated = true;
5360 return p;
5361 }
5362
GenTryStatement()5363 inline AstTryStatement* GenTryStatement()
5364 {
5365 AstTryStatement* p = NewTryStatement();
5366 p -> generated = true;
5367 return p;
5368 }
5369
GenIntegerLiteral(TokenIndex token)5370 inline AstIntegerLiteral* GenIntegerLiteral(TokenIndex token)
5371 {
5372 AstIntegerLiteral* p = NewIntegerLiteral(token);
5373 p -> generated = true;
5374 return p;
5375 }
5376
GenLongLiteral(TokenIndex token)5377 inline AstLongLiteral* GenLongLiteral(TokenIndex token)
5378 {
5379 AstLongLiteral* p = NewLongLiteral(token);
5380 p -> generated = true;
5381 return p;
5382 }
5383
GenFloatLiteral(TokenIndex token)5384 inline AstFloatLiteral* GenFloatLiteral(TokenIndex token)
5385 {
5386 AstFloatLiteral* p = NewFloatLiteral(token);
5387 p -> generated = true;
5388 return p;
5389 }
5390
GenDoubleLiteral(TokenIndex token)5391 inline AstDoubleLiteral* GenDoubleLiteral(TokenIndex token)
5392 {
5393 AstDoubleLiteral* p = NewDoubleLiteral(token);
5394 p -> generated = true;
5395 return p;
5396 }
5397
GenTrueLiteral(TokenIndex token)5398 inline AstTrueLiteral* GenTrueLiteral(TokenIndex token)
5399 {
5400 AstTrueLiteral* p = NewTrueLiteral(token);
5401 p -> generated = true;
5402 return p;
5403 }
5404
GenFalseLiteral(TokenIndex token)5405 inline AstFalseLiteral* GenFalseLiteral(TokenIndex token)
5406 {
5407 AstFalseLiteral* p = NewFalseLiteral(token);
5408 p -> generated = true;
5409 return p;
5410 }
5411
GenStringLiteral(TokenIndex token)5412 inline AstStringLiteral* GenStringLiteral(TokenIndex token)
5413 {
5414 AstStringLiteral* p = NewStringLiteral(token);
5415 p -> generated = true;
5416 return p;
5417 }
5418
GenCharacterLiteral(TokenIndex token)5419 inline AstCharacterLiteral* GenCharacterLiteral(TokenIndex token)
5420 {
5421 AstCharacterLiteral* p = NewCharacterLiteral(token);
5422 p -> generated = true;
5423 return p;
5424 }
5425
GenNullLiteral(TokenIndex token)5426 inline AstNullLiteral* GenNullLiteral(TokenIndex token)
5427 {
5428 AstNullLiteral* p = NewNullLiteral(token);
5429 p -> generated = true;
5430 return p;
5431 }
5432
GenClassLiteral(TokenIndex token)5433 inline AstClassLiteral* GenClassLiteral(TokenIndex token)
5434 {
5435 AstClassLiteral* p = NewClassLiteral(token);
5436 p -> generated = true;
5437 return p;
5438 }
5439
GenThisExpression(TokenIndex token)5440 inline AstThisExpression* GenThisExpression(TokenIndex token)
5441 {
5442 AstThisExpression* p = NewThisExpression(token);
5443 p -> generated = true;
5444 return p;
5445 }
5446
GenSuperExpression(TokenIndex token)5447 inline AstSuperExpression* GenSuperExpression(TokenIndex token)
5448 {
5449 AstSuperExpression* p = NewSuperExpression(token);
5450 p -> generated = true;
5451 return p;
5452 }
5453
GenParenthesizedExpression()5454 inline AstParenthesizedExpression* GenParenthesizedExpression()
5455 {
5456 AstParenthesizedExpression* p = NewParenthesizedExpression();
5457 p -> generated = true;
5458 return p;
5459 }
5460
GenClassCreationExpression()5461 inline AstClassCreationExpression* GenClassCreationExpression()
5462 {
5463 AstClassCreationExpression* p = NewClassCreationExpression();
5464 p -> generated = true;
5465 return p;
5466 }
5467
GenDimExpr()5468 inline AstDimExpr* GenDimExpr()
5469 {
5470 AstDimExpr* p = NewDimExpr();
5471 p -> generated = true;
5472 return p;
5473 }
5474
GenArrayCreationExpression()5475 inline AstArrayCreationExpression* GenArrayCreationExpression()
5476 {
5477 AstArrayCreationExpression* p = NewArrayCreationExpression();
5478 p -> generated = true;
5479 return p;
5480 }
5481
GenFieldAccess()5482 inline AstFieldAccess* GenFieldAccess()
5483 {
5484 AstFieldAccess* p = NewFieldAccess();
5485 p -> generated = true;
5486 return p;
5487 }
5488
GenMethodInvocation(TokenIndex t)5489 inline AstMethodInvocation* GenMethodInvocation(TokenIndex t)
5490 {
5491 AstMethodInvocation* p = NewMethodInvocation(t);
5492 p -> generated = true;
5493 return p;
5494 }
5495
GenArrayAccess()5496 inline AstArrayAccess* GenArrayAccess()
5497 {
5498 AstArrayAccess* p = NewArrayAccess();
5499 p -> generated = true;
5500 return p;
5501 }
5502
GenPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)5503 inline AstPostUnaryExpression* GenPostUnaryExpression(AstPostUnaryExpression::PostUnaryExpressionTag tag)
5504 {
5505 AstPostUnaryExpression* p = NewPostUnaryExpression(tag);
5506 p -> generated = true;
5507 return p;
5508 }
5509
GenPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)5510 inline AstPreUnaryExpression* GenPreUnaryExpression(AstPreUnaryExpression::PreUnaryExpressionTag tag)
5511 {
5512 AstPreUnaryExpression* p = NewPreUnaryExpression(tag);
5513 p -> generated = true;
5514 return p;
5515 }
5516
GenCastExpression()5517 inline AstCastExpression* GenCastExpression()
5518 {
5519 AstCastExpression* p = NewCastExpression();
5520 p -> generated = true;
5521 return p;
5522 }
5523
GenBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)5524 inline AstBinaryExpression* GenBinaryExpression(AstBinaryExpression::BinaryExpressionTag tag)
5525 {
5526 AstBinaryExpression* p = NewBinaryExpression(tag);
5527 p -> generated = true;
5528 return p;
5529 }
5530
GenInstanceofExpression()5531 inline AstInstanceofExpression* GenInstanceofExpression()
5532 {
5533 AstInstanceofExpression* p = NewInstanceofExpression();
5534 p -> generated = true;
5535 return p;
5536 }
5537
GenConditionalExpression()5538 inline AstConditionalExpression* GenConditionalExpression()
5539 {
5540 AstConditionalExpression* p = NewConditionalExpression();
5541 p -> generated = true;
5542 return p;
5543 }
5544
GenAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag,TokenIndex token)5545 inline AstAssignmentExpression* GenAssignmentExpression(AstAssignmentExpression::AssignmentExpressionTag tag,
5546 TokenIndex token)
5547 {
5548 AstAssignmentExpression* p = NewAssignmentExpression(tag, token);
5549 p -> generated = true;
5550 return p;
5551 }
5552 };
5553
5554
5555 //***********************************
5556
5557 //
5558 // Given an Ast tree, check whether it is a variable (not a value).
5559 //
IsLeftHandSide()5560 inline bool Ast::IsLeftHandSide()
5561 {
5562 return kind == NAME || kind == DOT || kind == ARRAY_ACCESS;
5563 }
5564
5565
5566 //
5567 // Given an Ast tree, check whether it is an explicit constructor invocation.
5568 //
IsExplicitConstructorInvocation()5569 inline bool Ast::IsExplicitConstructorInvocation()
5570 {
5571 return kind == THIS_CALL || kind == SUPER_CALL;
5572 }
5573
5574
5575 //
5576 // Given an Ast tree, check whether or not it is generated.
5577 //
IsGenerated()5578 inline bool Ast::IsGenerated()
5579 {
5580 return generated;
5581 }
5582
5583 //
5584 // Cast conversions for Ast
5585 //
5586
StatementCast()5587 inline AstStatement* Ast::StatementCast()
5588 {
5589 return DYNAMIC_CAST<AstStatement*> (class_tag == STATEMENT ? this : NULL);
5590 }
5591
MemberValueCast()5592 inline AstMemberValue* Ast::MemberValueCast()
5593 {
5594 return DYNAMIC_CAST<AstMemberValue*>
5595 ((class_tag == EXPRESSION || kind == ANNOTATION ||
5596 kind == ARRAY_INITIALIZER) ? this : NULL);
5597 }
5598
ExpressionCast()5599 inline AstExpression* Ast::ExpressionCast()
5600 {
5601 return DYNAMIC_CAST<AstExpression*>
5602 (class_tag == EXPRESSION ? this : NULL);
5603 }
5604
PrimitiveTypeCast()5605 inline AstPrimitiveType* Ast::PrimitiveTypeCast()
5606 {
5607 return DYNAMIC_CAST<AstPrimitiveType*>
5608 (class_tag == PRIMITIVE_TYPE ? this : NULL);
5609 }
5610
StaticFieldCast()5611 inline AstFieldDeclaration* Ast::StaticFieldCast()
5612 {
5613 return DYNAMIC_CAST<AstFieldDeclaration*>
5614 (kind == FIELD &&
5615 other_tag == AstFieldDeclaration::STATIC ? this : NULL);
5616 }
5617
StaticInitializerCast()5618 inline AstInitializerDeclaration* Ast::StaticInitializerCast()
5619 {
5620 return DYNAMIC_CAST<AstInitializerDeclaration*>
5621 (kind == INITIALIZER &&
5622 other_tag == AstInitializerDeclaration::STATIC ? this : NULL);
5623 }
5624
UnparsedClassBodyCast()5625 inline AstClassBody* Ast::UnparsedClassBodyCast()
5626 {
5627 return DYNAMIC_CAST<AstClassBody*>
5628 (kind == CLASS_BODY &&
5629 other_tag == AstClassBody::UNPARSED ? this : NULL);
5630 }
5631
BadCompilationUnitCast()5632 inline AstCompilationUnit* Ast::BadCompilationUnitCast()
5633 {
5634 return DYNAMIC_CAST<AstCompilationUnit*>
5635 (kind == COMPILATION &&
5636 other_tag == AstCompilationUnit::BAD_COMPILATION ? this : NULL);
5637 }
5638
EmptyCompilationUnitCast()5639 inline AstCompilationUnit* Ast::EmptyCompilationUnitCast()
5640 {
5641 return DYNAMIC_CAST<AstCompilationUnit*>
5642 (kind == COMPILATION &&
5643 other_tag == AstCompilationUnit::EMPTY_COMPILATION ? this : NULL);
5644 }
5645
5646 //
5647 // These cast functions are used for classes that represent exactly
5648 // one kind of node.
5649 //
5650
ListNodeCast()5651 inline AstListNode* Ast::ListNodeCast()
5652 {
5653 return DYNAMIC_CAST<AstListNode*> (kind == LIST_NODE ? this : NULL);
5654 }
5655
BlockCast()5656 inline AstBlock* Ast::BlockCast()
5657 {
5658 return DYNAMIC_CAST<AstBlock*>
5659 (kind == BLOCK || kind == METHOD_BODY || kind == SWITCH_BLOCK
5660 ? this : NULL);
5661 }
5662
NameCast()5663 inline AstName* Ast::NameCast()
5664 {
5665 return DYNAMIC_CAST<AstName*> (kind == NAME ? this : NULL);
5666 }
5667
BracketsCast()5668 inline AstBrackets* Ast::BracketsCast()
5669 {
5670 return DYNAMIC_CAST<AstBrackets*> (kind == BRACKETS ? this : NULL);
5671 }
5672
ArrayTypeCast()5673 inline AstArrayType* Ast::ArrayTypeCast()
5674 {
5675 return DYNAMIC_CAST<AstArrayType*> (kind == ARRAY ? this : NULL);
5676 }
5677
WildcardCast()5678 inline AstWildcard* Ast::WildcardCast()
5679 {
5680 return DYNAMIC_CAST<AstWildcard*> (kind == WILDCARD ? this : NULL);
5681 }
5682
TypeArgumentsCast()5683 inline AstTypeArguments* Ast::TypeArgumentsCast()
5684 {
5685 return DYNAMIC_CAST<AstTypeArguments*>
5686 (kind == TYPE_ARGUMENTS ? this : NULL);
5687 }
5688
TypeNameCast()5689 inline AstTypeName* Ast::TypeNameCast()
5690 {
5691 return DYNAMIC_CAST<AstTypeName*> (kind == TYPE ? this : NULL);
5692 }
5693
MemberValuePairCast()5694 inline AstMemberValuePair* Ast::MemberValuePairCast()
5695 {
5696 return DYNAMIC_CAST<AstMemberValuePair*>
5697 (kind == MEMBER_VALUE_PAIR ? this : NULL);
5698 }
5699
AnnotationCast()5700 inline AstAnnotation* Ast::AnnotationCast()
5701 {
5702 return DYNAMIC_CAST<AstAnnotation*> (kind == ANNOTATION ? this : NULL);
5703 }
5704
ModifierKeywordCast()5705 inline AstModifierKeyword* Ast::ModifierKeywordCast()
5706 {
5707 return DYNAMIC_CAST<AstModifierKeyword*>
5708 (kind == MODIFIER_KEYWORD ? this : NULL);
5709 }
5710
ModifiersCast()5711 inline AstModifiers* Ast::ModifiersCast()
5712 {
5713 return DYNAMIC_CAST<AstModifiers*> (kind == MODIFIERS ? this : NULL);
5714 }
5715
PackageDeclarationCast()5716 inline AstPackageDeclaration* Ast::PackageDeclarationCast()
5717 {
5718 return DYNAMIC_CAST<AstPackageDeclaration*>
5719 (kind == PACKAGE ? this : NULL);
5720 }
5721
ImportDeclarationCast()5722 inline AstImportDeclaration* Ast::ImportDeclarationCast()
5723 {
5724 return DYNAMIC_CAST<AstImportDeclaration*> (kind == IMPORT ? this : NULL);
5725 }
5726
CompilationUnitCast()5727 inline AstCompilationUnit* Ast::CompilationUnitCast()
5728 {
5729 return DYNAMIC_CAST<AstCompilationUnit*>
5730 (kind == COMPILATION ? this : NULL);
5731 }
5732
EmptyDeclarationCast()5733 inline AstEmptyDeclaration* Ast::EmptyDeclarationCast()
5734 {
5735 return DYNAMIC_CAST<AstEmptyDeclaration*>
5736 (kind == EMPTY_DECLARATION ? this : NULL);
5737 }
5738
ClassBodyCast()5739 inline AstClassBody* Ast::ClassBodyCast()
5740 {
5741 return DYNAMIC_CAST<AstClassBody*> (kind == CLASS_BODY ? this : NULL);
5742 }
5743
TypeParameterCast()5744 inline AstTypeParameter* Ast::TypeParameterCast()
5745 {
5746 return DYNAMIC_CAST<AstTypeParameter*> (kind == TYPE_PARAM ? this : NULL);
5747 }
5748
TypeParametersCast()5749 inline AstTypeParameters* Ast::TypeParametersCast()
5750 {
5751 return DYNAMIC_CAST<AstTypeParameters*> (kind == PARAM_LIST ? this : NULL);
5752 }
5753
ClassDeclarationCast()5754 inline AstClassDeclaration* Ast::ClassDeclarationCast()
5755 {
5756 return DYNAMIC_CAST<AstClassDeclaration*> (kind == CLASS ? this : NULL);
5757 }
5758
ArrayInitializerCast()5759 inline AstArrayInitializer* Ast::ArrayInitializerCast()
5760 {
5761 return DYNAMIC_CAST<AstArrayInitializer*>
5762 (kind == ARRAY_INITIALIZER ? this : NULL);
5763 }
5764
VariableDeclaratorIdCast()5765 inline AstVariableDeclaratorId* Ast::VariableDeclaratorIdCast()
5766 {
5767 return DYNAMIC_CAST<AstVariableDeclaratorId*>
5768 (kind == VARIABLE_DECLARATOR_NAME ? this : NULL);
5769 }
5770
VariableDeclaratorCast()5771 inline AstVariableDeclarator* Ast::VariableDeclaratorCast()
5772 {
5773 return DYNAMIC_CAST<AstVariableDeclarator*>
5774 (kind == VARIABLE_DECLARATOR ? this : NULL);
5775 }
5776
FieldDeclarationCast()5777 inline AstFieldDeclaration* Ast::FieldDeclarationCast()
5778 {
5779 return DYNAMIC_CAST<AstFieldDeclaration*> (kind == FIELD ? this : NULL);
5780 }
5781
FormalParameterCast()5782 inline AstFormalParameter* Ast::FormalParameterCast()
5783 {
5784 return DYNAMIC_CAST<AstFormalParameter*> (kind == PARAMETER ? this : NULL);
5785 }
5786
MethodDeclaratorCast()5787 inline AstMethodDeclarator* Ast::MethodDeclaratorCast()
5788 {
5789 return DYNAMIC_CAST<AstMethodDeclarator*>
5790 (kind == METHOD_DECLARATOR ? this : NULL);
5791 }
5792
MethodBodyCast()5793 inline AstMethodBody* Ast::MethodBodyCast()
5794 {
5795 return DYNAMIC_CAST<AstMethodBody*> (kind == METHOD_BODY ? this : NULL);
5796 }
5797
MethodDeclarationCast()5798 inline AstMethodDeclaration* Ast::MethodDeclarationCast()
5799 {
5800 return DYNAMIC_CAST<AstMethodDeclaration*> (kind == METHOD ? this : NULL);
5801 }
5802
InitializerDeclarationCast()5803 inline AstInitializerDeclaration* Ast::InitializerDeclarationCast()
5804 {
5805 return DYNAMIC_CAST<AstInitializerDeclaration*>
5806 (kind == INITIALIZER ? this : NULL);
5807 }
5808
ArgumentsCast()5809 inline AstArguments* Ast::ArgumentsCast()
5810 {
5811 return DYNAMIC_CAST<AstArguments*> (kind == ARGUMENTS ? this : NULL);
5812 }
5813
ThisCallCast()5814 inline AstThisCall* Ast::ThisCallCast()
5815 {
5816 return DYNAMIC_CAST<AstThisCall*> (kind == THIS_CALL ? this : NULL);
5817 }
5818
SuperCallCast()5819 inline AstSuperCall* Ast::SuperCallCast()
5820 {
5821 return DYNAMIC_CAST<AstSuperCall*> (kind == SUPER_CALL ? this : NULL);
5822 }
5823
ConstructorDeclarationCast()5824 inline AstConstructorDeclaration* Ast::ConstructorDeclarationCast()
5825 {
5826 return DYNAMIC_CAST<AstConstructorDeclaration*>
5827 (kind == CONSTRUCTOR ? this : NULL);
5828 }
5829
EnumDeclarationCast()5830 inline AstEnumDeclaration* Ast::EnumDeclarationCast()
5831 {
5832 return DYNAMIC_CAST<AstEnumDeclaration*> (kind == ENUM_TYPE ? this : NULL);
5833 }
5834
EnumConstantCast()5835 inline AstEnumConstant* Ast::EnumConstantCast()
5836 {
5837 return DYNAMIC_CAST<AstEnumConstant*> (kind == ENUM ? this : NULL);
5838 }
5839
InterfaceDeclarationCast()5840 inline AstInterfaceDeclaration* Ast::InterfaceDeclarationCast()
5841 {
5842 return DYNAMIC_CAST<AstInterfaceDeclaration*>
5843 (kind == INTERFACE ? this : NULL);
5844 }
5845
AnnotationDeclarationCast()5846 inline AstAnnotationDeclaration* Ast::AnnotationDeclarationCast()
5847 {
5848 return DYNAMIC_CAST<AstAnnotationDeclaration*>
5849 (kind == ANNOTATION_TYPE ? this : NULL);
5850 }
5851
LocalVariableStatementCast()5852 inline AstLocalVariableStatement* Ast::LocalVariableStatementCast()
5853 {
5854 return DYNAMIC_CAST<AstLocalVariableStatement*>
5855 (kind == LOCAL_VARIABLE_DECLARATION ? this : NULL);
5856 }
5857
LocalClassStatementCast()5858 inline AstLocalClassStatement* Ast::LocalClassStatementCast()
5859 {
5860 return DYNAMIC_CAST<AstLocalClassStatement*>
5861 (kind == LOCAL_CLASS ? this : NULL);
5862 }
5863
IfStatementCast()5864 inline AstIfStatement* Ast::IfStatementCast()
5865 {
5866 return DYNAMIC_CAST<AstIfStatement*> (kind == IF ? this : NULL);
5867 }
5868
EmptyStatementCast()5869 inline AstEmptyStatement* Ast::EmptyStatementCast()
5870 {
5871 return DYNAMIC_CAST<AstEmptyStatement*>
5872 (kind == EMPTY_STATEMENT ? this : NULL);
5873 }
5874
ExpressionStatementCast()5875 inline AstExpressionStatement* Ast::ExpressionStatementCast()
5876 {
5877 return DYNAMIC_CAST<AstExpressionStatement*>
5878 (kind == EXPRESSION_STATEMENT ? this : NULL);
5879 }
5880
SwitchLabelCast()5881 inline AstSwitchLabel* Ast::SwitchLabelCast()
5882 {
5883 return DYNAMIC_CAST<AstSwitchLabel*> (kind == SWITCH_LABEL ? this : NULL);
5884 }
5885
SwitchBlockStatementCast()5886 inline AstSwitchBlockStatement* Ast::SwitchBlockStatementCast()
5887 {
5888 return DYNAMIC_CAST<AstSwitchBlockStatement*>
5889 (kind == SWITCH_BLOCK ? this : NULL);
5890 }
5891
SwitchStatementCast()5892 inline AstSwitchStatement* Ast::SwitchStatementCast()
5893 {
5894 return DYNAMIC_CAST<AstSwitchStatement*> (kind == SWITCH ? this : NULL);
5895 }
5896
WhileStatementCast()5897 inline AstWhileStatement* Ast::WhileStatementCast()
5898 {
5899 return DYNAMIC_CAST<AstWhileStatement*> (kind == WHILE ? this : NULL);
5900 }
5901
DoStatementCast()5902 inline AstDoStatement* Ast::DoStatementCast()
5903 {
5904 return DYNAMIC_CAST<AstDoStatement*> (kind == DO ? this : NULL);
5905 }
5906
ForStatementCast()5907 inline AstForStatement* Ast::ForStatementCast()
5908 {
5909 return DYNAMIC_CAST<AstForStatement*> (kind == FOR ? this : NULL);
5910 }
5911
ForeachStatementCast()5912 inline AstForeachStatement* Ast::ForeachStatementCast()
5913 {
5914 return DYNAMIC_CAST<AstForeachStatement*> (kind == FOREACH ? this : NULL);
5915 }
5916
BreakStatementCast()5917 inline AstBreakStatement* Ast::BreakStatementCast()
5918 {
5919 return DYNAMIC_CAST<AstBreakStatement*> (kind == BREAK ? this : NULL);
5920 }
5921
ContinueStatementCast()5922 inline AstContinueStatement* Ast::ContinueStatementCast()
5923 {
5924 return DYNAMIC_CAST<AstContinueStatement*>
5925 (kind == CONTINUE ? this : NULL);
5926 }
5927
ReturnStatementCast()5928 inline AstReturnStatement* Ast::ReturnStatementCast()
5929 {
5930 return DYNAMIC_CAST<AstReturnStatement*> (kind == RETURN ? this : NULL);
5931 }
5932
ThrowStatementCast()5933 inline AstThrowStatement* Ast::ThrowStatementCast()
5934 {
5935 return DYNAMIC_CAST<AstThrowStatement*> (kind == THROW ? this : NULL);
5936 }
5937
SynchronizedStatementCast()5938 inline AstSynchronizedStatement* Ast::SynchronizedStatementCast()
5939 {
5940 return DYNAMIC_CAST<AstSynchronizedStatement*>
5941 (kind == SYNCHRONIZED_STATEMENT ? this : NULL);
5942 }
5943
AssertStatementCast()5944 inline AstAssertStatement* Ast::AssertStatementCast()
5945 {
5946 return DYNAMIC_CAST<AstAssertStatement*> (kind == ASSERT ? this : NULL);
5947 }
5948
CatchClauseCast()5949 inline AstCatchClause* Ast::CatchClauseCast()
5950 {
5951 return DYNAMIC_CAST<AstCatchClause*> (kind == CATCH ? this : NULL);
5952 }
5953
FinallyClauseCast()5954 inline AstFinallyClause* Ast::FinallyClauseCast()
5955 {
5956 return DYNAMIC_CAST<AstFinallyClause*> (kind == FINALLY ? this : NULL);
5957 }
5958
TryStatementCast()5959 inline AstTryStatement* Ast::TryStatementCast()
5960 {
5961 return DYNAMIC_CAST<AstTryStatement*> (kind == TRY ? this : NULL);
5962 }
5963
IntegerLiteralCast()5964 inline AstIntegerLiteral* Ast::IntegerLiteralCast()
5965 {
5966 return DYNAMIC_CAST<AstIntegerLiteral*>
5967 (kind == INTEGER_LITERAL ? this : NULL);
5968 }
5969
LongLiteralCast()5970 inline AstLongLiteral* Ast::LongLiteralCast()
5971 {
5972 return DYNAMIC_CAST<AstLongLiteral*> (kind == LONG_LITERAL ? this : NULL);
5973 }
5974
FloatLiteralCast()5975 inline AstFloatLiteral* Ast::FloatLiteralCast()
5976 {
5977 return DYNAMIC_CAST<AstFloatLiteral*>
5978 (kind == FLOAT_LITERAL ? this : NULL);
5979 }
5980
DoubleLiteralCast()5981 inline AstDoubleLiteral* Ast::DoubleLiteralCast()
5982 {
5983 return DYNAMIC_CAST<AstDoubleLiteral*>
5984 (kind == DOUBLE_LITERAL ? this : NULL);
5985 }
5986
TrueLiteralCast()5987 inline AstTrueLiteral* Ast::TrueLiteralCast()
5988 {
5989 return DYNAMIC_CAST<AstTrueLiteral*> (kind == TRUE_LITERAL ? this : NULL);
5990 }
5991
FalseLiteralCast()5992 inline AstFalseLiteral* Ast::FalseLiteralCast()
5993 {
5994 return DYNAMIC_CAST<AstFalseLiteral*>
5995 (kind == FALSE_LITERAL ? this : NULL);
5996 }
5997
StringLiteralCast()5998 inline AstStringLiteral* Ast::StringLiteralCast()
5999 {
6000 return DYNAMIC_CAST<AstStringLiteral*>
6001 (kind == STRING_LITERAL ? this : NULL);
6002 }
6003
CharacterLiteralCast()6004 inline AstCharacterLiteral* Ast::CharacterLiteralCast()
6005 {
6006 return DYNAMIC_CAST<AstCharacterLiteral*>
6007 (kind == CHARACTER_LITERAL ? this : NULL);
6008 }
6009
NullLiteralCast()6010 inline AstNullLiteral* Ast::NullLiteralCast()
6011 {
6012 return DYNAMIC_CAST<AstNullLiteral*> (kind == NULL_LITERAL ? this : NULL);
6013 }
6014
ClassLiteralCast()6015 inline AstClassLiteral* Ast::ClassLiteralCast()
6016 {
6017 return DYNAMIC_CAST<AstClassLiteral*>
6018 (kind == CLASS_LITERAL ? this : NULL);
6019 }
6020
ThisExpressionCast()6021 inline AstThisExpression* Ast::ThisExpressionCast()
6022 {
6023 return DYNAMIC_CAST<AstThisExpression*>
6024 (kind == THIS_EXPRESSION ? this : NULL);
6025 }
6026
SuperExpressionCast()6027 inline AstSuperExpression* Ast::SuperExpressionCast()
6028 {
6029 return DYNAMIC_CAST<AstSuperExpression*>
6030 (kind == SUPER_EXPRESSION ? this : NULL);
6031 }
6032
ParenthesizedExpressionCast()6033 inline AstParenthesizedExpression* Ast::ParenthesizedExpressionCast()
6034 {
6035 return DYNAMIC_CAST<AstParenthesizedExpression*>
6036 (kind == PARENTHESIZED_EXPRESSION ? this : NULL);
6037 }
6038
ClassCreationExpressionCast()6039 inline AstClassCreationExpression* Ast::ClassCreationExpressionCast()
6040 {
6041 return DYNAMIC_CAST<AstClassCreationExpression*>
6042 (kind == CLASS_CREATION ? this : NULL);
6043 }
6044
DimExprCast()6045 inline AstDimExpr* Ast::DimExprCast()
6046 {
6047 return DYNAMIC_CAST<AstDimExpr*> (kind == DIM ? this : NULL);
6048 }
6049
ArrayCreationExpressionCast()6050 inline AstArrayCreationExpression* Ast::ArrayCreationExpressionCast()
6051 {
6052 return DYNAMIC_CAST<AstArrayCreationExpression*>
6053 (kind == ARRAY_CREATION ? this : NULL);
6054 }
6055
FieldAccessCast()6056 inline AstFieldAccess* Ast::FieldAccessCast()
6057 {
6058 return DYNAMIC_CAST<AstFieldAccess*> (kind == DOT ? this : NULL);
6059 }
6060
MethodInvocationCast()6061 inline AstMethodInvocation* Ast::MethodInvocationCast()
6062 {
6063 return DYNAMIC_CAST<AstMethodInvocation*> (kind == CALL ? this : NULL);
6064 }
6065
ArrayAccessCast()6066 inline AstArrayAccess* Ast::ArrayAccessCast()
6067 {
6068 return DYNAMIC_CAST<AstArrayAccess*> (kind == ARRAY_ACCESS ? this : NULL);
6069 }
6070
PostUnaryExpressionCast()6071 inline AstPostUnaryExpression* Ast::PostUnaryExpressionCast()
6072 {
6073 return DYNAMIC_CAST<AstPostUnaryExpression*>
6074 (kind == POST_UNARY ? this : NULL);
6075 }
6076
PreUnaryExpressionCast()6077 inline AstPreUnaryExpression* Ast::PreUnaryExpressionCast()
6078 {
6079 return DYNAMIC_CAST<AstPreUnaryExpression*>
6080 (kind == PRE_UNARY ? this : NULL);
6081 }
6082
CastExpressionCast()6083 inline AstCastExpression* Ast::CastExpressionCast()
6084 {
6085 return DYNAMIC_CAST<AstCastExpression*> (kind == CAST ? this : NULL);
6086 }
6087
BinaryExpressionCast()6088 inline AstBinaryExpression* Ast::BinaryExpressionCast()
6089 {
6090 return DYNAMIC_CAST<AstBinaryExpression*> (kind == BINARY ? this : NULL);
6091 }
6092
InstanceofExpressionCast()6093 inline AstInstanceofExpression* Ast::InstanceofExpressionCast()
6094 {
6095 return DYNAMIC_CAST<AstInstanceofExpression*>
6096 (kind == INSTANCEOF ? this : NULL);
6097 }
6098
ConditionalExpressionCast()6099 inline AstConditionalExpression* Ast::ConditionalExpressionCast()
6100 {
6101 return DYNAMIC_CAST<AstConditionalExpression*>
6102 (kind == CONDITIONAL ? this : NULL);
6103 }
6104
AssignmentExpressionCast()6105 inline AstAssignmentExpression* Ast::AssignmentExpressionCast()
6106 {
6107 return DYNAMIC_CAST<AstAssignmentExpression*>
6108 (kind == ASSIGNMENT ? this : NULL);
6109 }
6110
6111 // **********************************************
6112
IsValid()6113 inline bool AstDeclaredType::IsValid()
6114 {
6115 return class_body && class_body -> semantic_environment;
6116 }
6117
AllocateStatements(unsigned estimate)6118 inline void AstBlock::AllocateStatements(unsigned estimate)
6119 {
6120 assert(! block_statements);
6121 block_statements = new (pool) AstArray<AstStatement*> (pool, estimate);
6122 }
6123
AddStatement(AstStatement * statement)6124 inline void AstBlock::AddStatement(AstStatement* statement)
6125 {
6126 assert(block_statements);
6127 block_statements -> Next() = statement;
6128 }
6129
AllocateLocallyDefinedVariables(unsigned estimate)6130 inline void AstBlock::AllocateLocallyDefinedVariables(unsigned estimate)
6131 {
6132 if (! defined_variables)
6133 defined_variables = pool -> NewVariableSymbolArray(estimate);
6134 }
6135
AddLocallyDefinedVariable(VariableSymbol * variable_symbol)6136 inline void AstBlock::AddLocallyDefinedVariable(VariableSymbol* variable_symbol)
6137 {
6138 if (! defined_variables)
6139 AllocateLocallyDefinedVariables(1);
6140 defined_variables -> Next() = variable_symbol;
6141 }
6142
AllocateTypeArguments(unsigned estimate)6143 inline void AstTypeArguments::AllocateTypeArguments(unsigned estimate)
6144 {
6145 assert(! type_arguments && estimate);
6146 type_arguments = new (pool) AstArray<AstType*> (pool, estimate);
6147 }
6148
AddTypeArgument(AstType * argument)6149 inline void AstTypeArguments::AddTypeArgument(AstType* argument)
6150 {
6151 assert(! argument -> PrimitiveTypeCast());
6152 assert(type_arguments);
6153 type_arguments -> Next() = argument;
6154 }
6155
AllocateMemberValuePairs(unsigned estimate)6156 inline void AstAnnotation::AllocateMemberValuePairs(unsigned estimate)
6157 {
6158 assert(! member_value_pairs);
6159 member_value_pairs =
6160 new (pool) AstArray<AstMemberValuePair*> (pool, estimate);
6161 }
6162
AddMemberValuePair(AstMemberValuePair * pair)6163 inline void AstAnnotation::AddMemberValuePair(AstMemberValuePair* pair)
6164 {
6165 assert(member_value_pairs);
6166 member_value_pairs -> Next() = pair;
6167 }
6168
AllocateModifiers(unsigned estimate)6169 inline void AstModifiers::AllocateModifiers(unsigned estimate)
6170 {
6171 assert(! modifiers && estimate);
6172 modifiers = new (pool) AstArray<Ast*> (pool, estimate);
6173 }
6174
AddModifier(AstAnnotation * annotation)6175 inline void AstModifiers::AddModifier(AstAnnotation* annotation)
6176 {
6177 assert(modifiers);
6178 modifiers -> Next() = annotation;
6179 }
6180
AddModifier(AstModifierKeyword * keyword)6181 inline void AstModifiers::AddModifier(AstModifierKeyword* keyword)
6182 {
6183 assert(modifiers);
6184 modifiers -> Next() = keyword;
6185 }
6186
AllocateImportDeclarations(unsigned estimate)6187 inline void AstCompilationUnit::AllocateImportDeclarations(unsigned estimate)
6188 {
6189 assert(! import_declarations);
6190 import_declarations =
6191 new (ast_pool) AstArray<AstImportDeclaration*> (ast_pool, estimate);
6192 }
6193
AddImportDeclaration(AstImportDeclaration * import_declaration)6194 inline void AstCompilationUnit::AddImportDeclaration(AstImportDeclaration* import_declaration)
6195 {
6196 assert(import_declarations);
6197 import_declarations -> Next() = import_declaration;
6198 }
6199
AllocateTypeDeclarations(unsigned estimate)6200 inline void AstCompilationUnit::AllocateTypeDeclarations(unsigned estimate)
6201 {
6202 assert(! type_declarations);
6203 type_declarations =
6204 new (ast_pool) AstArray<AstDeclaredType*> (ast_pool, estimate);
6205 }
6206
AddTypeDeclaration(AstDeclaredType * type_declaration)6207 inline void AstCompilationUnit::AddTypeDeclaration(AstDeclaredType* type_declaration)
6208 {
6209 assert(type_declarations);
6210 type_declarations -> Next() = type_declaration;
6211 }
6212
AllocateClassBodyDeclarations(unsigned estimate)6213 inline void AstClassBody::AllocateClassBodyDeclarations(unsigned estimate)
6214 {
6215 assert(! class_body_declarations);
6216 class_body_declarations =
6217 new (pool) AstArray<AstDeclared*> (pool, estimate);
6218 }
6219
AllocateInstanceVariables(unsigned estimate)6220 inline void AstClassBody::AllocateInstanceVariables(unsigned estimate)
6221 {
6222 assert(! instance_variables);
6223 instance_variables =
6224 new (pool) AstArray<AstFieldDeclaration*> (pool, estimate);
6225 }
6226
AddInstanceVariable(AstFieldDeclaration * field_declaration)6227 inline void AstClassBody::AddInstanceVariable(AstFieldDeclaration* field_declaration)
6228 {
6229 assert(instance_variables);
6230 instance_variables -> Next() = field_declaration;
6231 }
6232
AllocateClassVariables(unsigned estimate)6233 inline void AstClassBody::AllocateClassVariables(unsigned estimate)
6234 {
6235 assert(! class_variables);
6236 class_variables =
6237 new (pool) AstArray<AstFieldDeclaration*> (pool, estimate);
6238 }
6239
AddClassVariable(AstFieldDeclaration * field_declaration)6240 inline void AstClassBody::AddClassVariable(AstFieldDeclaration* field_declaration)
6241 {
6242 assert(class_variables);
6243 class_variables -> Next() = field_declaration;
6244 }
6245
AllocateMethods(unsigned estimate)6246 inline void AstClassBody::AllocateMethods(unsigned estimate)
6247 {
6248 assert(! methods);
6249 methods = new (pool) AstArray<AstMethodDeclaration*> (pool, estimate);
6250 }
6251
AddMethod(AstMethodDeclaration * method_declaration)6252 inline void AstClassBody::AddMethod(AstMethodDeclaration* method_declaration)
6253 {
6254 assert(methods);
6255 methods -> Next() = method_declaration;
6256 }
6257
AllocateConstructors(unsigned estimate)6258 inline void AstClassBody::AllocateConstructors(unsigned estimate)
6259 {
6260 assert(! constructors);
6261 constructors =
6262 new (pool) AstArray<AstConstructorDeclaration*> (pool, estimate);
6263 }
6264
AddConstructor(AstConstructorDeclaration * constructor_declaration)6265 inline void AstClassBody::AddConstructor(AstConstructorDeclaration* constructor_declaration)
6266 {
6267 assert(constructors);
6268 constructors -> Next() = constructor_declaration;
6269 }
6270
AllocateStaticInitializers(unsigned estimate)6271 inline void AstClassBody::AllocateStaticInitializers(unsigned estimate)
6272 {
6273 assert(! static_initializers);
6274 static_initializers =
6275 new (pool) AstArray<AstInitializerDeclaration*> (pool, estimate);
6276 }
6277
AddStaticInitializer(AstInitializerDeclaration * initializer)6278 inline void AstClassBody::AddStaticInitializer(AstInitializerDeclaration* initializer)
6279 {
6280 assert(static_initializers);
6281 static_initializers -> Next() = initializer;
6282 }
6283
AllocateInstanceInitializers(unsigned estimate)6284 inline void AstClassBody::AllocateInstanceInitializers(unsigned estimate)
6285 {
6286 assert(! instance_initializers);
6287 instance_initializers =
6288 new (pool) AstArray<AstInitializerDeclaration*> (pool, estimate);
6289 }
6290
AddInstanceInitializer(AstInitializerDeclaration * initializer)6291 inline void AstClassBody::AddInstanceInitializer(AstInitializerDeclaration* initializer)
6292 {
6293 assert(instance_initializers);
6294 instance_initializers -> Next() = initializer;
6295 }
6296
AllocateNestedClasses(unsigned estimate)6297 inline void AstClassBody::AllocateNestedClasses(unsigned estimate)
6298 {
6299 assert(! inner_classes);
6300 inner_classes = new (pool) AstArray<AstClassDeclaration*> (pool, estimate);
6301 }
6302
AddNestedClass(AstClassDeclaration * class_declaration)6303 inline void AstClassBody::AddNestedClass(AstClassDeclaration* class_declaration)
6304 {
6305 assert(inner_classes);
6306 inner_classes -> Next() = class_declaration;
6307 }
6308
AllocateNestedEnums(unsigned estimate)6309 inline void AstClassBody::AllocateNestedEnums(unsigned estimate)
6310 {
6311 assert(! inner_enums);
6312 inner_enums = new (pool) AstArray<AstEnumDeclaration*> (pool, estimate);
6313 }
6314
AddNestedEnum(AstEnumDeclaration * enum_declaration)6315 inline void AstClassBody::AddNestedEnum(AstEnumDeclaration* enum_declaration)
6316 {
6317 assert(inner_enums);
6318 inner_enums -> Next() = enum_declaration;
6319 }
6320
AllocateNestedInterfaces(unsigned estimate)6321 inline void AstClassBody::AllocateNestedInterfaces(unsigned estimate)
6322 {
6323 assert(! inner_interfaces);
6324 inner_interfaces =
6325 new (pool) AstArray<AstInterfaceDeclaration*> (pool, estimate);
6326 }
6327
AddNestedInterface(AstInterfaceDeclaration * interface_declaration)6328 inline void AstClassBody::AddNestedInterface(AstInterfaceDeclaration* interface_declaration)
6329 {
6330 assert(inner_interfaces);
6331 inner_interfaces -> Next() = interface_declaration;
6332 }
6333
AllocateNestedAnnotations(unsigned estimate)6334 inline void AstClassBody::AllocateNestedAnnotations(unsigned estimate)
6335 {
6336 assert(! inner_annotations);
6337 inner_annotations =
6338 new (pool) AstArray<AstAnnotationDeclaration*> (pool, estimate);
6339 }
6340
AddNestedAnnotation(AstAnnotationDeclaration * ann)6341 inline void AstClassBody::AddNestedAnnotation(AstAnnotationDeclaration* ann)
6342 {
6343 assert(inner_annotations);
6344 inner_annotations -> Next() = ann;
6345 }
6346
AllocateEmptyDeclarations(unsigned estimate)6347 inline void AstClassBody::AllocateEmptyDeclarations(unsigned estimate)
6348 {
6349 assert(! empty_declarations);
6350 empty_declarations =
6351 new (pool) AstArray<AstEmptyDeclaration*> (pool, estimate);
6352 }
6353
AddEmptyDeclaration(AstEmptyDeclaration * empty_declaration)6354 inline void AstClassBody::AddEmptyDeclaration(AstEmptyDeclaration* empty_declaration)
6355 {
6356 assert(empty_declarations);
6357 empty_declarations -> Next() = empty_declaration;
6358 }
6359
AllocateBounds(unsigned estimate)6360 inline void AstTypeParameter::AllocateBounds(unsigned estimate)
6361 {
6362 assert(! bounds);
6363 bounds = new (pool) AstArray<AstTypeName*> (pool, estimate);
6364 }
6365
AddBound(AstTypeName * bound)6366 inline void AstTypeParameter::AddBound(AstTypeName* bound)
6367 {
6368 assert(bounds);
6369 bounds -> Next() = bound;
6370 }
6371
AllocateTypeParameters(unsigned estimate)6372 inline void AstTypeParameters::AllocateTypeParameters(unsigned estimate)
6373 {
6374 assert(! parameters);
6375 parameters = new (pool) AstArray<AstTypeParameter*> (pool, estimate);
6376 }
6377
AddTypeParameter(AstTypeParameter * type)6378 inline void AstTypeParameters::AddTypeParameter(AstTypeParameter* type)
6379 {
6380 assert(parameters);
6381 parameters -> Next() = type;
6382 }
6383
AllocateInterfaces(unsigned estimate)6384 inline void AstClassDeclaration::AllocateInterfaces(unsigned estimate)
6385 {
6386 assert(! interfaces);
6387 interfaces = new (pool) AstArray<AstTypeName*> (pool, estimate);
6388 }
6389
AddInterface(AstTypeName * interf)6390 inline void AstClassDeclaration::AddInterface(AstTypeName* interf)
6391 {
6392 assert(interfaces);
6393 interfaces -> Next() = interf;
6394 }
6395
AllocateVariableInitializers(unsigned estimate)6396 inline void AstArrayInitializer::AllocateVariableInitializers(unsigned estimate)
6397 {
6398 assert(! variable_initializers);
6399 variable_initializers =
6400 new (pool) AstArray<AstMemberValue*> (pool, estimate);
6401 }
6402
AddVariableInitializer(AstMemberValue * initializer)6403 inline void AstArrayInitializer::AddVariableInitializer(AstMemberValue* initializer)
6404 {
6405 assert(variable_initializers);
6406 variable_initializers -> Next() = initializer;
6407 }
6408
AllocateVariableDeclarators(unsigned estimate)6409 inline void AstFieldDeclaration::AllocateVariableDeclarators(unsigned estimate)
6410 {
6411 assert(! variable_declarators);
6412 variable_declarators =
6413 new (pool) AstArray<AstVariableDeclarator*> (pool, estimate);
6414 }
6415
AddVariableDeclarator(AstVariableDeclarator * variable_declarator)6416 inline void AstFieldDeclaration::AddVariableDeclarator(AstVariableDeclarator* variable_declarator)
6417 {
6418 assert(variable_declarators);
6419 variable_declarators -> Next() = variable_declarator;
6420 }
6421
AllocateFormalParameters(unsigned estimate)6422 inline void AstMethodDeclarator::AllocateFormalParameters(unsigned estimate)
6423 {
6424 assert(! formal_parameters);
6425 formal_parameters =
6426 new (pool) AstArray<AstFormalParameter*> (pool, estimate);
6427 }
6428
AddFormalParameter(AstFormalParameter * formal_parameter)6429 inline void AstMethodDeclarator::AddFormalParameter(AstFormalParameter* formal_parameter)
6430 {
6431 assert(formal_parameters);
6432 formal_parameters -> Next() = formal_parameter;
6433 }
6434
AllocateThrows(unsigned estimate)6435 inline void AstMethodDeclaration::AllocateThrows(unsigned estimate)
6436 {
6437 assert(! throws);
6438 throws = new (pool) AstArray<AstTypeName*> (pool, estimate);
6439 }
6440
AddThrow(AstTypeName * exception)6441 inline void AstMethodDeclaration::AddThrow(AstTypeName* exception)
6442 {
6443 assert(throws);
6444 throws -> Next() = exception;
6445 }
6446
AllocateArguments(unsigned estimate)6447 inline void AstArguments::AllocateArguments(unsigned estimate)
6448 {
6449 assert(! arguments);
6450 arguments = new (pool) AstArray<AstExpression*> (pool, estimate);
6451 }
6452
AddArgument(AstExpression * argument)6453 inline void AstArguments::AddArgument(AstExpression* argument)
6454 {
6455 assert(arguments);
6456 arguments -> Next() = argument;
6457 }
6458
AllocateLocalArguments(unsigned estimate)6459 inline void AstArguments::AllocateLocalArguments(unsigned estimate)
6460 {
6461 assert(! shadow_arguments);
6462 shadow_arguments = new (pool) AstArray<AstName*> (pool, estimate);
6463 }
6464
AddLocalArgument(AstName * argument)6465 inline void AstArguments::AddLocalArgument(AstName* argument)
6466 {
6467 assert(shadow_arguments);
6468 shadow_arguments -> Next() = argument;
6469 }
6470
AllocateThrows(unsigned estimate)6471 inline void AstConstructorDeclaration::AllocateThrows(unsigned estimate)
6472 {
6473 assert(! throws);
6474 throws = new (pool) AstArray<AstTypeName*> (pool, estimate);
6475 }
6476
AddThrow(AstTypeName * exception)6477 inline void AstConstructorDeclaration::AddThrow(AstTypeName* exception)
6478 {
6479 assert(throws);
6480 throws -> Next() = exception;
6481 }
6482
AllocateInterfaces(unsigned estimate)6483 inline void AstEnumDeclaration::AllocateInterfaces(unsigned estimate)
6484 {
6485 assert(! interfaces);
6486 interfaces = new (pool) AstArray<AstTypeName*> (pool, estimate);
6487 }
6488
AddInterface(AstTypeName * interf)6489 inline void AstEnumDeclaration::AddInterface(AstTypeName* interf)
6490 {
6491 assert(interfaces);
6492 interfaces -> Next() = interf;
6493 }
6494
AllocateEnumConstants(unsigned estimate)6495 inline void AstEnumDeclaration::AllocateEnumConstants(unsigned estimate)
6496 {
6497 assert(! enum_constants);
6498 enum_constants = new (pool) AstArray<AstEnumConstant*> (pool, estimate);
6499 }
6500
AddEnumConstant(AstEnumConstant * constant)6501 inline void AstEnumDeclaration::AddEnumConstant(AstEnumConstant* constant)
6502 {
6503 assert(enum_constants);
6504 constant -> ordinal = enum_constants -> Length();
6505 enum_constants -> Next() = constant;
6506 }
6507
AllocateInterfaces(unsigned estimate)6508 inline void AstInterfaceDeclaration::AllocateInterfaces(unsigned estimate)
6509 {
6510 assert(! interfaces);
6511 interfaces = new (pool) AstArray<AstTypeName*> (pool, estimate);
6512 }
6513
AddInterface(AstTypeName * interf)6514 inline void AstInterfaceDeclaration::AddInterface(AstTypeName* interf)
6515 {
6516 assert(interfaces);
6517 interfaces -> Next() = interf;
6518 }
6519
AllocateVariableDeclarators(unsigned estimate)6520 inline void AstLocalVariableStatement::AllocateVariableDeclarators(unsigned estimate)
6521 {
6522 assert(! variable_declarators);
6523 variable_declarators =
6524 new (pool) AstArray<AstVariableDeclarator*> (pool, estimate);
6525 }
6526
AddVariableDeclarator(AstVariableDeclarator * variable_declarator)6527 inline void AstLocalVariableStatement::AddVariableDeclarator(AstVariableDeclarator* variable_declarator)
6528 {
6529 assert(variable_declarators);
6530 variable_declarators -> Next() = variable_declarator;
6531 }
6532
AllocateSwitchLabels(unsigned estimate)6533 inline void AstSwitchBlockStatement::AllocateSwitchLabels(unsigned estimate)
6534 {
6535 assert(! switch_labels);
6536 switch_labels = new (pool) AstArray<AstSwitchLabel*> (pool, estimate);
6537 }
6538
AddSwitchLabel(AstSwitchLabel * case_label)6539 inline void AstSwitchBlockStatement::AddSwitchLabel(AstSwitchLabel* case_label)
6540 {
6541 assert(switch_labels);
6542 switch_labels -> Next() = case_label;
6543 }
6544
AllocateCases(unsigned estimate)6545 inline void AstSwitchStatement::AllocateCases(unsigned estimate)
6546 {
6547 //
6548 // Add one to the estimate to save room for the default case in element 0.
6549 //
6550 assert(! cases);
6551 cases = new (pool -> Alloc((estimate + 1) * sizeof(CaseElement*)))
6552 CaseElement*[estimate + 1];
6553 #ifdef JIKES_DEBUG
6554 max_cases = estimate + 1;
6555 #endif // JIKES_DEBUG
6556 }
6557
AddCase(CaseElement * case_element)6558 inline void AstSwitchStatement::AddCase(CaseElement* case_element)
6559 {
6560 assert(cases);
6561 cases[++num_cases] = case_element;
6562 #ifdef JIKES_DEBUG
6563 assert(num_cases < max_cases);
6564 #endif // JIKES_DEBUG
6565 }
6566
AllocateForInitStatements(unsigned estimate)6567 inline void AstForStatement::AllocateForInitStatements(unsigned estimate)
6568 {
6569 assert(! for_init_statements);
6570 for_init_statements = new (pool) AstArray<AstStatement*> (pool, estimate);
6571 }
6572
AddForInitStatement(AstStatement * statement)6573 inline void AstForStatement::AddForInitStatement(AstStatement* statement)
6574 {
6575 assert(for_init_statements);
6576 for_init_statements -> Next() = statement;
6577 }
6578
AllocateForUpdateStatements(unsigned estimate)6579 inline void AstForStatement::AllocateForUpdateStatements(unsigned estimate)
6580 {
6581 assert(! for_update_statements);
6582 for_update_statements =
6583 new (pool) AstArray<AstExpressionStatement*> (pool, estimate);
6584 }
6585
AddForUpdateStatement(AstExpressionStatement * statement)6586 inline void AstForStatement::AddForUpdateStatement(AstExpressionStatement* statement)
6587 {
6588 assert(for_update_statements);
6589 for_update_statements -> Next() = statement;
6590 }
6591
AllocateCatchClauses(unsigned estimate)6592 inline void AstTryStatement::AllocateCatchClauses(unsigned estimate)
6593 {
6594 assert(! catch_clauses);
6595 catch_clauses = new (pool) AstArray<AstCatchClause*> (pool, estimate);
6596 }
6597
AddCatchClause(AstCatchClause * catch_clause)6598 inline void AstTryStatement::AddCatchClause(AstCatchClause* catch_clause)
6599 {
6600 assert(catch_clauses);
6601 catch_clauses -> Next() = catch_clause;
6602 }
6603
AllocateDimExprs(unsigned estimate)6604 inline void AstArrayCreationExpression::AllocateDimExprs(unsigned estimate)
6605 {
6606 assert(! dim_exprs);
6607 dim_exprs = new (pool) AstArray<AstDimExpr*> (pool, estimate);
6608 }
6609
AddDimExpr(AstDimExpr * dim_expr)6610 inline void AstArrayCreationExpression::AddDimExpr(AstDimExpr* dim_expr)
6611 {
6612 assert(dim_exprs);
6613 dim_exprs -> Next() = dim_expr;
6614 }
6615
6616 // ******************************************
6617
6618 //
6619 // Overridden placement new operator allows us to allocate storage from the
6620 // same pool as everything else in the compilation unit.
6621 //
new(size_t size,StoragePool * pool)6622 inline void* Ast::operator new(size_t size, StoragePool* pool)
6623 {
6624 return pool -> Alloc(size);
6625 }
6626
6627 template <typename T>
new(size_t size,StoragePool * pool)6628 inline void* AstArray<T>::operator new(size_t size, StoragePool* pool)
6629 {
6630 return pool -> Alloc(size);
6631 }
6632
6633 //
6634 // Constructor of an Ast array.
6635 //
6636 template <typename T>
AstArray(StoragePool * pool,unsigned estimate)6637 AstArray<T>::AstArray(StoragePool* pool, unsigned estimate)
6638 : size(estimate)
6639 {
6640 //
6641 // This bit of code is a compile-time assertion that only Ast* are stuck
6642 // in an AstArray.
6643 //
6644 #if defined JIKES_DEBUG && defined HAVE_STATIC_CAST
6645 assert(true || static_cast<Ast*> (T()));
6646 #endif // JIKES_DEBUG
6647
6648 if(estimate)
6649 array = new (pool -> Alloc(size * sizeof(T))) T[size];
6650 }
6651
6652 #ifdef HAVE_JIKES_NAMESPACE
6653 } // Close namespace Jikes block
6654 #endif
6655
6656 #endif // ast_INCLUDED
6657