fixed Segfault in decmatch confomance test cases (artf764443)
[deliverable/titan.core.git] / compiler2 / Value.cc
index 2fe448ea9d8dce0c4267b9cd6fb1db9cbba602b1..56a05debd9441488a562d67e3a32a0b7a0936572 100644 (file)
@@ -211,6 +211,9 @@ namespace Common {
       case OPTYPE_REMOVE_BOM:
         u.expr.v1=p.u.expr.v1->clone();
         break;
+      case OPTYPE_HOSTID: // [v1]
+        u.expr.v1=p.u.expr.v1?p.u.expr.v1->clone():0;
+        break;
       case OPTYPE_ADD: // v1 v2
       case OPTYPE_SUBTRACT:
       case OPTYPE_MULTIPLY:
@@ -528,6 +531,7 @@ namespace Common {
     case OPTYPE_REMOVE_BOM:
     case OPTYPE_GET_STRINGENCODING:
     case OPTYPE_DECODE_BASE64:
+    case OPTYPE_HOSTID:
       delete u.expr.v1;
       break;
     case OPTYPE_ADD: // v1 v2
@@ -922,6 +926,9 @@ namespace Common {
       if(!p_v1) FATAL_ERROR("Value::Value()");
       u.expr.v1=p_v1;
       break;
+    case OPTYPE_HOSTID:
+      u.expr.v1=p_v1;
+      break;
     default:
       FATAL_ERROR("Value::Value()");
     } // switch
@@ -945,6 +952,8 @@ namespace Common {
     case OPTYPE_TTCN2STRING:
       if(!p_ti1) FATAL_ERROR("Value::Value()");
       u.expr.ti1=p_ti1;
+      // Needed in the case of OPTYPE_ENCVALUE_UNICHAR
+      u.expr.v2=NULL;
       break;
     default:
       FATAL_ERROR("Value::Value()");
@@ -1335,6 +1344,8 @@ namespace Common {
       if(!p_r1 || !p_r2) FATAL_ERROR("Value::Value()");
       u.expr.r1=p_r1;
       u.expr.r2=p_r2;
+      // Needed in the case of OPTYPE_DECVALUE_UNICHAR
+      u.expr.v3=NULL;
       break;
     default:
       FATAL_ERROR("Value::Value()");
@@ -1534,6 +1545,9 @@ namespace Common {
     case OPTYPE_DECODE_BASE64:
       u.expr.v1->set_fullname(p_fullname+".<operand>");
       break;
+    case OPTYPE_HOSTID: // [v1]
+      if(u.expr.v1) u.expr.v1->set_fullname(p_fullname+".<operand>");
+      break;
     case OPTYPE_ADD: // v1 v2
     case OPTYPE_SUBTRACT:
     case OPTYPE_MULTIPLY:
@@ -1729,6 +1743,9 @@ namespace Common {
     case OPTYPE_DECODE_BASE64:
       u.expr.v1->set_my_scope(p_scope);
       break;
+    case OPTYPE_HOSTID: // [v1]
+      if(u.expr.v1) u.expr.v1->set_my_scope(p_scope);
+      break;
     case OPTYPE_ADD: // v1 v2
     case OPTYPE_SUBTRACT:
     case OPTYPE_MULTIPLY:
@@ -2054,6 +2071,9 @@ namespace Common {
       case OPTYPE_REMOVE_BOM:
         u.expr.v1->set_code_section(p_code_section);
         break;
+      case OPTYPE_HOSTID: // [v1]
+        if(u.expr.v1) u.expr.v1->set_code_section(p_code_section);
+        break;
       case OPTYPE_ADD: // v1 v2
       case OPTYPE_SUBTRACT:
       case OPTYPE_MULTIPLY:
@@ -3167,6 +3187,7 @@ namespace Common {
       case OPTYPE_TTCN2STRING:
       case OPTYPE_GET_STRINGENCODING:
       case OPTYPE_ENCODE_BASE64:
+      case OPTYPE_HOSTID:
         return Type::T_CSTR;
       case OPTYPE_INT2UNICHAR:
       case OPTYPE_OCT2UNICHAR:
@@ -3530,6 +3551,8 @@ namespace Common {
       return "encode_base64()";
     case OPTYPE_DECODE_BASE64:
       return "decode_base64()";
+    case OPTYPE_HOSTID: // [v1]
+      return "hostid()";
     case OPTYPE_ADD: // v1 v2
       return "+";
     case OPTYPE_SUBTRACT:
@@ -6592,6 +6615,17 @@ error:
         chk_expr_val_ustr_7bitchars(v1, the, opname);
       }
       break;
+    case OPTYPE_HOSTID:
+      v1=u.expr.v1 ? u.expr.v1 : 0;
+      if (v1)
+      {
+        Error_Context cntxt(this, "In the first operand of operation `%s'", opname);
+        v1->set_lowerid_to_ref();
+        tt1=v1->get_expr_returntype(exp_val);
+        chk_expr_operandtype_cstr(tt1, second, opname, v1);
+        chk_expr_eval_value(v1, t_chk, refch, exp_val);
+      }
+      break;
     case OPTYPE_UNICHAR2OCT: // v1 [v2]
       v1=u.expr.v1;
       {
@@ -7268,6 +7302,7 @@ error:
     case OPTYPE_DECVALUE_UNICHAR:
     case OPTYPE_CHECKSTATE_ANY:
     case OPTYPE_CHECKSTATE_ALL:
+    case OPTYPE_HOSTID:
       break;
     case OPTYPE_TESTCASENAME: { // -
       if (!my_scope) FATAL_ERROR("Value::evaluate_value()");
@@ -8568,6 +8603,7 @@ error:
       case OPTYPE_DECVALUE_UNICHAR:
       case OPTYPE_CHECKSTATE_ANY:
       case OPTYPE_CHECKSTATE_ALL:
+      case OPTYPE_HOSTID:
         return true;
       case OPTYPE_COMP_NULL: // -
         return false;
@@ -9782,6 +9818,13 @@ error:
       u.expr.t1->chk_recursions(refch);
       refch.prev_state();
       break;
+    case OPTYPE_HOSTID: // [v1]
+      if (u.expr.v1) {
+        refch.mark_state();
+        u.expr.v1->chk_recursions(refch);
+        refch.prev_state();
+      }
+      break;
     case OPTYPE_ADD: // v1 v2
     case OPTYPE_SUBTRACT:
     case OPTYPE_MULTIPLY:
@@ -10046,6 +10089,9 @@ error:
       break; // self-ref can't happen
     case Ttcn::Template::TEMPLATE_INVOKE:
       break; // assume self-ref can't happen
+    case Ttcn::Template::DECODE_MATCH:
+      self_ref |= chk_expr_self_ref_templ(t->get_decode_target()->get_Template(), lhs);
+      break;
     case Ttcn::Template::TEMPLATE_ERROR:
       //FATAL_ERROR("Value::chk_expr_self_ref_templ()");
       break;
@@ -10068,7 +10114,7 @@ error:
       }
     }
     return gov->chk_this_value(v, lhs, Type::EXPECTED_DYNAMIC_VALUE,
-      INCOMPLETE_NOT_ALLOWED, OMIT_NOT_ALLOWED, NO_SUB_CHK, NOT_IMPLICIT_OMIT,
+      INCOMPLETE_NOT_ALLOWED, OMIT_ALLOWED, NO_SUB_CHK, NOT_IMPLICIT_OMIT,
       is_str_elem);
   }
 
@@ -10140,6 +10186,9 @@ error:
     case OPTYPE_REMOVE_BOM:
       self_ref |= chk_expr_self_ref_val(u.expr.v1, lhs);
       break;
+    case OPTYPE_HOSTID: // [v1]
+      if (u.expr.v1) self_ref |= chk_expr_self_ref_val(u.expr.v1, lhs);
+      break;
     case OPTYPE_ADD: // v1 v2
     case OPTYPE_SUBTRACT: // v1 v2
     case OPTYPE_MULTIPLY: // v1 v2
@@ -10520,6 +10569,10 @@ error:
          if (u.expr.v2) return create_stringRepr_predef2("encvalue_unichar");
          else return create_stringRepr_predef1("encvalue_unichar");
       }
+      case OPTYPE_HOSTID: {
+        if (u.expr.v1) return create_stringRepr_predef1("hostid");   
+        else return string("hostid()");
+      }
       case OPTYPE_DECVALUE_UNICHAR: {
          if (u.expr.v3) {
            string ret_val("decvalue_unichar");
@@ -11475,13 +11528,14 @@ error:
         break;
       case OPTYPE_DECODE: {
         Ttcn::ActualParList *parlist = u.expr.r1->get_parlist();
-        Common::Assignment *ass = u.expr.r1->get_refd_assignment();
         if (parlist) str = parlist->rearrange_init_code(str, usage_mod);
 
         parlist = u.expr.r2->get_parlist();
-        ass = u.expr.r2->get_refd_assignment();
         if (parlist) str = parlist->rearrange_init_code(str, usage_mod);
         break; }
+      case OPTYPE_HOSTID:    
+        if (u.expr.v1) str = u.expr.v1->rearrange_init_code(str, usage_mod);
+        break;
       case OPTYPE_ADD:
       case OPTYPE_SUBTRACT:
       case OPTYPE_MULTIPLY:
@@ -11791,6 +11845,9 @@ error:
     case OPTYPE_DECVALUE_UNICHAR:
         generate_code_expr_decvalue_unichar(expr);
       break;
+    case OPTYPE_HOSTID:
+      generate_code_expr_hostid(expr);
+      break;
     case OPTYPE_OCT2HEX:
       generate_code_expr_predef1(expr, "oct2hex", u.expr.v1);
       break;
@@ -12921,6 +12978,14 @@ void Value::generate_code_expr_encvalue_unichar(expression_struct *expr)
     expr->expr = mputstr(expr->expr, ")");
   }
   
+  void Value::generate_code_expr_hostid(expression_struct *expr)
+  {
+    expr->expr = mputstr(expr->expr, "TTCN_Runtime::get_host_address(");
+    if (u.expr.v1) u.expr.v1->generate_code_expr_mandatory(expr);
+    else expr->expr = mputstr(expr->expr, "CHARSTRING(\"Ipv4orIpv6\")");
+    expr->expr = mputstr(expr->expr, ")");
+  }
+  
   char* Value::generate_code_char_coding_check(expression_struct *expr, Value *v, const char *name)
   {
     expression_struct expr2;
@@ -13599,6 +13664,7 @@ void Value::generate_code_expr_encvalue_unichar(expression_struct *expr)
     case OPTYPE_PROF_RUNNING:
     case OPTYPE_CHECKSTATE_ANY:
     case OPTYPE_CHECKSTATE_ALL:
+    case OPTYPE_HOSTID:
       return true;
     case OPTYPE_ENCODE:
     case OPTYPE_DECODE:
This page took 0.033299 seconds and 5 git commands to generate.