Browse Source

Some cleanup.

merge-requests/37/head
eidheim 11 years ago
parent
commit
0c0615f9ee
  1. 38
      src/Diagnostic.cc
  2. 5
      src/Diagnostic.h
  3. 2
      src/SourceRange.cc
  4. 3
      src/SourceRange.h
  5. 2
      src/Tokens.h
  6. 27
      src/TranslationUnit.cc
  7. 3
      src/TranslationUnit.h

38
src/Diagnostic.cc

@ -1,16 +1,44 @@
#include "Diagnostic.h"
#include "SourceLocation.h"
#include "Tokens.h"
clang::Diagnostic::Diagnostic(clang::TranslationUnit& tu, CXDiagnostic clang_diagnostic) {
severity=clang_getDiagnosticSeverity(clang_diagnostic);
severity_spelling=get_severity_spelling(severity);
spelling=clang_getCString(clang_getDiagnosticSpelling(clang_diagnostic));
clang::SourceLocation location(clang_getDiagnosticLocation(clang_diagnostic));
std::string tmp_path;
unsigned line, column, offset;
location.get_location_info(&tmp_path, &line, &column, &offset);
path=tmp_path;
start_location.line=line;
start_location.column=column;
start_location.offset=offset;
clang::SourceRange range(&location, &location);
clang::Tokens tokens(&tu, &range);
if(tokens.tokens().size()==1) {
auto& token=tokens.tokens()[0];
clang::SourceRange range=token.get_source_range(&tu);
clang::SourceLocation location(&range, false);
location.get_location_info(NULL, &line, &column, &offset);
end_location.line=line;
end_location.column=column;
end_location.offset=offset;
}
}
const std::string clang::Diagnostic::get_severity_spelling(unsigned severity) {
switch(severity) {
case 0:
case CXDiagnostic_Ignored:
return "Ignored";
case 1:
case CXDiagnostic_Note:
return "Note";
case 2:
case CXDiagnostic_Warning:
return "Warning";
case 3:
case CXDiagnostic_Error:
return "Error";
case 4:
case CXDiagnostic_Fatal:
return "Fatal";
default:
return "";

5
src/Diagnostic.h

@ -1,6 +1,9 @@
#ifndef DIAGNOSTIC_H_
#define DIAGNOSTIC_H_
#include <string>
#include <vector>
#include <clang-c/Index.h>
#include "TranslationUnit.h"
namespace clang {
class Diagnostic {
@ -10,6 +13,8 @@ namespace clang {
unsigned line, column, offset;
};
Diagnostic(clang::TranslationUnit& tu, CXDiagnostic clang_diagnostic);
static const std::string get_severity_spelling(unsigned severity);
unsigned severity;

2
src/SourceRange.cc

@ -10,8 +10,6 @@ SourceRange(clang::SourceLocation *start, clang::SourceLocation *end) {
range_ = clang_getRange(start->location_, end->location_);
}
clang::SourceRange::~SourceRange() { }
clang::SourceRange::SourceRange(Cursor *cursor) {
range_ = clang_getCursorExtent(cursor->cursor_);
}

3
src/SourceRange.h

@ -7,16 +7,17 @@
namespace clang {
class SourceRange {
public:
SourceRange() {}
SourceRange(TranslationUnit *tu, Token *token);
SourceRange(SourceLocation *start,
SourceLocation *end);
explicit SourceRange(Cursor *cursor);
~SourceRange();
private:
CXSourceRange range_;
friend Tokens;
friend SourceLocation;
friend Diagnostic;
};
} // namespace clang
#endif // SOURCERANGE_H_

2
src/Tokens.h

@ -10,7 +10,7 @@ namespace clang {
Tokens(TranslationUnit *tu, SourceRange *range);
~Tokens();
std::vector<Token>& tokens();
protected:
private:
std::vector<clang::Token> tks;
CXToken *tokens_;
unsigned num_tokens_;

27
src/TranslationUnit.cc

@ -94,32 +94,7 @@ std::vector<clang::Diagnostic> clang::TranslationUnit::get_diagnostics() {
std::vector<clang::Diagnostic> diagnostics;
for(unsigned c=0;c<clang_getNumDiagnostics(tu_);c++) {
CXDiagnostic clang_diagnostic=clang_getDiagnostic(tu_, c);
diagnostics.emplace_back();
auto& diagnostic=diagnostics.back();
diagnostic.severity=clang_getDiagnosticSeverity(clang_diagnostic);
diagnostic.severity_spelling=clang::Diagnostic::get_severity_spelling(diagnostic.severity);
diagnostic.spelling=clang_getCString(clang_getDiagnosticSpelling(clang_diagnostic));
SourceLocation location(clang_getDiagnosticLocation(clang_diagnostic));
std::string path;
unsigned line, column, offset;
location.get_location_info(&path, &line, &column, &offset);
diagnostic.path=path;
diagnostic.start_location.line=line;
diagnostic.start_location.column=column;
diagnostic.start_location.offset=offset;
clang::SourceRange range(&location, &location);
clang::Tokens tokens(this, &range);
if(tokens.tokens().size()==1) {
auto& token=tokens.tokens()[0];
clang::SourceRange range=token.get_source_range(this);
clang::SourceLocation end_location(&range, false);
end_location.get_location_info(NULL, &line, &column, &offset);
diagnostic.end_location.line=line;
diagnostic.end_location.column=column;
diagnostic.end_location.offset=offset;
}
diagnostics.emplace_back(clang::Diagnostic(*this, clang_diagnostic));
}
return diagnostics;
}

3
src/TranslationUnit.h

@ -15,6 +15,7 @@ namespace clang {
class SourceRange;
class Cursor;
class CodeCompleteResults;
class Diagnostic;
class TranslationUnit {
public:
@ -35,7 +36,7 @@ namespace clang {
&buffers,
unsigned flags=DefaultFlags());
static unsigned DefaultFlags();
std::vector<Diagnostic> get_diagnostics();
std::vector<clang::Diagnostic> get_diagnostics();
private:
friend Token;

Loading…
Cancel
Save