use of org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct in project titan.EclipsePlug-ins by eclipse.
the class RecordSetCodeGenerator method set_raw_options.
// FIXME comment
private static void set_raw_options(final boolean isSet, final List<FieldInfo> fieldInfos, final boolean hasRaw, final RawASTStruct raw, final ArrayList<raw_option_struct> raw_options, final AtomicBoolean hasLengthto, final AtomicBoolean hasPointer, final AtomicBoolean hasCrosstag, final AtomicBoolean has_ext_bit) {
for (int i = 0; i < fieldInfos.size(); i++) {
final raw_option_struct tempRawOption = new raw_option_struct();
raw_options.add(tempRawOption);
tempRawOption.lengthto = false;
tempRawOption.lengthof = 0;
tempRawOption.lengthofField = null;
tempRawOption.pointerto = false;
tempRawOption.pointerof = 0;
tempRawOption.ptrbase = false;
tempRawOption.extbitgroup = 0;
tempRawOption.tag_type = 0;
tempRawOption.delayedDecode = false;
tempRawOption.dependentFields = null;
}
hasLengthto.set(false);
hasPointer.set(false);
hasCrosstag.set(false);
has_ext_bit.set(hasRaw && raw.extension_bit != RawASTStruct.XDEFNO && raw.extension_bit != RawASTStruct.XDEFDEFAULT);
for (int i = 0; i < fieldInfos.size(); i++) {
if (fieldInfos.get(i).hasRaw && fieldInfos.get(i).raw.crosstaglist != null) {
hasCrosstag.set(true);
}
}
if (hasRaw) {
final int taglistSize = raw.taglist == null || raw.taglist.list == null ? 0 : raw.taglist.list.size();
for (int i = 0; i < taglistSize; i++) {
raw_options.get(raw.taglist.list.get(i).fieldnum).tag_type = i + 1;
}
final int extBitGroupsSize = raw.ext_bit_groups == null ? 0 : raw.ext_bit_groups.size();
for (int i = 0; i < extBitGroupsSize; i++) {
final rawAST_coding_ext_group tempExtGroup = raw.ext_bit_groups.get(i);
for (int k = tempExtGroup.from; k <= tempExtGroup.to; k++) {
raw_options.get(k).extbitgroup = i + 1;
}
}
}
for (int i = 0; i < fieldInfos.size(); i++) {
final FieldInfo tempFieldInfo = fieldInfos.get(i);
final int lengthSize = tempFieldInfo.raw == null || tempFieldInfo.raw.lengthto == null ? 0 : tempFieldInfo.raw.lengthto.size();
if (tempFieldInfo.hasRaw && lengthSize > 0) {
hasLengthto.set(true);
raw_options.get(i).lengthto = true;
for (int j = 0; j < lengthSize; j++) {
final int fieldIndex = tempFieldInfo.raw.lengthto.get(j);
final raw_option_struct tempOptions = raw_options.get(fieldIndex);
if (tempOptions.lengthofField == null) {
tempOptions.lengthofField = new ArrayList<Integer>();
}
tempOptions.lengthofField.add(i);
tempOptions.lengthof++;
}
}
if (tempFieldInfo.hasRaw && tempFieldInfo.raw.pointerto != -1) {
raw_options.get(i).pointerto = true;
raw_options.get(fieldInfos.get(i).raw.pointerto).pointerof = i + 1;
hasPointer.set(true);
raw_options.get(fieldInfos.get(i).raw.pointerbase).ptrbase = true;
}
}
if (!isSet && hasCrosstag.get()) {
for (int i = 0; i < fieldInfos.size(); i++) {
final FieldInfo tempFieldInfo = fieldInfos.get(i);
int maxIndex = i;
if (!tempFieldInfo.hasRaw) {
continue;
}
final int crosstagSize = tempFieldInfo.raw.crosstaglist == null || tempFieldInfo.raw.crosstaglist.list == null ? 0 : tempFieldInfo.raw.crosstaglist.list.size();
for (int j = 0; j < crosstagSize; j++) {
final rawAST_coding_taglist crosstag = tempFieldInfo.raw.crosstaglist.list.get(j);
final int fieldsSize = crosstag == null || crosstag.fields == null ? 0 : crosstag.fields.size();
for (int k = 0; k < fieldsSize; k++) {
final rawAST_coding_field_list keyid = crosstag.fields.get(k);
if (keyid.fields.size() >= 1) {
final int fieldIndex = keyid.fields.get(0).nthfield;
if (fieldIndex > maxIndex) {
maxIndex = fieldIndex;
}
}
}
}
if (maxIndex > i) {
raw_options.get(i).delayedDecode = true;
if (raw_options.get(maxIndex).dependentFields == null) {
raw_options.get(maxIndex).dependentFields = new ArrayList<Integer>();
}
raw_options.get(maxIndex).dependentFields.add(i);
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct in project titan.EclipsePlug-ins by eclipse.
the class RecordSetCodeGenerator method genRawDecodeRecordField.
/**
* This function generates the code for decoding a record field.
*
* @param aData only used to update imports if needed.
* @param source where the source code is to be generated.
* @param fieldInfos the list of field informations.
* @param i the index of the field to generate for.
* @param raw the raw attribute of the record/set.
* @param raw_options the pre-calculated raw options.
* @param delayed_decode true to generated for delayed decoding.
* @param prev_ext_group the index of the previous extension group.
*/
private static void genRawDecodeRecordField(final JavaGenData aData, final StringBuilder source, final List<FieldInfo> fieldInfos, final int i, final RawASTStruct raw, final ArrayList<raw_option_struct> raw_options, final boolean delayed_decode, final AtomicInteger prev_ext_group) {
final raw_option_struct tempRawOption = raw_options.get(i);
if (tempRawOption.ptrbase) {
source.append(MessageFormat.format("start_pos_of_field{0} = buff.get_pos_bit();\n", i));
}
if (prev_ext_group.get() != tempRawOption.extbitgroup) {
prev_ext_group.set(tempRawOption.extbitgroup);
if (prev_ext_group.get() > 0 && raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit != RawAST.XDEFNO) {
if (tempRawOption.pointerof > 0) {
final FieldInfo pointedField = fieldInfos.get(tempRawOption.pointerof - 1);
source.append("{\n");
source.append("int old_pos = buff.get_pos_bit();\n");
source.append(MessageFormat.format("if (start_of_field{0} != -1 && start_pos_of_field{1} != -1) '{'\n", i, pointedField.raw.pointerbase));
source.append(MessageFormat.format("start_of_field{0} = start_pos_of_field{1} + get{2}(){3}.getInt() * {4} + {5};\n", i, pointedField.raw.pointerbase, pointedField.mVarName, pointedField.isOptional ? ".get()" : "", pointedField.raw.unit, pointedField.raw.ptroffset));
source.append(MessageFormat.format("buff.set_pos_bit(start_of_field{0});\n", i));
source.append(MessageFormat.format("limit = end_of_available_data - start_of_field{0};\n", i));
}
source.append("{\n");
source.append("char[] data = buff.get_read_data();\n");
source.append("int count = 1;\n");
source.append("int rot = local_top_order == raw_order_t.ORDER_LSB ? 0: 7;\n");
source.append(MessageFormat.format("while (((data[count - 1] >> rot) & 0x01) == {0} && count * 8 < limit) '{'\n", raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit == RawAST.XDEFYES ? 0 : 1));
source.append("count++;\n");
source.append("}\n");
source.append(" if (limit > 0) {\n");
source.append("group_limit = count * 8;\n");
source.append("}\n");
source.append("}\n");
if (tempRawOption.pointerof > 0) {
source.append(" } else {\n");
source.append("group_limit = 0;\n");
source.append("}\n");
source.append("buff.set_pos_bit(old_pos);\n");
source.append("limit = end_of_available_data - old_pos;\n");
source.append("}\n");
}
}
}
final FieldInfo fieldInfo = fieldInfos.get(i);
final int crosstagsize = fieldInfo.raw == null || fieldInfo.raw.crosstaglist == null || fieldInfo.raw.crosstaglist.list == null ? 0 : fieldInfo.raw.crosstaglist.list.size();
if (crosstagsize > 0) {
int other = -1;
boolean first_value = true;
for (int j = 0; j < crosstagsize; j++) {
final rawAST_coding_taglist cur_choice = fieldInfo.raw.crosstaglist.list.get(j);
if (cur_choice.fields != null && cur_choice.fields.size() > 0) {
if (first_value) {
source.append("if (");
first_value = false;
} else {
source.append(" else if (");
}
genRawFieldChecker(source, cur_choice, true);
source.append(") {\n");
source.append(MessageFormat.format("selected_field = {0};\n", cur_choice.fieldnum));
source.append("}");
} else {
other = cur_choice.fieldnum;
}
}
source.append(" else {\n");
source.append(MessageFormat.format("selected_field = {0};\n", other));
source.append("}\n");
}
/* check the presence of optional field*/
if (fieldInfo.isOptional) {
/* check if enough bits to decode the field*/
source.append("if ( limit > 0");
for (int a = 0; a < tempRawOption.lengthof; a++) {
final int field_index = tempRawOption.lengthofField.get(a);
if (i > field_index) {
source.append(MessageFormat.format(" && value_of_length_field{0} > 0", field_index));
}
}
if (tempRawOption.extbitgroup > 0 && raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit != RawAST.XDEFNO) {
source.append(" && group_limit > 0");
}
if (tempRawOption.pointerof > 0) {
source.append(MessageFormat.format(" && start_of_field{0} != -1 && start_pos_of_field{1} != -1", i, fieldInfos.get(tempRawOption.pointerof - 1).raw.pointerbase));
}
final int presenceSize = fieldInfo.raw == null || fieldInfo.raw.presence == null || fieldInfo.raw.presence.fields == null ? 0 : fieldInfo.raw.presence.fields.size();
if (presenceSize > 0) {
source.append(" && ");
if (presenceSize > 1) {
source.append('(');
}
genRawFieldChecker(source, fieldInfo.raw.presence, true);
if (presenceSize > 1) {
source.append(')');
}
}
if (crosstagsize > 0) {
source.append("&& selected_field != -1");
}
source.append(") {\n");
}
if (tempRawOption.pointerof > 0) {
final FieldInfo tempPointed = fieldInfos.get(tempRawOption.pointerof - 1);
source.append(MessageFormat.format("start_of_field{0} = start_pos_of_field{1} + get{2}(){3}.getInt() * {4} + {5};\n", i, tempPointed.raw.pointerbase, tempPointed.mJavaVarName, tempPointed.isOptional ? ".get()" : "", tempPointed.raw.unit, tempPointed.raw.ptroffset));
source.append(MessageFormat.format("buff.set_pos_bit(start_of_field{0});\n", i));
source.append(MessageFormat.format("limit = end_of_available_data - start_of_field{0};\n", i));
}
if (fieldInfo.isOptional) {
source.append("int fl_start_pos = buff.get_pos_bit();\n");
}
final ExpressionStruct expression = new ExpressionStruct();
if (delayed_decode) {
/* the fixed field length is used as limit in case of delayed decoding */
expression.expression.append(fieldInfo.raw.length);
} else {
genRawFieldDecodeLimit(aData, expression, fieldInfos, i, raw, raw_options);
}
if (expression.preamble.length() > 0) {
source.append(expression.preamble);
}
source.append(MessageFormat.format("decoded_field_length = get{0}(){1}.RAW_decode({2}_descr_, buff, ", fieldInfo.mJavaVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.mTypeDescriptorName));
source.append(expression.expression);
source.append(MessageFormat.format(", local_top_order, {0}", fieldInfo.isOptional ? "true" : "no_err"));
if (crosstagsize > 0) {
source.append(", selected_field");
} else {
source.append(", -1");
}
boolean found = false;
for (int a = 0; a < tempRawOption.lengthof && !found; a++) {
final int field_index = tempRawOption.lengthofField.get(a);
if (fieldInfos.get(field_index).raw.unit == -1) {
source.append(MessageFormat.format(", value_of_length_field{0}", field_index));
found = true;
}
}
if (!found) {
source.append(", true");
}
source.append(");\n");
if (delayed_decode) {
source.append(MessageFormat.format("if ( decoded_field_length != {0}) '{'\n", fieldInfo.raw.length));
source.append("return -1;\n");
source.append("}\n");
} else if (fieldInfo.isOptional) {
source.append("if (decoded_field_length < 1) {\n");
source.append(MessageFormat.format("{0}.assign(template_sel.OMIT_VALUE);\n", fieldInfo.mVarName));
source.append("buff.set_pos_bit(fl_start_pos);\n");
source.append(" } else {\n");
} else {
source.append("if (decoded_field_length < 0) {\n");
source.append("return decoded_field_length;\n");
source.append("}\n");
}
if (tempRawOption.tag_type > 0 && raw.taglist.list.get(tempRawOption.tag_type - 1).fields.size() > 0) {
final rawAST_coding_taglist cur_choice = raw.taglist.list.get(tempRawOption.tag_type - 1);
source.append("if (");
genRawFieldChecker(source, cur_choice, false);
source.append(") {\n");
if (fieldInfo.isOptional) {
source.append(MessageFormat.format("{0}.assign(template_sel.OMIT_VALUE);\n", fieldInfo.mVarName));
source.append("buff.set_pos_bit(fl_start_pos);\n");
source.append(" } else {");
} else {
source.append("return -1;\n");
source.append("}\n");
}
}
if (!delayed_decode) {
source.append("decoded_length += decoded_field_length;\n");
source.append("limit -= decoded_field_length;\n");
source.append("last_decoded_pos = Math.max(last_decoded_pos, buff.get_pos_bit());\n");
}
if (tempRawOption.extbitgroup > 0 && raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit != RawAST.XDEFNO) {
source.append("group_limit -= decoded_field_length;\n");
}
if (tempRawOption.lengthto) {
if (fieldInfo.raw.lengthindex != null) {
if (fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD) {
source.append(MessageFormat.format("if ({0}{1}.get{2}().isPresent()) '{'\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthindex.nthfieldname));
}
if (fieldInfo.raw.lengthto_offset != 0) {
source.append(MessageFormat.format("{0}{1}.get{2}(){3}.assign({0}{1}.get{2}(){3} - {4});\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthindex.nthfieldname, fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD ? ".get()" : "", fieldInfo.raw.lengthto_offset));
}
source.append(MessageFormat.format("value_of_length_field{0} += {1}{2}.get{3}(){4}.getInt() * {5};\n", i, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthindex.nthfieldname, fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD ? ".get()" : "", fieldInfo.raw.unit == -1 ? 1 : fieldInfo.raw.unit));
if (fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD) {
source.append("}\n");
}
} else if (fieldInfo.raw.union_member_num > 0) {
source.append(MessageFormat.format("switch ({0}{1}.get_selection()) '{'\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : ""));
for (int m = 0; m < fieldInfo.raw.member_name.size(); m++) {
source.append(MessageFormat.format("case {0}.{1}", fieldInfo.raw.member_name.get(0), fieldInfo.raw.member_name.get(m)));
if (fieldInfo.raw.lengthto_offset != 0) {
source.append(MessageFormat.format("{0}{1}.get{2}().assign({0}{1}.get{2}() - {3});\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.member_name.get(m), fieldInfo.raw.lengthto_offset));
}
source.append(MessageFormat.format("value_of_length_field{0} += {1}{2}.get{3}().getInt() * {4};\n", i, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.member_name.get(m), fieldInfo.raw.unit == -1 ? 1 : fieldInfo.raw.unit));
source.append("break;\n");
}
source.append("default:\n");
source.append(MessageFormat.format("value_of_length_field{0} = 0;\n", i));
source.append("}\n");
} else {
if (fieldInfo.raw.lengthto_offset != 0) {
source.append(MessageFormat.format("{0}{1}.assign({0}{1}.getInt() - {2});\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthto_offset));
}
source.append(MessageFormat.format("value_of_length_field{0} += {1}{2}.getInt() * {3};\n", i, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.unit == -1 ? 1 : fieldInfo.raw.unit));
}
}
if (tempRawOption.pointerto) {
source.append(MessageFormat.format("start_of_field{0} = {1}{2}.getInt() {3};\n ", fieldInfo.raw.pointerto, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.ptroffset > 0 ? " + 1" : "- 1"));
}
if (!delayed_decode) {
/* mark the used bits in length area*/
for (int a = 0; a < tempRawOption.lengthof; a++) {
final int field_index = tempRawOption.lengthofField.get(a);
source.append(MessageFormat.format("value_of_length_field{0} -= decoded_field_length;\n", field_index));
if (i == field_index) {
source.append(MessageFormat.format("if (value_of_length_field{0} < 0) '{'\n", field_index));
source.append("return -1;\n");
source.append("}\n");
}
}
}
if (fieldInfo.isOptional) {
source.append("}\n");
source.append("}");
if (tempRawOption.tag_type > 0) {
source.append("\n}");
}
source.append(" else {\n");
source.append(MessageFormat.format("{0}.assign(template_sel.OMIT_VALUE);\n", fieldInfo.mVarName));
source.append("}\n");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Set_Type method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final String className = getGenNameOwn();
final String classReadableName = getFullName();
generateCodeTypedescriptor(aData, source);
final List<FieldInfo> namesList = 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(), compField.isOptional(), false, cfType.getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
hasOptional |= compField.isOptional();
namesList.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);
final RawASTStruct raw = convertRAWCodingAttributes(aData, source, hasRaw, namesList);
RecordSetCodeGenerator.generateValueClass(aData, source, className, classReadableName, namesList, hasOptional, true, hasRaw, raw);
RecordSetCodeGenerator.generateTemplateClass(aData, source, className, classReadableName, namesList, hasOptional, true);
if (hasDoneAttribute()) {
generateCodeDone(aData, source);
}
if (subType != null) {
subType.generateCode(aData, source);
}
generateCodeForCodingHandlers(aData, source);
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct 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);
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Sequence_Type method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final String className = getGenNameOwn();
final String classReadableName = getFullName();
generateCodeTypedescriptor(aData, source);
final List<FieldInfo> namesList = 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(), compField.isOptional(), false, cfType.getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
hasOptional |= compField.isOptional();
namesList.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);
final RawASTStruct raw = convertRAWCodingAttributes(aData, source, hasRaw, namesList);
RecordSetCodeGenerator.generateValueClass(aData, source, className, classReadableName, namesList, hasOptional, false, hasRaw, raw);
RecordSetCodeGenerator.generateTemplateClass(aData, source, className, classReadableName, namesList, hasOptional, false);
if (hasDoneAttribute()) {
generateCodeDone(aData, source);
}
if (subType != null) {
subType.generateCode(aData, source);
}
generateCodeForCodingHandlers(aData, source);
}
Aggregations