jitcraft/SemanticAnalysis.cpp
changeset 63 dd57743d220e
parent 59 b7d61ddb3c8d
child 66 cbba1997dc71
     1.1 --- a/jitcraft/SemanticAnalysis.cpp	Sun Jul 08 15:23:48 2012 -0700
     1.2 +++ b/jitcraft/SemanticAnalysis.cpp	Sun Jul 08 16:49:17 2012 -0700
     1.3 @@ -558,8 +558,20 @@
     1.4      Local<Type> funtype(zone_, zone_->types()->newFunction(returnType, args));
     1.5      if (!funtype)
     1.6          return false;
     1.7 +    
     1.8 +    // If the function already has a type, it was forward declared before, and
     1.9 +    // now this is our chance to type check the second declaration.
    1.10 +    if (node->fun()->type()) {
    1.11 +        Local<Type> forward(zone_, node->fun()->type());
    1.12 +        if (!Type::Compare(funtype, forward)) {
    1.13 +            cc_.reportError(node->pos(), Message_ForwardDeclareMismatches);
    1.14 +            return false;
    1.15 +        }
    1.16 +        node->fun()->setForwardType(forward);
    1.17 +    }
    1.18  
    1.19      node->fun()->setType(funtype);
    1.20 +
    1.21      return true;
    1.22  }
    1.23  
    1.24 @@ -568,7 +580,8 @@
    1.25  {
    1.26      function_ = node->fun()->type();
    1.27      scope_ = node->scope();
    1.28 -    node->body()->accept(this);
    1.29 +    if (node->body())
    1.30 +        node->body()->accept(this);
    1.31      scope_ = NULL;
    1.32      function_ = NULL;
    1.33  }
    1.34 @@ -689,6 +702,13 @@
    1.35          return;
    1.36      }
    1.37  
    1.38 +    // Currently, only calls from a NameProxy are possible.
    1.39 +    NamedFunction *fun = node->callee()->toNameProxy()->binding()->toNamedFunction();
    1.40 +    if (fun->isForward()) {
    1.41 +        cc_.reportError(node->pos(), Message_ForwardNotImplemented, fun->name()->chars());
    1.42 +        return;
    1.43 +    }
    1.44 +
    1.45      for (unsigned i = 0; i < node->arguments()->length(); i++) {
    1.46          // Note: we don't compute references unless the callee needs a
    1.47          // reference type.