Commit 7eb56de6 authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

Prohibited to create templates if the type has default or port field (Bug 518511)



Change-Id: I09a79f4ac9a290c00899c17c5c408ec8ba08acba
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent 1e1f040c
......@@ -610,6 +610,7 @@ namespace Common {
gen_json_coder_functions = false;
default_encoding.type = CODING_UNSET;
default_decoding.type = CODING_UNSET;
checked_incorrect_field = false;
}
void Type::clean_up()
......@@ -2267,12 +2268,12 @@ namespace Common {
int used_bits = 0; // number of bits used to store all previous fields
for(size_t i = 0; i < get_nof_comps(); i++) { // field attributes
CompField *cf = get_comp_byIndex(i);
const Identifier& field_id = cf->get_name();
Type *field_type = cf->get_type();
Type *field_type_last = field_type->get_type_refd_last();
field_type->force_raw();
RawAST *rawpar = field_type->rawattrib;
if (rawpar) {
const Identifier& field_id = cf->get_name();
Type *field_type_last = field_type->get_type_refd_last();
if (rawpar->prepadding != 0) {
used_bits = (used_bits + rawpar->prepadding - 1) / rawpar->prepadding *
rawpar->prepadding;
......
......@@ -18,6 +18,7 @@
* Kovacs, Ferenc
* Raduly, Csaba
* Szabados, Kristof
* Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Szalai, Gabor
* Tatarka, Gabor
......@@ -446,6 +447,10 @@ namespace Common {
* refer to this type may have JSON encoding, in which case this type needs
* to have JSON coder functions to code them. */
bool gen_json_coder_functions;
/** True if we already checked this type for default or port field*/
bool checked_incorrect_field;
/** Copy constructor, for the use of Type::clone() only. */
Type(const Type& p);
......@@ -883,6 +888,8 @@ namespace Common {
bool chk_this_template_generic(Template *t, namedbool incomplete_allowed,
namedbool allow_omit, namedbool allow_any_or_omit, namedbool sub_chk,
namedbool implicit_omit, Common::Assignment *lhs);
/** Checks if a template's type contains default or port field somehow.*/
void chk_this_template_incorrect_field();
private:
bool chk_this_refd_template(Template *t, Common::Assignment *lhs);
void chk_this_template_length_restriction(Template *t);
......
......@@ -5525,6 +5525,46 @@ bool Type::chk_this_template_ref_pard(Ttcn::Ref_pard* ref_pard, Common::Assignme
return false;
}
void Type::chk_this_template_incorrect_field() {
Type *t = get_type_refd_last();
if (t->checked_incorrect_field) return;
t->checked_incorrect_field = true;
t->chk();
Error_Context cntxt(t, "In type `%s'", t->get_fullname().c_str());
switch(t->typetype) {
case T_ANYTYPE:
case T_CHOICE_T:
case T_SEQ_T:
case T_SET_T:
case T_OPENTYPE:
for (size_t i = 0; i < t->get_nof_comps(); i++) {
Error_Context cntxt(t->get_comp_byIndex(i), "In field `%s'", t->get_comp_byIndex(i)->get_name().get_dispname().c_str());
t->get_comp_byIndex(i)->get_type()->chk_this_template_incorrect_field();
}
break;
case T_SEQOF:
case T_SETOF:
case T_ARRAY:
t->get_ofType()->chk_this_template_incorrect_field();
break;
case T_COMPONENT:
for (size_t i = 0; i < t->get_CompBody()->get_nof_asss(); i++) {
Assignment* ass = t->get_CompBody()->get_ass_byIndex(i);
Error_Context cntxt(ass, "In field `%s'", ass->get_id().get_dispname().c_str());
ass->get_Type()->chk_this_template_incorrect_field();
}
break;
case T_DEFAULT:
t->error("A template cannot contain a field with default type at any level.");
break;
case T_PORT:
t->error("A template cannot contain a field with port type at any level.");
break;
default:
break;
}
}
bool Type::chk_this_template_generic(Template *t, namedbool incomplete_allowed,
namedbool allow_omit, namedbool allow_any_or_omit, namedbool sub_chk,
namedbool implicit_omit, Common::Assignment *lhs)
......@@ -5677,7 +5717,7 @@ bool Type::chk_this_template_generic(Template *t, namedbool incomplete_allowed,
/* Note: A "permuation" itself has no type - it is just a fragment. */
if(sub_type!=NULL) sub_type->chk_this_template_generic(t);
}
return self_ref;
}
......
......@@ -1435,8 +1435,6 @@ namespace Ttcn {
for (size_t t = 0; t < imp.impmods_v.size(); t++) {
const ImpMod *im = imp.impmods_v[t];
const Identifier& im_id = im->get_modid();
Common::Module *cm = modules->get_mod_byId(im_id); // never NULL
refch.mark_state();
if (PRIVATE != im->get_visibility()) {
......@@ -1448,6 +1446,8 @@ namespace Ttcn {
refch.prev_state();
continue;
} else {
const Identifier& im_id = im->get_modid();
Common::Module *cm = modules->get_mod_byId(im_id); // never NULL
refch.add(m->get_fullname());
cm->chk_imp(refch, moduleStack);
}
......@@ -4123,6 +4123,7 @@ namespace Ttcn {
checked = true;
type->chk_this_template_generic(def_template, INCOMPLETE_ALLOWED,
OMIT_ALLOWED, ANY_OR_OMIT_ALLOWED, SUB_CHK, IMPLICIT_OMIT == has_implicit_omit_attr() ? IMPLICIT_OMIT : NOT_IMPLICIT_OMIT, 0);
type->chk_this_template_incorrect_field();
if (!semantic_check_only) {
def_template->set_genname_prefix("modulepar_");
def_template->set_genname_recursive(get_genname());
......@@ -4321,7 +4322,7 @@ namespace Ttcn {
derived_ref != NULL ? INCOMPLETE_ALLOWED : WARNING_FOR_INCOMPLETE,
OMIT_ALLOWED, ANY_OR_OMIT_ALLOWED, SUB_CHK,
IMPLICIT_OMIT == has_implicit_omit_attr() ? IMPLICIT_OMIT : NOT_IMPLICIT_OMIT, 0);
type->chk_this_template_incorrect_field();
erroneous_attrs = chk_erroneous_attr(w_attrib_path, type, get_my_scope(),
get_fullname(), false);
if (erroneous_attrs) body->add_err_descr(NULL, erroneous_attrs->get_err_descr());
......@@ -4718,10 +4719,6 @@ namespace Ttcn {
char *Def_Template::generate_code_str(char *str)
{
const string& t_genname = get_genname();
const char *genname_str = t_genname.c_str();
const string& type_genname = type->get_genname_template(my_scope);
const char *type_genname_str = type_genname.c_str();
if (fp_list) {
const char *dispname_str = id->get_dispname().c_str();
NOTSUPP("Code generation for parameterized local template `%s'",
......@@ -4729,6 +4726,10 @@ namespace Ttcn {
str = mputprintf(str, "/* NOT SUPPORTED: template %s */\n",
dispname_str);
} else {
const string& t_genname = get_genname();
const char *genname_str = t_genname.c_str();
const string& type_genname = type->get_genname_template(my_scope);
const char *type_genname_str = type_genname.c_str();
if (base_template) {
// non-parameterized modified template
if (use_runtime_2 && body->get_needs_conversion()) {
......@@ -4785,8 +4786,6 @@ namespace Ttcn {
void Def_Template::ilt_generate_code(ILT *ilt)
{
const string& t_genname = get_genname();
const char *genname_str = t_genname.c_str();
char*& def=ilt->get_out_def();
char*& init=ilt->get_out_branches();
if (fp_list) {
......@@ -4797,6 +4796,8 @@ namespace Ttcn {
init = mputprintf(init, "/* NOT SUPPORTED: template %s */\n",
dispname_str);
} else {
const string& t_genname = get_genname();
const char *genname_str = t_genname.c_str();
// non-parameterized template
// use the default constructor for initialization
def = mputprintf(def, "%s %s;\n",
......@@ -5113,6 +5114,7 @@ namespace Ttcn {
gen_restriction_check =
initial_value->chk_restriction("template variable definition",
template_restriction, initial_value);
type->chk_this_template_incorrect_field();
if (!semantic_check_only) {
initial_value->set_genname_recursive(get_genname());
initial_value->set_code_section(GovernedSimple::CS_INLINE);
......@@ -5242,10 +5244,10 @@ namespace Ttcn {
const string& t_genname = get_genname();
const char *genname_str = t_genname.c_str();
char*& def=ilt->get_out_def();
char*& init=ilt->get_out_branches();
def = mputprintf(def, "%s %s;\n",
type->get_genname_template(my_scope).c_str(), genname_str);
if (initial_value) {
char*& init=ilt->get_out_branches();
init = initial_value->generate_code_init(init, genname_str);
if (template_restriction!=TR_NONE && gen_restriction_check)
init = Template::generate_restriction_check_code(init, genname_str,
......
......@@ -114,6 +114,7 @@ inline boolean operator!=(Default_Base *default_value,
{ return !(default_value == other_value); }
//FIXME: It is not possible to create default templates (NegSem_15_TopLevel_003)
class DEFAULT_template : public Base_Template {
union {
Default_Base *single_value;
......
......@@ -13,6 +13,7 @@
.* Kovacs, Ferenc
.* Pandi, Krisztian
.* Szabados, Kristof
.* Szabo, Bence Janos
.* Szabo, Janos Zoltan – initial implementation
.* Szalai, Endre
.*
......@@ -810,23 +811,20 @@ module ModuleA {
charstring field2,
MySet field3,
address field4,
MyCT field5,
default field6
MyCT field5
}
template MyRec MyTempE := {?,?,?,?,?,?} // empty parameter list
template MyRec MyTempE := {?,?,?,?,?} // empty parameter list
template MyRec MyTemp (
charstring par_1,
address par_2,
MyCT par_3,
default par_4,
MySet par_5,
template float par_6 ) := {
field1 := par_6,
field2 := par_1,
field3 := par_5,
field4 := par_2,
field5 := par_3,
field6 := par_4
field5 := par_3
}
}
<END_MODULE>
......@@ -1736,8 +1734,6 @@ module ModuleA {
address field42,
MyCT field51,
MyCT field52,
default field61,
default field62,
float field71,
float field72
}
......@@ -1764,10 +1760,6 @@ module ModuleA {
field32 := par_32,
field41 := par_41,
field42 := par_42,
field51 := par_61,
field52 := par_62,
field61 := par_71,
field62 := par_72,
field71 := par_51,
field72 := par_52
}
......@@ -1819,8 +1811,6 @@ module ModuleA {
address field42,
MyCT field51,
MyCT field52,
default field61,
default field62,
float field71,
float field72
}
......@@ -1847,10 +1837,6 @@ module ModuleA {
field32 := par_32,
field41 := par_41,
field42 := par_42,
field51 := par_61,
field52 := par_62,
field61 := par_71,
field62 := par_72,
field71 := par_51,
field72 := par_52
}
......@@ -1931,7 +1917,10 @@ module ModuleA {
<RESULT IF_PASS COUNT 7>
(?im)\berror\b.+?template.+?cannot.+?have.+?inout.+?parameter
<END_RESULT>
<RESULT IF_PASS COUNT 14>
<RESULT IF_PASS COUNT 1>
(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?default
<END_RESULT>
<RESULT IF_PASS COUNT 15>
(?is)\berror:
<END_RESULT>
<RESULT IF_PASS POSITIVE>
......
......@@ -13,6 +13,7 @@
.* Lovassy, Arpad
.* Pandi, Krisztian
.* Szabados, Kristof
.* Szabo, Bence Janos
.* Szabo, Janos Zoltan – initial implementation
.* Szalai, Endre
.* Tatarka, Gabor
......@@ -5154,7 +5155,10 @@ module ModuleA {
<RESULT IF_PASS COUNT 1>
(?im)\berror\b.+?Type.+?mismatch.+?default.+?expected
<END_RESULT>
<RESULT IF_PASS COUNT 3>
<RESULT IF_PASS COUNT 1>
(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?default
<END_RESULT>
<RESULT IF_PASS COUNT 4>
(?is)\berror:
<END_RESULT>
<RESULT IF_PASS POSITIVE>
......
......@@ -17,6 +17,7 @@
.* Palugyai, Sandor
.* Pandi, Krisztian
.* Szabados, Kristof
.* Szabo, Bence Janos
.* Szabo, Janos Zoltan – initial implementation
.* Szalai, Endre
.*
......@@ -1699,7 +1700,10 @@ template default f:= r[0];
<RESULT IF_PASS COUNT 1>
(?im)\bNotify\b.+?\bcode\b.+?\bnot\b.+?\bgenerated\b
<END_RESULT>
<RESULT IF_PASS COUNT 1>
<RESULT IF_PASS COUNT 2>
(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?default
<END_RESULT>
<RESULT IF_PASS COUNT 3>
(?is)\berror:
<END_RESULT>
<END_TC>
......
......@@ -2030,6 +2030,9 @@ module Temp {
(?im)template.+?cannot.+?\bbe\b.+?defined.+?\bfor\b.+?port.+?type
<END_RESULT>
<RESULT COUNT 1>
(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?port
<END_RESULT>
<RESULT COUNT 2>
(?is)\berror:
<END_RESULT>
<RESULT>
......
/******************************************************************************
* 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:
* Szabo, Bence Janos
*
******************************************************************************/
module TempNoDefaultOrPort_SE { //^In TTCN-3 module//
type record MyRecordDefault { //In type \`\@TempNoDefaultOrPort\_SE\.MyRecordDefault\'//
default def //In field \`def\':// //In type \`\@TempNoDefaultOrPort_SE\.MyRecordDefault\.def\'// //A template cannot contain a field with default type at any level//
}
type record MyRecordDefault2 { //In type \`\@TempNoDefaultOrPort\_SE\.MyRecordDefault2\'//
default def //In field \`def\':// //In type \`\@TempNoDefaultOrPort_SE\.MyRecordDefault2\.def\'// //A template cannot contain a field with default type at any level//
}
type record of MyRecordDefault MyRecordOfDefault; //In type \`\@TempNoDefaultOrPort\_SE\.MyRecordOfDefault\'//
type union MyUnion { //In type \`\@TempNoDefaultOrPort\_SE\.MyUnion\'://
integer choice1,
MyRecordOfDefault a, //In field \`a\'://
anytype b //In type \`\@TempNoDefaultOrPort_SE\.anytype\'// //In field \`b\'://
}
template MyUnion m_integerChosen := { //In template definition//
choice1 := 5
}
} with {
extension "anytype MyRecordDefault2" //In field \`MyRecordDefault2\'\://
}
\ No newline at end of file
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