use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Trigger_Port_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expression = new ExpressionStruct();
generateCodeExpression(aData, expression);
PortGenerator.generateCodeStandalone(aData, source, expression.expression.toString(), getLocation());
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Def_Var method generateCodeString.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenName();
final String typeGeneratedName = type.getGenNameValue(aData, source, getMyScope());
if (type.getTypetype() == Type_type.TYPE_ARRAY) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sb = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sb);
}
if (initialValue != null && initialValue.canGenerateSingleExpression()) {
final ExpressionStruct expression = new ExpressionStruct();
initialValue.generateCodeExpressionMandatory(aData, expression, false);
if (initialValue.returnsNative() || initialValue.getValuetype() == Value_type.REFERENCED_VALUE || initialValue.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE || type.getTypetypeTtcn3() != initialValue.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE)) {
source.append(MessageFormat.format("{0} {1} = new {0}({2});\n", typeGeneratedName, genName, expression.expression));
} else {
source.append(MessageFormat.format("{0} {1} = {2};\n", typeGeneratedName, genName, expression.expression));
}
} else {
source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeGeneratedName, genName));
if (initialValue != null) {
initialValue.generateCodeInit(aData, source, genName);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method generateCodeString.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenName();
aData.addBuiltinTypeImport("TitanTimer");
if (defaultDuration != null) {
defaultDuration.setGenNameRecursive(getGenName());
}
if (dimensions == null) {
// single timer instance
if (defaultDuration == null) {
source.append("TitanTimer ");
source.append(genName);
source.append(" = new TitanTimer(\"");
source.append(identifier.getDisplayName());
source.append("\");\n");
} else {
if (defaultDuration.canGenerateSingleExpression()) {
// known in compile time
source.append("TitanTimer ");
source.append(genName);
source.append(" = new TitanTimer(\"");
source.append(identifier.getDisplayName());
source.append("\", ");
source.append(defaultDuration.generateSingleExpression(aData));
source.append(");\n");
} else {
source.append("TitanTimer ");
source.append(genName);
source.append(" = new TitanTimer(\"");
source.append(identifier.getDisplayName());
source.append("\");\n");
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(genName);
expression.expression.append(".setDefaultDuration(");
defaultDuration.generateCodeExpression(aData, expression, true);
expression.expression.append(')');
expression.mergeExpression(source);
}
}
} else {
final ArrayList<String> classNames = new ArrayList<String>();
aData.addBuiltinTypeImport("TitanTimerArray");
final StringBuilder sb = aData.getCodeForType(genName);
final String elementName = generateClassCode(aData, sb, classNames);
source.append(MessageFormat.format(" {0} {1} = new {0}();\n", elementName, genName));
if (defaultDuration != null) {
generateCodeArrayDuration(aData, source, genName, classNames, defaultDuration, 0);
}
source.append(genName).append(".setName(\"").append(identifier.getDisplayName()).append("\");\n");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method generateCodeArrayDuration.
private void generateCodeArrayDuration(final JavaGenData aData, final StringBuilder source, final String genName, final ArrayList<String> classNames, final Value defaultDuration2, final int startDim) {
final ArrayDimension dim = dimensions.get(startDim);
final int dim_size = (int) dim.getSize();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final Value v = (Value) defaultDuration2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (v.getValuetype() != Value_type.SEQUENCEOF_VALUE) {
// ErrorReporter.INTERNAL_ERROR()
return;
}
final SequenceOf_Value value = (SequenceOf_Value) v;
if (value.getNofComponents() != dim_size && !value.isIndexed()) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
return;
}
// Value-list notation.
if (!value.isIndexed()) {
if (startDim + 1 < dimensions.size()) {
// boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
for (int i = 0; i < dim_size; i++) {
// get_comp_byIndex(i);
final IValue v_elem = value.getValueByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final String embeddedName = MessageFormat.format("{0}.getAt({1})", genName, i + dim.getOffset());
generateCodeArrayDuration(aData, source, embeddedName, classNames, (Value) v_elem, startDim + 1);
}
} else {
// We are in the last dimension, the elements of "value" are floats.
for (int i = 0; i < dim_size; i++) {
final IValue v_elem = value.getValueByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(genName);
expression.expression.append(".getAt(").append(i + dim.getOffset()).append(")");
// originally set_default_duration(obj_name, i)
expression.expression.append(".assign(");
v_elem.generateCodeExpression(aData, expression, true);
expression.expression.append(')');
expression.mergeExpression(source);
}
}
// Indexed-list notation.
} else {
if (startDim + 1 < dimensions.size()) {
// boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
for (int i = 0; i < value.getNofComponents(); ++i) {
final IValue v_elem = value.getValueByIndex(i);
final IValue index = value.getIndexByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final String tempId1 = aData.getTemporaryVariableName();
final String tempIdX = aData.getTemporaryVariableName();
source.append("{\n");
source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
index.generateCodeInit(aData, source, tempIdX);
source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", classNames.get(classNames.size() - startDim - 2), tempId1, genName, tempIdX));
generateCodeArrayDuration(aData, source, tempId1, classNames, (Value) v_elem, startDim + 1);
source.append("}\n");
}
} else {
for (int i = 0; i < value.getNofComponents(); ++i) {
final IValue v_elem = value.getValueByIndex(i);
final IValue v_elemIndex = value.getIndexByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final ExpressionStruct expression = new ExpressionStruct();
final String tempIdX = aData.getTemporaryVariableName();
source.append("{\n");
source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
v_elemIndex.generateCodeInit(aData, source, tempIdX);
final String embeddedName = MessageFormat.format("{0}.getAt(", genName);
expression.expression.append(embeddedName).append(tempIdX).append(")");
// originally set_default_duration(obj_name, i)
expression.expression.append(".assign(");
v_elem.generateCodeExpression(aData, expression, true);
expression.expression.append(')');
expression.mergeExpression(source);
source.append("}\n");
}
}
}
return;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method generateCodeInitComp.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInitComp(final JavaGenData aData, final StringBuilder initComp, final Definition definition) {
if (defaultDuration == null) {
return;
}
if (!(definition instanceof Def_Timer)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
return;
}
final Def_Timer baseTimerDefinition = (Def_Timer) definition;
if (baseTimerDefinition.defaultDuration == null) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
return;
}
// constants in both timers
if (defaultDuration.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || baseTimerDefinition.defaultDuration.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || defaultDuration.checkEquality(CompilationTimeStamp.getBaseTimestamp(), baseTimerDefinition.defaultDuration)) {
if (dimensions == null) {
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(baseTimerDefinition.getGenNameFromScope(aData, initComp, myScope, ""));
expression.expression.append(".setDefaultDuration(");
defaultDuration.generateCodeExpression(aData, expression, true);
expression.expression.append(')');
expression.mergeExpression(initComp);
} else {
generateCodeArrayDuration(aData, initComp, baseTimerDefinition.getGenNameFromScope(aData, initComp, myScope, ""), new ArrayList<String>(), baseTimerDefinition.defaultDuration, 0);
}
}
}
Aggregations