fix enum in generate blocks
authorJeff Wang <jjj11x@gmail.com>
Thu, 16 Jan 2020 22:05:45 +0000 (17:05 -0500)
committerJeff Wang <jeffrey.wang@ll.mit.edu>
Thu, 16 Jan 2020 23:13:30 +0000 (18:13 -0500)
frontends/ast/simplify.cc

index 2e1b1e40411551fb80b5cf18fe77757d37f18b4d..c96f5d549e474d377b4e57a9ac98cbd65f8a3e6a 100644 (file)
@@ -3097,6 +3097,26 @@ void AstNode::expand_genblock(std::string index_var, std::string prefix, std::ma
                                child->str = new_name;
                        current_scope[new_name] = child;
                }
+               if (child->type == AST_ENUM){
+                       for (auto enode : child->children){
+                               log_assert(enode->type == AST_ENUM_ITEM);
+                               if (backup_name_map.size() == 0)
+                                       backup_name_map = name_map;
+                               std::string new_name = prefix[0] == '\\' ? prefix.substr(1) : prefix;
+                               size_t pos = enode->str.rfind('.');
+                               if (pos == std::string::npos)
+                                       pos = enode->str[0] == '\\' && prefix[0] == '\\' ? 1 : 0;
+                               else
+                                       pos = pos + 1;
+                               new_name = enode->str.substr(0, pos) + new_name + enode->str.substr(pos);
+                               if (new_name[0] != '$' && new_name[0] != '\\')
+                                       new_name = prefix[0] + new_name;
+                               name_map[enode->str] = new_name;
+
+                               enode->str = new_name;
+                               current_scope[new_name] = enode;
+                       }
+               }
        }
 
        for (size_t i = 0; i < children.size(); i++) {