You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB

#include "Diagnostic.h"
11 years ago
#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) {
11 years ago
case CXDiagnostic_Ignored:
return "Ignored";
11 years ago
case CXDiagnostic_Note:
return "Note";
11 years ago
case CXDiagnostic_Warning:
return "Warning";
11 years ago
case CXDiagnostic_Error:
return "Error";
11 years ago
case CXDiagnostic_Fatal:
return "Fatal";
default:
return "";
}
}