Add new method
authorChris Lattner <sabre@nondot.org>
Sat, 2 Aug 2003 01:27:37 +0000 (01:27 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 2 Aug 2003 01:27:37 +0000 (01:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7502 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7f81a382bb59b308a531654b9e2b4130bb37c6e3..309f386e78c094c033793dded27ab99119381cfb 100644 (file)
@@ -536,6 +536,23 @@ int Record::getValueAsInt(const std::string &FieldName) const {
         "' does not have a list initializer!";
 }
 
+/// 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.
+///
+Record *Record::getValueAsDef(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 (DefInit *DI = dynamic_cast<DefInit*>(R->getValue()))
+    return DI->getDef();
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
+
+
 void RecordKeeper::dump() const { std::cerr << *this; }
 
 std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK) {
index 1729b02866853f94af4ec5aa6c01fed84ff957a5..1eedf43a18a5f65e73983226523b12bc33eb7430 100644 (file)
@@ -626,6 +626,12 @@ public:
   ///
   ListInit *getValueAsListInit(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.
+  ///
+  Record *getValueAsDef(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.
index 7f81a382bb59b308a531654b9e2b4130bb37c6e3..309f386e78c094c033793dded27ab99119381cfb 100644 (file)
@@ -536,6 +536,23 @@ int Record::getValueAsInt(const std::string &FieldName) const {
         "' does not have a list initializer!";
 }
 
+/// 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.
+///
+Record *Record::getValueAsDef(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 (DefInit *DI = dynamic_cast<DefInit*>(R->getValue()))
+    return DI->getDef();
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
+
+
 void RecordKeeper::dump() const { std::cerr << *this; }
 
 std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK) {
index 1729b02866853f94af4ec5aa6c01fed84ff957a5..1eedf43a18a5f65e73983226523b12bc33eb7430 100644 (file)
@@ -626,6 +626,12 @@ public:
   ///
   ListInit *getValueAsListInit(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.
+  ///
+  Record *getValueAsDef(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.