Vuo  2.3.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  // Ignore warnings in other people's code.
58  if ((level == clang::DiagnosticsEngine::Note || level == clang::DiagnosticsEngine::Warning)
59  && (filename.find("/Vuo.framework/Frameworks/llvm.framework/") != llvm::StringRef::npos
60  || filename.find("/Vuo.framework/Headers/macos/") != llvm::StringRef::npos
61  || filename.find("/.conan/data/") != llvm::StringRef::npos
62  || filename.find("/Applications/Xcode.app/") != llvm::StringRef::npos))
63  return;
64 
65  llvm::raw_svector_ostream oss(location);
66  loc.print(oss, sourceManager);
67  }
68 
69  llvm::SmallString<64> message;
70  diagnostic.FormatDiagnostic(message);
71 
72  VUserLog("%s: %s: %s", levelName, location.c_str(), message.c_str());
73  issues->append(VuoCompilerIssue(issueType, "compiling module", location.str(), "", message.str()));
74 }