aboutsummaryrefslogtreecommitdiffstats
path: root/mutator_report.h
blob: ad3b843a17dff3d80a66581715b747197da1f5b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************Project Mutator****************************************************/
//-*-c++-*-
/*********************************************************************************************************************/
/*first line intentionally left blank*/
/*Copyright (C) 2017 Farzad Sadeghi

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*/
/*********************************************************************************************************************/
/*inclusion guard*/
#ifndef MUTATOR_REPORT_H
#define MUTATOR_REPORT_H
/*********************************************************************************************************************/
/*inclusion directives*/
#include <string>
#include <fstream>
#include "clang/AST/AST.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "tinyxml2/tinyxml2.h"
/*********************************************************************************************************************/
using namespace clang;
using namespace tinyxml2;
/*********************************************************************************************************************/
namespace Devi {
/*********************************************************************************************************************/
  class XMLReportBase
  {
    public:
    XMLReportBase();
    virtual ~XMLReportBase();

    void CreateReport(void);

    virtual void AddNode(void) = 0;

    void SaveReport(const char*);

    protected:
    XMLDocument Doc;
    XMLElement* RootPointer;
  };
/*********************************************************************************************************************/
  /*@DEVI- for both report classes, if the program gets terminated, since the destructor does not close
  the report files, what happens to them is implementation-defined in case of let's say an exit, but since
  we erase the files everytime a new instance of mutator-lvl0 is called, we are fine. or so i think.*/
  /*@DEVI- in case of a crash, the XML report will only hold the base node, while the JSON report will
  contain all the reports up until the crash. tinyxml2 writes the nodes to file on SaveFile which is
  called in SaveReport so that's why.*/
  class XMLReport
  {
  public:
    XMLReport();
    ~XMLReport();

    void XMLCreateReport(void);
    void XMLAddNode(ASTContext* ASTC, SourceLocation SL, std::string MisraRule, std::string Description);
    /*overloaded for rule checks that announce the result on onendoftranslation instead of run
    since they dont have access to matchresult or astcontext.*/
    void XMLAddNode(FullSourceLoc FSL, SourceLocation SL, std::string MisraRule, std::string Description);
    /*another overload to support the xml output for PPCallbacks.*/
    void XMLAddNode(const SourceManager &SM, SourceLocation SL, std::string MisraRule, std::string Description);

    void XMLAddNode(std::string FilePath, std::string MisraRule, std::string Description);

    void XMLAddNode(unsigned Line, unsigned Column, std::string FileName, std::string MisraRule, std::string Description);

    bool isReportEmpty(void);

    void SaveReport(void);

  private:
    XMLDocument XMLReportDoc;
    XMLElement* RootPointer;
  };
/*********************************************************************************************************************/
  class JSONReport
  {
  public:
    JSONReport();

    void JSONCreateReport(void);
    void JSONAddElement(ASTContext* ASTC, SourceLocation SL, std::string MisraRule, std::string Description);
    /*overload for checks that announce the result in onendoftranslation unit.*/
    void JSONAddElement(FullSourceLoc FSL, SourceLocation SL, std::string MisraRule, std::string Description);
    /*overload for PPCallbacks.*/
    void JSONAddElement(const SourceManager &SM, SourceLocation SL, std::string MisraRule, std::string Description);

    void JSONAddElement(std::string FilePath, std::string MisraRule, std::string Description);

    void JSONAddElement(unsigned Line, unsigned Column, std::string FileName, std::string MisraRule, std::string Description);

    void CloseReport(void);

  private:
    std::ofstream JSONRepFile;
  };
/*********************************************************************************************************************/
/*********************************************************************************************************************/
} //end of namespace devi
#endif
/*********************************************************************************************************************/
/*last line intentionally left blank.*/