From 50f7e1b69e8c33745a3f33a7af27382392332829 Mon Sep 17 00:00:00 2001 From: Pawel Szostek Date: Wed, 20 Jul 2011 18:19:48 +0200 Subject: [PATCH] Add parser cleanup to vhdlpp This commit adds removal of global objects in the execution of vhdlpp. This includes deleting design entities and the global parse scope. --- vhdlpp/main.cc | 9 +++++++-- vhdlpp/parse.y | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/vhdlpp/main.cc b/vhdlpp/main.cc index 87e4cd9cf..b705148b1 100644 --- a/vhdlpp/main.cc +++ b/vhdlpp/main.cc @@ -56,6 +56,7 @@ const char*dump_design_entities_path = 0; const char*dump_libraries_path = 0; extern void dump_libraries(ostream&file); +extern void parser_cleanup(); static void process_debug_token(const char*word) { @@ -141,21 +142,25 @@ int main(int argc, char*argv[]) dump_design_entities(file); } - if (errors > 0) + if (errors > 0) { + parser_cleanup(); return 2; + } errors = elaborate_entities(); if (errors > 0) { fprintf(stderr, "%d errors elaborating design.\n", errors); + parser_cleanup(); return 3; } errors = emit_entities(); if (errors > 0) { fprintf(stderr, "%d errors emitting design.\n", errors); + parser_cleanup(); return 4; } - lex_strings.cleanup(); + parser_cleanup(); return 0; } diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index a6d1bb8cd..54bcb8b7f 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -100,6 +100,31 @@ void preload_global_types(void) generate_global_types(active_scope); } +//Remove the scope created at the beginning of parser's work. +//After the parsing active_scope should keep it's address + +static void delete_global_scope(void) +{ + active_scope->destroy_global_scope(); + delete active_scope; +} + +//delete global entities that were gathered over the parsing process +static void delete_design_entities(void) +{ + for(map::iterator cur = design_entities.begin() + ; cur != design_entities.end(); ++cur) + delete cur->second; +} + +//clean the mess caused by the parser +void parser_cleanup(void) +{ + delete_design_entities(); + delete_global_scope(); + lex_strings.cleanup(); +} + const VType*parse_type_by_name(perm_string name) { return active_scope->find_type(name);