home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / Beta / ast.h < prev    next >
C/C++ Source or Header  |  2007-09-04  |  47KB  |  1,837 lines

  1. // ast.h  --  Classes of the Abstract Syntax Tree (AST)
  2. //
  3. // KPL Compiler
  4. //
  5. // Copyright 2002-2007, Harry H. Porter III
  6. //
  7. // This file may be freely copied, modified and compiled, on the sole
  8. // condition that if you modify it...
  9. //   (1) Your name and the date of modification is added to this comment
  10. //       under "Modifications by", and
  11. //   (2) Your name and the date of modification is added to the printHelp()
  12. //       routine in file "main.cc" under "Modifications by".
  13. //
  14. // Original Author:
  15. //   06/15/02 - Harry H. Porter III
  16. //
  17. // Modifcations by:
  18. //   03/15/06 - Harry H. Porter III
  19. //
  20.  
  21.  
  22.  
  23. //class AstNode;              // ...
  24.  
  25.   class Header;                // HEADER
  26.   class Code;                  // CODE
  27.   class Uses;                  // USES
  28.   class Renaming;              // RENAMING
  29.   class Abstract;              // ...
  30.     class Interface;              // INTERFACE
  31.     class ClassDef;               // CLASS_DEF
  32.   class Behavior;              // BEHAVIOR
  33.   class TypeDef;               // TYPE_DEF
  34.   class ConstDecl;             // CONST_DECL
  35.   class ErrorDecl;             // ERROR_DECL
  36.   class FunctionProto;         // FUNCTION_PROTO
  37.   class MethodProto;           // METHOD_PROTO
  38.   class MethOrFunction;        // ...
  39.     class Function;               // FUNCTION
  40.     class Method;                 // METHOD
  41.   class TypeParm;              // TYPE_PARM
  42.   class TypeArg;               // TYPE_ARG
  43.  
  44.   class Type;                  // ...
  45.     class CharType;               // CHAR_TYPE
  46.     class IntType;                // INT_TYPE
  47.     class DoubleType;             // DOUBLE_TYPE
  48.     class BoolType;               // BOOL_TYPE
  49.     class VoidType;               // VOID_TYPE
  50.     class TypeOfNullType;         // TYPE_OF_NULL_TYPE
  51.     class AnyType;                // ANY_TYPE
  52.     class PtrType;                // PTR_TYPE
  53.     class ArrayType;              // ARRAY_TYPE
  54.     class RecordType;             // RECORD_TYPE
  55.     class FunctionType;           // FUNCTION_TYPE
  56.     class NamedType;              // NAMED_TYPE
  57.  
  58.   class Statement;             // ...
  59.     class IfStmt;                 // IF_STMT
  60.     class AssignStmt;             // ASSIGN_STMT
  61.     class CallStmt;               // CALL_STMT
  62.     class SendStmt;               // SEND_STMT
  63.     class WhileStmt;              // WHILE_STMT
  64.     class DoStmt;                 // DO_STMT
  65.     class BreakStmt;              // BREAK_STMT
  66.     class ContinueStmt;           // CONTINUE_STMT
  67.     class ReturnStmt;             // RETURN_STMT
  68.     class ForStmt;                // FOR_STMT
  69.     class SwitchStmt;             // SWITCH_STMT
  70.     class TryStmt;                // TRY_STMT
  71.     class ThrowStmt;              // THROW_STMT
  72.     class FreeStmt;               // FREE_STMT
  73.     class DebugStmt;              // DEBUG_STMT
  74.  
  75.   class Case;                  // CASE
  76.   class Catch;                 // CATCH
  77.  
  78.   class VarDecl;               // ...
  79.     class Global;                 // GLOBAL
  80.     class Local;                  // LOCAL
  81.     class Parameter;              // PARAMETER
  82.     class ClassField;             // CLASS_FIELD
  83.     class RecordField;            // RECORD_FIELD
  84.  
  85.   class Expression;            // ...
  86.  
  87.     class Constant;               // ...
  88.       class IntConst;                // INT_CONST
  89.       class DoubleConst;             // DOUBLE_CONST
  90.       class CharConst;               // CHAR_CONST
  91.       class StringConst;             // STRING_CONST
  92.       class BoolConst;               // BOOL_CONST
  93.       class NullConst;               // NULL_CONST
  94.  
  95.     class CallExpr;               // CALL_EXPR
  96.     class SendExpr;               // SEND_EXPR
  97.     class SelfExpr;               // SELF_EXPR
  98.     class SuperExpr;              // SUPER_EXPR
  99.     class FieldAccess;            // FIELD_ACCESS
  100.     class ArrayAccess;            // ARRAY_ACCESS
  101.     class Constructor;            // CONSTRUCTOR
  102.     class ClosureExpr;            // CLOSURE_EXPR
  103.     class VariableExpr;           // VARIABLE_EXPR
  104.     class AsPtrToExpr;            // AS_PTR_TO_EXPR
  105.     class AsIntegerExpr;          // AS_INTEGER_EXPR
  106.     class ArraySizeExpr;          // ARRAY_SIZE_EXPR
  107.     class IsInstanceOfExpr;       // IS_INSTANCE_OF_EXPR
  108.     class IsKindOfExpr;           // IS_KIND_OF_EXPR
  109.     class SizeOfExpr;             // SIZE_OF_EXPR
  110.     class DynamicCheck;           // DYNAMIC_CHECK
  111.  
  112.   class Argument;              // ARGUMENT
  113.   class CountValue;            // COUNT_VALUE
  114.   class FieldInit;             // FIELD_INIT
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. //----------  AstNode  ----------
  122.  
  123. class AstNode {
  124.   public:
  125.     int   op;                      // e.g., HEADER, IF_STMT, SEND_EXPR, etc.
  126.     Token tokn;
  127.  
  128.     AstNode (int oper) {
  129.       op = oper;
  130.       tokn = token;
  131.     }
  132.     ~AstNode () {}
  133.     virtual void prettyPrint (int indent);
  134.     void positionAt (AstNode * node) {
  135.       tokn = node->tokn;
  136.     }
  137.     void positionAtToken (Token tok) {
  138.       tokn = tok;
  139.     }
  140. };
  141.  
  142.  
  143. //----------  Header  ----------
  144.  
  145. class Header : public AstNode {
  146.   public:
  147.     Header *        next;
  148.     String *        packageName;     // e.g., "MyPack"
  149.     Uses *          uses;            // Linked list, may be NULL
  150.     ConstDecl *     consts;          // Linked list, may be NULL
  151.     ErrorDecl *     errors;          // Linked list, may be NULL
  152.     Global *        globals;         // Linked list, may be NULL
  153.     TypeDef *       typeDefs;        // Linked list, may be NULL
  154.     FunctionProto * functionProtos;  // Linked list, may be NULL
  155.     Interface *     interfaces;      // Linked list, may be NULL
  156.     ClassDef *      classes;         // Linked list, may be NULL
  157.     int             hashVal;         // The pseudo-random code for this token sequence
  158.     int             mark;            // 0=unseen, 1=processing, 2=done
  159.     Header *        tempNext;        // Used in topoProcessAllPackages
  160.     Mapping<String,AstNode> *        // String --> ConstDecl,Global,TypeDef,
  161.                     packageMapping;  //            FunctionProto, Interface, ClassDef
  162.     Mapping<String,ErrorDecl> *      // String --> ErrorDecl
  163.                     errorMapping;    //
  164.     Function *      functions;       // For mainHeader; same as in code file
  165.     Function *      closures;        // All closures we have encountered;
  166.  
  167.     Header () : AstNode (HEADER) {
  168.       next = NULL;
  169.       packageName = NULL;
  170.       uses = NULL;
  171.       consts = NULL;
  172.       errors = NULL;
  173.       globals = NULL;
  174.       typeDefs = NULL;
  175.       functionProtos = NULL;
  176.       interfaces = NULL;
  177.       classes = NULL;
  178.       hashVal = 0;
  179.       mark = 0;
  180.       tempNext = NULL;
  181.       packageMapping = NULL;
  182.       errorMapping = NULL;
  183.       functions = NULL;
  184.       closures = NULL;
  185.     }
  186.     ~Header () {}
  187.     virtual void prettyPrint (int indent);
  188. };
  189.  
  190.  
  191.  
  192. //----------  Code  ----------
  193.  
  194. class Code : public AstNode {
  195.   public:
  196.     String *    packageName;         // e.g., "MyPack"
  197.     ConstDecl * consts;              // Linked list, may be NULL
  198.     ErrorDecl * errors;              // Linked list, may be NULL
  199.     Global *    globals;             // Linked list, may be NULL
  200.     TypeDef *   typeDefs;            // Linked list, may be NULL
  201.     Function *  functions;           // Linked list, may be NULL
  202.     Interface * interfaces;          // Linked list, may be NULL
  203.     ClassDef *  classes;             // Linked list, may be NULL
  204.     Behavior *  behaviors;           // Linked list, may be NULL
  205.     int         hashVal;             // The pseudo-random code for this token sequence
  206.  
  207.     Code () : AstNode (CODE) {
  208.       packageName = NULL;
  209.       consts = NULL;
  210.       errors = NULL;
  211.       globals = NULL;
  212.       typeDefs = NULL;
  213.       functions = NULL;
  214.       interfaces = NULL;
  215.       classes = NULL;
  216.       behaviors = NULL;
  217.       hashVal = 0;
  218.     }
  219.     ~ Code () {}
  220.     virtual void prettyPrint (int indent);
  221. };
  222.  
  223.  
  224.  
  225. //----------  Uses  ----------
  226.  
  227. class Uses : public AstNode {
  228.   public:
  229.     Uses *     next;
  230.     String *   id;                // name of package (e.g., "SysPack")
  231.     Renaming * renamings;         // Linked list, may be NULL
  232.     Header *    myDef;            // Null if errors in topoProcessing Headers
  233.  
  234.     Uses () : AstNode (USES) {
  235.       next = NULL;
  236.       id = NULL;
  237.       renamings = NULL;
  238.       myDef = NULL;
  239.     }
  240.     ~ Uses () {}
  241.     virtual void prettyPrint (int indent);
  242. };
  243.  
  244.  
  245.  
  246. //----------  Renaming  ----------
  247.  
  248. class Renaming : public AstNode {
  249.   public:
  250.     Renaming * next;
  251.     String *   from;               // e.g., "foo" or "++"
  252.     String *   to;                 // e.g., "superFoo" or "^++"
  253.  
  254.     Renaming () : AstNode (RENAMING) {
  255.       next = NULL;
  256.       from = NULL;
  257.       to = NULL;
  258.     }
  259.     ~ Renaming () {}
  260.     virtual void prettyPrint (int indent);
  261. };
  262.  
  263.  
  264.  
  265. //----------  Abstract  ----------
  266.  
  267. class Abstract : public AstNode {
  268.   public:
  269.     String *    id;                            // E.g., "MyClass" or "MyInterface"
  270.     Header *    myHeader;                      // Never NULL (set in
  271.                                                // .  topoProcessClasses / Interfaces)
  272.     Abstract *  nextAbstract;                  // A list of all classes & interfaces
  273.     Mapping<Abstract,Abstract> *               // All sub-Abstracts in this package
  274.                 knownSubAbstracts;             // .  (including self)
  275.     Mapping<Abstract,Abstract> *               // All super-Abstracts in this package
  276.                 superAbstractsInThisPackage;   // .  (including self)
  277.     Mapping<Abstract,Abstract> *               // Minimal super-Abstracts that are
  278.                 supersAbstractsInOtherPackages;// .   not in this package
  279.     Mapping<String,MethodProto> *       // String --> MethodProto
  280.                 selectorMapping;        // For Classes: This includes copies of
  281.                                         //   MethodProtos inherited from our superclass
  282.                                         // For Interfaces: Initially this
  283.                                         //   includes only the local MethodProtos
  284.                                         //   from this interface; after "checkExtends"
  285.                                         //   it includes inherited MethodProtos, too
  286.     Mapping<Offset,String> *            // This maps offsets to selectors
  287.                offsetToSelector;        // .
  288.     Mapping<String,Offset> *            // This maps selectors to offsets
  289.                selectorToOffset;        // .
  290.     Mapping<Offset,String> *            // Indicates that an offset has been reserved
  291.                unavailableOffsets;      // .  in this Abstract (and for which message);
  292.                                         // .  (The message may not be in this Abstract,
  293.                                         // .  but the offset in nonetheless occupied.)
  294.     char *        newName;              // ClassDef: label on dispatch table
  295.                                         // Interface: label on Interface Descriptor
  296.  
  297.     Abstract (int op) : AstNode (op) {
  298.       id = NULL;
  299.       myHeader = NULL;
  300.       nextAbstract = NULL;
  301.       knownSubAbstracts = NULL;
  302.       superAbstractsInThisPackage = NULL;
  303.       supersAbstractsInOtherPackages = NULL;
  304.       selectorMapping = NULL;
  305.       offsetToSelector = NULL;
  306.       selectorToOffset = NULL;
  307.       unavailableOffsets = NULL;
  308.       newName = NULL;
  309.     }
  310.     ~ Abstract () {}
  311.     virtual void prettyPrint (int indent);
  312. };
  313.  
  314.  
  315.  
  316. //----------  Interface  ----------
  317.  
  318. class Interface : public Abstract {
  319.   public:
  320.     Interface *   next;
  321.     TypeParm *    typeParms;               // Linked list, may be NULL
  322.     TypeArg *     extends;                 // Linked list of NamedTypes, may be NULL
  323.     MethodProto * methodProtos;            // Linked list, may be NULL (locals only)
  324.     int           mark;                    // 0=unseen, 1=processing, 2=done
  325.     Interface *   tempNext;                // temp, used in topo-sorting
  326.     int           isPrivate;               // 1=from code file, 0=from header file
  327.     MethodProto *                          // A list of (copies of) inherited
  328.                   inheritedMethodProtos;   //   messages
  329.  
  330.     Interface () : Abstract (INTERFACE) {
  331.       next = NULL;
  332.       typeParms = NULL;
  333.       extends = NULL;
  334.       methodProtos = NULL;
  335.       mark = 0;
  336.       tempNext = NULL;
  337.       isPrivate = 0;
  338.       inheritedMethodProtos = NULL;
  339.     }
  340.     ~ Interface () {}
  341.     virtual void prettyPrint (int indent);
  342. };
  343.  
  344.  
  345.  
  346. //----------  ClassDef  ----------
  347.  
  348. class ClassDef : public Abstract {
  349.   public:
  350.     ClassDef *    next;
  351.     TypeParm *    typeParms;            // Linked list, may be NULL
  352.     TypeArg *     implements;           // Linked list, may be NULL
  353.     NamedType *   superclass;           // NULL means class = "Object"
  354.     ClassField *  fields;               // Linked list, may be NULL
  355.     MethodProto * methodProtos;         // Linked list, may be NULL, in order
  356.                                         //   (copies of inherited protos added at front)
  357.     int mark;                           // 0=unseen, 1=processing, 2=done
  358.     ClassDef *    tempNext;             // temp var, used in topo-sorting
  359.     int           isPrivate;            // 1=from code file, 0=from header file
  360.     Method *      methods;              // From Behavior, may be NULL;
  361.                                         //   Does not include inherited methods.
  362.     ClassDef *    superclassDef;        // To our superclass, NULL if errors or none
  363.     Mapping<TypeParm,Type> *            // This mapping maps TypeParms from the
  364.                   superclassMapping;    //   superclass's ClassDef to types in our
  365.                                         //   'superclass' clause
  366.     Mapping<String,AstNode> *           // String --> ClassField; parent=packageMapping
  367.                   classMapping;         //   Includes copies of inherited ClassFields
  368.     Mapping<String,Method> *            // String --> Method; includes only local methods
  369.                   localMethodMapping;   //   (not inherited methods)
  370.     int           sizeInBytes;          // Size, including class ptr; -1 = problems
  371.     Type *        typeOfSelf;           // e.g., "Person" or Person[T]"
  372.  
  373.     ClassDef () : Abstract (CLASS_DEF) {
  374.       next = NULL;
  375.       typeParms = NULL;
  376.       implements = NULL;
  377.       superclass = NULL;
  378.       fields = NULL;
  379.       methodProtos = NULL;
  380.       mark = 0;
  381.       tempNext = NULL;
  382.       isPrivate = 0;
  383.       methods = NULL;
  384.       superclassDef = NULL;
  385.       superclassMapping = NULL;
  386.       classMapping = NULL;
  387.       localMethodMapping = NULL;
  388.       selectorMapping = NULL;
  389.       sizeInBytes = -1;
  390.       typeOfSelf = NULL;
  391.     }
  392.     ~ ClassDef () {}
  393.     virtual void prettyPrint (int indent);
  394. };
  395.  
  396.  
  397.  
  398. //----------  Behavior  ----------
  399.  
  400. class Behavior : public AstNode {
  401.   public:
  402.     Behavior * next;
  403.     String *   id;
  404.     Method *   methods;            // Linked list, may be NULL
  405.  
  406.     Behavior () : AstNode (BEHAVIOR) {
  407.       next = NULL;
  408.       id = NULL;
  409.       methods = NULL;
  410.     }
  411.     ~ Behavior () {}
  412.     virtual void prettyPrint (int indent);
  413. };
  414.  
  415.  
  416.  
  417. //----------  TypeDef  ----------
  418.  
  419. class TypeDef : public AstNode {
  420.   public:
  421.     TypeDef * next;
  422.     String *  id;
  423.     Type *    type;
  424.     int       mark;
  425.  
  426.     TypeDef () : AstNode (TYPE_DEF) {
  427.       next = NULL;
  428.       id = NULL;
  429.       type = NULL;
  430.       mark = 0;
  431.     }
  432.     ~ TypeDef () {}
  433.     virtual void prettyPrint (int indent);
  434. };
  435.  
  436.  
  437.  
  438. //----------  ConstDecl  ----------
  439.  
  440. class ConstDecl : public AstNode {
  441.   public:
  442.     ConstDecl * next;
  443.     String * id;
  444.     Expression * expr;
  445.     int isPrivate;                  // 1=in code file, 0=in header file
  446.  
  447.     ConstDecl () : AstNode (CONST_DECL) {
  448.       next = NULL;
  449.       id = NULL;
  450.       expr = NULL;
  451.       isPrivate = 0;
  452.     }
  453.     ~ ConstDecl () {}
  454.     virtual void prettyPrint (int indent);
  455. };
  456.  
  457.  
  458.  
  459. //----------  ErrorDecl  ----------
  460.  
  461. class ErrorDecl : public AstNode {
  462.   public:
  463.     ErrorDecl *     next;
  464.     String *       id;
  465.     Parameter *    parmList;         // Linked list, may be NULL
  466. //  int            isPrivate;        // 1=in code file, 0=in header file
  467.     char *         newName;          // E.g., "_Error_P_MyPackageName_OriginalName"
  468.     int            totalParmSize;
  469.  
  470.     ErrorDecl () : AstNode (ERROR_DECL) {
  471.       next = NULL;
  472.       id = NULL;
  473.       parmList = NULL;
  474.       // isPrivate = 0;
  475.       newName = NULL;
  476.       totalParmSize = 0;
  477.     }
  478.     ~ ErrorDecl () {}
  479.     virtual void prettyPrint (int indent);
  480. };
  481.  
  482.  
  483.  
  484. //----------  FunctionProto  ----------
  485.  
  486. class FunctionProto : public AstNode {
  487.   public:
  488.     FunctionProto * next;
  489.     String *        id;
  490.     Parameter *     parmList;       // Linked list, may be NULL
  491.     Type *          retType;        // Never NULL
  492.     int             isExternal;     // 1=external
  493.     int             isPrivate;      // 0=not in header file, 1=in header file
  494.     Header *        myHeader;       // The package containing this function
  495.     Function *      myFunction;     // NULL if none or if error
  496.     char *          newName;        // E.g., "bar", "_function_123_foo", "_closure_321"
  497.     int             totalParmSize;  // Size of all parms, including padding
  498.     int             retSize;        // Size of return result (-1 = void, could be 1)
  499.  
  500.     FunctionProto () : AstNode (FUNCTION_PROTO) {
  501.       next = NULL;
  502.       id = NULL;
  503.       parmList = NULL;
  504.       retType = NULL;
  505.       isExternal = 0;
  506.       isPrivate = 0;
  507.       myHeader = NULL;
  508.       myFunction = NULL;
  509.       totalParmSize = 0;
  510.       retSize = 0;
  511.     }
  512.     ~ FunctionProto () {}
  513.     virtual void prettyPrint (int indent);
  514. };
  515.  
  516.  
  517.  
  518. //----------  MethodProto  ----------
  519.  
  520. class MethodProto : public AstNode {
  521.   public:
  522.     MethodProto * next;
  523.     int           kind;             // INFIX, PREFIX, KEYWORD, NORMAL
  524.     String *      selector;         // e.g., "foo", "+", "at:put:"
  525.     Parameter *   parmList;         // Linked list, may be NULL
  526.     Type *        retType;          // Never NULL
  527.     Method *      myMethod;         // For Classes: Only NULL when errors; may
  528.                                     //   point to Methods in a superclass
  529.                                     // For interfaces: Always NULL
  530.     int           totalParmSize;    // Size of all parms, including padding
  531.     int           retSize;          // Size of return result (-1 = void, could be 1)
  532.     int           offset;           // The offset in the dispatch table
  533.  
  534.     MethodProto () : AstNode (METHOD_PROTO) {
  535.       next = NULL;
  536.       selector = NULL;
  537.       parmList = NULL;
  538.       retType = NULL;
  539.       kind = EOF;
  540.       myMethod = NULL;
  541.       totalParmSize = 0;
  542.       retSize = 0;
  543.       offset = -1;
  544.     }
  545.     ~ MethodProto () {}
  546.     virtual void prettyPrint (int indent);
  547. };
  548.  
  549.  
  550.  
  551. //----------  MethOrFunction  ----------
  552.  
  553. class MethOrFunction : public AstNode {
  554.   public:
  555.     Parameter *     parmList;       // Linked list, may be NULL
  556.     Type *          retType;        // Never NULL
  557.     Local *         locals;         // Linked list, may be NULL
  558.     Statement *     stmts;          // Linked list, may be NULL
  559.     int             frameSize;      // Frame size in bytes
  560.     char *          newName;        // Methods: e.g., "_Method_P_MyPackageName_47"
  561.                                     // Funs: "bar", "_function_123_foo", "_closure_321"
  562.     int             maxArgBytes;    // Minimum is zero if we call no funs or meths
  563.     int             totalParmSize;  // Size of all parms, including padding
  564.     int             containsTry;    // 1=there is a TRY stmt in this function
  565.     Local *         catchStackSave; // The temp where the catch stack will be saved
  566.     Catch *         catchList;      // List of all catches in this function
  567.  
  568.     MethOrFunction (int op) : AstNode (op) {
  569.       parmList = NULL;
  570.       retType = NULL;
  571.       locals = NULL;
  572.       stmts = NULL;
  573.       frameSize = -1;
  574.       newName = NULL;
  575.       maxArgBytes = -1;
  576.       totalParmSize = 0;
  577.       containsTry = 0;
  578.       catchStackSave = NULL;
  579.       catchList = NULL;
  580.     }
  581.     ~ MethOrFunction () {}
  582.     virtual void prettyPrint (int indent);
  583. };
  584.  
  585.  
  586.  
  587. //----------  Function  ----------
  588.  
  589. class Function : public MethOrFunction {
  590.   public:
  591.     Function *      next;
  592.     String *        id;             // NULL = Closure
  593.     FunctionProto * myProto;        // Null if error or closure
  594.  
  595.     Function () : MethOrFunction (FUNCTION) {
  596.       next = NULL;
  597.       id = NULL;
  598.       myProto = NULL;
  599.     }
  600.     ~ Function () {}
  601.     virtual void prettyPrint (int indent);
  602. };
  603.  
  604.  
  605.  
  606. //----------  Method  ----------
  607.  
  608. class Method : public MethOrFunction {
  609.   public:
  610.     Method *      next;
  611.     int           kind;             // INFIX, PREFIX, KEYWORD, NORMAL
  612.     String *      selector;         // e.g., "foo", "+", "at:put:"
  613.     MethodProto * myMethodProto;    // Only NULL when errors
  614.     ClassDef *    myClass;          // Class in which this code appeared
  615.  
  616.     Method () : MethOrFunction (METHOD) {
  617.       next = NULL;
  618.       kind = 0;
  619.       selector = NULL;
  620.       myMethodProto = NULL;
  621.       myClass = NULL;
  622.     }
  623.     ~ Method () {}
  624.     virtual void prettyPrint (int indent);
  625. };
  626.  
  627.  
  628.  
  629. //----------  TypeParm  ----------
  630.  
  631. class TypeParm : public AstNode {
  632.   //
  633.   // This represents something like [T1: Object, T2: String]
  634.   //
  635.   public:
  636.     TypeParm * next;
  637.     String * id;
  638.     Type * type;
  639.     int fourByteRestricted;               // 1=used in field, local, or parm decl
  640.  
  641.     TypeParm () : AstNode (TYPE_PARM) {
  642.       next = NULL;
  643.       id = NULL;
  644.       type = NULL;
  645.       fourByteRestricted = 0;
  646.     }
  647.     ~ TypeParm () {}
  648.     virtual void prettyPrint (int indent);
  649. };
  650.  
  651.  
  652.  
  653. //----------  TypeArg  ----------
  654.  
  655. class TypeArg : public AstNode {
  656.   //
  657.   // This represents something like "int, char, List[String]"
  658.   //
  659.   public:
  660.     TypeArg * next;
  661.     Type *    type;
  662.     int       offset;          // Only for typeArgs in FunctionTypes
  663.     int       sizeInBytes;     // Only for typeArgs in FunctionTypes
  664.  
  665.     TypeArg () : AstNode (TYPE_ARG) {
  666.       next        = NULL;
  667.       type        = NULL;
  668.       offset       = -1;
  669.       sizeInBytes = -1;
  670.     }
  671.     ~ TypeArg () {}
  672.     virtual void prettyPrint (int indent);
  673. };
  674.  
  675.  
  676.  
  677. //----------  Type  ----------
  678.  
  679. class Type : public AstNode {
  680.   public:
  681.  
  682.     Type (int op) : AstNode (op) { }
  683.     ~ Type () {}
  684.     virtual void prettyPrint (int indent);
  685. };
  686.  
  687.  
  688.  
  689. //----------  CharType  ----------
  690.  
  691. class CharType : public Type {
  692.   public:
  693.  
  694.     CharType () : Type (CHAR_TYPE) { }
  695.     ~ CharType () {}
  696.     virtual void prettyPrint (int indent);
  697. };
  698.  
  699.  
  700.  
  701. //----------  IntType  ----------
  702.  
  703. class IntType : public Type {
  704.   public:
  705.  
  706.     IntType () : Type (INT_TYPE) { }
  707.     ~ IntType () {}
  708.     virtual void prettyPrint (int indent);
  709. };
  710.  
  711.  
  712.  
  713. //----------  DoubleType  ----------
  714.  
  715. class DoubleType : public Type {
  716.   public:
  717.  
  718.     DoubleType () : Type (DOUBLE_TYPE) { }
  719.     ~ DoubleType () {}
  720.     virtual void prettyPrint (int indent);
  721. };
  722.  
  723.  
  724.  
  725. //----------  BoolType  ----------
  726.  
  727. class BoolType : public Type {
  728.   public:
  729.  
  730.     BoolType () : Type (BOOL_TYPE) { }
  731.     ~ BoolType () {}
  732.     virtual void prettyPrint (int indent);
  733. };
  734.  
  735.  
  736.  
  737. //----------  VoidType  ----------
  738.  
  739. class VoidType : public Type {
  740.   public:
  741.  
  742.     VoidType () : Type (VOID_TYPE) { }
  743.     ~ VoidType () {}
  744.     virtual void prettyPrint (int indent);
  745. };
  746.  
  747.  
  748.  
  749. //----------  TypeOfNullType  ----------
  750.  
  751. class TypeOfNullType : public Type {
  752.   public:
  753.  
  754.     TypeOfNullType () : Type (TYPE_OF_NULL_TYPE) { }
  755.     ~ TypeOfNullType () {}
  756.     virtual void prettyPrint (int indent);
  757. };
  758.  
  759.  
  760.  
  761. //----------  AnyType  ----------
  762.  
  763. class AnyType : public Type {
  764.   public:
  765.  
  766.     AnyType () : Type (ANY_TYPE) { }
  767.     ~ AnyType () {}
  768.     virtual void prettyPrint (int indent);
  769. };
  770.  
  771.  
  772.  
  773. //----------  PtrType  ----------
  774.  
  775. class PtrType : public Type {
  776.   public:
  777.     Type * baseType;
  778.  
  779.     PtrType () : Type (PTR_TYPE) {
  780.       baseType = NULL;
  781.     }
  782.     ~ PtrType () {}
  783.     virtual void prettyPrint (int indent);
  784. };
  785.  
  786.  
  787.  
  788. //----------  ArrayType  ----------
  789.  
  790. class ArrayType : public Type {
  791.   public:
  792.     Expression * sizeExpr;              // May be NULL
  793.     Type * baseType;
  794.     int sizeInBytes;                    // -1 = error or "array [*] of ..."
  795.     int sizeOfElements;                 // size of each element
  796.  
  797.     ArrayType () : Type (ARRAY_TYPE) {
  798.       sizeExpr = NULL;
  799.       baseType = NULL;
  800.       sizeInBytes = -1;
  801.       sizeOfElements = -1;
  802.     }
  803.     ~ ArrayType () {}
  804.     virtual void prettyPrint (int indent);
  805. };
  806.  
  807.  
  808.  
  809. //----------  RecordType  ----------
  810.  
  811. class RecordType : public Type {
  812.   public:
  813.     RecordField * fields;               // Null only if syntax error
  814.     int sizeInBytes;                    // Always a mulitple of 4
  815.     Mapping<String, RecordField> *      // String --> RecordField
  816.               fieldMapping;             //
  817.  
  818.     RecordType () : Type (RECORD_TYPE) {
  819.       fields = NULL;
  820.       sizeInBytes = -1;
  821.       fieldMapping = NULL;
  822.     }
  823.     ~ RecordType () {}
  824.     virtual void prettyPrint (int indent);
  825. };
  826.  
  827.  
  828.  
  829. //----------  FunctionType  ----------
  830.  
  831. class FunctionType : public Type {
  832.   public:
  833.     TypeArg * parmTypes;          // may be NULL
  834.     Type * retType;               // never NULL
  835.     int totalParmSize;            // Size of all parms, including return value!
  836.     int retSize;                  // Size of return result (-1 = void, could be 1)
  837.  
  838.     FunctionType () : Type (FUNCTION_TYPE) {
  839.       parmTypes = NULL;
  840.       retType = NULL;
  841.       totalParmSize = -1;
  842.       retSize = 0;
  843.     }
  844.     ~ FunctionType () {}
  845.     virtual void prettyPrint (int indent);
  846. };
  847.  
  848.  
  849.  
  850. //----------  NamedType  ----------
  851.  
  852. class NamedType : public Type {
  853.   //
  854.   // This represents something like "Person" or "Dictionary [String, int]"
  855.   //
  856.   public:
  857.     String * id;
  858.     TypeArg * typeArgs;                // May be NULL
  859.     AstNode * myDef;                   // Interface, ClassDef, TypeParm,
  860.                                        //   or TypeDef, or NULL if error
  861.     Mapping <TypeParm, Type> * subst;  // Used only for class and interfaces;
  862.                                        //   may be NULL
  863.  
  864.     NamedType () : Type (NAMED_TYPE) {
  865.       id = NULL;
  866.       typeArgs = NULL;
  867.       myDef = NULL;
  868.       subst = NULL;
  869.     }
  870.     ~ NamedType () {}
  871.     virtual void prettyPrint (int indent);
  872. };
  873.  
  874.  
  875.  
  876. //----------  Statement  ----------
  877.  
  878. class Statement : public AstNode {
  879.   public:
  880.     Statement * next;               // Statements are kept on linked lists
  881.  
  882.     Statement (int op) : AstNode (op) {
  883.       next = NULL;
  884.     }
  885.     ~ Statement () {}
  886.     virtual void prettyPrint (int indent);
  887. };
  888.  
  889.  
  890.  
  891. //----------  IfStmt  ----------
  892.  
  893. class IfStmt : public Statement {
  894.   public:
  895.     Expression * expr;
  896.     Statement * thenStmts;               // may be NULL
  897.     Statement * elseStmts;               // may be NULL
  898.  
  899.     IfStmt () : Statement (IF_STMT) {
  900.       expr = NULL;
  901.       thenStmts = NULL;
  902.       elseStmts = NULL;
  903.     }
  904.     ~ IfStmt () {}
  905.     virtual void prettyPrint (int indent);
  906. };
  907.  
  908.  
  909.  
  910. //----------  AssignStmt  ----------
  911.  
  912. class AssignStmt : public Statement {
  913.   public:
  914.     Expression * lvalue;
  915.     Expression * expr;
  916.     int          sizeInBytes;            // The number of bytes to be copied
  917.     int          dynamicCheck;           // 0 means no special check is needed
  918.     ClassDef *   classDef;               // For dynamicCheck == 2 or 3
  919.     int          arraySize;              // For dynamicCheck == 5, 6, or 7
  920.  
  921.     AssignStmt () : Statement (ASSIGN_STMT) {
  922.       lvalue = NULL;
  923.       expr = NULL;
  924.       sizeInBytes = -1;
  925.       dynamicCheck = 0;
  926.       classDef = NULL;
  927.       arraySize = -1;
  928.     }
  929.     ~ AssignStmt () {}
  930.     virtual void prettyPrint (int indent);
  931. };
  932.  
  933.  
  934.  
  935. //----------  CallStmt  ----------
  936.  
  937. class CallStmt : public Statement {
  938.   public:
  939.     CallExpr * expr;         // NULL if error
  940.  
  941.     CallStmt () : Statement (CALL_STMT) {
  942.       expr = NULL;
  943.     }
  944.     ~ CallStmt () {}
  945.     virtual void prettyPrint (int indent);
  946. };
  947.  
  948.  
  949.  
  950. //----------  SendStmt  ----------
  951.  
  952. class SendStmt : public Statement {
  953.   public:
  954.     SendExpr * expr;         // NULL if error
  955.  
  956.     SendStmt () : Statement (SEND_STMT) {
  957.       expr = NULL;
  958.     }
  959.     ~ SendStmt () {}
  960.     virtual void prettyPrint (int indent);
  961. };
  962.  
  963.  
  964.  
  965. //----------  WhileStmt  ----------
  966.  
  967. class WhileStmt : public Statement {
  968.   public:
  969.     Expression * expr;
  970.     Statement * stmts;
  971.     int containsAnyBreaks;
  972.     int containsAnyContinues;
  973.     char * topLabel;
  974.     char * exitLabel;
  975.  
  976.     WhileStmt () : Statement (WHILE_STMT) {
  977.       expr = NULL;
  978.       stmts = NULL;
  979.       containsAnyBreaks = 0;
  980.       containsAnyContinues = 0;
  981.       topLabel = NULL;
  982.       exitLabel = NULL;
  983.     }
  984.     ~ WhileStmt () {}
  985.     virtual void prettyPrint (int indent);
  986. };
  987.  
  988.  
  989.  
  990. //----------  DoStmt  ----------
  991.  
  992. class DoStmt : public Statement {
  993.   public:
  994.     Statement * stmts;
  995.     Expression * expr;
  996.     int containsAnyBreaks;
  997.     int containsAnyContinues;
  998.     char * exitLabel;
  999.     char * testLabel;
  1000.  
  1001.     DoStmt () : Statement (DO_STMT) {
  1002.       stmts = NULL;
  1003.       expr = NULL;
  1004.       containsAnyBreaks = 0;
  1005.       containsAnyContinues = 0;
  1006.       exitLabel = NULL;
  1007.       testLabel = NULL;
  1008.     }
  1009.     ~ DoStmt () {}
  1010.     virtual void prettyPrint (int indent);
  1011. };
  1012.  
  1013.  
  1014.  
  1015. //----------  BreakStmt  ----------
  1016.  
  1017. class BreakStmt : public Statement {
  1018.   public:
  1019.     Statement * enclosingStmt;     // A FOR_STMT, DO_STMT, WHILE_STMT, or SWITCH_STMT
  1020.  
  1021.     BreakStmt () : Statement (BREAK_STMT) {
  1022.       enclosingStmt = NULL;
  1023.     }
  1024.     ~ BreakStmt () {}
  1025.     virtual void prettyPrint (int indent);
  1026. };
  1027.  
  1028.  
  1029.  
  1030. //----------  ContinueStmt  ----------
  1031.  
  1032. class ContinueStmt : public Statement {
  1033.   public:
  1034.     Statement * enclosingStmt;       // A FOR_STMT, DO_STMT, or WHILE_STMT
  1035.  
  1036.     ContinueStmt () : Statement (CONTINUE_STMT) {
  1037.       enclosingStmt = NULL;
  1038.     }
  1039.     ~ ContinueStmt () {}
  1040.     virtual void prettyPrint (int indent);
  1041. };
  1042.  
  1043.  
  1044.  
  1045. //----------  ReturnStmt  ----------
  1046.  
  1047. class ReturnStmt : public Statement {
  1048.   public:
  1049.     Expression * expr;                   // may be NULL
  1050.     MethOrFunction * enclosingMethOrFunction;   // not NULL
  1051.     int retSize;                         // Size of return result (-1 = void, could be 1)
  1052.  
  1053.     ReturnStmt () : Statement (RETURN_STMT) {
  1054.       expr = NULL;
  1055.       enclosingMethOrFunction = NULL;
  1056.       retSize = 0;
  1057.     }
  1058.     ~ ReturnStmt () {}
  1059.     virtual void prettyPrint (int indent);
  1060. };
  1061.  
  1062.  
  1063.  
  1064. //----------  ForStmt  ----------
  1065.  
  1066. class ForStmt : public Statement {
  1067.   public:
  1068.     Expression * lvalue;
  1069.     Expression * expr1;
  1070.     Expression * expr2;
  1071.     Expression * expr3;            // may be NULL
  1072.     Statement * stmts;
  1073.     int containsAnyBreaks;
  1074.     int containsAnyContinues;
  1075.     char * incrLabel;
  1076.     char * exitLabel;
  1077.  
  1078.     ForStmt () : Statement (FOR_STMT) {
  1079.       lvalue = NULL;
  1080.       expr1 = NULL;
  1081.       expr2 = NULL;
  1082.       expr3 = NULL;
  1083.       stmts = NULL;
  1084.       containsAnyBreaks = 0;
  1085.       containsAnyContinues = 0;
  1086.       incrLabel = NULL;
  1087.       exitLabel = NULL;
  1088.     }
  1089.     ~ ForStmt () {}
  1090.     virtual void prettyPrint (int indent);
  1091. };
  1092.  
  1093.  
  1094.  
  1095. //----------  SwitchStmt  ----------
  1096.  
  1097. class SwitchStmt : public Statement {
  1098.   public:
  1099.     Expression * expr;
  1100.     Case * caseList;                     // may be NULL
  1101.     Statement * defaultStmts;            // may be NULL
  1102.     int containsAnyBreaks;
  1103.     int defaultIncluded;                 // 1="default:" clause is present
  1104.                                          // if absent, must check for runtime error
  1105.     int lowValue;                        // The range of values seen
  1106.     int highValue;                       // .
  1107.     char * exitLabel;                    // Used for break stmts
  1108.  
  1109.     SwitchStmt () : Statement (SWITCH_STMT) {
  1110.       expr = NULL;
  1111.       caseList = NULL;
  1112.       defaultStmts = NULL;
  1113.       containsAnyBreaks = 0;
  1114.       defaultIncluded = 0;
  1115.       lowValue = 0x7fffffff;
  1116.       highValue = 0x80000000;
  1117.       exitLabel = NULL;
  1118.     }
  1119.     ~ SwitchStmt () {}
  1120.     virtual void prettyPrint (int indent);
  1121. };
  1122.  
  1123.  
  1124.  
  1125. //----------  TryStmt  ----------
  1126.  
  1127. class TryStmt : public Statement {
  1128.   public:
  1129.     Statement * stmts;               // may be NULL
  1130.     Catch * catchList;               // NULL only if errors
  1131.  
  1132.     TryStmt () : Statement (TRY_STMT) {
  1133.       stmts = NULL;
  1134.       catchList = NULL;
  1135.     }
  1136.     ~ TryStmt () {}
  1137.     virtual void prettyPrint (int indent);
  1138. };
  1139.  
  1140.  
  1141.  
  1142. //----------  ThrowStmt  ----------
  1143.  
  1144. class ThrowStmt : public Statement {
  1145.   public:
  1146.     String * id;                  // aaaa
  1147.     Argument * argList;           // may be NULL
  1148.     ErrorDecl * myDef;            // NULL iff errors
  1149.  
  1150.     ThrowStmt () : Statement (THROW_STMT) {
  1151.       id = NULL;
  1152.       argList = NULL;
  1153.       myDef = NULL;
  1154.     }
  1155.     ~ ThrowStmt () {}
  1156.     virtual void prettyPrint (int indent);
  1157. };
  1158.  
  1159.  
  1160.  
  1161. //----------  FreeStmt  ----------
  1162.  
  1163. class FreeStmt : public Statement {
  1164.   public:
  1165.     Expression * expr;
  1166.  
  1167.     FreeStmt () : Statement (FREE_STMT) {
  1168.       expr = NULL;
  1169.     }
  1170.     ~ FreeStmt () {}
  1171.     virtual void prettyPrint (int indent);
  1172. };
  1173.  
  1174.  
  1175.  
  1176. //----------  DebugStmt  ----------
  1177.  
  1178. class DebugStmt : public Statement {
  1179.   public:
  1180.  
  1181.     DebugStmt () : Statement (DEBUG_STMT) { }
  1182.     ~ DebugStmt () {}
  1183.     virtual void prettyPrint (int indent);
  1184. };
  1185.  
  1186.  
  1187.  
  1188. //----------  Case  ----------
  1189.  
  1190. class Case : public AstNode {
  1191.   public:
  1192.     Case * next;
  1193.     Expression * expr;
  1194.     int ivalue;                      // The value of the case expression
  1195.     Statement * stmts;               // may be NULL
  1196.     char * label;
  1197.  
  1198.     Case () : AstNode (CASE) {
  1199.       next = NULL;
  1200.       expr = NULL;
  1201.       ivalue = 0;
  1202.       stmts = NULL;
  1203.       label = NULL;
  1204.     }
  1205.     ~ Case () {}
  1206.     virtual void prettyPrint (int indent);
  1207. };
  1208.  
  1209.  
  1210.  
  1211. //----------  Catch  ----------
  1212.  
  1213. class Catch : public AstNode {
  1214.   public:
  1215.     Catch *     next;                    // ... in list for each try stmt
  1216.     Catch *     nextInMethOrFunction;    // ... in list for this function/method
  1217.     String *    id;
  1218.     Parameter * parmList;                // may be NULL
  1219.     Statement * stmts;                   // may be NULL
  1220.     ErrorDecl * myDef;                   // NULL iff errors
  1221.     char *      label;
  1222.     MethOrFunction * enclosingMethOrFunction;
  1223.  
  1224.     Catch () : AstNode (CATCH) {
  1225.       next = NULL;
  1226.       nextInMethOrFunction = NULL;
  1227.       id = NULL;
  1228.       parmList = NULL;
  1229.       stmts = NULL;
  1230.       myDef = NULL;
  1231.       label = NULL;
  1232.       enclosingMethOrFunction = NULL;
  1233.     }
  1234.     ~ Catch () {}
  1235.     virtual void prettyPrint (int indent);
  1236. };
  1237.  
  1238.  
  1239.  
  1240. //----------  VarDecl  ----------
  1241.  
  1242. class VarDecl : public AstNode {
  1243.   public:
  1244.     String *  id;
  1245.     VarDecl * next;
  1246.     Type *    type;            // NULL for temporaries
  1247.     int       offset;          // Only for Local, Parameter, ClassField, RecordField;
  1248.                                //   not for Global
  1249.     int       sizeInBytes;
  1250.     char *    varDescLabel;    // Used in generating VarDesc info
  1251.  
  1252.     VarDecl (int op) : AstNode (op) {
  1253.       next = NULL;
  1254.       id = NULL;
  1255.       type = NULL;
  1256.       offset = -1;
  1257.       sizeInBytes = -1;
  1258.       varDescLabel = NULL;
  1259.     }
  1260.     ~ VarDecl () {}
  1261.     virtual void prettyPrint (int indent);
  1262. };
  1263.  
  1264.  
  1265.  
  1266. //----------  Global  ----------
  1267.  
  1268. class Global : public VarDecl {
  1269.   public:
  1270. //  Global * next;
  1271.     Expression * initExpr;               // may be NULL
  1272.     int isPrivate;                       // 0=in header file, 1=in code file
  1273.  
  1274.     Global () : VarDecl (GLOBAL) {
  1275. //    next = NULL;
  1276.       initExpr = NULL;
  1277.       isPrivate = 0;
  1278.     }
  1279.     ~ Global () {}
  1280.     virtual void prettyPrint (int indent);
  1281. };
  1282.  
  1283.  
  1284.  
  1285. //----------  Local  ----------
  1286.  
  1287. class Local : public VarDecl {
  1288.   public:
  1289. //  Local * next;
  1290.     Expression * initExpr;               // may be NULL
  1291.     int wasUsed;
  1292.  
  1293.     Local () : VarDecl (LOCAL) {
  1294. //    next = NULL;
  1295.       initExpr = NULL;
  1296.       wasUsed = 0;
  1297.     }
  1298.     ~ Local () {}
  1299.     virtual void prettyPrint (int indent);
  1300. };
  1301.  
  1302.  
  1303.  
  1304. //----------  Parameter  ----------
  1305.  
  1306. class Parameter : public VarDecl {
  1307.   public:
  1308. //  Parameter * next;
  1309.     int throwSideOffset;         // Only for catch parms; offset used during throw.
  1310.  
  1311.     Parameter () : VarDecl (PARAMETER) {
  1312. //    next = NULL;
  1313.       throwSideOffset = -1;
  1314.     }
  1315.     ~ Parameter () {}
  1316.     virtual void prettyPrint (int indent);
  1317. };
  1318.  
  1319.  
  1320.  
  1321. //----------  ClassField  ----------
  1322.  
  1323. class ClassField : public VarDecl {
  1324.   public:
  1325. //  ClassField * next;
  1326.  
  1327.     ClassField () : VarDecl (CLASS_FIELD) {
  1328. //    next = NULL;
  1329.     }
  1330.     ~ ClassField () {}
  1331.     virtual void prettyPrint (int indent);
  1332. };
  1333.  
  1334.  
  1335.  
  1336. //----------  RecordField  ----------
  1337.  
  1338. class RecordField : public VarDecl {
  1339.   public:
  1340. //  RecordField * next;
  1341.  
  1342.     RecordField () : VarDecl (RECORD_FIELD) {
  1343. //    next = NULL;
  1344.     }
  1345.     ~ RecordField () {}
  1346.     virtual void prettyPrint (int indent);
  1347. };
  1348.  
  1349.  
  1350.  
  1351. //----------  Expression  ----------
  1352.  
  1353. class Expression : public AstNode {
  1354.   public:
  1355.  
  1356.     Expression (int op) : AstNode (op) {
  1357.     }
  1358.     ~ Expression () {}
  1359.     virtual void prettyPrint (int indent);
  1360. };
  1361.  
  1362.  
  1363.  
  1364. //----------  Constant  ----------
  1365.  
  1366. class Constant : public Expression {
  1367.   public:
  1368.  
  1369.     Constant (int op) : Expression (op) {
  1370.     }
  1371.     ~ Constant () {}
  1372.     virtual void prettyPrint (int indent);
  1373. };
  1374.  
  1375.  
  1376.  
  1377. //----------  IntConst  ----------
  1378.  
  1379. class IntConst : public Constant {
  1380.   public:
  1381.     int ivalue;
  1382.  
  1383.     IntConst () : Constant (INT_CONST) {
  1384.       ivalue = 0;
  1385.     }
  1386.     ~ IntConst () {}
  1387.     virtual void prettyPrint (int indent);
  1388. };
  1389.  
  1390.  
  1391.  
  1392. //----------  DoubleConst  ----------
  1393.  
  1394. class DoubleConst : public Constant {
  1395.   public:
  1396.     double rvalue;
  1397.     DoubleConst * next;
  1398.     char * nameOfConstant;
  1399.  
  1400.     DoubleConst () : Constant (DOUBLE_CONST) {
  1401.       rvalue = 0.0;
  1402.       next = NULL;
  1403.       nameOfConstant = NULL;
  1404.     }
  1405.     ~ DoubleConst () {}
  1406.     virtual void prettyPrint (int indent);
  1407. };
  1408.  
  1409.  
  1410.  
  1411. //----------  CharConst  ----------
  1412.  
  1413. class CharConst : public Constant {
  1414.   public:
  1415.     int ivalue;
  1416.  
  1417.     CharConst () : Constant (CHAR_CONST) {
  1418.       ivalue = '?';
  1419.     }
  1420.     ~ CharConst () {}
  1421.     virtual void prettyPrint (int indent);
  1422. };
  1423.  
  1424.  
  1425.  
  1426. //----------  StringConst  ----------
  1427.  
  1428. class StringConst : public Constant {
  1429.   public:
  1430.     String * svalue;
  1431.     StringConst * next;
  1432.     char * nameOfConstant;
  1433.  
  1434.     StringConst () : Constant (STRING_CONST) {
  1435.       svalue = NULL;
  1436.       next = NULL;
  1437.       nameOfConstant = NULL;
  1438.     }
  1439.     ~ StringConst () {}
  1440.     virtual void prettyPrint (int indent);
  1441. };
  1442.  
  1443.  
  1444.  
  1445. //----------  BoolConst  ----------
  1446.  
  1447. class BoolConst : public Constant {
  1448.   public:
  1449.     int ivalue;               // 1=true, 0=false
  1450.  
  1451.     BoolConst (int i) : Constant (BOOL_CONST) {
  1452.       ivalue = i;
  1453.     }
  1454.     ~ BoolConst () {}
  1455.     virtual void prettyPrint (int indent);
  1456. };
  1457.  
  1458.  
  1459.  
  1460. //----------  NullConst  ----------
  1461.  
  1462. class NullConst : public Constant {
  1463.   public:
  1464.  
  1465.     NullConst () : Constant (NULL_CONST) { }
  1466.     ~ NullConst () {}
  1467.     virtual void prettyPrint (int indent);
  1468. };
  1469.  
  1470.  
  1471.  
  1472. //----------  CallExpr  ----------
  1473.  
  1474. class CallExpr : public Expression {
  1475.   public:
  1476.     String * id;               // e.g., "foo"
  1477.     Argument * argList;        // may be NULL
  1478.     AstNode * myDef;           // Points to a FunctionProto, Local, Global, Parameter,
  1479.                                //   or ClassField; NULL if error or primitive
  1480.     int primitiveSymbol;       // 0=not a primitive; e.g., PRIMITIVE_DOUBLE_TO_INT, etc...
  1481.     int retSize;               // Size of returned value (0 if void), -1 for primitives
  1482.  
  1483.     CallExpr () : Expression (CALL_EXPR) {
  1484.       id = NULL;
  1485.       argList = NULL;
  1486.       myDef = NULL;
  1487.       primitiveSymbol = 0;
  1488.       retSize = -1;
  1489.     }
  1490.     ~ CallExpr () {}
  1491.     virtual void prettyPrint (int indent);
  1492. };
  1493.  
  1494.  
  1495.  
  1496. //----------  SendExpr  ----------
  1497.  
  1498. class SendExpr : public Expression {
  1499.   public:
  1500.     String *      selector;            // e.g., "meth", "+", "at:put:"
  1501.     Expression *  receiver;
  1502.     Argument *    argList;             // may be NULL
  1503.     int           kind;                // INFIX, PREFIX, KEYWORD, NORMAL
  1504.     int           primitiveSymbol;     // 0=not a primitive; e.g., PRIMITIVE_I_ADD, etc...
  1505.     MethodProto * myProto;             // NULL for primitives
  1506.  
  1507.     SendExpr () : Expression (SEND_EXPR) {
  1508.       selector = NULL;
  1509.       receiver = NULL;
  1510.       argList = NULL;
  1511.       kind = EOF;
  1512.       primitiveSymbol = 0;
  1513.       myProto = NULL;
  1514.     }
  1515.     ~ SendExpr () {}
  1516.     virtual void prettyPrint (int indent);
  1517. };
  1518.  
  1519.  
  1520.  
  1521. //----------  SelfExpr  ----------
  1522.  
  1523. class SelfExpr : public Expression {
  1524.   public:
  1525.  
  1526.     SelfExpr () : Expression (SELF_EXPR) {
  1527.     }
  1528.     ~ SelfExpr () {}
  1529.     virtual void prettyPrint (int indent);
  1530. };
  1531.  
  1532.  
  1533.  
  1534. //----------  SuperExpr  ----------
  1535.  
  1536. class SuperExpr : public Expression {
  1537.   public:
  1538.  
  1539.     SuperExpr () : Expression (SUPER_EXPR) {
  1540.     }
  1541.     ~ SuperExpr () {}
  1542.     virtual void prettyPrint (int indent);
  1543. };
  1544.  
  1545.  
  1546.  
  1547. //----------  FieldAccess  ----------
  1548.  
  1549. class FieldAccess : public Expression {
  1550.   public:
  1551.     Expression * expr;
  1552.     String * id;
  1553.     int offset;
  1554.  
  1555.     FieldAccess () : Expression (FIELD_ACCESS) {
  1556.       expr = NULL;
  1557.       id = NULL;
  1558.       offset = 0;
  1559.     }
  1560.     ~ FieldAccess () {}
  1561.     virtual void prettyPrint (int indent);
  1562. };
  1563.  
  1564.  
  1565.  
  1566. //----------  ArrayAccess  ----------
  1567.  
  1568. class ArrayAccess : public Expression {
  1569.   public:
  1570.     Expression * arrayExpr;
  1571.     Expression * indexExpr;
  1572.     int sizeOfElements;               // This is the multiplication scale factor
  1573.  
  1574.     ArrayAccess () : Expression (ARRAY_ACCESS) {
  1575.       arrayExpr = NULL;
  1576.       indexExpr = NULL;
  1577.       sizeOfElements = -1;
  1578.     }
  1579.     ~ ArrayAccess () {}
  1580.     virtual void prettyPrint (int indent);
  1581. };
  1582.  
  1583.  
  1584.  
  1585. //----------  Constructor  ----------
  1586.  
  1587. class Constructor : public Expression {
  1588.   public:
  1589.     Type * type;                      // should be Array, Class, or Record type
  1590.     CountValue * countValueList;      // may be NULL
  1591.     FieldInit * fieldInits;           // may be NULL
  1592.     int sizeInBytes;                  // Classes, records, array: size of whole
  1593.     ClassDef * myClass;               // Null if not a Class constructor
  1594.     int kind;                         // CLASS, RECORD, or ARRAY
  1595.     int allocKind;                    // NEW or ALLOC
  1596.  
  1597.     Constructor () : Expression (CONSTRUCTOR) {
  1598.       type = NULL;
  1599.       countValueList = NULL;
  1600.       fieldInits = NULL;
  1601.       sizeInBytes = -1;
  1602.       myClass = NULL;
  1603.       kind = -1;
  1604.     }
  1605.     ~ Constructor () {}
  1606.     virtual void prettyPrint (int indent);
  1607. };
  1608.  
  1609.  
  1610.  
  1611. //----------  ClosureExpr  ----------
  1612.  
  1613. class ClosureExpr : public Expression {
  1614.   public:
  1615.     Function * function;
  1616.  
  1617.     ClosureExpr () : Expression (CLOSURE_EXPR) {
  1618.       function = NULL;
  1619.     }
  1620.     ~ ClosureExpr () {}
  1621.     virtual void prettyPrint (int indent);
  1622. };
  1623.  
  1624.  
  1625.  
  1626. //----------  VariableExpr  ----------
  1627.  
  1628. class VariableExpr : public Expression {
  1629.   public:
  1630.     String * id;
  1631.     AstNode * myDef;
  1632.  
  1633.     VariableExpr () : Expression (VARIABLE_EXPR) {
  1634.       id = NULL;
  1635.       myDef = NULL;
  1636.     }
  1637.     ~ VariableExpr () {}
  1638.     virtual void prettyPrint (int indent);
  1639. };
  1640.  
  1641.  
  1642.  
  1643. //----------  AsPtrToExpr  ----------
  1644.  
  1645. class AsPtrToExpr : public Expression {
  1646.   public:
  1647.     Expression * expr;
  1648.     Type * type;
  1649.  
  1650.     AsPtrToExpr () : Expression (AS_PTR_TO_EXPR) {
  1651.       expr = NULL;
  1652.       type = NULL;
  1653.     }
  1654.     ~ AsPtrToExpr () {}
  1655.     virtual void prettyPrint (int indent);
  1656. };
  1657.  
  1658.  
  1659.  
  1660. //----------  AsIntegerExpr  ----------
  1661.  
  1662. class AsIntegerExpr : public Expression {
  1663.   public:
  1664.     Expression * expr;
  1665.  
  1666.     AsIntegerExpr () : Expression (AS_INTEGER_EXPR) {
  1667.       expr = NULL;
  1668.     }
  1669.     ~ AsIntegerExpr () {}
  1670.     virtual void prettyPrint (int indent);
  1671. };
  1672.  
  1673.  
  1674.  
  1675. //----------  ArraySizeExpr  ----------
  1676.  
  1677. class ArraySizeExpr : public Expression {
  1678.   public:
  1679.     Expression * expr;
  1680.  
  1681.     ArraySizeExpr () : Expression (ARRAY_SIZE_EXPR) {
  1682.       expr = NULL;
  1683.     }
  1684.     ~ ArraySizeExpr () {}
  1685.     virtual void prettyPrint (int indent);
  1686. };
  1687.  
  1688.  
  1689.  
  1690. //----------  IsInstanceOfExpr  ----------
  1691.  
  1692. class IsInstanceOfExpr : public Expression {
  1693.   public:
  1694.     Expression * expr;
  1695.     Type * type;
  1696.     ClassDef * classDef;
  1697.  
  1698.     IsInstanceOfExpr () : Expression (IS_INSTANCE_OF_EXPR) {
  1699.       expr = NULL;
  1700.       type = NULL;
  1701.       classDef = NULL;
  1702.     }
  1703.     ~ IsInstanceOfExpr () {}
  1704.     virtual void prettyPrint (int indent);
  1705. };
  1706.  
  1707.  
  1708.  
  1709. //----------  IsKindOfExpr  ----------
  1710.  
  1711. class IsKindOfExpr : public Expression {
  1712.   public:
  1713.     Expression * expr;
  1714.     Type * type;
  1715.     Abstract * classOrInterface;
  1716.  
  1717.     IsKindOfExpr () : Expression (IS_KIND_OF_EXPR) {
  1718.       expr = NULL;
  1719.       type = NULL;
  1720.       classOrInterface = NULL;
  1721.     }
  1722.     ~ IsKindOfExpr () {}
  1723.     virtual void prettyPrint (int indent);
  1724. };
  1725.  
  1726.  
  1727.  
  1728. //----------  SizeOfExpr  ----------
  1729.  
  1730. class SizeOfExpr : public Expression {
  1731.   public:
  1732.     Type * type;
  1733.  
  1734.     SizeOfExpr () : Expression (SIZE_OF_EXPR) {
  1735.       type = NULL;
  1736.     }
  1737.     ~ SizeOfExpr () {}
  1738.     virtual void prettyPrint (int indent);
  1739. };
  1740.  
  1741.  
  1742.  
  1743. //----------  DynamicCheck  ----------
  1744.  
  1745. class DynamicCheck : public Expression {
  1746.   public:
  1747.     Expression * expr;
  1748.     int          kind;      // 8 ==  OBJECT COPY: ... := *objPtr
  1749.                             // 9 ==  ARRAY COPY: arr[10] := arr[10]
  1750.                             // 10 == ARRAY COPY: arr[10] := arr[*]
  1751.                             // 11 == ARRAY COPY: arr[*] := arr[10]  (will not occur)
  1752.                             // 12 == ARRAY COPY: arr[*] := arr[*]   (will not occur)
  1753.     int          expectedArraySize;   // Cases 9 and 10 only
  1754.     int          arraySizeInBytes;    // Cases 9 and 10 only
  1755.     ClassDef *   expectedClassDef;    // Case 8 only
  1756.  
  1757.     DynamicCheck () : Expression (DYNAMIC_CHECK) {
  1758.       expr = NULL;
  1759.       kind = -1;
  1760.       expectedArraySize = -1;
  1761.       arraySizeInBytes = -1;
  1762.       expectedClassDef = NULL;
  1763.     }
  1764.     ~ DynamicCheck () {}
  1765.     virtual void prettyPrint (int indent);
  1766. };
  1767.  
  1768.  
  1769.  
  1770. //----------  Argument  ----------
  1771.  
  1772. class Argument : public AstNode {
  1773.   public:
  1774.     Argument * next;
  1775.     Expression * expr;
  1776.     AstNode * tempName;             // Used in code gen
  1777.     int       offset;
  1778.     int       sizeInBytes;
  1779.     
  1780.  
  1781.     Argument () : AstNode (ARGUMENT) {
  1782.       next = NULL;
  1783.       expr = NULL;
  1784.       tempName = NULL;
  1785.       offset = -1;
  1786.       sizeInBytes = -1;
  1787.     }
  1788.     ~ Argument () {}
  1789.     virtual void prettyPrint (int indent);
  1790. };
  1791.  
  1792.  
  1793.  
  1794. //----------  CountValue  ----------
  1795.  
  1796. class CountValue : public AstNode {
  1797.   public:
  1798.     Expression * count;               // may be Null
  1799.     Expression * value;               // not NULL
  1800.     CountValue * next;
  1801.     AstNode *    countTemp;           // may be NULL, which means 1
  1802.     AstNode *    valueTemp;           // not NULL
  1803.  
  1804.     CountValue () : AstNode (COUNT_VALUE) {
  1805.       count = NULL;
  1806.       value = NULL;
  1807.       next = NULL;
  1808.       countTemp = NULL;
  1809.       valueTemp = NULL;
  1810.     }
  1811.     ~ CountValue () {}
  1812.     virtual void prettyPrint (int indent);
  1813. };
  1814.  
  1815.  
  1816.  
  1817. //----------  FieldInit  ----------
  1818.  
  1819. class FieldInit : public AstNode {
  1820.   public:
  1821.     FieldInit * next;
  1822.     String * id;
  1823.     Expression * expr;
  1824.     int offset;
  1825.     int sizeInBytes;
  1826.  
  1827.     FieldInit () : AstNode (FIELD_INIT) {
  1828.       next = NULL;
  1829.       id = NULL;
  1830.       expr = NULL;
  1831.       offset = -1;
  1832.       sizeInBytes = -1;
  1833.     }
  1834.     ~ FieldInit () {}
  1835.     virtual void prettyPrint (int indent);
  1836. };
  1837.