use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class Def_AltStatement_Writer method writeTestCaseAltStatement.
public void writeTestCaseAltStatement(Alt_Statement altStatement) {
AltGuards currentAltGuards = altStatement.getAltGuards();
String[] negativeConditions = new String[currentAltGuards.getNofAltguards()];
String[] positiveConditions = new String[currentAltGuards.getNofAltguards()];
// initialize values
for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) {
AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i);
if (currentAltGuard instanceof Operation_Altguard) {
Statement currentStatement = ((Operation_Altguard) currentAltGuard).getGuardStatement();
if (currentStatement instanceof Receive_Port_Statement) {
altReceiveCounter++;
if (altGuardConditions.get(i) != null) {
// alt guard present && any port receive
if (altGuardPortReference.get(altReceiveCounter).equals("any port")) {
positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + "anyPortReceive(true))";
negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + "anyPortReceive(false))";
} else {
// alt guard present && normal port receive
positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",true)!=null)";
negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",false)!=null)";
if (altGuardReceiveValue.get(altReceiveCounter).startsWith("Templates")) {
altGuardReceiveType.set(altReceiveCounter, "Templates");
}
}
} else {
// no alt guard && any port recieve
if (altGuardPortReference.get(altReceiveCounter).equals("any port")) {
positiveConditions[i] = "anyPortReceive(true)";
negativeConditions[i] = "anyPortReceive(false)";
} else {
// no alt guard && no receive parameter
if (altGuardReceiveType.get(altReceiveCounter).equals("noparam")) {
positiveConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(true)!=null";
negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(false)!=null";
} else if (// no alt guard && typed port recieve
altGuardReceiveType.get(altReceiveCounter).equals("_TYPED_PARAM_")) {
negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive_" + altGuardReceiveValue.get(altReceiveCounter) + "(false)!=null";
if (altGuardReceiveAnyValValue.get(altReceiveCounter) != null) {
positiveConditions[i] = "(" + altGuardReceiveAnyValValue.get(altReceiveCounter) + "=" + altGuardPortReference.get(altReceiveCounter) + ".receive_" + altGuardReceiveValue.get(altReceiveCounter) + "(true))!=null";
} else {
}
} else {
// no alt guard && normal port recieve
positiveConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",true)!=null";
negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",false)!=null";
}
if (altGuardReceiveValue.get(altReceiveCounter) != null && altGuardReceiveValue.get(altReceiveCounter).startsWith("Templates")) {
altGuardReceiveType.set(altReceiveCounter, "Templates");
}
}
}
}
if (currentStatement instanceof Timeout_Statement) {
timeOutCounter++;
if (altGuardConditions.get(i) != null) {
positiveConditions[i] = altGuardConditions.get(i) + "&&(" + altGuardTimeout.get(timeOutCounter) + ".timeout()";
negativeConditions[i] = altGuardConditions.get(i) + "&&(!" + altGuardTimeout.get(i) + ".timeout()";
} else {
positiveConditions[i] = altGuardTimeout.get(timeOutCounter) + ".timeout()";
negativeConditions[i] = "!" + altGuardTimeout.get(timeOutCounter) + ".timeout()";
}
}
}
}
// write
altString.append("rownum=" + altStatement.getLocation().getLine() + ";\r\n");
altString.append("for(;;){" + "\r\n");
altString.append("if(!(");
for (int j = 0; j < negativeConditions.length; j++) {
altString.append(negativeConditions[j]);
if (j + 1 < negativeConditions.length) {
altString.append("||");
}
}
altString.append(")){" + "\r\n");
// timer
if (isThereAStartedTimer) {
altString.append("long timeout = -1;" + "\r\n");
altString.append("long newtimeout;" + "\r\n");
altString.append("if(" + currentTimerName + ".running)if((newtimeout=(long)(" + currentTimerName + ".read().value*1000.0))<timeout || timeout == -1) timeout=newtimeout;" + "\r\n");
altString.append("if(timeout>0) try{queue.poll(timeout,TimeUnit.MILLISECONDS);}catch(InterruptedException e){} " + "\r\n");
} else {
altString.append("try{queue.take();}catch(InterruptedException e){}" + "\r\n");
}
// endoftimer
altString.append("}" + "\r\n");
altString.append("this.lock();" + "\r\n");
// ifwriter
altReceiveCounter = -1;
boolean isFirstIf = true;
for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) {
AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i);
if (currentAltGuard instanceof Operation_Altguard) {
Statement currentStatement = ((Operation_Altguard) currentAltGuard).getGuardStatement();
StatementBlock currentStatementBlock = ((Operation_Altguard) currentAltGuard).getStatementBlock();
if (isFirstIf) {
altString.append("if(" + positiveConditions[i] + "){\r\n");
isFirstIf = false;
} else {
altString.append("else if(" + positiveConditions[i] + "){\r\n");
}
if (currentStatement instanceof Receive_Port_Statement) {
altReceiveCounter++;
altString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n");
if (altGuardReceiveType.get(altReceiveCounter).equals("noparam")) {
altString.append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + "\", true);" + "\r\n");
} else if (altGuardReceiveType.get(altReceiveCounter).equals("Templates")) {
String methodName = altGuardReceiveValue.get(altReceiveCounter);
if (methodName.endsWith("()") && methodName.startsWith("Templates.")) {
methodName = (String) methodName.subSequence(10, methodName.length() - 2);
}
altString.append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ":\\n " + methodName + ":=\" + " + altGuardReceiveValue.get(altReceiveCounter) + ".toString(), true);" + "\r\n");
} else if (altGuardReceiveType.get(altReceiveCounter).equals("any port")) {
altString.append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port any port\", true);" + "\r\n");
} else if (altGuardReceiveType.get(altReceiveCounter).equals("_TYPED_PARAM_")) {
altString.append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ": type " + altGuardReceiveValue.get(altReceiveCounter) + "\", true);" + "\r\n");
} else {
if (altGuardReceiveValue.get(altReceiveCounter) != null) {
altString.append(" TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ":\" + " + altGuardReceiveValue.get(altReceiveCounter) + ".toString(), true);" + "\r\n");
}
}
} else if (currentStatement instanceof Timeout_Statement) {
altString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n" + "TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"Timeout on timer " + currentTimerName + ".\", false);" + "\r\n");
}
boolean isThereARepeatStatement = false;
for (int j = 0; j < currentStatementBlock.getSize(); j++) {
Statement currentStatementBlockStatement = currentStatementBlock.getStatementByIndex(j);
if (currentStatementBlockStatement instanceof Setverdict_Statement) {
Setverdict_Statement setVerdictStatement = (Setverdict_Statement) currentStatementBlockStatement;
String verdict = "";
if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) {
Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement.getVerdictValue();
if (verdictValue.getValue().toString().equals("PASS")) {
verdict = "pass";
} else if (verdictValue.getValue().toString().equals("INCONC")) {
verdict = "inconc";
} else {
verdict = "fail";
}
}
altString.append("rownum=" + setVerdictStatement.getLocation().getLine() + ";\r\n");
altString.append("TTCN3Logger.writeLog(compid, \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"setverdict(" + verdict + "): \" + getVerdict() + \" -> " + verdict + "\", true);" + "\r\n");
altString.append("setVerdict(\"" + verdict + "\");" + "\r\n");
}
if (currentStatementBlockStatement instanceof Assignment_Statement) {
if (isFunction) {
functionParent.assignCounter++;
altString.append(functionParent.writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement));
String test = "";
test.toString();
} else if (isTestCase) {
testcaseParent.assignCounter++;
altString.append(testcaseParent.writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement));
}
}
if (currentStatementBlockStatement instanceof Send_Statement) {
if (isFunction) {
functionParent.sendCounter++;
altString.append(functionParent.writeSendStatement((Send_Statement) currentStatementBlockStatement));
} else if (isTestCase) {
testcaseParent.sendCounter++;
altString.append(testcaseParent.writeSendStatement((Send_Statement) currentStatementBlockStatement));
}
}
if (currentStatementBlockStatement instanceof Repeat_Statement) {
isThereARepeatStatement = true;
}
}
if (isThereARepeatStatement) {
isThereARepeatStatement = false;
} else {
altString.append("break;\r\n");
}
altString.append("}\r\n");
}
}
altString.append("this.unlock();" + "\r\n");
altString.append("}" + "\r\n");
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class Def_Function_Writer method writeFunction.
public void writeFunction(StatementBlock statementBlock) {
for (int i = 0; i < statementBlock.getSize(); i++) {
if (statementBlock.getStatementByIndex(i) instanceof Definition_Statement) {
writeDefinitionStatement((Definition_Statement) statementBlock.getStatementByIndex(i));
} else if (statementBlock.getStatementByIndex(i) instanceof Assignment_Statement) {
assignCounter++;
functionString.append(writeAssignmentStatement((Assignment_Statement) statementBlock.getStatementByIndex(i)));
} else if (statementBlock.getStatementByIndex(i) instanceof Assignment_Statement) {
Assignment_Statement tc_assignStatement = (Assignment_Statement) statementBlock.getStatementByIndex(i);
assignCounter++;
functionString.append(writeAssignmentStatement(tc_assignStatement));
} else if (statementBlock.getStatementByIndex(i) instanceof Send_Statement) {
sendCounter++;
functionString.append(writeSendStatement((Send_Statement) statementBlock.getStatementByIndex(i)));
} else if (statementBlock.getStatementByIndex(i) instanceof Unknown_Start_Statement) {
startCounter++;
writeUnknownStartStatement((Unknown_Start_Statement) statementBlock.getStatementByIndex(i));
} else if (statementBlock.getStatementByIndex(i) instanceof Alt_Statement) {
altStatementCounter++;
altStatements.get(altStatementCounter).setTimerInfo(isThereAStartedTimer, currentTimerName);
functionString.append(altStatements.get(altStatementCounter).getJavaSource());
} else if (statementBlock.getStatementByIndex(i) instanceof Setverdict_Statement) {
writeSetVerdictStatement((Setverdict_Statement) statementBlock.getStatementByIndex(i));
} else if (statementBlock.getStatementByIndex(i) instanceof DoWhile_Statement) {
doWhileCounter++;
DoWhile_Statement doWhileStatement = (DoWhile_Statement) statementBlock.getStatementByIndex(i);
String test = doWhileStatement.getExpression().toString();
functionString.append("do{" + "\r\n");
this.writeFunction(doWhileStatement.getStatementBlock());
functionString.append("}while(" + doWhileExpressions.get(doWhileCounter) + ".getValue());\r\n");
}
}
if (returnStatementValue != null) {
functionString.append("return " + returnStatementValue + ";\r\n");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class TestcasenameExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
// unqualified name or "".
if (myScope != null) {
if (myScope instanceof StatementBlock) {
final StatementBlock block = (StatementBlock) myScope;
final Definition definition = block.getMyDefinition();
if (definition == null) {
// An error would be better here.
lastValue = new Charstring_Value("");
lastValue.copyGeneralProperties(this);
} else {
if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
}
}
// Run-time evaluation.
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class AssignmentHandlerAFTRerences method visit.
@Override
public int visit(final IVisitableNode node) {
if (node instanceof ASN1Assignment) {
final ASN1Assignment assignment = (ASN1Assignment) node;
if (assignment.getAssPard() != null) {
return V_SKIP;
}
}
if (node instanceof StatementBlock) {
final ReferenceCollector referenceCollector = new ReferenceCollector();
node.accept(referenceCollector);
// TODO: broken if reference does not point anywhere
final Set<Reference> references = referenceCollector.getReferences();
addNonContagiousReferences(computeReferences(references));
if (containsErroneousReference(references)) {
setIsInfected(true);
}
return V_SKIP;
}
if (node instanceof Reference) {
final Identifier identifier = ((Reference) node).getId();
if (identifier != null) {
addContagiousReference(identifier.getDisplayName());
}
if (((Reference) node).getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
setIsInfected(true);
setIsContagious(true);
return V_CONTINUE;
}
final Assignment assignment = ((Reference) node).getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false, null);
if (assignment == null || assignment.getIdentifier() == null || !assignment.getIdentifier().equals(identifier)) {
setIsInfected(true);
setIsContagious(true);
return V_CONTINUE;
}
}
return V_CONTINUE;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.
the class Macro_Value method evaluateMacro.
/**
* Evaluates the value of the macro.
*
* @param expectedValue the kind of the value to be expected
*
* @return the actual or the evaluated value
*/
private IValue evaluateMacro(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
lastTimeChecked = timestamp;
lastValue = this;
switch(value) {
case MODULEID:
if (myScope != null && myScope.getModuleScope() != null) {
final Module module = myScope.getModuleScope();
if (module.getIdentifier() != null) {
lastValue = new Charstring_Value(module.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
break;
case DEFINITIONID:
if (myScope != null) {
final StatementBlock block = myScope.getStatementBlockScope();
if (block != null) {
final Definition definition = block.getMyDefinition();
if (definition != null) {
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
} else {
setIsErroneous(true);
}
break;
case TESTCASEID:
if (myScope != null) {
final StatementBlock block = myScope.getStatementBlockScope();
if (block != null) {
final Definition definition = block.getMyDefinition();
if (definition == null) {
location.reportSemanticError(TESCASEIDINCONTROLPART);
setIsErroneous(true);
} else {
if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
// folding is possible in testcases only
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
} else {
location.reportSemanticError(TESTCASEIDNOTALLOWED);
setIsErroneous(true);
}
} else {
setIsErroneous(true);
}
break;
case FILENAME:
case BFILENAME:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Charstring_Value(location.getFile().getName());
lastValue.copyGeneralProperties(this);
}
break;
case FILEPATH:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
String canonicalPath;
final IPath absolutePath = location.getFile().getLocation();
if (absolutePath == null) {
location.reportSemanticError(UNDETERMINABLEPATH);
canonicalPath = location.getFile().getName();
setIsErroneous(true);
} else {
final File file = absolutePath.toFile();
try {
canonicalPath = file.getCanonicalPath();
} catch (IOException e) {
location.reportSemanticError(UNDETERMINABLEPATH);
canonicalPath = location.getFile().getName();
setIsErroneous(true);
}
}
lastValue = new Charstring_Value(canonicalPath);
lastValue.copyGeneralProperties(this);
}
break;
case LINENUMBER:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Charstring_Value(Long.toString(location.getLine()));
lastValue.copyGeneralProperties(this);
}
break;
case LINENUMBER_C:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Integer_Value(location.getLine());
lastValue.copyGeneralProperties(this);
}
break;
case SCOPE:
if (myScope != null) {
lastValue = new Charstring_Value(myScope.getScopeMacroName());
lastValue.copyGeneralProperties(this);
} else {
location.reportSemanticError(UNDETERMINABLESCOPE);
setIsErroneous(true);
}
break;
default:
setIsErroneous(true);
}
return lastValue;
}
Aggregations