aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser/bruiser.cpp
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2017-04-13 09:13:49 +0000
committerbloodstalker <thabogre@gmail.com>2017-04-13 09:13:49 +0000
commit73ea45d58be4aac298795bc810f5429ccf90c8f0 (patch)
tree2c64d9369fb737bf3e5461b46104553bf8a57dd4 /bruiser/bruiser.cpp
parentannouncing bruiser...sortof. (diff)
downloadmutator-73ea45d58be4aac298795bc810f5429ccf90c8f0.tar.gz
mutator-73ea45d58be4aac298795bc810f5429ccf90c8f0.zip
adding some infrastructure.wip.
Diffstat (limited to 'bruiser/bruiser.cpp')
-rw-r--r--bruiser/bruiser.cpp156
1 files changed, 148 insertions, 8 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index a7df7ca..4371e25 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
/*standard headers*/
#include <string>
#include <iostream>
-#include <cassert>
/*LLVM headers*/
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
@@ -49,32 +48,170 @@ using namespace clang::driver;
using namespace clang::tooling;
/**********************************************************************************************************************/
/*global vars*/
-
static llvm::cl::OptionCategory BruiserCategory("Empty");
/**********************************************************************************************************************/
+/*the implementation of the bruiser logger.*/
+bruiser::BruiserReport::BruiserReport ()
+{
+ BruiserLog.open("bruiser.log");
+}
+
+bruiser::BruiserReport::~BruiserReport()
+{
+ BruiserLog.close();
+}
+
+bool bruiser::BruiserReport::PrintToLog(std::string __in_arg)
+{
+ BruiserLog << __in_arg << "\n";
+ return !BruiserLog.bad();
+}
+/**********************************************************************************************************************/
+bruiser::TypeInfo::TypeInfo(const clang::ast_type_traits::DynTypedNode* __dtn) : DTN(__dtn) {};
+
+bruiser::TypeInfo::~TypeInfo() {};
+
+const clang::Type* bruiser::TypeInfo::getTypeInfo(clang::ASTContext* __astc)
+{
+ const clang::Expr* EXP = DTN->get<clang::Expr>();
+
+ const clang::Type* TP = EXP->getType().getTypePtr();
+
+ return __astc->getCanonicalType(TP);
+}
+/**********************************************************************************************************************/
+class AbstractMatcherHandler : public virtual MatchFinder::MatchCallback
+{
+ public:
+ AbstractMatcherHandler (Rewriter &Rewrite) : R(Rewrite) {}
+
+ public:
+ virtual void run(const MatchFinder::MatchResult &MR)
+ {
+
+ }
+
+ private:
+ Rewriter &R;
+};
+/**********************************************************************************************************************/
+class MatcherHandlerLVL0 : public AbstractMatcherHandler
+{
+ public:
+ MatcherHandlerLVL0 (Rewriter &Rewrite) : AbstractMatcherHandler(Rewrite) {}
+
+ virtual void run(const MatchFinder::MatchResult &MR) override
+ {
+
+ }
+
+ private:
+};
+/**********************************************************************************************************************/
+class NameFinder
+{
+ public:
+ NameFinder (Rewriter &Rewrite) : Rewrite(Rewrite) {}
+
+ virtual void runDeclRefExprMatcher(const llvm::StringRef __sr)
+ {
+ //Matcher.addMatcher();
+ }
+
+ virtual void runDeclMatcher(const llvm::StringRef __sr)
+ {
+
+ }
+
+ private:
+ Rewriter &Rewrite;
+ MatchFinder Matcher;
+};
+/**********************************************************************************************************************/
+/**********************************************************************************************************************/
+/**********************************************************************************************************************/
+class IfBreaker : public MatchFinder::MatchCallback
+{
+ public:
+ IfBreaker (Rewriter &Rewrite) : Rewrite(Rewrite) {}
+
+ virtual void run(const MatchFinder::MatchResult &MR)
+ {
+ if (MR.Nodes.getNodeAs<clang::UnaryOperator>("uno") != nullptr)
+ {
+ const clang::UnaryOperator* UO = MR.Nodes.getNodeAs<clang::UnaryOperator>("uno");
+
+ SourceLocation SL = UO->getLocStart();
+ CheckSLValidity(SL);
+ SL = Devi::SourceLocationHasMacro(SL, Rewrite);
+
+ const Expr* EXP = UO->getSubExpr();
+ const ast_type_traits::DynTypedNode DynNode = ast_type_traits::DynTypedNode::create<clang::Expr>(*EXP);
+ bruiser::TypeInfo TIProto(&DynNode);
+
+ const clang::Type* CTP = TIProto.getTypeInfo(MR.Context);
+
+ //Matcher.addMatcher();
+ }
+
+ if (MR.Nodes.getNodeAs<clang::BinaryOperator>("dous") != nullptr)
+ {
+ const clang::BinaryOperator* BO = MR.Nodes.getNodeAs<clang::BinaryOperator>("dous");
+
+ SourceLocation SL = BO->getLocStart();
+ CheckSLValidity(SL);
+ SL = Devi::SourceLocationHasMacro(SL, Rewrite);
+
+ const Expr* LHS = BO->getLHS();
+ const Expr* RHS = BO->getRHS();
+
+ QualType LQT = LHS->getType();
+ QualType RQT = RHS->getType();
+
+ const clang::Type* LTP = LQT.getTypePtr();
+ const clang::Type* RTP = RQT.getTypePtr();
+
+ const clang::Type* CLTP = MR.Context->getCanonicalType(LTP);
+ const clang::Type* CRTP = MR.Context->getCanonicalType(RTP);
+ }
+ }
+
+ private:
+ Rewriter &Rewrite;
+ MatchFinder Matcher;
+};
/**********************************************************************************************************************/
/**********************************************************************************************************************/
class MyASTConsumer : public ASTConsumer {
public:
- MyASTConsumer(Rewriter &R) {}
+ MyASTConsumer(Rewriter &R) : HIfBreaker(R)
+ {}
+
+ void HandleTranslationUnit(ASTContext &Context) override
+ {
+ Matcher.addMatcher(ifStmt(hasDescendant(expr(anyOf(unaryOperator().bind("uno"), binaryOperator().bind("dous"))))), &HIfBreaker);
- void HandleTranslationUnit(ASTContext &Context) override {
Matcher.matchAST(Context);
}
private:
+ IfBreaker HIfBreaker;
MatchFinder Matcher;
+ Rewriter R;
};
/**********************************************************************************************************************/
-class MyFrontendAction : public ASTFrontendAction {
+class MyFrontendAction : public ASTFrontendAction
+{
public:
MyFrontendAction() {}
- void EndSourceFileAction() override {
+ void EndSourceFileAction() override
+ {
TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(llvm::outs());
}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
+ {
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
return llvm::make_unique<MyASTConsumer>(TheRewriter);
}
@@ -84,10 +221,13 @@ private:
};
/**********************************************************************************************************************/
/*Main*/
-int main(int argc, const char **argv) {
+int main(int argc, const char **argv)
+{
CommonOptionsParser op(argc, argv, BruiserCategory);
ClangTool Tool(op.getCompilations(), op.getSourcePathList());
+ bruiser::BruiserReport BruiseRep;
+
return Tool.run(newFrontendActionFactory<MyFrontendAction>().get());
}
/*last line interntionally left blank.*/