typedef std::vector<Record*> SuperClassVector;
typedef std::vector<RecordVal> RecordValVector;
-static const RecordVal* findRecordVal(const RecordValVector& Vals,
- const std::string &key) {
+static const RecordVal* findRecordVal(const Record& R, const std::string &key) {
+ const RecordValVector &Vals = R.getValues();
for (RecordValVector::const_iterator I=Vals.begin(), E=Vals.end(); I!=E; ++I)
if ((*I).getName() == key)
return &*I;
}
}
+static void EmitAllCaps(std::ostream& OS, const std::string &s) {
+ for (std::string::const_iterator I=s.begin(), E=s.end(); I!=E; ++I)
+ OS << char(toupper(*I));
+}
+
static void ProcessDiag(std::ostream& OS, const Record* DiagClass,
const Record& R) {
return;
OS << "DIAG(" << R.getName() << ", ";
+ EmitAllCaps(OS, DiagKind->getName());
- const std::string &s = DiagKind->getName();
- for (std::string::const_iterator I=s.begin(), E=s.end(); I!=E; ++I)
- OS << char(toupper(*I));
-
- const RecordVal* Text = findRecordVal(R.getValues(), "Text");
+ const RecordVal* Text = findRecordVal(R, "Text");
assert(Text && "No 'Text' entry in Diagnostic.");
const StringInit* TextVal = dynamic_cast<const StringInit*>(Text->getValue());
assert(TextVal && "Value 'Text' must be a string.");
const Record* DiagClass = Records.getClass("Diagnostic");
assert(DiagClass && "No Diagnostic class defined.");
+ // Write the #if guard
+ if (!Component.empty()) {
+ OS << "#ifdef ";
+ EmitAllCaps(OS, Component);
+ OS << "START\n__";
+ EmitAllCaps(OS, Component);
+ OS << "START = DIAG_START_";
+ EmitAllCaps(OS, Component);
+ OS << ",\n#undef ";
+ EmitAllCaps(OS, Component);
+ OS << "START\n#endif\n";
+ }
+
for (RecordVector::const_iterator I=Diags.begin(), E=Diags.end(); I!=E; ++I) {
- // FIXME: Compare the component.
+ if (!Component.empty()) {
+ const RecordVal* V = findRecordVal(**I, "Component");
+ if (!V)
+ continue;
+
+ const StringInit* SV = dynamic_cast<const StringInit*>(V->getValue());
+ if (SV->getValue() != Component)
+ continue;
+ }
+
ProcessDiag(OS, DiagClass, **I);
}
-}
\ No newline at end of file
+}
cl::list<std::string>
IncludeDirs("I", cl::desc("Directory of include files"),
cl::value_desc("directory"), cl::Prefix);
+
+ cl::opt<std::string>
+ ClangComponent("clang-component",
+ cl::desc("Only use warnings from specified component"),
+ cl::value_desc("component"), cl::Hidden);
}
AsmWriterEmitter(Records).run(*Out);
break;
case GenClangDiagsDefs:
- ClangDiagsDefsEmitter(Records).run(*Out);
+ ClangDiagsDefsEmitter(Records, ClangComponent).run(*Out);
break;
case GenDAGISel:
DAGISelEmitter(Records).run(*Out);