Don't pollute the namespace with template arguments after they have been resolved
authorChris Lattner <sabre@nondot.org>
Wed, 30 Jul 2003 04:56:05 +0000 (04:56 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 30 Jul 2003 04:56:05 +0000 (04:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7410 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/FileParser.y
support/tools/TableGen/Record.h
utils/TableGen/FileParser.y
utils/TableGen/Record.h

index 6ebcf7691b1a0e90f50eb44e35533adc8b5e8a41..f8fa16de2a55b40a9c2deca465af1157296bfae2 100644 (file)
@@ -409,9 +409,9 @@ ObjectBody : OptID {
          } OptTemplateArgList ClassList {
            for (unsigned i = 0, e = $4->size(); i != e; ++i) {
             addSubClass((*$4)[i].first, *(*$4)[i].second);
-            delete (*$4)[i].second;  // Delete the template list
-          }
-           delete $4;
+             // Delete the template arg values for the class
+             delete (*$4)[i].second;
+           }
 
           // Process any variables on the set stack...
           for (unsigned i = 0, e = SetStack.size(); i != e; ++i)
@@ -419,6 +419,17 @@ ObjectBody : OptID {
                      SetStack[i].second);
          } Body {
   CurRec->resolveReferences();
+
+  // Now that all of the references have been resolved, we can delete template
+  // arguments for superclasses, so they don't pollute our record, and so that
+  // their names won't conflict with later uses of the name...
+  for (unsigned i = 0, e = $4->size(); i != e; ++i) {
+    Record *SuperClass = (*$4)[i].first;
+    for (unsigned i = 0, e = SuperClass->getTemplateArgs().size(); i != e; ++i)
+    CurRec->removeValue(SuperClass->getTemplateArgs()[i]);
+  }
+  delete $4;   // Delete the class list...
+
   $$ = CurRec;
   CurRec = 0;
 };
index d94bb34504fcb99692a6a69b608f692131eac30a..0ac5648c86d03004f7075be4f5ac041ce249cc25 100644 (file)
@@ -536,6 +536,16 @@ public:
     Values.push_back(RV);
   }
 
+  void removeValue(const std::string &Name) {
+    assert(getValue(Name) && "Cannot remove an entry that does not exist!");
+    for (unsigned i = 0, e = Values.size(); i != e; ++i)
+      if (Values[i].getName() == Name) {
+        Values.erase(Values.begin()+i);
+        return;
+      }
+    assert(0 && "Name does not exist in record!");
+  }
+
   bool isSubClassOf(Record *R) const {
     for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
       if (SuperClasses[i] == R)
index 6ebcf7691b1a0e90f50eb44e35533adc8b5e8a41..f8fa16de2a55b40a9c2deca465af1157296bfae2 100644 (file)
@@ -409,9 +409,9 @@ ObjectBody : OptID {
          } OptTemplateArgList ClassList {
            for (unsigned i = 0, e = $4->size(); i != e; ++i) {
             addSubClass((*$4)[i].first, *(*$4)[i].second);
-            delete (*$4)[i].second;  // Delete the template list
-          }
-           delete $4;
+             // Delete the template arg values for the class
+             delete (*$4)[i].second;
+           }
 
           // Process any variables on the set stack...
           for (unsigned i = 0, e = SetStack.size(); i != e; ++i)
@@ -419,6 +419,17 @@ ObjectBody : OptID {
                      SetStack[i].second);
          } Body {
   CurRec->resolveReferences();
+
+  // Now that all of the references have been resolved, we can delete template
+  // arguments for superclasses, so they don't pollute our record, and so that
+  // their names won't conflict with later uses of the name...
+  for (unsigned i = 0, e = $4->size(); i != e; ++i) {
+    Record *SuperClass = (*$4)[i].first;
+    for (unsigned i = 0, e = SuperClass->getTemplateArgs().size(); i != e; ++i)
+    CurRec->removeValue(SuperClass->getTemplateArgs()[i]);
+  }
+  delete $4;   // Delete the class list...
+
   $$ = CurRec;
   CurRec = 0;
 };
index d94bb34504fcb99692a6a69b608f692131eac30a..0ac5648c86d03004f7075be4f5ac041ce249cc25 100644 (file)
@@ -536,6 +536,16 @@ public:
     Values.push_back(RV);
   }
 
+  void removeValue(const std::string &Name) {
+    assert(getValue(Name) && "Cannot remove an entry that does not exist!");
+    for (unsigned i = 0, e = Values.size(); i != e; ++i)
+      if (Values[i].getName() == Name) {
+        Values.erase(Values.begin()+i);
+        return;
+      }
+    assert(0 && "Name does not exist in record!");
+  }
+
   bool isSubClassOf(Record *R) const {
     for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
       if (SuperClasses[i] == R)