From dbb295bd0d0e084ffbaae314026f389d83453619 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 2 Aug 2003 01:27:37 +0000 Subject: [PATCH] Add new method git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7502 91177308-0d34-0410-b5e6-96231b3b80d8 --- support/tools/TableGen/Record.cpp | 17 +++++++++++++++++ support/tools/TableGen/Record.h | 6 ++++++ utils/TableGen/Record.cpp | 17 +++++++++++++++++ utils/TableGen/Record.h | 6 ++++++ 4 files changed, 46 insertions(+) diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index 7f81a382bb5..309f386e78c 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/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(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) { diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h index 1729b028668..1eedf43a18a 100644 --- a/support/tools/TableGen/Record.h +++ b/support/tools/TableGen/Record.h @@ -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. diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 7f81a382bb5..309f386e78c 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(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) { diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 1729b028668..1eedf43a18a 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -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.