Browse Source

Merge branch 'master' of bitbucket.org:cppit/juci

merge-requests/365/head
tedjk 11 years ago
parent
commit
4d57227b2c
  1. 56
      juci/CMakeLists.txt
  2. 82
      juci/cmake/Modules/FindLibClang.cmake
  3. 12
      juci/cmake/Modules/FindLibClangmm.cmake
  4. 2
      juci/juci.cc
  5. 98
      juci/notebook.cc
  6. 1
      juci/notebook.h
  7. 92
      juci/source.cc
  8. 31
      juci/source.h

56
juci/CMakeLists.txt

@ -3,7 +3,6 @@ set(project_name juci)
set(module juci_to_python_api) set(module juci_to_python_api)
project (${project_name}) project (${project_name})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/")
@ -15,8 +14,22 @@ message("Searcing for libclang")
#LIBCLANG_LIBRARIES The libraries needed to use libclang. #LIBCLANG_LIBRARIES The libraries needed to use libclang.
#LIBCLANG_LIBRARY_DIR The path to the directory containing libclang. #LIBCLANG_LIBRARY_DIR The path to the directory containing libclang.
#LIBCLANG_KNOWN_LLVM_VERSIONS Known LLVM release numbers. #LIBCLANG_KNOWN_LLVM_VERSIONS Known LLVM release numbers.
find_package(Testlcl) find_package(LibClangmm)
find_package(LibClang)
if(${LCL_FOUND})
message("libclangmm libraries found. Continuing")
message("${LCL_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "The libclangmm libraries are required. Quitting.")
endif()
if(${LIBCLANG_FOUND})
message("libclangmm libraries found. Continuing")
message("${LIBCLANG_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "The libclangmm libraries are required. Quitting.")
endif()
#### Finding boost, the variables below is set ##### #### Finding boost, the variables below is set #####
#PYTHONLIBS_FOUND - True if headers and requested libraries were found #PYTHONLIBS_FOUND - True if headers and requested libraries were found
@ -39,7 +52,7 @@ endif()
#Boost_INCLUDE_DIRS - Boost include directories #Boost_INCLUDE_DIRS - Boost include directories
#Boost_LIBRARY_DIRS - Link directories for Boost libraries #Boost_LIBRARY_DIRS - Link directories for Boost libraries
#Boost_LIBRARIES - Boost component libraries to be linked #Boost_LIBRARIES - Boost component libraries to be linked
find_package(Boost 1.5 REQUIRED COMPONENTS python) find_package(Boost 1.5 REQUIRED COMPONENTS python timer system)
#If boost is not found #If boost is not found
if(${Boost_FOUND}) if(${Boost_FOUND})
@ -72,20 +85,25 @@ endif()
# name of the executable on Windows will be example.exe # name of the executable on Windows will be example.exe
add_executable(${project_name} add_executable(${project_name}
#list of every needed file to create the executable #list of every needed file to create the executable
juci.cc juci.cc
keybindings keybindings.h
menu keybindings.cc
source menu.h
menu.cc
source.h
source.cc
config.h config.h
config.cc config.cc
sourcefile.h sourcefile.h
sourcefile.cc sourcefile.cc
window window.cc
api window.h
notebook api.h
entry api.cc
notebook.cc
#there is no need for extentions notebook.h
entry.h
entry.cc
) )
add_library(${module} SHARED add_library(${module} SHARED
@ -94,29 +112,25 @@ add_library(${module} SHARED
) )
# dependencies # dependencies
if(${lcl_NOTFOUND})
message("FATAL_ERROR ohh lord!")
else()
message("Found libs!")
endif()
include_directories( include_directories(
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS}
${LCL_INCLUDE_DIRS} ${LCL_INCLUDE_DIRS}
${LIBCLANG_INCLUDE_DIRS}
) )
link_directories( link_directories(
${GTKMM_LIBRARY_DIRS} ${GTKMM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS}
${PYTHON_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}
${LCL_LIBRARY_DIRS} ${LCL_LIBRARY_DIRS}
${LIBCLANG_LIBRARY_DIRS}
) )
#module: #module:
set_target_properties(${module} PROPERTIES PREFIX "" set_target_properties(${module} PROPERTIES PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "/usr/lib/python2.7/dist-packages/") LIBRARY_OUTPUT_DIRECTORY "/usr/lib/python2.7/dist-packages/")
target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
#executable: #executable:
target_link_libraries(${project_name} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) target_link_libraries(${project_name} ${LIVCLANG_LIBRARIES} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

82
juci/cmake/Modules/FindLibClang.cmake

@ -0,0 +1,82 @@
#
# Try to find libclang
#
# Once done this will define:
# - LIBCLANG_FOUND
# System has libclang.
# - LIBCLANG_INCLUDE_DIRS
# The libclang include directories.
# - LIBCLANG_LIBRARIES
# The libraries needed to use libclang.
# - LIBCLANG_LIBRARY_DIR
# The path to the directory containing libclang.
# - LIBCLANG_KNOWN_LLVM_VERSIONS
# Known LLVM release numbers.
# most recent versions come first
set(LIBCLANG_KNOWN_LLVM_VERSIONS 3.6
3.5.1
3.5.0 #Arch Linux
3.5 #LLVM Debian/Ubuntu packages from http://llvm.org/apt/
3.4.2 3.4.1 3.4 3.3 3.2 3.1)
set(libclang_llvm_header_search_paths)
set(libclang_llvm_lib_search_paths
# LLVM Fedora
/usr/lib/llvm
)
foreach (version ${LIBCLANG_KNOWN_LLVM_VERSIONS})
list(APPEND libclang_llvm_header_search_paths
# LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
"/usr/lib/llvm-${version}/include"
# LLVM MacPorts
"/opt/local/libexec/llvm-${version}/include"
# LLVM Homebrew
"/usr/local/Cellar/llvm/${version}/include"
# LLVM Homebrew/versions
"/usr/local/lib/llvm-${version}/include"
)
list(APPEND libclang_llvm_lib_search_paths
# LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
"/usr/lib/llvm-${version}/lib/"
# LLVM MacPorts
"/opt/local/libexec/llvm-${version}/lib"
# LLVM Homebrew
"/usr/local/Cellar/llvm/${version}/lib"
# LLVM Homebrew/versions
"/usr/local/lib/llvm-${version}/lib"
)
endforeach()
find_path(LIBCLANG_INCLUDE_DIR clang-c/Index.h
PATHS ${libclang_llvm_header_search_paths}
PATH_SUFFIXES LLVM/include #Windows package from http://llvm.org/releases/
DOC "The path to the directory that contains clang-c/Index.h")
# On Windows with MSVC, the import library uses the ".imp" file extension
# instead of the comon ".lib"
if (MSVC)
find_file(LIBCLANG_LIBRARY libclang.imp
PATH_SUFFIXES LLVM/lib
DOC "The file that corresponds to the libclang library.")
endif()
find_library(LIBCLANG_LIBRARY NAMES libclang.imp libclang clang
PATHS ${libclang_llvm_lib_search_paths}
PATH_SUFFIXES LLVM/lib #Windows package from http://llvm.org/releases/
DOC "The file that corresponds to the libclang library.")
get_filename_component(LIBCLANG_LIBRARY_DIR ${LIBCLANG_LIBRARY} PATH)
set(LIBCLANG_LIBRARIES ${LIBCLANG_LIBRARY})
set(LIBCLANG_INCLUDE_DIRS ${LIBCLANG_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBCLANG_FOUND to TRUE if
# all listed variables are TRUE
find_package_handle_standard_args(LibClang DEFAULT_MSG
LIBCLANG_LIBRARY LIBCLANG_INCLUDE_DIR)
mark_as_advanced(LIBCLANG_INCLUDE_DIR LIBCLANG_LIBRARY)

12
juci/cmake/Modules/FindTestlcl.cmake → juci/cmake/Modules/FindLibClangmm.cmake

@ -9,16 +9,12 @@
find_package(PkgConfig) find_package(PkgConfig)
find_path(LCL_INCLUDE_DIR headers/TranslationUnit.h find_path(LCL_INCLUDE_DIR clangmm.h
HINTS "/home/gm/bachelor/lib/" HINTS "/usr/lib/libclangmm/include/"
"/home/forgie/code/libclangpp/"
"/home/zalox/bachelor/libclang++/"
) )
find_library(LCL_LIBRARY NAMES testlcl find_library(LCL_LIBRARY NAMES clangmm
HINTS "/home/gm/bachelor/lib/lib/" HINTS "/usr/lib/libclangmm/"
"/home/forgie/code/libclangpp/lib/"
"/home/zalox/bachelor/libclang++/lib/"
) )
set(LCL_LIBRARIES ${LCL_LIBRARY} ) set(LCL_LIBRARIES ${LCL_LIBRARY} )

2
juci/juci.cc

@ -1,11 +1,11 @@
#include "window.h" #include "window.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create( Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(
argc, argc,
argv, argv,
"no.sout.juci"); "no.sout.juci");
Window window; Window window;
//api::LoadPlugin("juci_api_test"); //api::LoadPlugin("juci_api_test");

98
juci/notebook.cc

@ -1,11 +1,14 @@
#include <thread>
#include "notebook.h" #include "notebook.h"
Notebook::Model::Model() { Notebook::Model::Model() {
cc_extension_ = ".cc"; cc_extension_ = ".cc";
h_extension_ = ".h"; h_extension_ = ".h";
scrollvalue_ = 20; scrollvalue_ = 50;
} };
Notebook::View::View(){ Notebook::View::View(){
view_.pack_start(notebook_); view_.pack_start(notebook_);
} }
@ -98,13 +101,6 @@ source_config_(source_cfg) {
[this]() { [this]() {
Search(false); Search(false);
}); });
text_vec_.back()->view().
signal_scroll_event().connect(sigc::mem_fun(
this,
&Notebook::Controller::
scroll_event_callback));
}//Constructor }//Constructor
@ -120,19 +116,14 @@ bool Notebook::Controller::scroll_event_callback(GdkEventScroll* scroll_event) {
get_vscrollbar()->get_adjustment(); get_vscrollbar()->get_adjustment();
if ( direction_y != 0 ) { if ( direction_y != 0 ) {
int dir_val = direction_y==-1?-model_.scrollvalue_:+model_.scrollvalue_; int dir_val = direction_y==-1?-model_.scrollvalue_:+model_.scrollvalue_;
adj->set_value(adj->get_value()+dir_val); adj->set_value(adj->get_value()+dir_val);
text_vec_.at(page)->view().set_vadjustment(adj); text_vec_.at(page)->view().set_vadjustment(adj);
linenumbers_vec_.at(page)->view().set_vadjustment(adj); linenumbers_vec_.at(page)->view().set_vadjustment(adj);
} }
if ( direction_x != 0 ) {
int dir_val = direction_x==-1?-model_.scrollvalue_:+model_.scrollvalue_;
adj->set_value(adj->get_value()+dir_val);
text_vec_.at(page)->view().set_hadjustment(adj);
}
return true; return true;
} }
Notebook::Controller::~Controller() { Notebook::Controller::~Controller() {
for (auto &i : text_vec_) delete i; for (auto &i : text_vec_) delete i;
for (auto &i : linenumbers_vec_) delete i; for (auto &i : linenumbers_vec_) delete i;
@ -148,9 +139,9 @@ Gtk::Box& Notebook::Controller::entry_view() {
return entry_.view(); return entry_.view();
} }
void Notebook::Controller::OnNewPage(std::string name) { void Notebook::Controller::OnNewPage(std::string name) {
OnCreatePage(); OnCreatePage();
std::cout << "oppretta pages" << std::endl; std::cout << "oppretta pages" << std::endl;
text_vec_.back()->OnNewEmptyFile(); text_vec_.back()->OnNewEmptyFile();
Notebook().append_page(*editor_vec_.back(), name); Notebook().append_page(*editor_vec_.back(), name);
@ -178,7 +169,7 @@ void Notebook::Controller::OnCreatePage(){
editor_vec_.push_back(new Gtk::HBox()); editor_vec_.push_back(new Gtk::HBox());
scrolledtext_vec_.back()->add(text_vec_.back()->view()); scrolledtext_vec_.back()->add(text_vec_.back()->view());
scrolledline_vec_.back()->add(linenumbers_vec_.back()->view()); scrolledline_vec_.back()->add(linenumbers_vec_.back()->view());
linenumbers_vec_.back()->view().get_buffer()->set_text("1 \n"); linenumbers_vec_.back()->view().get_buffer()->set_text("1 ");
linenumbers_vec_.back()->view().override_color(Gdk::RGBA("Black")); linenumbers_vec_.back()->view().override_color(Gdk::RGBA("Black"));
linenumbers_vec_.back()-> linenumbers_vec_.back()->
view().set_justification(Gtk::Justification::JUSTIFY_RIGHT); view().set_justification(Gtk::Justification::JUSTIFY_RIGHT);
@ -187,6 +178,7 @@ void Notebook::Controller::OnCreatePage(){
linenumbers_vec_.back()->view().set_sensitive(false); linenumbers_vec_.back()->view().set_sensitive(false);
editor_vec_.back()->pack_start(*scrolledline_vec_.back(),false,false); editor_vec_.back()->pack_start(*scrolledline_vec_.back(),false,false);
editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true); editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true);
BufferChangeHandler(text_vec_.back()->view().get_buffer()); BufferChangeHandler(text_vec_.back()->view().get_buffer());
} }
@ -268,7 +260,7 @@ void Notebook::Controller::Search(bool forward){
if ( !forward ) { if ( !forward ) {
if ( search_match_start_ == 0 || if ( search_match_start_ == 0 ||
search_match_start_.get_line_offset() == 0) { search_match_start_.get_line_offset() == 0) {
search_match_start_= Buffer(text_vec_.at(CurrentPage()))->end(); search_match_start_= Buffer(text_vec_.at(CurrentPage()))->end();
} }
search_match_start_. search_match_start_.
@ -289,42 +281,35 @@ void Notebook::Controller::Search(bool forward){
search_match_end_); search_match_end_);
} }
} }
void Notebook::Controller::OnBufferChange() {
int page = CurrentPage();
int line_nr = Buffer(text_vec_.at(page))->get_line_count();
Glib::RefPtr
<Gtk::TextBuffer::Mark> mark = Gtk::TextBuffer::Mark::create();
Glib::RefPtr
<Gtk::TextBuffer::Mark> mark_lines = Gtk::TextBuffer::Mark::create();
if(Buffer(text_vec_.at(page))->get_insert()->get_iter().starts_line() &&
Buffer(text_vec_.at(page))->get_insert()->get_iter().get_line() ==
Buffer(text_vec_.at(page))->end().get_line()) {
std::string lines ="1 ";
for ( int it = 2; it <= line_nr; ++it ) {
lines.append("\n"+ std::to_string(it)+" ");
}
Buffer(linenumbers_vec_.at(page))->set_text(lines);
Buffer(text_vec_.at(page))->
add_mark(
mark,
Buffer(text_vec_.at(page))->end());
Buffer(linenumbers_vec_.at(page))->
add_mark(
mark_lines,
Buffer(linenumbers_vec_.at(page))->end());
text_vec_.at(page)->view().scroll_to(mark); void Notebook::Controller::OnBufferChange() {
linenumbers_vec_.at(page)->view().scroll_to(mark_lines); int page = CurrentPage();
}else{ int text_nr = Buffer(text_vec_.at(page))->get_line_count();
Buffer(text_vec_.at(page))-> int line_nr = Buffer(linenumbers_vec_.at(page))->get_line_count();
add_mark( while (line_nr < text_nr ){
mark, line_nr++;
Buffer(text_vec_.at(page))-> Buffer(linenumbers_vec_.at(page))->
get_insert()->get_iter()); insert(Buffer(linenumbers_vec_.at(page))->end(),
} "\n"+std::to_string(line_nr)+" ");
}
while (line_nr > text_nr ){
Gtk::TextIter iter = Buffer(linenumbers_vec_.at(page))->get_iter_at_line(line_nr);
iter.backward_char();
line_nr--;
Buffer(linenumbers_vec_.at(page))->
erase(iter,
Buffer(linenumbers_vec_.at(page))->end());
}
if(Buffer(text_vec_.at(page))->get_insert()->get_iter().starts_line() &&
Buffer(text_vec_.at(page))->get_insert()->get_iter().get_line() ==
Buffer(text_vec_.at(page))->end().get_line()) {
GdkEventScroll* scroll = new GdkEventScroll;
scroll->delta_y = 1.0;
scroll->delta_x = 0.0;
scroll_event_callback(scroll);
delete scroll;
}
} }
@ -351,7 +336,8 @@ Gtk::Notebook& Notebook::Controller::Notebook() {
void Notebook::Controller::BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer> void Notebook::Controller::BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer>
buffer) { buffer) {
buffer->signal_changed().connect( buffer->signal_changed().connect(
[this]() { [this]() {
OnBufferChange(); OnBufferChange();
}); });
} }

1
juci/notebook.h

@ -69,4 +69,5 @@ namespace Notebook {
Glib::RefPtr<Gtk::Clipboard> refClipboard_; Glib::RefPtr<Gtk::Clipboard> refClipboard_;
}; // class controller }; // class controller
} // namespace Notebook } // namespace Notebook
#endif // JUCI_NOTEBOOK_H_ #endif // JUCI_NOTEBOOK_H_

92
juci/source.cc

@ -3,6 +3,7 @@
#include "sourcefile.h" #include "sourcefile.h"
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <fstream> #include <fstream>
#include <boost/timer/timer.hpp>
////////////// //////////////
//// View //// //// View ////
@ -15,7 +16,7 @@ Source::View::View() {
// returns the new line // returns the new line
string Source::View::UpdateLine() { string Source::View::UpdateLine() {
Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); Gtk::TextIter line(get_buffer()->get_insert()->get_iter());
//std::cout << line.get_line() << std::endl; // std::cout << line.get_line() << std::endl;
// for each word --> check what it is --> apply appropriate tag // for each word --> check what it is --> apply appropriate tag
return ""; return "";
} }
@ -37,9 +38,9 @@ void Source::View::ApplyConfig(const Source::Config &config) {
} }
} }
void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations, void Source::View::OnOpenFile(std::vector<clang::SourceLocation> &locations,
const Source::Config &config) { const Source::Config &config) {
ApplyConfig(config); /* ApplyConfig(config);
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer(); Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) { for (auto &loc : locations) {
string type = std::to_string(loc.kind()); string type = std::to_string(loc.kind());
@ -66,10 +67,11 @@ void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end);
// std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl; // std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl;
if (begin_iter.get_line() == end_iter.get_line()) { if (begin_iter.get_line() == end_iter.get_line()) {
buffer->apply_tag_by_name(config.typetable().at(type), buffer->apply_tag_by_name(config.typetable().at(type),
begin_iter, end_iter); begin_iter, end_iter);
} }
} }
*/
} }
@ -101,7 +103,7 @@ void Source::Config::InsertTag(const string &key, const string &value) {
// Source::View::Config::SetTagTable() // Source::View::Config::SetTagTable()
// sets the tagtable for the view // sets the tagtable for the view
void Source::Config::SetTypeTable( void Source::Config::SetTypeTable(
const std::unordered_map<string, string> &typetable) { const std::unordered_map<string, string> &typetable) {
typetable_ = typetable; typetable_ = typetable;
} }
@ -111,32 +113,13 @@ void Source::Config::InsertType(const string &key, const string &value) {
// Source::View::Config::SetTagTable() // Source::View::Config::SetTagTable()
// sets the tagtable for the view // sets the tagtable for the view
void Source::Config::SetTagTable( void Source::Config::SetTagTable(
const std::unordered_map<string, string> &tagtable) { const std::unordered_map<string, string> &tagtable) {
tagtable_ = tagtable; tagtable_ = tagtable;
} }
/////////////// ///////////////
//// Model //// //// Model ////
/////////////// ///////////////
/*Source::Model::Model() {
std::cout << "Model constructor run" << std::endl;
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json("config.json", pt);
for ( auto &i : pt ) {
boost::property_tree::ptree props = pt.get_child(i.first);
for (auto &pi : props) {
if (i.first.compare("syntax")) { // checks the config-file
config_.InsertTag(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting tag. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
if (i.first.compare("colors")) { // checks the config-file
config_.InsertType(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting type. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
}
}
}*/
Source::Model::Model(const Source::Config &config) : Source::Model::Model(const Source::Config &config) :
config_(config) { config_(config) {
} }
@ -154,7 +137,7 @@ void Source::Model::SetFilePath(const string &filepath) {
} }
void Source::Model:: void Source::Model::
SetSourceLocations(const std::vector<Clang::SourceLocation> &locations) { SetSourceLocations(const std::vector<clang::SourceLocation> &locations) {
locations_ = locations; locations_ = locations;
} }
//////////////////// ////////////////////
@ -170,13 +153,6 @@ Source::Controller::Controller(const Source::Config &config) :
}); });
} }
/*Source::Controller::Controller(){
//std::cout << "Controller constructor run" << std::endl;
view().get_buffer()->signal_changed().connect([this](){
this->OnLineEdit();
});
}*/
// Source::Controller::view() // Source::Controller::view()
// return shared_ptr to the view // return shared_ptr to the view
Source::View& Source::Controller::view() { Source::View& Source::Controller::view() {
@ -200,16 +176,44 @@ void Source::Controller::OnNewEmptyFile() {
s.save(""); s.save("");
} }
void Source::Controller::OnOpenFile(const string &filename) { void Source::Controller::OnOpenFile(const string &filepath) {
sourcefile s(filename); sourcefile s(filepath);
view().get_buffer()->set_text(s.get_content()); buffer()->set_text(s.get_content());
int linums = view().get_buffer()->end().get_line(); int start_offset = buffer()->begin().get_offset();
int offset = view().get_buffer()->end().get_line_offset(); int end_offset = buffer()->end().get_offset();
Clang::TranslationUnit tu(filename.c_str(), linums, offset);
model().SetSourceLocations(tu.getSourceLocations()); std::string project_path =
view().OnOpenFile(model().getSourceLocations(), model().config()); filepath.substr(0, filepath.find_last_of('/'));
clang::CompilationDatabase db(project_path);
clang::CompileCommands commands(filepath, &db);
std::vector<clang::CompileCommand> cmds = commands.get_commands();
std::vector<const char*> arguments;
for (auto &i : cmds) {
std::vector<std::string> lol = i.get_command_as_args();
for (int a = 1; a < lol.size()-4; a++) {
arguments.emplace_back(lol[a].c_str());
}
}
clang::TranslationUnit tu(true, filepath, arguments);
clang::SourceLocation start(&tu, filepath, start_offset);
clang::SourceLocation end(&tu, filepath, end_offset);
clang::SourceRange range(&start, &end);
clang::Tokens tokens(&tu, &range);
std::vector<clang::Token> tks = tokens.tokens();
for (auto &t : tks) {
clang::SourceLocation loc = t.get_source_location(&tu);
unsigned line;
unsigned column;
loc.get_location_info(NULL, &line, &column, NULL);
}
// std::cout << t.elapsed().user << std::endl;
// model().SetSourceLocations(tu.getSourceLocations());
// view().OnOpenFile(model().getSourceLocations(), model().theme());
} }
Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer(){ Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() {
return view().get_buffer(); return view().get_buffer();
} }

31
juci/source.h

@ -5,7 +5,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "gtkmm.h" #include "gtkmm.h"
#include <TranslationUnit.h> #include "clangmm.h"
using std::string; using std::string;
@ -25,14 +25,34 @@ namespace Source {
private: private:
std::unordered_map<string, string> tagtable_; std::unordered_map<string, string> tagtable_;
std::unordered_map<string, string> typetable_; std::unordered_map<string, string> typetable_;
string background_;
}; // class Config }; // class Config
/*
class BufferLocation {
BufferLocation(const BufferLocation &location);
BufferLocation(int, int);
int line_number() { return line_number_; }
int column_number() { return column_offset_; }
private:
int line_number_;
int column_offset_;
};
class BufferRange {
BufferRange(const BufferLocation &start, const BufferLocation &end) :
start_(start), end_(end) { }
private:
BufferLocation start_;
BufferLocation end_;
};*/
class View : public Gtk::TextView { class View : public Gtk::TextView {
public: public:
View(); View();
string UpdateLine(); string UpdateLine();
void ApplyConfig(const Config &config); void ApplyConfig(const Config &config);
void OnOpenFile(std::vector<Clang::SourceLocation> &locations, void OnOpenFile(std::vector<clang::SourceLocation> &locations,
const Config &config); const Config &config);
private: private:
string GetLine(const Gtk::TextIter &begin); string GetLine(const Gtk::TextIter &begin);
@ -45,16 +65,15 @@ namespace Source {
Config& config(); Config& config();
const string filepath(); const string filepath();
void SetFilePath(const string &filepath); void SetFilePath(const string &filepath);
void SetSourceLocations( void SetSourceLocations( const std::vector<clang::SourceLocation> &locations);
const std::vector<Clang::SourceLocation> &locations); std::vector<clang::SourceLocation>& getSourceLocations() {
std::vector<Clang::SourceLocation>& getSourceLocations() {
return locations_; return locations_;
} }
private: private:
Source::Config config_; Source::Config config_;
string filepath_; string filepath_;
std::vector<Clang::SourceLocation> locations_; std::vector<clang::SourceLocation> locations_;
}; };
class Controller { class Controller {

Loading…
Cancel
Save