aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/Record.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-02 01:27:37 +0000
committerChris Lattner <sabre@nondot.org>2003-08-02 01:27:37 +0000
commitdbb295bd0d0e084ffbaae314026f389d83453619 (patch)
tree11c9ced91d948465b3415bf692f88cae1da4791b /utils/TableGen/Record.cpp
parent14fef50bcf61d59493cb655b75fe21ed729bf73b (diff)
downloadexternal_llvm-dbb295bd0d0e084ffbaae314026f389d83453619.zip
external_llvm-dbb295bd0d0e084ffbaae314026f389d83453619.tar.gz
external_llvm-dbb295bd0d0e084ffbaae314026f389d83453619.tar.bz2
Add new method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7502 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r--utils/TableGen/Record.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 7f81a38..309f386 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -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) {