[llvm-commits] CVS: llvm/utils/TableGen/Record.h Record.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Aug 1 20:28:01 PDT 2003


Changes in directory llvm/utils/TableGen:

Record.h updated: 1.23 -> 1.24
Record.cpp updated: 1.17 -> 1.18

---
Log message:

Add new method


---
Diffs of the changes:

Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.23 llvm/utils/TableGen/Record.h:1.24
--- llvm/utils/TableGen/Record.h:1.23	Fri Aug  1 01:27:59 2003
+++ llvm/utils/TableGen/Record.h	Fri Aug  1 20:27:37 2003
@@ -626,6 +626,12 @@
   ///
   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: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.17 llvm/utils/TableGen/Record.cpp:1.18
--- llvm/utils/TableGen/Record.cpp:1.17	Fri Aug  1 01:27:59 2003
+++ llvm/utils/TableGen/Record.cpp	Fri Aug  1 20:27:37 2003
@@ -536,6 +536,23 @@
         "' 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) {





More information about the llvm-commits mailing list