Commit 58f742e6 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed code generated for parameters with type conversion (bug 544978)



Change-Id: I1ffc2b93b7ba249cece1df2f41249d9d2a9e4291
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 0331e0b9
......@@ -15566,8 +15566,12 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
bool Value::has_single_expr_invoke(Value *v, Ttcn::ActualParList *ap_list)
{
if (!v->has_single_expr()) return false;
Value* last_v = v->get_value_refd_last();
const Ttcn::FormalParList* fplist = (last_v->get_valuetype() == V_FUNCTION) ?
last_v->get_refd_fat()->get_FormalParList() : NULL;
for (size_t i = 0; i < ap_list->get_nof_pars(); i++)
if (!ap_list->get_par(i)->has_single_expr()) return false;
if (!ap_list->get_par(i)->has_single_expr(
fplist != NULL ? fplist->get_fp_byIndex(i) : NULL)) return false;
return true;
}
 
......
......@@ -700,8 +700,11 @@ namespace Ttcn {
return false;
}
if (parlist != NULL) {
Common::Assignment* ass = get_refd_assignment();
const FormalParList* fplist = (ass != NULL) ? ass->get_FormalParList() : NULL;
for (size_t i = 0; i < parlist->get_nof_pars(); i++) {
if (!parlist->get_par(i)->has_single_expr()) {
if (!parlist->get_par(i)->has_single_expr(
fplist != NULL ? fplist->get_fp_byIndex(i) : NULL)) {
return false;
}
}
......@@ -1089,18 +1092,17 @@ namespace Ttcn {
bool Ref_pard::has_single_expr()
{
if (!Ref_base::has_single_expr()) return false;
Common::Assignment *ass = get_refd_assignment();
const FormalParList *fplist = (ass != NULL) ? ass->get_FormalParList() : NULL;
for (size_t i = 0; i < parlist.get_nof_pars(); i++)
if (!parlist.get_par(i)->has_single_expr()) return false;
if (!parlist.get_par(i)->has_single_expr(
fplist != NULL ? fplist->get_fp_byIndex(i) : NULL)) return false;
// if any formal parameter has lazy or fuzzy evaluation
Common::Assignment *ass = get_refd_assignment();
if (ass) {
const FormalParList *fplist = ass->get_FormalParList();
if (fplist) {
size_t num_formal = fplist->get_nof_fps();
for (size_t i=0; i<num_formal; ++i) {
const FormalPar *fp = fplist->get_fp_byIndex(i);
if (fp->get_eval_type() != NORMAL_EVAL) return false;
}
if (fplist) {
size_t num_formal = fplist->get_nof_fps();
for (size_t i=0; i<num_formal; ++i) {
const FormalPar *fp = fplist->get_fp_byIndex(i);
if (fp->get_eval_type() != NORMAL_EVAL) return false;
}
}
return true;
......@@ -10240,7 +10242,7 @@ namespace Ttcn {
}
}
bool ActualPar::has_single_expr()
bool ActualPar::has_single_expr(FormalPar* formal_par)
{
switch (selection) {
case AP_VALUE:
......@@ -10260,6 +10262,25 @@ namespace Ttcn {
}
}
}
// check whether type conversion is needed
if (use_runtime_2 && formal_par != NULL &&
formal_par->get_asstype() != Common::Assignment::A_PAR_TIMER &&
formal_par->get_asstype() != Common::Assignment::A_PAR_PORT) {
bool is_template_par = false;
if (formal_par->get_asstype() == Common::Assignment::A_PAR_TEMPL_INOUT ||
formal_par->get_asstype() == Common::Assignment::A_PAR_TEMPL_OUT) {
is_template_par = true;
}
Common::Assignment* ass = ref->get_refd_assignment();
Type* actual_par_type = ass->get_Type()->get_field_type(ref->get_subrefs(),
is_template_par ? Type::EXPECTED_TEMPLATE : Type::EXPECTED_DYNAMIC_VALUE)->
get_type_refd_last();
Type* formal_par_type = formal_par->get_Type()->get_type_refd_last();
if (my_scope->get_scope_mod()->needs_type_conv(
actual_par_type, formal_par_type)) {
return false;
}
}
return ref->has_single_expr();
case AP_DEFAULT:
return !use_runtime_2 || act->selection != AP_TEMPLATE;
......
......@@ -123,7 +123,7 @@ namespace Ttcn {
void chk_recursions(ReferenceChain& refch);
/** Returns whether the actual parameter can be represented by an in-line
* C++ expression. */
bool has_single_expr();
bool has_single_expr(FormalPar* formal_par);
void set_code_section(GovernedSimple::code_section_t p_code_section);
/** Generates the C++ equivalent of \a this into \a expr.
* Flag \a copy_needed indicates whether to add an extra copy constructor
......
......@@ -5306,11 +5306,16 @@ compile_time:
}
// otherwise consider the reference itself
return u.ref.ref->has_single_expr(); }
case TEMPLATE_INVOKE:
case TEMPLATE_INVOKE: {
if (!u.invoke.v->has_single_expr()) return false;
Value* last_v = u.invoke.v->get_value_refd_last();
const FormalParList* fplist =
(last_v->get_valuetype() == Common::Value::V_FUNCTION) ?
last_v->get_refd_fat()->get_FormalParList() : NULL;
for (size_t i = 0; i < u.invoke.ap_list->get_nof_pars(); i++)
if (!u.invoke.ap_list->get_par(i)->has_single_expr()) return false;
return true;
if (!u.invoke.ap_list->get_par(i)->has_single_expr(
fplist != NULL ? fplist->get_fp_byIndex(i) : NULL)) return false;
return true; }
case TEMPLATE_LIST:
return u.templates->get_nof_ts() == 0;
case NAMED_TEMPLATE_LIST: {
......
Bug544978
Bug544978.exe
Bug544978*.cc
Bug544978*.hh
/******************************************************************************
* Copyright (c) 2000-2018 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Balasko, Jeno
* Baranyi, Botond
* Szabo, Bence Janos
*
******************************************************************************/
module Bug544978 {
type record Rec {
integer x
}
type record of Rec RecList1;
type record of Rec RecList2;
function f(inout RecList1 x) return integer {
return 0;
}
control {
var RecList2 x;
if (0 != f(x)) {
log("1");
}
}
}
##############################################################################
# Copyright (c) 2000-2018 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
#
# Contributors:
# Botond, Baranyi
#
##############################################################################
TOPDIR := ../..
include $(TOPDIR)/Makefile.regression
.PHONY: all clean dep
TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
TTCN3_MODULES = Bug544978.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 = Bug544978$(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)
......@@ -37,7 +37,7 @@ CODIRS += mfgen-xsd
endif
ifdef RT2
CODIRS += typeCompat
CODIRS += typeCompat Bug544978
endif
all dep clean distclean:
......
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