From 10ec75f895c6524d1babc52aca63fe1897c79542 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Tue, 13 Dec 2016 19:09:19 -0500 Subject: [PATCH] Updates to srcSlice. Directing the current policy to generate profiles --- CMakeLists.txt | 3 +- src/cpp/TestsrcSlicePolicy.cpp | 12 +-- src/headers/srcSlicePolicy.hpp | 171 -------------------------------- src/headers/srcSliceProfile.hpp | 94 ++++++++++++++++++ 4 files changed, 100 insertions(+), 180 deletions(-) delete mode 100644 src/headers/srcSlicePolicy.hpp create mode 100644 src/headers/srcSliceProfile.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f0d1ca..1520055 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,6 @@ include_directories(${LIBXML2_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/srcSAXEventDispatch/srcSAX/src/windows srcSAXEventDispatch/src/dispatcher srcSAXEventDispatch/src/policy_classes - src/headers - src/cpp) + src/headers) add_subdirectory(src) add_subdirectory(srcSAXEventDispatch) \ No newline at end of file diff --git a/src/cpp/TestsrcSlicePolicy.cpp b/src/cpp/TestsrcSlicePolicy.cpp index c49435d..7cc584b 100644 --- a/src/cpp/TestsrcSlicePolicy.cpp +++ b/src/cpp/TestsrcSlicePolicy.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include class TestSrcSlice : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ @@ -11,7 +11,7 @@ class TestSrcSlice : public srcSAXEventDispatch::PolicyDispatcher, public srcSAX ~TestSrcSlice(){} TestSrcSlice(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - srcslicedata = *policy->Data(); + srcslicedata = *policy->Data(); datatotest.push_back(srcslicedata); } void RunTest(){ @@ -30,10 +30,8 @@ class TestSrcSlice : public srcSAXEventDispatch::PolicyDispatcher, public srcSAX return (void*)0; //To silence the warning } private: - - SrcSlicePolicy srcslicepolicy; - SrcSlicePolicy::SrcSliceData srcslicedata; - std::vector datatotest; + srcSliceProfilePolicy::SrcProfile srcslicedata; + std::vector datatotest; }; int main(int argc, char** filename){ @@ -42,7 +40,7 @@ int main(int argc, char** filename){ std::cerr<<"out"< handler {&srcslicedata}; + srcSAXEventDispatch::srcSAXEventDispatcher handler {&srcslicedata}; std::cerr<<"Before"< -#include -#include -#include -#include - -//Problem with variables with same name in different scopes (Use a stack, every time change of scope push onto stack) -//Possibly add line numbers to names - -class SrcSlicePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - public: - struct SrcSliceData{ - SrcSliceData(){} - SrcSliceData(std::string name, std::string type, std::set lines){ - identifierName = name; - identifierType = type; - lineNumbers = lines; - } - - void clear(){ - identifierName.clear(); - identifierType.clear(); - lineNumbers.clear(); //Should I clear this??? - } - - std::string identifierName; - std::string identifierType; - std::set lineNumbers; - }; - - struct SrcSliceSet{ - SrcSliceSet() = default; - SrcSliceSet(std::map dat){ - srcSliceMap = dat; - } - void clear(){ - srcSliceMap.clear(); - } - std::map srcSliceMap; - }; - - std::map srcSliceMap; - SrcSliceSet data; - ~SrcSlicePolicy(){} - SrcSlicePolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ - exprPolicy.AddListener(this); - declTypePolicy.AddListener(this); - InitializeEventHandlers(); - } - - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - using namespace srcSAXEventDispatch; - - - if(ctx.IsOpen(ParserState::declstmt) && ctx.IsClosed(ParserState::exprstmt)){ - declData = *policy->Data(); - - - auto it = srcSliceMap.find(declData.nameofidentifier); - if(it == srcSliceMap.end()){ - std::set lines; - lines.insert(declData.linenumber); - srcSliceMap.insert(std::make_pair(declData.nameofidentifier, SrcSliceData(declData.nameofidentifier, declData.nameoftype, lines))); - }else{ - //What to do about multiple decl of same name - } - - - }else if (ctx.IsOpen(ParserState::exprstmt) && ctx.IsClosed(ParserState::declstmt)){ - exprData = *policy->Data(); - - //Needed? - for(auto deal : exprData.dataset){ - auto it = srcSliceMap.find(deal.second.nameofidentifier); - if(it != srcSliceMap.end()){ - - - std::set temp1 = deal.second.def; - std::set temp2 = deal.second.use; - std::set final = temp2; - bool match = false; - - - //Union - /* - for(std::set::iterator it1 = temp1.begin(); it1!= temp1.end(); ++it1){ - for(std::set::iterator it2 = temp2.begin(); it2!= temp2.end(); ++it2){ - if((*it1) == (*it2)) - match = true; - } - if(!match) - final.insert(*it1); - - match = false; - - } - - temp1 = it->second.lineNumbers; - temp2 = final; - - //Union with existing - for(std::set::iterator it1 = temp1.begin(); it1!= temp1.end(); ++it1){ - for(std::set::iterator it2 = temp2.begin(); it2!= temp2.end(); ++it2){ - if((*it1) == (*it2)) - match = true; - } - if(!match) - final.insert(*it1); - - match = false; - - } - - */ - - SrcSliceData sliceData = SrcSliceData(deal.second.nameofidentifier, it->second.identifierType, final); - data.srcSliceMap.insert(std::make_pair(deal.second.nameofidentifier, sliceData)); - } - } - - } - - - - - } - - - protected: - void * DataInner() const override { - return new SrcSliceSet(data); - } - private: - ExprPolicy exprPolicy; - ExprPolicy::ExprDataSet exprData; - DeclTypePolicy declTypePolicy; - DeclTypePolicy::DeclTypeData declData; - - //This correct? - void InitializeEventHandlers(){ - std::cerr<<"Enter"<AddListenerDispatch(&declTypePolicy); - }; - openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { - ctx.dispatcher->AddListenerDispatch(&exprPolicy); - }; - - - //Closing EventMap - closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->RemoveListenerDispatch(&exprPolicy); - NotifyAll(ctx); - //data.clear(); - }; - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->RemoveListenerDispatch(&declTypePolicy); - NotifyAll(ctx); - ///data.clear(); //Do we clear? - }; - - //Is this Needed?? - //closeEventMap[ParserState::archive] = [this](srcSAXEventContext& ctx){ - // NotifyAll(ctx); - //}; - std::cerr<<"Exit"< +#include +#include +#include +#include + +//Problem with variables with same name in different scopes (Use a stack, every time change of scope push onto stack) +//Possibly add line numbers to names + +class srcSliceProfilePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { + public: + struct SrcProfile{ + SrcProfile(){} + SrcProfile(std::string name, std::string type, std::set lines){ + identifierName = name; + identifierType = type; + lineNumbers = lines; + } + + void clear(){ + identifierName.clear(); + identifierType.clear(); + lineNumbers.clear(); + } + + std::vector namespaces; + int linenumber; + bool isConst; + bool isReference; + bool isPointer; + bool isStatic; + + std::string identifierName; + std::string identifierType; + std::set lineNumbers; + }; + SrcProfile data; + ~srcSliceProfilePolicy(){} + srcSliceProfilePolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + exprPolicy.AddListener(this); + declTypePolicy.AddListener(this); + InitializeEventHandlers(); + } + + void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + using namespace srcSAXEventDispatch; + if(ctx.IsOpen(ParserState::declstmt) && ctx.IsClosed(ParserState::exprstmt)){ + std::cerr<<"Call decl"<Data(); + + //Generate profile + data.identifierName = declData.nameofidentifier; + data.identifierType = declData.nameoftype; + data.isConst = declData.isConst; + data.isReference = declData.isReference; + data.isPointer = declData.isPointer; + data.isStatic = declData.isStatic; + }else if (ctx.IsOpen(ParserState::exprstmt) && ctx.IsClosed(ParserState::declstmt)){ + std::cerr<<"Call expr"<Data(); + } + } + + protected: + void * DataInner() const override { + //export profile to listeners + return new SrcProfile(data); + } + private: + ExprPolicy exprPolicy; + ExprPolicy::ExprDataSet exprData; + DeclTypePolicy declTypePolicy; + DeclTypePolicy::DeclTypeData declData; + + //This correct? + void InitializeEventHandlers(){ + using namespace srcSAXEventDispatch; + + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + ctx.dispatcher->AddListenerDispatch(&declTypePolicy); + }; + openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { + ctx.dispatcher->AddListenerDispatch(&exprPolicy); + }; + //Closing EventMap + closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx){ + ctx.dispatcher->RemoveListenerDispatch(&exprPolicy); + }; + closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx){ + ctx.dispatcher->RemoveListenerDispatch(&declTypePolicy); + }; + } + +};