Commit e5e34129 authored by Sudeep Kanav's avatar Sudeep Kanav
Browse files

YELLOW

refs 2756
parent a5343976
......@@ -26,6 +26,7 @@ import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
......@@ -43,10 +44,12 @@ import org.fortiss.pragmatictransformation.service.IPragmaticTransformation;
* module.
* Assumption: there are no empty functions
*
* TODO 8023. I think it might be better to transform functions to CPP directives.
*
* @author kanav
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 7FC62FC2F7A4F998C2A714DADBF6E6AA
* @ConQAT.Rating YELLOW Hash: E0B9C4F6C80B8C89C6DAE8CD51140C34
*/
public class FunctionToSingleStatementFunction extends CacheSupportedTransformationBase {
......@@ -60,17 +63,15 @@ public class FunctionToSingleStatementFunction extends CacheSupportedTransformat
return c;
} else if(c instanceof FunctionDefinition) {
FunctionDefinition fd = (FunctionDefinition)c;
replace(fd.getDefinition(),
sequence(convertStatementSequenceToSingleStatement(fd.getDefinition())));
StatementSequence newSS = sequence(convertToSingleStatement(fd.getDefinition()));
replace(fd.getDefinition(), newSS);
return c;
}
return null;
}
/**
* Converts a statement sequence to a single statement.
*/
private IStatementTerm convertStatementSequenceToSingleStatement(StatementSequence ss) {
/** Converts a statement sequence to a single statement. */
private IStatementTerm convertToSingleStatement(StatementSequence ss) {
List<IStatementTerm> statements = (List<IStatementTerm>)copyAll(ss.getStatements());
if(statements.size() == 1) {
// Assumption: there are no empty functions
......@@ -83,25 +84,25 @@ public class FunctionToSingleStatementFunction extends CacheSupportedTransformat
IfThenElse s1 = (IfThenElse)st;
IExpressionTerm guard = s1.getGuard();
StatementSequence thenBlock =
sequence(convertStatementSequenceToSingleStatement(sequenceFromTwoLists(s1
.getThenBlock().getStatements(), statements)));
EList<IStatementTerm> thenStatements = s1.getThenBlock().getStatements();
IStatementTerm singleStatementForThenBlock =
convertToSingleStatement(sequenceFromTwoLists(thenStatements, statements));
StatementSequence thenBlock = sequence(singleStatementForThenBlock);
StatementSequence elseStatements = s1.getElseBlock();
StatementSequence elseStatementBlock = s1.getElseBlock();
StatementSequence remainingStatements =
elseStatements != null ? sequenceFromTwoLists(
elseStatements.getStatements(), statements) : sequence(statements);
elseStatementBlock == null ? sequence(statements) : sequenceFromTwoLists(
elseStatementBlock.getStatements(), statements);
StatementSequence elseBlock =
sequence(convertStatementSequenceToSingleStatement(remainingStatements));
sequence(convertToSingleStatement(remainingStatements));
return ifthenelse(guard, thenBlock, elseBlock);
}
}
return null;
}
/**
* Returns a {@link StatementSequence} with the given content.
*/
/** Returns a {@link StatementSequence} with the given content. */
private StatementSequence sequenceFromTwoLists(List<IStatementTerm> body1,
List<IStatementTerm> body2) {
addAll(body1, copyAll(body2));
......
Supports Markdown
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