summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/utils/TableGen/ClangAttrEmitter.cpp55
1 files changed, 27 insertions, 28 deletions
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index fe615468b16..c3d593b0924 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1440,7 +1440,7 @@ static void writeAttrAccessorDefinition(const Record &R, raw_ostream &OS) {
assert(!SpellingList.empty() &&
"Attribute with empty spelling list can't have accessors!");
for (const auto *Accessor : Accessors) {
- std::string Name = Accessor->getValueAsString("Name");
+ const StringRef Name = Accessor->getValueAsString("Name");
std::vector<FlattenedSpelling> Spellings = GetFlattenedSpellings(*Accessor);
OS << " bool " << Name << "() const { return SpellingListIndex == ";
@@ -1589,7 +1589,7 @@ struct AttributeSubjectMatchRule {
// Abstract rules are used only for sub-rules
bool isAbstractRule() const { return getSubjects().empty(); }
- std::string getName() const {
+ StringRef getName() const {
return (Constraint ? Constraint : MetaSubject)->getValueAsString("Name");
}
@@ -1821,13 +1821,11 @@ PragmaClangAttributeSupport::generateStrictConformsTo(const Record &Attr,
// Generate a function that constructs a set of matching rules that describe
// to which declarations the attribute should apply to.
std::string FnName = "matchRulesFor" + Attr.getName().str();
- std::stringstream SS;
- SS << "static void " << FnName << "(llvm::SmallVectorImpl<std::pair<"
+ OS << "static void " << FnName << "(llvm::SmallVectorImpl<std::pair<"
<< AttributeSubjectMatchRule::EnumName
<< ", bool>> &MatchRules, const LangOptions &LangOpts) {\n";
if (Attr.isValueUnset("Subjects")) {
- SS << "}\n\n";
- OS << SS.str();
+ OS << "}\n\n";
return FnName;
}
const Record *SubjectObj = Attr.getValueAsDef("Subjects");
@@ -1840,24 +1838,23 @@ PragmaClangAttributeSupport::generateStrictConformsTo(const Record &Attr,
// The rule might be language specific, so only subtract it from the given
// rules if the specific language options are specified.
std::vector<Record *> LangOpts = Rule.getLangOpts();
- SS << " MatchRules.push_back(std::make_pair(" << Rule.getEnumValue()
+ OS << " MatchRules.push_back(std::make_pair(" << Rule.getEnumValue()
<< ", /*IsSupported=*/";
if (!LangOpts.empty()) {
for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
- std::string Part = (*I)->getValueAsString("Name");
+ const StringRef Part = (*I)->getValueAsString("Name");
if ((*I)->getValueAsBit("Negated"))
- SS << "!";
- SS << "LangOpts." + Part;
+ OS << "!";
+ OS << "LangOpts." << Part;
if (I + 1 != E)
- SS << " || ";
+ OS << " || ";
}
} else
- SS << "true";
- SS << "));\n";
+ OS << "true";
+ OS << "));\n";
}
}
- SS << "}\n\n";
- OS << SS.str();
+ OS << "}\n\n";
return FnName;
}
@@ -1913,7 +1910,8 @@ void PragmaClangAttributeSupport::generateParsingHelpers(raw_ostream &OS) {
continue;
std::string SubRuleFunction;
if (SubMatchRules.count(Rule.MetaSubject))
- SubRuleFunction = "isAttributeSubjectMatchSubRuleFor_" + Rule.getName();
+ SubRuleFunction =
+ ("isAttributeSubjectMatchSubRuleFor_" + Rule.getName()).str();
else
SubRuleFunction = "defaultIsAttributeSubjectMatchSubRuleFor";
OS << " Case(\"" << Rule.getName() << "\", std::make_pair("
@@ -3030,7 +3028,7 @@ static void GenerateDefaultAppertainsTo(raw_ostream &OS) {
static std::string CalculateDiagnostic(const Record &S) {
// If the SubjectList object has a custom diagnostic associated with it,
// return that directly.
- std::string CustomDiag = S.getValueAsString("CustomDiag");
+ const StringRef CustomDiag = S.getValueAsString("CustomDiag");
if (!CustomDiag.empty())
return CustomDiag;
@@ -3314,12 +3312,13 @@ static std::string GenerateLangOptRequirements(const Record &R,
// codegen efficiency).
std::string FnName = "check", Test;
for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
- std::string Part = (*I)->getValueAsString("Name");
+ const StringRef Part = (*I)->getValueAsString("Name");
if ((*I)->getValueAsBit("Negated")) {
FnName += "Not";
Test += "!";
}
- Test += "S.LangOpts." + Part;
+ Test += "S.LangOpts.";
+ Test += Part;
if (I + 1 != E)
Test += " || ";
FnName += Part;
@@ -3375,7 +3374,7 @@ static std::string GenerateTargetRequirements(const Record &Attr,
// applies to multiple target architectures. In order for the attribute to be
// considered valid, all of its architectures need to be included.
if (!Attr.isValueUnset("ParseKind")) {
- std::string APK = Attr.getValueAsString("ParseKind");
+ const StringRef APK = Attr.getValueAsString("ParseKind");
for (const auto &I : Dupes) {
if (I.first == APK) {
std::vector<StringRef> DA =
@@ -3676,13 +3675,13 @@ public:
static void WriteCategoryHeader(const Record *DocCategory,
raw_ostream &OS) {
- const std::string &Name = DocCategory->getValueAsString("Name");
- OS << Name << "\n" << std::string(Name.length(), '=') << "\n";
+ const StringRef Name = DocCategory->getValueAsString("Name");
+ OS << Name << "\n" << std::string(Name.size(), '=') << "\n";
// If there is content, print that as well.
- std::string ContentStr = DocCategory->getValueAsString("Content");
+ const StringRef ContentStr = DocCategory->getValueAsString("Content");
// Trim leading and trailing newlines and spaces.
- OS << StringRef(ContentStr).trim();
+ OS << ContentStr.trim();
OS << "\n\n";
}
@@ -3810,16 +3809,16 @@ static void WriteDocumentation(RecordKeeper &Records,
OS << "This attribute has been deprecated, and may be removed in a future "
<< "version of Clang.";
const Record &Deprecated = *Doc.Documentation->getValueAsDef("Deprecated");
- std::string Replacement = Deprecated.getValueAsString("Replacement");
+ const StringRef Replacement = Deprecated.getValueAsString("Replacement");
if (!Replacement.empty())
OS << " This attribute has been superseded by ``"
<< Replacement << "``.";
OS << "\n\n";
}
- std::string ContentStr = Doc.Documentation->getValueAsString("Content");
+ const StringRef ContentStr = Doc.Documentation->getValueAsString("Content");
// Trim leading and trailing newlines and spaces.
- OS << StringRef(ContentStr).trim();
+ OS << ContentStr.trim();
OS << "\n\n\n";
}
@@ -3848,7 +3847,7 @@ void EmitClangAttrDocs(RecordKeeper &Records, raw_ostream &OS) {
// If the category is "undocumented", then there cannot be any other
// documentation categories (otherwise, the attribute would become
// documented).
- std::string Cat = Category->getValueAsString("Name");
+ const StringRef Cat = Category->getValueAsString("Name");
bool Undocumented = Cat == "Undocumented";
if (Undocumented && Docs.size() > 1)
PrintFatalError(Doc.getLoc(),
OpenPOWER on IntegriCloud