Browse Source

Added std::vector::reserve to CompileCommands::get_commands(), and added byte offset to clangmm::Offset

merge-requests/37/head
eidheim 8 years ago
parent
commit
4d3f12f528
  1. 1
      src/CompileCommands.cc
  2. 8
      src/SourceLocation.cc
  3. 5
      src/SourceLocation.h

1
src/CompileCommands.cc

@ -14,6 +14,7 @@ clangmm::CompileCommands::~CompileCommands() {
std::vector<clangmm::CompileCommand> clangmm::CompileCommands::get_commands() { std::vector<clangmm::CompileCommand> clangmm::CompileCommands::get_commands() {
unsigned size = clang_CompileCommands_getSize(cx_commands); unsigned size = clang_CompileCommands_getSize(cx_commands);
std::vector<CompileCommand> commands; std::vector<CompileCommand> commands;
commands.reserve(size);
for (unsigned i = 0; i < size; i++) for (unsigned i = 0; i < size; i++)
commands.emplace_back(clang_CompileCommands_getCommand(cx_commands, i)); commands.emplace_back(clang_CompileCommands_getCommand(cx_commands, i));
return commands; return commands;

8
src/SourceLocation.cc

@ -16,13 +16,13 @@ clangmm::SourceLocation::SourceLocation(CXTranslationUnit &tu, const std::string
std::string clangmm::SourceLocation::get_path() { std::string clangmm::SourceLocation::get_path() {
std::string path; std::string path;
get_data(&path, NULL, NULL, NULL); get_data(&path, nullptr, nullptr, nullptr);
return path; return path;
} }
clangmm::Offset clangmm::SourceLocation::get_offset() { clangmm::Offset clangmm::SourceLocation::get_offset() {
unsigned line, index; unsigned line, index, offset;
get_data(NULL, &line, &index, NULL); get_data(nullptr, &line, &index, &offset);
return {line, index}; return {line, index, offset};
} }
void clangmm::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) { void clangmm::SourceLocation::get_data(std::string* path, unsigned *line, unsigned *column, unsigned *offset) {

5
src/SourceLocation.h

@ -6,12 +6,11 @@
namespace clangmm { namespace clangmm {
class Offset { class Offset {
public: public:
Offset() {} bool operator==(const clangmm::Offset &o) {return offset==o.offset;}
Offset(unsigned line, unsigned index): line(line), index(index) {}
bool operator==(const clangmm::Offset &o) {return (line==o.line && index==o.index);}
bool operator!=(const clangmm::Offset &o) {return !(*this==o);} bool operator!=(const clangmm::Offset &o) {return !(*this==o);}
unsigned line; unsigned line;
unsigned index; //byte index in line (not char number) unsigned index; //byte index in line (not char number)
unsigned offset;
}; };
class SourceLocation { class SourceLocation {

Loading…
Cancel
Save