Enable dynamic array declarations.
authorDavid Anderson <dvander@alliedmods.net>
Sun Sep 16 21:59:26 2012 -0700 (2012-09-16)
changeset 190dd04fce774cd
parent 189 eee18bf13c9b
child 191 9d17f29fe16a
Enable dynamic array declarations.
src/BytecodeCompiler.cpp
src/Messages.tbl
src/SemanticAnalysis.cpp
     1.1 --- a/src/BytecodeCompiler.cpp	Sun Sep 16 21:59:18 2012 -0700
     1.2 +++ b/src/BytecodeCompiler.cpp	Sun Sep 16 21:59:26 2012 -0700
     1.3 @@ -973,7 +973,18 @@
     1.4          } else if (type->isFixedLength()) {
     1.5              __ newarray(OP_NEWFIXED, map, tenure);
     1.6          } else {
     1.7 -            __ newarray(OP_NEWEMPTY, map, tenure);
     1.8 +            if (node->postDimensions()) {
     1.9 +                for (size_t i = 0; i < node->postDimensions()->length(); i++) {
    1.10 +                    Expression *expr = node->postDimensions()->at(i);
    1.11 +                    if (expr)
    1.12 +                        expr->accept(this);
    1.13 +                    else
    1.14 +                        __ int_(0);
    1.15 +                }
    1.16 +                __ newarray(OP_NEWSIZED, map, tenure);
    1.17 +            } else {
    1.18 +                __ newarray(OP_NEWEMPTY, map, tenure);
    1.19 +            }
    1.20          }
    1.21      } else if (type->isStruct()) {
    1.22          Local<Map> map(zone_, type->newMap());
     2.1 --- a/src/Messages.tbl	Sun Sep 16 21:59:18 2012 -0700
     2.2 +++ b/src/Messages.tbl	Sun Sep 16 21:59:26 2012 -0700
     2.3 @@ -78,4 +78,5 @@
     2.4  MSG(UnexpectedArrayLiteral,         SyntaxError,            "unexpected array literal")
     2.5  MSG(InvalidDimensionSize,           TypeError,              "invalid size %d for dimension %d")
     2.6  MSG(CannotComputeIndexRef,          SyntaxError,            "cannot use an array index as a reference")
     2.7 +MSG(BadDynamicInitializer,          SyntaxError,            "dynamic length specified, but preceding array is empty")
     2.8  
     3.1 --- a/src/SemanticAnalysis.cpp	Sun Sep 16 21:59:18 2012 -0700
     3.2 +++ b/src/SemanticAnalysis.cpp	Sun Sep 16 21:59:26 2012 -0700
     3.3 @@ -710,10 +710,13 @@
     3.4  bool
     3.5  SemanticAnalysis::evaluateDimensions(ExpressionList *exprs, int dims[MAX_ARRAY_DEPTH])
     3.6  {
     3.7 +    bool hadEmptySize = false;
     3.8 +
     3.9      for (size_t i = 0; i < exprs->length(); i++) {
    3.10          Expression *expr = exprs->at(i);
    3.11          if (!expr) {
    3.12              dims[i] = INFER_ARRAY_SIZE;
    3.13 +            hadEmptySize = true;
    3.14              continue;
    3.15          }
    3.16  
    3.17 @@ -738,6 +741,11 @@
    3.18              return false;
    3.19          }
    3.20  
    3.21 +        if (hadEmptySize) {
    3.22 +            cc_.reportError(expr->pos(), Message_BadDynamicInitializer);
    3.23 +            return false;
    3.24 +        }
    3.25 +
    3.26          dims[i] = EVAL_ARRAY_SIZE;
    3.27      }
    3.28