From 96a9f78c4aa1bc188f3f7ee869bed44cb7a6ff0e Mon Sep 17 00:00:00 2001 From: David Greene Date: Wed, 19 Oct 2011 13:02:29 +0000 Subject: [PATCH] Add Value Accessors Add accessors to get Record values by Init name. This lets us look up Record values whose names are not yet fully resolved. More work toward paste. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142496 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/TableGen/Record.h | 11 +++++++++-- lib/TableGen/Record.cpp | 12 ++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index 22e761f44ae..4502aa72a73 100644 --- a/include/llvm/TableGen/Record.h +++ b/include/llvm/TableGen/Record.h @@ -1442,6 +1442,9 @@ public: return 0; } + const RecordVal *getValue(Init *Name) const; + RecordVal *getValue(Init *Name); + void addTemplateArg(StringRef Name) { assert(!isTemplateArg(Name) && "Template arg already defined!"); TemplateArgs.push_back(Name); @@ -1452,15 +1455,19 @@ public: Values.push_back(RV); } - void removeValue(StringRef Name) { + void removeValue(Init *Name) { for (unsigned i = 0, e = Values.size(); i != e; ++i) - if (Values[i].getName() == Name) { + if (Values[i].getNameInit() == Name) { Values.erase(Values.begin()+i); return; } assert(0 && "Cannot remove an entry that does not exist!"); } + void removeValue(StringRef Name) { + removeValue(StringInit::get(Name.str())); + } + bool isSubClassOf(const Record *R) const { for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) if (SuperClasses[i] == R) diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index b7c51cae953..06a41c9eb26 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -1726,6 +1726,18 @@ void Record::setName(const std::string &Name) { setName(StringInit::get(Name)); } +const RecordVal *Record::getValue(Init *Name) const { + for (unsigned i = 0, e = Values.size(); i != e; ++i) + if (Values[i].getNameInit() == Name) return &Values[i]; + return 0; +} + +RecordVal *Record::getValue(Init *Name) { + for (unsigned i = 0, e = Values.size(); i != e; ++i) + if (Values[i].getNameInit() == Name) return &Values[i]; + return 0; +} + /// resolveReferencesTo - If anything in this record refers to RV, replace the /// reference to RV with the RHS of RV. If RV is null, we resolve all possible /// references.