diff options
Diffstat (limited to 'bruiser/bruiser.cpp')
-rw-r--r-- | bruiser/bruiser.cpp | 494 |
1 files changed, 100 insertions, 394 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 54b632e..ae6db23 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -618,13 +618,11 @@ class CompilationDatabaseProcessor { }; /**********************************************************************************************************************/ /*the implementation of the bruiser logger.*/ -bruiser::BruiserReport::BruiserReport () -{ +bruiser::BruiserReport::BruiserReport () { BruiserLog.open("bruiser.log"); } -bruiser::BruiserReport::~BruiserReport() -{ +bruiser::BruiserReport::~BruiserReport() { BruiserLog.close(); } @@ -636,8 +634,7 @@ bruiser::BruiserReport::~BruiserReport() * @return Returns true if the write was successful, false otherwise. */ template <typename T> -bool bruiser::BruiserReport::PrintToLog(T __arg) -{ +bool bruiser::BruiserReport::PrintToLog(T __arg) { BruiserLog << __arg << "\n"; return !BruiserLog.bad(); } @@ -646,184 +643,42 @@ bruiser::TypeInfo::TypeInfo(const clang::ast_type_traits::DynTypedNode* __dtn) : bruiser::TypeInfo::~TypeInfo() {}; -const clang::Type* bruiser::TypeInfo::getTypeInfo(clang::ASTContext* __astc) -{ +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 [[maybe_unused]]; -}; -/**********************************************************************************************************************/ -class MatcherHandlerLVL0 : public AbstractMatcherHandler -{ - public: - explicit MatcherHandlerLVL0 (Rewriter &Rewrite) : AbstractMatcherHandler(Rewrite) {} - - virtual ~MatcherHandlerLVL0() {} - - virtual void run(const MatchFinder::MatchResult &MR) override - { - - } - - private: -}; -/**********************************************************************************************************************/ -class NameFinder -{ - public: - NameFinder () {} - - class runDeclRefExprMatcher - { - public: - runDeclRefExprMatcher (Rewriter &__rwrt) : LVL0Proto(__rwrt), __rwrt(__rwrt) {} - - virtual void runMatcher(const StringRef __sr, ASTContext &__ctx) - { - Matcher.addMatcher(declRefExpr(to(namedDecl(hasName(__sr.str())))).bind("declrefexpbyname"), &LVL0Proto); - Matcher.matchAST(__ctx); - } - - private: - MatchFinder Matcher; - MatcherHandlerLVL0 LVL0Proto; - Rewriter __rwrt; - StringRef __sr; - }; - - class runNamedDeclMatcher - { - public: - runNamedDeclMatcher (Rewriter &__rwrt) : LVL0Proto(__rwrt), __rwrt(__rwrt) {} - - virtual void runMatcher(const StringRef __sr, ASTContext &__ctx) - { - Matcher.addMatcher(declRefExpr(to(namedDecl(hasName(__sr.str())))).bind("nameddeclbyname"), &LVL0Proto); - Matcher.matchAST(__ctx); - } - - private: - MatchFinder Matcher; - MatcherHandlerLVL0 LVL0Proto; - Rewriter __rwrt; - StringRef __sr; - }; - - private: -}; -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ -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 [[maybe_unused]] = TIProto.getTypeInfo(MR.Context); - - NameFinder::runDeclRefExprMatcher DRENameMatcher(Rewrite); - - DRENameMatcher.runMatcher(StringRef(), *MR.Context); - } - - 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 [[maybe_unused]] = MR.Context->getCanonicalType(LTP); - const clang::Type* CRTP [[maybe_unused]] = MR.Context->getCanonicalType(RTP); - } - } - - private: - Rewriter &Rewrite; - MatchFinder Matcher; -}; /**********************************************************************************************************************/ /** * @brief Hijacks the main main and replaces it with bruiser's main. */ -class MainWrapper : public MatchFinder::MatchCallback -{ +class MainWrapper : public MatchFinder::MatchCallback { public: MainWrapper (Rewriter &Rewrite) : Rewrite(Rewrite) {} - virtual void run(const MatchFinder::MatchResult &MR) - { - if (MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper") != nullptr) - { + virtual void run(const MatchFinder::MatchResult &MR) { + if (MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper") != nullptr) { const FunctionDecl* FD = MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper"); SourceLocation SL = FD->getLocStart(); CheckSLValidity(SL); SL = Devi::SourceLocationHasMacro(SL, Rewrite); - SourceLocation SLE = FD->getLocEnd(); CheckSLValidity(SLE); SLE = Devi::SourceLocationHasMacro(SLE, Rewrite); - if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) - { + if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) { return void(); } SourceRange SR(SL, SLE); - std::string MainSig = Rewrite.getRewrittenText(SR); - size_t mainbegin = MainSig.find("main"); - StringRef __sr("sub_main"); - Rewrite.ReplaceText(SL.getLocWithOffset(mainbegin), 4U, __sr); - /*@DEVI-obviously the best way to do this is to use the main signature already used, instead of going with a general predefined one. the current form is a temp.*/ Rewrite.InsertTextAfter(SLE.getLocWithOffset(1U), StringRef("\n\nint main(int argc, const char **argv)\n{\n\treturn sub_main(argc, argv);\n}\n")); - //BruiseRep.PrintToLog("hijacked main main."); } } @@ -832,36 +687,29 @@ public: Rewriter &Rewrite; }; /**********************************************************************************************************************/ -class LiveListFuncs : public MatchFinder::MatchCallback -{ +class LiveListFuncs : public MatchFinder::MatchCallback { public: LiveListFuncs (Rewriter &R) : R(R) {} - virtual void run(const MatchFinder::MatchResult &MR) - { - if (MR.Nodes.getNodeAs<clang::FunctionDecl>("livelistfuncs") != nullptr) - { + virtual void run(const MatchFinder::MatchResult &MR) { + if (MR.Nodes.getNodeAs<clang::FunctionDecl>("livelistfuncs") != nullptr) { const clang::FunctionDecl* FD = MR.Nodes.getNodeAs<clang::FunctionDecl>("livelistfuncs"); SourceLocation SL = FD->getLocStart(); CheckSLValidity(SL); SL = Devi::SourceLocationHasMacro(SL, R); - if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) - { + if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) { return void(); } - if (FD->hasBody()) - { + if (FD->hasBody()) { Stmt* Body = FD->getBody(); SourceLocation SLBody = Body->getLocStart(); SourceLocation SLShebang = FD->getLocStart(); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(clang::SourceRange(SLShebang, SLBody.getLocWithOffset(-1))).c_str()); PushToLua.push_back(R.getRewrittenText(clang::SourceRange(SLShebang, SLBody.getLocWithOffset(-1)))); - } - else - { + } else { SourceLocation SL = FD->getLocStart(); SourceLocation SLE = FD->getLocEnd(); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(clang::SourceRange(SL, SLE)).c_str()); @@ -874,23 +722,19 @@ class LiveListFuncs : public MatchFinder::MatchCallback Rewriter R; }; /**********************************************************************************************************************/ -class LiveListVars : public MatchFinder::MatchCallback -{ +class LiveListVars : public MatchFinder::MatchCallback { public: LiveListVars (Rewriter &R) : R(R) {} - virtual void run(const MatchFinder::MatchResult &MR) - { - if (MR.Nodes.getNodeAs<clang::VarDecl>("livelistvars") != nullptr) - { + virtual void run(const MatchFinder::MatchResult &MR) { + if (MR.Nodes.getNodeAs<clang::VarDecl>("livelistvars") != nullptr) { const clang::VarDecl* VD = MR.Nodes.getNodeAs<clang::VarDecl>("livelistvars"); SourceLocation SL = VD->getLocStart(); CheckSLValidity(SL); SL = Devi::SourceLocationHasMacro(SL, R); - if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) - { + if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) { return void(); } @@ -903,15 +747,12 @@ class LiveListVars : public MatchFinder::MatchCallback Rewriter R; }; /**********************************************************************************************************************/ -class LiveListRecords : public MatchFinder::MatchCallback -{ +class LiveListRecords : public MatchFinder::MatchCallback { public: LiveListRecords (Rewriter &R) : R(R) {} - virtual void run(const MatchFinder::MatchResult &MR) - { - if (MR.Nodes.getNodeAs<clang::RecordDecl>("livelistvars") != nullptr) - { + virtual void run(const MatchFinder::MatchResult &MR) { + if (MR.Nodes.getNodeAs<clang::RecordDecl>("livelistvars") != nullptr) { const clang::RecordDecl* RD = MR.Nodes.getNodeAs<clang::RecordDecl>("livelistvars"); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(SourceRange(RD->getLocStart(), RD->getLocEnd())).c_str()); @@ -924,76 +765,27 @@ class LiveListRecords : public MatchFinder::MatchCallback }; /**********************************************************************************************************************/ /**********************************************************************************************************************/ -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ class BruiserASTConsumer : public ASTConsumer { - public: - BruiserASTConsumer(Rewriter &R) : HIfBreaker(R), HMainWrapper(R) - {} - - void HandleTranslationUnit(ASTContext &Context) override - { - Matcher.addMatcher(ifStmt(hasDescendant(expr(anyOf(unaryOperator().bind("uno"), binaryOperator().bind("dous"))))), &HIfBreaker); + BruiserASTConsumer(Rewriter &R) : HMainWrapper(R) {} + void HandleTranslationUnit(ASTContext &Context) override { Matcher.addMatcher(functionDecl(hasName("main")).bind("mainwrapper"), &HMainWrapper); - - Matcher.matchAST(Context); } private: - IfBreaker HIfBreaker; MainWrapper HMainWrapper; MatchFinder Matcher; Rewriter R; }; /**********************************************************************************************************************/ -class LiveConsumerFactory -{ +class LiveListVarsConsumer : public ASTConsumer { public: - LiveConsumerFactory() {} + LiveListVarsConsumer(Rewriter &R) : HLLVars(R) {} - template<typename T> - void operator()(T __consumer) - { - - } - -}; -/**********************************************************************************************************************/ -class LiveConsumer : public ASTConsumer -{ - public: - LiveConsumer(Rewriter &R) : HLLVars(R), HLLFuncs(R), HLLRecords(R) - {} - - void HandleTranslationUnit(ASTContext &ctx) override - { - Matcher.matchAST(ctx); - } - - private: - MatchFinder Matcher; - LiveListVars HLLVars; - LiveListFuncs HLLFuncs; - LiveListRecords HLLRecords; - Rewriter R; -}; -/**********************************************************************************************************************/ -class LiveListVarsConsumer : public ASTConsumer -{ - public: - LiveListVarsConsumer(Rewriter &R) : HLLVars(R) - {} - - void HandleTranslationUnit(ASTContext &ctx) override - { + void HandleTranslationUnit(ASTContext &ctx) override { Matcher.addMatcher(varDecl().bind("livelistvars"), &HLLVars); - Matcher.matchAST(ctx); } @@ -1003,16 +795,12 @@ class LiveListVarsConsumer : public ASTConsumer MatchFinder Matcher; }; /**********************************************************************************************************************/ -class LiveListFuncsConsumer : public ASTConsumer -{ +class LiveListFuncsConsumer : public ASTConsumer { public: - LiveListFuncsConsumer(Rewriter &R) : HLLFuncs(R) - {} + LiveListFuncsConsumer(Rewriter &R) : HLLFuncs(R) {} - void HandleTranslationUnit(ASTContext &ctx) override - { + void HandleTranslationUnit(ASTContext &ctx) override { Matcher.addMatcher(functionDecl().bind("livelistfuncs"), &HLLFuncs); - Matcher.matchAST(ctx); } @@ -1022,16 +810,12 @@ class LiveListFuncsConsumer : public ASTConsumer Rewriter R; }; /**********************************************************************************************************************/ -class LiveListClassConsumer : public ASTConsumer -{ +class LiveListClassConsumer : public ASTConsumer { public: - LiveListClassConsumer(Rewriter &R) : HLLRecords(R) - {} + LiveListClassConsumer(Rewriter &R) : HLLRecords(R) {} - void HandleTranslationUnit(ASTContext &ctx) override - { + void HandleTranslationUnit(ASTContext &ctx) override { Matcher.addMatcher(recordDecl(isClass()).bind("livelistclass"), &HLLRecords); - Matcher.matchAST(ctx); } @@ -1041,16 +825,12 @@ class LiveListClassConsumer : public ASTConsumer Rewriter R; }; /**********************************************************************************************************************/ -class LiveListStructConsumer : public ASTConsumer -{ +class LiveListStructConsumer : public ASTConsumer { public: - LiveListStructConsumer(Rewriter &R) : HLLRecords(R) - {} + LiveListStructConsumer(Rewriter &R) : HLLRecords(R) {} - void HandleTranslationUnit(ASTContext &ctx) override - { + void HandleTranslationUnit(ASTContext &ctx) override { Matcher.addMatcher(recordDecl(isStruct()).bind("liveliststruct"), &HLLRecords); - Matcher.matchAST(ctx); } @@ -1060,16 +840,12 @@ class LiveListStructConsumer : public ASTConsumer Rewriter R; }; /**********************************************************************************************************************/ -class LiveListUnionConsumer : public ASTConsumer -{ +class LiveListUnionConsumer : public ASTConsumer { public: - LiveListUnionConsumer(Rewriter &R) : HLLRecords(R) - {} + LiveListUnionConsumer(Rewriter &R) : HLLRecords(R) {} - void HandleTranslationUnit(ASTContext &ctx) override - { + void HandleTranslationUnit(ASTContext &ctx) override { Matcher.addMatcher(recordDecl(isUnion()).bind("livelistclass"), &HLLRecords); - Matcher.matchAST(ctx); } @@ -1079,16 +855,12 @@ class LiveListUnionConsumer : public ASTConsumer Rewriter R; }; /**********************************************************************************************************************/ -class LiveListArrayConsumer : public ASTConsumer -{ +class LiveListArrayConsumer : public ASTConsumer { public: - LiveListArrayConsumer(Rewriter &R) : HLLVars(R) - {} + LiveListArrayConsumer(Rewriter &R) : HLLVars(R) {} - void HandleTranslationUnit(ASTContext &ctx) override - { + void HandleTranslationUnit(ASTContext &ctx) override { Matcher.addMatcher(varDecl(hasType(arrayType())).bind("livelistvars"), &HLLVars); - Matcher.matchAST(ctx); } @@ -1099,28 +871,22 @@ class LiveListArrayConsumer : public ASTConsumer }; /**********************************************************************************************************************/ /**********************************************************************************************************************/ -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ -class BlankDiagConsumer : public clang::DiagnosticConsumer -{ +class BlankDiagConsumer : public clang::DiagnosticConsumer { public: BlankDiagConsumer() = default; virtual ~BlankDiagConsumer() {} virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override {} }; /**********************************************************************************************************************/ -class BruiserFrontendAction : public ASTFrontendAction -{ +class BruiserFrontendAction : public ASTFrontendAction { public: BruiserFrontendAction() {} - virtual ~BruiserFrontendAction() - { + virtual ~BruiserFrontendAction() { delete BDCProto; delete tee; } - void EndSourceFileAction() override - { + void EndSourceFileAction() override { std::error_code EC; std::string OutputFilename = "./libtooling-tee"; TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(llvm::outs()); @@ -1128,8 +894,7 @@ public: TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(*tee); } - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override - { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); @@ -1142,19 +907,16 @@ private: raw_ostream *tee = &llvm::outs(); }; /**********************************************************************************************************************/ -class LiveActionListVars : public ASTFrontendAction -{ +class LiveActionListVars : public ASTFrontendAction { public: LiveActionListVars() = default; - virtual ~LiveActionListVars() - { + virtual ~LiveActionListVars() { delete BDCProto; } void EndSourceFileAction() override {} - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override - { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); @@ -1166,19 +928,16 @@ class LiveActionListVars : public ASTFrontendAction BlankDiagConsumer* BDCProto = new BlankDiagConsumer(); }; /**********************************************************************************************************************/ -class LiveActionListFuncs : public ASTFrontendAction -{ +class LiveActionListFuncs : public ASTFrontendAction { public: LiveActionListFuncs() {} - ~LiveActionListFuncs() - { + ~LiveActionListFuncs() { delete BDCProto; } void EndSourceFileAction() override {} - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override - { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); @@ -1190,19 +949,16 @@ class LiveActionListFuncs : public ASTFrontendAction BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ -class LiveActionListStructs : public ASTFrontendAction -{ +class LiveActionListStructs : public ASTFrontendAction { public: LiveActionListStructs() {} - ~LiveActionListStructs() - { + ~LiveActionListStructs() { delete BDCProto; } void EndSourceFileAction() override {} - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override - { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); @@ -1214,19 +970,16 @@ class LiveActionListStructs : public ASTFrontendAction BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ -class LiveActionListClasses : public ASTFrontendAction -{ +class LiveActionListClasses : public ASTFrontendAction { public: LiveActionListClasses() {} - ~LiveActionListClasses() - { + ~LiveActionListClasses() { delete BDCProto; } void EndSourceFileAction() override {} - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override - { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); @@ -1238,19 +991,16 @@ class LiveActionListClasses : public ASTFrontendAction BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ -class LiveActionListUnions : public ASTFrontendAction -{ +class LiveActionListUnions : public ASTFrontendAction { public: LiveActionListUnions() {} - ~LiveActionListUnions() - { + ~LiveActionListUnions() { delete BDCProto; } void EndSourceFileAction() override {} - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override - { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); @@ -1262,19 +1012,16 @@ class LiveActionListUnions : public ASTFrontendAction BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ -class LiveActionListArrays : public ASTFrontendAction -{ +class LiveActionListArrays : public ASTFrontendAction { public: LiveActionListArrays() {} - ~LiveActionListArrays() - { + ~LiveActionListArrays() { delete BDCProto; } void EndSourceFileAction() override {} - std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override - { + std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); @@ -1288,39 +1035,31 @@ class LiveActionListArrays : public ASTFrontendAction /**********************************************************************************************************************/ /**********************************************************************************************************************/ /*lua wrappers*/ -class LuaWrapper -{ +class LuaWrapper { public: //LuaWrapper(std::unique_ptr<Executioner> _e, std::unique_ptr<XGlobals> _x) : executioner(std::move(_e)), xglobals(std::move(_x)) {} LuaWrapper() {} /*print out the history*/ - int BruiserLuaHistory(lua_State* __ls) - { + int BruiserLuaHistory(lua_State* __ls) { std::ifstream historyfile; historyfile.open(SHELL_HISTORY_FILE); std::string tempstring; unsigned int tempint = 0; - while(std::getline(historyfile, tempstring)) - { + while(std::getline(historyfile, tempstring)) { printf(BLUE"%d ", tempint); printf(CYAN"%s", tempstring.c_str()); printf(NORMAL"\n"); - tempint++; } - return tempint; } /*print the help menu*/ - int BruiserLuaHelp(lua_State* __ls) - { + int BruiserLuaHelp(lua_State* __ls) { unsigned int argcount = 0U; - - for (auto &iter : bruiser::CMDHelp) - { + for (auto &iter : bruiser::CMDHelp) { printf(GREEN"name: "); printf(CYAN"%s ", iter.name.c_str()); printf(GREEN"proto: "); @@ -1341,19 +1080,16 @@ class LuaWrapper /*print out bruiser version*/ - int BruiserLuaVersion(lua_State* __ls) - { + int BruiserLuaVersion(lua_State* __ls) { PRINT_WITH_COLOR_LB(GREEN, "bruiser experimental version something."); PRINT_WITH_COLOR_LB(GREEN, "project mutator"); PRINT_WITH_COLOR_LB(GREEN, "GPL v3.0"); PRINT_WITH_COLOR_LB(GREEN, "bloodstalker 2017"); - return 1; } /*clear the screen*/ - int BruiserLuaClear(lua_State* __ls) - { + int BruiserLuaClear(lua_State* __ls) { linenoiseClearScreen(); return 0; } @@ -1985,42 +1721,34 @@ class LuaWrapper } /*read the m0 report*/ - int BruiserLuaM0(lua_State* __ls) - { - bruiser::ReadM0 M0Rep; - tinyxml2::XMLError XMLErr; - - XMLErr = M0Rep.LoadXMLDoc(); - if (XMLErr != XML_SUCCESS) - { - std::cout << RED << "could not load m0 xml report.\n" << NORMAL; - std::cout << RED << "tinyxml2 returned " << XMLErr << NORMAL; - return XMLErr; - } + int BruiserLuaM0(lua_State* __ls) { + bruiser::ReadM0 M0Rep; + tinyxml2::XMLError XMLErr; - XMLErr = M0Rep.ReadFirstElement(); - if (XMLErr != XML_SUCCESS) - { - std::cerr << RED << "could not read first element of m0 xml report.\n" << NORMAL; - return XMLErr; - } + XMLErr = M0Rep.LoadXMLDoc(); + if (XMLErr != XML_SUCCESS) { + std::cout << RED << "could not load m0 xml report.\n" << NORMAL; + std::cout << RED << "tinyxml2 returned " << XMLErr << NORMAL; + return XMLErr; + } - bruiser::SearchM0(M0Rep.getRootPointer()); + XMLErr = M0Rep.ReadFirstElement(); + if (XMLErr != XML_SUCCESS) { + std::cerr << RED << "could not read first element of m0 xml report.\n" << NORMAL; + return XMLErr; + } - return 1; + bruiser::SearchM0(M0Rep.getRootPointer()); + return 1; } - int BruiserLuaReadXMLReport(lua_State* __ls) - { + int BruiserLuaReadXMLReport(lua_State* __ls) { int numargs = lua_gettop(__ls); std::string xml_address; - if (numargs == 1) - { + if (numargs == 1) { xml_address = lua_tostring(__ls, 1); - } - else - { + } else { xml_address = bruiser::M0REP; } @@ -2028,8 +1756,7 @@ class LuaWrapper tinyxml2::XMLError error; error = MutagenRep.LoadXMLDoc(); - if (error != XML_SUCCESS) - { + if (error != XML_SUCCESS) { PRINT_WITH_COLOR_LB(RED, "could not load report."); PRINT_WITH_COLOR(RED, "tinyxml2 returned "); std::cout << RED << error << NORMAL; @@ -2038,59 +1765,49 @@ class LuaWrapper } error = MutagenRep.ReadFirstElement(); - if (error != XML_SUCCESS) - { + if (error != XML_SUCCESS) { PRINT_WITH_COLOR_LB(RED, "could not read first element of xml report."); lua_pushnumber(__ls, (double)error); return 1; } bruiser::SearchM0(MutagenRep.getRootPointer()); - return 1; } /*quit*/ - int BruiserLuaQuit(lua_State* __ls) - { + int BruiserLuaQuit(lua_State* __ls) { dostring(__ls, "os.exit()", "test"); return 0; } /*quit*/ - int BruiserLuaExit(lua_State* __ls) - { + int BruiserLuaExit(lua_State* __ls) { dostring(__ls, "os.exit()", "test"); return 0; } - int BruiserLuaRunMake(lua_State* __ls) - { + int BruiserLuaRunMake(lua_State* __ls) { unsigned int args = 0U; - if ((args = lua_gettop(__ls)) != 1U) - { + if ((args = lua_gettop(__ls)) != 1U) { PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help()."); lua_pushnumber(__ls, 1); return 1; } std::string makearg = lua_tostring(__ls , 1); - - if (ShellGlobalInstance.MAKEPATH == "") - { + if (ShellGlobalInstance.MAKEPATH == "") { PRINT_WITH_COLOR_LB(RED, "MAKEPATH is not set. set it using setmakepath or type help."); lua_pushnumber(__ls, 1); return 1; } pid_t pid = fork(); - if (pid < 0) { PRINT_WITH_COLOR_LB(RED, "could not fork..."); lua_pushnumber(__ls, EXIT_FAILURE); } - if (pid == 0) { std::cout << BLUE << "MAKEPATH: " << ShellGlobalInstance.MAKEPATH << NORMAL << "\n"; std::cout << BLUE << "Running: " << "make -C " << ShellGlobalInstance.MAKEPATH << " " << makearg << NORMAL << "\n"; @@ -2098,7 +1815,6 @@ class LuaWrapper lua_pushnumber(__ls, retval); exit(EXIT_SUCCESS); } - if (pid > 0) { int status; pid_t returned; @@ -2111,14 +1827,12 @@ class LuaWrapper int BruiserLuaChangeHistorySize(lua_State* __ls) { unsigned int args = 0U; - if ((args = lua_gettop(__ls)) != 1U) { PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help()."); return 0; } unsigned int historysize = lua_tonumber(__ls, 1); - linenoiseHistorySetMaxLen(historysize); ShellGlobalInstance.HISTORY_SIZE = historysize; @@ -2143,9 +1857,7 @@ class LuaWrapper if (iter.rfind(filename) == iter.size() - filename.size()) { ShellCacheInstance.LastFileUsed = iter; ShellCacheInstance.LastFileUsedShort = filename; - targetfile.open(iter); - if(targetfile.rdstate() != std::ios_base::goodbit) { PRINT_WITH_COLOR_LB(RED, "could not open the file."); } @@ -2176,7 +1888,6 @@ class LuaWrapper } pid_t pid = fork(); - if (pid < 0) { /*bruiser could not spawn a child*/ PRINT_WITH_COLOR_LB(RED, "could not fork a child process(m0)."); @@ -2291,7 +2002,6 @@ class LuaWrapper } ShellGlobalInstance.BINPATH = lua_tostring(__ls, 1); - return 0; } @@ -2388,8 +2098,7 @@ class LuaWrapper return 0; } - int BruiserLuaPWD(lua_State* __ls) - { + int BruiserLuaPWD(lua_State* __ls) { pid_t pid = fork(); if (pid < 0) { @@ -2426,13 +2135,11 @@ class BruiserCFE { std::ifstream libtooling_tee("../test/bruisertest/libtooling-tee"); std::string luaoutstr; std::string dummy; - while(std::getline(libtooling_tee, dummy)) { luaoutstr = luaoutstr + dummy + "\n"; } lua_pushstring(__ls, luaoutstr.c_str()); - return 1; } @@ -2473,8 +2180,7 @@ class BruiserCFE { std::unique_ptr<ClangTool> CT; }; /**********************************************************************************************************************/ -class RunLoop -{ +class RunLoop { public: RunLoop(lua_State* __ls, LuaEngine __le) : ls(__ls), le(__le) {} @@ -2558,7 +2264,7 @@ std::pair<ClangTool*, CompilationDatabaseProcessor*> clang_cli_args(int argc, co } /**********************************************************************************************************************/ /*Main*/ -int main(int argc, const char **argv) { +int main(int argc, const char** argv) { int argc_n = 0; std::vector<std::string> argv_n; std::vector<const char*> vc; |