TextDiagnostics.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===--- TextDiagnostics.cpp - Text Diagnostics Parent Class --------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file was developed by Bill Wendling and is distributed under the
  6. // University of Illinois Open Source License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This is the parent class for all text diagnostics.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "TextDiagnostics.h"
  14. #include "clang/Basic/SourceLocation.h"
  15. #include "clang/Basic/SourceManager.h"
  16. #include "clang/Lex/HeaderSearch.h"
  17. using namespace clang;
  18. TextDiagnostics:: ~TextDiagnostics() {}
  19. std::string TextDiagnostics::FormatDiagnostic(Diagnostic::Level Level,
  20. diag::kind ID,
  21. const std::string *Strs,
  22. unsigned NumStrs) {
  23. std::string Msg = Diagnostic::getDescription(ID);
  24. // Replace all instances of %0 in Msg with 'Extra'.
  25. for (unsigned i = 0; i < Msg.size() - 1; ++i) {
  26. if (Msg[i] == '%' && isdigit(Msg[i + 1])) {
  27. unsigned StrNo = Msg[i + 1] - '0';
  28. Msg = std::string(Msg.begin(), Msg.begin() + i) +
  29. (StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
  30. std::string(Msg.begin() + i + 2, Msg.end());
  31. }
  32. }
  33. return Msg;
  34. }
  35. bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
  36. SourceLocation Pos) {
  37. if (Pos.isValid()) {
  38. // If this is a warning or note, and if it a system header, suppress the
  39. // diagnostic.
  40. if (Level == Diagnostic::Warning ||
  41. Level == Diagnostic::Note) {
  42. SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Pos);
  43. const FileEntry *F = SourceMgr.getFileEntryForFileID(PhysLoc.getFileID());
  44. if (F) {
  45. DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
  46. if (DirInfo == DirectoryLookup::SystemHeaderDir ||
  47. DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
  48. return true;
  49. }
  50. }
  51. }
  52. return false;
  53. }