From d1b23c7274d6430ccc70bf2baf616437db9f5706 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Fri, 20 Mar 2015 12:55:09 +0100 Subject: [PATCH] Implement InformationManager / Comment and ChangeCommentEvent Comments can now be passed through the InformationManager who will properly emit events --- src/core/Comment.cxx | 8 ++++++++ src/core/Comment.hxx | 1 + src/core/InformationManager.cxx | 24 ++++++++++++++++++++++-- src/core/InformationManager.hxx | 11 +++++++++-- src/core/events/ChangeCommentEvent.hxx | 21 +++++++++++++++++++++ src/disassembler/Instruction.hxx | 4 ++++ 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/core/events/ChangeCommentEvent.hxx diff --git a/src/core/Comment.cxx b/src/core/Comment.cxx index 0cb804c..d6fedfb 100644 --- a/src/core/Comment.cxx +++ b/src/core/Comment.cxx @@ -1,5 +1,7 @@ #include "Comment.hxx" #include "Function.hxx" +#include "InformationManager.hxx" +#include "events/ChangeCommentEvent.hxx" Comment::Comment(uint64_t address, InformationManager* manager) : address(address) @@ -12,9 +14,15 @@ Comment::Comment(uint64_t address, Function* location, InformationManager* manag , manager(manager) {} void Comment::setText(const std::string& text) { + ChangeCommentEvent event(address, location, this); this->text = text; + manager->dispatch(&event); } uint64_t Comment::getAddress() { return address; } + +Function* Comment::getLocation() { + return location; +} diff --git a/src/core/Comment.hxx b/src/core/Comment.hxx index b07f13a..98febe4 100644 --- a/src/core/Comment.hxx +++ b/src/core/Comment.hxx @@ -12,6 +12,7 @@ public: void setText(const std::string& text); uint64_t getAddress(); + Function* getLocation(); private: Comment(uint64_t address, InformationManager* manager); Comment(uint64_t address, Function* location, InformationManager* manager); diff --git a/src/core/InformationManager.cxx b/src/core/InformationManager.cxx index e157189..8834a7a 100644 --- a/src/core/InformationManager.cxx +++ b/src/core/InformationManager.cxx @@ -5,6 +5,7 @@ #include "core/BasicBlock.hxx" #include "core/Comment.hxx" #include "core/events/NewFunctionEvent.hxx" +#include "core/events/ChangeCommentEvent.hxx" #include "gui/qt.hxx" #include @@ -160,6 +161,22 @@ std::map::const_iterator InformationManager::endBasicBloc return blocks.end(); } +/* ********************************* + * Accessors for the Comments map + */ +std::pair< + std::multimap::const_iterator, + std::multimap::const_iterator> +InformationManager::getComments(uint64_t address) { + return comments.equal_range(address); +} + +std::multimap::const_iterator InformationManager::beginComments() { + return comments.begin(); +} +std::multimap::const_iterator InformationManager::endComments() { + return comments.end(); +} /* ********************************* * Accessors for the Interpreter map @@ -210,7 +227,7 @@ Comment* InformationManager::newGlobalComment(uint64_t address) { } Comment* InformationManager::newLocalComment(uint64_t address, Function* f) { - Comment* comment = new Comment(address, this); + Comment* comment = new Comment(address, f, this); comments.insert(std::make_pair(address, comment)); return comment; } @@ -228,7 +245,10 @@ void InformationManager::finishFunction(Function* fun) { void InformationManager::finishBasicBlock(BasicBlock*) { } -void InformationManager::finnishComment(Comment* c) { +void InformationManager::finishComment(Comment* c) { + LOG4CXX_DEBUG(logger, "Finishing comment " << c->getAddress()); + ChangeCommentEvent event(c->getAddress(), c->getLocation(), c); + dispatch(&event); } void InformationManager::deleteFunction(Function* f) { diff --git a/src/core/InformationManager.hxx b/src/core/InformationManager.hxx index bb37a1e..3407113 100644 --- a/src/core/InformationManager.hxx +++ b/src/core/InformationManager.hxx @@ -72,12 +72,19 @@ public: std::map::const_iterator beginBasicBlocks(); std::map::const_iterator endBasicBlocks(); + std::pair< + std::multimap::const_iterator, + std::multimap::const_iterator> + getComments(uint64_t address); + bool hasComments() const {return ! comments.empty();} + std::multimap::const_iterator beginComments(); + std::multimap::const_iterator endComments(); + Interpreter* getInterpreter(const std::string& name); bool hasInterpreters() const {return interpreters.size() != 0;} std::map::const_iterator beginInterpreters(); std::map::const_iterator endInterpreters(); - /* Protocoll: * * Users may allocate new Data containers with the new*() @@ -104,7 +111,7 @@ public: Comment* newLocalComment(uint64_t address, Function* f); void finishFunction(Function* f); void finishBasicBlock(BasicBlock* b); - void finnishComment(Comment* c); + void finishComment(Comment* c); void deleteFunction(Function* f); void deleteBasicBlock(BasicBlock* b); void deleteComment(Comment* c); diff --git a/src/core/events/ChangeCommentEvent.hxx b/src/core/events/ChangeCommentEvent.hxx new file mode 100644 index 0000000..de8d5c3 --- /dev/null +++ b/src/core/events/ChangeCommentEvent.hxx @@ -0,0 +1,21 @@ +#ifndef INCLUDE__ChangeCommentEvent_hxx_ +#define INCLUDE__ChangeCommentEvent_hxx_ + +#include + +class Comment; +class Function; + +class ChangeCommentEvent { +public: + ChangeCommentEvent(uint64_t address, Function* function, Comment* comment) + : address(address), function(function), comment(comment) {} + ChangeCommentEvent(uint64_t address, Comment* comment) + : address(address), function(NULL), comment(comment) {} + + uint64_t address; + Function* function; + Comment* comment; +}; + +#endif /* INCLUDE__ChangeCommentEvent_hxx_ */ diff --git a/src/disassembler/Instruction.hxx b/src/disassembler/Instruction.hxx index e79b24f..5a74e22 100644 --- a/src/disassembler/Instruction.hxx +++ b/src/disassembler/Instruction.hxx @@ -5,6 +5,8 @@ #include #include +class Comment; + class Instruction { public: Instruction(uint64_t address, const std::string& text, const std::vector& bytes, const std::string& reference) @@ -13,11 +15,13 @@ public: const std::string& getText() const {return text;} const std::vector& getBytes() const {return bytes;} const std::string& getReference() const {return reference;} + std::vector& comments() {return _comments;} private: uint64_t address; std::string text; std::vector bytes; std::string reference; + std::vector _comments; }; #endif /* INCLUDE__Instruction_hxx_ */ -- 2.39.5