Skip to content

Commit

Permalink
Updates to srcSlice. Directing the current policy to generate profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
cnewman committed Dec 14, 2016
1 parent d33b7be commit 10ec75f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 180 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 5 additions & 7 deletions src/cpp/TestsrcSlicePolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include <unordered_map>
#include <unordered_set>
#include <srcSAXHandler.hpp>
#include <srcSlicePolicy.hpp>
#include <srcSliceProfile.hpp>
#include <cassert>

class TestSrcSlice : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{
public:
~TestSrcSlice(){}
TestSrcSlice(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){}
void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override {
srcslicedata = *policy->Data<SrcSlicePolicy::SrcSliceData>();
srcslicedata = *policy->Data<srcSliceProfilePolicy::SrcProfile>();
datatotest.push_back(srcslicedata);
}
void RunTest(){
Expand All @@ -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<SrcSlicePolicy::SrcSliceData> datatotest;
srcSliceProfilePolicy::SrcProfile srcslicedata;
std::vector<srcSliceProfilePolicy::SrcProfile> datatotest;
};

int main(int argc, char** filename){
Expand All @@ -42,7 +40,7 @@ int main(int argc, char** filename){
std::cerr<<"out"<<std::endl;
TestSrcSlice srcslicedata;
srcSAXController control(srcmlstr);
srcSAXEventDispatch::srcSAXEventDispatcher<SrcSlicePolicy> handler {&srcslicedata};
srcSAXEventDispatch::srcSAXEventDispatcher<srcSliceProfilePolicy> handler {&srcslicedata};
std::cerr<<"Before"<<std::endl;
control.parse(&handler); //Start parsing
std::cout << "HERE HERE HERE HERE" << std::endl;
Expand Down
171 changes: 0 additions & 171 deletions src/headers/srcSlicePolicy.hpp

This file was deleted.

94 changes: 94 additions & 0 deletions src/headers/srcSliceProfile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <srcSAXEventDispatcher.hpp>
#include <srcSAXHandler.hpp>
#include <exception>
#include <DeclTypePolicy.hpp>
#include <ExprPolicy.hpp>

//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<unsigned int> lines){
identifierName = name;
identifierType = type;
lineNumbers = lines;
}

void clear(){
identifierName.clear();
identifierType.clear();
lineNumbers.clear();
}

std::vector<std::string> namespaces;
int linenumber;
bool isConst;
bool isReference;
bool isPointer;
bool isStatic;

std::string identifierName;
std::string identifierType;
std::set<unsigned int> lineNumbers;
};
SrcProfile data;
~srcSliceProfilePolicy(){}
srcSliceProfilePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> 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"<<std::endl;
declData = *policy->Data<DeclTypePolicy::DeclTypeData>();

//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"<<std::endl;
exprData = *policy->Data<ExprPolicy::ExprDataSet>();
}
}

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);
};
}

};

0 comments on commit 10ec75f

Please sign in to comment.