Skip to content

Commit

Permalink
Merge pull request #12 from cjxgm/dev
Browse files Browse the repository at this point in the history
some fix
  • Loading branch information
eXerigumo Clanjor (哆啦比猫/兰威举) committed Aug 26, 2014
2 parents 84a8bf3 + b2dd13d commit abb2eb0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 21 deletions.
5 changes: 4 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ sub write_makefile
# License: The MIT License with modification. See LICENSE for details.
# (C) 2014. eXerigumo Clanjor (哆啦比猫/兰威举) <cjxgm\@126.com>
LOG = no
LOG_SYSTEM = \$(LOG)_log
CC = $CC
LD = $LD
CCFLAGS = $CCFLAGS
CCFLAGS = $CCFLAGS -DLOG_SYSTEM=\$(LOG_SYSTEM)
LDFLAGS = $LDFLAGS
EOF
Expand Down
46 changes: 34 additions & 12 deletions src/analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace vimlight
tu.parse(src);

auto diags = tu.diagnostics();
log << "analyzer::parse():" << endl;
log << "analyzer::parse():\n";
for (auto& diag: diags) {
log << "\t[error]" << endl
<< "\t\t" << diag.text() << endl;
log << "\t[error]\n"
<< "\t\t" << diag.text() << '\n';

auto loc = diag.location();
if (!loc.is_from_main()) continue;
Expand All @@ -26,7 +26,7 @@ namespace vimlight
pos.y, pos.x+1,
"error" });

log << "\t\t" << pos.y << ", " << pos.x << endl;
log << "\t\t" << pos.y << ", " << pos.x << '\n';
}

tu.cursor().each_child([&](const clang::cursor& cursor) {
Expand All @@ -38,17 +38,39 @@ namespace vimlight
auto head_pos = head .position();
auto tail_pos = range.tail().position();
auto kind = cursor.kind().name();
log << "\t[" << kind << "]" << endl
<< "\t\t\"" << cursor.name() << "\"" << endl
log << "\t[" << kind << "]\n"
<< "\t\t\"" << cursor.name() << "\"\n"
<< "\t\t" << head_pos.y << ", " << head_pos.x
<< " -> " << tail_pos.y << ", " << tail_pos.x << endl;
<< " -> " << tail_pos.y << ", " << tail_pos.x << '\n';

try {
list.push_back({
head_pos.y, head_pos.x,
tail_pos.y, tail_pos.x,
group.at(kind)});
log << "\t\t" << group.at(kind) << endl;
if (kind == "InitListExpr") {
kind = group.at("init_list_brace");
log << "\t[init_list_brace]\n"
<< "\t\t" << head_pos.y << ", " << head_pos.x
<< " -> " << head_pos.y << ", " << head_pos.x+1
<< '\n'
<< "\t\t" << tail_pos.y << ", " << tail_pos.x-1
<< " -> " << tail_pos.y << ", " << tail_pos.x
<< '\n';
list.push_back({
head_pos.y, head_pos.x,
head_pos.y, head_pos.x+1,
kind });
list.push_back({
tail_pos.y, tail_pos.x-1,
tail_pos.y, tail_pos.x,
kind });
log << "\t\t" << kind << '\n';
}

else {
list.push_back({
head_pos.y, head_pos.x,
tail_pos.y, tail_pos.x,
group.at(kind) });
log << "\t\t" << group.at(kind) << '\n';
}
return true;
}
catch (std::out_of_range) {}
Expand Down
2 changes: 1 addition & 1 deletion src/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace vimlight
{
log_file log{"/tmp/vimlight.log"};
log_system::log log;
};

38 changes: 35 additions & 3 deletions src/log.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,40 @@

namespace vimlight
{
using log_file = std::ofstream;
using std::endl;
extern log_file log;
namespace no_log
{
struct log {};
namespace helper
{
template <class T>
log& operator<<(log& l, T&&) { return l; }
};
};

namespace file_log
{
struct log
{
std::ofstream o{"/tmp/vimlight.log"};
};
namespace helper
{
template <class T>
log& operator<<(log& l, T&& what)
{
l.o << what;
return l;
}
};
};

#ifndef LOG_SYSTEM
#define LOG_SYSTEM no_log
#endif

namespace log_system = LOG_SYSTEM;
extern log_system::log log;
};

using namespace vimlight::log_system::helper;

4 changes: 2 additions & 2 deletions src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ namespace vimlight
chn_main.post(event_done{});

chn_worker.listen<event_request>([&](event_request ev) {
log << "(worker) parse request" << endl;
log << "(worker) parse request\n";
auto result = analyzer.parse(ev.src, group);
delta.update(result, vim);
chn_main.post(event_done{});
chn_main.post(event_result{std::move(vim.get())});
});

chn_worker.listen<event_name>([&](event_name ev) {
log << "(worker) name: " << ev.name << endl;
log << "(worker) name: " << ev.name << '\n';
analyzer.name(ev.name);
});

Expand Down
3 changes: 1 addition & 2 deletions vim/etc/hlgroup.vimlight
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ TypeRef Type
NamespaceRef Special
TemplateRef MoreMsg
FunctionRef MoreMsg
MemberRefExpr Underlined
DeclRefExpr Normal
error Error
init_list_brace Define

0 comments on commit abb2eb0

Please sign in to comment.