aboutsummaryrefslogtreecommitdiffstats
path: root/mutator-lvl0.cpp
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2017-01-05 09:33:41 +0000
committerbloodstalker <thabogre@gmail.com>2017-01-05 09:33:41 +0000
commitcc4aa044d738dd497d34736ba8a6146598840587 (patch)
tree8c1ffaaac0551265fbfb5e5144e95a49a52c071a /mutator-lvl0.cpp
parentupdated interface with the new overlaod (diff)
downloadmutator-cc4aa044d738dd497d34736ba8a6146598840587.tar.gz
mutator-cc4aa044d738dd497d34736ba8a6146598840587.zip
added 19.1
Diffstat (limited to '')
-rw-r--r--mutator-lvl0.cpp133
1 files changed, 128 insertions, 5 deletions
diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp
index 443be9f..958ea44 100644
--- a/mutator-lvl0.cpp
+++ b/mutator-lvl0.cpp
@@ -7,9 +7,10 @@
#include "mutator_aux.h"
#include "tinyxml2/tinyxml2.h"
/*standard headers*/
-#include <string>
-#include <iostream>
#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <string>
#include <vector>
/*Clang headers*/
#include "clang/AST/AST.h"
@@ -5436,6 +5437,125 @@ private:
const SourceManager &SM;
};
/**********************************************************************************************************************/
+class IsThereJunkPreInclusion
+{
+public:
+ IsThereJunkPreInclusion() {}
+
+ void Check(std::vector<std::string> SourcePathList)
+ {
+ bool HaveWeMatchedInclusionDirYet = false;
+ bool HaveWeMatchIllegal191Yet = false;
+
+ for (auto &iter : SourcePathList)
+ {
+ //std::cout << iter << std::endl;
+ std::ifstream InputFile(iter);
+
+ HaveWeMatchIllegal191Yet = false;
+ HaveWeMatchedInclusionDirYet = false;
+
+ for (std::string line; getline(InputFile, line);)
+ {
+ //std::cout << iter << ":" << line << ":" << HaveWeMatchedInclusionDirYet << " " << HaveWeMatchIllegal191Yet << std::endl;
+
+ if (line.empty())
+ {
+ continue;
+ }
+
+ if (line.front() == '#')
+ {
+ size_t st = line.find("#include", 0U);
+
+ if (st == 0U)
+ {
+ /*we've found a header include*/
+ HaveWeMatchedInclusionDirYet = true;
+
+ if (HaveWeMatchIllegal191Yet)
+ {
+ /*print diag out*/
+ std::cout << "19.1" << ":" << "Inclusion directives should only be preceeded by other inclusion directives, pp directives or comments" << ":" << iter << std::endl;
+
+ XMLDocOut.XMLAddNode(iter, "19.1", "Inclusion directives should only be preceeded by other inclusion directives, pp directives or comments : ");
+ JSONDocOUT.JSONAddElement(iter, "19.1", "Inclusion directives should only be preceeded by other inclusion directives, pp directives or comments : ");
+ break;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ continue;
+ }
+
+ if (line.front() == '/')
+ {
+ /*has to be a comment*/
+ continue;
+ }
+
+ if (line.front() == '\n' || line.front() == '\t' || line.front() == ' ' || line.front() == '\r')
+ {
+ HaveWeMatchIllegal191Yet = false;
+
+ for (auto &iterchar : line)
+ {
+ if (iterchar == '\n' || iterchar == '\t' || iterchar == ' ' || line.front() == '\r')
+ {
+ continue;
+ }
+
+ if (iterchar == '/')
+ {
+ break;
+ }
+
+ if (iterchar == '#')
+ {
+ size_t st = line.find("#include", 0U);
+
+ if (st == 0U)
+ {
+ /*we've found a header include*/
+ HaveWeMatchedInclusionDirYet = true;
+
+ if (HaveWeMatchIllegal191Yet)
+ {
+ /*print diag out*/
+ std::cout << "19.1" << ":" << "Inclusion directives should only be preceeded by other inclusion directives, pp directives or comments" << ":" << iter << std::endl;
+
+ XMLDocOut.XMLAddNode(iter, "19.1", "Inclusion directives should only be preceeded by other inclusion directives, pp directives or comments : ");
+ JSONDocOUT.JSONAddElement(iter, "19.1", "Inclusion directives should only be preceeded by other inclusion directives, pp directives or comments : ");
+ break;
+ }
+ else
+ {
+ break;
+ }
+
+ continue;
+ }
+ }
+
+ HaveWeMatchIllegal191Yet = true;
+ }
+
+ continue;
+ }
+
+ HaveWeMatchIllegal191Yet = true;
+ }
+
+ InputFile.close();
+ }
+ }
+
+private:
+
+};
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/**********************************************************************************************************************/
@@ -5756,9 +5876,8 @@ int main(int argc, const char **argv)
{
/*@DEVI-we should parse the common options before parsing the custom options.*/
CommonOptionsParser op(argc, argv, MutatorLVL0Cat);
-#if 0
- cl::ParseCommandLineOptions(argc, argv);
-#endif
+
+ const std::vector<std::string> &SourcePathList = op.getSourcePathList();
ClangTool Tool(op.getCompilations(), op.getSourcePathList());
@@ -5766,6 +5885,10 @@ int main(int argc, const char **argv)
JSONDocOUT.JSONCreateReport();
+ IsThereJunkPreInclusion ITJPIInstance;
+
+ ITJPIInstance.Check(SourcePathList);
+
int RunResult = Tool.run(newFrontendActionFactory<MyFrontendAction>().get());
XMLDocOut.SaveReport();