Debugger - Stage 2 (artf511247)
[deliverable/titan.core.git] / core / Objid.cc
index 79fe281c049b46672d53435b627e9f6140abce91..beab7b3e7203feb68de56146b5cc954082f9de2e 100644 (file)
@@ -1,10 +1,25 @@
-///////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2000-2014 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
-///////////////////////////////////////////////////////////////////////////////
+/******************************************************************************
+ * 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:
+ *   Balasko, Jeno
+ *   Baranyi, Botond
+ *   Beres, Szabolcs
+ *   Delic, Adam
+ *   Forstner, Matyas
+ *   Kovacs, Ferenc
+ *   Raduly, Csaba
+ *   Szabados, Kristof
+ *   Szabo, Bence Janos
+ *   Szabo, Janos Zoltan – initial implementation
+ *   Szalai, Gabor
+ *   Tatarka, Gabor
+ *
+ ******************************************************************************/
 #include "Objid.hh"
 
 #include "../common/dbgnew.hh"
@@ -215,11 +230,25 @@ void OBJID::log() const
 
 void OBJID::set_param(Module_Param& param) {
   param.basic_check(Module_Param::BC_VALUE, "objid value");
-  if (param.get_type()!=Module_Param::MP_Objid) param.type_error("objid value");
+  Module_Param_Ptr mp = &param;
+  if (param.get_type() == Module_Param::MP_Reference) {
+    mp = param.get_referenced_param();
+  }
+  if (mp->get_type()!=Module_Param::MP_Objid) param.type_error("objid value");
   if (sizeof(objid_element)!=sizeof(int)) TTCN_error("Internal error: OBJID::set_param()");
   clean_up();
-  init_struct(param.get_string_size());
-  memcpy(val_ptr->components_ptr, param.get_string_data(), val_ptr->n_components * sizeof(objid_element));
+  init_struct(mp->get_string_size());
+  memcpy(val_ptr->components_ptr, mp->get_string_data(), val_ptr->n_components * sizeof(objid_element));
+}
+
+Module_Param* OBJID::get_param(Module_Param_Name& /* param_name */) const
+{
+  if (!is_bound()) {
+    return new Module_Param_Unbound();
+  }
+  int* val_cpy = (int *)Malloc(val_ptr->n_components);
+  memcpy(val_cpy, val_ptr->components_ptr, val_ptr->n_components * sizeof(int));
+  return new Module_Param_Objid(val_ptr->n_components, val_cpy);
 }
 
 void OBJID::encode_text(Text_Buf& text_buf) const
@@ -311,7 +340,7 @@ void OBJID::decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf,
       if (type==XML_READER_TYPE_ELEMENT)
        break;
     }
-    XER_decode(*p_td.xer, reader, XER_coding, 0);
+    XER_decode(*p_td.xer, reader, XER_coding, XER_NONE, 0);
     size_t bytes = reader.ByteConsumed();
     p_buf.set_pos(bytes);
     break;}
@@ -526,7 +555,7 @@ void OBJID::from_string(char* p_str)
 }
 
 int OBJID::XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
-                 unsigned int flavor, embed_values_dec_struct_t*)
+                 unsigned int flavor, unsigned int /*flavor2*/, embed_values_dec_struct_t*)
 {
   int exer  = is_exer(flavor);
   int success = reader.Ok(), depth = -1;
@@ -742,7 +771,7 @@ OBJID_template& OBJID_template::operator=(const OBJID_template& other_value)
   return *this;
 }
 
-boolean OBJID_template::match(const OBJID& other_value) const
+boolean OBJID_template::match(const OBJID& other_value, boolean /* legacy */) const
 {
   if (!other_value.is_bound()) return FALSE;
   switch (template_selection) {
@@ -854,7 +883,8 @@ void OBJID_template::log() const
   log_ifpresent();
 }
 
-void OBJID_template::log_match(const OBJID& match_value) const
+void OBJID_template::log_match(const OBJID& match_value,
+                               boolean /* legacy */) const
 {
   if (TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()
   &&  TTCN_Logger::get_logmatch_buffer_len() != 0) {
@@ -870,7 +900,11 @@ void OBJID_template::log_match(const OBJID& match_value) const
 
 void OBJID_template::set_param(Module_Param& param) {
   param.basic_check(Module_Param::BC_TEMPLATE, "objid template");
-  switch (param.get_type()) {
+  Module_Param_Ptr mp = &param;
+  if (param.get_type() == Module_Param::MP_Reference) {
+    mp = param.get_referenced_param();
+  }
+  switch (mp->get_type()) {
   case Module_Param::MP_Omit:
     *this = OMIT_VALUE;
     break;
@@ -881,15 +915,18 @@ void OBJID_template::set_param(Module_Param& param) {
     *this = ANY_OR_OMIT;
     break;
   case Module_Param::MP_List_Template:
-  case Module_Param::MP_ComplementList_Template:
-    set_type(param.get_type()==Module_Param::MP_List_Template ? VALUE_LIST : COMPLEMENTED_LIST, param.get_size());
-    for (size_t i=0; i<param.get_size(); i++) {
-      list_item(i).set_param(*param.get_elem(i));
+  case Module_Param::MP_ComplementList_Template: {
+    OBJID_template temp;
+    temp.set_type(mp->get_type() == Module_Param::MP_List_Template ?
+      VALUE_LIST : COMPLEMENTED_LIST, mp->get_size());
+    for (size_t i=0; i<mp->get_size(); i++) {
+      temp.list_item(i).set_param(*mp->get_elem(i));
     }
-    break;
+    *this = temp;
+    break; }
   case Module_Param::MP_Objid:
     if (sizeof(OBJID::objid_element)!=sizeof(int)) TTCN_error("Internal error: OBJID_template::set_param()"); 
-    *this = OBJID(param.get_string_size(), (OBJID::objid_element*)param.get_string_data());
+    *this = OBJID(mp->get_string_size(), (OBJID::objid_element*)mp->get_string_data());
     break;
   //case Module_Param::MP_Objid_Template:
   // TODO
@@ -897,7 +934,47 @@ void OBJID_template::set_param(Module_Param& param) {
   default:
     param.type_error("objid template");
   }
-  is_ifpresent = param.get_ifpresent();
+  is_ifpresent = param.get_ifpresent() || mp->get_ifpresent();
+}
+
+Module_Param* OBJID_template::get_param(Module_Param_Name& param_name) const
+{
+  Module_Param* mp = NULL;
+  switch (template_selection) {
+  case UNINITIALIZED_TEMPLATE:
+    mp = new Module_Param_Unbound();
+    break;
+  case OMIT_VALUE:
+    mp = new Module_Param_Omit();
+    break;
+  case ANY_VALUE:
+    mp = new Module_Param_Any();
+    break;
+  case ANY_OR_OMIT:
+    mp = new Module_Param_AnyOrNone();
+    break;
+  case SPECIFIC_VALUE:
+    mp = single_value.get_param(param_name);
+    break;
+  case VALUE_LIST:
+  case COMPLEMENTED_LIST: {
+    if (template_selection == VALUE_LIST) {
+      mp = new Module_Param_List_Template();
+    }
+    else {
+      mp = new Module_Param_ComplementList_Template();
+    }
+    for (size_t i = 0; i < value_list.n_values; ++i) {
+      mp->add_elem(value_list.list_value[i].get_param(param_name));
+    }
+    break; }
+  default:
+    break;
+  }
+  if (is_ifpresent) {
+    mp->set_ifpresent();
+  }
+  return mp;
 }
 
 void OBJID_template::encode_text(Text_Buf& text_buf) const
@@ -948,13 +1025,13 @@ void OBJID_template::decode_text(Text_Buf& text_buf)
   }
 }
 
-boolean OBJID_template::is_present() const
+boolean OBJID_template::is_present(boolean legacy /* = FALSE */) const
 {
   if (template_selection==UNINITIALIZED_TEMPLATE) return FALSE;
-  return !match_omit();
+  return !match_omit(legacy);
 }
 
-boolean OBJID_template::match_omit() const
+boolean OBJID_template::match_omit(boolean legacy /* = FALSE */) const
 {
   if (is_ifpresent) return TRUE;
   switch (template_selection) {
@@ -963,10 +1040,14 @@ boolean OBJID_template::match_omit() const
     return TRUE;
   case VALUE_LIST:
   case COMPLEMENTED_LIST:
-    for (unsigned int i=0; i<value_list.n_values; i++)
-      if (value_list.list_value[i].match_omit())
-        return template_selection==VALUE_LIST;
-    return template_selection==COMPLEMENTED_LIST;
+    if (legacy) {
+      // legacy behavior: 'omit' can appear in the value/complement list
+      for (unsigned int i=0; i<value_list.n_values; i++)
+        if (value_list.list_value[i].match_omit())
+          return template_selection==VALUE_LIST;
+      return template_selection==COMPLEMENTED_LIST;
+    }
+    // else fall through
   default:
     return FALSE;
   }
@@ -974,7 +1055,8 @@ boolean OBJID_template::match_omit() const
 }
 
 #ifndef TITAN_RUNTIME_2
-void OBJID_template::check_restriction(template_res t_res, const char* t_name) const
+void OBJID_template::check_restriction(template_res t_res, const char* t_name,
+                                       boolean legacy /* = FALSE */) const
 {
   if (template_selection==UNINITIALIZED_TEMPLATE) return;
   switch ((t_name&&(t_res==TR_VALUE))?TR_OMIT:t_res) {
@@ -986,7 +1068,7 @@ void OBJID_template::check_restriction(template_res t_res, const char* t_name) c
         template_selection==SPECIFIC_VALUE)) return;
     break;
   case TR_PRESENT:
-    if (!match_omit()) return;
+    if (!match_omit(legacy)) return;
     break;
   default:
     return;
This page took 0.026577 seconds and 5 git commands to generate.