From: Chris Lattner Date: Fri, 18 Sep 2009 18:31:37 +0000 (+0000) Subject: convert some stuff to StringRef to avoid temporary std::strings. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c19418f31fa8ab09ff43c57150e5042dbe368f49;p=oota-llvm.git convert some stuff to StringRef to avoid temporary std::strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82244 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index d594c9aa09a..a551166a9cd 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -1384,11 +1384,11 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) { /// getValueInit - Return the initializer for a value with the specified name, /// or throw an exception if the field does not exist. /// -Init *Record::getValueInit(const std::string &FieldName) const { +Init *Record::getValueInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; return R->getValue(); } @@ -1397,15 +1397,15 @@ Init *Record::getValueInit(const std::string &FieldName) const { /// 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 { +std::string Record::getValueAsString(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (const StringInit *SI = dynamic_cast(R->getValue())) return SI->getValue(); - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a string initializer!"; } @@ -1413,15 +1413,15 @@ std::string Record::getValueAsString(const std::string &FieldName) const { /// its value as a BitsInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// -BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const { +BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (BitsInit *BI = dynamic_cast(R->getValue())) return BI; - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a BitsInit initializer!"; } @@ -1429,15 +1429,15 @@ BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const { /// its value as a ListInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// -ListInit *Record::getValueAsListInit(const std::string &FieldName) const { +ListInit *Record::getValueAsListInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (ListInit *LI = dynamic_cast(R->getValue())) return LI; - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a list initializer!"; } @@ -1446,14 +1446,14 @@ ListInit *Record::getValueAsListInit(const std::string &FieldName) const { /// not exist or if the value is not the right type. /// std::vector -Record::getValueAsListOfDefs(const std::string &FieldName) const { +Record::getValueAsListOfDefs(StringRef FieldName) const { ListInit *List = getValueAsListInit(FieldName); std::vector Defs; for (unsigned i = 0; i < List->getSize(); i++) { if (DefInit *DI = dynamic_cast(List->getElement(i))) { Defs.push_back(DI->getDef()); } else { - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' list is not entirely DefInit!"; } } @@ -1464,15 +1464,15 @@ Record::getValueAsListOfDefs(const std::string &FieldName) const { /// value as an int64_t, throwing an exception if the field does not exist or if /// the value is not the right type. /// -int64_t Record::getValueAsInt(const std::string &FieldName) const { +int64_t Record::getValueAsInt(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (IntInit *II = dynamic_cast(R->getValue())) return II->getValue(); - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have an int initializer!"; } @@ -1481,14 +1481,14 @@ int64_t Record::getValueAsInt(const std::string &FieldName) const { /// not exist or if the value is not the right type. /// std::vector -Record::getValueAsListOfInts(const std::string &FieldName) const { +Record::getValueAsListOfInts(StringRef FieldName) const { ListInit *List = getValueAsListInit(FieldName); std::vector Ints; for (unsigned i = 0; i < List->getSize(); i++) { if (IntInit *II = dynamic_cast(List->getElement(i))) { Ints.push_back(II->getValue()); } else { - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a list of ints initializer!"; } } @@ -1499,15 +1499,15 @@ Record::getValueAsListOfInts(const std::string &FieldName) const { /// 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 { +Record *Record::getValueAsDef(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (DefInit *DI = dynamic_cast(R->getValue())) return DI->getDef(); - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a def initializer!"; } @@ -1515,15 +1515,15 @@ Record *Record::getValueAsDef(const std::string &FieldName) const { /// value as a bit, throwing an exception if the field does not exist or if /// the value is not the right type. /// -bool Record::getValueAsBit(const std::string &FieldName) const { +bool Record::getValueAsBit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (BitInit *BI = dynamic_cast(R->getValue())) return BI->getValue(); - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a bit initializer!"; } @@ -1531,27 +1531,27 @@ bool Record::getValueAsBit(const std::string &FieldName) const { /// value as an Dag, throwing an exception if the field does not exist or if /// the value is not the right type. /// -DagInit *Record::getValueAsDag(const std::string &FieldName) const { +DagInit *Record::getValueAsDag(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (DagInit *DI = dynamic_cast(R->getValue())) return DI; - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a dag initializer!"; } -std::string Record::getValueAsCode(const std::string &FieldName) const { +std::string Record::getValueAsCode(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + - FieldName + "'!\n"; + FieldName.str() + "'!\n"; if (const CodeInit *CI = dynamic_cast(R->getValue())) return CI->getValue(); - throw "Record `" + getName() + "', field `" + FieldName + + throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a code initializer!"; } diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 9415109dbb3..1b33743e141 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -1248,24 +1248,24 @@ public: const std::vector &getValues() const { return Values; } const std::vector &getSuperClasses() const { return SuperClasses; } - bool isTemplateArg(const std::string &Name) const { + bool isTemplateArg(StringRef Name) const { for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i) if (TemplateArgs[i] == Name) return true; return false; } - const RecordVal *getValue(const std::string &Name) const { + const RecordVal *getValue(StringRef Name) const { for (unsigned i = 0, e = Values.size(); i != e; ++i) if (Values[i].getName() == Name) return &Values[i]; return 0; } - RecordVal *getValue(const std::string &Name) { + RecordVal *getValue(StringRef Name) { for (unsigned i = 0, e = Values.size(); i != e; ++i) if (Values[i].getName() == Name) return &Values[i]; return 0; } - void addTemplateArg(const std::string &Name) { + void addTemplateArg(StringRef Name) { assert(!isTemplateArg(Name) && "Template arg already defined!"); TemplateArgs.push_back(Name); } @@ -1275,7 +1275,7 @@ public: Values.push_back(RV); } - void removeValue(const std::string &Name) { + void removeValue(StringRef Name) { assert(getValue(Name) && "Cannot remove an entry that does not exist!"); for (unsigned i = 0, e = Values.size(); i != e; ++i) if (Values[i].getName() == Name) { @@ -1292,7 +1292,7 @@ public: return false; } - bool isSubClassOf(const std::string &Name) const { + bool isSubClassOf(StringRef Name) const { for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) if (SuperClasses[i]->getName() == Name) return true; @@ -1323,67 +1323,67 @@ public: /// getValueInit - Return the initializer for a value with the specified name, /// or throw an exception if the field does not exist. /// - Init *getValueInit(const std::string &FieldName) const; + Init *getValueInit(StringRef FieldName) const; /// 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 getValueAsString(const std::string &FieldName) const; + std::string getValueAsString(StringRef FieldName) const; /// getValueAsBitsInit - This method looks up the specified field and returns /// its value as a BitsInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// - BitsInit *getValueAsBitsInit(const std::string &FieldName) const; + BitsInit *getValueAsBitsInit(StringRef FieldName) const; /// getValueAsListInit - This method looks up the specified field and returns /// its value as a ListInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// - ListInit *getValueAsListInit(const std::string &FieldName) const; + ListInit *getValueAsListInit(StringRef FieldName) const; /// getValueAsListOfDefs - 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 getValueAsListOfDefs(const std::string &FieldName) const; + std::vector getValueAsListOfDefs(StringRef FieldName) const; /// getValueAsListOfInts - This method looks up the specified field and returns /// its value as a vector of integers, throwing an exception if the field does /// not exist or if the value is not the right type. /// - std::vector getValueAsListOfInts(const std::string &FieldName) const; + std::vector getValueAsListOfInts(StringRef 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; + Record *getValueAsDef(StringRef FieldName) const; /// getValueAsBit - This method looks up the specified field and returns its /// value as a bit, throwing an exception if the field does not exist or if /// the value is not the right type. /// - bool getValueAsBit(const std::string &FieldName) const; + bool getValueAsBit(StringRef FieldName) const; /// getValueAsInt - This method looks up the specified field and returns its /// value as an int64_t, throwing an exception if the field does not exist or /// if the value is not the right type. /// - int64_t getValueAsInt(const std::string &FieldName) const; + int64_t getValueAsInt(StringRef FieldName) const; /// getValueAsDag - This method looks up the specified field and returns its /// value as an Dag, throwing an exception if the field does not exist or if /// the value is not the right type. /// - DagInit *getValueAsDag(const std::string &FieldName) const; + DagInit *getValueAsDag(StringRef FieldName) const; /// getValueAsCode - This method looks up the specified field and returns /// its value as the string data in a CodeInit, throwing an exception if the /// field does not exist or if the value is not a code object. /// - std::string getValueAsCode(const std::string &FieldName) const; + std::string getValueAsCode(StringRef FieldName) const; }; raw_ostream &operator<<(raw_ostream &OS, const Record &R);