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() {
unsigned size = clang_CompileCommands_getSize(cx_commands);
std::vector<CompileCommand> commands;
commands.reserve(size);
for (unsigned i = 0; i < size; i++)
commands.emplace_back(clang_CompileCommands_getCommand(cx_commands, i));
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 path;
get_data(&path, NULL, NULL, NULL);
get_data(&path, nullptr, nullptr, nullptr);
return path;
}
clangmm::Offset clangmm::SourceLocation::get_offset() {
unsigned line, index;
get_data(NULL, &line, &index, NULL);
return {line, index};
unsigned line, index, offset;
get_data(nullptr, &line, &index, &offset);
return {line, index, 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 {
class Offset {
public:
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 offset==o.offset;}
bool operator!=(const clangmm::Offset &o) {return !(*this==o);}
unsigned line;
unsigned index; //byte index in line (not char number)
unsigned offset;
};
class SourceLocation {

Loading…
Cancel
Save