Vuo  2.1.2
VuoCompilerDiagnosticConsumer.cc
Go to the documentation of this file.
1 
11 
12 #include "VuoCompilerIssue.hh"
13 
14 #ifndef DOXYGEN
15 // Workaround for "Undefined symbols… typeinfo for clang::DiagnosticConsumer".
16 clang::DiagnosticConsumer::~DiagnosticConsumer() {}
17 #endif
18 
23  : issues(issues)
24 {
25 }
26 
32 void VuoCompilerDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level level, const clang::Diagnostic &diagnostic)
33 {
35  const char *levelName;
36  if (level == clang::DiagnosticsEngine::Note)
37  levelName = "note";
38  else if (level == clang::DiagnosticsEngine::Warning)
39  levelName = "warning";
40  else if (level == clang::DiagnosticsEngine::Error
41  || level == clang::DiagnosticsEngine::Fatal)
42  {
43  issueType = VuoCompilerIssue::Error;
44  levelName = "error";
45  }
46  else
47  return;
48 
49  llvm::SmallString<64> location;
50  if (diagnostic.hasSourceManager() && diagnostic.getLocation().isValid())
51  {
52  auto &sourceManager = diagnostic.getSourceManager();
53  auto loc = sourceManager.getFileLoc(diagnostic.getLocation());
54 
55  auto filename = sourceManager.getFilename(loc);
56 
57  // Not our code.
58  if (filename.find("/Vuo.framework/Frameworks/llvm.framework/") != llvm::StringRef::npos
59  || filename.find("/Vuo.framework/Headers/macos/") != llvm::StringRef::npos
60  || filename.find("/.conan/data/") != llvm::StringRef::npos
61  || filename.find("/Applications/Xcode.app/") != llvm::StringRef::npos)
62  return;
63 
64  llvm::raw_svector_ostream oss(location);
65  loc.print(oss, sourceManager);
66  }
67 
68  llvm::SmallString<64> message;
69  diagnostic.FormatDiagnostic(message);
70 
71  VUserLog("%s: %s: %s", levelName, location.c_str(), message.c_str());
72  issues->append(VuoCompilerIssue(issueType, "compiling module", location.str(), "", message.str()));
73 }