home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / jikes-1.02 / src / symbol.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-05  |  71.1 KB  |  2,329 lines

  1. // $Id: symbol.h,v 1.23 1999/09/01 14:58:26 shields 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. #ifndef symbol_INCLUDED
  11. #define symbol_INCLUDED
  12.  
  13. #include "config.h"
  14. #include <assert.h>
  15. #include <stddef.h>
  16. #include <stdio.h>
  17. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <string.h>
  20. #include "code.h"
  21. #include "stream.h"
  22. #include "option.h"
  23. #include "lookup.h"
  24. #include "depend.h"
  25. #include "access.h"
  26. #include "tuple.h"
  27. #include "case.h"
  28.  
  29. class Semantic;
  30. class SemanticEnvironment;
  31. class Ast;
  32. class AstCompilationUnit;
  33. class AstMethodDeclarator;
  34. class AstBlock;
  35. class AstList;
  36. class AstExpression;
  37. class AstVariableDeclarator;
  38. class ExpandedTypeTable;
  39. class ExpandedFieldTable;
  40. class ExpandedMethodTable;
  41. class SymbolTable;
  42. class SymbolSet;
  43. class SymbolMap;
  44. class Zip;
  45.  
  46. class PackageSymbol;
  47.  
  48. class PathSymbol : public Symbol
  49. {
  50. public:
  51.     NameSymbol *name_symbol;
  52.     Zip *zipfile;
  53.  
  54.     PathSymbol(NameSymbol *);
  55.     virtual ~PathSymbol();
  56.  
  57.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  58.     virtual int NameLength() { return name_symbol -> NameLength(); }
  59.     virtual NameSymbol *Identity() { return name_symbol; }
  60.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  61.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  62.  
  63.     inline bool IsZip() { return zipfile != NULL; }
  64.  
  65.     inline DirectorySymbol *RootDirectory() { return root_directory; }
  66.  
  67. private:
  68.     friend class SymbolTable;
  69.     DirectorySymbol *root_directory;
  70. };
  71.  
  72.  
  73. class DirectorySymbol : public Symbol
  74. {
  75. public:
  76.     Symbol *owner;
  77.     NameSymbol *name_symbol;
  78.  
  79.     Tuple<DirectorySymbol *> subdirectories;
  80.  
  81.     DirectorySymbol(NameSymbol *, Symbol *);
  82.     virtual ~DirectorySymbol();
  83.  
  84.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  85.     virtual int NameLength() { return name_symbol -> NameLength(); }
  86.     virtual NameSymbol *Identity() { return name_symbol; }
  87.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  88.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  89.  
  90.     DirectoryEntry *FindEntry(char *name, int len) { return (entries ? entries -> FindEntry(name, len) : (DirectoryEntry *) NULL); }
  91.  
  92. #ifdef WIN32_FILE_SYSTEM
  93.     DirectoryEntry *FindCaseInsensitiveEntry(char *name, int length)
  94.     {
  95.         return (entries ? entries -> FindCaseInsensitiveEntry(name, length) : (DirectoryEntry *) NULL);
  96.     }
  97.  
  98.     void InsertEntry(char *name, int length)
  99.     {
  100.         assert(entries);
  101.  
  102.         DirectoryEntry *entry = entries -> InsertEntry((DirectorySymbol *) this, name, length);
  103.         entries -> InsertCaseInsensitiveEntry(entry);
  104.  
  105.         return;
  106.     }
  107. #endif
  108.  
  109.     PathSymbol *PathSym()
  110.     {
  111.         return (owner -> PathCast() ? (PathSymbol *) owner : ((DirectorySymbol *) owner) -> PathSym());
  112.     }
  113.  
  114.     inline bool IsZip() { return PathSym() -> IsZip(); }
  115.  
  116.     void SetDirectoryName();
  117.     inline char *DirectoryName()
  118.     {
  119.         if (! directory_name)
  120.             SetDirectoryName();
  121.         return directory_name;
  122.     }
  123.     inline int DirectoryNameLength()
  124.     {
  125.         if (! directory_name)
  126.             SetDirectoryName();
  127.         return directory_name_length;
  128.     }
  129.  
  130.     inline DirectorySymbol *InsertDirectorySymbol(NameSymbol *);
  131.     inline DirectorySymbol *FindDirectorySymbol(NameSymbol *);
  132.  
  133.     inline FileSymbol *InsertFileSymbol(NameSymbol *);
  134.     inline FileSymbol *FindFileSymbol(NameSymbol *);
  135.  
  136.     void ResetDirectory();
  137.  
  138.     void ReadDirectory();
  139.  
  140. private:
  141.  
  142.     time_t mtime;
  143.  
  144.     SymbolTable *table;
  145.     inline SymbolTable *Table();
  146.  
  147.     DirectoryTable *entries;
  148.     char *directory_name;
  149.     int directory_name_length;
  150. };
  151.  
  152.  
  153. class FileSymbol : public Symbol
  154. {
  155. private:
  156.     enum FileKind
  157.     {
  158.         JAVA,
  159.         CLASS,
  160.         CLASS_ONLY
  161.     };
  162.  
  163.     DirectorySymbol *output_directory;
  164.     char *file_name;
  165.     int file_name_length;
  166.     Utf8LiteralValue *file_name_literal;
  167.  
  168. public:
  169.     NameSymbol *name_symbol;
  170.     DirectorySymbol *directory_symbol;
  171.     PackageSymbol *package;
  172.     FileKind kind;
  173.  
  174.     //
  175.     // These fields are used for files in zip packages.
  176.     //
  177.     u4 uncompressed_size;
  178.     u4 date_time;
  179.     long offset;
  180.  
  181.     //
  182.     // This field holds the time of last data modification for a non-zip file
  183.     //
  184.     time_t mtime;
  185.  
  186.     LexStream *lex_stream;
  187.     AstCompilationUnit *compilation_unit;
  188.     Semantic *semantic;
  189.  
  190.     Tuple<TypeSymbol *> types;
  191.  
  192.     FileSymbol(NameSymbol *name_symbol_) : name_symbol(name_symbol_),
  193.                                            output_directory(NULL),
  194.                                            directory_symbol(NULL),
  195.                                            package(NULL),
  196.                                            file_name(NULL),
  197.                                            file_name_literal(NULL),
  198.                                            mtime(0),
  199.                                            lex_stream(NULL),
  200.                                            compilation_unit(NULL),
  201.                                            semantic(NULL),
  202.                                            types(4)
  203.     {
  204.          Symbol::_kind = _FILE;
  205.     }
  206.  
  207.     virtual ~FileSymbol()
  208.     {
  209.         delete [] file_name;
  210.         delete lex_stream;
  211.     }
  212.  
  213.     FileSymbol *Clone()
  214.     {
  215.         FileSymbol *clone = new FileSymbol(name_symbol);
  216.  
  217.         clone -> kind = kind;
  218.         clone -> directory_symbol = directory_symbol;
  219.         clone -> mtime = mtime;
  220.  
  221.         return clone;
  222.     }
  223.  
  224.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  225.     virtual int NameLength() { return name_symbol -> NameLength(); }
  226.     virtual NameSymbol *Identity() { return name_symbol; }
  227.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  228.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  229.  
  230.     inline void SetJava()       { kind = JAVA; }
  231.     inline void SetClass()      { kind = CLASS; }
  232.     inline void SetClassOnly()  { kind = CLASS_ONLY; }
  233.  
  234.     inline bool IsJava()       { return kind == JAVA; }
  235.     inline bool IsClass()      { return kind >= CLASS; }
  236.     inline bool IsClassOnly()  { return kind == CLASS_ONLY; }
  237.  
  238.     PathSymbol *PathSym()
  239.     {
  240.         return directory_symbol -> PathSym();
  241.     }
  242.     inline bool IsZip() { return PathSym() -> IsZip(); }
  243.     inline Zip *Zipfile() { return PathSym() -> zipfile; }
  244.  
  245.     static char *java_suffix;
  246.     static int java_suffix_length;
  247.     static char *class_suffix;
  248.     static int class_suffix_length;
  249.     static inline bool IsJavaSuffix(char *ptr);
  250.     static inline bool IsClassSuffix(char *ptr);
  251.  
  252.     inline char *FileName()
  253.     {
  254.         if (! file_name)
  255.             SetFileName();
  256.         return file_name;
  257.     }
  258.     inline int FileNameLength()
  259.     {
  260.         if (! file_name)
  261.             SetFileName();
  262.         return file_name_length;
  263.     }
  264.  
  265.     inline Utf8LiteralValue *FileNameLiteral() { assert(file_name_literal); return file_name_literal; }
  266.  
  267.     void SetFileNameLiteral(Control *);
  268.  
  269.     DirectorySymbol *OutputDirectory();
  270.  
  271.     void SetFileName();
  272.  
  273.     void CleanUp();
  274.  
  275.     void Reset()
  276.     {
  277.         CleanUp();
  278.  
  279.         delete [] file_name;
  280.         file_name = NULL;
  281.         types.Reset();
  282.     }
  283. };
  284.  
  285.  
  286. class FileLocation
  287. {
  288. public:
  289.     wchar_t *location;
  290.  
  291.     FileLocation (LexStream *lex_stream, LexStream::TokenIndex token_index)
  292.     {
  293.         char *file_name = lex_stream -> FileName();
  294.         int length = lex_stream -> FileNameLength();
  295.         location = new wchar_t[length + 13];
  296.         for (int i = 0; i < length; i++) {
  297.             location[i] = (wchar_t) file_name[i];
  298.         }
  299.         location[length++] = U_COLON;
  300.  
  301.         char str[13];
  302.         sprintf(str, "%i", lex_stream -> Line(token_index));
  303.         for (int j = 0; str[j]; j++)
  304.             location[length++] = str[j];
  305.         location[length] = U_NULL;
  306.  
  307.         return;
  308.     }
  309.  
  310.     FileLocation (FileSymbol *file_symbol)
  311.     {
  312.         char *file_name = file_symbol -> FileName();
  313.         int length = file_symbol -> FileNameLength();
  314.         location = new wchar_t[length + 13];
  315.         for (int i = 0; i < length; i++) {
  316.             location[i] = (wchar_t) file_name[i];
  317.         }
  318.         location[length] = U_NULL;
  319.  
  320.         return;
  321.     }
  322.  
  323.     ~FileLocation()
  324.     {
  325.         delete [] location;
  326.     }
  327. };
  328.  
  329.  
  330. class PackageSymbol : public Symbol
  331. {
  332. public:
  333.     Tuple<DirectorySymbol *> directory;
  334.     PackageSymbol *owner;
  335.  
  336.     PackageSymbol(NameSymbol *name_symbol_, PackageSymbol *owner_) : name_symbol(name_symbol_),
  337.                                                                      directory(4),
  338.                                                                      owner(owner_),
  339.                                                                      package_name(NULL),
  340.                                                                      table(NULL)
  341.     {
  342.         Symbol::_kind = PACKAGE;
  343.     }
  344.  
  345.     virtual ~PackageSymbol();
  346.  
  347.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  348.     virtual int NameLength() { return name_symbol -> NameLength(); }
  349.     virtual NameSymbol *Identity() { return name_symbol; }
  350.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  351.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  352.  
  353.     void SetPackageName();
  354.     wchar_t *PackageName()
  355.     {
  356.         if (! package_name)
  357.             SetPackageName();
  358.         return package_name;
  359.     }
  360.     int PackageNameLength()
  361.     {
  362.         if (! package_name)
  363.             SetPackageName();
  364.         return package_name_length;
  365.     }
  366.  
  367.     inline PackageSymbol *FindPackageSymbol(NameSymbol *);
  368.     inline PackageSymbol *InsertPackageSymbol(NameSymbol *);
  369.  
  370.     inline TypeSymbol *FindTypeSymbol(NameSymbol *);
  371.     inline TypeSymbol *InsertSystemTypeSymbol(NameSymbol *);
  372.     inline TypeSymbol *InsertOuterTypeSymbol(NameSymbol *);
  373.     inline void DeleteTypeSymbol(TypeSymbol *);
  374.  
  375. private:
  376.  
  377.     NameSymbol *name_symbol;
  378.     SymbolTable *table;
  379.     inline SymbolTable *Table();
  380.  
  381.     wchar_t *package_name;
  382.     int package_name_length;
  383. };
  384.  
  385.  
  386. class MethodSymbol : public Symbol, public AccessFlags
  387. {
  388. public:
  389.     Ast *method_or_constructor_declaration; // AstMethodDeclaration or AstConstructorDeclaration
  390.     NameSymbol *name_symbol;
  391.     TypeSymbol *containing_type;
  392.     BlockSymbol *block_symbol;
  393.     MethodSymbol *next_method;
  394.     Utf8LiteralValue *signature;
  395.  
  396.     //
  397.     // If this method is a method that is generated in order to process initializer
  398.     // blocks contained in the body of a class, it needs to know the set of
  399.     // constructors that might invoke it in order to figure out which exceptions
  400.     // can be safely thrown within an initializer block.
  401.     //
  402.     int NumInitializerConstructors()
  403.     {
  404.         return (initializer_constructors ? initializer_constructors -> Length() : 0);
  405.     }
  406.     MethodSymbol *InitializerConstructor(int i)
  407.     {
  408.         return (*initializer_constructors)[i];
  409.     }
  410.     void AddInitializerConstructor(MethodSymbol *method)
  411.     {
  412.         if (! initializer_constructors)
  413.             initializer_constructors = new Tuple<MethodSymbol *>(8);
  414.         initializer_constructors -> Next() = method;
  415.     }
  416.  
  417.     int max_block_depth,
  418.         constant_pool_index,
  419.         constant_pool_class;
  420.  
  421.     //
  422.     // If this method is a method that permits access to a private member of an
  423.     // enclosing type then accessed_member identifies the member in question.
  424.     //
  425.     Symbol *accessed_member;
  426.  
  427.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  428.     virtual int NameLength() { return name_symbol -> NameLength(); }
  429.     virtual NameSymbol *Identity() { return name_symbol; }
  430.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  431.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  432.  
  433.     MethodSymbol(NameSymbol *name_symbol_) : method_or_constructor_declaration(NULL),
  434.                                              name_symbol(name_symbol_),
  435.                                              external_name_symbol(NULL),
  436.                                              containing_type(NULL),
  437.                                              block_symbol(NULL),
  438.                                              next_method(NULL),
  439.                                              signature(NULL),
  440.                                              type_(NULL),
  441.                                              status(0),
  442.                                              header(NULL),
  443.                                              max_block_depth(1), // there must be at least one block in a method
  444.                                                                  // this default is useful for default constructors.
  445.                                              constant_pool_index(0),
  446.                                              constant_pool_class(0),
  447.                                              local_constructor(NULL),
  448.                                              accessed_member(NULL),
  449.                                              formal_parameters(NULL),
  450.                                              throws(NULL),
  451.                                              throws_signatures(NULL),
  452.                                              initializer_constructors(NULL)
  453.     {
  454.         Symbol::_kind = METHOD;
  455.     }
  456.  
  457.     virtual ~MethodSymbol();
  458.  
  459.     bool IsFinal();
  460.  
  461.     bool IsTyped()
  462.     {
  463.         return type_ != NULL;
  464.     }
  465.  
  466.     void SetType(TypeSymbol *_type)
  467.     {
  468.         type_ = _type;
  469.     }
  470.  
  471.     void ProcessMethodSignature(Semantic *, LexStream::TokenIndex);
  472.     void ProcessMethodThrows(Semantic *, LexStream::TokenIndex);
  473.  
  474.     TypeSymbol *Type()
  475.     {
  476.         assert(type_); // make sure that the method signature associated with this method is processed prior to invoking
  477.                        // this function. ( "this -> ProcessMethodSignature(sem, tok);" )
  478.  
  479.         return type_;
  480.     }
  481.  
  482.     int NumFormalParameters()
  483.     {
  484.         assert(type_);
  485.  
  486.         return (formal_parameters ? formal_parameters -> Length() : 0);
  487.     }
  488.     VariableSymbol *FormalParameter(int i)
  489.     {
  490.         return (*formal_parameters)[i];
  491.     }
  492.     void AddFormalParameter(VariableSymbol *variable)
  493.     {
  494.         if (! formal_parameters)
  495.             formal_parameters = new Tuple<VariableSymbol *>(8);
  496.         formal_parameters -> Next() = variable;
  497.     }
  498.  
  499.     int NumThrows()
  500.     {
  501.         assert(! throws_signatures);
  502.  
  503.         return (throws ? throws -> Length() : 0);
  504.     }
  505.     TypeSymbol *Throws(int i)
  506.     {
  507.         return (*throws)[i];
  508.     }
  509.     void AddThrows(TypeSymbol *exception)
  510.     {
  511.         if (! throws)
  512.             throws = new Tuple<TypeSymbol *>(8);
  513.         throws -> Next() = exception;
  514.     }
  515.  
  516.     int NumThrowsSignatures()
  517.     {
  518.         return (throws_signatures ? throws_signatures -> Length() : 0);
  519.     }
  520.     char *ThrowsSignature(int i)
  521.     {
  522.         return (*throws_signatures)[i];
  523.     }
  524.     void AddThrowsSignature(char *signature_, int length)
  525.     {
  526.         char *signature = new char[length + 1];
  527.         strncpy(signature, signature_, length);
  528.         signature[length] = U_NULL;
  529.  
  530.         if (! throws_signatures)
  531.             throws_signatures = new Tuple<char *>(8);
  532.         throws_signatures -> Next() = signature;
  533.     }
  534.  
  535.     void SetGeneratedLocalConstructor(MethodSymbol *base_method)
  536.     {
  537.         assert(! base_method -> local_constructor);
  538.  
  539.         base_method -> local_constructor = this;
  540.         this -> local_constructor = base_method;
  541.     }
  542.     bool IsGeneratedLocalConstructor() { return ((local_constructor != NULL) && (this -> external_name_symbol == NULL)); }
  543.     MethodSymbol *LocalConstructor()  { return local_constructor; }
  544.  
  545.     void SetExternalIdentity(NameSymbol *external_name_symbol_) { external_name_symbol = external_name_symbol_; }
  546.     NameSymbol *ExternalIdentity()
  547.     {
  548.         return (external_name_symbol ? external_name_symbol : name_symbol);
  549.     }
  550.     wchar_t *ExternalName()
  551.     {
  552.         return (external_name_symbol ? external_name_symbol -> Name() : name_symbol -> Name());
  553.     }
  554.     int ExternalNameLength()
  555.     {
  556.         return (external_name_symbol ? external_name_symbol -> NameLength() : name_symbol -> NameLength());
  557.     }
  558.     char *ExternalUtf8Name()
  559.     {
  560.         return (char *) (external_name_symbol ? external_name_symbol -> Utf8_literal -> value
  561.                                               : (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL));
  562.     }
  563.     int ExternalUtf8NameLength()
  564.     {
  565.         return (external_name_symbol ? (external_name_symbol -> Utf8_literal ? external_name_symbol -> Utf8_literal -> length : 0)
  566.                                      : (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0));
  567.     }
  568.  
  569.     void SetContainingType(TypeSymbol *containing_type_) { containing_type = containing_type_; }
  570.     void SetBlockSymbol(BlockSymbol *block_symbol_) { block_symbol = block_symbol_; }
  571.     void SetSignature(Control &, VariableSymbol * = NULL);
  572.     void SetSignature(Utf8LiteralValue *signature_) { signature = signature_; }
  573.     char *SignatureString() { return signature -> value; }
  574.     wchar_t *Header();
  575.  
  576.     void CleanUp();
  577.  
  578.     void MarkSynthetic() { status |= (unsigned char) 0x08; }
  579.     bool IsSynthetic()   { return (status & (unsigned char) 0x08) != 0; }
  580.  
  581.     void MarkDeprecated() { status |= (unsigned char) 0x10; }
  582.     bool IsDeprecated()   { return (status & (unsigned char) 0x10) != 0; }
  583.  
  584. private:
  585.     NameSymbol *external_name_symbol;
  586.  
  587.     unsigned char status;
  588.     wchar_t *header;
  589.  
  590.     TypeSymbol *type_;
  591.     Tuple<VariableSymbol *> *formal_parameters;
  592.     Tuple<TypeSymbol *> *throws;
  593.     Tuple<char *> *throws_signatures;
  594.     Tuple<MethodSymbol *> *initializer_constructors;
  595.  
  596.     //
  597.     // If the method in question is a constructor of a local type, we may need to construct
  598.     // another constructor that accepts extra local parameters.
  599.     //
  600.     MethodSymbol *local_constructor;
  601.  
  602.     bool ACC_FINAL()
  603.     {
  604.         assert(! "use the ACC_FINAL() flag on a method symbol. Use the function IsFinal() instead");
  605.  
  606.         return false;
  607.     }
  608. };
  609.  
  610.  
  611. class TypeSymbol : public Symbol, public AccessFlags
  612. {
  613. public:
  614.     SemanticEnvironment *semantic_environment;
  615.     Ast *declaration;  // AstClassDeclaration or AstInterfaceDeclaration
  616.     FileSymbol *file_symbol;
  617.     FileLocation *file_location;
  618.     NameSymbol *name_symbol;
  619.     Symbol *owner;
  620.     TypeSymbol *outermost_type; // An nested class identifies the outer most type that contains it.
  621.                                 // If a class is not nested then it identifies itself as its outer
  622.                                 // most type.
  623.     TypeSymbol *super,
  624.                *base_type; // indicates the base type (type of elements in the last dimension) of an array
  625.                            // For a normal type base_type is NULL. If base_type is a "bad" type it points
  626.                            // to itself (this).
  627.     int index,             // This variable is used in TypeCycleChecker to determine if this type
  628.                            // forms an inter-type cycle in its "extends" or "implements" relationship.
  629.                            //
  630.         unit_index,        // This variable is used in TypeCycleChecker to check if this type
  631.                            // forms an intra-type cycle in its "extends" or "implements" relationship;
  632.                            //
  633.         incremental_index; // This variable is used in TypeCycleChecker to determine which types (files)
  634.                            // need to be recompiled based on the "dependent" relationship.
  635.  
  636.     int NumLocalConstructorCallEnvironments() { return (local_constructor_call_environments ? local_constructor_call_environments -> Length() : 0); }
  637.     SemanticEnvironment *&LocalConstructorCallEnvironment(int i) { return (*local_constructor_call_environments)[i]; }
  638.     void AddLocalConstructorCallEnvironment(SemanticEnvironment *environment)
  639.     {
  640.         if (! local_constructor_call_environments)
  641.             local_constructor_call_environments = new Tuple<SemanticEnvironment *>(8);
  642.         local_constructor_call_environments -> Next() = environment;
  643.     }
  644.  
  645.     int NumPrivateAccessMethods() { return (private_access_methods ? private_access_methods -> Length() : 0); }
  646.     MethodSymbol *&PrivateAccessMethod(int i) { return (*private_access_methods)[i]; }
  647.     void AddPrivateAccessMethod(MethodSymbol *method_symbol)
  648.     {
  649.         if (! private_access_methods)
  650.             private_access_methods = new Tuple<MethodSymbol *>(8);
  651.         private_access_methods -> Next() = method_symbol;
  652.     }
  653.  
  654.     int NumPrivateAccessConstructors() { return (private_access_constructors ? private_access_constructors -> Length() : 0); }
  655.     MethodSymbol *&PrivateAccessConstructor(int i) { return (*private_access_constructors)[i]; }
  656.     void AddPrivateAccessConstructor(MethodSymbol *constructor_symbol)
  657.     {
  658.         if (! private_access_constructors)
  659.             private_access_constructors = new Tuple<MethodSymbol *>(8);
  660.         private_access_constructors -> Next() = constructor_symbol;
  661.     }
  662.  
  663.     int NumConstructorParameters() { return (constructor_parameters ? constructor_parameters -> Length() : 0); }
  664.     VariableSymbol *&ConstructorParameter(int i) { return (*constructor_parameters)[i]; }
  665.     void AddConstructorParameter(VariableSymbol *variable_symbol)
  666.     {
  667.         if (! constructor_parameters)
  668.             constructor_parameters = new Tuple<VariableSymbol *>(8);
  669.         constructor_parameters -> Next() = variable_symbol;
  670.     }
  671.  
  672.     int NumGeneratedConstructors() { return (generated_constructors ? generated_constructors -> Length() : 0); }
  673.     MethodSymbol *&GeneratedConstructor(int i) { return (*generated_constructors)[i]; }
  674.     void AddGeneratedConstructor(MethodSymbol *constructor_symbol)
  675.     {
  676.         if (! generated_constructors)
  677.             generated_constructors = new Tuple<MethodSymbol *>(8);
  678.         generated_constructors -> Next() = constructor_symbol;
  679.     }
  680.  
  681.     int NumEnclosingInstances() { return (enclosing_instances ? enclosing_instances -> Length() : 0); }
  682.     VariableSymbol *&EnclosingInstance(int i) { return (*enclosing_instances)[i]; }
  683.     void AddEnclosingInstance(VariableSymbol *instance_symbol)
  684.     {
  685.         if (! enclosing_instances)
  686.             enclosing_instances = new Tuple<VariableSymbol *>(8);
  687.         enclosing_instances -> Next() = instance_symbol;
  688.     }
  689.  
  690.     int NumClassLiterals() { return (class_literals ? class_literals -> Length() : 0); }
  691.     VariableSymbol *&ClassLiteral(int i) { return (*class_literals)[i]; }
  692.     void AddClassLiteral(VariableSymbol *literal_symbol)
  693.     {
  694.         if (! class_literals)
  695.             class_literals = new Tuple<VariableSymbol *>(8);
  696.         class_literals -> Next() = literal_symbol;
  697.     }
  698.  
  699.     int NumNestedTypes() { return (nested_types ? nested_types -> Length() : 0); }
  700.     TypeSymbol *&NestedType(int i) { return (*nested_types)[i]; }
  701.     void AddNestedType(TypeSymbol *type_symbol)
  702.     {
  703.         if (! nested_types)
  704.             nested_types = new Tuple<TypeSymbol *>(8);
  705.         nested_types -> Next() = type_symbol;
  706.     }
  707.  
  708.     int NumInterfaces() { return (interfaces ? interfaces -> Length() : 0); }
  709.     void ResetInterfaces()
  710.     {
  711.         delete interfaces;
  712.         interfaces = NULL;
  713.     }
  714.     TypeSymbol *Interface(int i) { return (*interfaces)[i]; }
  715.     void AddInterface(TypeSymbol *type_symbol)
  716.     {
  717.         if (! interfaces)
  718.             interfaces = new Tuple<TypeSymbol *>(8);
  719.         interfaces -> Next() = type_symbol;
  720.     }
  721.  
  722.     int num_anonymous_types() { return (anonymous_types ? anonymous_types -> Length() : 0); }
  723.     TypeSymbol *&AnonymousType(int i) { return (*anonymous_types)[i]; }
  724.     void AddAnonymousType(TypeSymbol *type_symbol)
  725.     {
  726.         if (! anonymous_types)
  727.             anonymous_types = new Tuple<TypeSymbol *>(8);
  728.         anonymous_types -> Next() = type_symbol;
  729.     }
  730.     void DeleteAnonymousTypes();
  731.  
  732.     SymbolSet *local,
  733.               *non_local;
  734.  
  735.     SymbolSet *supertypes_closure,
  736.               *subtypes,
  737.               *subtypes_closure,
  738.               *innertypes_closure;
  739.  
  740.     SymbolSet *dependents,
  741.               *parents,
  742.               *static_parents,
  743.               *dependents_closure,  // processed in cycle.cpp
  744.               *parents_closure;     // processed in cycle.cpp
  745.  
  746.     int pool_index; // index of element in symbol_pool (in the relevant symbol table) that points to this type
  747.  
  748.     Utf8LiteralValue *signature;
  749.     Utf8LiteralValue *fully_qualified_name;
  750.  
  751.     ExpandedTypeTable *expanded_type_table;
  752.     ExpandedFieldTable *expanded_field_table;
  753.     ExpandedMethodTable *expanded_method_table;
  754.  
  755.     int num_dimensions;
  756.  
  757.     MethodSymbol *static_initializer_method;
  758.     MethodSymbol *block_initializer_method;
  759.  
  760.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  761.     virtual int NameLength() { return name_symbol -> NameLength(); }
  762.     virtual NameSymbol *Identity() { return name_symbol; }
  763.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  764.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  765.  
  766.     void SetExternalIdentity(NameSymbol *external_name_symbol_) { external_name_symbol = external_name_symbol_; }
  767.     NameSymbol *ExternalIdentity()
  768.     {
  769.         return (external_name_symbol ? external_name_symbol : name_symbol);
  770.     }
  771.     wchar_t *ExternalName()
  772.     {
  773.         return (external_name_symbol ? external_name_symbol -> Name() : name_symbol -> Name());
  774.     }
  775.     int ExternalNameLength()
  776.     {
  777.         return (external_name_symbol ? external_name_symbol -> NameLength() : name_symbol -> NameLength());
  778.     }
  779.     char *ExternalUtf8Name()
  780.     {
  781.         return (char *) (external_name_symbol ? external_name_symbol -> Utf8_literal -> value
  782.                                               : (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL));
  783.     }
  784.     int ExternalUtf8NameLength()
  785.     {
  786.         return (external_name_symbol ? (external_name_symbol -> Utf8_literal ? external_name_symbol -> Utf8_literal -> length : 0)
  787.                                      : (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0));
  788.     }
  789.  
  790.     TypeSymbol(NameSymbol *);
  791.     virtual ~TypeSymbol();
  792.  
  793.     void ProcessTypeHeaders();
  794.     void ProcessMembers();
  795.     void CompleteSymbolTable();
  796.     void ProcessExecutableBodies();
  797.     void RemoveCompilationReferences();
  798.  
  799.     NameSymbol *GetThisName(Control &, int);
  800.  
  801.     VariableSymbol *FindThis(int k)
  802.     {
  803.         assert(IsInner());
  804.         assert(NumConstructorParameters() > 0);
  805.  
  806.         return (k == 0 ? ConstructorParameter(0)
  807.                        : (VariableSymbol *) (NumEnclosingInstances() > k ? EnclosingInstance(k) : NULL));
  808.     }
  809.     VariableSymbol *InsertThis(int k);
  810.  
  811.     TypeSymbol *FindOrInsertClassLiteralClass(LexStream::TokenIndex);
  812.     TypeSymbol *ClassLiteralClass()
  813.     {
  814.         return class_literal_class;
  815.     }
  816.     MethodSymbol *FindOrInsertClassLiteralMethod(Control &);
  817.     MethodSymbol *ClassLiteralMethod()
  818.     {
  819.         return class_literal_method;
  820.     }
  821.     Utf8LiteralValue *FindOrInsertClassLiteralName(Control &);
  822.     Utf8LiteralValue *ClassLiteralName()
  823.     {
  824.         return class_literal_name;
  825.     }
  826.     VariableSymbol *FindOrInsertClassLiteral(TypeSymbol *);
  827.     VariableSymbol *FindOrInsertLocalShadow(VariableSymbol *);
  828.  
  829.     static MethodSymbol *GetReadAccessMethod(MethodSymbol *);
  830.     static MethodSymbol *GetReadAccessMethod(VariableSymbol *);
  831.     static MethodSymbol *GetWriteAccessMethod(VariableSymbol *);
  832.  
  833.     bool IsArray() { return (num_dimensions > 0); }
  834.  
  835.     void SetOwner(Symbol *owner_) { owner = owner_; }
  836.     bool IsOwner(TypeSymbol *type)
  837.     {
  838.         Symbol *sym = type -> owner;
  839.         while (! sym -> PackageCast())
  840.         {
  841.             if (sym == this)
  842.                 return true;
  843.  
  844.             MethodSymbol *method = sym -> MethodCast();
  845.             sym = (method ? method -> containing_type : ((TypeSymbol *) sym) -> owner);
  846.         }
  847.  
  848.         return false;
  849.     }
  850.  
  851.     TypeSymbol *ContainingType()
  852.     {
  853.         if (owner)
  854.         {
  855.             TypeSymbol *type = owner -> TypeCast();
  856.             if (type)
  857.                 return type;
  858.             MethodSymbol *method = owner -> MethodCast();
  859.             if (method)
  860.                 return method -> containing_type;
  861.         }
  862.  
  863.         return NULL;
  864.     }
  865.  
  866.     bool CanAccess(TypeSymbol *);
  867.  
  868.     bool HasProtectedAccessTo(TypeSymbol *);
  869.  
  870.     bool IsSubclass(TypeSymbol *super_class)
  871.     {
  872.         return (this == super_class ? true : (super == NULL ? false : super -> IsSubclass(super_class)));
  873.     }
  874.  
  875.     bool IsSubinterface(TypeSymbol *super_interface)
  876.     {
  877.         if (this == super_interface)
  878.             return true;
  879.         for (int i = 0; i < NumInterfaces(); i++)
  880.         {
  881.             if (Interface(i) -> IsSubinterface(super_interface))
  882.                 return true;
  883.         }
  884.         return false;
  885.     }
  886.  
  887.     bool Implements(TypeSymbol *inter)
  888.     {
  889.         for (int i = 0; i < NumInterfaces(); i++)
  890.         {
  891.             if (Interface(i) -> IsSubinterface(inter))
  892.                 return true;
  893.         }
  894.         return (this -> super ? this -> super -> Implements(inter) : false);
  895.     }
  896.  
  897.     wchar_t *FileLoc()
  898.     {
  899.         return (wchar_t *) (file_location ? file_location -> location : NULL);
  900.     }
  901.  
  902.     void SetLocation();
  903.  
  904.     TypeSymbol *GetArrayType(Semantic *, int);
  905.  
  906.     TypeSymbol *ArraySubtype()
  907.     {
  908.         return this -> base_type -> Array(this -> num_dimensions - 1);
  909.     }
  910.  
  911.     void SetSignature(Control &);
  912.     void SetSignature(Utf8LiteralValue *signature_) { signature = signature_; }
  913.     char *SignatureString() { return signature -> value; }
  914.  
  915.     void SetClassLiteralName(Utf8LiteralValue *class_literal_name_) { class_literal_name = class_literal_name_; }
  916.  
  917.     PackageSymbol *ContainingPackage() { return outermost_type -> owner -> PackageCast(); }
  918.  
  919.     bool IsNestedIn(TypeSymbol *);
  920.  
  921.     bool IsNested() { return outermost_type != this; }
  922.  
  923.     bool IsTopLevel() { return (! IsNested()) || this -> ACC_STATIC(); }
  924.  
  925.     bool IsInner() { return (! IsTopLevel()); }
  926.  
  927.     bool IsLocal()
  928.     {
  929.         for (Symbol *sym = owner; ! sym -> PackageCast(); sym = ((TypeSymbol *) sym) -> owner)
  930.         {
  931.             if (sym -> MethodCast())
  932.                 return true;
  933.         }
  934.  
  935.         return false;
  936.     }
  937.  
  938.     inline char *ClassName()
  939.     {
  940.         if (! class_name)
  941.             SetClassName();
  942.         return class_name;
  943.     }
  944.  
  945.     void MarkConstructorMembersProcessed() { status |= (unsigned short) 0x0001; }
  946.     bool ConstructorMembersProcessed() { return (status & (unsigned short) 0x0001) != 0 ; }
  947.  
  948.     void MarkMethodMembersProcessed() { status |= (unsigned short) 0x0002; }
  949.     bool MethodMembersProcessed() { return (status & (unsigned short) 0x0002) != 0; }
  950.  
  951.     void MarkFieldMembersProcessed() { status |= (unsigned short) 0x0004; }
  952.     bool FieldMembersProcessed() { return (status & (unsigned short) 0x0004) != 0; }
  953.  
  954.     void MarkLocalClassProcessingCompleted() { status |= (unsigned short) 0x0008; }
  955.     bool LocalClassProcessingCompleted() { return (status & (unsigned short) 0x0008) != 0; }
  956.  
  957.     void MarkSourcePending() { status |= (unsigned short) 0x0010; }
  958.     void MarkSourceNoLongerPending() { status &= (~ ((unsigned short) 0x0010)); }
  959.     bool SourcePending() { return (status & (unsigned short) 0x0010) != 0; }
  960.  
  961.     void MarkAnonymous() { status |= (unsigned short) 0x0020; }
  962.     bool Anonymous() { return (status & (unsigned short) 0x0020) != 0; }
  963.  
  964.     void MarkHeaderProcessed() { status |= (unsigned short) 0x0040; }
  965.     bool HeaderProcessed() { return (status & (unsigned short) 0x0040) != 0; }
  966.  
  967.     void MarkPrimitive() { status |= (unsigned short) 0x0080; }
  968.     bool Primitive()     { return (status & (unsigned short) 0x0080) != 0; }
  969.  
  970.     void MarkDeprecated() { status |= (unsigned short) 0x0100; }
  971.     bool IsDeprecated()   { return (status & (unsigned short) 0x0100) != 0; }
  972.  
  973.     void MarkBad()
  974.     {
  975.         SetACC_PUBLIC();
  976.  
  977.         status |= (unsigned short) 0x0200;
  978.  
  979.         MarkHeaderProcessed();
  980.         MarkConstructorMembersProcessed();
  981.         MarkMethodMembersProcessed();
  982.         MarkFieldMembersProcessed();
  983.         MarkLocalClassProcessingCompleted();
  984.         MarkSourceNoLongerPending();
  985.  
  986.         return;
  987.     }
  988.     bool Bad() { return (status & (unsigned short) 0x0200) != 0; }
  989.  
  990.     void MarkCircular()
  991.     {
  992.         status |= (unsigned short) 0x0400;
  993.         MarkBad();
  994.         return;
  995.     }
  996.     void MarkNonCircular() { status &= (~ ((unsigned short) 0x0400)); }
  997.     bool Circular() { return (status & (unsigned short) 0x0400) != 0; }
  998.  
  999.     void ProcessNestedTypeSignatures(Semantic *, LexStream::TokenIndex);
  1000.  
  1001.     bool NestedTypesProcessed() { return nested_type_signatures == NULL; }
  1002.  
  1003.     int NumNestedTypeSignatures()
  1004.     {
  1005.         return (nested_type_signatures ? nested_type_signatures -> Length() : 0);
  1006.     }
  1007.     char *NestedTypeSignature(int i)
  1008.     {
  1009.         return (*nested_type_signatures)[i];
  1010.     }
  1011.     void AddNestedTypeSignature(char *signature_, int length)
  1012.     {
  1013.         char *signature = new char[length + 1];
  1014.         strncpy(signature, signature_, length);
  1015.         signature[length] = U_NULL;
  1016.  
  1017.         if (! nested_type_signatures)
  1018.             nested_type_signatures = new Tuple<char *>(8);
  1019.         nested_type_signatures -> Next() = signature;
  1020.     }
  1021.  
  1022.     inline void SetSymbolTable(int);
  1023.     inline SymbolTable *Table();
  1024.  
  1025.     int NumVariableSymbols();
  1026.     VariableSymbol *VariableSym(int);
  1027.  
  1028.     int NumMethodSymbols();
  1029.     MethodSymbol *MethodSym(int);
  1030.  
  1031.     int NumTypeSymbols();
  1032.     TypeSymbol *TypeSym(int);
  1033.  
  1034.     inline TypeSymbol *InsertAnonymousTypeSymbol(NameSymbol *);
  1035.     inline TypeSymbol *FindTypeSymbol(NameSymbol *);
  1036.     inline TypeSymbol *InsertNestedTypeSymbol(NameSymbol *);
  1037.     inline MethodSymbol *FindConstructorSymbol();
  1038.     inline MethodSymbol *InsertConstructorSymbol(NameSymbol *);
  1039.     inline void InsertConstructorSymbol(MethodSymbol *);
  1040.     inline MethodSymbol *FindMethodSymbol(NameSymbol *);
  1041.     inline VariableSymbol *FindVariableSymbol(NameSymbol *);
  1042.     inline VariableSymbol *InsertVariableSymbol(NameSymbol *);
  1043.     inline void InsertVariableSymbol(VariableSymbol *);
  1044.  
  1045.     inline MethodSymbol *InsertMethodSymbol(NameSymbol *);
  1046.     inline void InsertMethodSymbol(MethodSymbol *);
  1047.     inline MethodSymbol *Overload(MethodSymbol *);
  1048.     inline void Overload(MethodSymbol *, MethodSymbol *);
  1049.     inline MethodSymbol *LocalConstructorOverload(MethodSymbol *);
  1050.     MethodSymbol *FindOverloadMethod(MethodSymbol *, AstMethodDeclarator *);
  1051.  
  1052.     inline void CompressSpace();
  1053.  
  1054. private:
  1055.     //
  1056.     // The fields hash_address and next_type are used in the class TypeLookupTable
  1057.     // to contruct a mapping from each fully_qualified name into the type that it defines.
  1058.     //
  1059.     friend TypeLookupTable;
  1060.     unsigned hash_address;
  1061.     TypeSymbol *next_type;
  1062.  
  1063.     NameSymbol *external_name_symbol;
  1064.  
  1065.     SymbolTable *table;
  1066.     SymbolMap *local_shadow_map;
  1067.  
  1068.     unsigned short status;
  1069.  
  1070.     PackageSymbol *package;
  1071.     char *class_name;
  1072.  
  1073.     void SetClassName();
  1074.  
  1075.     TypeSymbol *class_literal_class;
  1076.     MethodSymbol *class_literal_method;
  1077.     Utf8LiteralValue *class_literal_name;
  1078.  
  1079.     //
  1080.     // For a local type, when we first encounter an embedded call
  1081.     // to one of its constructors or a constructor of one of its inner
  1082.     // types, either via a ClassInstanceCreation or an ExplicitConstructorInvocation,
  1083.     // we record it and resolve it after we have computed all necessary
  1084.     // information about the type and its inner types.
  1085.     //
  1086.     Tuple<SemanticEnvironment *> *local_constructor_call_environments;
  1087.  
  1088.     //
  1089.     // When an inner class tries to access a private member of one of its enclosing
  1090.     // classes, one (or two) access method(s) to read (and/or write) the private member
  1091.     // is (are) generated.
  1092.     //
  1093.     // The maps read_method and write_method are used to keep track of the read and
  1094.     // write method to which a member has been mapped.
  1095.     //
  1096.     Tuple<MethodSymbol *> *private_access_methods,
  1097.                           *private_access_constructors;
  1098.  
  1099.     inline void MapSymbolToReadMethod(Symbol *, MethodSymbol *);
  1100.     inline MethodSymbol *ReadMethod(Symbol *);
  1101.     inline void MapSymbolToWriteMethod(VariableSymbol *, MethodSymbol *);
  1102.     inline MethodSymbol *WriteMethod(VariableSymbol *);
  1103.  
  1104.     SymbolMap *read_method,
  1105.               *write_method;
  1106.  
  1107.     //
  1108.     // For an accessible inner class the first elememt in this array
  1109.     // identifies the "this$0" pointer of the containing type. For a local
  1110.     // class, in addition to the this$0 pointer (if it is needed), all local
  1111.     // variables that are referred to in the local type are passed as argument
  1112.     // to the local type and copied in the constructor into a local field. These
  1113.     // local variables are stored in constructor_parameters.
  1114.     //
  1115.     // The array enclosing_instances is there for optimization purposes.
  1116.     // If this type is deeply nested within several other types and it makes
  1117.     // references to members in the enclosing types, then it might
  1118.     // be useful to keep a reference to each of these enclosing
  1119.     // instances in the form of this$0, this$1, this$2, ...
  1120.     //
  1121.     // The array class_identities is used to store static variables of type Class
  1122.     // that contain the proper value for a given type.
  1123.     //
  1124.     Tuple<VariableSymbol *> *constructor_parameters;
  1125.     Tuple<MethodSymbol *> *generated_constructors;
  1126.     Tuple<VariableSymbol *> *enclosing_instances;
  1127.     Tuple<VariableSymbol *> *class_literals;
  1128.  
  1129.     Tuple<char *> *nested_type_signatures;
  1130.  
  1131.     //
  1132.     // The inner types that appear immediately within this type in the order
  1133.     // in which they should be processed (compiled).
  1134.     Tuple<TypeSymbol *> *nested_types;
  1135.  
  1136.     //
  1137.     // The interfaces that were declared in the header of the type.
  1138.     //
  1139.     Tuple<TypeSymbol *> *interfaces;
  1140.  
  1141.     //
  1142.     // The anonymous types that were declared in this type.
  1143.     //
  1144.     Tuple<TypeSymbol *> *anonymous_types;
  1145.  
  1146.     //
  1147.     // The arrays of this type that were declared.
  1148.     //
  1149.     Tuple<TypeSymbol *> *array;
  1150.     inline int NumArrays()
  1151.     {
  1152.         return (array ? array -> Length() : 0);
  1153.     }
  1154.     inline TypeSymbol *Array(int i)
  1155.     {
  1156.         return (*array)[i];
  1157.     }
  1158.     inline void AddArrayType(TypeSymbol *type_symbol)
  1159.     {
  1160.         if (! array)
  1161.             array = new Tuple<TypeSymbol *>(4);
  1162.         array -> Next() = type_symbol;
  1163.     }
  1164. };
  1165.  
  1166.  
  1167. class VariableSymbol : public Symbol, public AccessFlags
  1168. {
  1169. public:
  1170.     AstVariableDeclarator *declarator;
  1171.  
  1172.     NameSymbol *name_symbol;
  1173.     Symbol     *owner;
  1174.     LiteralValue *initial_value;
  1175.     int constant_pool_index,
  1176.         constant_pool_class,
  1177.         local_program_counter;
  1178.  
  1179.     VariableSymbol *accessed_local;
  1180.  
  1181.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  1182.     virtual int NameLength() { return name_symbol -> NameLength(); }
  1183.     virtual NameSymbol *Identity() { return name_symbol; }
  1184.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  1185.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  1186.  
  1187.     void SetExternalIdentity(NameSymbol *external_name_symbol_) { external_name_symbol = external_name_symbol_; }
  1188.     NameSymbol *ExternalIdentity()
  1189.     {
  1190.         return (external_name_symbol ? external_name_symbol : name_symbol);
  1191.     }
  1192.     wchar_t *ExternalName()
  1193.     {
  1194.         return (external_name_symbol ? external_name_symbol -> Name() : name_symbol -> Name());
  1195.     }
  1196.     int ExternalNameLength()
  1197.     {
  1198.         return (external_name_symbol ? external_name_symbol -> NameLength() : name_symbol -> NameLength());
  1199.     }
  1200.     char *ExternalUtf8Name()
  1201.     {
  1202.         return (char *) (external_name_symbol ? external_name_symbol -> Utf8_literal -> value
  1203.                                               : (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL));
  1204.     }
  1205.     int ExternalUtf8NameLength()
  1206.     {
  1207.         return (external_name_symbol ? (external_name_symbol -> Utf8_literal ? external_name_symbol -> Utf8_literal -> length : 0)
  1208.                                      : (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0));
  1209.     }
  1210.  
  1211.     VariableSymbol(NameSymbol *name_symbol_) : declarator(NULL),
  1212.                                                name_symbol(name_symbol_),
  1213.                                                external_name_symbol(NULL),
  1214.                                                owner(NULL),
  1215.                                                type_(NULL),
  1216.                                                signature_string(NULL),
  1217.                                                initial_value(NULL),
  1218.                                                local_variable_index_(-1),
  1219.                                                constant_pool_index(0),
  1220.                                                constant_pool_class(0),
  1221.                                                local_program_counter(0),
  1222.                                                accessed_local(NULL),
  1223.                                                status(0)
  1224.     {
  1225.         Symbol::_kind = VARIABLE;
  1226.     }
  1227.  
  1228.     virtual ~VariableSymbol() { delete [] signature_string; }
  1229.  
  1230.     void SetOwner(Symbol *owner_) { owner = owner_; }
  1231.  
  1232.     void SetLocalVariableIndex(int index)
  1233.     {
  1234.         local_variable_index_ = index;
  1235.         MarkComplete();
  1236.     }
  1237.     int LocalVariableIndex() { return local_variable_index_; }
  1238.  
  1239.     bool IsTyped()
  1240.     {
  1241.         return type_ != NULL;
  1242.     }
  1243.  
  1244.     void SetType(TypeSymbol *_type)
  1245.     {
  1246.         type_ = _type;
  1247.     }
  1248.  
  1249.     void ProcessVariableSignature(Semantic *, LexStream::TokenIndex);
  1250.  
  1251.     TypeSymbol *Type()
  1252.     {
  1253.         assert(type_); // make sure that the method signature associated with this method is processed prior to invoking
  1254.                        // this function. ( "this -> ProcessVariableSignature(sem, tok);" )
  1255.  
  1256.         return type_;
  1257.     }
  1258.  
  1259.     void SetSignatureString(char *signature_, int length)
  1260.     {
  1261.         signature_string = new char[length + 1];
  1262.         strncpy(signature_string, signature_, length);
  1263.         signature_string[length] = U_NULL;
  1264.     }
  1265.  
  1266.     bool IsLocal()                     { return owner -> MethodCast() != NULL; }           // is variable a local variable?
  1267.     bool IsLocal(MethodSymbol *method) { return owner == method; } // is variable local to a particular method ?
  1268.     bool IsFinal(TypeSymbol *type)     { return (owner == type && ACC_FINAL()); }
  1269.  
  1270.     //
  1271.     // These functions are used to identify when the declaration of a field in the body of a class is
  1272.     // complete.
  1273.     //
  1274.     void MarkIncomplete()         { status &= (~((unsigned char) 0x01)); }
  1275.     void MarkComplete()           { status |= (unsigned char) 0x01; }
  1276.     bool IsDeclarationComplete()  { return (status & (unsigned char) 0x01) != 0; }
  1277.  
  1278.     void MarkNotDefinitelyAssigned() { status &= (~((unsigned char) 0x02)); }
  1279.     void MarkDefinitelyAssigned()    { status |= (unsigned char) 0x02; }
  1280.     bool IsDefinitelyAssigned()      { return (status & (unsigned char) 0x02) != 0; }
  1281.  
  1282.     void MarkPossiblyAssigned() { status |= (unsigned char) 0x04; }
  1283.     bool IsPossiblyAssigned()   { return (status & (unsigned char) 0x04) != 0; }
  1284.  
  1285.     void MarkSynthetic() { status |= (unsigned char) 0x08; }
  1286.     bool IsSynthetic()   { return (status & (unsigned char) 0x08) != 0; }
  1287.  
  1288.     void MarkDeprecated() { status |= (unsigned char) 0x10; }
  1289.     bool IsDeprecated()   { return (status & (unsigned char) 0x10) != 0; }
  1290.  
  1291. private:
  1292.     NameSymbol *external_name_symbol;
  1293.  
  1294.     unsigned char status;
  1295.     int local_variable_index_;
  1296.     TypeSymbol *type_;
  1297.     char *signature_string;
  1298. };
  1299.  
  1300.  
  1301. class BlockSymbol : public Symbol
  1302. {
  1303. public:
  1304.     int max_variable_index,
  1305.         synchronized_variable_index,
  1306.         try_variable_index;
  1307.  
  1308.     BlockSymbol(int hash_size);
  1309.     virtual ~BlockSymbol();
  1310.  
  1311.     int NumVariableSymbols();
  1312.     VariableSymbol *VariableSym(int);
  1313.  
  1314.     inline VariableSymbol *FindVariableSymbol(NameSymbol *);
  1315.     inline VariableSymbol *InsertVariableSymbol(NameSymbol *);
  1316.     inline void InsertVariableSymbol(VariableSymbol *);
  1317.     inline BlockSymbol *InsertBlockSymbol(int);
  1318.  
  1319.     inline void CompressSpace();
  1320.  
  1321.     inline SymbolTable *Table();
  1322.  
  1323. private:
  1324.  
  1325.     SymbolTable *table;
  1326. };
  1327.  
  1328.  
  1329. class LabelSymbol : public Symbol
  1330. {
  1331. public:
  1332.     AstBlock *block; // the block that is labeled by this symbol
  1333.     NameSymbol *name_symbol;
  1334.  
  1335.     int nesting_level;
  1336.  
  1337.     virtual wchar_t *Name() { return name_symbol -> Name(); }
  1338.     virtual int NameLength() { return name_symbol -> NameLength(); }
  1339.     virtual NameSymbol *Identity() { return name_symbol; }
  1340.     char *Utf8Name() { return (char *) (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> value : NULL); }
  1341.     int Utf8NameLength() { return (name_symbol -> Utf8_literal ? name_symbol -> Utf8_literal -> length : 0); }
  1342.  
  1343.     LabelSymbol(NameSymbol *name_symbol_) : block(NULL),
  1344.                                             nesting_level(0),
  1345.                                             name_symbol(name_symbol_)
  1346.     {
  1347.         Symbol::_kind = LABEL;
  1348.     }
  1349.  
  1350.     virtual ~LabelSymbol() {}
  1351.  
  1352. private:
  1353. };
  1354.  
  1355.  
  1356. class SymbolTable
  1357. {
  1358. public:
  1359.     enum
  1360.     {
  1361.         DEFAULT_HASH_SIZE = 13,
  1362.         MAX_HASH_SIZE = 1021
  1363.     };
  1364.  
  1365.     int NumAnonymousSymbols()
  1366.     {
  1367.         return (anonymous_symbol_pool ? anonymous_symbol_pool -> Length() : 0);
  1368.     }
  1369.     TypeSymbol *AnonymousSym(int i)
  1370.     {
  1371.         return (*anonymous_symbol_pool)[i];
  1372.     }
  1373.     void AddAnonymousSymbol(TypeSymbol *symbol)
  1374.     {
  1375.         if (! anonymous_symbol_pool)
  1376.             anonymous_symbol_pool = new ConvertibleArray<TypeSymbol *>(256);
  1377.         anonymous_symbol_pool -> Next() = symbol;
  1378.     }
  1379.  
  1380.     int NumTypeSymbols()
  1381.     {
  1382.         return (type_symbol_pool ? type_symbol_pool -> Length() : 0);
  1383.     }
  1384.     TypeSymbol *&TypeSym(int i)
  1385.     {
  1386.         return (*type_symbol_pool)[i];
  1387.     }
  1388.     void AddTypeSymbol(TypeSymbol *symbol)
  1389.     {
  1390.         if (! type_symbol_pool)
  1391.             type_symbol_pool = new ConvertibleArray<TypeSymbol *>(256);
  1392.         type_symbol_pool -> Next() = symbol;
  1393.     }
  1394.  
  1395.     int NumMethodSymbols()
  1396.     {
  1397.         return (method_symbol_pool ? method_symbol_pool -> Length() : 0);
  1398.     }
  1399.     MethodSymbol *MethodSym(int i)
  1400.     {
  1401.         return (*method_symbol_pool)[i];
  1402.     }
  1403.     void AddMethodSymbol(MethodSymbol *symbol)
  1404.     {
  1405.         if (! method_symbol_pool)
  1406.             method_symbol_pool = new ConvertibleArray<MethodSymbol *>(256);
  1407.         method_symbol_pool -> Next() = symbol;
  1408.     }
  1409.  
  1410.     int NumVariableSymbols()
  1411.     {
  1412.         return (variable_symbol_pool ? variable_symbol_pool -> Length() : 0);
  1413.     }
  1414.     VariableSymbol *VariableSym(int i)
  1415.     {
  1416.         return (*variable_symbol_pool)[i];
  1417.     }
  1418.     void AddVariableSymbol(VariableSymbol *symbol)
  1419.     {
  1420.         if (! variable_symbol_pool)
  1421.             variable_symbol_pool = new ConvertibleArray<VariableSymbol *>(256);
  1422.         variable_symbol_pool -> Next() = symbol;
  1423.     }
  1424.  
  1425.     int NumOtherSymbols()
  1426.     {
  1427.         return (other_symbol_pool ? other_symbol_pool -> Length() : 0);
  1428.     }
  1429.     Symbol *OtherSym(int i)
  1430.     {
  1431.         return (*other_symbol_pool)[i];
  1432.     }
  1433.     void AddOtherSymbol(Symbol *symbol)
  1434.     {
  1435.         if (! other_symbol_pool)
  1436.             other_symbol_pool = new ConvertibleArray<Symbol *>(256);
  1437.         other_symbol_pool -> Next() = symbol;
  1438.     }
  1439.  
  1440.     SymbolTable(int hash_size_ = DEFAULT_HASH_SIZE);
  1441.     ~SymbolTable();
  1442.  
  1443.     inline void CompressSpace()
  1444.     {
  1445.         if (anonymous_symbol_pool)
  1446.             (void) anonymous_symbol_pool -> Array();
  1447.         if (method_symbol_pool)
  1448.             (void) method_symbol_pool -> Array();
  1449.         if (variable_symbol_pool)
  1450.             (void) variable_symbol_pool -> Array();
  1451.         if (other_symbol_pool)
  1452.             (void) other_symbol_pool -> Array();
  1453.  
  1454.         return;
  1455.     }
  1456.  
  1457. private:
  1458.  
  1459.     Tuple<TypeSymbol *> *type_symbol_pool; // This array should not be convertible. See SymbolTable::DeleteTypeSymbol
  1460.  
  1461.     ConvertibleArray<TypeSymbol *>     *anonymous_symbol_pool;
  1462.     ConvertibleArray<MethodSymbol *>   *method_symbol_pool;
  1463.     ConvertibleArray<VariableSymbol *> *variable_symbol_pool;
  1464.     ConvertibleArray<Symbol *>         *other_symbol_pool;
  1465.  
  1466.     Symbol **base;
  1467.     int hash_size;
  1468.  
  1469.     static int primes[];
  1470.     int prime_index;
  1471.  
  1472.     int Size()
  1473.     {
  1474.         return NumAnonymousSymbols() +
  1475.                NumTypeSymbols() +
  1476.                NumMethodSymbols() +
  1477.                NumVariableSymbols() +
  1478.                NumOtherSymbols();
  1479.     }
  1480.     void Rehash();
  1481.  
  1482.     MethodSymbol *constructor;
  1483.  
  1484. public:
  1485.  
  1486.     inline PathSymbol *InsertPathSymbol(NameSymbol *, DirectorySymbol *);
  1487.     inline PathSymbol *FindPathSymbol(NameSymbol *);
  1488.     inline DirectorySymbol *InsertDirectorySymbol(NameSymbol *, Symbol *);
  1489.     inline DirectorySymbol *FindDirectorySymbol(NameSymbol *);
  1490.     inline FileSymbol *InsertFileSymbol(NameSymbol *);
  1491.     inline FileSymbol *FindFileSymbol(NameSymbol *);
  1492.     inline PackageSymbol *InsertPackageSymbol(NameSymbol *, PackageSymbol *);
  1493.     inline PackageSymbol *FindPackageSymbol(NameSymbol *);
  1494.     inline TypeSymbol *InsertAnonymousTypeSymbol(NameSymbol *);
  1495.     inline TypeSymbol *InsertSystemTypeSymbol(NameSymbol *);
  1496.     inline TypeSymbol *InsertOuterTypeSymbol(NameSymbol *);
  1497.     inline TypeSymbol *InsertNestedTypeSymbol(NameSymbol *);
  1498.     inline void DeleteTypeSymbol(TypeSymbol *);
  1499.     inline void DeleteAnonymousTypes();
  1500.     inline TypeSymbol *FindTypeSymbol(NameSymbol *);
  1501.     inline MethodSymbol *InsertMethodSymbol(NameSymbol *);
  1502.     inline MethodSymbol *InsertConstructorSymbol(NameSymbol *);
  1503.     inline void InsertMethodSymbol(MethodSymbol *);
  1504.     inline void InsertConstructorSymbol(MethodSymbol *);
  1505.     inline MethodSymbol *FindMethodSymbol(NameSymbol *);
  1506.     inline MethodSymbol *FindConstructorSymbol();
  1507.     inline VariableSymbol *InsertVariableSymbol(NameSymbol *);
  1508.     inline void InsertVariableSymbol(VariableSymbol *);
  1509.     inline VariableSymbol *FindVariableSymbol(NameSymbol *);
  1510.     inline LabelSymbol *InsertLabelSymbol(NameSymbol *);
  1511.     inline LabelSymbol *FindLabelSymbol(NameSymbol *);
  1512.     inline BlockSymbol *InsertBlockSymbol(int);
  1513.  
  1514.     inline MethodSymbol *Overload(MethodSymbol *);
  1515.     inline void Overload(MethodSymbol *, MethodSymbol *);
  1516.     inline MethodSymbol *LocalConstructorOverload(MethodSymbol *);
  1517.     MethodSymbol *FindOverloadMethod(MethodSymbol *, AstMethodDeclarator *);
  1518. };
  1519.  
  1520.  
  1521. inline int TypeSymbol::NumVariableSymbols() { return (table ? table -> NumVariableSymbols() : 0); }
  1522. inline int BlockSymbol::NumVariableSymbols() { return (table ? table -> NumVariableSymbols() : 0); }
  1523.  
  1524. inline VariableSymbol *TypeSymbol::VariableSym(int i) { return table -> VariableSym(i); }
  1525. inline VariableSymbol *BlockSymbol::VariableSym(int i) { return table -> VariableSym(i); }
  1526.  
  1527. inline int TypeSymbol::NumMethodSymbols() { return (table ? table -> NumMethodSymbols() : 0); }
  1528.  
  1529. inline MethodSymbol *TypeSymbol::MethodSym(int i) { return table -> MethodSym(i); }
  1530.  
  1531. inline int TypeSymbol::NumTypeSymbols() { return (table ? table -> NumTypeSymbols() : 0); }
  1532.  
  1533. inline TypeSymbol *TypeSymbol::TypeSym(int i) { return table -> TypeSym(i); }
  1534.  
  1535. inline void TypeSymbol::CompressSpace() { if (table) table -> CompressSpace(); }
  1536. inline void BlockSymbol::CompressSpace() { if (table) table -> CompressSpace(); }
  1537.  
  1538. inline PathSymbol *SymbolTable::InsertPathSymbol(NameSymbol *name_symbol, DirectorySymbol *directory_symbol)
  1539. {
  1540.     assert(base);
  1541.  
  1542.     PathSymbol *symbol = new PathSymbol(name_symbol);
  1543.     directory_symbol -> owner = symbol;
  1544.     symbol -> root_directory = directory_symbol;
  1545.     AddOtherSymbol(symbol);
  1546.  
  1547.     int k = name_symbol -> index % hash_size;
  1548.     symbol -> next = base[k];
  1549.     base[k] = symbol;
  1550.  
  1551.     //
  1552.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1553.     // 2 times the size of the base, and we have not yet reached the maximum
  1554.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1555.     //
  1556.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1557.         Rehash();
  1558.  
  1559.     return symbol;
  1560. }
  1561.  
  1562.  
  1563. inline PathSymbol *SymbolTable::FindPathSymbol(NameSymbol *name_symbol)
  1564. {
  1565.     assert(base);
  1566.  
  1567.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  1568.     {
  1569.         if (name_symbol == symbol -> Identity())
  1570.             return (PathSymbol *) symbol;
  1571.     }
  1572.  
  1573.     return (PathSymbol *) NULL;
  1574. }
  1575.  
  1576.  
  1577. inline DirectorySymbol *SymbolTable::InsertDirectorySymbol(NameSymbol *name_symbol, Symbol *owner)
  1578. {
  1579.     assert(base);
  1580.  
  1581.     DirectorySymbol *symbol = new DirectorySymbol(name_symbol, owner);
  1582.     AddOtherSymbol(symbol);
  1583.  
  1584.     int k = name_symbol -> index % hash_size;
  1585.     symbol -> next = base[k];
  1586.     base[k] = symbol;
  1587.  
  1588.     //
  1589.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1590.     // 2 times the size of the base, and we have not yet reached the maximum
  1591.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1592.     //
  1593.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1594.         Rehash();
  1595.  
  1596.     return symbol;
  1597. }
  1598.  
  1599.  
  1600. inline DirectorySymbol *DirectorySymbol::InsertDirectorySymbol(NameSymbol *name_symbol)
  1601. {
  1602.     DirectorySymbol *subdirectory_symbol = Table() -> InsertDirectorySymbol(name_symbol, this);
  1603.     this -> subdirectories.Next() = subdirectory_symbol;
  1604.  
  1605.     return subdirectory_symbol;
  1606. }
  1607.  
  1608.  
  1609. inline DirectorySymbol *SymbolTable::FindDirectorySymbol(NameSymbol *name_symbol)
  1610. {
  1611.     assert(base);
  1612.  
  1613.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  1614.     {
  1615.         if (name_symbol == symbol -> Identity())
  1616.         {
  1617.             DirectorySymbol *directory_symbol = symbol -> DirectoryCast();
  1618.             if (directory_symbol)
  1619.                 return directory_symbol;
  1620.         }
  1621.     }
  1622.  
  1623.     return (DirectorySymbol *) NULL;
  1624. }
  1625.  
  1626.  
  1627. inline DirectorySymbol *DirectorySymbol::FindDirectorySymbol(NameSymbol *name_symbol)
  1628. {
  1629.     return (table ? table -> FindDirectorySymbol(name_symbol) : (DirectorySymbol *) NULL);
  1630. }
  1631.  
  1632.  
  1633. inline FileSymbol *SymbolTable::InsertFileSymbol(NameSymbol *name_symbol)
  1634. {
  1635.     assert(base);
  1636.  
  1637.     FileSymbol *symbol = new FileSymbol(name_symbol);
  1638.     AddOtherSymbol(symbol);
  1639.  
  1640.     int k = name_symbol -> index % hash_size;
  1641.     symbol -> next = base[k];
  1642.     base[k] = symbol;
  1643.  
  1644.     //
  1645.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1646.     // 2 times the size of the base, and we have not yet reached the maximum
  1647.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1648.     //
  1649.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1650.         Rehash();
  1651.  
  1652.     return symbol;
  1653. }
  1654.  
  1655.  
  1656. inline FileSymbol *DirectorySymbol::InsertFileSymbol(NameSymbol *name_symbol)
  1657. {
  1658.     return Table() -> InsertFileSymbol(name_symbol);
  1659. }
  1660.  
  1661.  
  1662. inline FileSymbol *SymbolTable::FindFileSymbol(NameSymbol *name_symbol)
  1663. {
  1664.     assert(base);
  1665.  
  1666.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  1667.     {
  1668.         if (name_symbol == symbol -> Identity())
  1669.         {
  1670.             FileSymbol *file_symbol = symbol -> FileCast();
  1671.             if (file_symbol)
  1672.                 return file_symbol;
  1673.         }
  1674.     }
  1675.  
  1676.     return (FileSymbol *) NULL;
  1677. }
  1678.  
  1679.  
  1680. inline FileSymbol *DirectorySymbol::FindFileSymbol(NameSymbol *name_symbol)
  1681. {
  1682.     return (table ? table -> FindFileSymbol(name_symbol) : (FileSymbol *) NULL);
  1683. }
  1684.  
  1685.  
  1686. inline PackageSymbol *SymbolTable::InsertPackageSymbol(NameSymbol *name_symbol, PackageSymbol *owner)
  1687. {
  1688.     assert(base);
  1689.  
  1690.     PackageSymbol *symbol = new PackageSymbol(name_symbol, owner);
  1691.     AddOtherSymbol(symbol);
  1692.  
  1693.     int k = name_symbol -> index % hash_size;
  1694.     symbol -> next = base[k];
  1695.     base[k] = symbol;
  1696.  
  1697.     //
  1698.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1699.     // 2 times the size of the base, and we have not yet reached the maximum
  1700.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1701.     //
  1702.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1703.         Rehash();
  1704.  
  1705.     return symbol;
  1706. }
  1707.  
  1708.  
  1709. inline PackageSymbol *PackageSymbol::InsertPackageSymbol(NameSymbol *name_symbol)
  1710. {
  1711.     return Table() -> InsertPackageSymbol(name_symbol, this);
  1712. }
  1713.  
  1714.  
  1715. inline PackageSymbol *SymbolTable::FindPackageSymbol(NameSymbol *name_symbol)
  1716. {
  1717.     assert(base);
  1718.  
  1719.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  1720.     {
  1721.         if (name_symbol == symbol -> Identity())
  1722.         {
  1723.             PackageSymbol *package_symbol = symbol -> PackageCast();
  1724.             if (package_symbol)
  1725.                 return package_symbol;
  1726.         }
  1727.     }
  1728.  
  1729.     return (PackageSymbol *) NULL;
  1730. }
  1731.  
  1732.  
  1733. inline PackageSymbol *PackageSymbol::FindPackageSymbol(NameSymbol *name_symbol)
  1734. {
  1735.   return (table ? table -> FindPackageSymbol(name_symbol) : (PackageSymbol *) NULL);
  1736. }
  1737.  
  1738. inline TypeSymbol *SymbolTable::InsertAnonymousTypeSymbol(NameSymbol *name_symbol)
  1739. {
  1740.     TypeSymbol *symbol = new TypeSymbol(name_symbol);
  1741.     AddAnonymousSymbol(symbol);
  1742.  
  1743.     return symbol;
  1744. }
  1745.  
  1746.  
  1747. inline TypeSymbol *TypeSymbol::InsertAnonymousTypeSymbol(NameSymbol *name_symbol)
  1748. {
  1749.     return Table() -> InsertAnonymousTypeSymbol(name_symbol);
  1750. }
  1751.  
  1752.  
  1753. inline TypeSymbol *SymbolTable::InsertSystemTypeSymbol(NameSymbol *name_symbol)
  1754. {
  1755.     assert(base);
  1756.  
  1757.     TypeSymbol *symbol = new TypeSymbol(name_symbol);
  1758.     symbol -> pool_index = NumTypeSymbols();
  1759.     AddTypeSymbol(symbol);
  1760.  
  1761.     int k = name_symbol -> index % hash_size;
  1762.     symbol -> next = base[k];
  1763.     base[k] = symbol;
  1764.  
  1765.     //
  1766.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1767.     // 2 times the size of the base, and we have not yet reached the maximum
  1768.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1769.     //
  1770.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1771.         Rehash();
  1772.  
  1773.     return symbol;
  1774. }
  1775.  
  1776.  
  1777. inline TypeSymbol *PackageSymbol::InsertSystemTypeSymbol(NameSymbol *name_symbol)
  1778. {
  1779.     return Table() -> InsertSystemTypeSymbol(name_symbol);
  1780. }
  1781.  
  1782.  
  1783. inline TypeSymbol *SymbolTable::InsertOuterTypeSymbol(NameSymbol *name_symbol)
  1784. {
  1785.     assert(base);
  1786.  
  1787.     TypeSymbol *symbol = new TypeSymbol(name_symbol);
  1788.     symbol -> pool_index = NumTypeSymbols();
  1789.     AddTypeSymbol(symbol);
  1790.  
  1791.     int k = name_symbol -> index % hash_size;
  1792.     symbol -> next = base[k];
  1793.     base[k] = symbol;
  1794.  
  1795.     //
  1796.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1797.     // 2 times the size of the base, and we have not yet reached the maximum
  1798.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1799.     //
  1800.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1801.         Rehash();
  1802.  
  1803.     return symbol;
  1804. }
  1805.  
  1806.  
  1807. inline TypeSymbol *PackageSymbol::InsertOuterTypeSymbol(NameSymbol *name_symbol)
  1808. {
  1809.     return Table() -> InsertOuterTypeSymbol(name_symbol);
  1810. }
  1811.  
  1812.  
  1813. inline TypeSymbol *SymbolTable::InsertNestedTypeSymbol(NameSymbol *name_symbol)
  1814. {
  1815.     assert(base);
  1816.  
  1817.     TypeSymbol *symbol = new TypeSymbol(name_symbol);
  1818.     symbol -> pool_index = NumTypeSymbols();
  1819.     AddTypeSymbol(symbol);
  1820.  
  1821.     int k = name_symbol -> index % hash_size;
  1822.     symbol -> next = base[k];
  1823.     base[k] = symbol;
  1824.  
  1825.     //
  1826.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1827.     // 2 times the size of the base, and we have not yet reached the maximum
  1828.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1829.     //
  1830.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1831.         Rehash();
  1832.  
  1833.     return symbol;
  1834. }
  1835.  
  1836.  
  1837. inline TypeSymbol *TypeSymbol::InsertNestedTypeSymbol(NameSymbol *name_symbol)
  1838. {
  1839.     return Table() -> InsertNestedTypeSymbol(name_symbol);
  1840. }
  1841.  
  1842.  
  1843. inline void SymbolTable::DeleteTypeSymbol(TypeSymbol *type)
  1844. {
  1845.     assert(base);
  1846.  
  1847.     int k = type -> name_symbol -> index % hash_size;
  1848.     if (type == base[k])
  1849.         base[k] = type -> next;
  1850.     else
  1851.     {
  1852.         Symbol *previous = base[k];
  1853.         for (Symbol *symbol = previous -> next; symbol != type; previous = symbol, symbol = symbol -> next)
  1854.             ;
  1855.         previous -> next = type -> next;
  1856.     }
  1857.  
  1858.     int last_index = NumTypeSymbols() - 1;
  1859.     if (type -> pool_index != last_index)
  1860.     {// move last element to position previously occupied by element being deleted
  1861.         TypeSym(last_index) -> pool_index = type -> pool_index;
  1862.         TypeSym(type -> pool_index) = TypeSym(last_index);
  1863.     }
  1864.  
  1865.     type_symbol_pool -> Reset(last_index); // remove last slot in symbol_pool
  1866.  
  1867.     delete type;
  1868.  
  1869.     return;
  1870. }
  1871.  
  1872.  
  1873. inline void PackageSymbol::DeleteTypeSymbol(TypeSymbol *type)
  1874. {
  1875.     if (table)
  1876.         table -> DeleteTypeSymbol(type);
  1877. }
  1878.  
  1879.  
  1880. inline void SymbolTable::DeleteAnonymousTypes()
  1881. {
  1882.     for (int i = 0; i < NumAnonymousSymbols(); i++)
  1883.         delete AnonymousSym(i);
  1884.     delete anonymous_symbol_pool;
  1885.     anonymous_symbol_pool = NULL;
  1886.  
  1887.     return;
  1888. }
  1889.  
  1890.  
  1891. inline void TypeSymbol::DeleteAnonymousTypes()
  1892. {
  1893.     delete anonymous_types;
  1894.     anonymous_types = NULL;
  1895.     if (table)
  1896.         table -> DeleteAnonymousTypes();
  1897. }
  1898.  
  1899. inline TypeSymbol *SymbolTable::FindTypeSymbol(NameSymbol *name_symbol)
  1900. {
  1901.     assert(base);
  1902.  
  1903.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  1904.     {
  1905.         if (name_symbol == symbol -> Identity())
  1906.         {
  1907.             TypeSymbol *type = symbol -> TypeCast();
  1908.             if (type)
  1909.                 return type;
  1910.         }
  1911.     }
  1912.  
  1913.     return (TypeSymbol *) NULL;
  1914. }
  1915.  
  1916.  
  1917. inline TypeSymbol *PackageSymbol::FindTypeSymbol(NameSymbol *name_symbol)
  1918. {
  1919.     return (table ? table -> FindTypeSymbol(name_symbol) : (TypeSymbol *) NULL);
  1920. }
  1921.  
  1922.  
  1923. inline TypeSymbol *TypeSymbol::FindTypeSymbol(NameSymbol *name_symbol)
  1924. {
  1925.     return (table ? table -> FindTypeSymbol(name_symbol) : (TypeSymbol *) NULL);
  1926. }
  1927.  
  1928.  
  1929. inline MethodSymbol *SymbolTable::InsertMethodSymbol(NameSymbol *name_symbol)
  1930. {
  1931.     assert(base);
  1932.  
  1933.     MethodSymbol *symbol = new MethodSymbol(name_symbol);
  1934.     AddMethodSymbol(symbol);
  1935.  
  1936.     int k = name_symbol -> index % hash_size;
  1937.     symbol -> next = base[k];
  1938.     base[k] = symbol;
  1939.  
  1940.     //
  1941.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1942.     // 2 times the size of the base, and we have not yet reached the maximum
  1943.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1944.     //
  1945.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1946.         Rehash();
  1947.  
  1948.     return symbol;
  1949. }
  1950.  
  1951.  
  1952. inline MethodSymbol *TypeSymbol::InsertMethodSymbol(NameSymbol *name_symbol)
  1953. {
  1954.     return Table() -> InsertMethodSymbol(name_symbol);
  1955. }
  1956.  
  1957.  
  1958. inline MethodSymbol *SymbolTable::InsertConstructorSymbol(NameSymbol *name_symbol)
  1959. {
  1960.     assert(! constructor);
  1961.  
  1962.     this -> constructor = InsertMethodSymbol(name_symbol);
  1963.     return this -> constructor;
  1964. }
  1965.  
  1966.  
  1967. inline MethodSymbol *TypeSymbol::InsertConstructorSymbol(NameSymbol *name_symbol)
  1968. {
  1969.     return Table() -> InsertConstructorSymbol(name_symbol);
  1970. }
  1971.  
  1972.  
  1973. inline void SymbolTable::InsertMethodSymbol(MethodSymbol *method_symbol)
  1974. {
  1975.     assert(base);
  1976.  
  1977.     AddMethodSymbol(method_symbol);
  1978.  
  1979.     int k = method_symbol -> name_symbol -> index % hash_size;
  1980.     method_symbol -> next = base[k];
  1981.     base[k] = method_symbol;
  1982.  
  1983.     //
  1984.     // If the set is "adjustable" and the number of unique elements in it exceeds
  1985.     // 2 times the size of the base, and we have not yet reached the maximum
  1986.     // allowable size for a base, reallocate a larger base and rehash the elements.
  1987.     //
  1988.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  1989.         Rehash();
  1990.  
  1991.     return;
  1992. }
  1993.  
  1994.  
  1995. inline void TypeSymbol::InsertMethodSymbol(MethodSymbol *method_symbol)
  1996. {
  1997.     Table() -> InsertMethodSymbol(method_symbol);
  1998. }
  1999.  
  2000.  
  2001. inline void SymbolTable::InsertConstructorSymbol(MethodSymbol *method_symbol)
  2002. {
  2003.     assert(! constructor);
  2004.  
  2005.     this -> constructor = method_symbol;
  2006.     InsertMethodSymbol(method_symbol);
  2007. }
  2008.  
  2009.  
  2010. inline void TypeSymbol::InsertConstructorSymbol(MethodSymbol *method_symbol)
  2011. {
  2012.     Table() -> InsertConstructorSymbol(method_symbol);
  2013. }
  2014.  
  2015.  
  2016. inline MethodSymbol *SymbolTable::FindMethodSymbol(NameSymbol *name_symbol)
  2017. {
  2018.     assert(base);
  2019.  
  2020.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  2021.     {
  2022.         if (name_symbol == symbol -> Identity())
  2023.         {
  2024.             MethodSymbol *method = symbol -> MethodCast();
  2025.             if (method)
  2026.                 return method;
  2027.         }
  2028.     }
  2029.  
  2030.     return (MethodSymbol *) NULL;
  2031. }
  2032.  
  2033.  
  2034. inline MethodSymbol *TypeSymbol::FindMethodSymbol(NameSymbol *name_symbol)
  2035. {
  2036.     return (table ? table -> FindMethodSymbol(name_symbol) : (MethodSymbol *) NULL);
  2037. }
  2038.  
  2039.  
  2040. inline MethodSymbol *SymbolTable::FindConstructorSymbol()
  2041. {
  2042.     return this -> constructor;
  2043. }
  2044.  
  2045. inline MethodSymbol *TypeSymbol::FindConstructorSymbol()
  2046. {
  2047.     return (table ? table -> FindConstructorSymbol() : (MethodSymbol *) NULL);
  2048. }
  2049.  
  2050. inline VariableSymbol *SymbolTable::InsertVariableSymbol(NameSymbol *name_symbol)
  2051. {
  2052.     assert(base);
  2053.  
  2054.     VariableSymbol *symbol = new VariableSymbol(name_symbol);
  2055.     AddVariableSymbol(symbol);
  2056.  
  2057.     int k = name_symbol -> index % hash_size;
  2058.     symbol -> next = base[k];
  2059.     base[k] = symbol;
  2060.  
  2061.     //
  2062.     // If the set is "adjustable" and the number of unique elements in it exceeds
  2063.     // 2 times the size of the base, and we have not yet reached the maximum
  2064.     // allowable size for a base, reallocate a larger base and rehash the elements.
  2065.     //
  2066.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  2067.         Rehash();
  2068.  
  2069.     return symbol;
  2070. }
  2071.  
  2072.  
  2073. inline VariableSymbol *TypeSymbol::InsertVariableSymbol(NameSymbol *name_symbol)
  2074. {
  2075.     return Table() -> InsertVariableSymbol(name_symbol);
  2076. }
  2077.  
  2078.  
  2079. inline VariableSymbol *BlockSymbol::InsertVariableSymbol(NameSymbol *name_symbol)
  2080. {
  2081.     return Table() -> InsertVariableSymbol(name_symbol);
  2082. }
  2083.  
  2084.  
  2085. inline void SymbolTable::InsertVariableSymbol(VariableSymbol *variable_symbol)
  2086. {
  2087.     assert(base);
  2088.  
  2089.     AddVariableSymbol(variable_symbol);
  2090.  
  2091.     int k = variable_symbol -> name_symbol -> index % hash_size;
  2092.     variable_symbol -> next = base[k];
  2093.     base[k] = variable_symbol;
  2094.  
  2095.     //
  2096.     // If the set is "adjustable" and the number of unique elements in it exceeds
  2097.     // 2 times the size of the base, and we have not yet reached the maximum
  2098.     // allowable size for a base, reallocate a larger base and rehash the elements.
  2099.     //
  2100.     if ((Size() > (hash_size << 1)) && (hash_size < MAX_HASH_SIZE))
  2101.         Rehash();
  2102.  
  2103.     return;
  2104. }
  2105.  
  2106.  
  2107. inline void TypeSymbol::InsertVariableSymbol(VariableSymbol *variable_symbol)
  2108. {
  2109.     Table() -> InsertVariableSymbol(variable_symbol);
  2110. }
  2111.  
  2112.  
  2113. inline void BlockSymbol::InsertVariableSymbol(VariableSymbol *variable_symbol)
  2114. {
  2115.     Table() -> InsertVariableSymbol(variable_symbol);
  2116. }
  2117.  
  2118.  
  2119. inline VariableSymbol *SymbolTable::FindVariableSymbol(NameSymbol *name_symbol)
  2120. {
  2121.     assert(base);
  2122.  
  2123.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  2124.     {
  2125.         if (name_symbol == symbol -> Identity())
  2126.         {
  2127.             VariableSymbol *variable_symbol = symbol -> VariableCast();
  2128.             if (variable_symbol)
  2129.                 return variable_symbol;
  2130.         }
  2131.     }
  2132.  
  2133.     return (VariableSymbol *) NULL;
  2134. }
  2135.  
  2136.  
  2137. inline VariableSymbol *TypeSymbol::FindVariableSymbol(NameSymbol *name_symbol)
  2138. {
  2139.     return (table ? table -> FindVariableSymbol(name_symbol) : (VariableSymbol *) NULL);
  2140. }
  2141.  
  2142.  
  2143. inline VariableSymbol *BlockSymbol::FindVariableSymbol(NameSymbol *name_symbol)
  2144. {
  2145.     return (table ? table -> FindVariableSymbol(name_symbol) : (VariableSymbol *) NULL);
  2146. }
  2147.  
  2148.  
  2149. inline LabelSymbol *SymbolTable::InsertLabelSymbol(NameSymbol *name_symbol)
  2150. {
  2151.     assert(base);
  2152.  
  2153.     LabelSymbol *symbol = new LabelSymbol(name_symbol);
  2154.     AddOtherSymbol(symbol);
  2155.  
  2156.     int k = name_symbol -> index % hash_size;
  2157.     symbol -> next = base[k];
  2158.     base[k] = symbol;
  2159.  
  2160.     //
  2161.     // as only one label can be inserted in any given symboltable,
  2162.     // we don't need to try to rehash here !
  2163.     //
  2164.  
  2165.     return symbol;
  2166. }
  2167.  
  2168.  
  2169. inline LabelSymbol *SymbolTable::FindLabelSymbol(NameSymbol *name_symbol)
  2170. {
  2171.     assert(base);
  2172.  
  2173.     for (Symbol *symbol = base[name_symbol -> index % hash_size]; symbol; symbol = symbol -> next)
  2174.     {
  2175.         if (name_symbol == symbol -> Identity())
  2176.         {
  2177.             LabelSymbol *label = symbol -> LabelCast();
  2178.             if (label)
  2179.                 return label;
  2180.         }
  2181.     }
  2182.  
  2183.     return (LabelSymbol *) NULL;
  2184. }
  2185.  
  2186. inline BlockSymbol *SymbolTable::InsertBlockSymbol(int hash_size = 0)
  2187. {
  2188.     BlockSymbol *symbol = new BlockSymbol(hash_size);
  2189.     AddOtherSymbol(symbol);
  2190.  
  2191.     return symbol;
  2192. }
  2193.  
  2194.  
  2195. inline BlockSymbol *BlockSymbol::InsertBlockSymbol(int hash_size = 0)
  2196. {
  2197.     return Table() -> InsertBlockSymbol(hash_size);
  2198. }
  2199.  
  2200.  
  2201. inline MethodSymbol *SymbolTable::Overload(MethodSymbol *base_method)
  2202. {
  2203.     MethodSymbol *overload = new MethodSymbol(base_method -> Identity());
  2204.     AddMethodSymbol(overload);
  2205.  
  2206.     overload -> next = overload; // mark overloaded method
  2207.     overload -> next_method = base_method -> next_method;
  2208.     base_method -> next_method = overload;
  2209.  
  2210.     return overload;
  2211. }
  2212.  
  2213.  
  2214. inline MethodSymbol *TypeSymbol::Overload(MethodSymbol *base_method)
  2215. {
  2216.     assert(table);
  2217.  
  2218.     return table -> Overload(base_method);
  2219. }
  2220.  
  2221.  
  2222. inline void SymbolTable::Overload(MethodSymbol *base_method, MethodSymbol *overload)
  2223. {
  2224.     AddMethodSymbol(overload);
  2225.  
  2226.     overload -> next = overload; // mark overloaded method
  2227.     overload -> next_method = base_method -> next_method;
  2228.     base_method -> next_method = overload;
  2229.  
  2230.     return;
  2231. }
  2232.  
  2233. inline void TypeSymbol::Overload(MethodSymbol *base_method, MethodSymbol *overload)
  2234. {
  2235.     assert(table);
  2236.  
  2237.     table -> Overload(base_method, overload);
  2238. }
  2239.  
  2240.  
  2241. inline MethodSymbol *SymbolTable::LocalConstructorOverload(MethodSymbol *base_method)
  2242. {
  2243.     MethodSymbol *overload = new MethodSymbol(base_method -> Identity());
  2244.     AddMethodSymbol(overload);
  2245.  
  2246.     overload -> next = overload; // mark overloaded method
  2247.     overload -> SetGeneratedLocalConstructor(base_method);
  2248.  
  2249.     return overload;
  2250. }
  2251.  
  2252.  
  2253. inline MethodSymbol *TypeSymbol::LocalConstructorOverload(MethodSymbol *base_method)
  2254. {
  2255.     assert(table);
  2256.  
  2257.     return table -> LocalConstructorOverload(base_method);
  2258. }
  2259.  
  2260.  
  2261. inline MethodSymbol *TypeSymbol::FindOverloadMethod(MethodSymbol *base_method, AstMethodDeclarator *method_declarator)
  2262. {
  2263.     return (table ? table -> FindOverloadMethod(base_method, method_declarator) : (MethodSymbol *) NULL);
  2264. }
  2265.  
  2266.  
  2267. inline SymbolTable *DirectorySymbol::Table()
  2268. {
  2269.     return (table ? table : table = new SymbolTable(101));
  2270. }
  2271.  
  2272. inline SymbolTable *PackageSymbol::Table()
  2273. {
  2274.     return (table ? table : table = new SymbolTable(101));
  2275. }
  2276.  
  2277. inline void TypeSymbol::SetSymbolTable(int estimate)
  2278. {
  2279.     if (! table) // If table was not yet allocated, allocate one based on the estimate
  2280.         table = new SymbolTable(estimate);
  2281. }
  2282.  
  2283. inline SymbolTable *TypeSymbol::Table()
  2284. {
  2285.     return (table ? table : table = new SymbolTable());
  2286. }
  2287.  
  2288. inline SymbolTable *BlockSymbol::Table()
  2289. {
  2290.     return (table ? table : table = new SymbolTable());
  2291. }
  2292.  
  2293. #ifdef UNIX_FILE_SYSTEM
  2294.     inline bool FileSymbol::IsClassSuffix(char *suffix)
  2295.     {
  2296.         return (strncmp(suffix, class_suffix, class_suffix_length) == 0);
  2297.     }
  2298.  
  2299.     inline bool  FileSymbol::IsJavaSuffix(char *suffix)
  2300.     {
  2301.         return (strncmp(suffix, java_suffix, java_suffix_length) == 0);
  2302.     }
  2303. #elif defined(WIN32_FILE_SYSTEM)
  2304.     inline bool FileSymbol::IsClassSuffix(char *suffix)
  2305.     {
  2306.         return Case::StringSegmentEqual(suffix, class_suffix, class_suffix_length);
  2307.     }
  2308.  
  2309.     inline bool  FileSymbol::IsJavaSuffix(char *suffix)
  2310.     {
  2311.         return Case::StringSegmentEqual(suffix, java_suffix, java_suffix_length);
  2312.     }
  2313. #elif defined(AMIGAOS_FILE_SYSTEM)
  2314.     // Do not use StringSegmentEqual() as in the WIN32 case, because that
  2315.     // function may check beyond the end of the string, thus possibly causing
  2316.     // enforcer hits.
  2317.     inline bool FileSymbol::IsClassSuffix(char *suffix)
  2318.     {
  2319.         return (strncasecmp(suffix, class_suffix, class_suffix_length) == 0);
  2320.     }
  2321.  
  2322.     inline bool  FileSymbol::IsJavaSuffix(char *suffix)
  2323.     {
  2324.         return (strncasecmp(suffix, java_suffix, java_suffix_length) == 0);
  2325.     }
  2326. #endif
  2327.  
  2328. #endif // ifndef symbol_INCLUDED
  2329.