aboutsummaryrefslogtreecommitdiffstats
path: root/mutator_aux.cpp
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2016-12-26 22:42:27 +0000
committerbloodstalker <thabogre@gmail.com>2016-12-26 22:42:27 +0000
commiteae4d12ba1b114e6078fae6078737b93379f2676 (patch)
tree2a375b31ad6cb67182f433244471dc555b7f4698 /mutator_aux.cpp
parentremoved (diff)
downloadmutator-eae4d12ba1b114e6078fae6078737b93379f2676.tar.gz
mutator-eae4d12ba1b114e6078fae6078737b93379f2676.zip
added the json report writer implementations
Diffstat (limited to '')
-rw-r--r--mutator_aux.cpp88
1 files changed, 86 insertions, 2 deletions
diff --git a/mutator_aux.cpp b/mutator_aux.cpp
index f094ea3..20bcbb0 100644
--- a/mutator_aux.cpp
+++ b/mutator_aux.cpp
@@ -6,6 +6,7 @@
#include <string>
#include <cassert>
#include <iostream>
+#include <fstream>
#include "clang/AST/AST.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Rewrite/Core/Rewriter.h"
@@ -49,7 +50,7 @@ SourceLocation SourceLocationHasMacro (SourceLocation SL, Rewriter &Rewrite, std
return (SL);
}
-/*********************************************************************************************************************/
+/******************************************************XMLReport******************************************************/
XMLReport::XMLReport()
{
RootPointer = XMLReportDoc.NewElement("Report");
@@ -132,7 +133,90 @@ void XMLReport::SaveReport(void)
std::cout << "could not write xml misra report." << std::endl;
}
}
-/*********************************************************************************************************************/
+/***************************************************End of XMLReport**************************************************/
+
+/*****************************************************JSONReport******************************************************/
+JSONReport::JSONReport()
+{
+
+}
+
+void JSONReport::JSONCreateReport(void)
+{
+ JSONRepFile.open("./test/misrareport.json", std::ios::out);
+}
+
+void JSONReport::JSONAddElement(ASTContext* ASTC, SourceLocation SL, std::string MisraRule, std::string Description)
+{
+ assert(SL.isValid() && "SourceLocation passed as function parameter in an overload(1) of JSONAddElement is not valid.");
+
+ FullSourceLoc FSL = ASTC->getFullLoc(SL);
+
+ unsigned LineNumber = FSL.getSpellingLineNumber();
+ unsigned ColumnNumber = FSL.getSpellingColumnNumber();
+
+ const SourceManager& SM = FSL.getManager();
+ std::string FileNameString = SM.getFilename(SL).str();
+
+ json RepJ;
+
+ RepJ["MisraDiag"]["Description"] = Description.c_str();
+ RepJ["MisraDiag"]["Misra-C:2004Rule"] = MisraRule.c_str();
+ RepJ["MisraDiag"]["FileName"] = FileNameString.c_str();
+ RepJ["MisraDiag"]["SpellingLineNumber"] = LineNumber;
+ RepJ["MisraDiag"]["SpellingColumnNumber"] = ColumnNumber;
+
+ JSONRepFile << RepJ << std::endl;
+}
+
+void JSONReport::JSONAddElement(FullSourceLoc FullSrcLoc, SourceLocation SL, std::string MisraRule, std::string Description)
+{
+ assert(SL.isValid() && "SourceLocation passed as function parameter in an overload(2) of XMLAddNode is not valid.");
+
+ unsigned LineNumber = FullSrcLoc.getSpellingLineNumber();
+ unsigned ColumnNumber = FullSrcLoc.getSpellingColumnNumber();
+
+ const SourceManager& SM = FullSrcLoc.getManager();
+ std::string FileNameString = SM.getFilename(SL).str();
+
+ json RepJ;
+
+ RepJ["MisraDiag"]["Description"] = Description.c_str();
+ RepJ["MisraDiag"]["Misra-C:2004Rule"] = MisraRule.c_str();
+ RepJ["MisraDiag"]["FileName"] = FileNameString.c_str();
+ RepJ["MisraDiag"]["SpellingLineNumber"] = LineNumber;
+ RepJ["MisraDiag"]["SpellingColumnNumber"] = ColumnNumber;
+
+ JSONRepFile << RepJ << std::endl;
+}
+
+void JSONReport::JSONAddElement(const SourceManager &SM, SourceLocation SL, std::string MisraRule, std::string Description)
+{
+ SL = SM.getSpellingLoc(SL);
+
+ assert(SL.isValid() && "SourceLocation Acquired by SourceManager in an overload(3) of XMLAddNode is not valid.");
+
+ unsigned LineNumber = SM.getSpellingLineNumber(SL);
+ unsigned ColumnNumber = SM.getSpellingColumnNumber(SL);
+
+ std::string FileNameString = SM.getFilename(SL).str();
+
+ json RepJ;
+
+ RepJ["MisraDiag"]["Description"] = Description.c_str();
+ RepJ["MisraDiag"]["Misra-C:2004Rule"] = MisraRule.c_str();
+ RepJ["MisraDiag"]["FileName"] = FileNameString.c_str();
+ RepJ["MisraDiag"]["SpellingLineNumber"] = LineNumber;
+ RepJ["MisraDiag"]["SpellingColumnNumber"] = ColumnNumber;
+
+ JSONRepFile << RepJ << std::endl;
+}
+
+void JSONReport::CloseReport(void)
+{
+ JSONRepFile.close();
+}
+/****************************************************End Of JSONReport************************************************/
}
/*********************************************************************************************************************/
/*last line intentionally left blank.*/