From 4bf459fa99f3001c4650e95c8479b1ab27a2ae2d Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sat, 26 Jul 2014 15:31:55 +0200 Subject: [PATCH] logic: Refreshing reloads the source code and resets the Token ids to start from 1 --- bin/app/data/src/header.h | 2 +- src/lib/Application.cpp | 19 +++++++++++++++---- src/lib/Application.h | 4 ++++ src/lib/Project.cpp | 19 ++++++++++++++----- src/lib/Project.h | 1 + src/lib/data/graph/Token.cpp | 5 +++++ src/lib/data/graph/Token.h | 2 ++ 7 files changed, 42 insertions(+), 10 deletions(-) diff --git a/bin/app/data/src/header.h b/bin/app/data/src/header.h index 05c6fbf2..33d387b5 100644 --- a/bin/app/data/src/header.h +++ b/bin/app/data/src/header.h @@ -13,7 +13,7 @@ y fooy(); z fooz(); */ -const bool *ab(int a, int b); +const bool *ab(int abc, int bca); bool const *abc(int a, int b); diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 116d536e..2a7ea527 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -45,8 +45,7 @@ void Application::loadProject(const std::string& projectSettingsFilePath) m_project->loadProjectSettings(projectSettingsFilePath); m_project->parseCode(); - MessageActivateToken message(1); - message.dispatch(); + MessageActivateToken(1).dispatch(); } void Application::loadSource(const std::string& sourceDirectoryPath) @@ -57,8 +56,15 @@ void Application::loadSource(const std::string& sourceDirectoryPath) m_project->setSourceDirectoryPath(sourceDirectoryPath); m_project->parseCode(); - MessageActivateToken message(1); - message.dispatch(); + MessageActivateToken(1).dispatch(); +} + +void Application::reloadProject() +{ + m_project->clearStorage(); + m_project->parseCode(); + + MessageActivateToken(1).dispatch(); } void Application::handleMessage(MessageLoadProject* message) @@ -70,3 +76,8 @@ void Application::handleMessage(MessageLoadSource* message) { loadSource(message->sourceDirectoryPath); } + +void Application::handleMessage(MessageRefresh* message) +{ + reloadProject(); +} diff --git a/src/lib/Application.h b/src/lib/Application.h index 63e08d0c..e505e39b 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -8,6 +8,7 @@ #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageLoadSource.h" +#include "utility/messaging/type/MessageRefresh.h" class ViewFactory; class MainView; @@ -17,6 +18,7 @@ class LocationAccessProxy; class Application : public MessageListener , public MessageListener + , public MessageListener { public: static std::shared_ptr create(ViewFactory* viewFactory); @@ -25,12 +27,14 @@ public: void loadProject(const std::string& projectSettingsFilePath); void loadSource(const std::string& sourceDirectoryPath); + void reloadProject(); private: Application(); virtual void handleMessage(MessageLoadProject* message); virtual void handleMessage(MessageLoadSource* message); + virtual void handleMessage(MessageRefresh* message); std::shared_ptr m_project; std::shared_ptr m_graphAccessProxy; diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 7499f8d4..dc0f1d65 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -5,6 +5,7 @@ #include "data/access/GraphAccessProxy.h" #include "data/access/LocationAccessProxy.h" +#include "data/graph/Token.h" #include "data/parser/cxx/CxxParser.h" #include "utility/FileSystem.h" #include "utility/logging/logging.h" @@ -13,11 +14,7 @@ std::shared_ptr Project::create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy) { std::shared_ptr ptr(new Project(graphAccessProxy, locationAccessProxy)); - ptr->m_storage = std::make_shared(); - - graphAccessProxy->setSubject(ptr->m_storage.get()); - locationAccessProxy->setSubject(ptr->m_storage.get()); - + ptr->clearStorage(); return ptr; } @@ -40,13 +37,25 @@ bool Project::setSourceDirectoryPath(const std::string& sourceDirectoryPath) return ProjectSettings::getInstance()->setSourcePath(sourceDirectoryPath); } +void Project::clearStorage() +{ + m_storage = std::make_shared(); + + m_graphAccessProxy->setSubject(m_storage.get()); + m_locationAccessProxy->setSubject(m_storage.get()); + + Token::resetNextId(); +} + void Project::parseCode() { if (ProjectSettings::getInstance()->getSourcePath() != "") { std::vector extensions; extensions.push_back(".cpp"); + extensions.push_back(".cc"); extensions.push_back(".h"); + extensions.push_back(".hpp"); CxxParser parser(m_storage); parser.parseFiles( diff --git a/src/lib/Project.h b/src/lib/Project.h index c764afc5..6bc90890 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -21,6 +21,7 @@ public: bool setSourceDirectoryPath(const std::string& sourceDirectoryPath); + void clearStorage(); void parseCode(); private: diff --git a/src/lib/data/graph/Token.cpp b/src/lib/data/graph/Token.cpp index f43e4f55..12e09fcf 100644 --- a/src/lib/data/graph/Token.cpp +++ b/src/lib/data/graph/Token.cpp @@ -3,6 +3,11 @@ #include "data/location/TokenLocation.h" #include "utility/logging/logging.h" +void Token::resetNextId() +{ + s_nextId = 1; +} + Token::Token() : m_id(s_nextId++) { diff --git a/src/lib/data/graph/Token.h b/src/lib/data/graph/Token.h index 24f80e48..e29f43ae 100644 --- a/src/lib/data/graph/Token.h +++ b/src/lib/data/graph/Token.h @@ -10,6 +10,8 @@ class Token { public: + static void resetNextId(); + Token(); virtual ~Token();