diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-03-13 22:53:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-03-13 22:53:41 +0000 |
commit | 9750429e61dffb55035abe1514a028ccb8d1b295 (patch) | |
tree | 246960acdbc56d9ccbb6bc0eab3174ff1906db4b /llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp | |
parent | 94d48e0bd07f19df239d11627ad3c867be2c9503 (diff) | |
download | bcm5719-llvm-9750429e61dffb55035abe1514a028ccb8d1b295.tar.gz bcm5719-llvm-9750429e61dffb55035abe1514a028ccb8d1b295.zip |
Add (hidden) TableGen command option '-clang-component' which specifies the
component's warnings to process for '-gen-clang-diags-defs'.
Also, when the component is specified, generate a '#if' prologue at the top of
the generated .def file (to match the current files).
llvm-svn: 66975
Diffstat (limited to 'llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp')
-rw-r--r-- | llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp b/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp index fa139e7729e..f9501fb494d 100644 --- a/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/llvm/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -22,8 +22,8 @@ typedef std::vector<Record*> RecordVector; 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; @@ -49,6 +49,11 @@ static void EmitEscaped(std::ostream& OS, const std::string &s) { } } +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) { @@ -57,12 +62,9 @@ static void ProcessDiag(std::ostream& OS, const Record* DiagClass, 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."); @@ -77,8 +79,30 @@ void ClangDiagsDefsEmitter::run(std::ostream &OS) { 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 +} |