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:
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;
}
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) {
return;
}
- refd_param_usage_found();
+ ref_usage_found();
Common::Assignment *ass = get_refd_assignment();
if (!ass) FATAL_ERROR("Reference::generate_code_const_ref()");
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,
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();
{
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();
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);
}
// 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;
}
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) {
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);
}
}
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()
"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(),
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"
// 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 {
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 {