Add new getValueAsListInit and getValueAsInt methods
authorChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 06:15:10 +0000 (06:15 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 06:15:10 +0000 (06:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7472 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/Record.cpp
support/tools/TableGen/Record.h
utils/TableGen/Record.cpp
utils/TableGen/Record.h

index fc035aceb3886248c3895d5abef0789243a59bf4..8649b5fe4cc270d8776f72a514525d2b52d4ca8d 100644 (file)
@@ -492,7 +492,37 @@ BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const {
         "' does not have a BitsInit initializer!";
 }
 
+/// getValueAsListInit - This method looks up the specified field and returns
+/// its value as a ListInit, throwing an exception if the field does not exist
+/// or if the value is not the right type.
+///
+ListInit *Record::getValueAsListInit(const std::string &FieldName) const {
+  const RecordVal *R = getValue(FieldName);
+  if (R == 0 || R->getValue() == 0)
+    throw "Record '" + R->getName() + "' does not have a field named '" +
+          FieldName + "!\n";
+
+  if (ListInit *LI = dynamic_cast<ListInit*>(R->getValue()))
+    return LI;
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
 
+/// 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.
+///
+int Record::getValueAsInt(const std::string &FieldName) const {
+  const RecordVal *R = getValue(FieldName);
+  if (R == 0 || R->getValue() == 0)
+    throw "Record '" + R->getName() + "' does not have a field named '" +
+          FieldName + "!\n";
+
+  if (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
+    return II->getValue();
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
 
 void RecordKeeper::dump() const { std::cerr << *this; }
 
index 5dbd9b9c56257b4886238c3f2eccd8dc13eed2aa..0eaf16ff0e2b79fec93794815387b3540653ed56 100644 (file)
@@ -613,6 +613,17 @@ public:
   ///
   BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
 
+  /// getValueAsListInit - This method looks up the specified field and returns
+  /// its value as a ListInit, throwing an exception if the field does not exist
+  /// or if the value is not the right type.
+  ///
+  ListInit *getValueAsListInit(const std::string &FieldName) const;
+
+  /// 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.
+  ///
+  int getValueAsInt(const std::string &FieldName) const;
 };
 
 std::ostream &operator<<(std::ostream &OS, const Record &R);
index fc035aceb3886248c3895d5abef0789243a59bf4..8649b5fe4cc270d8776f72a514525d2b52d4ca8d 100644 (file)
@@ -492,7 +492,37 @@ BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const {
         "' does not have a BitsInit initializer!";
 }
 
+/// getValueAsListInit - This method looks up the specified field and returns
+/// its value as a ListInit, throwing an exception if the field does not exist
+/// or if the value is not the right type.
+///
+ListInit *Record::getValueAsListInit(const std::string &FieldName) const {
+  const RecordVal *R = getValue(FieldName);
+  if (R == 0 || R->getValue() == 0)
+    throw "Record '" + R->getName() + "' does not have a field named '" +
+          FieldName + "!\n";
+
+  if (ListInit *LI = dynamic_cast<ListInit*>(R->getValue()))
+    return LI;
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
 
+/// 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.
+///
+int Record::getValueAsInt(const std::string &FieldName) const {
+  const RecordVal *R = getValue(FieldName);
+  if (R == 0 || R->getValue() == 0)
+    throw "Record '" + R->getName() + "' does not have a field named '" +
+          FieldName + "!\n";
+
+  if (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
+    return II->getValue();
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
 
 void RecordKeeper::dump() const { std::cerr << *this; }
 
index 5dbd9b9c56257b4886238c3f2eccd8dc13eed2aa..0eaf16ff0e2b79fec93794815387b3540653ed56 100644 (file)
@@ -613,6 +613,17 @@ public:
   ///
   BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
 
+  /// getValueAsListInit - This method looks up the specified field and returns
+  /// its value as a ListInit, throwing an exception if the field does not exist
+  /// or if the value is not the right type.
+  ///
+  ListInit *getValueAsListInit(const std::string &FieldName) const;
+
+  /// 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.
+  ///
+  int getValueAsInt(const std::string &FieldName) const;
 };
 
 std::ostream &operator<<(std::ostream &OS, const Record &R);