home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / Jikes / Source / src / symbol.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-03  |  71.1 KB  |  2,332 lines

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