Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:55

0001 //===--- LogDiagnosticPrinter.h - Log Diagnostic Client ---------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
0010 #define LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
0011 
0012 #include "clang/Basic/Diagnostic.h"
0013 #include "clang/Basic/SourceLocation.h"
0014 #include "llvm/ADT/SmallVector.h"
0015 #include "llvm/ADT/StringRef.h"
0016 
0017 namespace clang {
0018 class DiagnosticOptions;
0019 class LangOptions;
0020 
0021 class LogDiagnosticPrinter : public DiagnosticConsumer {
0022   struct DiagEntry {
0023     /// The primary message line of the diagnostic.
0024     std::string Message;
0025 
0026     /// The source file name, if available.
0027     std::string Filename;
0028 
0029     /// The source file line number, if available.
0030     unsigned Line;
0031 
0032     /// The source file column number, if available.
0033     unsigned Column;
0034 
0035     /// The ID of the diagnostic.
0036     unsigned DiagnosticID;
0037 
0038     /// The Option Flag for the diagnostic
0039     std::string WarningOption;
0040 
0041     /// The level of the diagnostic.
0042     DiagnosticsEngine::Level DiagnosticLevel;
0043   };
0044 
0045   void EmitDiagEntry(llvm::raw_ostream &OS,
0046                      const LogDiagnosticPrinter::DiagEntry &DE);
0047 
0048   // Conditional ownership (when StreamOwner is non-null, it's keeping OS
0049   // alive). We might want to replace this with a wrapper for conditional
0050   // ownership eventually - it seems to pop up often enough.
0051   raw_ostream &OS;
0052   std::unique_ptr<raw_ostream> StreamOwner;
0053   const LangOptions *LangOpts;
0054   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
0055 
0056   SourceLocation LastWarningLoc;
0057   FullSourceLoc LastLoc;
0058 
0059   SmallVector<DiagEntry, 8> Entries;
0060 
0061   std::string MainFilename;
0062   std::string DwarfDebugFlags;
0063 
0064 public:
0065   LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags,
0066                        std::unique_ptr<raw_ostream> StreamOwner);
0067 
0068   void setDwarfDebugFlags(StringRef Value) {
0069     DwarfDebugFlags = std::string(Value);
0070   }
0071 
0072   void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override {
0073     LangOpts = &LO;
0074   }
0075 
0076   void EndSourceFile() override;
0077 
0078   void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
0079                         const Diagnostic &Info) override;
0080 };
0081 
0082 } // end namespace clang
0083 
0084 #endif