Support return tags on functions.
authorDavid Anderson <dvander@alliedmods.net>
Sun Jul 29 18:19:12 2012 -0700 (2012-07-29)
changeset 132d8379f5d5a1d
parent 131 48b0c2edb0df
child 133 7797936ba34c
Support return tags on functions.
src/AST.h
src/HashTable.h
src/Parser.cpp
src/SemanticAnalysis.cpp
     1.1 --- a/src/AST.h	Sun Jul 29 18:02:13 2012 -0700
     1.2 +++ b/src/AST.h	Sun Jul 29 18:19:12 2012 -0700
     1.3 @@ -1,19 +1,20 @@
     1.4 -/*
     1.5 +/* vim: set ts=4 sw=4 tw=99 et:
     1.6 + *
     1.7   * Copyright (C) 2012 David Anderson
     1.8   *
     1.9 - * This file is part of JITCraft.
    1.10 + * This file is part of SourcePawn.
    1.11   *
    1.12 - * JITCraft is free software: you can redistribute it and/or modify it under
    1.13 + * SourcePawn is free software: you can redistribute it and/or modify it under
    1.14   * the terms of the GNU General Public License as published by the Free
    1.15   * Software Foundation, either version 3 of the License, or (at your option)
    1.16   * any later version.
    1.17   * 
    1.18 - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    1.19 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    1.20   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.21   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.22   *
    1.23   * You should have received a copy of the GNU General Public License along with
    1.24 - * JITCraft. If not, see http://www.gnu.org/licenses/.
    1.25 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
    1.26   */
    1.27  #ifndef _include_jitcraft_ast_h_
    1.28  #define _include_jitcraft_ast_h_
    1.29 @@ -691,10 +692,11 @@
    1.30      Statement *body_;
    1.31      ParameterList *parameters_;
    1.32      bool explicitReturn_;
    1.33 +    ScopedRoot<String> tag_;
    1.34  
    1.35    public:
    1.36      FunctionStatement(const SourcePosition &pos, Scope *scope, NamedFunction *fun, Statement *body,
    1.37 -                      ParameterList *parameters, bool explicitReturn)
    1.38 +                      ParameterList *parameters, Handle<String> returnTag, bool explicitReturn)
    1.39        : Statement(pos),
    1.40          scope_(scope),
    1.41          fun_(fun),
    1.42 @@ -725,6 +727,9 @@
    1.43      bool hasExplicitReturn() const {
    1.44          return explicitReturn_;
    1.45      }
    1.46 +    String *returnTag() const {
    1.47 +        return tag_;
    1.48 +    }
    1.49  };
    1.50  
    1.51  class IfStatement : public Statement
     2.1 --- a/src/HashTable.h	Sun Jul 29 18:02:13 2012 -0700
     2.2 +++ b/src/HashTable.h	Sun Jul 29 18:19:12 2012 -0700
     2.3 @@ -1,19 +1,20 @@
     2.4 -/*
     2.5 +/* vim: set ts=4 sw=4 tw=99 et:
     2.6 + *
     2.7   * Copyright (C) 2012 David Anderson
     2.8   *
     2.9 - * This file is part of JITCraft.
    2.10 + * This file is part of SourcePawn.
    2.11   *
    2.12 - * JITCraft is free software: you can redistribute it and/or modify it under
    2.13 + * SourcePawn is free software: you can redistribute it and/or modify it under
    2.14   * the terms of the GNU General Public License as published by the Free
    2.15   * Software Foundation, either version 3 of the License, or (at your option)
    2.16   * any later version.
    2.17   * 
    2.18 - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    2.19 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    2.20   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    2.21   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    2.22   *
    2.23   * You should have received a copy of the GNU General Public License along with
    2.24 - * JITCraft. If not, see http://www.gnu.org/licenses/.
    2.25 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
    2.26   */
    2.27  #ifndef _INCLUDE_KEIMA_HASHTABLE_H_
    2.28  #define _INCLUDE_KEIMA_HASHTABLE_H_
    2.29 @@ -191,7 +192,6 @@
    2.30      }
    2.31      
    2.32      bool grow() {
    2.33 -        assert(IsPowerOfTwo(kMaxCapacity));
    2.34          if (capacity_ >= kMaxCapacity) {
    2.35              this->reportAllocationOverflow();
    2.36              return false;
    2.37 @@ -339,10 +339,12 @@
    2.38      }
    2.39  
    2.40      bool init(uint32 capacity = 0) {
    2.41 -        if (capacity < kMinCapacity)
    2.42 +        if (capacity < kMinCapacity) {
    2.43              capacity = kMinCapacity;
    2.44 -        else if (capacity > kMaxCapacity)
    2.45 -            capacity = kMaxCapacity;
    2.46 +        } else if (capacity > kMaxCapacity) {
    2.47 +            this->reportAllocationOverflow();
    2.48 +            return false;
    2.49 +        }
    2.50  
    2.51          minCapacity_ = capacity;
    2.52  
     3.1 --- a/src/Parser.cpp	Sun Jul 29 18:02:13 2012 -0700
     3.2 +++ b/src/Parser.cpp	Sun Jul 29 18:19:12 2012 -0700
     3.3 @@ -922,6 +922,10 @@
     3.4  Statement *
     3.5  Parser::function(TokenKind token)
     3.6  {
     3.7 +    Local<String> returnTag(zone_);
     3.8 +    if (matchName(returnTag.ref(), TOK_LABEL) && !returnTag)
     3.9 +        return NULL;
    3.10 +
    3.11      Local<String> name(zone_, expectName());
    3.12      if (!name)
    3.13          return NULL;
    3.14 @@ -1039,7 +1043,8 @@
    3.15      }
    3.16  
    3.17      scope_ = scope_->enclosing();
    3.18 -    return new (pool_) FunctionStatement(pos, scope, fun, body, parameters, encounteredReturn_);
    3.19 +    return new (pool_) FunctionStatement(pos, scope, fun, body, parameters, returnTag,
    3.20 +                                         encounteredReturn_);
    3.21  }
    3.22  
    3.23  ParseTree *
     4.1 --- a/src/SemanticAnalysis.cpp	Sun Jul 29 18:02:13 2012 -0700
     4.2 +++ b/src/SemanticAnalysis.cpp	Sun Jul 29 18:19:12 2012 -0700
     4.3 @@ -717,10 +717,14 @@
     4.4      }
     4.5  
     4.6      Local<Type> returnType(zone_);
     4.7 -    if (node->hasExplicitReturn() || node->fun()->isNative())
     4.8 +    if (node->returnTag()) {
     4.9 +        Local<String> tag(zone_, node->returnTag());
    4.10 +        returnType = zone_->types()->getPrimitiveForTag(tag);
    4.11 +    } else if (node->hasExplicitReturn() || node->fun()->isNative()) {
    4.12          returnType = zone_->types()->getPrimitive(PrimitiveType_Int32);
    4.13 -    else
    4.14 +    } else {
    4.15          returnType = zone_->types()->getVoid();
    4.16 +    }
    4.17      if (!returnType)
    4.18          return false;
    4.19