Commit 4d1f0398 authored by Botond Baranyi's avatar Botond Baranyi

OOP: the log of a class object no longer contains its members (issue #533)

Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 1de3060f
...@@ -3898,47 +3898,25 @@ namespace Ttcn { ...@@ -3898,47 +3898,25 @@ namespace Ttcn {
// logging function (similar to logging a record value, but with the // logging function (similar to logging a record value, but with the
// class name and the base class' log at the beginning) // class name and the base class' log at the beginning)
// members are no longer logged, as this could cause infinite loops
local_struct->header.class_defs = mputstr(local_struct->header.class_defs, local_struct->header.class_defs = mputstr(local_struct->header.class_defs,
"public:\n" "public:\n"
"virtual void log() const;\n"); "virtual void log() const;\n");
local_struct->source.methods = mputprintf(local_struct->source.methods, local_struct->source.methods = mputprintf(local_struct->source.methods,
"void %s::log() const\n" "void %s::log() const\n"
"{\n" "{\n"
"TTCN_Logger::log_event_str(\"%s: { \");\n", "TTCN_Logger::log_event_str(\"%s%s\");\n",
class_id->get_name().c_str(), class_id->get_dispname().c_str()); class_id->get_name().c_str(), class_id->get_dispname().c_str(), base_type != NULL ? " ( " : "");
bool first_logged = false;
if (base_type != NULL) { if (base_type != NULL) {
local_struct->source.methods = mputprintf(local_struct->source.methods, local_struct->source.methods = mputprintf(local_struct->source.methods,
"%s::log();\n", "%s::log();\n"
"TTCN_Logger::log_event_str(\" )\");\n",
base_type_name.c_str()); base_type_name.c_str());
first_logged = true;
} }
for (size_t i = 0; i < members->get_nof_asss(); ++i) {
Common::Assignment* member = members->get_ass_byIndex(i, false);
switch (member->get_asstype()) {
case Common::Assignment::A_CONST:
case Common::Assignment::A_VAR:
case Common::Assignment::A_TEMPLATE:
case Common::Assignment::A_VAR_TEMPLATE:
case Common::Assignment::A_TIMER: // ?
if (first_logged) {
local_struct->source.methods = mputstr(local_struct->source.methods, local_struct->source.methods = mputstr(local_struct->source.methods,
"TTCN_Logger::log_event_str(\", \");\n");
}
local_struct->source.methods = mputprintf(local_struct->source.methods,
"TTCN_Logger::log_event_str(\"%s := \");\n"
"%s.log();\n",
member->get_id().get_dispname().c_str(), member->get_id().get_name().c_str());
first_logged = true;
break;
default:
break; // don't log anything for methods
}
}
local_struct->source.methods = mputstr(local_struct->source.methods,
"TTCN_Logger::log_event_str(\" }\");\n"
"}\n\n"); "}\n\n");
local_struct->header.class_defs = mputstr(local_struct->header.class_defs, "};\n\n"); local_struct->header.class_defs = mputstr(local_struct->header.class_defs, "};\n\n");
if (external) { if (external) {
......
...@@ -242,9 +242,9 @@ testcase tc_logging() runs on CT { ...@@ -242,9 +242,9 @@ testcase tc_logging() runs on CT {
log(v_sub); log(v_sub);
log(v_final); log(v_final);
var charstring v_base_str := "BaseClass: { m_const := 2, m_const2 := { 1, 2, 1 }, m_var := \"a\", m_temp := *, m_var_temp := (0.000000 .. 10.000000), m_timer := timer: { name: m_timer, default duration: none, state: inactive }, m_timer_array := { timer: { name: m_timer_array[0], default duration: none, state: inactive }, timer: { name: m_timer_array[1], default duration: none, state: inactive }, timer: { name: m_timer_array[2], default duration: none, state: inactive } } }"; var charstring v_base_str := "BaseClass";
var charstring v_sub_str := "SubClass: { BaseClass: { m_const := 2, m_const2 := { 1, 2, 1 }, m_var := \"ax\", m_temp := *, m_var_temp := (0.000000 .. 10.000000), m_timer := timer: { name: m_timer, default duration: none, state: inactive }, m_timer_array := { timer: { name: m_timer_array[0], default duration: none, state: inactive }, timer: { name: m_timer_array[1], default duration: none, state: inactive }, timer: { name: m_timer_array[2], default duration: none, state: inactive } } }, m_const3 := 'FFFF'O }"; var charstring v_sub_str := "SubClass ( BaseClass )";
var charstring v_final_str := "FinalClass: { SubClass: { BaseClass: { m_const := 2, m_const2 := { 1, 2, 1 }, m_var := \"ax\", m_temp := *, m_var_temp := (0.000000 .. 10.000000), m_timer := timer: { name: m_timer, default duration: none, state: inactive }, m_timer_array := { timer: { name: m_timer_array[0], default duration: none, state: inactive }, timer: { name: m_timer_array[1], default duration: none, state: inactive }, timer: { name: m_timer_array[2], default duration: none, state: inactive } } }, m_const3 := 'FFFF'O }, m_final_const := 8, m_final_temp := \"x\", m_final_var := -1.500000, m_final_var_temp := * }"; var charstring v_final_str := "FinalClass ( SubClass ( BaseClass ) )";
if (log2str(v_base) != v_base_str) { if (log2str(v_base) != v_base_str) {
setverdict(fail, "v_base: ", v_base); setverdict(fail, "v_base: ", v_base);
...@@ -463,6 +463,7 @@ type class Node2 { ...@@ -463,6 +463,7 @@ type class Node2 {
var object data; var object data;
var Node2 next; var Node2 next;
public function get_data() return object { return data; } public function get_data() return object { return data; }
public function get_next() return Node2 { return next; }
public function f(in object p) { data := p; } public function f(in object p) { data := p; }
} }
...@@ -520,29 +521,12 @@ testcase tc_object() runs on CT { ...@@ -520,29 +521,12 @@ testcase tc_object() runs on CT {
setverdict(fail, "v_obj2.toString()[3]: ", v_obj2.toString()[3]); setverdict(fail, "v_obj2.toString()[3]: ", v_obj2.toString()[3]);
} }
var Node2 v_node2 := Node2.create(Something.create, Node2.create(Node.create(1, null), null)); var Node2 v_node2 := Node2.create(Something.create, Node2.create(Node.create(1, null), null));
if (log2str(v_node2) != "Node2: { data := Something: { }, next := Node2: { data := Node: { data := 1, next := null }, next := null } }") { if (log2str(v_node2.get_data()) != "Something" or log2str(v_node2.get_next().get_data()) != "Node") {
setverdict(fail, "v_node2: ", v_node2); setverdict(fail, "v_node2: ", v_node2);
} }
setverdict(pass); setverdict(pass);
} }
type class Order {
var integer b;
var integer d;
var integer c;
var integer a;
}
testcase tc_order() runs on CT {
var Order x := Order.create(1, 2, 3, 4);
if (log2str(x) == "Order: { b := 1, d := 2, c := 3, a := 4 }") {
setverdict(pass);
}
else {
setverdict(fail, x);
}
}
testcase tc_abstract() runs on CT { testcase tc_abstract() runs on CT {
var AbstractClass v := ConcreteClass.create; var AbstractClass v := ConcreteClass.create;
var integer x := 0; var integer x := 0;
...@@ -737,7 +721,6 @@ control { ...@@ -737,7 +721,6 @@ control {
execute(tc_function_pars_and_retval()); execute(tc_function_pars_and_retval());
execute(tc_function_pars_in()); execute(tc_function_pars_in());
execute(tc_object()); execute(tc_object());
execute(tc_order());
execute(tc_abstract()); execute(tc_abstract());
execute(tc_destructor()); execute(tc_destructor());
execute(tc_of_operator()); execute(tc_of_operator());
......
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