src/AST.h
changeset 145 e9d804821c48
parent 143 393f1b8ac8c3
child 146 dc7d3b7a918c
     1.1 --- a/src/AST.h	Mon Jul 30 22:30:38 2012 -0700
     1.2 +++ b/src/AST.h	Wed Aug 01 22:32:59 2012 -0700
     1.3 @@ -98,36 +98,6 @@
     1.4  #undef _
     1.5  };
     1.6  
     1.7 -class NameLocation
     1.8 -{
     1.9 -  public:
    1.10 -    enum Kind {
    1.11 -        LOCAL
    1.12 -    };
    1.13 -
    1.14 -    static NameLocation Local(VariableDeclaration *decl) {
    1.15 -        NameLocation loc;
    1.16 -        loc.kind_ = LOCAL;
    1.17 -        loc.u_.decl = decl;
    1.18 -        return loc;
    1.19 -    }
    1.20 -
    1.21 -    Kind kind() const {
    1.22 -        return kind_;
    1.23 -    }
    1.24 -
    1.25 -    VariableDeclaration *local() const {
    1.26 -        assert(kind() == LOCAL);
    1.27 -        return u_.decl;
    1.28 -    }
    1.29 -
    1.30 -  private:
    1.31 -    Kind kind_;
    1.32 -    union {
    1.33 -        VariableDeclaration *decl;
    1.34 -    } u_;
    1.35 -};
    1.36 -
    1.37  class Statement : public AstNode
    1.38  {
    1.39    public:
    1.40 @@ -164,23 +134,24 @@
    1.41      Variable *variable_;
    1.42      Expression *initialization_;
    1.43      ExpressionList *postDimensions_;
    1.44 -    ScopedRoot<String> tag_;
    1.45 +    BoundName *type_;
    1.46      TokenKind declarator_;
    1.47  
    1.48    public:
    1.49      VariableDeclaration(const SourcePosition &pos, TokenKind declarator, Variable *var,
    1.50 -                        Handle<String> tag, ExpressionList *postDimensions,
    1.51 +                        BoundName *type, ExpressionList *postDimensions,
    1.52                          Expression *initialization)
    1.53        : Statement(pos),
    1.54          variable_(var),
    1.55          initialization_(initialization),
    1.56          postDimensions_(postDimensions),
    1.57 -        tag_(tag)
    1.58 +        type_(type),
    1.59 +        declarator_(declarator)
    1.60      {
    1.61      }
    1.62  
    1.63 -    String *tag() const {
    1.64 -        return tag_;
    1.65 +    BoundName *type() const {
    1.66 +        return type_;
    1.67      }
    1.68      Kind kind() const {
    1.69          return kVariableDeclaration;
    1.70 @@ -205,17 +176,17 @@
    1.71  class Parameter : public PoolObject
    1.72  {
    1.73      Variable *variable_;
    1.74 -    ScopedRoot<String> tag_;
    1.75 +    BoundName *type_;
    1.76      bool reference_;
    1.77      bool const_;
    1.78      ExpressionList *dimensions_;
    1.79      Expression *initializer_;
    1.80  
    1.81    public:
    1.82 -    Parameter(Variable *var, Handle<String> tag, bool reference, bool isConst,
    1.83 +    Parameter(Variable *var, BoundName *type, bool reference, bool isConst,
    1.84                ExpressionList *dimensions, Expression *initializer)
    1.85        : variable_(var),
    1.86 -        tag_(tag),
    1.87 +        type_(type),
    1.88          reference_(reference),
    1.89          const_(isConst),
    1.90          dimensions_(dimensions),
    1.91 @@ -223,8 +194,8 @@
    1.92      {
    1.93      }
    1.94  
    1.95 -    String *tag() const {
    1.96 -        return tag_;
    1.97 +    BoundName *type() const {
    1.98 +        return type_;
    1.99      }
   1.100      Variable *variable() const {
   1.101          return variable_;
   1.102 @@ -366,7 +337,7 @@
   1.103  {
   1.104      Expression *expression_;
   1.105      TokenKind token_;
   1.106 -    ScopedRoot<String> tag_;
   1.107 +    BoundName *type_;
   1.108  
   1.109    public:
   1.110      UnaryExpression(const SourcePosition &pos, TokenKind token, Expression *expr)
   1.111 @@ -377,11 +348,11 @@
   1.112      }
   1.113  
   1.114      UnaryExpression(const SourcePosition &pos, TokenKind token, Expression *expr,
   1.115 -                    Handle<String> tag)
   1.116 +                    BoundName *type)
   1.117        : Expression(pos),
   1.118          expression_(expr),
   1.119          token_(token),
   1.120 -        tag_(tag)
   1.121 +        type_(type)
   1.122      {
   1.123      }
   1.124  
   1.125 @@ -394,8 +365,8 @@
   1.126      TokenKind token() const {
   1.127          return token_;
   1.128      }
   1.129 -    String *tag() const {
   1.130 -        return tag_;
   1.131 +    BoundName *type() const {
   1.132 +        return type_;
   1.133      }
   1.134      void accept(AstVisitor *visitor) {
   1.135          visitor->visit(this);
   1.136 @@ -739,18 +710,18 @@
   1.137      Statement *body_;
   1.138      ParameterList *parameters_;
   1.139      bool explicitReturn_;
   1.140 -    ScopedRoot<String> tag_;
   1.141 +    BoundName *returnType_;
   1.142  
   1.143    public:
   1.144      FunctionStatement(const SourcePosition &pos, Scope *scope, NamedFunction *fun, Statement *body,
   1.145 -                      ParameterList *parameters, Handle<String> returnTag, bool explicitReturn)
   1.146 +                      ParameterList *parameters, BoundName *returnType, bool explicitReturn)
   1.147        : Statement(pos),
   1.148          scope_(scope),
   1.149          fun_(fun),
   1.150          body_(body),
   1.151          parameters_(parameters),
   1.152          explicitReturn_(explicitReturn),
   1.153 -        tag_(returnTag)
   1.154 +        returnType_(returnType)
   1.155      {
   1.156      }
   1.157  
   1.158 @@ -775,8 +746,8 @@
   1.159      bool hasExplicitReturn() const {
   1.160          return explicitReturn_;
   1.161      }
   1.162 -    String *returnTag() const {
   1.163 -        return tag_;
   1.164 +    BoundName *returnType() const {
   1.165 +        return returnType_;
   1.166      }
   1.167  };
   1.168  
   1.169 @@ -818,6 +789,7 @@
   1.170  class EnumStatement : public Statement
   1.171  {
   1.172      ScopedRoot<String> name_;
   1.173 +    NamedType *type_;
   1.174  
   1.175    public:
   1.176      struct Entry {
   1.177 @@ -834,9 +806,10 @@
   1.178      typedef PoolList<Entry> EntryList;
   1.179  
   1.180    public:
   1.181 -    EnumStatement(const SourcePosition &pos, Handle<String> name, EntryList *entries)
   1.182 +    EnumStatement(const SourcePosition &pos, NamedType *type, Handle<String> name, EntryList *entries)
   1.183        : Statement(pos),
   1.184          name_(name),
   1.185 +        type_(type),
   1.186          entries_(entries)
   1.187      {
   1.188      }
   1.189 @@ -850,6 +823,9 @@
   1.190      EntryList *entries() const {
   1.191          return entries_;
   1.192      }
   1.193 +    NamedType *decl() const {
   1.194 +        return type_;
   1.195 +    }
   1.196      void accept(AstVisitor *visitor) {
   1.197          visitor->visit(this);
   1.198      }