home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / Jikes / Source / src / ast.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-24  |  183.9 KB  |  6,107 lines

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