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

  1. // $Id: control.h,v 1.31 2001/01/05 09:13:20 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 control_INCLUDED
  11. #define control_INCLUDED
  12.  
  13. #include "platform.h"
  14. #include "option.h"
  15. #include "symbol.h"
  16. #include "tuple.h"
  17. #include "set.h"
  18.  
  19. /*
  20. //FIXME: need to readdress this include stuff
  21. #include <iostream.h>
  22. #include <stdio.h>
  23. */
  24.  
  25. #ifdef    HAVE_JIKES_NAMESPACE
  26. namespace Jikes {    // Open namespace Jikes block
  27. #endif
  28.  
  29. class StoragePool;
  30. class Scanner;
  31. class Parser;
  32. class Semantic;
  33. class LexStream;
  34. class AstPackageDeclaration;
  35.  
  36. class Control : public StringConstant
  37. {
  38. public:
  39.     int return_code;
  40.     Option &option;
  41.     SymbolTable classpath_table,
  42.                 external_table;
  43.  
  44.     PackageSymbol *system_package,
  45.                   *java_util_package,
  46.                   *unnamed_package;
  47.     int dot_classpath_index;
  48.     Tuple<PathSymbol *> classpath;
  49.     Tuple<wchar_t *> bad_zip_filenames,
  50.                      bad_input_filenames,
  51.                      unreadable_input_filenames;
  52.  
  53.     SystemTable *system_table;
  54.     Tuple<DirectorySymbol *> system_directories;
  55.  
  56.     Semantic *system_semantic;
  57.     Tuple<Semantic *> semantic;
  58.     Tuple<TypeSymbol *> needs_body_work,
  59.                         type_trash_bin;
  60.  
  61.     NameSymbolMap unnamed_package_types;
  62.  
  63.     SymbolSet input_java_file_set,
  64.               input_class_file_set,
  65.               expired_file_set,
  66.               recompilation_file_set;
  67.  
  68.     Parser *parser;
  69.     Scanner *scanner;
  70.  
  71.     //
  72.     //
  73.     //
  74.     LiteralLookupTable string_table,
  75.                        int_table,
  76.                        long_table,
  77.                        char_table,
  78.                        float_table,
  79.                        double_table;
  80.     NameLookupTable name_table;
  81.     TypeLookupTable type_table;
  82.  
  83.     //
  84.     //
  85.     //
  86.     NameSymbol *dot_name_symbol,
  87.                *dot_dot_name_symbol,
  88.                *length_name_symbol,
  89.                *init_name_symbol,
  90.                *clinit_name_symbol,
  91.                *block_init_name_symbol,
  92.                *this0_name_symbol,
  93.                *clone_name_symbol,
  94.                *object_name_symbol,
  95.                *type_name_symbol,
  96.                *class_name_symbol,
  97.                *toString_name_symbol,
  98.                *append_name_symbol,
  99.                *forName_name_symbol,
  100.                *getMessage_name_symbol;
  101.  
  102.     //
  103.     //
  104.     //
  105.     TypeSymbol *byte_type,
  106.                *short_type,
  107.                *int_type,
  108.                *long_type,
  109.                *char_type,
  110.                *float_type,
  111.                *double_type,
  112.                *boolean_type,
  113.                *void_type,
  114.                *null_type,
  115.                *no_type;
  116.  
  117.     //
  118.     TypeSymbol *GetType(PackageSymbol *, wchar_t *);
  119.  
  120.     inline TypeSymbol *Serializable()
  121.     {
  122.         if (! Serializable_type)
  123.         {
  124.             PackageSymbol *io_package = ProcessPackage(StringConstant::US_java_SL_io);
  125.             FindPathsToDirectory(io_package);
  126.             Serializable_type = GetType(io_package, StringConstant::US_Serializable);
  127.         }
  128.  
  129.         return Serializable_type;
  130.     }
  131.  
  132.     inline TypeSymbol *Object()
  133.     {
  134.         return (Object_type ? Object_type : Object_type = GetType(system_package, StringConstant::US_Object));
  135.     }
  136.  
  137.     inline TypeSymbol *Cloneable()
  138.     {
  139.         return (Cloneable_type ? Cloneable_type : Cloneable_type = GetType(system_package, StringConstant::US_Cloneable));
  140.     }
  141.  
  142.     inline TypeSymbol *String()
  143.     {
  144.         return (String_type ? String_type : String_type = GetType(system_package, StringConstant::US_String));
  145.     }
  146.  
  147.     inline TypeSymbol *Void()
  148.     {
  149.         return (Void_type ? Void_type : Void_type = GetType(system_package, StringConstant::US_Void));
  150.     }
  151.  
  152.     inline TypeSymbol *Boolean()
  153.     {
  154.         return (Boolean_type ? Boolean_type : Boolean_type = GetType(system_package, StringConstant::US_Boolean));
  155.     }
  156.  
  157.     inline TypeSymbol *Byte()
  158.     {
  159.         return (Byte_type ? Byte_type : Byte_type = GetType(system_package, StringConstant::US_Byte));
  160.     }
  161.  
  162.     inline TypeSymbol *Short()
  163.     {
  164.         return (Short_type ? Short_type : Short_type = GetType(system_package, StringConstant::US_Short));
  165.     }
  166.  
  167.     inline TypeSymbol *Character()
  168.     {
  169.         return (Character_type ? Character_type : Character_type = GetType(system_package, StringConstant::US_Character));
  170.     }
  171.  
  172.     inline TypeSymbol *Integer()
  173.     {
  174.         return (Integer_type ? Integer_type : Integer_type = GetType(system_package, StringConstant::US_Integer));
  175.     }
  176.  
  177.     inline TypeSymbol *Long()
  178.     {
  179.         return (Long_type ? Long_type : Long_type = GetType(system_package, StringConstant::US_Long));
  180.     }
  181.  
  182.     inline TypeSymbol *Float()
  183.     {
  184.         return (Float_type ? Float_type : Float_type = GetType(system_package, StringConstant::US_Float));
  185.     }
  186.  
  187.     inline TypeSymbol *Double()
  188.     {
  189.         return (Double_type ? Double_type : Double_type = GetType(system_package, StringConstant::US_Double));
  190.     }
  191.  
  192.     void InitClassInfo();
  193.     inline TypeSymbol *Class()
  194.     {
  195.         if (! Class_type)
  196.         {
  197.             Class_type = GetType(system_package, StringConstant::US_Class);
  198.             InitClassInfo();
  199.         }
  200.  
  201.         return Class_type;
  202.     }
  203.  
  204.     MethodSymbol *Class_forNameMethod()
  205.     {
  206.         if (! Class_forName_method)
  207.             (void) Class();
  208.         return Class_forName_method;
  209.     }
  210.  
  211.  
  212.     void InitThrowableInfo();
  213.     inline TypeSymbol *Throwable()
  214.     {
  215.         if (! Throwable_type)
  216.         {
  217.             Throwable_type = GetType(system_package, StringConstant::US_Throwable);
  218.             InitThrowableInfo();
  219.         }
  220.  
  221.         return Throwable_type;
  222.     }
  223.  
  224.     MethodSymbol *Throwable_getMessageMethod()
  225.     {
  226.         if (! Throwable_getMessage_method)
  227.             (void) Throwable();
  228.         return Throwable_getMessage_method;
  229.     }
  230.  
  231.     inline TypeSymbol *Exception()
  232.     {
  233.         return (Exception_type
  234.                        ? Exception_type
  235.                        : Exception_type = GetType(system_package, StringConstant::US_Exception));
  236.     }
  237.  
  238.     inline TypeSymbol *RuntimeException()
  239.     {
  240.         return (RuntimeException_type
  241.                        ? RuntimeException_type
  242.                        : RuntimeException_type = GetType(system_package, StringConstant::US_RuntimeException));
  243.     }
  244.  
  245.     inline TypeSymbol *ClassNotFoundException()
  246.     {
  247.         return (ClassNotFoundException_type
  248.                        ? ClassNotFoundException_type
  249.                        : ClassNotFoundException_type = GetType(system_package, StringConstant::US_ClassNotFoundException));
  250.     }
  251.  
  252.     inline TypeSymbol *Error()
  253.     {
  254.         return (Error_type ? Error_type : Error_type = GetType(system_package, StringConstant::US_Error));
  255.     }
  256.  
  257.     inline TypeSymbol *Vector()
  258.     {
  259.         return (Vector_type ? Vector_type : Vector_type = GetType(java_util_package, StringConstant::US_Vector));
  260.     }
  261.  
  262.     void InitNoClassDefFoundErrorInfo();
  263.     inline TypeSymbol *NoClassDefFoundError()
  264.     {
  265.         if (! NoClassDefFoundError_type)
  266.         {
  267.             NoClassDefFoundError_type = GetType(system_package, StringConstant::US_NoClassDefFoundError);
  268.             InitNoClassDefFoundErrorInfo();
  269.         }
  270.  
  271.         return NoClassDefFoundError_type;
  272.     }
  273.  
  274.     MethodSymbol *NoClassDefFoundError_InitMethod()
  275.     {
  276.         if (! NoClassDefFoundError_InitWithString_method)
  277.             (void) NoClassDefFoundError();
  278.         return NoClassDefFoundError_InitWithString_method;
  279.     }
  280.  
  281.  
  282.     void InitStringBufferInfo();
  283.     inline TypeSymbol *StringBuffer()
  284.     {
  285.         if (! StringBuffer_type)
  286.         {
  287.             StringBuffer_type = GetType(system_package, StringConstant::US_StringBuffer);
  288.             InitStringBufferInfo();
  289.         }
  290.  
  291.         return StringBuffer_type;
  292.     }
  293.  
  294.  
  295.     MethodSymbol *StringBuffer_InitMethod()
  296.     {
  297.         if (! StringBuffer_Init_method)
  298.             (void) StringBuffer();
  299.         return StringBuffer_Init_method;
  300.     }
  301.  
  302.  
  303.     MethodSymbol *StringBuffer_InitWithStringMethod()
  304.     {
  305.         if (! StringBuffer_InitWithString_method)
  306.             (void) StringBuffer();
  307.         return StringBuffer_InitWithString_method;
  308.     }
  309.  
  310.  
  311.     MethodSymbol *StringBuffer_toStringMethod()
  312.     {
  313.         if (! StringBuffer_InitWithString_method)
  314.             (void) StringBuffer();
  315.         return StringBuffer_toString_method;
  316.     }
  317.  
  318.  
  319.     MethodSymbol *StringBuffer_append_char_arrayMethod()
  320.     {
  321.         if (! StringBuffer_InitWithString_method)
  322.             (void) StringBuffer();
  323.         return StringBuffer_append_char_array_method;
  324.     }
  325.  
  326.  
  327.     MethodSymbol *StringBuffer_append_charMethod()
  328.     {
  329.         if (! StringBuffer_InitWithString_method)
  330.             (void) StringBuffer();
  331.         return StringBuffer_append_char_method;
  332.     }
  333.  
  334.  
  335.     MethodSymbol *StringBuffer_append_booleanMethod()
  336.     {
  337.         if (! StringBuffer_InitWithString_method)
  338.             (void) StringBuffer();
  339.         return StringBuffer_append_boolean_method;
  340.     }
  341.  
  342.  
  343.     MethodSymbol *StringBuffer_append_intMethod()
  344.     {
  345.         if (! StringBuffer_InitWithString_method)
  346.             (void) StringBuffer();
  347.         return StringBuffer_append_int_method;
  348.     }
  349.  
  350.  
  351.     MethodSymbol *StringBuffer_append_longMethod()
  352.     {
  353.         if (! StringBuffer_InitWithString_method)
  354.             (void) StringBuffer();
  355.         return StringBuffer_append_long_method;
  356.     }
  357.  
  358.  
  359.     MethodSymbol *StringBuffer_append_floatMethod()
  360.     {
  361.         if (! StringBuffer_InitWithString_method)
  362.             (void) StringBuffer();
  363.         return StringBuffer_append_float_method;
  364.     }
  365.  
  366.  
  367.     MethodSymbol *StringBuffer_append_doubleMethod()
  368.     {
  369.         if (! StringBuffer_InitWithString_method)
  370.             (void) StringBuffer();
  371.         return StringBuffer_append_double_method;
  372.     }
  373.  
  374.  
  375.     MethodSymbol *StringBuffer_append_stringMethod()
  376.     {
  377.         if (! StringBuffer_InitWithString_method)
  378.             (void) StringBuffer();
  379.         return StringBuffer_append_string_method;
  380.     }
  381.  
  382.  
  383.     MethodSymbol *StringBuffer_append_objectMethod()
  384.     {
  385.         if (! StringBuffer_InitWithString_method)
  386.             (void) StringBuffer();
  387.         return StringBuffer_append_object_method;
  388.     }
  389.  
  390.     IntLiteralTable    int_pool;
  391.     LongLiteralTable   long_pool;
  392.     FloatLiteralTable  float_pool;
  393.     DoubleLiteralTable double_pool;
  394.     Utf8LiteralTable   Utf8_pool;
  395.  
  396.     Utf8LiteralValue *ConstantValue_literal,
  397.                      *Exceptions_literal,
  398.                      *InnerClasses_literal,
  399.                      *Synthetic_literal,
  400.                      *Deprecated_literal,
  401.                      *LineNumberTable_literal,
  402.                      *LocalVariableTable_literal,
  403.                      *Code_literal,
  404.                      *Sourcefile_literal,
  405.  
  406.                      *null_literal,
  407.                      *this_literal;
  408.  
  409.     Control(char **, Option &);
  410.     ~Control();
  411.  
  412.     Utf8LiteralValue *ConvertUnicodeToUtf8(wchar_t *source)
  413.     {
  414.         char *target = new char[wcslen(source) * 3 + 1]; // should be big enough for the worst case
  415.         int length = ConvertUnicodeToUtf8(source, target);
  416.         Utf8LiteralValue *literal = Utf8_pool.FindOrInsert(target, length);
  417.         delete [] target;
  418.  
  419.         return literal;
  420.     }
  421.  
  422.     static int ConvertUtf8ToUnicode(wchar_t *, const char *, int);
  423.  
  424.     NameSymbol *ConvertUtf8ToUnicode(const char *source, int length)
  425.     {
  426.         wchar_t *name = new wchar_t[length + 1];
  427.         int name_length = ConvertUtf8ToUnicode(name, source, length);
  428.         NameSymbol *name_symbol = FindOrInsertName(name, name_length);
  429.         delete [] name;
  430.  
  431.         return name_symbol;
  432.     }
  433.  
  434.     void FindPathsToDirectory(PackageSymbol *);
  435.  
  436.     DirectoryEntry *FindInputFile(FileSymbol *);
  437.     void FindMoreRecentInputFiles(SymbolSet &);
  438.     void RemoveTrashedTypes(SymbolSet &);
  439.     void RereadDirectory(DirectorySymbol *);
  440.     void RereadDirectories();
  441.     void ComputeRecompilationSet(TypeDependenceChecker &);
  442.     bool IncrementalRecompilation();
  443.  
  444.     //
  445.     // The one and only null value constant.
  446.     //
  447.     LiteralValue *NullValue() { return &null_value; }
  448.  
  449.     //
  450.     // The one and only bad value constant.
  451.     //
  452.     LiteralValue *BadValue() { return &bad_value; }
  453.  
  454.     //
  455.     // Note that only names are converted here and not literals, since
  456.     // no error can occur in a name.
  457.     // A literal is converted during the semantic pass so that an
  458.     // accurate diagnostic can be issued in case it is invalid.
  459.     //
  460.     NameSymbol *FindOrInsertName(wchar_t *name, int len)
  461.     {
  462.         NameSymbol *name_symbol = name_table.FindOrInsertName(name, len);
  463.         if (! name_symbol -> Utf8_literal)
  464.             name_symbol -> Utf8_literal = ConvertUnicodeToUtf8(name_symbol -> Name());
  465.  
  466.         return name_symbol;
  467.     }
  468.  
  469.     //
  470.     // Make up a parameter name of the form #(num) and return its name symbol.
  471.     //
  472.     NameSymbol *MakeParameter(int num)
  473.     {
  474.         IntToWstring value(num);
  475.  
  476.         wchar_t str[13];
  477.         str[0] = U_DOLLAR; // '$'
  478.         wcscpy(&str[1], value.String());
  479.  
  480.         return FindOrInsertName(str, value.Length() + 1);
  481.     }
  482.  
  483.     //
  484.     //
  485.     //
  486.     static DirectorySymbol *GetOutputDirectory(FileSymbol *);
  487.     static FileSymbol *GetJavaFile(PackageSymbol *, NameSymbol *);
  488.     static FileSymbol *GetFile(Control &, PackageSymbol *, NameSymbol *);
  489.     static FileSymbol *GetFileFirst(Control &, PackageSymbol *, NameSymbol *);
  490.     static FileSymbol *GetFileBoth(Control &, PackageSymbol *, NameSymbol *);
  491.  
  492.     PackageSymbol *FindOrInsertPackage(LexStream *, AstExpression *);
  493.     void ProcessPackageDeclaration(FileSymbol *, AstPackageDeclaration *);
  494.     void CleanUp(FileSymbol *);
  495.  
  496.     inline bool IsSimpleIntegerValueType(TypeSymbol *type)
  497.     {
  498.         return (type == byte_type || type == short_type || type == int_type || type == char_type);
  499.     }
  500.  
  501.     inline bool IsIntegral(TypeSymbol *type)
  502.     {
  503.         return (IsSimpleIntegerValueType(type) || type == long_type);
  504.     }
  505.  
  506.     inline bool IsFloatingPoint(TypeSymbol *type)
  507.     {
  508.         return (type == float_type || type == double_type);
  509.     }
  510.  
  511.     inline bool IsNumeric(TypeSymbol *type)
  512.     {
  513.         return IsIntegral(type) || IsFloatingPoint(type);
  514.     }
  515.  
  516.     inline bool IsDoubleWordType(TypeSymbol *type)
  517.     {
  518.         return (type == long_type || type == double_type);
  519.     }
  520.  
  521.     inline bool IsPrimitive(TypeSymbol *type)
  522.     {
  523.         return (IsNumeric(type) || type == boolean_type);
  524.     }
  525.  
  526.     inline void ProcessBadType(TypeSymbol *type_symbol)
  527.     {
  528.         type_trash_bin.Next() = type_symbol;
  529.     }
  530.  
  531.     void ProcessHeaders(FileSymbol *);
  532.  
  533. #ifdef JIKES_DEBUG
  534.     int input_files_processed,
  535.         class_files_read,
  536.         class_files_written,
  537.         line_count;
  538. #endif
  539.  
  540.     PackageSymbol *ProcessPackage(wchar_t *);
  541.  
  542.     DirectorySymbol *FindSubdirectory(PathSymbol *, wchar_t *, int);
  543.     DirectorySymbol *ProcessSubdirectories(wchar_t *, int);
  544.  
  545. private:
  546.  
  547.     LiteralValue null_value,
  548.                  bad_value;
  549.  
  550.     TypeSymbol *Serializable_type,
  551.  
  552.                *Object_type,
  553.                *Cloneable_type,
  554.                *String_type,
  555.                *Void_type,
  556.                *Boolean_type,
  557.                *Byte_type,
  558.                *Short_type,
  559.                *Character_type,
  560.                *Integer_type,
  561.                *Long_type,
  562.                *Float_type,
  563.                *Double_type,
  564.                *Class_type,
  565.                *Throwable_type,
  566.                *Exception_type,
  567.                *RuntimeException_type,
  568.                *ClassNotFoundException_type,
  569.                *Error_type,
  570.                *Vector_type,
  571.                *NoClassDefFoundError_type,
  572.                *StringBuffer_type;
  573.  
  574.     MethodSymbol *Class_forName_method,
  575.  
  576.                  *Throwable_getMessage_method,
  577.  
  578.                  *NoClassDefFoundError_InitWithString_method,
  579.  
  580.                  *StringBuffer_Init_method,
  581.                  *StringBuffer_InitWithString_method,
  582.                  *StringBuffer_toString_method,
  583.                  *StringBuffer_append_char_array_method,
  584.                  *StringBuffer_append_char_method,
  585.                  *StringBuffer_append_boolean_method,
  586.                  *StringBuffer_append_int_method,
  587.                  *StringBuffer_append_long_method,
  588.                  *StringBuffer_append_float_method,
  589.                  *StringBuffer_append_double_method,
  590.                  *StringBuffer_append_string_method,
  591.                  *StringBuffer_append_object_method;
  592.  
  593.     static int ConvertUnicodeToUtf8(wchar_t *, char *);
  594.  
  595.     void ProcessGlobals();
  596.     void ProcessUnnamedPackage();
  597.     void ProcessPath();
  598.     TypeSymbol *GetPrimitiveType(wchar_t *, char *);
  599.     void ProcessSystemInformation();
  600.  
  601.     void ProcessFile(FileSymbol *);
  602.     void ProcessMembers();
  603.     void ProcessBodies(TypeSymbol *);
  604.  
  605.     void ProcessNewInputFiles(SymbolSet &, char **, int = 0);
  606.  
  607.     FileSymbol *FindOrInsertJavaInputFile(DirectorySymbol *, NameSymbol *);
  608.     FileSymbol *FindOrInsertJavaInputFile(wchar_t *, int);
  609. };
  610.  
  611. #ifdef    HAVE_JIKES_NAMESPACE
  612. }            // Close namespace Jikes block
  613. #endif
  614.  
  615. #endif /* control_INCLUDED */
  616.  
  617.