Unverified Commit 695a2715 authored by Kristof Szabados's avatar Kristof Szabados Committed by GitHub

Merge pull request #279 from izaingrid/master

generate code for break, continue and added dependencies
parents 08ef5e2c 659eb007
......@@ -262,7 +262,9 @@ public final class Def_Altstep extends Definition implements IParameterisedAssig
}
if (altGuards != null) {
altGuards.setIsAltstep();
altGuards.setMyAltguards(altGuards);
altGuards.setMyLaicStmt(altGuards, null);
altGuards.check(timestamp);
altGuards.setCodeSection(CodeSectionType.CS_INLINE);
}
......
......@@ -114,4 +114,22 @@ public abstract class AltGuard extends ASTNode implements ILocateableNode, IIncr
* after the semantic check was completely run.
*/
public abstract void postCheck();
public void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
switch (altguardType) {
case AG_OP:
case AG_ELSE:
statementblock.setMyLaicStmt(pAltGuards, pLoopStmt);
break;
case AG_REF:
case AG_INVOKE:
if (statementblock != null) {
statementblock.setMyLaicStmt(pAltGuards, pLoopStmt);
}
break;
default:
// FIXME: FATAL_ERROR("AltGuard::set_my_laic_stmt()");
break;
}
}
}
......@@ -61,6 +61,7 @@ public final class AltGuards extends ASTNode implements IIncrementallyUpdateable
private boolean hasRepeat = false;
private String label;
private boolean isAltstep = false;
/**
* The location of the whole assignment. This location encloses the
......@@ -173,6 +174,14 @@ public final class AltGuards extends ASTNode implements IIncrementallyUpdateable
return label;
}
public void setIsAltstep() {
isAltstep = true;
}
public boolean getIsAltstep() {
return isAltstep;
}
/**
* Checks whether there is an else branch among the altguards.
*
......@@ -810,4 +819,10 @@ public final class AltGuards extends ASTNode implements IIncrementallyUpdateable
source.append("TTCN_Snapshot.takeNew(true);\n");
source.append("}\n");
}
public void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
for (AltGuard altGuard : altGuards) {
altGuard.setMyLaicStmt(pAltGuards, pLoopStmt);
}
}
}
......@@ -107,6 +107,13 @@ public final class Alt_Statement extends Statement {
return true;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
if (pLoopStmt != null) {
altGuards.setMyLaicStmt(null,pLoopStmt);
}
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......@@ -116,6 +123,7 @@ public final class Alt_Statement extends Statement {
if (altGuards != null) {
altGuards.setMyAltguards(altGuards);
altGuards.setMyLaicStmt(altGuards, null);
altGuards.check(timestamp);
}
......
......@@ -8,18 +8,23 @@
package org.eclipse.titan.designer.AST.TTCN3.statements;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException;
import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
/**
* @author Kristof Szabados
* @author Farkas Izabella Ingrid
* */
public final class Break_Statement extends Statement {
private static final String INCORRECTUSAGE = "Break statement cannot be used outside loops,"
+ " alt or interleave statements, altsteps or response and exception handling part of call operations";
private static final String STATEMENT_NAME = "break";
private Statement loop_stmt;
private AltGuards altGuards;
@Override
/** {@inheritDoc} */
public Statement_type getType() {
......@@ -38,6 +43,14 @@ public final class Break_Statement extends Statement {
return true;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
if (pLoopStmt != null) {
loop_stmt = pLoopStmt;
}
altGuards = pAltGuards;
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......@@ -47,6 +60,15 @@ public final class Break_Statement extends Statement {
if (myStatementBlock == null || !myStatementBlock.hasEnclosingLoopOrAltguard()) {
location.reportSemanticError(INCORRECTUSAGE);
}
if(loop_stmt == null && altGuards == null) {
location.reportSemanticError(INCORRECTUSAGE);
}
if (loop_stmt != null) {
//FIXME:
// brk_cnt.loop_stmt->loop.has_brk=true;
}
lastTimeChecked = timestamp;
}
......@@ -64,4 +86,14 @@ public final class Break_Statement extends Statement {
// no members
return true;
}
@Override
/** {@inheritDoc} */
public void generateCode( final JavaGenData aData, final StringBuilder source ) {
if (altGuards != null && altGuards.getIsAltstep()) {
source.append("return TitanAlt_Status.ALT_BREAK;\n");
} else {
source.append("break;\n");
}
}
}
......@@ -207,6 +207,14 @@ public final class Call_Statement extends Statement {
return false;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStatement) {
if (pLoopStatement != null && altGuards != null) {
altGuards.setMyLaicStmt(null, pLoopStatement);
}
// ags is set later
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......@@ -351,6 +359,7 @@ public final class Call_Statement extends Statement {
}
}
altGuards.setMyLaicStmt(altGuards, null);
altGuards.setMyAltguards(altGuards);
altGuards.check(timestamp);
......
......@@ -8,18 +8,23 @@
package org.eclipse.titan.designer.AST.TTCN3.statements;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException;
import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
/**
* @author Kristof Szabados
* @author Farkas Izabella Ingrid
* */
public final class Continue_Statement extends Statement {
private static final String INCORRECTUSAGE = "Continue statement cannot be used outside loops";
private static final String STATEMENT_NAME = "continue";
private Statement loop_stmt;
private AltGuards altGuards;
@Override
/** {@inheritDoc} */
public Statement_type getType() {
......@@ -38,6 +43,14 @@ public final class Continue_Statement extends Statement {
return true;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
if (pLoopStmt != null) {
loop_stmt = pLoopStmt;
}
altGuards = pAltGuards;
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......@@ -47,6 +60,18 @@ public final class Continue_Statement extends Statement {
if (myStatementBlock == null || !myStatementBlock.hasEnclosingLoop()) {
location.reportSemanticError(INCORRECTUSAGE);
}
if (loop_stmt != null) {
// FIXME:
// loop_stmt->loop.has_cnt=true;
if (altGuards != null) {
//FIXME:
// loop_stmt->loop.has_cnt_in_ags=true;
}
} else {
location.reportSemanticError(INCORRECTUSAGE);
}
lastTimeChecked = timestamp;
}
......@@ -64,4 +89,24 @@ public final class Continue_Statement extends Statement {
// no members
return true;
}
@Override
/** {@inheritDoc} */
public void generateCode( final JavaGenData aData, final StringBuilder source ) {
// not inside interleave when continue is not inside embedded ags (2 or 1)
// continue is inside ags enclosed in the loop (3)
// in interleave (3, 2 or 1)
//FIXME: implement
if (loop_stmt != null) {
if (altGuards != null) { // iterate_once, is_ilt
source.append("break;\n");
}
else {
// if !brk_cnt.loop_stmt->loop.label_next
source.append("continue;\n");
}
} else {
// FIXME: FATAL_ERROR("Statement::generate_code_continue()");
}
}
}
......@@ -173,6 +173,7 @@ public final class DoWhile_Statement extends Statement {
isInfiniteLoop = false;
if (statementblock != null) {
statementblock.setMyLaicStmt(null, this);
statementblock.check(timestamp);
}
if (expression != null) {
......
......@@ -279,6 +279,7 @@ public final class For_Statement extends Statement {
stepAssignment.check(timestamp);
}
if (statementblock != null) {
statementblock.setMyLaicStmt(null,this);
statementblock.check(timestamp);
//warning for "return" has been removed. Not valid problem
}
......
......@@ -291,4 +291,10 @@ public final class If_Clauses extends ASTNode implements IIncrementallyUpdateabl
ifclauses.get(i).generateCode(aData, source, blockCount, unReachable, eachFalse);
}
}
public void setMyLaicStmt(AltGuards pAgs, Statement pLoopStmt) {
for (If_Clause ifClause : ifclauses) {
ifClause.getStatementBlock().setMyLaicStmt(pAgs, pLoopStmt);
}
}
}
......@@ -199,6 +199,14 @@ public final class If_Statement extends Statement {
return result;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
ifClauses.setMyLaicStmt(pAltGuards, pLoopStmt);
if (statementblock != null) { // if (if_stmt.elseblock)
statementblock.setMyLaicStmt(pAltGuards, pLoopStmt);
}
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......
......@@ -93,6 +93,13 @@ public final class Interleave_Statement extends Statement {
return true;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
if (pLoopStmt != null) {
altGuards.setMyLaicStmt(null,pLoopStmt);
}
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......@@ -101,6 +108,7 @@ public final class Interleave_Statement extends Statement {
}
if (altGuards != null) {
altGuards.setMyLaicStmt(altGuards, null);
altGuards.check(timestamp);
altGuards.checkAllowedInterleave();
}
......
......@@ -125,6 +125,11 @@ public final class SelectCase_Statement extends Statement {
return false;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
selectcases.setMyLaicStmt(pAltGuards,pLoopStmt);
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......
......@@ -267,4 +267,10 @@ public final class SelectCases extends ASTNode implements IIncrementallyUpdateab
source.append(init);
}
public void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
for (SelectCase selectCase : select_cases) {
selectCase.getStatementBlock().setMyLaicStmt(pAltGuards, pLoopStmt);
}
}
}
......@@ -132,6 +132,11 @@ public final class SelectUnionCase_Statement extends Statement {
return false;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
selectUnionCases.setMyLaicStmt(pAltGuards, pLoopStmt);
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......
......@@ -303,4 +303,10 @@ public final class SelectUnionCases extends ASTNode implements IIncrementallyUpd
source.append("default:\nbreak;\n");
}
}
public void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
for (SelectUnionCase selectCase : selectUnionCases) {
selectCase.getStatementBlock().setMyLaicStmt(pAltGuards, pLoopStmt);
}
}
}
......@@ -205,6 +205,10 @@ public abstract class Statement extends ASTNode implements ILocateableNode, IApp
protected boolean isErroneous;
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
//empty by default
}
protected Statement() {
isErroneous = false;
location = NULL_Location.INSTANCE;
......@@ -403,7 +407,7 @@ public abstract class Statement extends ASTNode implements ILocateableNode, IApp
* Add generated java code on this level
* @param aData the generated java code with other info
*/
//public abstract void generateCode( final JavaGenData aData );
//public abstract void generateCode( final JavaGenData aData, final StringBuilder source );
//TODO: remove
/**
......
......@@ -553,6 +553,12 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
}
}
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
for(Statement statment : statements) {
statment.setMyLaicStmt(pAltGuards, pLoopStmt);
}
}
/**
* Does the semantic checking of the statement block.
*
......
......@@ -136,6 +136,11 @@ public final class StatementBlock_Statement extends Statement {
return false;
}
@Override
protected void setMyLaicStmt(AltGuards pAltGuards, Statement pLoopStmt) {
statementblock.setMyLaicStmt(pAltGuards, pLoopStmt);
}
@Override
/** {@inheritDoc} */
public void check(final CompilationTimeStamp timestamp) {
......
......@@ -209,6 +209,7 @@ public final class While_Statement extends Statement {
}
}
if (statementblock != null) {
statementblock.setMyLaicStmt(null, this);
statementblock.check(timestamp);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment