use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class ReplaceExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
if (lastValue != null && lastValue != this) {
lastValue.generateCodeExpression(aData, expression, true);
return;
}
final IValue lastValue2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
final IValue lastValue3 = value3.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
// TODO handle the needs conversion case
final Type_type expressionType = templateInstance1.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
switch(expressionType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
aData.addCommonLibraryImport("AdditionalFunctions");
expression.expression.append("AdditionalFunctions.replace( ");
templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(", ");
if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
lastValue2.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue2).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
lastValue3.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue3).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(')');
break;
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
// TODO: need to test
templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(".replace( ");
if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
lastValue2.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue2).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
lastValue3.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue3).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(')');
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method generateCodeInitMandatory.
@Override
public /**
* {@inheritDoc}
*/
StringBuilder generateCodeInitMandatory(final JavaGenData aData, final StringBuilder source, final String name) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last == this) {
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(name);
expression.expression.append(".assign(");
reference.generateConstRef(aData, expression);
generateCodeExpressionOptionalFieldReference(aData, expression, reference);
expression.expression.append(")");
expression.mergeExpression(source);
return source;
}
// the code generation is based on the referred value
if (last.canGenerateSingleExpression() && myScope.getModuleScope() == last.getMyScope().getModuleScope()) {
// simple substitution for in-line values within the same module
source.append(MessageFormat.format("{0}.assign({1});\n", name, last.generateSingleExpression(aData)));
} else {
// TODO might need initialization see needs_init_precede
// TODO Value.cc:generate_code_init_refd
source.append(MessageFormat.format("{0}.assign({1});\n", name, last.getGenNameOwn(myScope)));
}
return source;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method generateSingleExpression.
@Override
public /**
* {@inheritDoc}
*/
StringBuilder generateSingleExpression(final JavaGenData aData) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last != this && last.canGenerateSingleExpression() && last.getMyScope().getModuleScope() == myScope.getModuleScope()) {
return last.generateSingleExpression(aData);
}
final ExpressionStruct expression = new ExpressionStruct();
reference.generateConstRef(aData, expression);
return expression.expression;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Expression_Value method generateCodeExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final boolean forceObject) {
if (lastValue != null && lastValue != this) {
lastValue.generateCodeExpression(aData, expression, forceObject);
return;
}
if (canGenerateSingleExpression()) {
if (returnsNative() && forceObject) {
final IType gov = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
expression.expression.append(MessageFormat.format("new {0}(", gov.getGenNameValue(aData, new StringBuilder(), myScope)));
expression.expression.append(generateSingleExpression(aData));
expression.expression.append(")");
} else {
expression.expression.append(generateSingleExpression(aData));
}
return;
}
if (returnsNative() && forceObject) {
final ExpressionStruct tempExpression = new ExpressionStruct();
generateCodeExpressionExpression(aData, tempExpression);
final IType gov = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
expression.preamble.append(tempExpression.preamble);
expression.expression.append(MessageFormat.format("new {0}(", gov.getGenNameValue(aData, new StringBuilder(), myScope)));
expression.expression.append(tempExpression.expression);
expression.expression.append(")");
} else {
generateCodeExpressionExpression(aData, expression);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class ActivateDereferedExpression 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.ALTSTEP_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, "activate_")));
} else {
// the referred testcase is unknown
value.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".activate(");
}
actualParameters.generateCodeAlias(aData, expression);
expression.expression.append(')');
}
Aggregations