Skip to content

Commit

Permalink
Parse mos-file statements using iteration
Browse files Browse the repository at this point in the history
Recursion caused very long mos-files to crash during the parsing. Doing
a listReverseInPlace is a small price to pay for not crashing.
Note: There will be no testcase for this since you need ~45MB mos-files
to trigger this on an -Os optimized omc (really only triggers for
-O0 -g).
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 27, 2017
1 parent f9882c3 commit 8e2a2a0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Parser/Modelica.g
Expand Up @@ -1676,20 +1676,24 @@ interactive_stmt returns [void* ast]
@declarations { int last_sc = 0; }
@init{ ss = 0; } :
// A list of expressions or algorithms separated by semicolons and optionally ending with a semicolon
BOM? ss=interactive_stmt_list[&last_sc] EOF
BOM? ss=interactive_stmt_list (SEMICOLON {last_sc=1;})? EOF
{
ast = GlobalScript__ISTMTS(or_nil(ss), mmc_mk_bcon(last_sc));
}
;
interactive_stmt_list [int *last_sc] returns [void* ast]
@init { a.ast = 0; $ast = 0; void *val; } :
a=top_algorithm ( (SEMICOLON ss=interactive_stmt_list[last_sc]) | (SEMICOLON { *last_sc = 1; }) | /* empty */ )
{
$ast = mmc_mk_cons(a.ast, or_nil(ss));
}
interactive_stmt_list returns [void* ast]
@init { a.ast = 0; $ast = mmc_mk_nil(); void *val; } :
a=top_algorithm {$ast = mmc_mk_cons(a.ast, $ast);} (SEMICOLON a=top_algorithm {$ast = mmc_mk_cons(a.ast, $ast);})*
{
/* We build the list using iteration instead of recursion to save
* stack space, so we need to reverse the result. */
$ast = listReverseInPlace($ast);
}
;
/* MetaModelica */
match_expression returns [void* ast]
@init{ ty = 0; exp.ast = 0; cmt = 0; es = 0; cs = 0; } :
Expand Down

0 comments on commit 8e2a2a0

Please sign in to comment.