diff options
author | bloodstalker <thabogre@gmail.com> | 2017-05-23 11:46:49 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2017-05-23 11:46:49 +0000 |
commit | 886f344694057f864fd211f285d48921348bfe1d (patch) | |
tree | 28c4f99e0776e27cf1b05dfa798a96327bd57096 | |
parent | nothing (diff) | |
download | mutator-886f344694057f864fd211f285d48921348bfe1d.tar.gz mutator-886f344694057f864fd211f285d48921348bfe1d.zip |
added xml report classes, there is a problem with a tinyxml2 assert being triggered on inheritance while the same problem doesnt exist when you dont inherit, raised an issue, until that gets sorted out, the report classes are one-offs, took me 2 days
-rw-r--r-- | mutator-lvl0.cpp | 15 | ||||
-rw-r--r-- | mutator-lvl0.h | 65 | ||||
-rw-r--r-- | mutator_aux.h | 2 | ||||
-rw-r--r-- | mutator_report.cpp | 4 | ||||
-rw-r--r-- | mutator_report.h | 4 |
5 files changed, 77 insertions, 13 deletions
diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp index e5fd494..f73bd6a 100644 --- a/mutator-lvl0.cpp +++ b/mutator-lvl0.cpp @@ -89,6 +89,7 @@ using namespace clang::tooling; /*global vars*/ Devi::XMLReport XMLDocOut; Devi::JSONReport JSONDocOUT; +MutagenExtraction ME; std::vector<SourceLocation> MacroDefSourceLocation; std::vector<SourceLocation> MacroUndefSourceLocation; @@ -438,14 +439,14 @@ public: { const IfStmt *IS = MR.Nodes.getNodeAs<clang::IfStmt>("mcelse"); -#if 1 if (mutagen) { ME.ExtractAncestry(ast_type_traits::DynTypedNode::create(*IS), *MR.Context); +#if 0 ME.DumpLast(); ME.DumpAll(); - } #endif + } SourceLocation SL = IS->getLocStart(); CheckSLValidity(SL); @@ -472,7 +473,6 @@ public: } private: - MutagenExtraction ME; Rewriter &Rewrite; }; /**********************************************************************************************************************/ @@ -486,6 +486,11 @@ public: { const IfStmt *IS = MR.Nodes.getNodeAs<clang::IfStmt>("mcif"); + if (mutagen) + { + ME.ExtractAncestry(ast_type_traits::DynTypedNode::create(*IS), *MR.Context); + } + SourceLocation SL = IS->getLocStart(); CheckSLValidity(SL); SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start"); @@ -8386,7 +8391,6 @@ public: } private: - MutagenExtraction ME; Rewriter TheRewriter; }; /**********************************************************************************************************************/ @@ -8475,6 +8479,9 @@ int main(int argc, const char **argv) XMLDocOut.SaveReport(); JSONDocOUT.CloseReport(); + + ME.DumpAll(); + ME.XMLReport(); return RunResult; } diff --git a/mutator-lvl0.h b/mutator-lvl0.h index 0ec92c5..11049c6 100644 --- a/mutator-lvl0.h +++ b/mutator-lvl0.h @@ -350,16 +350,64 @@ class MutatorLVL0Tests }; /**********************************************************************************************************************/ -class mutagenAncestryReport : public Devi::XMLReportBase +class mutagenAncestryReport// : public Devi::XMLReportBase { public: - mutagenAncestryReport() {} - ~mutagenAncestryReport() {} + mutagenAncestryReport(std::vector<std::vector<std::string>> __dss) : DoomedStrains(__dss) + { + RootPointer = Doc.NewElement("mutagen:Report"); + RootPointer->SetAttribute("xmlns:mutator", "http://www.w3.org/2001/XMLSchema"); + } + + ~mutagenAncestryReport() + { + Doc.InsertEndChild(RootPointer); + } virtual void AddNode(void) - {} + { +#if 1 + XMLElement* MGene = Doc.NewElement("DoomedStrains"); + + for (auto &iter : DoomedStrains) + { + XMLElement* NodeDoomedStrain = Doc.NewElement("DoomedStrain"); + + for (auto &iterer : iter) + { + XMLElement* Child = Doc.NewElement("Strain"); + Child->SetText(iterer.c_str()); + NodeDoomedStrain->InsertEndChild(Child); + } + + MGene->InsertEndChild(NodeDoomedStrain); + } + + RootPointer->InsertEndChild(MGene); +#endif + } + + void CreateReport() + { + Doc.InsertFirstChild(RootPointer); + } + + void SaveReport(const char* __filename) + { + Doc.InsertEndChild(RootPointer); + + XMLError XMLErrorResult = Doc.SaveFile(__filename); + + if (XMLErrorResult != XML_SUCCESS) + { + std::cerr << "could not write xml misra report.\n"; + } + } private: + std::vector<std::vector<std::string>> DoomedStrains; + XMLElement* RootPointer; + XMLDocument Doc; }; /**********************************************************************************************************************/ #define EXTRACT_MUTAGEN @@ -389,6 +437,7 @@ class MutagenExtraction } MutantStrainsAncestry.push_back(LastStrain); + LastStrain.clear(); } void DumpLast(void) @@ -412,6 +461,14 @@ class MutagenExtraction } } + void XMLReport(void) + { + mutagenAncestryReport MAR(MutantStrainsAncestry); + MAR.CreateReport(); + MAR.AddNode(); + MAR.SaveReport("m0.xml"); + } + private: std::vector<std::string> LastStrain; std::vector<std::vector<std::string>> MutantStrainsAncestry; diff --git a/mutator_aux.h b/mutator_aux.h index 52be1b0..c6baa8e 100644 --- a/mutator_aux.h +++ b/mutator_aux.h @@ -46,7 +46,7 @@ enum class Scope {NoValue, TU, Block}; enum class FunctionDeclKind {NoValue, Definition, Declaration}; /*********************************************************************************************************************/ -SourceLocation SourceLocationHasMacro [[deprecated("doesnt work")]] (SourceLocation SL, Rewriter &Rewrite, std::string Kind); +SourceLocation SourceLocationHasMacro(SourceLocation SL, Rewriter &Rewrite, std::string Kind); SourceLocation SourceLocationHasMacro(SourceLocation __sl, Rewriter &__rewrite); /*********************************************************************************************************************/ diff --git a/mutator_report.cpp b/mutator_report.cpp index c989d32..6086880 100644 --- a/mutator_report.cpp +++ b/mutator_report.cpp @@ -55,11 +55,11 @@ namespace Devi { Doc.InsertFirstChild(RootPointer); } - void XMLReportBase::SaveReport() + void XMLReportBase::SaveReport(const char* __filename) { Doc.InsertEndChild(RootPointer); - XMLError XMLErrorResult = Doc.SaveFile("./test/misrareport.xml"); + XMLError XMLErrorResult = Doc.SaveFile(__filename); if (XMLErrorResult != XML_SUCCESS) { diff --git a/mutator_report.h b/mutator_report.h index e6b1936..ee8041b 100644 --- a/mutator_report.h +++ b/mutator_report.h @@ -47,9 +47,9 @@ namespace Devi { virtual void AddNode(void) = 0; - void SaveReport(void); + void SaveReport(const char*); - private: + protected: XMLDocument Doc; XMLElement* RootPointer; }; |