Fixed code generated for anytype field references in ispresent clauses (bug 495128)
authorBotond Baranyi <botond.baranyi@ericsson.com>
Thu, 2 Jun 2016 15:20:15 +0000 (17:20 +0200)
committerBotond Baranyi <botond.baranyi@ericsson.com>
Thu, 2 Jun 2016 15:20:15 +0000 (17:20 +0200)
Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
compiler2/Type_codegen.cc
regression_test/ispresent/IsPresent_Test.ttcn

index f6225b8938ae4008a5f3a280742d673a8607ded2..530c2e83763ab6accb15e25de12f11b6e77f3c62 100644 (file)
@@ -2472,10 +2472,10 @@ void Type::generate_code_ispresentbound(expression_struct *expr,
         const string& tmp_id = module->get_temporary_id();
         const char *tmp_id_str = tmp_id.c_str();
         expr->expr = mputprintf(expr->expr,
-          "const %s%s& %s = %s.%s();\n",
+          "const %s%s& %s = %s.%s%s();\n",
           next_t->get_genname_value(module).c_str(),
           is_template?"_template":"", tmp_id_str, tmp_generalid_str,
-          id.get_name().c_str());
+          t->typetype == T_ANYTYPE ? "AT_" : "", id.get_name().c_str());
 
         expr->expr = mputprintf(expr->expr,
           "%s = %s.%s(%s);\n", global_id.c_str(),
index 41a4a7f1c3425919a3a0e441e20cab6450ad531e..60fbb5bfae8145f52d07c53d3bfa70198b858f25 100644 (file)
@@ -838,6 +838,19 @@ type record of MyRec2 MyRecOf
     if(ispresent(t_i(1,2*vl_i))) {setverdict(pass)} else {setverdict(fail)};
     //if(ispresent(t_i(1,2/vl_j))) {setverdict(pass)} else {setverdict(fail)}; //DTE
   }
+  
+  // Test case for:
+  // Bug 495128 - Incorrect code generated for anytype field reference in ispresent clause
+  // The 'ispresent' clauses in this test caused C++ compilation errors, because 
+  // 'x.MyRecord()' was generated instead of 'x.AT_MyRecord()', when accessing the anytype field
+  testcase tc_anytype_field() runs on MTC_CT {
+    var anytype x;
+    x.MyRecord := { i := 1, x := omit, c := "a" };
+    if (ispresent(x.MyRecord.i)) { setverdict(pass); }
+    else { setverdict(fail, "field i should be present"); }
+    if (not ispresent(x.MyRecord.x)) { setverdict(pass); }
+    else { setverdict(fail, "field x should not be present"); }
+  }
 
 
   control {
@@ -929,7 +942,10 @@ type record of MyRec2 MyRecOf
     //execute(tc_runtimeDivisionByZero()); //expected DTE
     //execute(tc_compilationErrorDivisionByZero()); ok!?
     execute(tc_runtimeExprEval());
-
+    execute(tc_anytype_field());
   }
 
 }//module
+with {
+  extension "anytype MyRecord";
+}
This page took 0.025919 seconds and 5 git commands to generate.