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

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