Debugger - Stage 3 (artf511247)
[deliverable/titan.core.git] / compiler2 / ttcn3 / AST_ttcn3.cc
index b720bcb0be34372452c1edb1714f1d375d5eb1d7..6859e36cc11c7b90c97f61bc1d2e7e2f15091a43 100644 (file)
@@ -617,10 +617,10 @@ namespace Ttcn {
     return true;
   }
   
-  void Reference::refd_param_usage_found()
+  void Reference::ref_usage_found()
   {
     Common::Assignment *ass = get_refd_assignment();
-    if (!ass) FATAL_ERROR("Reference::refd_param_usage_found()");
+    if (!ass) FATAL_ERROR("Reference::ref_usage_found()");
     switch (ass->get_asstype()) {
     case Common::Assignment::A_PAR_VAL_OUT:
     case Common::Assignment::A_PAR_TEMPL_OUT:
@@ -632,9 +632,18 @@ namespace Ttcn {
     case Common::Assignment::A_PAR_PORT:
     case Common::Assignment::A_PAR_TIMER: {
       FormalPar *fpar = dynamic_cast<FormalPar*>(ass);
-      if (!fpar) FATAL_ERROR("Reference::refd_param_usage_found()");
+      if (fpar == NULL) {
+        FATAL_ERROR("Reference::ref_usage_found()");
+      }
       fpar->set_usage_found();
       break; }
+    case Common::Assignment::A_EXT_CONST: {
+      Def_ExtConst* def = dynamic_cast<Def_ExtConst*>(ass);
+      if (def == NULL) {
+        FATAL_ERROR("Reference::ref_usage_found()");
+      }
+      def->set_usage_found();
+      break; }
     default:
       break;
     }
@@ -642,7 +651,7 @@ namespace Ttcn {
 
   void Reference::generate_code(expression_struct_t *expr)
   {
-    refd_param_usage_found();
+    ref_usage_found();
     Common::Assignment *ass = get_refd_assignment();
     if (!ass) FATAL_ERROR("Reference::generate_code()");
     if (parlist) {
@@ -670,7 +679,7 @@ namespace Ttcn {
       return;
     }
     
-    refd_param_usage_found();
+    ref_usage_found();
     Common::Assignment *ass = get_refd_assignment();
     if (!ass) FATAL_ERROR("Reference::generate_code_const_ref()");
 
@@ -731,7 +740,7 @@ namespace Ttcn {
   void Reference::generate_code_portref(expression_struct_t *expr,
     Scope *p_scope)
   {
-    refd_param_usage_found();
+    ref_usage_found();
     Common::Assignment *ass = get_refd_assignment();
     if (!ass) FATAL_ERROR("Reference::generate_code_portref()");
     expr->expr = mputstr(expr->expr,
@@ -743,7 +752,7 @@ namespace Ttcn {
   void Reference::generate_code_ispresentbound(expression_struct_t *expr,
     bool is_template, const bool isbound)
   {
-    refd_param_usage_found();
+    ref_usage_found();
     Common::Assignment *ass = get_refd_assignment();
     const string& ass_id = ass->get_genname_from_scope(my_scope);
     const char *ass_id_str = ass_id.c_str();
@@ -1674,10 +1683,6 @@ namespace Ttcn {
   {
     target->header.includes = mputstr(target->header.includes,
       "#include <TTCN3.hh>\n");
-    /*if (debugger_active) {
-      target->header.includes = mputstr(target->header.includes,
-        "#include \"init_debug.inc\"\n");
-    }*/
     for (size_t i = 0; i < impmods_v.size(); i++) {
       ImpMod *im = impmods_v[i];
       Common::Module *m = im->get_mod();
@@ -2819,12 +2824,14 @@ namespace Ttcn {
   
   void Module::generate_debugger_init(output_struct* output)
   {
+    static boolean first = TRUE;
     // create the initializer function
-    output->source.global_vars = mputstr(output->source.global_vars,
-      "\n/* Initializing TTCN-3 debugger */\n"
+    output->source.global_vars = mputprintf(output->source.global_vars,
+      "\n/* Initializing the TTCN-3 debugger */\n"
       "void init_ttcn3_debugger()\n"
       "{\n"
-      /*"  debugger_manual_init();\n"*/);
+      "%s", first ? "  ttcn3_debugger.activate();\n" : "");
+    first = FALSE;
     
     // initialize global scope and variables (including imported variables)
     char* str_glob = generate_debugger_global_vars(NULL, this);
@@ -2883,11 +2890,19 @@ namespace Ttcn {
         }
         // else fall through
       case Common::Assignment::A_CONST:
-      //case Common::Assignment::A_EXT_CONST: TODO: handle unused ext_const
       case Common::Assignment::A_MODULEPAR:
       case Common::Assignment::A_MODULEPAR_TEMP:
         str = generate_code_debugger_add_var(str, ass, current_mod, "global");
         break;
+      case Common::Assignment::A_EXT_CONST: {
+        Def_ExtConst* def = dynamic_cast<Def_ExtConst*>(ass);
+        if (def == NULL) {
+          FATAL_ERROR("Module::generate_debugger_global_vars");
+        }
+        if (def->is_used()) {
+          str = generate_code_debugger_add_var(str, ass, current_mod, "global");
+        }
+        break; }
       default:
         break;
       }
@@ -2897,7 +2912,8 @@ namespace Ttcn {
   
   void Module::generate_debugger_functions(output_struct *output)
   {
-    char* str = NULL;
+    char* print_str = NULL;
+    char* overwrite_str = NULL;
     for (size_t i = 0; i < asss->get_nof_asss(); ++i) {
       Def_Type* def = dynamic_cast<Def_Type*>(asss->get_ass_byIndex(i));
       if (def != NULL) {
@@ -2905,41 +2921,74 @@ namespace Ttcn {
         if (!t->is_ref() && t->get_typetype() != Type::T_COMPONENT) {
           // don't generate code for subtypes
           if (t->get_typetype() != Type::T_SIGNATURE) {
-            str = mputprintf(str, 
+            print_str = mputprintf(print_str, 
               "  %sif (!strcmp(p_var.type_name, \"%s\")) {\n"
-              "    ((const %s*)p_var.value)->log();\n"
+              "    ((const %s*)ptr)->log();\n"
               "  }\n"
-              , (str != NULL) ? "else " : ""
+              , (print_str != NULL) ? "else " : ""
               , t->get_dispname().c_str(), t->get_genname_value(this).c_str());
+            if (t->get_typetype() != Type::T_PORT) {
+              overwrite_str = mputprintf(overwrite_str,
+                "  %sif (!strcmp(p_var.type_name, \"%s\")) {\n"
+                "    ((%s*)p_var.value)->set_param(p_new_value);\n"
+                "  }\n"
+                , (overwrite_str != NULL) ? "else " : ""
+                , t->get_dispname().c_str(), t->get_genname_value(this).c_str());
+            }
           }
           if (t->get_typetype() != Type::T_PORT) {
-            str = mputprintf(str,
+            print_str = mputprintf(print_str,
               "  %sif (!strcmp(p_var.type_name, \"%s template\")) {\n"
-              "    ((const %s_template*)p_var.value)->log();\n"
+              "    ((const %s_template*)ptr)->log();\n"
               "  }\n"
-              , (str != NULL) ? "else " : ""
+              , (print_str != NULL) ? "else " : ""
               , t->get_dispname().c_str(), t->get_genname_value(this).c_str());
+            if (t->get_typetype() != Type::T_SIGNATURE) {
+              overwrite_str = mputprintf(overwrite_str,
+                "  %sif (!strcmp(p_var.type_name, \"%s template\")) {\n"
+                "    ((%s_template*)p_var.value)->set_param(p_new_value);\n"
+                "  }\n"
+                , (overwrite_str != NULL) ? "else " : ""
+                , t->get_dispname().c_str(), t->get_genname_value(this).c_str());
+            }
           }
         }
       }
     }
-    if (str != NULL) {
+    if (print_str != NULL) {
       // don't generate an empty printing function
       output->header.class_defs = mputprintf(output->header.class_defs,
-        "/* Debugger printing function for types declared in this module */\n\n"
+        "/* Debugger printing and overwriting functions for types declared in this module */\n\n"
         "extern CHARSTRING print_var_%s(const TTCN3_Debugger::variable_t& p_var);\n",
         get_modid().get_ttcnname().c_str());
       output->source.global_vars = mputprintf(output->source.global_vars,
         "\n/* Debugger printing function for types declared in this module */\n"
         "CHARSTRING print_var_%s(const TTCN3_Debugger::variable_t& p_var)\n"
         "{\n"
+        "  const void* ptr = p_var.set_function != NULL ? p_var.value : p_var.cvalue;\n"
         "  TTCN_Logger::begin_event_log2str();\n"
         "%s"
         "  else {\n"
         "    TTCN_Logger::log_event_str(\"<unrecognized value or template>\");\n"
         "  }\n"
         "  return TTCN_Logger::end_event_log2str();\n"
-        "}\n", get_modid().get_ttcnname().c_str(), str);
+        "}\n", get_modid().get_ttcnname().c_str(), print_str);
+    }
+    if (overwrite_str != NULL) {
+      // don't generate an empty overwriting function
+      output->header.class_defs = mputprintf(output->header.class_defs,
+        "extern boolean set_var_%s(TTCN3_Debugger::variable_t& p_var, Module_Param& p_new_value);\n",
+        get_modid().get_ttcnname().c_str());
+      output->source.global_vars = mputprintf(output->source.global_vars,
+        "\n/* Debugger overwriting function for types declared in this module */\n"
+        "boolean set_var_%s(TTCN3_Debugger::variable_t& p_var, Module_Param& p_new_value)\n"
+        "{\n"
+        "%s"
+        "  else {\n"
+        "    return FALSE;\n"
+        "  }\n"
+        "  return TRUE;\n"
+        "}\n", get_modid().get_ttcnname().c_str(), overwrite_str);
     }
   }
 
@@ -3559,6 +3608,7 @@ namespace Ttcn {
     if (!p_type) FATAL_ERROR("Ttcn::Def_ExtConst::Def_ExtConst()");
     type = p_type;
     type->set_ownertype(Type::OT_CONST_DEF, this);
+    usage_found = false;
   }
 
   Def_ExtConst::~Def_ExtConst()
@@ -7526,6 +7576,9 @@ namespace Ttcn {
         "timer_value);\n");
     body = create_location_object(body, "TESTCASE", dispname_str);
     body = fp_list->generate_shadow_objects(body);
+    if (debugger_active) {
+      body = generate_code_debugger_function_init(body, this);
+    }
     body = mputprintf(body, "try {\n"
       "TTCN_Runtime::begin_testcase(\"%s\", \"%s\", ",
       my_scope->get_scope_mod()->get_modid().get_dispname().c_str(),
@@ -7537,9 +7590,6 @@ namespace Ttcn {
       body = system_type->get_CompBody()->generate_code_comptype_name(body);
     else body = runs_on_body->generate_code_comptype_name(body);
     body = mputstr(body, ", has_timer, timer_value);\n");
-    if (debugger_active) {
-      body = generate_code_debugger_function_init(body, this);
-    }
     body = block->generate_code(body);
     body = mputprintf(body,
       "} catch (const TC_Error& tc_error) {\n"
@@ -9512,7 +9562,7 @@ namespace Ttcn {
           // check if the reference is a parameter, mark it as used if it is
           Reference* ref = dynamic_cast<Reference*>(val->get_reference());
           if (ref != NULL) {
-            ref->refd_param_usage_found();
+            ref->ref_usage_found();
           }
         }
       } else {
@@ -9544,7 +9594,7 @@ namespace Ttcn {
           Reference* ref = dynamic_cast<Reference*>(temp->get_DerivedRef() != NULL ?
             temp->get_DerivedRef() : temp->get_Template()->get_reference());
           if (ref != NULL) {
-            ref->refd_param_usage_found();
+            ref->ref_usage_found();
           }
         }
       } else {
This page took 0.027144 seconds and 5 git commands to generate.