return nullptr;
}
+llvm::iterator_range<diagtool::GroupRecord::subgroup_iterator>
+GroupRecord::subgroups() const {
+ return llvm::make_range(subgroup_begin(), subgroup_end());
+}
+
GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const {
return DiagArrays + Members;
}
return nullptr;
}
+llvm::iterator_range<diagtool::GroupRecord::diagnostics_iterator>
+GroupRecord::diagnostics() const {
+ return llvm::make_range(diagnostics_begin(), diagnostics_end());
+}
+
llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() {
return llvm::makeArrayRef(OptionTable);
}
const char *NameStr;
short DiagID;
uint8_t NameLen;
-
+
llvm::StringRef getName() const {
return llvm::StringRef(NameStr, NameLen);
}
bool operator==(group_iterator &Other) const {
return CurrentID == Other.CurrentID;
}
-
+
bool operator!=(group_iterator &Other) const {
return CurrentID != Other.CurrentID;
}
typedef group_iterator<GroupRecord> subgroup_iterator;
subgroup_iterator subgroup_begin() const;
subgroup_iterator subgroup_end() const;
+ llvm::iterator_range<subgroup_iterator> subgroups() const;
typedef group_iterator<DiagnosticRecord> diagnostics_iterator;
diagnostics_iterator diagnostics_begin() const;
diagnostics_iterator diagnostics_end() const;
+ llvm::iterator_range<diagnostics_iterator> diagnostics() const;
bool operator<(llvm::StringRef Other) const {
return getName() < Other;
DEF_DIAGTOOL("list-warnings",
"List warnings and their corresponding flags",
ListWarnings)
-
+
using namespace clang;
using namespace diagtool;
struct Entry {
llvm::StringRef DiagName;
llvm::StringRef Flag;
-
+
Entry(llvm::StringRef diagN, llvm::StringRef flag)
: DiagName(diagN), Flag(flag) {}
-
+
bool operator<(const Entry &x) const { return DiagName < x.DiagName; }
};
}
static void printEntries(std::vector<Entry> &entries, llvm::raw_ostream &out) {
- for (std::vector<Entry>::iterator it = entries.begin(), ei = entries.end();
- it != ei; ++it) {
- out << " " << it->DiagName;
- if (!it->Flag.empty())
- out << " [-W" << it->Flag << "]";
+ for (const Entry &E : entries) {
+ out << " " << E.DiagName;
+ if (!E.Flag.empty())
+ out << " [-W" << E.Flag << "]";
out << '\n';
}
}
int ListWarnings::run(unsigned int argc, char **argv, llvm::raw_ostream &out) {
std::vector<Entry> Flagged, Unflagged;
llvm::StringMap<std::vector<unsigned> > flagHistogram;
-
- ArrayRef<DiagnosticRecord> AllDiagnostics = getBuiltinDiagnosticsByName();
-
- for (ArrayRef<DiagnosticRecord>::iterator di = AllDiagnostics.begin(),
- de = AllDiagnostics.end();
- di != de; ++di) {
- unsigned diagID = di->DiagID;
-
+
+ for (const DiagnosticRecord &DR : getBuiltinDiagnosticsByName()) {
+ const unsigned diagID = DR.DiagID;
+
if (DiagnosticIDs::isBuiltinNote(diagID))
continue;
-
+
if (!DiagnosticIDs::isBuiltinWarningOrExtension(diagID))
continue;
-
- Entry entry(di->getName(),
- DiagnosticIDs::getWarningOptionForDiag(diagID));
-
+
+ Entry entry(DR.getName(), DiagnosticIDs::getWarningOptionForDiag(diagID));
+
if (entry.Flag.empty())
Unflagged.push_back(entry);
else {
flagHistogram[entry.Flag].push_back(diagID);
}
}
-
+
out << "Warnings with flags (" << Flagged.size() << "):\n";
printEntries(Flagged, out);
-
+
out << "Warnings without flags (" << Unflagged.size() << "):\n";
printEntries(Unflagged, out);
out << "\nSTATISTICS:\n\n";
- double percentFlagged = ((double) Flagged.size())
- / (Flagged.size() + Unflagged.size()) * 100.0;
-
- out << " Percentage of warnings with flags: "
- << llvm::format("%.4g",percentFlagged) << "%\n";
-
+ double percentFlagged =
+ ((double)Flagged.size()) / (Flagged.size() + Unflagged.size()) * 100.0;
+
+ out << " Percentage of warnings with flags: "
+ << llvm::format("%.4g", percentFlagged) << "%\n";
+
out << " Number of unique flags: "
<< flagHistogram.size() << '\n';
-
+
double avgDiagsPerFlag = (double) Flagged.size() / flagHistogram.size();
out << " Average number of diagnostics per flag: "
<< llvm::format("%.4g", avgDiagsPerFlag) << '\n';
<< flagHistogram["pedantic"].size() << '\n';
out << '\n';
-
+
return 0;
}
// which ones are turned on.
// FIXME: It would be very nice to print which flags are turning on which
// diagnostics, but this can be done with a diff.
- ArrayRef<DiagnosticRecord> AllDiagnostics = getBuiltinDiagnosticsByName();
std::vector<PrettyDiag> Active;
- for (ArrayRef<DiagnosticRecord>::iterator I = AllDiagnostics.begin(),
- E = AllDiagnostics.end();
- I != E; ++I) {
- unsigned DiagID = I->DiagID;
-
+ for (const DiagnosticRecord &DR : getBuiltinDiagnosticsByName()) {
+ unsigned DiagID = DR.DiagID;
+
if (DiagnosticIDs::isBuiltinNote(DiagID))
continue;
-
+
if (!DiagnosticIDs::isBuiltinWarningOrExtension(DiagID))
continue;
continue;
StringRef WarningOpt = DiagnosticIDs::getWarningOptionForDiag(DiagID);
- Active.push_back(PrettyDiag(I->getName(), WarningOpt, DiagLevel));
+ Active.push_back(PrettyDiag(DR.getName(), WarningOpt, DiagLevel));
}
// Print them all out.
- for (std::vector<PrettyDiag>::const_iterator I = Active.begin(),
- E = Active.end(); I != E; ++I) {
+ for (const PrettyDiag &PD : Active) {
if (ShouldShowLevels)
- Out << getCharForLevel(I->Level) << " ";
- Out << I->Name;
- if (!I->Flag.empty())
- Out << " [-W" << I->Flag << "]";
+ Out << getCharForLevel(PD.Level) << " ";
+ Out << PD.Name;
+ if (!PD.Flag.empty())
+ Out << " [-W" << PD.Flag << "]";
Out << '\n';
}
resetColor();
++Indent;
- for (GroupRecord::subgroup_iterator I = Group.subgroup_begin(),
- E = Group.subgroup_end();
- I != E; ++I) {
- printGroup(*I, Indent);
+ for (const GroupRecord &GR : Group.subgroups()) {
+ printGroup(GR, Indent);
}
if (!FlagsOnly) {
- for (GroupRecord::diagnostics_iterator I = Group.diagnostics_begin(),
- E = Group.diagnostics_end();
- I != E; ++I) {
- if (ShowColors && !isIgnored(I->DiagID))
+ for (const DiagnosticRecord &DR : Group.diagnostics()) {
+ if (ShowColors && !isIgnored(DR.DiagID))
setColor(llvm::raw_ostream::GREEN);
out.indent(Indent * 2);
- out << I->getName();
+ out << DR.getName();
resetColor();
out << "\n";
}
ArrayRef<GroupRecord> AllGroups = getDiagnosticGroups();
llvm::DenseSet<unsigned> NonRootGroupIDs;
- for (ArrayRef<GroupRecord>::iterator I = AllGroups.begin(),
- E = AllGroups.end();
- I != E; ++I) {
- for (GroupRecord::subgroup_iterator SI = I->subgroup_begin(),
- SE = I->subgroup_end();
- SI != SE; ++SI) {
+ for (const GroupRecord &GR : AllGroups) {
+ for (auto SI = GR.subgroup_begin(), SE = GR.subgroup_end(); SI != SE;
+ ++SI) {
NonRootGroupIDs.insert((unsigned)SI.getID());
}
}