-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Franco Montenegro
committed
May 25, 2016
1 parent
ceacd4b
commit 1386702
Showing
8 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/java/com/ruke/vrjassc/translator/expression/ContinueStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.ruke.vrjassc.translator.expression; | ||
|
||
public class ContinueStatement extends Statement { | ||
|
||
@Override | ||
public String translate() { | ||
LoopStatement loop = ((StatementBody) this.getParent()).getLoop(); | ||
|
||
if (loop == null || loop.getContinueSymbol() == null) { | ||
return ""; | ||
} | ||
|
||
Expression continueTrue = new AssignmentStatement( | ||
new VariableExpression(loop.getContinueSymbol(), null), | ||
new RawExpression("true") | ||
); | ||
|
||
return continueTrue.translate() + "\nexitwhen true\n"; | ||
} | ||
|
||
} |
88 changes: 87 additions & 1 deletion
88
src/main/java/com/ruke/vrjassc/translator/expression/LoopStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,96 @@ | ||
package com.ruke.vrjassc.translator.expression; | ||
|
||
import com.ruke.vrjassc.vrjassc.symbol.BuiltInTypeSymbol; | ||
import com.ruke.vrjassc.vrjassc.symbol.Symbol; | ||
|
||
/** | ||
* Thanks to Aniki for providing the continue translation! | ||
* http://www.hiveworkshop.com/forums/warcraft-editing-tools-277/vrjass-264114/index9.html#post2788578 | ||
*/ | ||
public class LoopStatement extends StatementBody { | ||
|
||
protected static int LOOP_CONTINUE_COUNTER = 0; | ||
protected Symbol _continue; | ||
|
||
protected void registerContinue() { | ||
if (this._continue != null) { | ||
return; | ||
} | ||
|
||
this._continue = new Symbol("vr_c_" + LOOP_CONTINUE_COUNTER, null, null); | ||
this._continue.setType(new BuiltInTypeSymbol("boolean", null, null)); | ||
|
||
this.add(new VariableStatement(this._continue, null)); | ||
|
||
LOOP_CONTINUE_COUNTER++; | ||
} | ||
|
||
@Override | ||
public void add(Statement e) { | ||
super.add(e); | ||
|
||
if (this._continue == null && this.containsContinue(e)) { | ||
this.registerContinue(); | ||
} | ||
} | ||
|
||
protected boolean containsContinue(Statement e) { | ||
if (e == null) { | ||
return false; | ||
} | ||
|
||
if (e instanceof LoopStatement) { | ||
return false; | ||
} | ||
|
||
if (e instanceof ContinueStatement) { | ||
return true; | ||
} | ||
|
||
if (e instanceof StatementBody) { | ||
for (Statement s : ((StatementBody) e).getStatements()) { | ||
if (this.containsContinue(s)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public Symbol getContinueSymbol() { | ||
return this._continue; | ||
} | ||
|
||
@Override | ||
public String translate() { | ||
return "loop\n"+ super.translate() + "endloop"; | ||
String continueHeader = ""; | ||
String body = super.translate(); | ||
String continueFooter = ""; | ||
|
||
if (this._continue != null) { | ||
continueHeader = new AssignmentStatement( | ||
new VariableExpression(this._continue, null), | ||
new RawExpression("false") | ||
).translate() + "\n"; | ||
|
||
body = "loop\n" + body + "endloop\n"; | ||
|
||
continueFooter = new ExitWhenStatement( | ||
new BooleanExpression( | ||
new VariableExpression(this._continue, null), | ||
BooleanExpression.Operator.EQUAL_EQUAL, | ||
new RawExpression("false") | ||
) | ||
).translate() + "\n"; | ||
} | ||
|
||
return | ||
"loop\n" + | ||
continueHeader + | ||
body + | ||
continueFooter + | ||
"endloop"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters