Tag at C++ Compiler 2019.05.09 Kei Hasegawa
scope : Symbol Table struct scope { }; scope* m_parent; vector<scope*> m_children; map<string, vector<usr*> > m_usrs; // Variable etc map<string, tag*> m_tags; // Structure etc ... virtual ~scope(); };
tag : expressing structure etc // C Compiler struct tag { // Scope where the structure is declared scope* m_scope; ... }; // C++ Compiler struct tag : scope { // scope::m_parent is correspond to m_scope of C Compiler ... };
Destroy symbol tables when finishing to compile a function definition // C Compiler void destroy_temporary() { ... // Simple! vector<scope*>& children = scope::root.m_children; for (auto p : children) delete p; children.clear(); }
Destroy symbol tables when finishing to compile a function definition(2) // C++ Compiler void destroy_temporary() { ... vector<scope*>& children = scope::root.m_children; for (IT p = begin(children) ; p != end(children) ; ) { switch ( (*p)->m_id) { case PARAM: case BLOCK: delete *p; p = children.erase(p); break; default: ++p; // Not delete structure or namespace }
scope::~scope() // C Compiler scope::~scope() { } for (auto p : m_children) delete p; ... for (auto& p : m_tags) p.second->m_scope = 0; // Not understandable. See C Compiler Temporary Type Document. }
scope::~scope() (2) // C++ Compiler scope::~scope() { for (auto p : m_children) { switch (p->m_id) { case PARAM: case BLOCK: delete p; break; default: p->m_parent = 0; // Break parent-child relation } // Nothing to be done for `m_tags’