Add convenient helper to obtain list of ints
authorAnton Korobeynikov <asl@math.spbu.ru>
Sun, 11 Nov 2007 11:19:37 +0000 (11:19 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Sun, 11 Nov 2007 11:19:37 +0000 (11:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43993 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 75583bb1d17f1e8c317052877a56f81b68c83def..4cba8891c390229c50f6deb7297720dec9093420 100644 (file)
@@ -866,6 +866,25 @@ int Record::getValueAsInt(const std::string &FieldName) const {
         "' does not have an int initializer!";
 }
 
+/// getValueAsListOfInts - This method looks up the specified field and returns
+/// its value as a vector of integers, throwing an exception if the field does
+/// not exist or if the value is not the right type.
+///
+std::vector<int> 
+Record::getValueAsListOfInts(const std::string &FieldName) const {
+  ListInit *List = getValueAsListInit(FieldName);
+  std::vector<int> Ints;
+  for (unsigned i = 0; i < List->getSize(); i++) {
+    if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
+      Ints.push_back(II->getValue());
+    } else {
+      throw "Record `" + getName() + "', field `" + FieldName +
+            "' does not have a list of ints initializer!";
+    }
+  }
+  return Ints;
+}
+
 /// 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.
index d419f0b629acdd3d4ac7d7163959ef645f35fb97..5e88e50d3e40e4cb6f0850c99cbb30fca10728ff 100644 (file)
@@ -1042,11 +1042,17 @@ public:
   ListInit *getValueAsListInit(const std::string &FieldName) const;
 
   /// getValueAsListOfDefs - This method looks up the specified field and
-  /// returnsits value as a vector of records, throwing an exception if the
+  /// 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*> getValueAsListOfDefs(const std::string &FieldName) const;
 
+  /// getValueAsListOfInts - This method looks up the specified field and returns
+  /// its value as a vector of integers, throwing an exception if the field does
+  /// not exist or if the value is not the right type.
+  ///
+  std::vector<int> getValueAsListOfInts(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.