src/Parser.cpp
changeset 191 9d17f29fe16a
parent 189 eee18bf13c9b
child 192 23a804fa1d3e
     1.1 --- a/src/Parser.cpp	Sun Sep 16 21:59:26 2012 -0700
     1.2 +++ b/src/Parser.cpp	Sun Sep 16 22:49:54 2012 -0700
     1.3 @@ -1257,18 +1257,42 @@
     1.4  
     1.5          token = TOK_STOCK;
     1.6      } else {
     1.7 -        if (matchName(returnTag.ref(), TOK_LABEL) && !returnTag)
     1.8 +        if (peek(TOK_LABEL)) {
     1.9 +            if (matchName(returnTag.ref(), TOK_LABEL) && !returnTag)
    1.10 +                return NULL;
    1.11 +        } else if (peek(TOK_NAME)) {
    1.12 +            // Peek for a type that has no :
    1.13 +            returnTag = expectName();
    1.14 +            if (!returnTag)
    1.15 +                return NULL;
    1.16 +        }
    1.17 +    }
    1.18 +
    1.19 +    Local<String> name(zone_);
    1.20 +    ExpressionList *returnDimensions = NULL;
    1.21 +
    1.22 +    bool allowArrayReturns = token != TOK_NATIVE &&
    1.23 +                             token != TOK_PUBLIC &&
    1.24 +                             token != TOK_FORWARD;
    1.25 +
    1.26 +    if (allowArrayReturns && peek(TOK_LBRACKET)) {
    1.27 +        if ((returnDimensions = dimensions()) == NULL)
    1.28              return NULL;
    1.29 +        if ((name = expectName()) == NULL)
    1.30 +            return NULL;
    1.31 +    } else if (peek(TOK_NAME)) {
    1.32 +        if ((name = expectName()) == NULL)
    1.33 +            return NULL;
    1.34 +    } else {
    1.35 +        // We predicted |type name|, but just got |name| instead.
    1.36 +        name = returnTag;
    1.37 +        returnTag = NULL;
    1.38      }
    1.39  
    1.40      BoundName *returnType = NULL;
    1.41      if (returnTag)
    1.42          returnType = bindType(returnTag);
    1.43  
    1.44 -    Local<String> name(zone_, expectName());
    1.45 -    if (!name)
    1.46 -        return NULL;
    1.47 -
    1.48      SourcePosition pos = scanner_.begin();
    1.49  
    1.50      // The function name goes into the outer (global) scope.
    1.51 @@ -1392,7 +1416,7 @@
    1.52  
    1.53      scope_ = scope_->enclosing();
    1.54  
    1.55 -    FunctionSignature signature(returnType, parameters);
    1.56 +    FunctionSignature signature(returnType, returnDimensions, parameters);
    1.57      if (token == TOK_TYPEDEF)
    1.58          return new (pool_) FunctionTypeStatement(pos, type, signature);
    1.59  
    1.60 @@ -1560,6 +1584,17 @@
    1.61      {
    1.62      }
    1.63  
    1.64 +    void dump(const FunctionSignature &sig) {
    1.65 +        prefix();
    1.66 +        fprintf(fp_, "%s", sig.returnType()
    1.67 +                           ? sig.returnType()->name()->chars()
    1.68 +                           : "_");
    1.69 +        if (sig.returnDimensions()) {
    1.70 +            for (size_t i = 0; i < sig.returnDimensions()->length(); i++)
    1.71 +                fprintf(fp_, "[]");
    1.72 +        }
    1.73 +        fprintf(fp_, "()\n");
    1.74 +    }
    1.75      void visit(NameProxy *name) {
    1.76          prefix();
    1.77          fprintf(fp_, "[ NameProxy (%s)%s\n", name->name()->chars(),
    1.78 @@ -1577,11 +1612,15 @@
    1.79      void visit(FunctionTypeStatement *node) {
    1.80          prefix();
    1.81          fprintf(fp_, "[ FunctionTypeStatement (%s)\n", node->decl()->name()->chars());
    1.82 +        indent();
    1.83 +        dump(node->signature());
    1.84 +        unindent();
    1.85      }
    1.86      void visit(FunctionStatement *node) {
    1.87          prefix();
    1.88          fprintf(fp_, "[ FunctionStatement (%s)\n", node->fun()->name()->chars());
    1.89          indent();
    1.90 +        dump(node->signature());
    1.91          if (node->body())
    1.92              node->body()->accept(this);
    1.93          unindent();