/[svn]/linuxsampler/trunk/src/scriptvm/parser.y
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/parser.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3052 by schoenebeck, Wed Dec 14 17:34:54 2016 UTC revision 3257 by schoenebeck, Tue May 30 17:20:02 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2016 Christian Schoenebeck and Andreas Persson   * Copyright (c) 2014-2017 Christian Schoenebeck and Andreas Persson
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 280  statement: Line 280  statement:
280                  PARSE_ERR(@4, (String("Array variable '") + name + "' must be declared with positive array size.").c_str());                  PARSE_ERR(@4, (String("Array variable '") + name + "' must be declared with positive array size.").c_str());
281                  $$ = new FunctionCall("nothing", new Args, NULL); // whatever                  $$ = new FunctionCall("nothing", new Args, NULL); // whatever
282              } else if (args->argsCount() > size) {              } else if (args->argsCount() > size) {
283                  PARSE_ERR(@8, (String("Variable '") + name +                  PARSE_ERR(@8, (String("Array variable '") + name +
284                            "' was declared with size " + ToString(size) +                            "' was declared with size " + ToString(size) +
285                            " but " + ToString(args->argsCount()) +                            " but " + ToString(args->argsCount()) +
286                            " values were assigned." ).c_str());                            " values were assigned." ).c_str());
# Line 307  statement: Line 307  statement:
307              }              }
308          }          }
309      }      }
310        | DECLARE CONST_ VARIABLE '[' expr ']' ASSIGNMENT '(' args ')'  {
311            const char* name = $3;
312            if (!$5->isConstExpr()) {
313                PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with constant array size.").c_str());
314                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
315            } else if ($5->exprType() != INT_EXPR) {
316                PARSE_ERR(@5, (String("Size of array variable '") + name + "' declared with non integer expression.").c_str());
317                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
318            } else if (context->variableByName(name)) {
319                PARSE_ERR(@3, (String("Redeclaration of variable '") + name + "'.").c_str());
320                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
321            } else {
322                IntExprRef sizeExpr = $5;
323                ArgsRef args = $9;
324                int size = sizeExpr->evalInt();
325                if (size <= 0) {
326                    PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with positive array size.").c_str());
327                    $$ = new FunctionCall("nothing", new Args, NULL); // whatever
328                } else if (args->argsCount() > size) {
329                    PARSE_ERR(@9, (String("Array variable '") + name +
330                              "' was declared with size " + ToString(size) +
331                              " but " + ToString(args->argsCount()) +
332                              " values were assigned." ).c_str());
333                    $$ = new FunctionCall("nothing", new Args, NULL); // whatever          
334                } else {
335                    bool argsOK = true;
336                    for (int i = 0; i < args->argsCount(); ++i) {
337                        if (args->arg(i)->exprType() != INT_EXPR) {
338                            PARSE_ERR(
339                                @9,
340                                (String("Array variable '") + name +
341                                "' declared with invalid assignment values. Assigned element " +
342                                ToString(i+1) + " is not an integer expression.").c_str()
343                            );
344                            argsOK = false;
345                            break;
346                        }
347                        if (!args->arg(i)->isConstExpr()) {
348                            PARSE_ERR(
349                                @9,
350                                (String("const array variable '") + name +
351                                "' must be defined with const values. Assigned element " +
352                                ToString(i+1) + " is not a const expression though.").c_str()
353                            );
354                            argsOK = false;
355                            break;
356                        }
357                    }
358                    if (argsOK) {
359                        context->vartable[name] = new IntArrayVariable(context, size, args, true);
360                        $$ = new NoOperation;
361                    } else
362                        $$ = new FunctionCall("nothing", new Args, NULL); // whatever
363                }
364            }
365        }
366      | DECLARE CONST_ VARIABLE ASSIGNMENT expr  {      | DECLARE CONST_ VARIABLE ASSIGNMENT expr  {
367          const char* name = $3;          const char* name = $3;
368          if ($5->exprType() == STRING_EXPR) {          if ($5->exprType() == STRING_EXPR) {
# Line 507  assignment: Line 563  assignment:
563              PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str());              PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str());
564          else if (var->exprType() != INT_ARR_EXPR)          else if (var->exprType() != INT_ARR_EXPR)
565              PARSE_ERR(@2, (String("Variable '") + name + "' is not an array variable.").c_str());              PARSE_ERR(@2, (String("Variable '") + name + "' is not an array variable.").c_str());
566            else if (var->isConstExpr())
567                PARSE_ERR(@5, (String("Variable assignment: Cannot modify const array variable '") + name + "'.").c_str());
568            else if (!var->isAssignable())
569                PARSE_ERR(@5, (String("Variable assignment: Array variable '") + name + "' is not assignable.").c_str());
570          else if ($3->exprType() != INT_EXPR)          else if ($3->exprType() != INT_EXPR)
571              PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str());              PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str());
572          else if ($6->exprType() != INT_EXPR)          else if ($6->exprType() != INT_EXPR)
573              PARSE_ERR(@5, (String("Value assigned to array variable '") + name + "' must be an integer expression.").c_str());              PARSE_ERR(@5, (String("Value assigned to array variable '") + name + "' must be an integer expression.").c_str());
574            else if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize())
575                PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) +
576                              " exceeds size of array variable '" + name +
577                              "' which was declared with size " +
578                              ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str());
579          IntArrayElementRef element = new IntArrayElement(var, $3);          IntArrayElementRef element = new IntArrayElement(var, $3);
580          $$ = new Assignment(element, $6);          $$ = new Assignment(element, $6);
581      }      }
# Line 545  unary_expr: Line 610  unary_expr:
610              PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str());              PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str());
611              $$ = new IntLiteral(0);              $$ = new IntLiteral(0);
612          } else {          } else {
613                if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize())
614                    PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) +
615                                   " exceeds size of array variable '" + name +
616                                   "' which was declared with size " +
617                                   ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str());
618              $$ = new IntArrayElement(var, $3);              $$ = new IntArrayElement(var, $3);
619          }          }
620      }      }
# Line 838  int InstrScript_tnamerr(char* yyres, con Line 908  int InstrScript_tnamerr(char* yyres, con
908      }      }
909    
910    if (! yyres)    if (! yyres)
911      return yystrlen (yystr);      return (int) yystrlen (yystr);
912    
913    return yystpcpy (yyres, yystr) - yyres;    return int( yystpcpy (yyres, yystr) - yyres );
914  }  }

Legend:
Removed from v.3052  
changed lines
  Added in v.3257

  ViewVC Help
Powered by ViewVC