diff --git a/compiler2/Value.cc b/compiler2/Value.cc index 69eb6ce567692c2ff39232e77ae00ec1cf796957..5191ff06d06e52e2bc43e36e153b9d875248cec7 100644 --- a/compiler2/Value.cc +++ b/compiler2/Value.cc @@ -8831,7 +8831,8 @@ error: Value* Value::get_refd_sub_value(Ttcn::FieldOrArrayRefs *subrefs, size_t start_i, bool usedInIsbound, - ReferenceChain *refch) + ReferenceChain *refch, + bool silent) { if (!subrefs) return this; Value *v = this; @@ -8849,18 +8850,21 @@ error: } // switch Ttcn::FieldOrArrayRef *ref = subrefs->get_ref(i); if (ref->get_type() == Ttcn::FieldOrArrayRef::FIELD_REF) - v = v->get_refd_field_value(*ref->get_id(), usedInIsbound, *ref); - else v = v->get_refd_array_value(ref->get_val(), usedInIsbound, refch); + v = v->get_refd_field_value(*ref->get_id(), usedInIsbound, *ref, silent); + else v = v->get_refd_array_value(ref->get_val(), usedInIsbound, refch, silent); } return v; } Value *Value::get_refd_field_value(const Identifier& field_id, - bool usedInIsbound, const Location& loc) + bool usedInIsbound, const Location& loc, + bool silent) { if (valuetype == V_OMIT) { - loc.error("Reference to field `%s' of omit value `%s'", - field_id.get_dispname().c_str(), get_fullname().c_str()); + if (!silent) { + loc.error("Reference to field `%s' of omit value `%s'", + field_id.get_dispname().c_str(), get_fullname().c_str()); + } return 0; } if (!my_governor) FATAL_ERROR("Value::get_refd_field_value()"); @@ -8874,9 +8878,11 @@ error: case Type::T_OPENTYPE: case Type::T_ANYTYPE: if (!t->has_comp_withName(field_id)) { - loc.error("Reference to non-existent union field `%s' in type `%s'", - field_id.get_dispname().c_str(), t->get_typename().c_str()); - return 0; + if (!silent) { + loc.error("Reference to non-existent union field `%s' in type `%s'", + field_id.get_dispname().c_str(), t->get_typename().c_str()); + } + return 0; } else if (valuetype != V_CHOICE) { // remain silent, the error is already reported return 0; @@ -8884,7 +8890,7 @@ error: // everything is OK return u.choice.alt_value; }else { - if (!usedInIsbound) { + if (!usedInIsbound && !silent) { loc.error("Reference to inactive field `%s' in a value of union type " "`%s'. The active field is `%s'", field_id.get_dispname().c_str(), t->get_typename().c_str(), @@ -8895,9 +8901,11 @@ error: case Type::T_SEQ_A: case Type::T_SEQ_T: if (!t->has_comp_withName(field_id)) { - loc.error("Reference to non-existent record field `%s' in type `%s'", - field_id.get_dispname().c_str(), t->get_typename().c_str()); - return 0; + if (!silent) { + loc.error("Reference to non-existent record field `%s' in type `%s'", + field_id.get_dispname().c_str(), t->get_typename().c_str()); + } + return 0; } else if (valuetype != V_SEQ) { // remain silent, the error has been already reported return 0; @@ -8905,17 +8913,21 @@ error: case Type::T_SET_A: case Type::T_SET_T: if (!t->has_comp_withName(field_id)) { - loc.error("Reference to non-existent set field `%s' in type `%s'", - field_id.get_dispname().c_str(), t->get_typename().c_str()); - return 0; + if (!silent) { + loc.error("Reference to non-existent set field `%s' in type `%s'", + field_id.get_dispname().c_str(), t->get_typename().c_str()); + } + return 0; } else if (valuetype != V_SET) { // remain silent, the error has been already reported return 0; } else break; default: - loc.error("Invalid field reference `%s': type `%s' " - "does not have fields", field_id.get_dispname().c_str(), - t->get_typename().c_str()); + if (!silent) { + loc.error("Invalid field reference `%s': type `%s' " + "does not have fields", field_id.get_dispname().c_str(), + t->get_typename().c_str()); + } return 0; } // the common end for record & set types @@ -8923,7 +8935,7 @@ error: // everything is OK return u.val_nvs->get_nv_byName(field_id)->get_value(); } else if (!is_asn1()) { - if (!usedInIsbound) { + if (!usedInIsbound && !silent) { loc.error("Reference to unbound field `%s'", field_id.get_dispname().c_str()); // this is an error in TTCN-3, which has been already reported @@ -8949,7 +8961,7 @@ error: } Value *Value::get_refd_array_value(Value *array_index, bool usedInIsbound, - ReferenceChain *refch) + ReferenceChain *refch, bool silent) { Value *v_index = array_index->get_value_refd_last(refch); Int index = 0; @@ -8958,13 +8970,15 @@ error: if (v_index->valuetype == V_INT) { index = v_index->get_val_Int()->get_val(); index_available = true; - } else { + } else if (!silent) { array_index->error("An integer value was expected as index"); } } if (valuetype == V_OMIT) { - array_index->error("Accessing an element with index of omit value `%s'", - get_fullname().c_str()); + if (!silent) { + array_index->error("Accessing an element with index of omit value `%s'", + get_fullname().c_str()); + } return 0; } if (!my_governor) FATAL_ERROR("Value::get_refd_field_value()"); @@ -8976,17 +8990,19 @@ error: case Type::T_SEQOF: if (index_available) { if (index < 0) { - array_index->error("A non-negative integer value was expected " - "instead of %s for indexing a value of `record " - "of' type `%s'", Int2string(index).c_str(), - t->get_typename().c_str()); + if (!silent) { + array_index->error("A non-negative integer value was expected " + "instead of %s for indexing a value of `record " + "of' type `%s'", Int2string(index).c_str(), + t->get_typename().c_str()); + } return 0; } switch (valuetype) { case V_SEQOF: if (!is_indexed()) { if (index >= static_cast<Int>(u.val_vs->get_nof_vs())) { - if (!usedInIsbound) { + if (!usedInIsbound && !silent) { array_index->error("Index overflow in a value of `record of' " "type `%s': the index is %s, but the value " "has only %lu elements", @@ -8997,7 +9013,7 @@ error: return 0; } else { Value* temp = u.val_vs->get_v_byIndex(index); - if(temp->get_value_refd_last()->get_valuetype() == V_NOTUSED) + if(!silent && temp->get_value_refd_last()->get_valuetype() == V_NOTUSED) temp->error("Not used symbol is not allowed in this context"); return u.val_vs->get_v_byIndex(index); } @@ -9024,16 +9040,18 @@ error: case Type::T_SETOF: if (index_available) { if (index < 0) { - array_index->error("A non-negative integer value was expected " - "instead of %s for indexing a value of `set of' type `%s'", - Int2string(index).c_str(), t->get_typename().c_str()); + if (!silent) { + array_index->error("A non-negative integer value was expected " + "instead of %s for indexing a value of `set of' type `%s'", + Int2string(index).c_str(), t->get_typename().c_str()); + } return 0; } switch (valuetype) { case V_SETOF: if (!is_indexed()) { if (index >= static_cast<Int>(u.val_vs->get_nof_vs())) { - if (!usedInIsbound) { + if (!usedInIsbound && !silent) { array_index->error("Index overflow in a value of `set of' type " "`%s': the index is %s, but the value has " "only %lu elements", @@ -9044,7 +9062,7 @@ error: return 0; } else { Value* temp = u.val_vs->get_v_byIndex(index); - if(temp->get_value_refd_last()->get_valuetype() == V_NOTUSED) + if(!silent && temp->get_value_refd_last()->get_valuetype() == V_NOTUSED) temp->error("Not used symbol is not allowed in this context"); return temp; } @@ -9123,8 +9141,10 @@ error: if (index_available) return get_string_element(index, *array_index); else return 0; default: - array_index->error("Invalid array element reference: type `%s' cannot " - "be indexed", t->get_typename().c_str()); + if (!silent) { + array_index->error("Invalid array element reference: type `%s' cannot " + "be indexed", t->get_typename().c_str()); + } return 0; } } diff --git a/compiler2/Value.hh b/compiler2/Value.hh index 59feef3ee85dd1911af4859c4df5f6c1999809cc..5ee2d21a307dcf8ae890c5405c3771a13fae591e 100644 --- a/compiler2/Value.hh +++ b/compiler2/Value.hh @@ -486,7 +486,8 @@ namespace Common { Type::expected_value_t exp_val=Type::EXPECTED_DYNAMIC_VALUE); Value *get_refd_sub_value(Ttcn::FieldOrArrayRefs *subrefs, size_t start_i, bool usedInIsbound, - ReferenceChain *refch); + ReferenceChain *refch, + bool silent = false); /** Returns true if the value is unknown at compile-time. */ bool is_unfoldable (ReferenceChain *refch=0, @@ -674,9 +675,9 @@ namespace Common { bool evaluate_isvalue(bool from_sequence); Value *get_refd_field_value(const Identifier& field_id, bool usedInIsbound, - const Location& loc); + const Location& loc, bool silent); Value *get_refd_array_value(Value *array_index, bool usedInIsbound, - ReferenceChain *refch); + ReferenceChain *refch, bool silent); Value *get_string_element(const Int& index, const Location& loc); public: diff --git a/compiler2/ttcn3/Statement.cc b/compiler2/ttcn3/Statement.cc index bb7ae1bc6de23d033e410b961d340ffdb9835466..6d8e73c36decb75e3d39c1513dec0f0abaa680e6 100644 --- a/compiler2/ttcn3/Statement.cc +++ b/compiler2/ttcn3/Statement.cc @@ -6379,7 +6379,7 @@ error: // Calculate the head expression only once const string& tmp_id = my_sb->get_scope_mod_gen()->get_temporary_id(); - char * head_expr = mputprintf(head_expr, "const %s &%s = %s;\n", + char * head_expr = mprintf("const %s &%s = %s;\n", select.expr->get_my_governor()->get_genname_value(select.expr->get_my_scope()).c_str(), tmp_id.c_str(), expr_name); @@ -7038,7 +7038,9 @@ error: expr->expr = mputprintf(expr->expr, ".%s(", opname); if (port_op.r.rcvpar) { // The receive parameter is present. - port_op.r.rcvpar->generate_code(expr); + bool has_decoded_redirect = port_op.r.redirect.value != NULL && + port_op.r.redirect.value->has_decoded_modifier(); + port_op.r.rcvpar->generate_code(expr, TR_NONE, has_decoded_redirect); expr->expr = mputstr(expr->expr, ", "); if (port_op.r.redirect.value) { // Value redirect is also present. @@ -7117,11 +7119,8 @@ error: if (port_op.r.rcvpar) { bool has_decoded_param_redirect = port_op.r.redirect.param != NULL && port_op.r.redirect.param->has_decoded_modifier(); - bool has_decoded_value_redirect = port_op.r.redirect.value != NULL && - port_op.r.redirect.value->has_decoded_modifier(); // the signature template is present - port_op.r.rcvpar->generate_code(expr, TR_NONE, - has_decoded_param_redirect || has_decoded_value_redirect); + port_op.r.rcvpar->generate_code(expr, TR_NONE, has_decoded_param_redirect); Type *signature = port_op.r.rcvpar->get_Template()->get_my_governor(); Type *return_type = signature->get_type_refd_last()->get_signature_return_type(); @@ -7129,7 +7128,10 @@ error: expr->expr = mputstr(expr->expr, ".set_value_template("); if (port_op.r.getreply_valuematch) { // the value match is also present - port_op.r.getreply_valuematch->generate_code(expr); + bool has_decoded_value_redirect = port_op.r.redirect.value != NULL && + port_op.r.redirect.value->has_decoded_modifier(); + port_op.r.getreply_valuematch->generate_code(expr, TR_NONE, + has_decoded_value_redirect); } else { // the value match is not present // we must substitute it with ? in the signature template @@ -9332,10 +9334,9 @@ error: } const char* subrefs_str = (subrefs_expr.expr != NULL) ? subrefs_expr.expr : ""; if (v[i]->is_decoded()) { - // set the usedInIsbound parameter to true so get_refd_sub_template does not - // report errors for missing fields/elements + // set the silent parameter to 'true', so no errors are displayed Template* matched_temp = matched_ti->get_Template()->get_refd_sub_template( - v[i]->get_subrefs(), true, NULL); + v[i]->get_subrefs(), false, NULL, true); if (matched_temp != NULL) { matched_temp = matched_temp->get_template_refd_last(); } diff --git a/compiler2/ttcn3/TtcnTemplate.cc b/compiler2/ttcn3/TtcnTemplate.cc index 8d786184edb56f3ed30db911a190fd0189da96fd..73c1fb939a930fab4845be6788fab58323298a7e 100644 --- a/compiler2/ttcn3/TtcnTemplate.cc +++ b/compiler2/ttcn3/TtcnTemplate.cc @@ -1332,7 +1332,8 @@ namespace Ttcn { Template* Template::get_refd_sub_template(Ttcn::FieldOrArrayRefs *subrefs, bool usedInIsbound, - ReferenceChain *refch) + ReferenceChain *refch, + bool silent) { if (!subrefs) return this; Template *t=this; @@ -1349,7 +1350,7 @@ namespace Ttcn { return this; case SPECIFIC_VALUE: (void)t->u.specific_value->get_refd_sub_value( - subrefs, i, usedInIsbound, refch); // only to report errors + subrefs, i, usedInIsbound, refch, silent); // only to report errors break; default: break; @@ -1357,8 +1358,9 @@ namespace Ttcn { Ttcn::FieldOrArrayRef *ref=subrefs->get_ref(i); if(ref->get_type() == Ttcn::FieldOrArrayRef::FIELD_REF) t=t->get_refd_field_template(*ref->get_id(), *ref, usedInIsbound, - refch); - else t=t->get_refd_array_template(ref->get_val(), usedInIsbound, refch); + refch, silent); + else t=t->get_refd_array_template(ref->get_val(), usedInIsbound, refch, + silent); } return t; } @@ -1426,7 +1428,7 @@ namespace Ttcn { } Template* Template::get_refd_field_template(const Identifier& field_id, - const Location& loc, bool usedInIsbound, ReferenceChain *refch) + const Location& loc, bool usedInIsbound, ReferenceChain *refch, bool silent) { switch (templatetype) { case OMIT_VALUE: @@ -1436,9 +1438,11 @@ namespace Ttcn { case COMPLEMENTED_LIST: // the above template types are valid matching mechanisms, // but they cannot be sub-referenced - loc.error("Reference to field `%s' of %s `%s'", - field_id.get_dispname().c_str(), get_templatetype_str(), - get_fullname().c_str()); + if (!silent) { + loc.error("Reference to field `%s' of %s `%s'", + field_id.get_dispname().c_str(), get_templatetype_str(), + get_fullname().c_str()); + } break; default: break; @@ -1455,8 +1459,10 @@ namespace Ttcn { case Type::T_OPENTYPE: case Type::T_ANYTYPE: if (!t->has_comp_withName(field_id)) { - loc.error("Reference to non-existent union field `%s' in type `%s'", - field_id.get_dispname().c_str(), t->get_typename().c_str()); + if (!silent) { + loc.error("Reference to non-existent union field `%s' in type `%s'", + field_id.get_dispname().c_str(), t->get_typename().c_str()); + } return 0; } else if (templatetype != NAMED_TEMPLATE_LIST) { // this is an invalid matching mechanism, the error is already reported @@ -1470,7 +1476,7 @@ namespace Ttcn { } else { NamedTemplate *nt = u.named_templates->get_nt_byIndex(0); if (nt->get_name() != field_id) { - if (!usedInIsbound) { + if (!usedInIsbound && !silent) { loc.error("Reference to inactive field `%s' in a template of" " union type `%s'. The active field is `%s'.", field_id.get_dispname().c_str(), @@ -1490,9 +1496,11 @@ namespace Ttcn { case Type::T_SET_A: case Type::T_SET_T: if (!t->has_comp_withName(field_id)) { - loc.error("Reference to non-existent %s field `%s' in type `%s'", - typetype_str, field_id.get_dispname().c_str(), - t->get_typename().c_str()); + if (!silent) { + loc.error("Reference to non-existent %s field `%s' in type `%s'", + typetype_str, field_id.get_dispname().c_str(), + t->get_typename().c_str()); + } return 0; } else if (templatetype != NAMED_TEMPLATE_LIST) { // this is an invalid matching mechanism @@ -1504,9 +1512,9 @@ namespace Ttcn { } else if (base_template) { // take the field from the base template (recursively) return base_template->get_template_refd_last(refch) - ->get_refd_field_template(field_id, loc, usedInIsbound, refch); + ->get_refd_field_template(field_id, loc, usedInIsbound, refch, silent); } else { - if (!usedInIsbound) { + if (!usedInIsbound && !silent) { // this should not happen unless there is an error // (e.g. missing field) loc.error("Reference to an unbound field `%s'", @@ -1515,16 +1523,19 @@ namespace Ttcn { return 0; } default: - loc.error("Invalid field reference `%s': type `%s' " - "does not have fields", field_id.get_dispname().c_str(), - t->get_typename().c_str()); + if (!silent) { + loc.error("Invalid field reference `%s': type `%s' " + "does not have fields", field_id.get_dispname().c_str(), + t->get_typename().c_str()); + } return 0; } } Template* Template::get_refd_array_template(Value *array_index, bool usedInIsbound, - ReferenceChain *refch) + ReferenceChain *refch, + bool silent) { switch (templatetype) { case OMIT_VALUE: @@ -1536,8 +1547,10 @@ namespace Ttcn { case SUBSET_MATCH: // the above template types are valid matching mechanisms, // but they cannot be sub-referenced - array_index->error("Reference with index to an element of %s `%s'", - get_templatetype_str(), get_fullname().c_str()); + if (!silent) { + array_index->error("Reference with index to an element of %s `%s'", + get_templatetype_str(), get_fullname().c_str()); + } break; default: break; @@ -1549,7 +1562,7 @@ namespace Ttcn { if (v_index->get_valuetype() == Value::V_INT) { index = v_index->get_val_Int()->get_val(); index_available = true; - } else { + } else if (!silent) { array_index->error("An integer value was expected as index"); } } @@ -1566,10 +1579,12 @@ namespace Ttcn { case Type::T_SETOF: if (index_available) { if(index < 0) { - array_index->error("A non-negative integer value was expected " - "instead of %s for indexing a template of `%s of' type `%s'", - Int2string(index).c_str(), typetype_str, - t->get_typename().c_str()); + if (!silent) { + array_index->error("A non-negative integer value was expected " + "instead of %s for indexing a template of `%s of' type `%s'", + Int2string(index).c_str(), typetype_str, + t->get_typename().c_str()); + } return 0; } else if (templatetype != TEMPLATE_LIST) { // remain silent the error has been already reported @@ -1577,10 +1592,12 @@ namespace Ttcn { } else { size_t nof_elements = get_nof_listitems(); if (index >= static_cast<Int>(nof_elements)) { - array_index->error("Index overflow in a template of `%s of' type " - "`%s': the index is %s, but the template has only %lu elements", - typetype_str, t->get_typename().c_str(), - Int2string(index).c_str(), (unsigned long) nof_elements); + if (!silent) { + array_index->error("Index overflow in a template of `%s of' type " + "`%s': the index is %s, but the template has only %lu elements", + typetype_str, t->get_typename().c_str(), + Int2string(index).c_str(), (unsigned long) nof_elements); + } return 0; } } @@ -1609,8 +1626,10 @@ namespace Ttcn { } break; default: - array_index->error("Invalid array element reference: type `%s' cannot " - "be indexed", t->get_typename().c_str()); + if (!silent) { + array_index->error("Invalid array element reference: type `%s' cannot " + "be indexed", t->get_typename().c_str()); + } return 0; } Template *ret_val = get_listitem_byIndex(index); @@ -1618,9 +1637,9 @@ namespace Ttcn { if (base_template) { // take the referred element from the base template return base_template->get_template_refd_last(refch) - ->get_refd_array_template(v_index, usedInIsbound, refch); + ->get_refd_array_template(v_index, usedInIsbound, refch, silent); } else { - if(ret_val->get_templatetype() == TEMPLATE_NOTUSED) + if(!silent && ret_val->get_templatetype() == TEMPLATE_NOTUSED) error("Not used symbol is not allowed in this context"); return 0; } @@ -5325,7 +5344,7 @@ compile_time: // after it const string& tmp_id = template_body->get_temporary_id(); const char *tmp_id_str = tmp_id.c_str(); - expr->preamble = mputprintf(expr->preamble, "%s %s(%s);\n", + expr->preamble = mputprintf(expr->preamble, "%s %s = %s;\n", template_body->get_my_governor()->get_genname_template( template_body->get_my_scope()).c_str(), tmp_id_str, expr->expr); Free(expr->expr); diff --git a/compiler2/ttcn3/TtcnTemplate.hh b/compiler2/ttcn3/TtcnTemplate.hh index 7a686459102296cdf802b211fca2e44bbe2bd757..2742ffb60bb979912eb1f2914b1019f9b5da47c6 100644 --- a/compiler2/ttcn3/TtcnTemplate.hh +++ b/compiler2/ttcn3/TtcnTemplate.hh @@ -298,15 +298,16 @@ namespace Ttcn { Template* get_template_refd_last(ReferenceChain *refch=0); Template* get_refd_sub_template(Ttcn::FieldOrArrayRefs *subrefs, bool usedInIsbound, - ReferenceChain *refch); + ReferenceChain *refch, + bool silent = false); Value* get_string_encoding() const; TemplateInstance* get_decode_target() const; private: Template* get_template_refd(ReferenceChain *refch); Template* get_refd_field_template(const Identifier& field_id, - const Location& loc, bool usedInIsbound, ReferenceChain *refch); + const Location& loc, bool usedInIsbound, ReferenceChain *refch, bool silent); Template* get_refd_array_template(Value *array_index, bool usedInIsbound, - ReferenceChain *refch); + ReferenceChain *refch, bool silent); bool compile_time() const; public: