char *def = NULL, *src = NULL;
const char *name = sdef->name, *dispname = sdef->dispname;
const char *type = sdef->type;
- boolean ber_needed = sdef->isASN1 && enable_ber();
- boolean raw_needed = sdef->hasRaw && enable_raw();
- boolean text_needed = sdef->hasText && enable_text();
- boolean xer_needed = sdef->hasXer && enable_xer();
- boolean json_needed = sdef->hasJson && enable_json();
+ boolean ber_needed = force_gen_seof || (sdef->isASN1 && enable_ber());
+ boolean raw_needed = force_gen_seof || (sdef->hasRaw && enable_raw());
+ boolean text_needed = force_gen_seof || (sdef->hasText && enable_text());
+ boolean xer_needed = force_gen_seof || (sdef->hasXer && enable_xer());
+ boolean json_needed = force_gen_seof || (sdef->hasJson && enable_json());
/* Class definition and private data members */
def = mputprintf(def,
" p_buf.put_cs(*p_td.text->separator_encode);\n"
" encoded_length+=p_td.text->separator_encode->lengthof();\n"
" }\n"
- " encoded_length+=(*this)[a].TEXT_encode(%s_descr_,p_buf);\n"
+ " encoded_length+=(*this)[a].TEXT_encode(*p_td.oftype_descr,p_buf);\n"
" }\n"
" if(p_td.text->end_encode){\n"
" p_buf.put_cs(*p_td.text->end_encode);\n"
" }\n"
" return encoded_length;\n"
"}\n"
- ,name,sdef->oftypedescrname
+ ,name
);
src = mputprintf(src,
"int %s::TEXT_decode(const TTCN_Typedescriptor_t& p_td,"
" while(TRUE){\n"
" %s *val=new %s;\n"
" pos=p_buf.get_pos();\n"
- " int len=val->TEXT_decode(%s_descr_,p_buf,limit,TRUE);\n"
+ " int len=val->TEXT_decode(*p_td.oftype_descr,p_buf,limit,TRUE);\n"
" if(len==-1 || (len==0 && !limit.has_token())){\n"
" p_buf.set_pos(pos);\n"
" delete val;\n"
" }\n"
" }\n"
" }\n"
- ,name,type,type,sdef->oftypedescrname,type
+ ,name,type,type,type
);
src = mputstr(src,
" limit.remove_tokens(ml);\n"
" for(int elem_i=0; elem_i<val_ptr->n_elements; elem_i++) {\n"
" ec.set_msg(\"Component #%%d: \", elem_i);\n"
" new_tlv->add_TLV((*this)[elem_i].BER_encode_TLV"
- "(%s_descr_, p_coding));\n"
+ "(*p_td.oftype_descr, p_coding));\n"
" }\n"
"%s"
" }\n"
"val_ptr->n_elements + 1);\n"
" val_ptr->n_elements++;\n"
" val_ptr->value_elements[val_ptr->n_elements - 1] = new %s;\n"
- " val_ptr->value_elements[val_ptr->n_elements - 1]->BER_decode_TLV(%s_descr_, tmp_tlv, "
+ " val_ptr->value_elements[val_ptr->n_elements - 1]->BER_decode_TLV(*p_td.oftype_descr, tmp_tlv, "
"L_form);\n"
" ec_2.set_msg(\"%%d: \", val_ptr->n_elements);\n"
" }\n"
" return TRUE;\n"
"}\n"
"\n"
- , name, sdef->oftypedescrname
+ , name
, sdef->kind==SET_OF?" new_tlv->sort_tlvs();\n":""
- , name, type, type, sdef->oftypedescrname
+ , name, type, type
);
if(sdef->has_opentypes) {
" int a=0;\n"
" if(sel_field==-1) sel_field=p_td.raw->fieldlength;\n"
" for(a=0;a<sel_field;a++){\n"
- " decoded_field_length=(*this)[a+start_field].RAW_decode(%s_descr_,"
+ " decoded_field_length=(*this)[a+start_field].RAW_decode(*p_td.oftype_descr,"
"p_buf,limit,top_bit_ord,TRUE);\n"
" if(decoded_field_length < 0) return decoded_field_length;\n"
" decoded_length+=decoded_field_length;\n"
" }\n"
" while(limit>0){\n"
" start_of_field=p_buf.get_pos_bit();\n"
- " decoded_field_length=(*this)[a].RAW_decode(%s_descr_,p_buf,limit,"
+ " decoded_field_length=(*this)[a].RAW_decode(*p_td.oftype_descr,p_buf,limit,"
"top_bit_ord,TRUE);\n"
" if(decoded_field_length < 0){\n"
" delete &(*this)[a];\n"
" decoded_length+=decoded_field_length;\n"
" limit-=decoded_field_length;\n"
" a++;\n"
- ,name,sdef->oftypedescrname,sdef->oftypedescrname
+ ,name
);
- if(sdef->raw.extension_bit!=XDEFNO && sdef->raw.extension_bit!=XDEFDEFAULT){
+ if (force_gen_seof || (sdef->raw.extension_bit!=XDEFNO && sdef->raw.extension_bit!=XDEFDEFAULT)){
src=mputprintf(src,
- " if (%sp_buf.get_last_bit())\n"
+ " if (%s%sp_buf.get_last_bit()%s)\n"
" return decoded_length+p_buf.increase_pos_padd(p_td.raw->padding)"
- "+prepaddlength;\n", sdef->raw.extension_bit == XDEFYES ? "" : "!");
+ "+prepaddlength;\n"
+ , force_gen_seof ? "EXT_BIT_NO != p_td.raw->extension_bit && ((EXT_BIT_YES != p_td.raw->extension_bit) ^ " : ""
+ , (force_gen_seof || sdef->raw.extension_bit == XDEFYES) ? "" : "!"
+ , force_gen_seof ? ")" : "");
}
src=mputprintf(src,
" }\n"
" myleaf.body.node.nodes=init_nodes_of_enc_tree(encoded_num_of_records);\n"
" for(int a=0;a<encoded_num_of_records;a++){\n"
" myleaf.body.node.nodes[a]=new RAW_enc_tree(TRUE,&myleaf,"
- "&(myleaf.curr_pos),a,%s_descr_.raw);\n"
- " encoded_length+=(*this)[a].RAW_encode(%s_descr_,"
+ "&(myleaf.curr_pos),a,p_td.oftype_descr->raw);\n"
+ " encoded_length+=(*this)[a].RAW_encode(*p_td.oftype_descr,"
"*myleaf.body.node.nodes[a]);\n"
" }\n"
" return myleaf.length=encoded_length;\n}\n\n"
- , name, sdef->oftypedescrname, sdef->oftypedescrname
+ , name
);
}
"boolean %s::can_start(const char *name, const char *uri, "
"XERdescriptor_t const& xd, unsigned int flavor) {\n"
" boolean e_xer = is_exer(flavor);\n"
- " if (e_xer && (xd.xer_bits & ANY_ELEMENT)) "
+ " if ((!e_xer || !(xd.xer_bits & UNTAGGED)) && !(flavor & XER_RECOF)) return "
+ "check_name(name, xd, e_xer) && (!e_xer || check_namespace(uri, xd));\n"
+ " if (e_xer && (xd.oftype_descr->xer_bits & ANY_ELEMENT)) "
, name
);
- if (sdef->nFollowers) {
+ if (!force_gen_seof && sdef->nFollowers) {
/* If there are optional fields following the record-of, then seeing
* {any XML tag that belongs to those fields} where the record-of may be
* means that the record-of is empty. */
else src = mputstr(src, "return TRUE;\n");
src = mputprintf(src,
- " if ((!e_xer || !(xd.xer_bits & UNTAGGED)) && !(flavor & XER_RECOF)) return "
- "check_name(name, xd, e_xer) && (!e_xer || check_namespace(uri, xd));\n"
- " else return %s::can_start(name, uri, %s_xer_, flavor | XER_RECOF);\n"
+ " return %s::can_start(name, uri, *xd.oftype_descr, flavor | XER_RECOF);\n"
"}\n\n"
, sdef->type
- , sdef->oftypedescrname
);
src = mputprintf(src,
" size_t num_new;\n"
" for (int i = 0; i < val_ptr->n_elements; ++i) {\n"
" bool def_ns_1 = false;"
- " new_ns = (*this)[i].collect_ns(%s_xer_, num_new, def_ns_1);\n"
+ " new_ns = (*this)[i].collect_ns(*p_td.oftype_descr, num_new, def_ns_1);\n"
" merge_ns(collected_ns, num_collected, new_ns, num_new);\n"
" def_ns = def_ns || def_ns_1;\n" /* alas, no ||= */
" }\n"
" num = num_collected;\n"
" return collected_ns;\n"
"}\n\n"
- , name, sdef->oftypedescrname);
+ , name);
src=mputprintf(src,
"int %s::XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, "
"%s" /* Factor out p_indent if not attribute */
" if (val_ptr->n_elements==0) {\n" /* Empty record of */
, name
- , sdef->xerAttribute ? "" : " if (indenting) do_indent(p_buf, p_indent);\n"
+ , force_gen_seof ? " if (indenting && !(p_td.xer_bits & XER_ATTRIBUTE)) do_indent(p_buf, p_indent);\n"
+ : (sdef->xerAttribute ? "" : " if (indenting) do_indent(p_buf, p_indent);\n")
);
- if (sdef->xerAttribute) {
- src=mputstr(src,
- " if (e_xer) {\n" /* Empty attribute. */
+ if (force_gen_seof || sdef->xerAttribute) {
+ src=mputprintf(src,
+ " if (e_xer%s) {\n" /* Empty attribute. */
" begin_attribute(p_td, p_buf);\n"
" p_buf.put_c('\\'');\n"
- " } else\n");
+ " } else\n"
+ , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
}
- else {
+ if (force_gen_seof || !sdef->xerAttribute) {
src = mputstr(src,
" if (own_tag)");
}
" }\n"
" }\n"
" else {\n" /* Not empty record of. Start tag or attribute */
- , sdef->xerAttribute ? " if (indenting) do_indent(p_buf, p_indent);\n" : ""
+ , force_gen_seof ? " if (indenting && (p_td.xer_bits & XER_ATTRIBUTE)) do_indent(p_buf, p_indent);\n"
+ : (sdef->xerAttribute ? " if (indenting) do_indent(p_buf, p_indent);\n" : "")
);
if (sdef->xerAnyAttrElem) {
src = mputstr(src,
" p_buf.put_s(shorter, saved);\n" /* restore the '>' and anything after */
" } else {\n");
}
- if (sdef->xerAttribute) {
- src=mputstr(src,
- " if (e_xer) {\n"
+ if (force_gen_seof || sdef->xerAttribute) {
+ src=mputprintf(src,
+ " if (e_xer%s) {\n"
" begin_attribute(p_td, p_buf);\n"
- " } else\n");
+ " } else\n"
+ , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
}
src=mputprintf(src,
" if (own_tag) {\n"
" Free(collected_ns);\n"
" p_buf.put_s(1 + keep_newline, (cbyte*)\">\\n\");\n"
" }\n"
- , sdef->xerAttribute ? " if (indenting) do_indent(p_buf, p_indent);\n" : ""
+ , force_gen_seof ? " if (indenting && (p_td.xer_bits & XER_ATTRIBUTE)) do_indent(p_buf, p_indent);\n"
+ : (sdef->xerAttribute ? " if (indenting) do_indent(p_buf, p_indent);\n" : "")
);
if (sdef->xmlValueList) {
src=mputstr(src, " if (indenting && !e_xer) do_indent(p_buf, p_indent+1);\n"); /* !e_xer or GDMO */
" TTCN_EncDec_ErrorContext ec_0(\"Index \");\n"
" TTCN_EncDec_ErrorContext ec_1;\n"
);
- src=mputprintf(src,
+ src=mputstr(src,
" for (int i = 0; i < val_ptr->n_elements; ++i) {\n"
- /*" if (i > 0 && !own_tag && 0 != emb_val &&\n"
- " emb_val->embval_index < emb_val->embval_size) {\n"
- " emb_val->embval_array->get_embedded_value(emb_val->embval_index).XER_encode(\n"
- " UNIVERSAL_CHARSTRING_xer_, p_buf, p_flavor | EMBED_VALUES, p_indent+1, 0);\n"
+ " if (i > 0 && !own_tag && 0 != emb_val &&\n"
+ " emb_val->embval_index < (0 != emb_val->embval_array_reg ?\n"
+ " emb_val->embval_array_reg->size_of() : emb_val->embval_array_opt->size_of())) {\n"
+ " if (0 != emb_val->embval_array_reg) {\n"
+ " (*emb_val->embval_array_reg)[emb_val->embval_index].XER_encode(\n"
+ " UNIVERSAL_CHARSTRING_xer_, p_buf, p_flavor | EMBED_VALUES, p_indent+1, 0);\n"
+ " }\n"
+ " else {\n"
+ " (*emb_val->embval_array_opt)[emb_val->embval_index].XER_encode(\n"
+ " UNIVERSAL_CHARSTRING_xer_, p_buf, p_flavor | EMBED_VALUES, p_indent+1, 0);\n"
+ " }\n"
" ++emb_val->embval_index;\n"
- " }\n" - temporarily removed in RT1 */
- " ec_1.set_msg(\"%%d: \", i);\n"
+ " }\n"
+ " ec_1.set_msg(\"%d: \", i);\n"
" if (e_xer && (p_td.xer_bits & XER_LIST) && i>0) p_buf.put_c(' ');\n"
- " (*this)[i].XER_encode(%s_xer_, p_buf, p_flavor, p_indent+own_tag, emb_val);\n"
+ " (*this)[i].XER_encode(*p_td.oftype_descr, p_buf, p_flavor, p_indent+own_tag, emb_val);\n"
" }\n"
- " if (indenting && !is_exerlist(p_flavor)) {\n",
- sdef->oftypedescrname
+ " if (indenting && !is_exerlist(p_flavor)) {\n"
);
if (sdef->xmlValueList) {
src=mputstr(src, " if (!e_xer) p_buf.put_c('\\n');\n"); /* !e_xer or GDMO */
src=mputstr(src,
" do_indent(p_buf, p_indent);\n"
" }\n");
- if (sdef->xerAttribute) {
- src=mputstr(src,
- " if (e_xer) p_buf.put_c('\\'');\n"
- " else\n");
+ if (force_gen_seof || sdef->xerAttribute) {
+ src=mputprintf(src,
+ " if (e_xer%s) p_buf.put_c('\\'');\n"
+ " else\n"
+ , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
}
src=mputstr(src,
" if (own_tag){\n"
" }\n" /* next read */
" else xml_depth = p_reader.Depth();\n"
" p_flavor |= XER_RECOF;\n"
+ " TTCN_EncDec_ErrorContext ec_0(\"Index \");\n"
+ " TTCN_EncDec_ErrorContext ec_1;\n"
#ifndef NDEBUG
, __FUNCTION__, __LINE__
#endif
, name
);
- src = mputprintf(src,
+ src = mputstr(src,
" if (e_xer && (p_td.xer_bits & XER_LIST)) {\n" /* LIST decoding*/
" char *x_val = (char*)p_reader.NewValue();\n" /* we own it */
" size_t x_pos = 0;\n"
" x_pos += strlen(str) + 1;\n"
" TTCN_Buffer buf_2;\n"
" buf_2.put_c('<');\n"
- " write_ns_prefix(%s_xer_, buf_2);\n"
- " const char * const exer_name = %s_xer_.names[1];\n"
- " boolean i_can_has_ns = %s_xer_.my_module != 0 && %s_xer_.ns_index != -1;\n"
+ " write_ns_prefix(*p_td.oftype_descr, buf_2);\n"
+ " const char * const exer_name = p_td.oftype_descr->names[1];\n"
+ " boolean i_can_has_ns = p_td.oftype_descr->my_module != 0 && p_td.oftype_descr->ns_index != -1;\n"
/* If it has a namespace, chop off the '>' from the end */
- " buf_2.put_s((size_t)%s_xer_.namelens[1]-1-i_can_has_ns, (cbyte*)exer_name);\n"
+ " buf_2.put_s((size_t)p_td.oftype_descr->namelens[1]-1-i_can_has_ns, (cbyte*)exer_name);\n"
" if (i_can_has_ns) {\n"
- " const namespace_t * const pns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
+ " const namespace_t * const pns = p_td.oftype_descr->my_module->get_ns(p_td.oftype_descr->ns_index);\n"
" buf_2.put_s(7 - (*pns->px == 0), (cbyte*)\" xmlns:\");\n"
" buf_2.put_s(strlen(pns->px), (cbyte*)pns->px);\n"
" buf_2.put_s(2, (cbyte*)\"='\");\n"
" buf_2.put_s(strlen(str), (cbyte*)str);\n"
" buf_2.put_c('<');\n"
" buf_2.put_c('/');\n"
- " write_ns_prefix(%s_xer_, buf_2);\n"
- " buf_2.put_s((size_t)%s_xer_.namelens[1], (cbyte*)exer_name);\n"
+ " write_ns_prefix(*p_td.oftype_descr, buf_2);\n"
+ " buf_2.put_s((size_t)p_td.oftype_descr->namelens[1], (cbyte*)exer_name);\n"
" XmlReaderWrap reader_2(buf_2);\n"
" rd_ok = reader_2.Read();\n" /* Move to the start element. */
+ " ec_1.set_msg(\"%d: \", val_ptr->n_elements);\n"
/* Don't move to the #text, that's the callee's responsibility. */
/* The call to the non-const operator[] creates a new element object,
* then we call its XER_decode with the temporary XML reader. */
- " (*this)[val_ptr->n_elements].XER_decode(%s_xer_, reader_2, p_flavor, 0);\n"
+ " (*this)[val_ptr->n_elements].XER_decode(*p_td.oftype_descr, reader_2, p_flavor, 0);\n"
" if (p_flavor & EXIT_ON_ERROR && !(*this)[val_ptr->n_elements - 1].is_bound()) {\n"
" if (1 == val_ptr->n_elements) {\n"
// Failed to decode even the first element
" p_reader.Read();\n" /* past it */
" }\n"
" }\n"
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
);
src = mputprintf(src,
" if (p_reader.NodeType() != XML_READER_TYPE_ELEMENT) rd_ok = p_reader.Read();\n"
" } else");
}
- src = mputprintf(src,
+ src = mputstr(src,
" {\n"
/* An untagged record-of ends if it encounters an element with a name
* that doesn't match its component */
" if (!own_tag && !can_start((const char*)p_reader.LocalName(), "
- "(const char*)p_reader.NamespaceUri(), %s_xer_, p_flavor)) {\n"
+ "(const char*)p_reader.NamespaceUri(), p_td, p_flavor)) {\n"
" for (; rd_ok == 1 && p_reader.Depth() > xml_depth; rd_ok = p_reader.Read()) ;\n"
" break;\n"
" }\n"
+ " ec_1.set_msg(\"%d: \", val_ptr->n_elements);\n"
/* The call to the non-const operator[] creates the element */
- " (*this)[val_ptr->n_elements].XER_decode(%s_xer_, p_reader, p_flavor, emb_val);\n"
+ " (*this)[val_ptr->n_elements].XER_decode(*p_td.oftype_descr, p_reader, p_flavor, emb_val);\n"
" if (0 != emb_val && !own_tag && val_ptr->n_elements > 1) {\n"
" ++emb_val->embval_index;\n"
" }\n"
" }\n"
" break;\n"
" }\n"
- /*" else if (XML_READER_TYPE_TEXT == type && 0 != emb_val && !own_tag && get_nof_elements() > 0) {\n"
+ " else if (XML_READER_TYPE_TEXT == type && 0 != emb_val && !own_tag && val_ptr->n_elements > 0) {\n"
" UNIVERSAL_CHARSTRING emb_ustr((const char*)p_reader.Value());\n"
- " emb_val->embval_array->set_embedded_value(emb_val->embval_index, emb_ustr);\n"
+ " if (0 != emb_val->embval_array_reg) {\n"
+ " (*emb_val->embval_array_reg)[emb_val->embval_index] = emb_ustr;\n"
+ " }\n"
+ " else {\n"
+ " (*emb_val->embval_array_opt)[emb_val->embval_index] = emb_ustr;\n"
+ " }\n"
" rd_ok = p_reader.Read();\n"
- " }\n" - temporarily removed in RT1 */
+ " }\n"
" else {\n"
" rd_ok = p_reader.Read();\n"
" }\n"
" }\n" /* if not LIST */
" return 1;\n"
"}\n\n"
- , sdef->oftypedescrname, sdef->oftypedescrname
);
}
if (json_needed) {
// JSON encode, RT1
src = mputprintf(src,
- "int %s::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok) const\n"
+ "int %s::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok) const\n"
"{\n"
" if (!is_bound()) {\n"
" TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND,\n"
" }\n\n"
" int enc_len = p_tok.put_next_token(JSON_TOKEN_ARRAY_START, NULL);\n"
" for(int i = 0; i < val_ptr->n_elements; ++i) {\n"
- " int ret_val = (*this)[i].JSON_encode(%s_descr_, p_tok);\n"
+ " int ret_val = (*this)[i].JSON_encode(*p_td.oftype_descr, p_tok);\n"
" if (0 > ret_val) break;\n"
" enc_len += ret_val;\n"
" }\n"
" enc_len += p_tok.put_next_token(JSON_TOKEN_ARRAY_END, NULL);\n"
" return enc_len;\n"
"}\n\n"
- , name, dispname, sdef->oftypedescrname);
+ , name, dispname);
// JSON decode, RT1
src = mputprintf(src,
- "int %s::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_silent)\n"
+ "int %s::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)\n"
"{\n"
" json_token_t token = JSON_TOKEN_NONE;\n"
" int dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
" while (true) {\n"
" size_t buf_pos = p_tok.get_buf_pos();\n"
" %s* val = new %s;\n"
- " int ret_val = val->JSON_decode(%s_descr_, p_tok, p_silent);\n"
+ " int ret_val = val->JSON_decode(*p_td.oftype_descr, p_tok, p_silent);\n"
" if (JSON_ERROR_INVALID_TOKEN == ret_val) {\n"
" p_tok.set_buf_pos(buf_pos);\n"
" delete val;\n"
" }\n\n"
" return dec_len;\n"
"}\n\n"
- , name, type, type, sdef->oftypedescrname, type);
+ , name, type, type, type);
}
/* end of class */
def = mputstr(def, "};\n\n");
char *def = NULL, *src = NULL;
const char *name = sdef->name, *dispname = sdef->dispname;
const char *type = sdef->type;
- boolean ber_needed = sdef->isASN1 && enable_ber();
- boolean raw_needed = sdef->hasRaw && enable_raw();
- boolean text_needed = sdef->hasText && enable_text();
- boolean xer_needed = sdef->hasXer && enable_xer();
- boolean json_needed = sdef->hasJson && enable_json();
+ boolean ber_needed = force_gen_seof || (sdef->isASN1 && enable_ber());
+ boolean raw_needed = force_gen_seof || (sdef->hasRaw && enable_raw());
+ boolean text_needed = force_gen_seof || (sdef->hasText && enable_text());
+ boolean xer_needed = force_gen_seof || (sdef->hasXer && enable_xer());
+ boolean json_needed = force_gen_seof || (sdef->hasJson && enable_json());
/* Class definition and private data members */
def = mputprintf(def,
/* constructors */
def = mputprintf(def, "%s(): n_elements(-1), value_elements(NULL) {}\n", name);
- def = mputprintf(def, "%s(null_type other_value): n_elements(0), value_elements(NULL) {}\n", name);
+ def = mputprintf(def, "%s(null_type): n_elements(0), value_elements(NULL) {}\n", name);
/* copy constructor */
def = mputprintf(def, "%s(const %s& other_value) { copy_value(other_value); }\n", name, name);
" p_buf.put_cs(*p_td.text->separator_encode);\n"
" encoded_length+=p_td.text->separator_encode->lengthof();\n"
" }\n"
- " encoded_length+=value_elements[a].TEXT_encode(%s_descr_,p_buf);\n"
+ " encoded_length+=value_elements[a].TEXT_encode(*p_td.oftype_descr,p_buf);\n"
" }\n"
" if(p_td.text->end_encode){\n"
" p_buf.put_cs(*p_td.text->end_encode);\n"
" }\n"
" return encoded_length;\n"
"}\n"
- ,name,sdef->oftypedescrname
+ ,name
);
src = mputprintf(src,
"int %s::TEXT_decode(const TTCN_Typedescriptor_t& p_td,"
" while(TRUE){\n"
" %s val;\n"
" pos=p_buf.get_pos();\n"
- " int len=val.TEXT_decode(%s_descr_,p_buf,limit,TRUE);\n"
+ " int len=val.TEXT_decode(*p_td.oftype_descr,p_buf,limit,TRUE);\n"
" if(len==-1 || (len==0 && !limit.has_token())){\n"
" p_buf.set_pos(pos);\n"
" if(sep_found){\n"
" }\n"
" }\n"
" }\n"
- ,name,type,sdef->oftypedescrname
+ ,name,type
);
src = mputstr(src,
" limit.remove_tokens(ml);\n"
" for(int elem_i=0; elem_i<n_elements; elem_i++) {\n"
" ec.set_msg(\"Component #%%d: \", elem_i);\n"
" new_tlv->add_TLV(value_elements[elem_i].BER_encode_TLV"
- "(%s_descr_, p_coding));\n"
+ "(*p_td.oftype_descr, p_coding));\n"
" }\n"
"%s"
" }\n"
" while(BER_decode_constdTLV_next(stripped_tlv, V_pos, L_form, "
"tmp_tlv)) {\n"
" set_size(n_elements+1);\n"
- " value_elements[n_elements-1].BER_decode_TLV(%s_descr_, tmp_tlv, "
+ " value_elements[n_elements-1].BER_decode_TLV(*p_td.oftype_descr, tmp_tlv, "
"L_form);\n"
" ec_2.set_msg(\"%%d: \", n_elements);\n"
" }\n"
" return TRUE;\n"
"}\n"
"\n"
- , name, sdef->oftypedescrname
+ , name
, sdef->kind==SET_OF?" new_tlv->sort_tlvs();\n":""
- , name, sdef->oftypedescrname
+ , name
);
if(sdef->has_opentypes) {
" int a=0;\n"
" if(sel_field==-1) sel_field=p_td.raw->fieldlength;\n"
" for(a=0;a<sel_field;a++){\n"
- " decoded_field_length=(*this)[a+start_field].RAW_decode(%s_descr_,"
+ " decoded_field_length=(*this)[a+start_field].RAW_decode(*p_td.oftype_descr,"
"p_buf,limit,top_bit_ord,TRUE);\n"
" if(decoded_field_length < 0) return decoded_field_length;\n"
" decoded_length+=decoded_field_length;\n"
" }\n"
" while(limit>0){\n"
" start_of_field=p_buf.get_pos_bit();\n"
- " decoded_field_length=(*this)[a].RAW_decode(%s_descr_,p_buf,limit,"
+ " decoded_field_length=(*this)[a].RAW_decode(*p_td.oftype_descr,p_buf,limit,"
"top_bit_ord,TRUE);\n"
" if(decoded_field_length < 0){\n"
/*" delete &(*this)[a];\n"*/
" decoded_length+=decoded_field_length;\n"
" limit-=decoded_field_length;\n"
" a++;\n"
- ,name,sdef->oftypedescrname,sdef->oftypedescrname
+ ,name
);
if(sdef->raw.extension_bit!=XDEFNO && sdef->raw.extension_bit!=XDEFDEFAULT){
src=mputprintf(src,
" myleaf.body.node.nodes=init_nodes_of_enc_tree(encoded_num_of_records);\n"
" for(int a=0;a<encoded_num_of_records;a++){\n"
" myleaf.body.node.nodes[a]=new RAW_enc_tree(TRUE,&myleaf,"
- "&(myleaf.curr_pos),a,%s_descr_.raw);\n"
- " encoded_length+=(*this)[a].RAW_encode(%s_descr_,"
+ "&(myleaf.curr_pos),a,p_td.oftype_descr->raw);\n"
+ " encoded_length+=(*this)[a].RAW_encode(*p_td.oftype_descr,"
"*myleaf.body.node.nodes[a]);\n"
" }\n"
" return myleaf.length=encoded_length;\n}\n\n"
- , name, sdef->oftypedescrname, sdef->oftypedescrname
+ , name
);
}
"boolean %s::can_start(const char *name, const char *uri, "
"XERdescriptor_t const& xd, unsigned int flavor) {\n"
" boolean e_xer = is_exer(flavor);\n"
- " if (e_xer && (xd.xer_bits & ANY_ELEMENT)) "
+ " if ((!e_xer || !(xd.xer_bits & UNTAGGED)) && !(flavor & XER_RECOF)) return "
+ "check_name(name, xd, e_xer) && (!e_xer || check_namespace(uri, xd));\n"
+ " if (e_xer && (xd.oftype_descr->xer_bits & ANY_ELEMENT)) "
, name
);
- if (sdef->nFollowers) {
+ if (!force_gen_seof && sdef->nFollowers) {
/* If there are optional fields following the record-of, then seeing
* {any XML tag that belongs to those fields} where the record-of may be
* means that the record-of is empty. */
else src = mputstr(src, "return TRUE;\n");
src = mputprintf(src,
- " if ((!e_xer || !(xd.xer_bits & UNTAGGED)) && !(flavor & XER_RECOF)) return "
- "check_name(name, xd, e_xer) && (!e_xer || check_namespace(uri, xd));\n"
- " else return %s::can_start(name, uri, %s_xer_, flavor | XER_RECOF);\n"
+ " return %s::can_start(name, uri, *xd.oftype_descr, flavor | XER_RECOF);\n"
"}\n\n"
, sdef->type
- , sdef->oftypedescrname
);
src = mputprintf(src,
" size_t num_new;\n"
" for (int i = 0; i < n_elements; ++i) {\n"
" bool def_ns_1 = false;"
- " new_ns = value_elements[i].collect_ns(%s_xer_, num_new, def_ns_1);\n"
+ " new_ns = value_elements[i].collect_ns(*p_td.oftype_descr, num_new, def_ns_1);\n"
" merge_ns(collected_ns, num_collected, new_ns, num_new);\n"
" def_ns = def_ns || def_ns_1;\n" /* alas, no ||= */
" }\n"
" num = num_collected;\n"
" return collected_ns;\n"
"}\n\n"
- , name, sdef->oftypedescrname);
+ , name);
src=mputprintf(src,
"int %s::XER_encode(const XERdescriptor_t& p_td, TTCN_Buffer& p_buf, "
"%s" /* Factor out p_indent if not attribute */
" if (n_elements==0) {\n" /* Empty record of */
, name
- , sdef->xerAttribute ? "" : " if (indenting) do_indent(p_buf, p_indent);\n"
+ , force_gen_seof ? " if (indenting && !(p_td.xer_bits & XER_ATTRIBUTE)) do_indent(p_buf, p_indent);\n"
+ : (sdef->xerAttribute ? "" : " if (indenting) do_indent(p_buf, p_indent);\n")
);
- if (sdef->xerAttribute) {
- src=mputstr(src,
- " if (e_xer) {\n" /* Empty attribute. */
+ if (force_gen_seof || sdef->xerAttribute) {
+ src=mputprintf(src,
+ " if (e_xer%s) {\n" /* Empty attribute. */
" begin_attribute(p_td, p_buf);\n"
" p_buf.put_c('\\'');\n"
- " } else\n");
+ " } else\n"
+ , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
}
- else {
+ if (force_gen_seof || !sdef->xerAttribute) {
src = mputstr(src,
" if (own_tag)");
}
" }\n"
" }\n"
" else {\n" /* Not empty record of. Start tag or attribute */
- , sdef->xerAttribute ? " if (indenting) do_indent(p_buf, p_indent);\n" : ""
+ , force_gen_seof ? " if (indenting && !(p_td.xer_bits & XER_ATTRIBUTE)) do_indent(p_buf, p_indent);\n"
+ : (sdef->xerAttribute ? "" : " if (indenting) do_indent(p_buf, p_indent);\n")
);
if (sdef->xerAnyAttrElem) {
src = mputstr(src,
" p_buf.put_s(shorter, saved);\n" /* restore the '>' and anything after */
" } else {\n");
}
- if (sdef->xerAttribute) {
- src=mputstr(src,
- " if (e_xer) {\n"
+ if (force_gen_seof || sdef->xerAttribute) {
+ src=mputprintf(src,
+ " if (e_xer%s) {\n"
" begin_attribute(p_td, p_buf);\n"
- " } else\n");
+ " } else\n"
+ , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
}
src=mputprintf(src,
" if (own_tag) {\n"
" Free(collected_ns);\n"
" p_buf.put_s(1 + keep_newline, (cbyte*)\">\\n\");\n"
" }\n"
- , sdef->xerAttribute ? " if (indenting) do_indent(p_buf, p_indent);\n" : ""
+ , force_gen_seof ? " if (indenting && (p_td.xer_bits & XER_ATTRIBUTE)) do_indent(p_buf, p_indent);\n"
+ : (sdef->xerAttribute ? " if (indenting) do_indent(p_buf, p_indent);\n" : "")
);
if (sdef->xmlValueList) {
src=mputstr(src, " if (indenting && !e_xer) do_indent(p_buf, p_indent+1);\n"); /* !e_xer or GDMO */
" TTCN_EncDec_ErrorContext ec_0(\"Index \");\n"
" TTCN_EncDec_ErrorContext ec_1;\n"
);
- src=mputprintf(src,
+ src=mputstr(src,
" for (int i = 0; i < n_elements; ++i) {\n"
- /*" if (i > 0 && !own_tag && 0 != emb_val &&\n"
- " emb_val->embval_index < emb_val->embval_size) {\n"
- " emb_val->embval_array->get_embedded_value(emb_val->embval_index).XER_encode(\n"
- " UNIVERSAL_CHARSTRING_xer_, p_buf, p_flavor | EMBED_VALUES, p_indent+1, 0);\n"
+ " if (i > 0 && !own_tag && 0 != emb_val &&\n"
+ " emb_val->embval_index < (0 != emb_val->embval_array_reg ?\n"
+ " emb_val->embval_array_reg->size_of() : emb_val->embval_array_opt->size_of())) {\n"
+ " if (0 != emb_val->embval_array_reg) {\n"
+ " (*emb_val->embval_array_reg)[emb_val->embval_index].XER_encode(\n"
+ " UNIVERSAL_CHARSTRING_xer_, p_buf, p_flavor | EMBED_VALUES, p_indent+1, 0);\n"
+ " }\n"
+ " else {\n"
+ " (*emb_val->embval_array_opt)[emb_val->embval_index].XER_encode(\n"
+ " UNIVERSAL_CHARSTRING_xer_, p_buf, p_flavor | EMBED_VALUES, p_indent+1, 0);\n"
+ " }\n"
" ++emb_val->embval_index;\n"
- " }\n" - temporarily removed in RT1 */
- " ec_1.set_msg(\"%%d: \", i);\n"
+ " }\n"
+ " ec_1.set_msg(\"%d: \", i);\n"
" if (e_xer && (p_td.xer_bits & XER_LIST) && i>0) p_buf.put_c(' ');\n"
- " value_elements[i].XER_encode(%s_xer_, p_buf, p_flavor, p_indent+own_tag, emb_val);\n"
+ " value_elements[i].XER_encode(*p_td.oftype_descr, p_buf, p_flavor, p_indent+own_tag, emb_val);\n"
" }\n"
- " if (indenting && !is_exerlist(p_flavor)) {\n",
- sdef->oftypedescrname
+ " if (indenting && !is_exerlist(p_flavor)) {\n"
);
if (sdef->xmlValueList) {
src=mputstr(src, " if (!e_xer) p_buf.put_c('\\n');\n"); /* !e_xer or GDMO */
src=mputstr(src,
" do_indent(p_buf, p_indent);\n"
" }\n");
- if (sdef->xerAttribute) {
- src=mputstr(src,
- " if (e_xer) p_buf.put_c('\\'');\n"
- " else\n");
+ if (force_gen_seof || sdef->xerAttribute) {
+ src=mputprintf(src,
+ " if (e_xer%s) p_buf.put_c('\\'');\n"
+ " else\n"
+ , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
}
src=mputstr(src,
" if (own_tag){\n"
, name
);
- src = mputprintf(src,
+ src = mputstr(src,
" if (e_xer && (p_td.xer_bits & XER_LIST)) {\n" /* LIST decoding*/
" char *x_val = (char*)p_reader.NewValue();\n" /* we own it */
" size_t x_pos = 0;\n"
" x_pos += strlen(str) + 1;\n"
" TTCN_Buffer buf_2;\n"
" buf_2.put_c('<');\n"
- " write_ns_prefix(%s_xer_, buf_2);\n"
- " const char * const exer_name = %s_xer_.names[1];\n"
- " boolean i_can_has_ns = %s_xer_.my_module != 0 && %s_xer_.ns_index != -1;\n"
+ " write_ns_prefix(*p_td.oftype_descr, buf_2);\n"
+ " const char * const exer_name = p_td.oftype_descr->names[1];\n"
+ " boolean i_can_has_ns = p_td.oftype_descr->my_module != 0 && p_td.oftype_descr->ns_index != -1;\n"
/* If it has a namespace, chop off the '>' from the end */
- " buf_2.put_s((size_t)%s_xer_.namelens[1]-1-i_can_has_ns, (cbyte*)exer_name);\n"
+ " buf_2.put_s((size_t)p_td.oftype_descr->namelens[1]-1-i_can_has_ns, (cbyte*)exer_name);\n"
" if (i_can_has_ns) {\n"
- " const namespace_t * const pns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
+ " const namespace_t * const pns = p_td.oftype_descr->my_module->get_ns(p_td.oftype_descr->ns_index);\n"
" buf_2.put_s(7 - (*pns->px == 0), (cbyte*)\" xmlns:\");\n"
" buf_2.put_s(strlen(pns->px), (cbyte*)pns->px);\n"
" buf_2.put_s(2, (cbyte*)\"='\");\n"
" buf_2.put_s(strlen(str), (cbyte*)str);\n"
" buf_2.put_c('<');\n"
" buf_2.put_c('/');\n"
- " write_ns_prefix(%s_xer_, buf_2);\n"
- " buf_2.put_s((size_t)%s_xer_.namelens[1], (cbyte*)exer_name);\n"
+ " write_ns_prefix(*p_td.oftype_descr, buf_2);\n"
+ " buf_2.put_s((size_t)p_td.oftype_descr->namelens[1], (cbyte*)exer_name);\n"
" XmlReaderWrap reader_2(buf_2);\n"
" rd_ok = reader_2.Read();\n" /* Move to the start element. */
/* Don't move to the #text, that's the callee's responsibility. */
/* The call to the non-const operator[] creates a new element object,
* then we call its XER_decode with the temporary XML reader. */
- " (*this)[n_elements].XER_decode(%s_xer_, reader_2, p_flavor, 0);\n"
+ " (*this)[n_elements].XER_decode(*p_td.oftype_descr, reader_2, p_flavor, 0);\n"
" if (p_flavor & EXIT_ON_ERROR && !(*this)[n_elements - 1].is_bound()) {\n"
" if (1 == n_elements) {\n"
// Failed to decode even the first element
" p_reader.Read();\n" /* past it */
" }\n"
" }\n"
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
- , sdef->oftypedescrname, sdef->oftypedescrname
);
src = mputprintf(src,
" if (p_reader.NodeType() != XML_READER_TYPE_ELEMENT) rd_ok = p_reader.Read();\n"
" } else");
}
- src = mputprintf(src,
+ src = mputstr(src,
" {\n"
/* An untagged record-of ends if it encounters an element with a name
* that doesn't match its component */
" if (!own_tag && !can_start((const char*)p_reader.LocalName(), "
- "(const char*)p_reader.NamespaceUri(), %s_xer_, p_flavor)) {\n"
+ "(const char*)p_reader.NamespaceUri(), p_td, p_flavor)) {\n"
" for (; rd_ok == 1 && p_reader.Depth() > xml_depth; rd_ok = p_reader.Read()) ;\n"
" break;\n"
" }\n"
/* The call to the non-const operator[] creates the element */
- " operator [](n_elements).XER_decode(%s_xer_, p_reader, p_flavor, emb_val);\n"
+ " operator [](n_elements).XER_decode(*p_td.oftype_descr, p_reader, p_flavor, emb_val);\n"
" if (0 != emb_val && !own_tag && n_elements > 1) {\n"
" ++emb_val->embval_index;\n"
" }\n"
" }\n"
" break;\n"
" }\n"
- /*" else if (XML_READER_TYPE_TEXT == type && 0 != emb_val && !own_tag && n_elements > 0) {\n"
+ " else if (XML_READER_TYPE_TEXT == type && 0 != emb_val && !own_tag && n_elements > 0) {\n"
" UNIVERSAL_CHARSTRING emb_ustr((const char*)p_reader.Value());\n"
- " emb_val->embval_array->set_embedded_value(emb_val->embval_index, emb_ustr);\n"
+ " if (0 != emb_val->embval_array_reg) {\n"
+ " (*emb_val->embval_array_reg)[emb_val->embval_index] = emb_ustr;\n"
+ " }\n"
+ " else {\n"
+ " (*emb_val->embval_array_opt)[emb_val->embval_index] = emb_ustr;\n"
+ " }\n"
" rd_ok = p_reader.Read();\n"
- " }\n" - temporarily removed in RT1 */
+ " }\n"
" else {\n"
" rd_ok = p_reader.Read();\n"
" }\n"
" }\n" /* if not LIST */
" return 1;\n"
"}\n\n"
- , sdef->oftypedescrname, sdef->oftypedescrname
);
}
if (json_needed) {
// JSON encode, RT1, mem. alloc. optimised
src = mputprintf(src,
- "int %s::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok) const\n"
+ "int %s::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok) const\n"
"{\n"
" if (!is_bound()) {\n"
" TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_UNBOUND,\n"
" }\n\n"
" int enc_len = p_tok.put_next_token(JSON_TOKEN_ARRAY_START, NULL);\n"
" for(int i = 0; i < n_elements; ++i) {\n"
- " int ret_val = value_elements[i].JSON_encode(%s_descr_, p_tok);\n"
+ " int ret_val = value_elements[i].JSON_encode(*p_td.oftype_descr, p_tok);\n"
" if (0 > ret_val) break;\n"
" enc_len += ret_val;\n"
" }\n"
" enc_len += p_tok.put_next_token(JSON_TOKEN_ARRAY_END, NULL);\n"
" return enc_len;\n"
"}\n\n"
- , name, dispname, sdef->oftypedescrname);
+ , name, dispname);
// JSON decode, RT1, mem. alloc. optimised
src = mputprintf(src,
- "int %s::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_silent)\n"
+ "int %s::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)\n"
"{\n"
" json_token_t token = JSON_TOKEN_NONE;\n"
" int dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
" while (true) {\n"
" size_t buf_pos = p_tok.get_buf_pos();\n"
" %s val;\n"
- " int ret_val = val.JSON_decode(%s_descr_, p_tok, p_silent);\n"
+ " int ret_val = val.JSON_decode(*p_td.oftype_descr, p_tok, p_silent);\n"
" if (JSON_ERROR_INVALID_TOKEN == ret_val) {\n"
" p_tok.set_buf_pos(buf_pos);\n"
" break;\n"
" }\n\n"
" return dec_len;\n"
"}\n\n"
- , name, type, sdef->oftypedescrname);
+ , name, type);
}
/* end of class */
def = mputstr(def, "};\n\n");
char *def = NULL, *src = NULL;
const char *name = sdef->name;
const char *type = sdef->type;
- boolean raw_needed = sdef->hasRaw && enable_raw();
- boolean xer_needed = sdef->hasXer && enable_xer();
+ boolean raw_needed = force_gen_seof || (sdef->hasRaw && enable_raw());
+ boolean xer_needed = force_gen_seof || (sdef->hasXer && enable_xer());
/* Class definition */
def = mputprintf(def,
src = mputprintf(src,
"Base_Type* %s::create_elem() const { return new %s; }\n"
"const Base_Type* %s::get_unbound_elem() const { return &UNBOUND_ELEM; }\n"
- "const TTCN_Typedescriptor_t* %s::get_descriptor() const { return &%s_descr_; }\n"
- "const TTCN_Typedescriptor_t* %s::get_elem_descr() const { return &%s_descr_; }\n\n",
+ "const TTCN_Typedescriptor_t* %s::get_descriptor() const { return &%s_descr_; }\n",
name, type,
name,
- name, name,
- name, sdef->oftypedescrname);
+ name, name);
/* helper functions called by enc/dec members of the ancestor class */
if (raw_needed) {
"boolean %s::can_start(const char *name, const char *uri, "
"XERdescriptor_t const& xd, unsigned int flavor) {\n"
" boolean e_xer = is_exer(flavor);\n"
+ /* if EXER and UNTAGGED, it can begin with the tag of the element,
+ * otherwise it must be the tag of the type itself,
+ * specified in the supplied parameter.
+ * If flavor contains UNTAGGED, that's a signal to go directly
+ * to the embedded type. */
+ " if (!e_xer || !((xd.xer_bits|flavor) & UNTAGGED)) return "
+ "check_name(name, xd, e_xer) && (!e_xer || check_namespace(uri, xd));\n"
/* a record-of with ANY-ELEMENT can start with any tag
* :-( with some exceptions )-: */
- " if (e_xer && (xd.xer_bits & ANY_ELEMENT)) "
+ " if (e_xer && (xd.oftype_descr->xer_bits & ANY_ELEMENT)) "
, name, name
);
- if (sdef->nFollowers) {
+ if (!force_gen_seof && sdef->nFollowers) {
size_t f;
src = mputstr(src, "{\n");
for (f = 0; f < sdef->nFollowers; ++f) {
src = mputstr(src, "return TRUE;\n");
}
src = mputprintf(src,
- /* if EXER and UNTAGGED, it can begin with the tag of the element,
- * otherwise it must be the tag of the type itself,
- * specified in the supplied parameter.
- * If flavor contains UNTAGGED, that's a signal to go directly
- * to the embedded type. */
- " if (!e_xer || !((xd.xer_bits|flavor) & UNTAGGED)) return "
- "check_name(name, xd, e_xer) && (!e_xer || check_namespace(uri, xd));\n"
- " else return %s::can_start(name, uri, %s_xer_, flavor | XER_RECOF);\n"
- "}\n\n", sdef->type, sdef->oftypedescrname);
+ " return %s::can_start(name, uri, *xd.oftype_descr, flavor | XER_RECOF);\n"
+ "}\n\n", sdef->type);
def = mputprintf(def, "boolean isXmlValueList() const { return %s; }\n\n",
sdef->xmlValueList ? "TRUE" : "FALSE");
}