Commit 676de8ca authored by Elemer Lelik's avatar Elemer Lelik Committed by GitHub
Browse files

Merge pull request #111 from BotondBaranyi/master

Fixed code generation for list and array types with JSON encoding
parents 2bedddbe 836ba471
......@@ -6219,7 +6219,8 @@ namespace Common {
else if (rawattrib && enable_raw()) return false;
else if (textattrib && enable_text()) return false;
else if (enable_xer()) return false;
else if (jsonattrib && enable_json()) return false;
else if ((jsonattrib || (!is_asn1() &&
hasEncodeAttr(get_encoding_name(CT_JSON)))) && enable_json()) return false;
else return true;
default:
return false;
......@@ -6635,7 +6636,7 @@ namespace Common {
* descriptor.
*/
if (t->is_tagged() || t->rawattrib || t->textattrib || t->jsonattrib ||
(!is_asn1() && t->hasEncodeAttr(get_encoding_name(CT_JSON))) ||
(!t->is_asn1() && t->hasEncodeAttr(get_encoding_name(CT_JSON))) ||
(t->xerattrib && !t->xerattrib->empty() ))
{
return t->get_genname_own(p_scope);
......
......@@ -2098,12 +2098,16 @@ void Type::generate_code_Array(output_struct *target)
if (has_encoding(CT_JSON)) {
target->header.class_decls = mputprintf(target->header.class_decls,
"class %s;\n", own_name);
string base_name = u.array.dimension->get_value_type(u.array.element_type, my_scope);
target->header.class_defs = mputprintf(target->header.class_defs,
"class %s : public %s {\n"
"const TTCN_Typedescriptor_t* get_elem_descr() const;\n"
"public:\n"
"%s(): %s() {}\n"
"%s(const %s& p): %s(p) {}\n"
"};\n\n",
own_name,
u.array.dimension->get_value_type(u.array.element_type, my_scope).c_str());
own_name, base_name.c_str(), own_name, base_name.c_str(),
own_name, base_name.c_str(), base_name.c_str());
target->source.methods = mputprintf(target->source.methods,
"const TTCN_Typedescriptor_t* %s::get_elem_descr() const { return &%s_descr_; }\n\n",
own_name, u.array.element_type->get_genname_typedescriptor(my_scope).c_str());
......
......@@ -28,7 +28,8 @@ CODIRS := dynamicTemplate styleGuide topLevelPdu \
isbound namedActualParameters assignmentNotation \
attribQualif HT48786 selectCase openTypeNames \
defaultParamUsageBeforeDecl deterministic readFromFile \
asn1_hyphen nameClash portTranslation UntaggedOnTopLevelUnionSwitch
asn1_hyphen nameClash portTranslation UntaggedOnTopLevelUnionSwitch \
typeDescrGenWIthNoXER
ifdef DYN
CODIRS += mfgen-xsd
......
##############################################################################
# Copyright (c) 2000-2017 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Botond, Baranyi
#
##############################################################################
TOPDIR := ../..
include $(TOPDIR)/Makefile.regression
.PHONY: all clean dep
TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
COMPILER_FLAGS += -X
TTCN3_MODULES = typeDescrGenWIthNoXER.ttcn
GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc)
GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
ifdef CODE_SPLIT
GENERATED_SOURCES := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), .cc _seq.cc _set.cc _seqof.cc _setof.cc _union.cc))
else ifdef SPLIT_TO_SLICES
POSTFIXES := $(foreach file, $(SPLIT_TO_SLICES), $(addsuffix $(file), _part_))
POSTFIXES := $(foreach file, $(POSTFIXES), $(addprefix $(file), .cc))
GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), $(POSTFIXES)))
GENERATED_SOURCES += $(GENERATED_SOURCES2)
endif
OBJECTS = $(GENERATED_SOURCES:.cc=.o)
TARGET = typeDescrGenWIthNoXER$(EXESUFFIX)
all: $(TARGET)
$(TARGET): $(GENERATED_SOURCES) $(USER_SOURCES)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ -L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) \
-L$(OPENSSL_DIR)/lib -lcrypto $($(PLATFORM)_LIBS)
$(GENERATED_SOURCES) $(GENERATED_HEADERS): $(TTCN3_MODULES)
$(TTCN3_COMPILER) $(COMPILER_FLAGS) $^
clean distclean:
$(RM) $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
$(GENERATED_SOURCES) compile *.log
dep: $(GENERATED_SOURCES)
makedepend $(CPPFLAGS) $(GENERATED_SOURCES)
/******************************************************************************
* Copyright (c) 2000-2017 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Baranyi, Botond
*
******************************************************************************/
// This module contains tests for the semantic analysis and code generation of
// list types (record of, set of) with JSON encoding support.
// Previously, the type descriptors of the lists' element types were not generated
// if the XER codec was disabled (with the compiler option -X).
module typeDescrGenWIthNoXER {
// structured types used as element types
type record Rec {
integer num,
charstring str
}
type record of integer IntList;
type union Uni {
integer num,
octetstring oct
}
type bitstring BitArray[4];
type enumerated Enum { val1, val2 }
// 'record of' and 'set of' types with structured element types
type record of Rec RecList;
type set of IntList IntListList;
type record of Uni UniList;
type set of BitArray BitArrayList;
type record of Enum EnumList;
type set of anytype AnyList;
// JSON coder functions for the list types
external function f_enc_rec_list(in RecList x) return octetstring
with { extension "prototype(convert) encode(JSON)" }
external function f_dec_list_list(in octetstring x) return IntListList
with { extension "prototype(convert) decode(JSON)" }
external function f_dec_uni_list(in octetstring x, out UniList y)
with { extension "prototype(fast) decode(JSON)" }
external function f_dec_array_list(in BitArrayList x, out octetstring y)
with { extension "prototype(fast) encode(JSON)" }
external function f_dec_enum_list(in octetstring x, out EnumList y) return integer
with { extension "prototype(backtrack) decode(JSON)" }
external function f_dec_any_list(inout octetstring x, out AnyList y) return integer
with { extension "prototype(sliding) decode(JSON)" }
}
with {
encode "JSON";
extension "anytype integer, boolean";
}
......@@ -62,7 +62,7 @@ testcase tc_char_vt_values() runs on CT {
var template charstring vt_char4 := "xx" & t_char & "xx";
var template charstring vt_char4_exp := "xxdefxx";
if (log2str(vt_char1) != log2str(vt_char1_exp)) {
setverdict(fail, "Expected: ", vt_char1_exp, ", got: ", vt_char1);
}
......
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