Commit 1de26575 authored by Kristof Szabados's avatar Kristof Szabados
Browse files

fix for json shoosen coding issues.


Signed-off-by: Kristof Szabados's avatarKristof Szabados <Kristof.Szabados@ericsson.com>
parent 0627dfda
...@@ -43,7 +43,6 @@ import org.eclipse.titan.designer.AST.ASN1.Block; ...@@ -43,7 +43,6 @@ import org.eclipse.titan.designer.AST.ASN1.Block;
import org.eclipse.titan.designer.AST.ASN1.IASN1Type; import org.eclipse.titan.designer.AST.ASN1.IASN1Type;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type; import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.attributes.JsonAST; import org.eclipse.titan.designer.AST.TTCN3.attributes.JsonAST;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_taglist;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template; import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Template_type; import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Template_type;
import org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate; import org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate;
...@@ -1336,14 +1335,13 @@ public final class ASN1_Sequence_Type extends ASN1_Set_Seq_Choice_BaseType { ...@@ -1336,14 +1335,13 @@ public final class ASN1_Sequence_Type extends ASN1_Set_Seq_Choice_BaseType {
} }
final JsonAST jsonAttribute = cfType.getJsonAttribute(); final JsonAST jsonAttribute = cfType.getJsonAttribute();
final List<rawAST_coding_taglist> jsonChosen = jsonAttribute != null && jsonAttribute.tag_list != null ? new ArrayList<rawAST_coding_taglist>(jsonAttribute.tag_list) : null;
final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ), final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ),
cfType.getGenNameTemplate( aData, source ), cfType.getGenNameTemplate( aData, source ),
compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(),
ofType, cfType.getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source), ofType, cfType.getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source),
jsonAttribute != null ? jsonAttribute.metainfo_unbound : false, jsonAttribute != null ? jsonAttribute.metainfo_unbound : false,
jsonAttribute != null ? jsonAttribute.parsed_default_value : null, jsonAttribute != null ? jsonAttribute.parsed_default_value : null,
jsonChosen, null,
jsonAttribute != null ? jsonAttribute.alias : null, jsonAttribute != null ? jsonAttribute.alias : null,
jsonAttribute != null ? jsonAttribute.omit_as_null : false); jsonAttribute != null ? jsonAttribute.omit_as_null : false);
hasOptional |= compField.isOptional(); hasOptional |= compField.isOptional();
......
...@@ -43,7 +43,6 @@ import org.eclipse.titan.designer.AST.ASN1.Block; ...@@ -43,7 +43,6 @@ import org.eclipse.titan.designer.AST.ASN1.Block;
import org.eclipse.titan.designer.AST.ASN1.IASN1Type; import org.eclipse.titan.designer.AST.ASN1.IASN1Type;
import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type; import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.attributes.JsonAST; import org.eclipse.titan.designer.AST.TTCN3.attributes.JsonAST;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_taglist;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template; import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Template_type; import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Template_type;
import org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate; import org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate;
...@@ -1192,14 +1191,13 @@ public final class ASN1_Set_Type extends ASN1_Set_Seq_Choice_BaseType { ...@@ -1192,14 +1191,13 @@ public final class ASN1_Set_Type extends ASN1_Set_Seq_Choice_BaseType {
} }
final JsonAST jsonAttribute = cfType.getJsonAttribute(); final JsonAST jsonAttribute = cfType.getJsonAttribute();
final List<rawAST_coding_taglist> jsonChosen = jsonAttribute != null && jsonAttribute.tag_list != null ? new ArrayList<rawAST_coding_taglist>(jsonAttribute.tag_list) : null;
final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ), final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ),
cfType.getGenNameTemplate( aData, source ), cfType.getGenNameTemplate( aData, source ),
compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(),
ofType, compField.getType().getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source), ofType, compField.getType().getClass().getSimpleName(), cfType.getGenNameTypeDescriptor(aData, source),
jsonAttribute != null ? jsonAttribute.metainfo_unbound : false, jsonAttribute != null ? jsonAttribute.metainfo_unbound : false,
jsonAttribute != null ? jsonAttribute.parsed_default_value : null, jsonAttribute != null ? jsonAttribute.parsed_default_value : null,
jsonChosen, null,
jsonAttribute != null ? jsonAttribute.alias : null, jsonAttribute != null ? jsonAttribute.alias : null,
jsonAttribute != null ? jsonAttribute.omit_as_null : false); jsonAttribute != null ? jsonAttribute.omit_as_null : false);
hasOptional |= compField.isOptional(); hasOptional |= compField.isOptional();
......
...@@ -137,7 +137,7 @@ public class JsonAST { ...@@ -137,7 +137,7 @@ public class JsonAST {
public boolean as_number; public boolean as_number;
/** chosen fields for JSON encoding */ /** chosen fields for JSON encoding */
public List<rawAST_coding_taglist> tag_list; public List<RawAST.rawAST_single_tag> tag_list;
/** /**
* If set, encodes the value into a map of key-value pairs (i.e. a fully * If set, encodes the value into a map of key-value pairs (i.e. a fully
...@@ -168,7 +168,7 @@ public class JsonAST { ...@@ -168,7 +168,7 @@ public class JsonAST {
parsed_default_value = value.parsed_default_value; parsed_default_value = value.parsed_default_value;
metainfo_unbound = value.metainfo_unbound; metainfo_unbound = value.metainfo_unbound;
as_number = value.as_number; as_number = value.as_number;
tag_list = value.tag_list != null ? new ArrayList<rawAST_coding_taglist>(value.tag_list) : null; tag_list = value.tag_list != null ? new ArrayList<RawAST.rawAST_single_tag>(value.tag_list) : null;
as_map = value.as_map; as_map = value.as_map;
enum_texts = new ArrayList<JsonEnumText>(value.enum_texts); enum_texts = new ArrayList<JsonEnumText>(value.enum_texts);
schema_extensions = new ArrayList<JsonSchemaExtension>(value.schema_extensions); schema_extensions = new ArrayList<JsonSchemaExtension>(value.schema_extensions);
...@@ -262,6 +262,7 @@ public class JsonAST { ...@@ -262,6 +262,7 @@ public class JsonAST {
} }
} }
//FIXME system.out is unreliable for such purposes !
public void print_JsonAST() { public void print_JsonAST() {
System.out.printf("\n\rOmit encoding: "); System.out.printf("\n\rOmit encoding: ");
if (omit_as_null) { if (omit_as_null) {
...@@ -295,18 +296,18 @@ public class JsonAST { ...@@ -295,18 +296,18 @@ public class JsonAST {
System.out.printf(" Number of rules: %d\n\r", tag_list.size()); System.out.printf(" Number of rules: %d\n\r", tag_list.size());
for (int i = 0; i < tag_list.size(); ++i) { for (int i = 0; i < tag_list.size(); ++i) {
System.out.printf(" Rule #%d:\n\r", i); System.out.printf(" Rule #%d:\n\r", i);
System.out.printf(" Chosen field: %s\n\r", tag_list.get(i).fieldname != null ? System.out.printf(" Chosen field: %s\n\r", tag_list.get(i).fieldName != null ?
tag_list.get(i).fieldname : "omit"); tag_list.get(i).fieldName : "omit");
System.out.printf(" Number of conditions: %d\n\r", tag_list.get(i).fields.size()); System.out.printf(" Number of conditions: %d\n\r", tag_list.get(i).keyList.size());
for (int j = 0; j < tag_list.get(i).fields.size(); ++j) { for (int j = 0; j < tag_list.get(i).keyList.size(); ++j) {
System.out.printf(" Condition #%d:\n\r", j); System.out.printf(" Condition #%d:\n\r", j);
System.out.printf(" Value: %s\n\r", tag_list.get(i).fields.get(j).value); System.out.printf(" Value: %s\n\r", tag_list.get(i).keyList.get(j).value);
System.out.printf(" Field: "); System.out.printf(" Field: ");
for (int k = 0; k < tag_list.get(i).fields.get(j).fields.size(); ++k) { for (int k = 0; k < tag_list.get(i).keyList.get(j).keyField.names.size(); ++k) {
if (k != 0) { if (k != 0) {
System.out.printf("."); System.out.printf(".");
} }
System.out.printf("%s", tag_list.get(i).fields.get(j).fields.get(k).nthfieldname); System.out.printf("%s", tag_list.get(i).keyList.get(j).keyField.names.get(k).getName());
} }
System.out.printf("\n\r"); System.out.printf("\n\r");
} }
......
...@@ -1092,7 +1092,8 @@ public final class TTCN3_Sequence_Type extends TTCN3_Set_Seq_Choice_BaseType { ...@@ -1092,7 +1092,8 @@ public final class TTCN3_Sequence_Type extends TTCN3_Set_Seq_Choice_BaseType {
} }
final JsonAST jsonAttribute = cfType.getJsonAttribute(); final JsonAST jsonAttribute = cfType.getJsonAttribute();
final List<rawAST_coding_taglist> jsonChosen = jsonAttribute != null && jsonAttribute.tag_list != null ? new ArrayList<rawAST_coding_taglist>(jsonAttribute.tag_list) : null; List<rawAST_coding_taglist> jsonChosen = convertJsonCodingAttributes(jsonAttribute, aData, source, lastType);
final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ), final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ),
cfType.getGenNameTemplate( aData, source ), cfType.getGenNameTemplate( aData, source ),
compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(),
......
...@@ -921,7 +921,8 @@ public final class TTCN3_Set_Type extends TTCN3_Set_Seq_Choice_BaseType { ...@@ -921,7 +921,8 @@ public final class TTCN3_Set_Type extends TTCN3_Set_Seq_Choice_BaseType {
} }
final JsonAST jsonAttribute = cfType.getJsonAttribute(); final JsonAST jsonAttribute = cfType.getJsonAttribute();
final List<rawAST_coding_taglist> jsonChosen = jsonAttribute != null && jsonAttribute.tag_list != null ? new ArrayList<rawAST_coding_taglist>(jsonAttribute.tag_list) : null; List<rawAST_coding_taglist> jsonChosen = convertJsonCodingAttributes(jsonAttribute, aData, source, lastType);
final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ), final FieldInfo fi = new FieldInfo(cfType.getGenNameValue( aData, source ),
cfType.getGenNameTemplate( aData, source ), cfType.getGenNameTemplate( aData, source ),
compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), compField.isOptional(),
......
...@@ -41,9 +41,9 @@ import org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers; ...@@ -41,9 +41,9 @@ import org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST; import org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_field_list; import org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_field_list;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag; import org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_field_list; import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_field_list;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_field_type; import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_field_type;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_fields;
import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_taglist; import org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_taglist;
import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute; import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute;
import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_type; import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_type;
...@@ -3038,8 +3038,8 @@ public abstract class Type extends Governor implements IType, IIncrementallyUpda ...@@ -3038,8 +3038,8 @@ public abstract class Type extends Governor implements IType, IIncrementallyUpda
} else { } else {
JSON_value.append("null").append(','); JSON_value.append("null").append(',');
} }
// FIXME: || jsonattrib->tag_list != NULL
JSON_value.append(jsonAttribute.as_value).append(','); JSON_value.append(jsonAttribute.as_value || jsonAttribute.tag_list != null).append(',');
if (jsonAttribute.default_value == null) { if (jsonAttribute.default_value == null) {
JSON_value.append("null").append(','); JSON_value.append("null").append(',');
...@@ -3115,55 +3115,63 @@ public abstract class Type extends Governor implements IType, IIncrementallyUpda ...@@ -3115,55 +3115,63 @@ public abstract class Type extends Governor implements IType, IIncrementallyUpda
} }
} }
protected List<rawAST_coding_taglist> convertJsonCodingAttributes(RawAST jsonattrib, final JavaGenData aData, final StringBuilder source, IType t) { protected List<rawAST_coding_taglist> convertJsonCodingAttributes(JsonAST jsonattrib, final JavaGenData aData, final StringBuilder source, final IType lastType) {
if (jsonattrib == null || jsonattrib.taglist == null) { if (jsonattrib == null || jsonattrib.tag_list == null) {
return null; return null;
} }
final List<rawAST_single_tag> tag_list = jsonattrib.taglist; final List<rawAST_single_tag> tag_list = jsonattrib.tag_list;
final List<rawAST_coding_taglist> jsonChosen = new ArrayList<rawAST_coding_taglist>(); final List<rawAST_coding_taglist> jsonChosen = new ArrayList<rawAST_coding_taglist>(tag_list.size());
for (int c = 0; c < tag_list.size(); ++c) { for (int c = 0; c < jsonAttribute.tag_list.size(); c++) {
final rawAST_coding_taglist jsonChosenElement = new rawAST_coding_taglist(); final rawAST_single_tag curr_single_Tag = jsonAttribute.tag_list.get(c);
if (tag_list.get(c).keyList == null || tag_list.get(c).keyList.size() == 0) { final rawAST_coding_taglist curr_coding_taglist = new rawAST_coding_taglist();
jsonChosenElement.fields = null; final int keyListSize = curr_single_Tag.keyList == null ? 0: curr_single_Tag.keyList.size();
if (keyListSize > 0) {
curr_coding_taglist.fields = new ArrayList<RawASTStruct.rawAST_coding_field_list>(keyListSize);
} else { } else {
jsonChosenElement.fields = new ArrayList<rawAST_coding_field_list>(); curr_coding_taglist.fields = null;
} }
final Identifier union_field_id = tag_list.get(c).fieldName; jsonChosen.add(curr_coding_taglist);
final TTCN3_Set_Seq_Choice_BaseType ct = (TTCN3_Set_Seq_Choice_BaseType) t;
final TTCN3_Set_Seq_Choice_BaseType clast = (TTCN3_Set_Seq_Choice_BaseType)getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp()); final Identifier union_field_id = curr_single_Tag.fieldName;
jsonChosenElement.fieldname = union_field_id != null ? union_field_id.getName() : null; // TODO: currently unused curr_coding_taglist.fieldname = union_field_id != null ? union_field_id.getName() : null;
jsonChosenElement.fieldnum = union_field_id != null ? clast.getComponentIndexByName(tag_list.get(c).fieldName) : -2; curr_coding_taglist.fieldnum = union_field_id != null ? ((TTCN3_Set_Seq_Choice_BaseType)lastType).getComponentIndexByName(curr_single_Tag.fieldName) : -2;
if (tag_list.get(c).keyList != null) { for (int a = 0; a < keyListSize; a++) {
for (int a = 0; a <tag_list.get(c).keyList.size(); ++a) { final rawAST_coding_field_list key = new rawAST_coding_field_list();
final rawAST_coding_field_list key = new rawAST_coding_field_list(); curr_coding_taglist.fields.add(key);
key.value = tag_list.get(c).keyList.get(a).value; key.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(curr_single_Tag.keyList.get(a).keyField.names.size());
key.fields = new ArrayList<rawAST_coding_fields>(); key.value = curr_single_Tag.keyList.get(a).value;
for (int b = 0; b < key.fields.size(); ++b) { final ExpressionStruct expression = new ExpressionStruct();
final String current_field_id = tag_list.get(c).keyList.get(a).keyField.names.get(b).getName(); curr_single_Tag.keyList.get(a).v_value.generateCodeExpression(aData, expression, true);
final int current_field_index = ct.getComponentIndexByName(current_field_id); key.expression = expression;
final CompField current_field = ct.getComponentByIndex(current_field_index); final ExpressionStruct nativeExpression = new ExpressionStruct();
final rawAST_coding_fields jsonChosenElementField = new rawAST_coding_fields(); curr_single_Tag.keyList.get(a).v_value.generateCodeExpression(aData, nativeExpression, false);
jsonChosenElementField.nthfield = current_field_index; key.nativeExpression = nativeExpression;
jsonChosenElementField.nthfieldname = current_field_id; IType t = this;
if (t.getTypetype() == Type_type.TYPE_TTCN3_CHOICE) { for (int b = 0; b < curr_single_Tag.keyList.get(a).keyField.names.size(); b++) {
jsonChosenElementField.fieldtype = rawAST_coding_field_type.UNION_FIELD; final Identifier curr_field_id = curr_single_Tag.keyList.get(a).keyField.names.get(b);
} else if (current_field.isOptional()) { final int current_field_index = ((TTCN3_Set_Seq_Choice_BaseType)t).getComponentIndexByName(curr_field_id);
jsonChosenElementField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD; final CompField current_field = ((TTCN3_Set_Seq_Choice_BaseType)t).getComponentByIndex(current_field_index);
} else { RawASTStruct.rawAST_coding_fields current_coding_fields = new RawASTStruct.rawAST_coding_fields();
jsonChosenElementField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD; current_coding_fields.nthfield = current_field_index;
} current_coding_fields.nthfieldname = curr_field_id.getName();
final Type field_type = current_field.getType(); if (t.getTypetype() == Type_type.TYPE_TTCN3_CHOICE) {
jsonChosenElementField.type = field_type.getGenNameValue(aData, source); current_coding_fields.fieldtype = rawAST_coding_field_type.UNION_FIELD;
jsonChosenElementField.typedesc = field_type.getGenNameTypeDescriptor(aData, source); } else if (current_field.isOptional()) {
t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp()); current_coding_fields.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
key.fields.add(jsonChosenElementField); } else {
current_coding_fields.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
} }
jsonChosenElement.fields.add(key);
final Type field_type = current_field.getType();
current_coding_fields.type = field_type.getGenNameValue(aData, source);
current_coding_fields.typedesc = field_type.getGenNameTypeDescriptor(aData, source);
t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
key.fields.add(current_coding_fields);
} }
} }
jsonChosen.add(jsonChosenElement);
} }
return jsonChosen; return jsonChosen;
} }
......
...@@ -1189,7 +1189,7 @@ pr_JAsNumber: ASKeyword NUMBERKeyword {jsonstruct.as_number = true;}; ...@@ -1189,7 +1189,7 @@ pr_JAsNumber: ASKeyword NUMBERKeyword {jsonstruct.as_number = true;};
pr_JChosen: pr_JChosen:
CHOSENKeyword CHOSENKeyword
LPAREN LPAREN
taglist = pr_XAssocList {rawstruct.taglist = $taglist.taglist;} taglist = pr_XAssocList {jsonstruct.tag_list = $taglist.taglist;}
SEMICOLON? SEMICOLON?
RPAREN RPAREN
; ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment