diff --git a/src/Diagnostic.cc b/src/Diagnostic.cc index e0d5ec9..2167181 100644 --- a/src/Diagnostic.cc +++ b/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 ""; diff --git a/src/Diagnostic.h b/src/Diagnostic.h index ce4cf28..9ac3b2f 100644 --- a/src/Diagnostic.h +++ b/src/Diagnostic.h @@ -1,6 +1,9 @@ #ifndef DIAGNOSTIC_H_ #define DIAGNOSTIC_H_ #include +#include +#include +#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; diff --git a/src/SourceRange.cc b/src/SourceRange.cc index d6edc89..87581d4 100644 --- a/src/SourceRange.cc +++ b/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_); } diff --git a/src/SourceRange.h b/src/SourceRange.h index 8cc9afe..d1f772b 100644 --- a/src/SourceRange.h +++ b/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_ diff --git a/src/Tokens.h b/src/Tokens.h index 344b0a0..254b74c 100644 --- a/src/Tokens.h +++ b/src/Tokens.h @@ -10,7 +10,7 @@ namespace clang { Tokens(TranslationUnit *tu, SourceRange *range); ~Tokens(); std::vector& tokens(); - protected: + private: std::vector tks; CXToken *tokens_; unsigned num_tokens_; diff --git a/src/TranslationUnit.cc b/src/TranslationUnit.cc index 63d52e0..e9cac42 100644 --- a/src/TranslationUnit.cc +++ b/src/TranslationUnit.cc @@ -94,32 +94,7 @@ std::vector clang::TranslationUnit::get_diagnostics() { std::vector diagnostics; for(unsigned c=0;c get_diagnostics(); + std::vector get_diagnostics(); private: friend Token;