Skip to content

Commit 5f02b77

Browse files
committedDec 8, 2015
Use range loops and autos in utils/TableGen/ClangAttrEmitter.cpp and generated code.
Differential revision: http://reviews.llvm.org/D15313 llvm-svn: 255042
1 parent 7544602 commit 5f02b77

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed
 

Diff for: ‎clang/utils/TableGen/ClangAttrEmitter.cpp

+17-21
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ namespace {
619619
std::vector<std::string> uniques;
620620
std::set<std::string> unique_set(enums.begin(), enums.end());
621621
for (const auto &i : enums) {
622-
std::set<std::string>::iterator set_i = unique_set.find(i);
622+
auto set_i = unique_set.find(i);
623623
if (set_i != unique_set.end()) {
624624
uniques.push_back(i);
625625
unique_set.erase(set_i);
@@ -665,8 +665,7 @@ namespace {
665665
OS << type << " " << getUpperName();
666666
}
667667
void writeDeclarations(raw_ostream &OS) const override {
668-
std::vector<std::string>::const_iterator i = uniques.begin(),
669-
e = uniques.end();
668+
auto i = uniques.cbegin(), e = uniques.cend();
670669
// The last one needs to not have a comma.
671670
--e;
672671

@@ -771,8 +770,7 @@ namespace {
771770
bool isVariadicEnumArg() const override { return true; }
772771

773772
void writeDeclarations(raw_ostream &OS) const override {
774-
std::vector<std::string>::const_iterator i = uniques.begin(),
775-
e = uniques.end();
773+
auto i = uniques.cbegin(), e = uniques.cend();
776774
// The last one needs to not have a comma.
777775
--e;
778776

@@ -958,7 +956,7 @@ namespace {
958956
}
959957

960958
void writeTemplateInstantiation(raw_ostream &OS) const override {
961-
OS << " " << getType() << " *tempInst" << getUpperName()
959+
OS << " auto *tempInst" << getUpperName()
962960
<< " = new (C, 16) " << getType()
963961
<< "[A->" << getLowerName() << "_size()];\n";
964962
OS << " {\n";
@@ -1537,7 +1535,7 @@ void EmitClangAttrClass(RecordKeeper &Records, raw_ostream &OS) {
15371535
}
15381536
OS << ", SourceRange Loc = SourceRange()";
15391537
OS << ") {\n";
1540-
OS << " " << R.getName() << "Attr *A = new (Ctx) " << R.getName();
1538+
OS << " auto *A = new (Ctx) " << R.getName();
15411539
OS << "Attr(Loc, Ctx, ";
15421540
for (auto const &ai : Args) {
15431541
if (ai->isFake() && !emitFake) continue;
@@ -1654,7 +1652,7 @@ void EmitClangAttrClass(RecordKeeper &Records, raw_ostream &OS) {
16541652
OS << "};\n\n";
16551653
}
16561654

1657-
OS << "#endif\n";
1655+
OS << "#endif // LLVM_CLANG_ATTR_CLASSES_INC\n";
16581656
}
16591657

16601658
// Emits the class method definitions for attributes.
@@ -1729,7 +1727,7 @@ void EmitClangAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
17291727

17301728
static void EmitAttrList(raw_ostream &OS, StringRef Class,
17311729
const std::vector<Record*> &AttrList) {
1732-
std::vector<Record*>::const_iterator i = AttrList.begin(), e = AttrList.end();
1730+
auto i = AttrList.cbegin(), e = AttrList.cend();
17331731

17341732
if (i != e) {
17351733
// Move the end iterator back to emit the last attribute.
@@ -1881,7 +1879,7 @@ void EmitClangAttrPCHWrite(RecordKeeper &Records, raw_ostream &OS) {
18811879
OS << " case attr::" << R.getName() << ": {\n";
18821880
Args = R.getValueAsListOfDefs("Args");
18831881
if (R.isSubClassOf(InhClass) || !Args.empty())
1884-
OS << " const " << R.getName() << "Attr *SA = cast<" << R.getName()
1882+
OS << " const auto *SA = cast<" << R.getName()
18851883
<< "Attr>(A);\n";
18861884
if (R.isSubClassOf(InhClass))
18871885
OS << " Record.push_back(SA->isInherited());\n";
@@ -2045,9 +2043,7 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
20452043
GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
20462044
OS << "case AttrSyntax::CXX: {\n";
20472045
// C++11-style attributes are further split out based on the Scope.
2048-
for (std::map<std::string, std::vector<Record *>>::iterator I = CXX.begin(),
2049-
E = CXX.end();
2050-
I != E; ++I) {
2046+
for (auto I = CXX.cbegin(), E = CXX.cend(); I != E; ++I) {
20512047
if (I != CXX.begin())
20522048
OS << " else ";
20532049
if (I->first.empty())
@@ -2197,7 +2193,7 @@ void EmitClangAttrTemplateInstantiate(RecordKeeper &Records, raw_ostream &OS) {
21972193
continue;
21982194
}
21992195

2200-
OS << " const " << R.getName() << "Attr *A = cast<"
2196+
OS << " const auto *A = cast<"
22012197
<< R.getName() << "Attr>(At);\n";
22022198
bool TDependent = R.getValueAsBit("TemplateDependent");
22032199

@@ -2405,7 +2401,7 @@ static std::string GenerateCustomAppertainsTo(const Record &Subject,
24052401
// If this code has already been generated, simply return the previous
24062402
// instance of it.
24072403
static std::set<std::string> CustomSubjectSet;
2408-
std::set<std::string>::iterator I = CustomSubjectSet.find(FnName);
2404+
auto I = CustomSubjectSet.find(FnName);
24092405
if (I != CustomSubjectSet.end())
24102406
return *I;
24112407

@@ -2419,7 +2415,7 @@ static std::string GenerateCustomAppertainsTo(const Record &Subject,
24192415
}
24202416

24212417
OS << "static bool " << FnName << "(const Decl *D) {\n";
2422-
OS << " if (const " << GetSubjectWithSuffix(Base) << " *S = dyn_cast<";
2418+
OS << " if (const auto *S = dyn_cast<";
24232419
OS << GetSubjectWithSuffix(Base);
24242420
OS << ">(D))\n";
24252421
OS << " return " << Subject.getValueAsString("CheckCode") << ";\n";
@@ -2519,7 +2515,7 @@ static std::string GenerateLangOptRequirements(const Record &R,
25192515
// If this code has already been generated, simply return the previous
25202516
// instance of it.
25212517
static std::set<std::string> CustomLangOptsSet;
2522-
std::set<std::string>::iterator I = CustomLangOptsSet.find(FnName);
2518+
auto I = CustomLangOptsSet.find(FnName);
25232519
if (I != CustomLangOptsSet.end())
25242520
return *I;
25252521

@@ -2582,7 +2578,7 @@ static std::string GenerateTargetRequirements(const Record &Attr,
25822578
// If this code has already been generated, simply return the previous
25832579
// instance of it.
25842580
static std::set<std::string> CustomTargetSet;
2585-
std::set<std::string>::iterator I = CustomTargetSet.find(FnName);
2581+
auto I = CustomTargetSet.find(FnName);
25862582
if (I != CustomTargetSet.end())
25872583
return *I;
25882584

@@ -2800,13 +2796,13 @@ void EmitClangAttrDump(RecordKeeper &Records, raw_ostream &OS) {
28002796

28012797
Args = R.getValueAsListOfDefs("Args");
28022798
if (!Args.empty()) {
2803-
OS << " const " << R.getName() << "Attr *SA = cast<" << R.getName()
2799+
OS << " const auto *SA = cast<" << R.getName()
28042800
<< "Attr>(A);\n";
28052801
for (const auto *Arg : Args)
28062802
createArgument(*Arg, R.getName())->writeDump(OS);
28072803

2808-
for (auto AI = Args.begin(), AE = Args.end(); AI != AE; ++AI)
2809-
createArgument(**AI, R.getName())->writeDumpChildren(OS);
2804+
for (const auto *AI : Args)
2805+
createArgument(*AI, R.getName())->writeDumpChildren(OS);
28102806
}
28112807
OS <<
28122808
" break;\n"

0 commit comments

Comments
 (0)
Please sign in to comment.