|
| 1 | +//===--- DiagnosticHelper.h - Diagnostic Helper -----------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// This file exposes helper class to emit diagnostics from swift-frontend. |
| 14 | +// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#ifndef SWIFT_FRONTEND_DIAGNOSTIC_HELPER_H |
| 18 | +#define SWIFT_FRONTEND_DIAGNOSTIC_HELPER_H |
| 19 | + |
| 20 | +#include "swift/Basic/LLVM.h" |
| 21 | +#include "llvm/Support/raw_ostream.h" |
| 22 | + |
| 23 | +namespace swift { |
| 24 | +class CompilerInstance; |
| 25 | +class CompilerInvocation; |
| 26 | + |
| 27 | +class DiagnosticHelper { |
| 28 | +private: |
| 29 | + class Implementation; |
| 30 | + Implementation &Impl; |
| 31 | + |
| 32 | +public: |
| 33 | + /// Create a DiagnosticHelper class to emit diagnostics from frontend actions. |
| 34 | + /// OS is the stream to print diagnostics. useQuasiPID determines if using |
| 35 | + /// real PID when priting parseable output. |
| 36 | + static DiagnosticHelper create(CompilerInstance &instance, |
| 37 | + llvm::raw_pwrite_stream &OS = llvm::errs(), |
| 38 | + bool useQuasiPID = false); |
| 39 | + |
| 40 | + /// Initialized all DiagConsumers and add to the CompilerInstance. |
| 41 | + void initDiagConsumers(CompilerInvocation &invocation); |
| 42 | + |
| 43 | + /// Begin emitting the message, specifically the parseable output message. |
| 44 | + void beginMessage(CompilerInvocation &invocation, |
| 45 | + ArrayRef<const char *> args); |
| 46 | + |
| 47 | + /// End emitting all diagnostics. This has to be called if beginMessage() is |
| 48 | + /// called. |
| 49 | + void endMessage(int retCode); |
| 50 | + |
| 51 | + /// Set if printing output should be suppressed. |
| 52 | + void setSuppressOutput(bool suppressOutput); |
| 53 | + |
| 54 | + /// Helper function to emit fatal error. |
| 55 | + void diagnoseFatalError(const char *reason, bool shouldCrash); |
| 56 | + |
| 57 | + DiagnosticHelper(const DiagnosticHelper &) = delete; |
| 58 | + DiagnosticHelper(DiagnosticHelper &&) = delete; |
| 59 | + DiagnosticHelper &operator=(const DiagnosticHelper &) = delete; |
| 60 | + DiagnosticHelper &operator=(DiagnosticHelper &&) = delete; |
| 61 | + ~DiagnosticHelper(); |
| 62 | + |
| 63 | +private: |
| 64 | + DiagnosticHelper(CompilerInstance &instance, llvm::raw_pwrite_stream &OS, |
| 65 | + bool useQuasiPID); |
| 66 | +}; |
| 67 | + |
| 68 | +} // namespace swift |
| 69 | + |
| 70 | +#endif |
0 commit comments