From aa71fe22d7d9072c4f5d0a9ab3f78105b431cc3f Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 5 Jun 2017 02:48:32 +0430 Subject: now the list commands output the results in as strings so they can be reused in lua in any way the user sees fit --- bruiser/bruiser.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index e388ae6..89e84f2 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -66,6 +66,7 @@ using namespace clang::tooling; /**********************************************************************************************************************/ /*global vars*/ static llvm::cl::OptionCategory BruiserCategory("Empty"); +std::vector PushToLua; bruiser::M0_ERR m0_err; bruiser::BruiserReport BruiseRep; @@ -413,6 +414,7 @@ class LiveListFuncs : public MatchFinder::MatchCallback //printf(CYAN"%s", R.getRewrittenText(clang::SourceRange(SLShebang, SLBody.getLocWithOffset(-1))).c_str()); //printf(NORMAL "\n"); 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)))); //PRINT_WITH_COLOR_LB(GREEN, "end"); } else @@ -420,6 +422,7 @@ class LiveListFuncs : public MatchFinder::MatchCallback SourceLocation SL = FD->getLocStart(); SourceLocation SLE = FD->getLocEnd(); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(clang::SourceRange(SL, SLE)).c_str()); + PushToLua.push_back(R.getRewrittenText(clang::SourceRange(SL, SLE))); } } } @@ -440,6 +443,7 @@ class LiveListVars : public MatchFinder::MatchCallback const clang::VarDecl* VD = MR.Nodes.getNodeAs("livelistvars"); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(SourceRange(VD->getLocStart(), VD->getLocEnd())).c_str()); + PushToLua.push_back(R.getRewrittenText(SourceRange(VD->getLocStart(), VD->getLocEnd()))); } } @@ -459,6 +463,7 @@ class LiveListRecords : public MatchFinder::MatchCallback const clang::RecordDecl* RD = MR.Nodes.getNodeAs("livelistvars"); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(SourceRange(RD->getLocStart(), RD->getLocEnd())).c_str()); + PushToLua.push_back(R.getRewrittenText(SourceRange(RD->getLocStart(), RD->getLocEnd()))); } } @@ -833,10 +838,14 @@ class LuaWrapper #define LIST_GENERATOR(__x1) \ int List##__x1(lua_State* __ls)\ {\ - unsigned int InArgCnt = 0;\ + unsigned int InArgCnt = 0U;\ InArgCnt = lua_gettop(__ls);\ + unsigned int returncount=0U;\ this->GetClangTool().run(newFrontendActionFactory().get());\ - return 1;\ + for(auto &iter : PushToLua)\ + {lua_pushstring(__ls, iter.c_str());returncount++;}\ + PushToLua.clear();\ + return returncount;\ } #define LIST_LIST_GENERATORS \ -- cgit v1.2.3