Added method to return a vector of records for a ListInit of Def field. This
authorJim Laskey <jlaskey@mac.com>
Fri, 28 Oct 2005 21:46:31 +0000 (21:46 +0000)
committerJim Laskey <jlaskey@mac.com>
Fri, 28 Oct 2005 21:46:31 +0000 (21:46 +0000)
simplifies using list of records.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24069 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/Record.cpp
utils/TableGen/Record.h

index c5f0565749979bdf4637e1ac9b527c4a397d621d..109ed392513c20f40d350487a48fbdeaa86b5b31 100644 (file)
@@ -709,6 +709,25 @@ ListInit *Record::getValueAsListInit(const std::string &FieldName) const {
         "' does not have a list initializer!";
 }
 
+/// getValueAsListDef - This method looks up the specified field and returns
+/// its value as a vector of records, throwing an exception if the field does
+/// not exist or if the value is not the right type.
+///
+std::vector<Record*>  Record::getValueAsListDef(const std::string &FieldName)
+                                                                         const {
+  ListInit *List = getValueAsListInit(FieldName);
+  std::vector<Record*> Defs;
+  for (unsigned i = 0; i < List->getSize(); i++) {
+    if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) {
+      Defs.push_back(DI->getDef());
+    } else {
+      throw "Record `" + getName() + "', field `" + FieldName +
+            "' list is not entirely DefInit!";
+    }
+  }
+  return Defs;
+}
+
 /// getValueAsInt - This method looks up the specified field and returns its
 /// value as an int, throwing an exception if the field does not exist or if
 /// the value is not the right type.
index edd875afcec51c6e3b7d1db6b5b2bfc3ab410f68..ecd6d7020a8f65f1f1067ded70d2b1dff2635d37 100644 (file)
@@ -1000,6 +1000,12 @@ public:
   ///
   ListInit *getValueAsListInit(const std::string &FieldName) const;
 
+  /// getValueAsListDef - This method looks up the specified field and returns
+  /// its value as a vector of records, throwing an exception if the field does
+  /// not exist or if the value is not the right type.
+  ///
+  std::vector<Record*> getValueAsListDef(const std::string &FieldName) const;
+
   /// getValueAsDef - This method looks up the specified field and returns its
   /// value as a Record, throwing an exception if the field does not exist or if
   /// the value is not the right type.