summaryrefslogtreecommitdiffstats
path: root/clang/Driver/TextDiagnostics.cpp
blob: 5b14cdda8215fab4495856b0f50db675f8beb231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//===--- TextDiagnostics.cpp - Text Diagnostics Parent Class --------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by Bill Wendling and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is the parent class for all text diagnostics.
//
//===----------------------------------------------------------------------===//

#include "TextDiagnostics.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/HeaderSearch.h"
using namespace clang;

TextDiagnostics:: ~TextDiagnostics() {}

std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags,
                                              Diagnostic::Level Level,
                                              diag::kind ID,
                                              const std::string *Strs,
                                              unsigned NumStrs) {
  std::string Msg = Diags.getDescription(ID);
  
  // Replace all instances of %0 in Msg with 'Extra'.
  for (unsigned i = 0; i < Msg.size() - 1; ++i) {
    if (Msg[i] == '%' && isdigit(Msg[i + 1])) {
      unsigned StrNo = Msg[i + 1] - '0';
      Msg = std::string(Msg.begin(), Msg.begin() + i) +
            (StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
            std::string(Msg.begin() + i + 2, Msg.end());
    }
  }

  return Msg;
}

bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
                                       SourceLocation Pos) {
  if (Pos.isValid()) {
    // If this is a warning or note, and if it a system header, suppress the
    // diagnostic.
    if (Level == Diagnostic::Warning || Level == Diagnostic::Note) {
      if (const FileEntry *F = SourceMgr.getFileEntryForLoc(Pos)) {
        DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
        if (DirInfo == DirectoryLookup::SystemHeaderDir ||
            DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
          return true;
      }
    }
  }

  return false;
}
OpenPOWER on IntegriCloud