[PATCH] D15313: [Clang] Use range loops and autos in utils/TableGen/ClangAttrEmitter.cpp

2015-12-07 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko created this revision.
Eugene.Zelenko added reviewers: hans, aaron.ballman.
Eugene.Zelenko added a subscriber: cfe-commits.
Eugene.Zelenko set the repository for this revision to rL LLVM.

I fixed Clang-tidy modernize-loop-convert and modernize-use-auto. Autos are 
also used for pointer variables assigned via casts. Patch includes other minor 
cleanups.

Fixes are in both source and generated code.

Build and regressions were finr on RHEL 6.

Repository:
  rL LLVM

http://reviews.llvm.org/D15313

Files:
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -619,7 +619,7 @@
 std::vector uniques;
 std::set unique_set(enums.begin(), enums.end());
 for (const auto &i : enums) {
-  std::set::iterator set_i = unique_set.find(i);
+  auto set_i = unique_set.find(i);
   if (set_i != unique_set.end()) {
 uniques.push_back(i);
 unique_set.erase(set_i);
@@ -665,8 +665,7 @@
   OS << type << " " << getUpperName();
 }
 void writeDeclarations(raw_ostream &OS) const override {
-  std::vector::const_iterator i = uniques.begin(),
-   e = uniques.end();
+  auto i = uniques.cbegin(), e = uniques.cend();
   // The last one needs to not have a comma.
   --e;
 
@@ -771,8 +770,7 @@
 bool isVariadicEnumArg() const override { return true; }
 
 void writeDeclarations(raw_ostream &OS) const override {
-  std::vector::const_iterator i = uniques.begin(),
-   e = uniques.end();
+  auto i = uniques.cbegin(), e = uniques.cend();
   // The last one needs to not have a comma.
   --e;
 
@@ -958,7 +956,7 @@
 }
 
 void writeTemplateInstantiation(raw_ostream &OS) const override {
-  OS << "  " << getType() << " *tempInst" << getUpperName()
+  OS << "  auto *tempInst" << getUpperName()
  << " = new (C, 16) " << getType()
  << "[A->" << getLowerName() << "_size()];\n";
   OS << "  {\n";
@@ -1537,7 +1535,7 @@
   }
   OS << ", SourceRange Loc = SourceRange()";
   OS << ") {\n";
-  OS << "" << R.getName() << "Attr *A = new (Ctx) " << R.getName();
+  OS << "auto *A = new (Ctx) " << R.getName();
   OS << "Attr(Loc, Ctx, ";
   for (auto const &ai : Args) {
 if (ai->isFake() && !emitFake) continue;
@@ -1654,7 +1652,7 @@
 OS << "};\n\n";
   }
 
-  OS << "#endif\n";
+  OS << "#endif // LLVM_CLANG_ATTR_CLASSES_INC\n";
 }
 
 // Emits the class method definitions for attributes.
@@ -1729,7 +1727,7 @@
 
 static void EmitAttrList(raw_ostream &OS, StringRef Class,
  const std::vector &AttrList) {
-  std::vector::const_iterator i = AttrList.begin(), e = AttrList.end();
+  auto i = AttrList.cbegin(), e = AttrList.cend();
 
   if (i != e) {
 // Move the end iterator back to emit the last attribute.
@@ -1881,7 +1879,7 @@
 OS << "  case attr::" << R.getName() << ": {\n";
 Args = R.getValueAsListOfDefs("Args");
 if (R.isSubClassOf(InhClass) || !Args.empty())
-  OS << "const " << R.getName() << "Attr *SA = cast<" << R.getName()
+  OS << "const auto *SA = cast<" << R.getName()
  << "Attr>(A);\n";
 if (R.isSubClassOf(InhClass))
   OS << "Record.push_back(SA->isInherited());\n";
@@ -2045,9 +2043,7 @@
   GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
   OS << "case AttrSyntax::CXX: {\n";
   // C++11-style attributes are further split out based on the Scope.
-  for (std::map>::iterator I = CXX.begin(),
-  E = CXX.end();
-   I != E; ++I) {
+  for (auto I = CXX.cbegin(), E = CXX.cend(); I != E; ++I) {
 if (I != CXX.begin())
   OS << " else ";
 if (I->first.empty())
@@ -2197,7 +2193,7 @@
   continue;
 }
 
-OS << "  const " << R.getName() << "Attr *A = cast<"
+OS << "  const auto *A = cast<"
<< R.getName() << "Attr>(At);\n";
 bool TDependent = R.getValueAsBit("TemplateDependent");
 
@@ -2405,7 +2401,7 @@
   // If this code has already been generated, simply return the previous
   // instance of it.
   static std::set CustomSubjectSet;
-  std::set::iterator I = CustomSubjectSet.find(FnName);
+  const auto I = CustomSubjectSet.find(FnName);
   if (I != CustomSubjectSet.end())
 return *I;
 
@@ -2419,7 +2415,7 @@
   }
 
   OS << "static bool " << FnName << "(const Decl *D) {\n";
-  OS << "  if (const " << GetSubjectWithSuffix(Base) << " *S = dyn_cast<";
+  OS << "  if (const auto *S = dyn_cast<";
   OS << GetSubjectWithSuffix(Base);
   OS << ">(D))\n";
   OS << "return " << Subject.getValueAsString("CheckCode") << ";\n";
@@ -2519,7 +2515,7 @@
   // If this code has already been generated, simply return the previo

Re: [PATCH] D15313: [Clang] Use range loops and autos in utils/TableGen/ClangAttrEmitter.cpp

2015-12-08 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

A few small nits, but mostly looks good. Thank you for this!



Comment at: utils/TableGen/ClangAttrEmitter.cpp:2404
@@ -2407,3 +2403,3 @@
   static std::set CustomSubjectSet;
-  std::set::iterator I = CustomSubjectSet.find(FnName);
+  const auto I = CustomSubjectSet.find(FnName);
   if (I != CustomSubjectSet.end())

I don't think this is the correct change (a const std::foo::iterator is 
often different than a std::foo::const_iterator). I would drop the const 
since the original is an iterator instead of a const_iterator anyway.


Comment at: utils/TableGen/ClangAttrEmitter.cpp:2518
@@ -2521,3 +2517,3 @@
   static std::set CustomLangOptsSet;
-  std::set::iterator I = CustomLangOptsSet.find(FnName);
+  const auto I = CustomLangOptsSet.find(FnName);
   if (I != CustomLangOptsSet.end())

Same here.


Comment at: utils/TableGen/ClangAttrEmitter.cpp:2581
@@ -2584,3 +2580,3 @@
   static std::set CustomTargetSet;
-  std::set::iterator I = CustomTargetSet.find(FnName);
+  const auto I = CustomTargetSet.find(FnName);
   if (I != CustomTargetSet.end())

And here.


Repository:
  rL LLVM

http://reviews.llvm.org/D15313



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15313: [Clang] Use range loops and autos in utils/TableGen/ClangAttrEmitter.cpp

2015-12-08 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko removed rL LLVM as the repository for this revision.
Eugene.Zelenko updated this revision to Diff 42192.
Eugene.Zelenko added a comment.

Replaced const auto with auto as suggested by Aaron.


http://reviews.llvm.org/D15313

Files:
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -619,7 +619,7 @@
 std::vector uniques;
 std::set unique_set(enums.begin(), enums.end());
 for (const auto &i : enums) {
-  std::set::iterator set_i = unique_set.find(i);
+  auto set_i = unique_set.find(i);
   if (set_i != unique_set.end()) {
 uniques.push_back(i);
 unique_set.erase(set_i);
@@ -665,8 +665,7 @@
   OS << type << " " << getUpperName();
 }
 void writeDeclarations(raw_ostream &OS) const override {
-  std::vector::const_iterator i = uniques.begin(),
-   e = uniques.end();
+  auto i = uniques.cbegin(), e = uniques.cend();
   // The last one needs to not have a comma.
   --e;
 
@@ -771,8 +770,7 @@
 bool isVariadicEnumArg() const override { return true; }
 
 void writeDeclarations(raw_ostream &OS) const override {
-  std::vector::const_iterator i = uniques.begin(),
-   e = uniques.end();
+  auto i = uniques.cbegin(), e = uniques.cend();
   // The last one needs to not have a comma.
   --e;
 
@@ -958,7 +956,7 @@
 }
 
 void writeTemplateInstantiation(raw_ostream &OS) const override {
-  OS << "  " << getType() << " *tempInst" << getUpperName()
+  OS << "  auto *tempInst" << getUpperName()
  << " = new (C, 16) " << getType()
  << "[A->" << getLowerName() << "_size()];\n";
   OS << "  {\n";
@@ -1537,7 +1535,7 @@
   }
   OS << ", SourceRange Loc = SourceRange()";
   OS << ") {\n";
-  OS << "" << R.getName() << "Attr *A = new (Ctx) " << R.getName();
+  OS << "auto *A = new (Ctx) " << R.getName();
   OS << "Attr(Loc, Ctx, ";
   for (auto const &ai : Args) {
 if (ai->isFake() && !emitFake) continue;
@@ -1654,7 +1652,7 @@
 OS << "};\n\n";
   }
 
-  OS << "#endif\n";
+  OS << "#endif // LLVM_CLANG_ATTR_CLASSES_INC\n";
 }
 
 // Emits the class method definitions for attributes.
@@ -1729,7 +1727,7 @@
 
 static void EmitAttrList(raw_ostream &OS, StringRef Class,
  const std::vector &AttrList) {
-  std::vector::const_iterator i = AttrList.begin(), e = AttrList.end();
+  auto i = AttrList.cbegin(), e = AttrList.cend();
 
   if (i != e) {
 // Move the end iterator back to emit the last attribute.
@@ -1881,7 +1879,7 @@
 OS << "  case attr::" << R.getName() << ": {\n";
 Args = R.getValueAsListOfDefs("Args");
 if (R.isSubClassOf(InhClass) || !Args.empty())
-  OS << "const " << R.getName() << "Attr *SA = cast<" << R.getName()
+  OS << "const auto *SA = cast<" << R.getName()
  << "Attr>(A);\n";
 if (R.isSubClassOf(InhClass))
   OS << "Record.push_back(SA->isInherited());\n";
@@ -2045,9 +2043,7 @@
   GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
   OS << "case AttrSyntax::CXX: {\n";
   // C++11-style attributes are further split out based on the Scope.
-  for (std::map>::iterator I = CXX.begin(),
-  E = CXX.end();
-   I != E; ++I) {
+  for (auto I = CXX.cbegin(), E = CXX.cend(); I != E; ++I) {
 if (I != CXX.begin())
   OS << " else ";
 if (I->first.empty())
@@ -2197,7 +2193,7 @@
   continue;
 }
 
-OS << "  const " << R.getName() << "Attr *A = cast<"
+OS << "  const auto *A = cast<"
<< R.getName() << "Attr>(At);\n";
 bool TDependent = R.getValueAsBit("TemplateDependent");
 
@@ -2405,7 +2401,7 @@
   // If this code has already been generated, simply return the previous
   // instance of it.
   static std::set CustomSubjectSet;
-  std::set::iterator I = CustomSubjectSet.find(FnName);
+  auto I = CustomSubjectSet.find(FnName);
   if (I != CustomSubjectSet.end())
 return *I;
 
@@ -2419,7 +2415,7 @@
   }
 
   OS << "static bool " << FnName << "(const Decl *D) {\n";
-  OS << "  if (const " << GetSubjectWithSuffix(Base) << " *S = dyn_cast<";
+  OS << "  if (const auto *S = dyn_cast<";
   OS << GetSubjectWithSuffix(Base);
   OS << ">(D))\n";
   OS << "return " << Subject.getValueAsString("CheckCode") << ";\n";
@@ -2519,7 +2515,7 @@
   // If this code has already been generated, simply return the previous
   // instance of it.
   static std::set CustomLangOptsSet;
-  std::set::iterator I = CustomLangOptsSet.find(FnName);
+  auto I = CustomLangOptsSet.find(FnName);
   if (I != CustomLangOptsSet.end())
 return *I;
 
@@ -2582,7 +2578,7 @@
   // If this code has already been gener

Re: [PATCH] D15313: [Clang] Use range loops and autos in utils/TableGen/ClangAttrEmitter.cpp

2015-12-08 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


http://reviews.llvm.org/D15313



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15313: [Clang] Use range loops and autos in utils/TableGen/ClangAttrEmitter.cpp

2015-12-08 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL255042: Use range loops and autos in 
utils/TableGen/ClangAttrEmitter.cpp and… (authored by eugenezelenko).

Changed prior to commit:
  http://reviews.llvm.org/D15313?vs=42192&id=42197#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D15313

Files:
  cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
===
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
@@ -619,7 +619,7 @@
 std::vector uniques;
 std::set unique_set(enums.begin(), enums.end());
 for (const auto &i : enums) {
-  std::set::iterator set_i = unique_set.find(i);
+  auto set_i = unique_set.find(i);
   if (set_i != unique_set.end()) {
 uniques.push_back(i);
 unique_set.erase(set_i);
@@ -665,8 +665,7 @@
   OS << type << " " << getUpperName();
 }
 void writeDeclarations(raw_ostream &OS) const override {
-  std::vector::const_iterator i = uniques.begin(),
-   e = uniques.end();
+  auto i = uniques.cbegin(), e = uniques.cend();
   // The last one needs to not have a comma.
   --e;
 
@@ -771,8 +770,7 @@
 bool isVariadicEnumArg() const override { return true; }
 
 void writeDeclarations(raw_ostream &OS) const override {
-  std::vector::const_iterator i = uniques.begin(),
-   e = uniques.end();
+  auto i = uniques.cbegin(), e = uniques.cend();
   // The last one needs to not have a comma.
   --e;
 
@@ -958,7 +956,7 @@
 }
 
 void writeTemplateInstantiation(raw_ostream &OS) const override {
-  OS << "  " << getType() << " *tempInst" << getUpperName()
+  OS << "  auto *tempInst" << getUpperName()
  << " = new (C, 16) " << getType()
  << "[A->" << getLowerName() << "_size()];\n";
   OS << "  {\n";
@@ -1537,7 +1535,7 @@
   }
   OS << ", SourceRange Loc = SourceRange()";
   OS << ") {\n";
-  OS << "" << R.getName() << "Attr *A = new (Ctx) " << R.getName();
+  OS << "auto *A = new (Ctx) " << R.getName();
   OS << "Attr(Loc, Ctx, ";
   for (auto const &ai : Args) {
 if (ai->isFake() && !emitFake) continue;
@@ -1654,7 +1652,7 @@
 OS << "};\n\n";
   }
 
-  OS << "#endif\n";
+  OS << "#endif // LLVM_CLANG_ATTR_CLASSES_INC\n";
 }
 
 // Emits the class method definitions for attributes.
@@ -1729,7 +1727,7 @@
 
 static void EmitAttrList(raw_ostream &OS, StringRef Class,
  const std::vector &AttrList) {
-  std::vector::const_iterator i = AttrList.begin(), e = AttrList.end();
+  auto i = AttrList.cbegin(), e = AttrList.cend();
 
   if (i != e) {
 // Move the end iterator back to emit the last attribute.
@@ -1881,7 +1879,7 @@
 OS << "  case attr::" << R.getName() << ": {\n";
 Args = R.getValueAsListOfDefs("Args");
 if (R.isSubClassOf(InhClass) || !Args.empty())
-  OS << "const " << R.getName() << "Attr *SA = cast<" << R.getName()
+  OS << "const auto *SA = cast<" << R.getName()
  << "Attr>(A);\n";
 if (R.isSubClassOf(InhClass))
   OS << "Record.push_back(SA->isInherited());\n";
@@ -2045,9 +2043,7 @@
   GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
   OS << "case AttrSyntax::CXX: {\n";
   // C++11-style attributes are further split out based on the Scope.
-  for (std::map>::iterator I = CXX.begin(),
-  E = CXX.end();
-   I != E; ++I) {
+  for (auto I = CXX.cbegin(), E = CXX.cend(); I != E; ++I) {
 if (I != CXX.begin())
   OS << " else ";
 if (I->first.empty())
@@ -2197,7 +2193,7 @@
   continue;
 }
 
-OS << "  const " << R.getName() << "Attr *A = cast<"
+OS << "  const auto *A = cast<"
<< R.getName() << "Attr>(At);\n";
 bool TDependent = R.getValueAsBit("TemplateDependent");
 
@@ -2405,7 +2401,7 @@
   // If this code has already been generated, simply return the previous
   // instance of it.
   static std::set CustomSubjectSet;
-  std::set::iterator I = CustomSubjectSet.find(FnName);
+  auto I = CustomSubjectSet.find(FnName);
   if (I != CustomSubjectSet.end())
 return *I;
 
@@ -2419,7 +2415,7 @@
   }
 
   OS << "static bool " << FnName << "(const Decl *D) {\n";
-  OS << "  if (const " << GetSubjectWithSuffix(Base) << " *S = dyn_cast<";
+  OS << "  if (const auto *S = dyn_cast<";
   OS << GetSubjectWithSuffix(Base);
   OS << ">(D))\n";
   OS << "return " << Subject.getValueAsString("CheckCode") << ";\n";
@@ -2519,7 +2515,7 @@
   // If this code has already been generated, simply return the previous
   // instance of it.
   static std::set CustomLangOptsSet;
-  std::set::iterator I = CustomLangOptsSet.find(FnName);
+  auto I = CustomLangOp