aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/Record.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-01 04:37:57 +0000
committerChris Lattner <sabre@nondot.org>2003-08-01 04:37:57 +0000
commit5c737ad4d669b835b8fb973a5c477a4dbb213830 (patch)
treed0dda2b3d62f9d7ff14f11a646feed5b35d1bc01 /utils/TableGen/Record.cpp
parentcf1b5853127352096ea6c2f8ec130f809168da2f (diff)
downloadexternal_llvm-5c737ad4d669b835b8fb973a5c477a4dbb213830.zip
external_llvm-5c737ad4d669b835b8fb973a5c477a4dbb213830.tar.gz
external_llvm-5c737ad4d669b835b8fb973a5c477a4dbb213830.tar.bz2
Switch over to an exception handling model for "high-level" requests.
Add new getValueAsString method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7463 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r--utils/TableGen/Record.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 6dc409b..f282e4b 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -452,6 +452,23 @@ std::ostream &operator<<(std::ostream &OS, const Record &R) {
return OS << "}\n";
}
+/// getValueAsString - This method looks up the specified field and returns its
+/// value as a string, throwing an exception if the field does not exist or if
+/// the value is not a string.
+///
+std::string Record::getValueAsString(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 (const StringInit *SI = dynamic_cast<const StringInit*>(R->getValue()))
+ return SI->getValue();
+ throw "Record '" + R->getName() + "', field '" + FieldName +
+ "' does not have a string initializer!";
+}
+
+
void RecordKeeper::dump() const { std::cerr << *this; }
std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK) {
@@ -473,18 +490,17 @@ std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK) {
/// getAllDerivedDefinitions - This method returns all concrete definitions
/// that derive from the specified class name. If a class with the specified
/// name does not exist, an error is printed and true is returned.
-bool RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName,
- std::vector<Record*> &Defs) const {
+std::vector<Record*>
+RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
Record *Class = Records.getClass(ClassName);
- if (!Class) {
- std::cerr << "ERROR: Couldn't find the '" << ClassName << "' class!\n";
- return true;
- }
+ if (!Class)
+ throw "ERROR: Couldn't find the '" + ClassName + "' class!\n";
+ std::vector<Record*> Defs;
for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(),
E = getDefs().end(); I != E; ++I)
if (I->second->isSubClassOf(Class))
Defs.push_back(I->second);
- return false;
+ return Defs;
}