use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class ExecuteExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final Assignment testcase = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
expression.expression.append(MessageFormat.format("{0}(", testcase.getGenNameFromScope(aData, expression.expression, myScope, "testcase_")));
final List<ISubReference> subReferences = reference.getSubreferences();
if (!subReferences.isEmpty() && subReferences.get(0) instanceof ParameterisedSubReference) {
final ActualParameterList actualParList = ((ParameterisedSubReference) subReferences.get(0)).getActualParameters();
if (actualParList.getNofParameters() > 0) {
actualParList.generateCodeAlias(aData, expression);
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 ) ))");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class IsValueExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final TTCN3Template templateBody = templateInstance.getTemplateBody();
// FIXME actually a bit more complex
if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
final IValue value = ((SpecificValue_Template) templateBody).getValue();
// FIXME implement support for cast
value.generateCodeExpression(aData, expression, true);
} else {
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(".isValue()");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class LengthofExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final TTCN3Template templateBody = templateInstance.getTemplateBody();
// FIXME actually a bit more complex
if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
final IValue value = ((SpecificValue_Template) templateBody).getValue();
// FIXME implement support for cast
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(".lengthOf()");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class NotequalesExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
// TODO actually a bit more complicated
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) {
expression.expression.append("!(");
value1.generateCodeExpression(aData, expression, true);
expression.expression.append(".operatorEquals( ");
value2.generateCodeExpression(aData, expression, true);
expression.expression.append(" ))");
} else if (isOptional2) {
expression.expression.append("!(");
value2.generateCodeExpression(aData, expression, true);
expression.expression.append(".operatorEquals( ");
value1.generateCodeExpression(aData, expression, true);
expression.expression.append(" ))");
} else {
expression.expression.append("!(");
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 TTCN3_Choice_Type method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenNameOwn();
final String displayName = getFullName();
generateCodeTypedescriptor(aData, source);
final List<FieldInfo> fieldInfos = new ArrayList<FieldInfo>();
boolean hasOptional = false;
for (final CompField compField : compFieldMap.fields) {
final IType cfType = compField.getType();
final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
hasOptional |= compField.isOptional();
fieldInfos.add(fi);
}
for (final CompField compField : compFieldMap.fields) {
final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
compField.getType().generateCode(aData, tempSource);
}
final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
RawASTStruct raw = null;
if (hasRaw) {
RawAST dummy_raw;
if (rawAttribute == null) {
dummy_raw = new RawAST(getDefaultRawFieldLength());
} else {
dummy_raw = rawAttribute;
}
raw = new RawASTStruct(dummy_raw);
// building taglist
final int taglistSize = dummy_raw.taglist == null ? 0 : dummy_raw.taglist.size();
for (int c = 0; c < taglistSize; c++) {
final rawAST_single_tag singleTag = dummy_raw.taglist.get(c);
final rawAST_coding_taglist codingSingleTag = raw.taglist.list.get(c);
if (singleTag.keyList != null) {
codingSingleTag.fields = new ArrayList<RawASTStruct.rawAST_coding_field_list>(singleTag.keyList.size());
}
codingSingleTag.fieldname = singleTag.fieldName.getName();
codingSingleTag.varName = FieldSubReference.getJavaGetterName(codingSingleTag.fieldname);
final Identifier idf = singleTag.fieldName;
codingSingleTag.fieldnum = getComponentIndexByName(idf);
final int keyListSize = singleTag.keyList == null ? 0 : singleTag.keyList.size();
for (int a = 0; a < keyListSize; a++) {
final rawAST_tag_field_value key = singleTag.keyList.get(a);
final RawASTStruct.rawAST_coding_field_list codingKey = new RawASTStruct.rawAST_coding_field_list();
codingSingleTag.fields.add(codingKey);
codingKey.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(key.keyField.names.size());
// codingKey.value = key.value;
final ExpressionStruct expression = new ExpressionStruct();
key.v_value.generateCodeExpression(aData, expression, true);
codingKey.expression = expression;
codingKey.isOmitValue = key.v_value.getValuetype() == Value_type.OMIT_VALUE;
codingKey.start_pos = 0;
final CompField cf = getComponentByIndex(codingSingleTag.fieldnum);
IType t = cf.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final RawASTStruct.rawAST_coding_fields tempField = new rawAST_coding_fields();
tempField.nthfield = codingSingleTag.fieldnum;
tempField.nthfieldname = singleTag.fieldName.getName();
tempField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
tempField.type = t.getGenNameValue(aData, source, myScope);
tempField.typedesc = t.getGenNameTypeDescriptor(aData, source, myScope);
codingKey.fields.add(tempField);
for (int b = 0; b < key.keyField.names.size(); b++) {
final RawASTStruct.rawAST_coding_fields newField = new rawAST_coding_fields();
codingKey.fields.add(newField);
final Identifier idf2 = key.keyField.names.get(b);
int comp_index = 0;
CompField cf2;
switch(t.getTypetype()) {
case TYPE_TTCN3_CHOICE:
comp_index = ((TTCN3_Choice_Type) t).getComponentIndexByName(idf2);
cf2 = ((TTCN3_Choice_Type) t).getComponentByIndex(comp_index);
newField.nthfield = comp_index;
newField.nthfieldname = idf2.getName();
newField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
break;
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentIndexByName(idf2);
cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentByIndex(comp_index);
newField.nthfield = comp_index;
newField.nthfieldname = idf2.getName();
if (cf2.isOptional()) {
newField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
} else {
newField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
}
break;
default:
// internal error
return;
}
final IType field_type = cf2.getType();
newField.type = field_type.getGenNameValue(aData, source, myScope);
newField.typedesc = field_type.getGenNameTypeDescriptor(aData, source, myScope);
if (field_type.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE && ((TTCN3_Sequence_Type) field_type).rawAttribute != null && (((TTCN3_Sequence_Type) field_type).rawAttribute.pointerto == null || ((TTCN3_Sequence_Type) field_type).rawAttribute.lengthto != null)) {
codingKey.start_pos = -1;
}
if (t.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE) {
IType t2;
for (int i = 0; i < comp_index && codingKey.start_pos >= 0; i++) {
t2 = ((TTCN3_Sequence_Type) t).getComponentByIndex(i).getType();
if (t2.getRawLength() >= 0) {
if (((Type) t2).rawAttribute != null) {
codingKey.start_pos += ((Type) t2).rawAttribute.padding;
}
codingKey.start_pos += ((Type) t2).getRawLength();
} else {
codingKey.start_pos = -1;
}
}
}
t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
}
}
}
}
UnionGenerator.generateValueClass(aData, source, genName, displayName, fieldInfos, hasOptional, hasRaw, raw);
UnionGenerator.generateTemplateClass(aData, source, genName, displayName, fieldInfos, hasOptional);
if (hasDoneAttribute()) {
generateCodeDone(aData, source);
}
if (subType != null) {
subType.generateCode(aData, source);
}
generateCodeForCodingHandlers(aData, source);
}
Aggregations