// make package typedefs available to parser
add_package_types(pkg_user_types, design->verilog_packages);
- UserTypeMap *global_types_map = new UserTypeMap();
+ UserTypeMap global_types_map;
for (auto def : design->verilog_globals) {
if (def->type == AST::AST_TYPEDEF) {
- (*global_types_map)[def->str] = def;
+ global_types_map[def->str] = def;
}
}
log_assert(user_type_stack.empty());
// use previous global typedefs as bottom level of user type stack
- user_type_stack.push_back(global_types_map);
+ user_type_stack.push_back(std::move(global_types_map));
// add a new empty type map to allow overriding existing global definitions
- user_type_stack.push_back(new UserTypeMap());
+ user_type_stack.push_back(UserTypeMap());
frontend_verilog_yyset_lineno(1);
frontend_verilog_yyrestart(NULL);
// only the previous and new global type maps remain
log_assert(user_type_stack.size() == 2);
- for (auto it : user_type_stack) {
- // the global typedefs have to remain valid for future invocations, so just drop the map without deleting values
- delete it;
- }
user_type_stack.clear();
delete current_ast;
dict<IdString, AstNode*> *attr_list, default_attr_list;
std::stack<dict<IdString, AstNode*> *> attr_list_stack;
dict<IdString, AstNode*> *albuf;
- std::vector<UserTypeMap*> user_type_stack;
+ std::vector<UserTypeMap> user_type_stack;
dict<std::string, AstNode*> pkg_user_types;
std::vector<AstNode*> ast_stack;
struct AstNode *astbuf1, *astbuf2, *astbuf3;
log_assert(node);
auto *tnode = new AstNode(AST_TYPEDEF, node);
tnode->str = *name;
- auto user_types = user_type_stack.back();
- (*user_types)[*name] = tnode;
+ auto &user_types = user_type_stack.back();
+ user_types[*name] = tnode;
if (current_ast_mod && current_ast_mod->type == AST_PACKAGE) {
// typedef inside a package so we need the qualified name
auto qname = current_ast_mod->str + "::" + (*name).substr(1);
static void enterTypeScope()
{
- auto user_types = new UserTypeMap();
- user_type_stack.push_back(user_types);
+ user_type_stack.push_back(UserTypeMap());
}
static void exitTypeScope()
static bool isInLocalScope(const std::string *name)
{
// tests if a name was declared in the current block scope
- auto user_types = user_type_stack.back();
- return (user_types->count(*name) > 0);
+ auto &user_types = user_type_stack.back();
+ return (user_types.count(*name) > 0);
}
static AstNode *getTypeDefinitionNode(std::string type_name)
{
// check current scope then outer scopes for a name
for (auto it = user_type_stack.rbegin(); it != user_type_stack.rend(); ++it) {
- if ((*it)->count(type_name) > 0) {
+ if (it->count(type_name) > 0) {
// return the definition nodes from the typedef statement
- auto typedef_node = (**it)[type_name];
+ auto typedef_node = (*it)[type_name];
log_assert(typedef_node->type == AST_TYPEDEF);
return typedef_node->children[0];
}