Skip to content

Commit

Permalink
Fixed false warning about break/continue in do/while/for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Mar 17, 2024
1 parent 644f51b commit ec08d7a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,51 @@ void collect(current: (StringTemplate) `if( <{Expression ","}+ conditions> ){ <S

void collect(current: (StringTemplate) `for( <{Expression ","}+ generators> ) { <Statement* preStats> <StringMiddle body> <Statement* postStats> }`, Collector c){
c.enterScope(generators); // body may refer to variables defined in conditions
loopName = "";
c.setScopeInfo(c.getScope(), loopScope(), loopInfo(loopName, [])); // appends in body
c.fact(current, alist(avoid()));

condList = [cond | Expression cond <- generators];
c.require("for statement template", current, condList, void (Solver s){ checkConditions(condList, s); });

beginPatternScope("conditions", c);
collect(condList, c);
collect(condList, c);
endPatternScope(c);

collect(preStats, body, postStats, c);
c.leaveScope(generators);
}

void collect(current: (StringTemplate) `do { <Statement* preStats> <StringMiddle body> <Statement* postStats> } while( <Expression condition> )`, Collector c){
c.enterScope(current); // condition may refer to variables defined in body
loopName = "";
c.setScopeInfo(c.getScope(), loopScope(), loopInfo(loopName, [])); // appends in body
c.fact(current, alist(avoid()));

condList = [condition];
c.require("do statement template", current, condList, void (Solver s){ checkConditions(condList, s); });
collect(preStats, body, postStats, c);

beginPatternScope("conditions", c);
collect(condition, c);
collect(condition, c);
endPatternScope(c);

collect(preStats, body, postStats, c);
c.leaveScope(current);
}

void collect(current: (StringTemplate) `while( <Expression condition> ) { <Statement* preStats> <StringMiddle body> <Statement* postStats> }`, Collector c){
c.enterScope(condition); // body may refer to variables defined in conditions
loopName = "";
c.setScopeInfo(c.getScope(), loopScope(), loopInfo(loopName, [])); // appends in body
c.fact(current, alist(avoid()));

condList = [condition];
c.require("while statement template", current, condList, void (Solver s){ checkConditions(condList, s); });

beginPatternScope("conditions", c);
collect(condList, c);
collect(condList, c);
endPatternScope(c);

collect(preStats, body, postStats, c);
c.leaveScope(condition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,11 @@ void collect(current: (Statement) `<Label label> do <Statement body> while ( <Ex
c.require("do statement", current, [body, condition], void (Solver s){ checkConditions([condition], s); });

collect(body, c);

beginPatternScope("conditions", c);
collect(condition, c);
collect(condition, c);
endPatternScope(c);

computeLoopType("do statement", loopName, current, c);
c.leaveScope(current);
}
Expand All @@ -339,11 +341,11 @@ void collect(current: (Statement) `<Label label> for( <{Expression ","}+ conditi
c.require("for statement", current, condList + [body], void (Solver s){ checkConditions(condList, s); });

beginPatternScope("conditions", c);
collect(condList, c);
collect(condList, c);
endPatternScope(c);

collect(body, c);
computeLoopType("for statement", loopName, current, c);

c.leaveScope(current);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ list[Message] compile(str qualifiedModuleName, RascalCompilerConfig compilerConf
start_comp = cpuTime();
ms = rascalTModelForNames([qualifiedModuleName], compilerConfig, compile1);

iprintln(convertTModel2PhysicalLocs(ms.tmodels[qualifiedModuleName]), lineLimit=10000);
//iprintln(convertTModel2PhysicalLocs(ms.tmodels[qualifiedModuleName]), lineLimit=10000);

comp_time = (cpuTime() - start_comp)/1000000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module lang::rascalcore::compile::Examples::Tst5

import String;
void main(){
previous = "non empty";
msg = "<for (x <- ["a", "b", "c"]) { if (trim(previous) == "", trim(x) == "") { continue; } previous = x;><x>
msg = "<for (x <- ["a", "b", "c"]) { continue;><x>
'<}>";
}

Expand Down

0 comments on commit ec08d7a

Please sign in to comment.