From 991047a8ee509e70ea31a7fbc519633cc7c6ddfd Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Thu, 2 Feb 2017 20:39:14 +0330 Subject: mutator now accesses the diagnostics printed out by clang and adds them to the report. for the time being they are all tagged ClangDiag, later to be changed to their corresponding misra rule number. most of those warnings are have nothing to do with misra so they will be omitted later on. I'm supposed to be on a break... --- mutator-lvl0.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'mutator-lvl0.cpp') diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp index f0c78e4..ddf4cbc 100644 --- a/mutator-lvl0.cpp +++ b/mutator-lvl0.cpp @@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include "clang/AST/Type.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" @@ -53,6 +54,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include "clang/Tooling/Tooling.h" #include "clang/Rewrite/Core/Rewriter.h" /*LLVM headers*/ +#include "llvm/ADT/SmallString.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" #include "llvm/IR/Function.h" @@ -7233,6 +7235,47 @@ private: MatchFinder Matcher; }; /**********************************************************************************************************************/ +class Mutator0DiagnosticConsumer : public clang::DiagnosticConsumer +{ +public: + + virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override + { + DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info); + + SourceLocation SL = Info.getLocation(); + + SourceManager &SM = Info.getSourceManager(); + + if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, SM, SL)) + { + return void(); + } + + if (!Devi::IsTheMatchInMainFile(MainFileOnly, SM, SL)) + { + return void(); + } + + SL = SM.getSpellingLoc(SL); + + unsigned SpellingLine = SM.getSpellingLineNumber(SL); + unsigned SpellingColumn = SM.getSpellingColumnNumber(SL); + std::string FileName = SM.getFilename(SL).str(); + + SmallString<100> DiagBuffer; + + Info.FormatDiagnostic(DiagBuffer); + + std::cout << "ClangDiag:" << DiagBuffer.str().str() << ":" << SL.printToString(SM) << ":" << std::endl; + + XMLDocOut.XMLAddNode(SpellingLine, SpellingColumn, FileName, "ClangDiag", DiagBuffer.str().str()); + JSONDocOUT.JSONAddElement(SpellingLine, SpellingColumn, FileName, "ClangDiag", DiagBuffer.str().str()); + } + +private: + +}; /**********************************************************************************************************************/ class MyFrontendAction : public ASTFrontendAction { @@ -7248,9 +7291,15 @@ public: { CI.getPreprocessor().addPPCallbacks(llvm::make_unique(&CI.getSourceManager())); - DiagnosticsEngine &DiagEngine [[maybe_unused]] = CI.getPreprocessor().getDiagnostics(); + DiagnosticsEngine &DiagEngine = CI.getPreprocessor().getDiagnostics(); + +#if 0 + std::unique_ptr M0DiagConsumer(new Mutator0DiagnosticConsumer); +#endif + + Mutator0DiagnosticConsumer* M0DiagConsumer = new Mutator0DiagnosticConsumer; - const DiagnosticConsumer* DiagConsumer [[maybe_unused]] = DiagEngine.getClient(); + DiagEngine.setClient(M0DiagConsumer, true); #if 0 const IdentifierTable &IT [[maybe_unused]] = CI.getPreprocessor().getIdentifierTable(); -- cgit v1.2.3