Files
Sourcetrail/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp
T
Eberhard Graether 149a305761 logic: Fixed error view related issues
* polished color schemes for error view
* fixed error id column not hidden
* fixed error count shown correctly in each view
* moved storage stats logging to application
* fixed indexed flag of errors broken for indexed headers in cdb project
* fixed scrolling to active error when errors where not visible before
* reverted tictactoe files to no errors
2016-10-13 14:21:22 +02:00

92 lines
2.1 KiB
C++

#include "data/parser/cxx/CxxDiagnosticConsumer.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Tooling/Tooling.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParserClient.h"
#include "utility/file/FileRegister.h"
CxxDiagnosticConsumer::CxxDiagnosticConsumer(
clang::raw_ostream &os,
clang::DiagnosticOptions *diags,
ParserClient* client,
FileRegister* fileRegister,
bool useLogging
)
: clang::TextDiagnosticPrinter(os, diags)
, m_client(client)
, m_register(fileRegister)
, m_isParsingFile(false)
, m_useLogging(useLogging)
{
}
void CxxDiagnosticConsumer::BeginSourceFile(const clang::LangOptions& langOptions, const clang::Preprocessor* preProcessor)
{
if (m_useLogging)
{
clang::TextDiagnosticPrinter::BeginSourceFile(langOptions, preProcessor);
}
m_isParsingFile = true;
}
void CxxDiagnosticConsumer::EndSourceFile()
{
if (m_useLogging)
{
clang::TextDiagnosticPrinter::EndSourceFile();
}
m_isParsingFile = false;
}
void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level level, const clang::Diagnostic& info)
{
if (m_useLogging)
{
clang::TextDiagnosticPrinter::HandleDiagnostic(level, info);
}
if (!m_isParsingFile)
{
return;
}
if (level >= clang::DiagnosticsEngine::Error)
{
llvm::SmallString<100> messageStr;
info.FormatDiagnostic(messageStr);
std::string message = messageStr.str();
if (message == "MS-style inline assembly is not available: Unable to find target for this triple (no targets are registered)")
{
return;
}
std::string filePath;
uint line = 0;
uint column = 0;
if (info.getLocation().isValid() && info.hasSourceManager())
{
const clang::SourceManager& sourceManager = info.getSourceManager();
clang::PresumedLoc presumedLocation = sourceManager.getPresumedLoc(info.getLocation());
filePath = clang::tooling::getAbsolutePath(presumedLocation.getFilename());
line = presumedLocation.getLine();
column = presumedLocation.getColumn();
}
ParseLocation location(filePath, line, column);
m_client->onError(
location,
message,
level == clang::DiagnosticsEngine::Fatal,
m_register->hasFilePath(location.filePath)
);
}
}