Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/DiagnosticHandler.h
Line
Count
Source
1
//===- DiagnosticHandler.h - DiagnosticHandler class for LLVM ---*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
// Base DiagnosticHandler class declaration. Derive from this class to provide
9
// custom diagnostic reporting.
10
//===----------------------------------------------------------------------===//
11
12
#ifndef LLVM_IR_DIAGNOSTICHANDLER_H
13
#define LLVM_IR_DIAGNOSTICHANDLER_H
14
15
#include "llvm/ADT/StringRef.h"
16
17
namespace llvm {
18
class DiagnosticInfo;
19
20
/// This is the base class for diagnostic handling in LLVM.
21
/// The handleDiagnostics method must be overriden by the subclasses to handle
22
/// diagnostic. The *RemarkEnabled methods can be overriden to control
23
/// which remarks are enabled.
24
struct DiagnosticHandler {
25
  void *DiagnosticContext = nullptr;
26
  DiagnosticHandler(void *DiagContext = nullptr)
27
154k
      : DiagnosticContext(DiagContext) {}
28
141k
  virtual ~DiagnosticHandler() = default;
29
30
  using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
31
32
  /// DiagHandlerCallback is settable from the C API and base implementation
33
  /// of DiagnosticHandler will call it from handleDiagnostics(). Any derived
34
  /// class of DiagnosticHandler should not use callback but
35
  /// implement handleDiagnostics().
36
  DiagnosticHandlerTy DiagHandlerCallback = nullptr;
37
38
  /// Override handleDiagnostics to provide custom implementation.
39
  /// Return true if it handles diagnostics reporting properly otherwise
40
  /// return false to make LLVMContext::diagnose() to print the message
41
  /// with a prefix based on the severity.
42
340k
  virtual bool handleDiagnostics(const DiagnosticInfo &DI) {
43
340k
    if (DiagHandlerCallback) {
44
4
      DiagHandlerCallback(DI, DiagnosticContext);
45
4
      return true;
46
4
    }
47
340k
    return false;
48
340k
  }
49
50
  /// Return true if analysis remarks are enabled, override
51
  /// to provide different implementation.
52
  virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
53
54
  /// Return true if missed optimization remarks are enabled, override
55
  /// to provide different implementation.
56
  virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
57
58
  /// Return true if passed optimization remarks are enabled, override
59
  /// to provide different implementation.
60
  virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
61
62
  /// Return true if any type of remarks are enabled for this pass.
63
4.21M
  bool isAnyRemarkEnabled(StringRef PassName) const {
64
4.21M
    return (isMissedOptRemarkEnabled(PassName) ||
65
4.21M
            
isPassedOptRemarkEnabled(PassName)4.21M
||
66
4.21M
            
isAnalysisRemarkEnabled(PassName)4.21M
);
67
4.21M
  }
68
69
  /// Return true if any type of remarks are enabled for any pass.
70
  virtual bool isAnyRemarkEnabled() const;
71
};
72
} // namespace llvm
73
74
#endif // LLVM_IR_DIAGNOSTICHANDLER_H