added any2unistr predefined function (artf724008)
authorebensza <bence.janos.szabo@ericsson.com>
Thu, 21 Apr 2016 16:24:18 +0000 (18:24 +0200)
committerebensza <bence.janos.szabo@ericsson.com>
Thu, 21 Apr 2016 16:30:01 +0000 (18:30 +0200)
Signed-off-by: ebensza <bence.janos.szabo@ericsson.com>
compiler2/Value.cc
compiler2/Value.hh
compiler2/ttcn3/compiler.l
compiler2/ttcn3/compiler.y
regression_test/ucharstrOper/Any2Unistr.ttcn [new file with mode: 0644]
regression_test/ucharstrOper/Makefile
regression_test/ucharstrOper/config.cfg
regression_test/uidChars/compile [deleted file]

index 3fb3b9838b5c96d734a0a4ae725ce20e58f5e4b4..2ffffb894306c0d27bf69ffcef0c6badb3c54d6b 100644 (file)
@@ -340,6 +340,7 @@ namespace Common {
         u.expr.v3 = p.u.expr.v3 ? p.u.expr.v3->clone() : 0;
         break;
       case OPTYPE_LOG2STR:
+      case OPTYPE_ANY2UNISTR:
         u.expr.logargs = p.u.expr.logargs->clone();
         break;
       default:
@@ -647,6 +648,7 @@ namespace Common {
       delete u.expr.v3;
       break;
     case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR:
       delete u.expr.logargs;
       break;
     default:
@@ -1215,6 +1217,7 @@ namespace Common {
     u.expr.state = EXPR_NOT_CHECKED;
     switch(p_optype) {
     case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR:
       if (!p_logargs) FATAL_ERROR("Value::Value()");
       u.expr.logargs = p_logargs;
       break;
@@ -1640,6 +1643,9 @@ namespace Common {
     case OPTYPE_LOG2STR:
       u.expr.logargs->set_fullname(p_fullname+".<logargs>");
       break;
+    case OPTYPE_ANY2UNISTR:
+      u.expr.logargs->set_fullname(p_fullname+".<logarg>");
+      break;
     default:
       FATAL_ERROR("Value::set_fullname_expr()");
     } // switch
@@ -1828,6 +1834,7 @@ namespace Common {
        u.expr.v3->set_my_scope(p_scope);
       break;
     case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR:
       u.expr.logargs->set_my_scope(p_scope);
       break;
     default:
@@ -2152,6 +2159,7 @@ namespace Common {
           u.expr.v3->set_code_section(p_code_section);
       break;
       case OPTYPE_LOG2STR:
+      case OPTYPE_ANY2UNISTR:
         u.expr.logargs->set_code_section(p_code_section);
         break;
       default:
@@ -3131,6 +3139,7 @@ namespace Common {
       case OPTYPE_INT2UNICHAR:
       case OPTYPE_OCT2UNICHAR:
       case OPTYPE_ENCVALUE_UNICHAR:
+      case OPTYPE_ANY2UNISTR:
         return Type::T_USTR;
       case OPTYPE_INT2BIT:
       case OPTYPE_HEX2BIT:
@@ -3578,6 +3587,8 @@ namespace Common {
       return "isbound()";
     case OPTYPE_LOG2STR:
       return "log2str()";
+    case OPTYPE_ANY2UNISTR:
+      return "any2unistr()";
     case OPTYPE_TTCN2STRING:
       return "ttcn2string()";
     case OPTYPE_PROF_RUNNING:
@@ -5402,7 +5413,8 @@ void Value::chk_expr_operand_execute_refd(Value *v1,
   void Value::chk_expr_operand_encode(ReferenceChain *refch,
     Type::expected_value_t exp_val) {
 
-    Error_Context cntxt(this, "In the parameter of encvalue()");
+    Error_Context cntxt(this, "In the parameter of %s",
+      u.expr.v_optype == OPTYPE_ENCVALUE_UNICHAR ? "encvalue_unichar()" : "encvalue()");
     Type t_chk(Type::T_ERROR);
     Type* t_type;
 
@@ -5461,7 +5473,8 @@ error:
 
   void Value::chk_expr_operands_decode(operationtype_t p_optype)
   {
-    Error_Context cntxt(this, "In the parameters of decvalue()"); //todo
+    Error_Context cntxt(this, "In the parameters of %s",
+      p_optype == OPTYPE_DECVALUE_UNICHAR ? "encvalue_unichar()" : "decvalue()");
     Ttcn::Ref_base* ref = u.expr.r1;
     Ttcn::FieldOrArrayRefs* t_subrefs = ref->get_subrefs();
     Type* t_type = 0;
@@ -7115,7 +7128,8 @@ error:
       }
       chk_expr_operands_replace();
       break; }
-    case OPTYPE_LOG2STR: {
+    case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR: {
       Error_Context cntxt(this, "In the operand of operation `%s'", opname);
       u.expr.logargs->chk();
       if (!semantic_check_only) u.expr.logargs->join_strings();
@@ -7184,6 +7198,7 @@ error:
     case OPTYPE_MATCH: // v1 t2
     case OPTYPE_ISCHOSEN_T:
     case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR:
     case OPTYPE_ENCODE:
     case OPTYPE_DECODE:
     case OPTYPE_ISBOUND:
@@ -8627,6 +8642,7 @@ error:
       case OPTYPE_ISCHOSEN_V:
         return u.expr.v1->is_unfoldable(refch, exp_val);
       case OPTYPE_LOG2STR:
+      case OPTYPE_ANY2UNISTR:
       case OPTYPE_TTCN2STRING:
         return true;
       default:
@@ -9840,6 +9856,7 @@ error:
       refch.prev_state();
       break;
     case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR:
       u.expr.logargs->chk_recursions(refch);
       break;
     default:
@@ -10140,14 +10157,16 @@ error:
       // boolvar := a_timer.running -- assume no self-ref
       break;
       break;
-
+      
+    case OPTYPE_ANY2UNISTR:
     case OPTYPE_LOG2STR: {// logargs
       for (size_t i = 0, e = u.expr.logargs->get_nof_logargs(); i < e; ++i) {
         const Ttcn::LogArgument *la = u.expr.logargs->get_logarg_byIndex(i);
         switch (la->get_type()) {
         case Ttcn::LogArgument::L_UNDEF:
         case Ttcn::LogArgument::L_ERROR:
-          FATAL_ERROR("log2str argument type");
+          FATAL_ERROR("%s argument type",
+            u.expr.v_optype == OPTYPE_ANY2UNISTR ? "any2unistr" : "log2str");
           break; // not reached
 
         case Ttcn::LogArgument::L_MACRO:
@@ -10617,6 +10636,8 @@ error:
        return ret_val; }
       case OPTYPE_LOG2STR:
         return string("log2str(...)");
+      case OPTYPE_ANY2UNISTR:
+        return string("any2unistr(...)");     
       case OPTYPE_MATCH: {
         string ret_val("match(");
         ret_val += u.expr.v1->get_stringRepr();
@@ -12006,6 +12027,7 @@ error:
       generate_code_expr_execute_refd(expr);
       break;
     case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR:
       u.expr.logargs->generate_code_expr(expr);
       break;
     case OPTYPE_TTCN2STRING: {
@@ -13580,6 +13602,7 @@ void Value::generate_code_expr_encvalue_unichar(expression_struct *expr)
     case OPTYPE_VALUEOF: // ti1
       return u.expr.ti1->has_single_expr();
     case OPTYPE_LOG2STR:
+    case OPTYPE_ANY2UNISTR:
       return u.expr.logargs->has_single_expr();
     case OPTYPE_MATCH: // v1 t2
       return u.expr.v1->has_single_expr() &&
index dd75c42fcdf010d4c574427663a8eca62cb8dcaf..549ad1abe9ba205352bdd414f1ef8f092a61780f 100644 (file)
@@ -258,11 +258,13 @@ namespace Common {
       OPTYPE_EXECUTE, // r1 [v2]
       OPTYPE_EXECUTE_REFD, // v1 t_list2 [v3]
 
-      OPTYPE_LOG2STR, // logagrs
+      OPTYPE_LOG2STR, // logargs
       OPTYPE_PROF_RUNNING, // -     99
       
       OPTYPE_ENCVALUE_UNICHAR, // ti1 [v2]
       OPTYPE_DECVALUE_UNICHAR, // r1 r2 [v3]
+      
+      OPTYPE_ANY2UNISTR, // logarg, length = 1
 
       NUMBER_OF_OPTYPES // must be last
     };
index 47682da8d6aabc169535b8217f5f9acb8920ce74..210fe7d3bdfee11ec2de41b86c6916a110e67979 100644 (file)
@@ -587,6 +587,7 @@ encode_base64       RETURN(encode_base64KeyWord);
 decode_base64  RETURN(decode_base64KeyWord);
 encvalue_unichar RETURN(encvalue_unicharKeyWord);
 decvalue_unichar RETURN(decvalue_unicharKeyWord);
+any2unistr      RETURN(any2unistrKeyWord);
 
        /* Values */
 
index f6f16f3d81536fe82a1e2147c6000c6f6fa56d88..32ce893a1c8951b469cb79139a61e4f15f0f4f69 100644 (file)
@@ -834,6 +834,7 @@ static const string anyname("anytype");
 %token decode_base64KeyWord
 %token encvalue_unicharKeyWord
 %token decvalue_unicharKeyWord
+%token any2unistrKeyWord
 
 /* Multi-character operators */
 
@@ -8726,6 +8727,20 @@ PredefinedOps:
     $$ = new Value(Value::OPTYPE_LOG2STR, new LogArguments());
     $$->set_location(infile, @$);
   }
+| any2unistrKeyWord '(' LogItemList optError ')'
+  {
+    if ($3->get_nof_logargs() != 1) {
+      Location loc(infile, @1);
+      loc.error("The any2unistr function takes exactly one argument, not %lu.",
+        $3->get_nof_logargs());
+        delete $3;
+        $$ = new Value(Value::OPTYPE_ANY2UNISTR, new LogArguments());
+        $$->set_location(infile, @$);
+    } else {
+      $$ = new Value(Value::OPTYPE_ANY2UNISTR, $3);
+      $$->set_location(infile, @$);
+    }
+  }
 | testcasenameKeyword '(' ')'
   {
     $$ = new Value(Value::OPTYPE_TESTCASENAME);
diff --git a/regression_test/ucharstrOper/Any2Unistr.ttcn b/regression_test/ucharstrOper/Any2Unistr.ttcn
new file mode 100644 (file)
index 0000000..af30eb5
--- /dev/null
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * Copyright (c) 2000-2016 Ericsson Telecom AB
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Szabo, Bence Janos – initial implementation
+ *
+ ******************************************************************************/
+module Any2Unistr
+{
+   
+    type component EmptyCT {}
+       testcase tc_any2unistr() runs on EmptyCT {
+               var integer v_int1 := 5, v_int2;
+               var template integer vmw_int1 := ?;
+               var template integer vmw_int2 := -1 ifpresent;
+               var universal charstring v_chr1, v_chr2, v_chr3, v_chr4;
+               v_chr1 := any2unistr(v_int1); // after the assignment v_chr1 will be "5"
+               v_chr2 := any2unistr(v_int2); // after the assignment v_chr2 will be "<unbound>"
+               v_chr3 := any2unistr(vmw_int1); // after the assignment v_chr3 will be "?"
+               v_chr4 := any2unistr(vmw_int2); // after the assignment v_chr3 will be "-1 ifpresent" 
+
+               var universal charstring v_chr1_exp, v_chr2_exp, v_chr3_exp, v_chr4_exp;
+               v_chr1_exp := "5";
+               v_chr2_exp := "<unbound>";
+               v_chr3_exp := "?";
+               v_chr4_exp := "-1 ifpresent";
+
+               if(match(v_chr1,v_chr1_exp) and match(v_chr2,v_chr2_exp) and
+                  match(v_chr3,v_chr3_exp) and match(v_chr4,v_chr4_exp)) {
+                 setverdict(pass);
+               } else {
+                 setverdict(fail);
+               }
+       }
+
+    control
+    {
+           execute(tc_any2unistr());
+    }
+}
index 2b40fb98552916da2f1593a22de54930138009c9..bdc679af67641f1e9cfbce3ccc70cebf606ebdfe 100644 (file)
@@ -9,6 +9,7 @@
 #   Balasko, Jeno
 #   Kovacs, Ferenc
 #   Raduly, Csaba
+#   Szabo, Bence Janos
 #   Zalanyi, Balazs Andor
 #
 ##############################################################################
@@ -20,7 +21,8 @@ include $(TOPDIR)/Makefile.regression
 
 TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
 
-TTCN3_MODULES = TucharstrOper.ttcn cstr_content.ttcn Common.ttcn UTF8Testcases.ttcn UTF16Testcases.ttcn UTF32Testcases.ttcn Base64Testcases.ttcn EncDecvalueUnichar.ttcn
+TTCN3_MODULES = TucharstrOper.ttcn cstr_content.ttcn Common.ttcn UTF8Testcases.ttcn UTF16Testcases.ttcn UTF32Testcases.ttcn \
+                Base64Testcases.ttcn EncDecvalueUnichar.ttcn Any2Unistr.ttcn
 
 GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc)
 GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
index f50ffe85e42d7c00076444f6d71546bfe2c0baef..aa6e1346f8746c83b0feca91906adb687200b106 100644 (file)
@@ -8,6 +8,7 @@
 # Contributors:
 #   Balasko, Jeno
 #   Kovacs, Ferenc
+#   Szabo, Bence Janos
 #   Zalanyi, Balazs Andor
 #
 ###############################################################################
@@ -31,3 +32,4 @@ UTF16Testcases.control
 UTF32Testcases.control
 Base64Testcases.control
 EncDecvalueUnichar.control
+Any2Unistr.control
diff --git a/regression_test/uidChars/compile b/regression_test/uidChars/compile
deleted file mode 100644 (file)
index e69de29..0000000
This page took 0.036094 seconds and 5 git commands to generate.