diff -r dd04fce774cd -r 9d17f29fe16a src/Parser.cpp --- a/src/Parser.cpp Sun Sep 16 21:59:26 2012 -0700 +++ b/src/Parser.cpp Sun Sep 16 22:49:54 2012 -0700 @@ -1257,18 +1257,42 @@ token = TOK_STOCK; } else { - if (matchName(returnTag.ref(), TOK_LABEL) && !returnTag) + if (peek(TOK_LABEL)) { + if (matchName(returnTag.ref(), TOK_LABEL) && !returnTag) + return NULL; + } else if (peek(TOK_NAME)) { + // Peek for a type that has no : + returnTag = expectName(); + if (!returnTag) + return NULL; + } + } + + Local name(zone_); + ExpressionList *returnDimensions = NULL; + + bool allowArrayReturns = token != TOK_NATIVE && + token != TOK_PUBLIC && + token != TOK_FORWARD; + + if (allowArrayReturns && peek(TOK_LBRACKET)) { + if ((returnDimensions = dimensions()) == NULL) return NULL; + if ((name = expectName()) == NULL) + return NULL; + } else if (peek(TOK_NAME)) { + if ((name = expectName()) == NULL) + return NULL; + } else { + // We predicted |type name|, but just got |name| instead. + name = returnTag; + returnTag = NULL; } BoundName *returnType = NULL; if (returnTag) returnType = bindType(returnTag); - Local name(zone_, expectName()); - if (!name) - return NULL; - SourcePosition pos = scanner_.begin(); // The function name goes into the outer (global) scope. @@ -1392,7 +1416,7 @@ scope_ = scope_->enclosing(); - FunctionSignature signature(returnType, parameters); + FunctionSignature signature(returnType, returnDimensions, parameters); if (token == TOK_TYPEDEF) return new (pool_) FunctionTypeStatement(pos, type, signature); @@ -1560,6 +1584,17 @@ { } + void dump(const FunctionSignature &sig) { + prefix(); + fprintf(fp_, "%s", sig.returnType() + ? sig.returnType()->name()->chars() + : "_"); + if (sig.returnDimensions()) { + for (size_t i = 0; i < sig.returnDimensions()->length(); i++) + fprintf(fp_, "[]"); + } + fprintf(fp_, "()\n"); + } void visit(NameProxy *name) { prefix(); fprintf(fp_, "[ NameProxy (%s)%s\n", name->name()->chars(), @@ -1577,11 +1612,15 @@ void visit(FunctionTypeStatement *node) { prefix(); fprintf(fp_, "[ FunctionTypeStatement (%s)\n", node->decl()->name()->chars()); + indent(); + dump(node->signature()); + unindent(); } void visit(FunctionStatement *node) { prefix(); fprintf(fp_, "[ FunctionStatement (%s)\n", node->fun()->name()->chars()); indent(); + dump(node->signature()); if (node->body()) node->body()->accept(this); unindent();