Skip to content
Snippets Groups Projects
Commit 0bf78d39 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed variables of recursive altsteps (#754)


Signed-off-by: default avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 6a9187ce
No related branches found
No related tags found
1 merge request!512Fixed variables of recursive altsteps (#754)
......@@ -6463,10 +6463,15 @@ namespace Ttcn {
str = mputstr(str, expr.preamble);
}
if (altstep_main_def) {
str = mputprintf(str, "static Lazy_Fuzzy_Var< %s > %s(%s);\n",
str = mputprintf(str, "Lazy_Fuzzy_Var< %s > %s(%s);\n",
type_name.c_str(), genname_str, eval == FUZZY_EVAL ? "TRUE" : "FALSE");
if (initial_value != NULL) {
str = mputprintf(str, "if (first_alt_run) %s = %s;\n", genname_str, expr.expr);
str = mputprintf(str,
"static Lazy_Fuzzy_Var< %s > %s_init(%s);\n"
"if (first_alt_run) %s_init = %s;\n"
"%s = %s_init;\n",
type_name.c_str(), genname_str, eval == FUZZY_EVAL ? "TRUE" : "FALSE",
genname_str, expr.expr, genname_str, genname_str);
}
}
else {
......@@ -6482,20 +6487,26 @@ namespace Ttcn {
type_name.c_str(), genname_str, initial_value->get_single_expr().c_str());
} else {
// use the default constructor
str = mputprintf(str, "%s%s %s;\n",
altstep_main_def ? "static " : "", type_name.c_str(), genname_str);
str = mputprintf(str, "%s %s;\n", type_name.c_str(), genname_str);
if (initial_value) {
// the initial value is assigned using subsequent statements
string address_postfix;
if (type->is_address() && !initial_value->has_single_expr()) {
address_postfix = "()";
}
string init_name = t_genname;
if (altstep_main_def) {
str = mputstr(str, "if (first_alt_run) {\n");
init_name += "_init";
str = mputprintf(str,
"static %s %s;\n"
"if (first_alt_run) {\n",
type_name.c_str(), init_name.c_str());
}
str = initial_value->generate_code_init(str, (t_genname + address_postfix).c_str());
str = initial_value->generate_code_init(str, (init_name + address_postfix).c_str());
if (altstep_main_def) {
str = mputstr(str, "}\n");
str = mputprintf(str,
"}\n"
"%s = %s;\n", genname_str, init_name.c_str());
}
}
}
......@@ -6890,10 +6901,15 @@ namespace Ttcn {
str = mputstr(str, expr.preamble);
}
if (altstep_main_def) {
str = mputprintf(str, "static Lazy_Fuzzy_Var< %s > %s(%s);\n",
str = mputprintf(str, "Lazy_Fuzzy_Var< %s > %s(%s);\n",
type_name.c_str(), genname_str, eval == FUZZY_EVAL ? "TRUE" : "FALSE");
if (initial_value != NULL) {
str = mputprintf(str, "if (first_alt_run) %s = %s;\n", genname_str, expr.expr);
str = mputprintf(str,
"static Lazy_Fuzzy_Var< %s > %s_init(%s);\n"
"if (first_alt_run) %s_init = %s;\n"
"%s = %s_init;\n",
type_name.c_str(), genname_str, eval == FUZZY_EVAL ? "TRUE" : "FALSE",
genname_str, expr.expr, genname_str, genname_str);
}
}
else {
......@@ -6909,21 +6925,28 @@ namespace Ttcn {
type_name.c_str(), genname_str, initial_value->get_single_expr(false).c_str());
} else {
// Use the default constructor.
str = mputprintf(str, "%s%s %s;\n", altstep_main_def ? "static " : "", type_name.c_str(), genname_str);
str = mputprintf(str, "%s %s;\n", type_name.c_str(), genname_str);
if (initial_value) {
// The initial value is assigned using subsequent statements.
string address_postfix;
if (type->is_address() && !initial_value->has_single_expr()) {
address_postfix = "()";
}
string init_name = t_genname;
if (altstep_main_def) {
str = mputstr(str, "if (first_alt_run) {\n");
init_name += "_init";
str = mputprintf(str,
"static %s %s;\n"
"if (first_alt_run) {\n",
type_name.c_str(), init_name.c_str());
}
if (use_runtime_2 && TypeConv::needs_conv_refd(initial_value))
str = TypeConv::gen_conv_code_refd(str, genname_str, initial_value);
else str = initial_value->generate_code_init(str, (t_genname + address_postfix).c_str());
str = TypeConv::gen_conv_code_refd(str, init_name.c_str(), initial_value);
else str = initial_value->generate_code_init(str, (init_name.c_str() + address_postfix).c_str());
if (altstep_main_def) {
str = mputstr(str, "}\n");
str = mputprintf(str,
"}\n"
"%s = %s;\n", genname_str, init_name.c_str());
}
}
}
......
......@@ -12,12 +12,18 @@
module altstep_test {
type port PT message {
inout integer
}
with { extension "internal" }
type component CT {
var integer counter1 := 0;
var integer counter2 := 0;
var integer counter3 := 0;
timer t1 := 0.5;
timer t2 := 1.0;
port PT pt;
}
function f1() runs on CT return integer {
......@@ -25,7 +31,7 @@ function f1() runs on CT return integer {
return counter1;
}
function f2() runs on CT return template integer {
function f2() runs on CT return integer {
counter2 := counter2 + 1;
return counter2;
}
......@@ -41,8 +47,9 @@ function f3() runs on CT return template integer {
altstep as() runs on CT {
var integer v := f1();
const integer c := 100;
template integer t := f2();
template integer t := 3;
var template integer vt := f3();
var @lazy integer vl := f2();
[t1.running] t1.timeout {
if (v != 1) {
setverdict(fail, "v: ", v);
......@@ -50,11 +57,14 @@ altstep as() runs on CT {
if (c != 100) {
setverdict(fail, "c: ", c);
}
if (not isvalue(t) or valueof(t) != 1) {
if (not isvalue(t) or valueof(t) != 3) {
setverdict(fail, "t: ", t);
}
if (not isvalue(vt) or valueof(vt) != 1) {
setverdict(fail, "vt: ", t);
setverdict(fail, "vt: ", vt);
}
if (vl != 1) {
setverdict(fail, "vl: ", vl);
}
}
}
......@@ -81,9 +91,47 @@ testcase tc_altstep_first_run_activate() runs on CT {
setverdict(pass);
}
altstep as2() runs on CT {
var integer v;
var template integer vt;
var template @fuzzy integer vtf;
[] pt.receive(integer: ?) -> value v {
var integer local := v;
vt := local + 1;
vtf := local + f1();
timer tmr := 0.2;
tmr.start;
tmr.timeout; // recursive call (since this altstep is activated as default)
if (v != local) {
setverdict(fail, "v: ", v, ", original message: ", local);
}
if (not isvalue(vt) or valueof(vt) != local + 1) {
setverdict(fail, "vt: ", vt, ", original message + 1: ", local + 1);
}
var integer vtf_val := valueof(vtf);
var integer vtf_exp := local + counter1;
if (vtf_val != vtf_exp) {
setverdict(fail, "vtf: ", vtf_val, ", expected: ", vtf_exp);
}
}
}
testcase tc_altstep_recursive() runs on CT {
connect(self:pt, self:pt);
activate(as2());
pt.send(1);
pt.send(2);
pt.send(3);
timer tmr := 2.0;
tmr.start;
tmr.timeout;
setverdict(pass);
}
control {
execute(tc_altstep_first_run());
execute(tc_altstep_first_run_activate());
execute(tc_altstep_recursive());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment