Handleized SemanticAnalysis (PHEW).
authorDavid Anderson <dvander@alliedmods.net>
Tue Jul 03 01:14:15 2012 -0700 (2012-07-03)
changeset 40ce787d61fb71
parent 39 158f476b92b3
child 41 34987baade41
Handleized SemanticAnalysis (PHEW).
jitcraft/Handles.h
jitcraft/SemanticAnalysis.cpp
jitcraft/SemanticAnalysis.h
     1.1 --- a/jitcraft/Handles.h	Tue Jul 03 01:00:02 2012 -0700
     1.2 +++ b/jitcraft/Handles.h	Tue Jul 03 01:14:15 2012 -0700
     1.3 @@ -34,6 +34,9 @@
     1.4      T * const *thingp_;
     1.5  
     1.6    public:
     1.7 +    Handle(const Handle &other) {
     1.8 +        thingp_ = other.address();
     1.9 +    }
    1.10      template <typename S> Handle(const Handle<S> &handle) {
    1.11          typeCheck<S>();
    1.12          thingp_ = reinterpret_cast<T * const *>(handle.address());
     2.1 --- a/jitcraft/SemanticAnalysis.cpp	Tue Jul 03 01:00:02 2012 -0700
     2.2 +++ b/jitcraft/SemanticAnalysis.cpp	Tue Jul 03 01:14:15 2012 -0700
     2.3 @@ -137,8 +137,7 @@
     2.4  Type *
     2.5  SemanticAnalysis::visitForLoad(Expression *expression)
     2.6  {
     2.7 -    // :TODO: use Local
     2.8 -    Type *type = visitAndApplyType(expression);
     2.9 +    Local<Type> type(zone_, visitAndApplyType(expression));
    2.10      if (!type)
    2.11          return NULL;
    2.12  
    2.13 @@ -174,7 +173,7 @@
    2.14  }
    2.15  
    2.16  void
    2.17 -SemanticAnalysis::unaryTypeError(AstNode *node, TokenKind token, Type *type)
    2.18 +SemanticAnalysis::unaryTypeError(AstNode *node, TokenKind token, Handle<Type> type)
    2.19  {
    2.20      const char *op = TokenNames[token];
    2.21      const char *name = GetTypeName(type);
    2.22 @@ -183,7 +182,7 @@
    2.23  }
    2.24  
    2.25  void
    2.26 -SemanticAnalysis::binaryTypeError(AstNode *node, TokenKind token, Type *left, Type *right)
    2.27 +SemanticAnalysis::binaryTypeError(AstNode *node, TokenKind token, Handle<Type> left, Handle<Type> right)
    2.28  {
    2.29      const char *op = TokenNames[token];
    2.30      const char *leftName = GetTypeName(left);
    2.31 @@ -193,7 +192,7 @@
    2.32  }
    2.33  
    2.34  Type *
    2.35 -SemanticAnalysis::typeCheckBinary(AstNode *node, TokenKind token, Type *left, Type *right)
    2.36 +SemanticAnalysis::typeCheckBinary(AstNode *node, TokenKind token, Handle<Type> left, Handle<Type> right)
    2.37  {
    2.38      if ((token >= TOK_PLUS && token <= TOK_SLASH) ||
    2.39          (token >= TOK_ASSIGN_ADD && token <= TOK_ASSIGN_DIV))
    2.40 @@ -218,7 +217,7 @@
    2.41  }
    2.42  
    2.43  bool
    2.44 -SemanticAnalysis::canTest(AstNode *node, Type *type)
    2.45 +SemanticAnalysis::canTest(AstNode *node, Handle<Type> type)
    2.46  {
    2.47      if (type->isArray()) {
    2.48          cc_.reportError(node->pos(), Message_ArrayIsNotBoolean);
    2.49 @@ -267,12 +266,11 @@
    2.50  void
    2.51  SemanticAnalysis::visit(Assignment *node)
    2.52  {
    2.53 -    Type *exprType = visitForLoad(node->expression());
    2.54 +    Local<Type> exprType(zone_, visitForLoad(node->expression()));
    2.55      if (!exprType)
    2.56          return ;
    2.57  
    2.58 -    // :TODO: use Local
    2.59 -    Type *type = visitForLValue(node->lvalue());
    2.60 +    Local<Type> type(zone_, visitForLValue(node->lvalue()));
    2.61      if (!type)
    2.62          return;
    2.63  
    2.64 @@ -290,8 +288,7 @@
    2.65  void
    2.66  SemanticAnalysis::visit(IncDecExpression *node)
    2.67  {
    2.68 -    // :TODO: use Local
    2.69 -    Type *type = visitForLValue(node->expression());
    2.70 +    Local<Type> type(zone_, visitForLValue(node->expression()));
    2.71      if (!type)
    2.72          return;
    2.73  
    2.74 @@ -308,13 +305,12 @@
    2.75  void
    2.76  SemanticAnalysis::visit(BinaryExpression *node)
    2.77  {
    2.78 -    // :TODO: use Local
    2.79 -    Type *left = visitForLoad(node->left());
    2.80 -    Type *right = visitForLoad(node->right());
    2.81 +    Local<Type> left(zone_, visitForLoad(node->left()));
    2.82 +    Local<Type> right(zone_, visitForLoad(node->right()));
    2.83      if (!left || !right)
    2.84          return;
    2.85  
    2.86 -    Type *result = typeCheckBinary(node, node->token(), left, right);
    2.87 +    Local<Type> result(zone_, typeCheckBinary(node, node->token(), left, right));
    2.88      if (!result)
    2.89          return;
    2.90  
    2.91 @@ -324,11 +320,12 @@
    2.92  void
    2.93  SemanticAnalysis::visit(ReturnStatement *node)
    2.94  {
    2.95 -    Type *type = visitForLoad(node->expression());
    2.96 +    Local<Type> type(zone_, visitForLoad(node->expression()));
    2.97      if (!type)
    2.98          return;
    2.99  
   2.100 -    if (!typeCheckAssignment(node, type, function_->returnType(), true))
   2.101 +    Local<Type> returnType(zone_, function_->returnType());
   2.102 +    if (!typeCheckAssignment(node, type, returnType, true))
   2.103          return;
   2.104  }
   2.105  
   2.106 @@ -343,7 +340,7 @@
   2.107          node->initialization()->accept(this);
   2.108  
   2.109      if (node->condition()) {
   2.110 -        Type *type = visitForLoad(node->condition());
   2.111 +        Local<Type> type(zone_, visitForLoad(node->condition()));
   2.112          if (!type || !canTest(node->condition(), type)) {
   2.113              loopDepth_--;
   2.114              return;
   2.115 @@ -365,7 +362,7 @@
   2.116  {
   2.117      loopDepth_++;
   2.118  
   2.119 -    Type *type = visitForLoad(node->condition());
   2.120 +    Local<Type> type(zone_, visitForLoad(node->condition()));
   2.121      if (!type || !canTest(node->condition(), type)) {
   2.122          loopDepth_--;
   2.123          return;
   2.124 @@ -493,7 +490,7 @@
   2.125          scope_->setUsesLifoHeap();
   2.126      } else {
   2.127          if (node->initialization()) {
   2.128 -            Type *right = visitForLoad(node->initialization());
   2.129 +            Local<Type> right(zone_, visitForLoad(node->initialization()));
   2.130              if (!right)
   2.131                  return;
   2.132              if (!typeCheckAssignment(node, type, right, true))
   2.133 @@ -573,8 +570,11 @@
   2.134  }
   2.135  
   2.136  bool
   2.137 -SemanticAnalysis::typeCheckArrayAssignment(AstNode *node, Type *given, Type *actual, bool forAssign)
   2.138 +SemanticAnalysis::typeCheckArrayAssignment(AstNode *node, Handle<Type> argGiven, Handle<Type> argActual, bool forAssign)
   2.139  {
   2.140 +    Local<Type> actual(zone_, argActual);
   2.141 +    Local<Type> given(zone_, argGiven);
   2.142 +
   2.143      if (!given->isArray()) {
   2.144          cc_.reportError(node->pos(), Message_ExpectedArray);
   2.145          return false;
   2.146 @@ -627,8 +627,11 @@
   2.147  }
   2.148  
   2.149  bool
   2.150 -SemanticAnalysis::typeCheckAssignment(AstNode *node, Type *given, Type *actual, bool forAssign)
   2.151 +SemanticAnalysis::typeCheckAssignment(AstNode *node, Handle<Type> argGiven, Handle<Type> argActual, bool forAssign)
   2.152  {
   2.153 +    Local<Type> actual(zone_, argActual);
   2.154 +    Local<Type> given(zone_, argGiven);
   2.155 +
   2.156      if (actual->isArray())
   2.157          return typeCheckArrayAssignment(node, given, actual, forAssign);
   2.158  
   2.159 @@ -659,7 +662,7 @@
   2.160  }
   2.161  
   2.162  bool
   2.163 -SemanticAnalysis::typeCheckParameter(AstNode *node, Type *given, Type *actual)
   2.164 +SemanticAnalysis::typeCheckParameter(AstNode *node, Handle<Type> given, Handle<Type> actual)
   2.165  {
   2.166      return typeCheckAssignment(node, given, actual, false);
   2.167  }
   2.168 @@ -667,7 +670,7 @@
   2.169  void
   2.170  SemanticAnalysis::visit(CallExpression *node)
   2.171  {
   2.172 -    Type *type = visitForLoad(node->callee());
   2.173 +    Local<Type> type(zone_, visitForLoad(node->callee()));
   2.174      if (!type)
   2.175          return;
   2.176  
   2.177 @@ -684,7 +687,7 @@
   2.178          // Note: we don't compute references unless the callee needs a
   2.179          // reference type.
   2.180          Expression *expression = node->arguments()->at(i);
   2.181 -        Type *given = visitAndApplyType(expression);
   2.182 +        Local<Type> given(zone_, visitAndApplyType(expression));
   2.183          if (!given)
   2.184              return;
   2.185  
   2.186 @@ -693,7 +696,7 @@
   2.187          if (expression->isIndexExpression())
   2.188              given = given->contained();
   2.189  
   2.190 -        Type *actual = type->parameterAt(i);
   2.191 +        Local<Type> actual(zone_, type->parameterAt(i));
   2.192          if (!typeCheckParameter(expression, given, actual))
   2.193              return;
   2.194  
   2.195 @@ -707,7 +710,7 @@
   2.196  void
   2.197  SemanticAnalysis::visit(IfStatement *node)
   2.198  {
   2.199 -    Type *type = visitForLoad(node->condition());
   2.200 +    Local<Type> type(zone_, visitForLoad(node->condition()));
   2.201      if (!type)
   2.202          return;
   2.203  
   2.204 @@ -722,9 +725,8 @@
   2.205  void
   2.206  SemanticAnalysis::visit(IndexExpression *node)
   2.207  {
   2.208 -    // :TODO: use locals
   2.209 -    Type *left = visitForRef(node->left());
   2.210 -    Type *right = visitForLoad(node->right());
   2.211 +    Local<Type> left(zone_, visitForRef(node->left()));
   2.212 +    Local<Type> right(zone_, visitForLoad(node->right()));
   2.213  
   2.214      if (!left || !right)
   2.215          return;
   2.216 @@ -754,7 +756,7 @@
   2.217          return;
   2.218      }
   2.219  
   2.220 -    Type *type = zone_->types()->getPrimitiveForTag(tag);
   2.221 +    Local<Type> type(zone_, zone_->types()->getPrimitiveForTag(tag));
   2.222      if (!type)
   2.223          return;
   2.224  
   2.225 @@ -782,7 +784,7 @@
   2.226  void
   2.227  SemanticAnalysis::visit(StringLiteral *node)
   2.228  {
   2.229 -    Type *type = zone_->types()->getPrimitive(PrimitiveType_Char);
   2.230 +    Local<Type> type(zone_, zone_->types()->getPrimitive(PrimitiveType_Char));
   2.231      if (!type)
   2.232          return;
   2.233  
   2.234 @@ -796,7 +798,7 @@
   2.235  void
   2.236  SemanticAnalysis::visit(FloatLiteral *node)
   2.237  {
   2.238 -    Type *type = zone_->types()->getPrimitive(PrimitiveType_Float);
   2.239 +    Local<Type> type(zone_, zone_->types()->getPrimitive(PrimitiveType_Float));
   2.240      if (!type)
   2.241          return;
   2.242  
     3.1 --- a/jitcraft/SemanticAnalysis.h	Tue Jul 03 01:00:02 2012 -0700
     3.2 +++ b/jitcraft/SemanticAnalysis.h	Tue Jul 03 01:14:15 2012 -0700
     3.3 @@ -31,13 +31,13 @@
     3.4      ParseTree *tree_;
     3.5      unsigned loopDepth_;
     3.6      Scope *scope_;
     3.7 -    Type *function_;
     3.8 +    ScopedRoot<Type> function_;
     3.9  
    3.10    private:
    3.11 -    bool canTest(AstNode *node, Type *type);
    3.12 -    void unaryTypeError(AstNode *node, TokenKind token, Type *type);
    3.13 -    void binaryTypeError(AstNode *node, TokenKind token, Type *left, Type *right);
    3.14 -    Type *typeCheckBinary(AstNode *node, TokenKind token, Type *left, Type *right);
    3.15 +    bool canTest(AstNode *node, Handle<Type> type);
    3.16 +    void unaryTypeError(AstNode *node, TokenKind token, Handle<Type> type);
    3.17 +    void binaryTypeError(AstNode *node, TokenKind token, Handle<Type> left, Handle<Type> right);
    3.18 +    Type *typeCheckBinary(AstNode *node, TokenKind token, Handle<Type> left, Handle<Type> right);
    3.19  
    3.20      // These check if one type is compatible with another type, for various
    3.21      // purposes, like:
    3.22 @@ -45,10 +45,10 @@
    3.23      //      call(a, b)    matches expected arg type
    3.24      //      a = b         matches declared type
    3.25      //
    3.26 -    bool typeCheckArrayAssignment(AstNode *node, Type *given, Type *actual, bool forAssign);
    3.27 -    bool typeCheckAssignment(AstNode *node, Type *given, Type *actual, bool forAssign);
    3.28 +    bool typeCheckArrayAssignment(AstNode *node, Handle<Type> given, Handle<Type> actual, bool forAssign);
    3.29 +    bool typeCheckAssignment(AstNode *node, Handle<Type> given, Handle<Type> actual, bool forAssign);
    3.30  
    3.31 -    bool typeCheckParameter(AstNode *node, Type *given, Type *actual);
    3.32 +    bool typeCheckParameter(AstNode *node, Handle<Type> given, Handle<Type> actual);
    3.33  
    3.34      Type *visitForLoad(Expression *expression);
    3.35      Type *visitForRef(Expression *expression);