diff options
author | Jim Laskey <jlaskey@mac.com> | 2005-10-28 21:46:31 +0000 |
---|---|---|
committer | Jim Laskey <jlaskey@mac.com> | 2005-10-28 21:46:31 +0000 |
commit | fd306bfdd294772560b3a1cf762bc1081f66e6ba (patch) | |
tree | 5d1eaee66efd2e565fbfab9f9182694362ab8c1c /utils/TableGen/Record.cpp | |
parent | ed048c067dc7bf342b2947b4de39e915dcbd2bf0 (diff) | |
download | external_llvm-fd306bfdd294772560b3a1cf762bc1081f66e6ba.zip external_llvm-fd306bfdd294772560b3a1cf762bc1081f66e6ba.tar.gz external_llvm-fd306bfdd294772560b3a1cf762bc1081f66e6ba.tar.bz2 |
Added method to return a vector of records for a ListInit of Def field. This
simplifies using list of records.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24069 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r-- | utils/TableGen/Record.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index c5f0565..109ed39 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -709,6 +709,25 @@ ListInit *Record::getValueAsListInit(const std::string &FieldName) const { "' does not have a list initializer!"; } +/// getValueAsListDef - This method looks up the specified field and returns +/// its value as a vector of records, throwing an exception if the field does +/// not exist or if the value is not the right type. +/// +std::vector<Record*> Record::getValueAsListDef(const std::string &FieldName) + const { + ListInit *List = getValueAsListInit(FieldName); + std::vector<Record*> Defs; + for (unsigned i = 0; i < List->getSize(); i++) { + if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) { + Defs.push_back(DI->getDef()); + } else { + throw "Record `" + getName() + "', field `" + FieldName + + "' list is not entirely DefInit!"; + } + } + return Defs; +} + /// 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. |