use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Altstep_Applied_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expression = new ExpressionStruct();
final IValue last = dereferredValue.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (last.getValuetype().equals(Value_type.ALTSTEP_REFERENCE_VALUE)) {
// TODO Optimize for easily resolvable value
}
dereferredValue.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".invoke_standalone(");
if (actualParameterList2 != null && actualParameterList2.getNofParameters() > 0) {
actualParameterList2.generateCodeAlias(aData, expression);
}
expression.expression.append(')');
expression.mergeExpression(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Type method generateCodeIspresentBound_forStrings.
/**
* Generates type specific call for the reference used in isbound call
* into argument expression. Argument \a subrefs holds the reference path
* that needs to be checked. Argument \a module is the actual module of
* the reference and is used to gain access to temporal identifiers.
*
* This version should only be called from string types.
* It only serves to save from copy-paste -ing the same code to every string type class.
* generate_code_ispresentbound in the compiler
*
* @param aData only used to update imports if needed
* @param expression the expression for code generation
* @param subreferences the subreference to process
* @param subReferenceIndex the index telling which part of the subreference to process
* @param globalId is the name of the bool variable where the result
* of the isbound check is calculated.
* @param externalId is the name
* of the assignment where the call chain starts.
* @param isTemplate is_template tells if the assignment is a template or not.
* @param isBound tells if the function is isbound or ispresent.
*/
protected void generateCodeIspresentBound_forStrings(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, final String field) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return;
}
if (subReferenceIndex >= subreferences.size()) {
return;
}
if (isTemplate) {
// FIXME handle template
expression.expression.append("//TODO: template handling in");
expression.expression.append(getClass().getSimpleName());
expression.expression.append(".generateCodeIspresentBound() is not be implemented yet!\n");
}
final ISubReference subReference = subreferences.get(subReferenceIndex);
if (!(subReference instanceof ArraySubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return;
}
final Value indexValue = ((ArraySubReference) subReference).getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = indexValue.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
final String temporalIndexId = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("TitanInteger {0} = ", temporalIndexId));
last.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(";\n");
expression.expression.append(MessageFormat.format("{0} = {1}.isGreaterThanOrEqual(0) && {1}.isLessThan({2}.lengthOf());\n", globalId, temporalIndexId, externalId));
final String temporalId = aData.getTemporaryVariableName();
final boolean isLast = subReferenceIndex == (subreferences.size() - 1);
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
if (optype == Operation_type.ISBOUND_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.constGetAt({2}).isBound();\n", globalId, externalId, temporalIndexId));
} else if (optype == Operation_type.ISPRESENT_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.constGetAt({2}).{3}({4});\n", globalId, externalId, temporalIndexId, (!isLast) ? "isBound" : "isPresent", isLast && isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
}
generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId, isTemplate, optype, field);
expression.expression.append("}\n}\n");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class RefersExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
if (governor == null || referredAssignment == null) {
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
return;
}
final IType lastGovernor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final String moduleName = referredAssignment.getMyScope().getModuleScope().getName();
final String functionName = referredAssignment.getIdentifier().getName();
expression.expression.append(MessageFormat.format("new {0}(new {0}.function_pointer() '{'\n", governor.getGenNameValue(aData, expression.expression, myScope)));
expression.expression.append("@Override\n");
expression.expression.append("public String getModuleName() {\n");
expression.expression.append(MessageFormat.format("return \"{0}\";\n", moduleName));
expression.expression.append("}\n");
expression.expression.append("@Override\n");
expression.expression.append("public String getDefinitionName() {\n");
expression.expression.append(MessageFormat.format("return \"{0}\";\n", functionName));
expression.expression.append("}\n");
if (lastGovernor.getTypetype().equals(Type_type.TYPE_FUNCTION)) {
expression.expression.append("@Override\n");
expression.expression.append("public ");
final Function_Type functionType = (Function_Type) lastGovernor;
final Type returnType = functionType.getReturnType();
final StringBuilder actualParList = functionType.getFormalParameters().generateCodeActualParlist("");
if (returnType == null) {
expression.expression.append("void");
} else {
if (functionType.returnsTemplate()) {
expression.expression.append(returnType.getGenNameTemplate(aData, expression.expression, myScope));
} else {
expression.expression.append(returnType.getGenNameValue(aData, expression.expression, myScope));
}
}
expression.expression.append(" invoke(");
functionType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
if (returnType != null) {
expression.expression.append("return ");
}
expression.expression.append(referredAssignment.getIdentifier().getName());
expression.expression.append('(');
expression.expression.append(actualParList);
expression.expression.append(");\n");
expression.expression.append("}\n");
if (functionType.isStartable(CompilationTimeStamp.getBaseTimestamp())) {
aData.addBuiltinTypeImport("TitanComponent");
expression.expression.append("@Override\n");
expression.expression.append("public void start(final TitanComponent component_reference");
if (functionType.getFormalParameters().getNofParameters() > 0) {
expression.expression.append(", ");
functionType.getFormalParameters().generateCode(aData, expression.expression);
}
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("{0}.start_{1}(component_reference", moduleName, functionName));
if (actualParList != null && actualParList.length() > 0) {
expression.expression.append(MessageFormat.format(", {0}", actualParList));
}
expression.expression.append(");\n");
expression.expression.append("}\n");
}
} else if (lastGovernor.getTypetype().equals(Type_type.TYPE_ALTSTEP)) {
aData.addBuiltinTypeImport("Default_Base");
aData.addBuiltinTypeImport("TitanAlt_Status");
final Altstep_Type altstepType = (Altstep_Type) lastGovernor;
final String altstepName = referredAssignment.getIdentifier().getName();
final StringBuilder actualParList = altstepType.getFormalParameters().generateCodeActualParlist("");
expression.expression.append("@Override\n");
expression.expression.append("public void invoke_standalone(");
altstepType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("{0}({1});\n", altstepName, actualParList));
expression.expression.append("}\n");
expression.expression.append("@Override\n");
expression.expression.append("public Default_Base activate(");
altstepType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("return activate_{0}({1});\n", altstepName, actualParList));
expression.expression.append("}\n");
expression.expression.append("@Override\n");
expression.expression.append("public TitanAlt_Status invoke(");
altstepType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("return {0}_instance({1});\n", altstepName, actualParList));
expression.expression.append("}\n");
} else if (lastGovernor.getTypetype().equals(Type_type.TYPE_TESTCASE)) {
aData.addBuiltinTypeImport("TitanVerdictType");
aData.addBuiltinTypeImport("TitanFloat");
expression.expression.append("@Override\n");
expression.expression.append("public ");
final Testcase_Type testcaseType = (Testcase_Type) lastGovernor;
expression.expression.append("TitanVerdictType");
expression.expression.append(" execute(");
if (testcaseType.getFormalParameters().getNofParameters() > 0) {
testcaseType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(", ");
}
expression.expression.append("boolean has_timer, TitanFloat timer_value");
expression.expression.append(") {\n");
expression.expression.append("return testcase_");
expression.expression.append(referredAssignment.getIdentifier().getName());
expression.expression.append('(');
if (testcaseType.getFormalParameters().getNofParameters() > 0) {
expression.expression.append(testcaseType.getFormalParameters().generateCodeActualParlist(""));
expression.expression.append(", ");
}
expression.expression.append("has_timer, timer_value");
expression.expression.append(");\n");
expression.expression.append("}\n");
}
expression.expression.append("})\n");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class EqualsExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
// TODO actually a bit more complicated
// TODO maybe this can be optimized later
boolean isOptional1 = false;
boolean isOptional2 = false;
final IValue temp = value1.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
if (temp instanceof Omit_Value) {
isOptional1 = true;
} else if (temp instanceof Referenced_Value) {
final Reference reference = ((Referenced_Value) temp).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
isOptional1 = true;
}
}
final IValue temp2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
if (temp2 instanceof Omit_Value) {
isOptional2 = true;
} else if (temp2 instanceof Referenced_Value) {
final Reference reference = ((Referenced_Value) temp2).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
isOptional2 = true;
}
}
if (isOptional1) {
value1.generateCodeExpression(aData, expression, true);
expression.expression.append(".operatorEquals( ");
value2.generateCodeExpression(aData, expression, true);
expression.expression.append(" )");
} else if (isOptional2) {
value2.generateCodeExpression(aData, expression, true);
expression.expression.append(".operatorEquals( ");
value1.generateCodeExpression(aData, expression, true);
expression.expression.append(" )");
} else {
value1.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".operatorEquals( ");
value2.generateCodeExpressionMandatory(aData, expression, false);
expression.expression.append(" )");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class ExecuteDereferedExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), chain);
chain.release();
if (last.getValuetype() == Value_type.TESTCASE_REFERENCE_VALUE) {
// the referred testcase is known
final Def_Testcase testcase = ((Testcase_Reference_Value) last).getReferredTestcase();
expression.expression.append(MessageFormat.format("{0}(", testcase.getGenNameFromScope(aData, expression.expression, myScope, "testcase_")));
actualParameters.generateCodeAlias(aData, expression);
} else {
// the referred testcase is unknown
value.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".execute(");
actualParameters.generateCodeAlias(aData, expression);
}
if (actualParameters.getNofParameters() > 0) {
expression.expression.append(", ");
}
if (timerValue != null) {
expression.expression.append("true, ");
timerValue.generateCodeExpression(aData, expression, true);
expression.expression.append(')');
} else {
expression.expression.append("false, new TitanFloat( new Ttcn3Float( 0.0 ) ))");
}
}
Aggregations