diff options
author | Nico Weber <nicolasweber@gmx.de> | 2008-08-10 19:59:06 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2008-08-10 19:59:06 +0000 |
commit | 7bfaaaecb3113f955db31e8d8a51acffd1bc0c27 (patch) | |
tree | bac57d5f77ac6696a51a822a63f513fb92d79a65 /include | |
parent | 3ac5e9fc38e1a59da84844f6adb95e803779098d (diff) |
* Remove isInSystemHeader() from DiagClient, move it to SourceManager
* Move FormatError() from TextDiagnostic up to DiagClient, remove now
empty class TextDiagnostic
* Make DiagClient optional for Diagnostic
This fixes the following problems:
* -html-diags (and probably others) does now output the same set of
warnings as console clang does
* nothing crashes if one forgets to call setHeaderSearch() on
TextDiagnostic
* some code duplication is removed
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54620 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/Basic/Diagnostic.h | 16 | ||||
-rw-r--r-- | include/clang/Basic/SourceLocation.h | 2 | ||||
-rw-r--r-- | include/clang/Basic/SourceManager.h | 30 | ||||
-rw-r--r-- | include/clang/Driver/TextDiagnosticBuffer.h | 6 | ||||
-rw-r--r-- | include/clang/Driver/TextDiagnosticPrinter.h | 4 | ||||
-rw-r--r-- | include/clang/Driver/TextDiagnostics.h | 50 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 3 |
7 files changed, 40 insertions, 71 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index f214091272..c23abdcd0f 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -76,16 +76,17 @@ private: /// CustomDiagInfo - Information for uniquing and looking up custom diags. diag::CustomDiagInfo *CustomDiagInfo; + public: - explicit Diagnostic(DiagnosticClient *client); + explicit Diagnostic(DiagnosticClient *client = 0); ~Diagnostic(); //===--------------------------------------------------------------------===// // Diagnostic characterization methods, used by a client to customize how // - DiagnosticClient &getClient() { return *Client; }; - const DiagnosticClient &getClient() const { return *Client; }; + DiagnosticClient *getClient() { return Client; }; + const DiagnosticClient *getClient() const { return Client; }; void setClient(DiagnosticClient* client) { Client = client; } @@ -181,13 +182,14 @@ public: /// DiagnosticClient - This is an abstract interface implemented by clients of /// the front-end, which formats and prints fully processed diagnostics. class DiagnosticClient { +protected: + std::string FormatDiagnostic(Diagnostic &Diags, Diagnostic::Level Level, + diag::kind ID, + const std::string *Strs, + unsigned NumStrs); public: virtual ~DiagnosticClient(); - /// isInSystemHeader - If the client can tell that this is a system header, - /// return true. - virtual bool isInSystemHeader(FullSourceLoc Pos) const { return false; } - /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or /// capturing it to a log as needed. virtual void HandleDiagnostic(Diagnostic &Diags, diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index 6bc45057d5..145e1c8487 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -246,6 +246,8 @@ public: const char* getSourceName() const; const FileEntry* getFileEntryForLoc() const; + + bool isInSystemHeader() const; bool isFileID() const { return Loc.isFileID(); } diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 7cb1f4c4ba..7cc4087db8 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -112,25 +112,30 @@ namespace SrcMgr { /// ChunkNo - Really large buffers are broken up into chunks that are /// each (1 << SourceLocation::FilePosBits) in size. This specifies the /// chunk number of this FileID. - unsigned ChunkNo; + unsigned ChunkNo:30; + + /// isSystemHeader - Set for system header files. + bool isSysHeader:1; /// Content - Information about the source buffer itself. const ContentCache* Content; - + public: /// get - Return a FileIDInfo object. static FileIDInfo get(SourceLocation IL, unsigned CN, - const ContentCache *Con) { + const ContentCache *Con, bool SysHeader) { FileIDInfo X; X.IncludeLoc = IL; X.ChunkNo = CN; X.Content = Con; + X.isSysHeader = SysHeader; return X; } SourceLocation getIncludeLoc() const { return IncludeLoc; } unsigned getChunkNo() const { return ChunkNo; } const ContentCache* getContentCache() const { return Content; } + bool isSystemHeader() const { return isSysHeader; } /// Emit - Emit this FileIDInfo to Bitcode. void Emit(llvm::Serializer& S) const; @@ -244,10 +249,11 @@ public: /// createFileID - Create a new FileID that represents the specified file /// being #included from the specified IncludePosition. This returns 0 on /// error and translates NULL into standard input. - unsigned createFileID(const FileEntry *SourceFile, SourceLocation IncludePos){ + unsigned createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, + bool isSysHeader = false) { const SrcMgr::ContentCache *IR = getContentCache(SourceFile); if (IR == 0) return 0; // Error opening file? - return createFileID(IR, IncludePos); + return createFileID(IR, IncludePos, isSysHeader); } /// createMainFileID - Create the FileID for the main source file. @@ -262,8 +268,10 @@ public: /// createFileIDForMemBuffer - Create a new FileID that represents the /// specified memory buffer. This does no caching of the buffer and takes /// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once. - unsigned createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) { - return createFileID(createMemBufferContentCache(Buffer), SourceLocation()); + unsigned createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer, + bool isSysHeader = false) { + return createFileID(createMemBufferContentCache(Buffer), SourceLocation(), + isSysHeader); } /// createMainFileIDForMembuffer - Create the FileID for a memory buffer @@ -421,6 +429,12 @@ public: bool isFromMainFile(SourceLocation Loc) const { return getCanonicalFileID(Loc) == getMainFileID(); } + + /// isInSystemHeader - Returns if a SourceLocation is in a system header. + bool isInSystemHeader(SourceLocation Loc) const { + assert (Loc.isFileID() && "method only valid for file ids"); + return getFIDInfo(Loc.getFileID())->isSystemHeader(); + } /// PrintStats - Print statistics to stderr. /// @@ -440,7 +454,7 @@ private: /// include position. This works regardless of whether the ContentCache /// corresponds to a file or some other input source. unsigned createFileID(const SrcMgr::ContentCache* File, - SourceLocation IncludePos); + SourceLocation IncludePos, bool isSysHeader = false); /// getContentCache - Create or return a cached ContentCache for the specified /// file. This returns null on failure. diff --git a/include/clang/Driver/TextDiagnosticBuffer.h b/include/clang/Driver/TextDiagnosticBuffer.h index 99df075fb4..76dfeaf305 100644 --- a/include/clang/Driver/TextDiagnosticBuffer.h +++ b/include/clang/Driver/TextDiagnosticBuffer.h @@ -14,7 +14,7 @@ #ifndef DRIVER_TEXT_DIAGNOSTIC_BUFFER_H_ #define DRIVER_TEXT_DIAGNOSTIC_BUFFER_H_ -#include "clang/Driver/TextDiagnostics.h" +#include "clang/Basic/Diagnostic.h" #include <vector> namespace clang { @@ -22,7 +22,7 @@ namespace clang { class Preprocessor; class SourceManager; -class TextDiagnosticBuffer : public TextDiagnostics { +class TextDiagnosticBuffer : public DiagnosticClient { public: typedef std::vector<std::pair<SourceLocation, std::string> > DiagList; typedef DiagList::iterator iterator; @@ -30,8 +30,6 @@ public: private: DiagList Errors, Warnings; public: - TextDiagnosticBuffer() {} - const_iterator err_begin() const { return Errors.begin(); } const_iterator err_end() const { return Errors.end(); } diff --git a/include/clang/Driver/TextDiagnosticPrinter.h b/include/clang/Driver/TextDiagnosticPrinter.h index 03ac65a247..1d609ced4d 100644 --- a/include/clang/Driver/TextDiagnosticPrinter.h +++ b/include/clang/Driver/TextDiagnosticPrinter.h @@ -15,14 +15,14 @@ #ifndef TEXT_DIAGNOSTIC_PRINTER_H_ #define TEXT_DIAGNOSTIC_PRINTER_H_ -#include "clang/Driver/TextDiagnostics.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" #include "llvm/Support/Streams.h" namespace clang { class SourceManager; -class TextDiagnosticPrinter : public TextDiagnostics { +class TextDiagnosticPrinter : public DiagnosticClient { FullSourceLoc LastWarningLoc; FullSourceLoc LastLoc; llvm::OStream OS; diff --git a/include/clang/Driver/TextDiagnostics.h b/include/clang/Driver/TextDiagnostics.h deleted file mode 100644 index 9b8d9fb27d..0000000000 --- a/include/clang/Driver/TextDiagnostics.h +++ /dev/null @@ -1,50 +0,0 @@ -//===--- TextDiagnostics.h - Text Diagnostics Checkers ----------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This is the parent class for all text diagnostics. -// -//===----------------------------------------------------------------------===// - -#ifndef TEXT_DIAGNOSTICS_H_ -#define TEXT_DIAGNOSTICS_H_ - -#include "clang/Basic/Diagnostic.h" - -namespace clang { -class SourceManager; -class HeaderSearch; -class Preprocessor; - -class TextDiagnostics : public DiagnosticClient { - HeaderSearch *TheHeaderSearch; -protected: - std::string FormatDiagnostic(Diagnostic &Diags, Diagnostic::Level Level, - diag::kind ID, - const std::string *Strs, - unsigned NumStrs); -public: - TextDiagnostics() {} - virtual ~TextDiagnostics(); - - void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; } - - virtual bool isInSystemHeader(FullSourceLoc Pos) const; - - virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel, - FullSourceLoc Pos, - diag::kind ID, - const std::string *Strs, - unsigned NumStrs, - const SourceRange *Ranges, - unsigned NumRanges) = 0; -}; - -} // end namspace clang - -#endif diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 772ce228a4..786af69938 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -469,6 +469,9 @@ private: /// isInPrimaryFile - Return true if we're in the top-level file, not in a /// #include. bool isInPrimaryFile() const; + + /// isSystemHeader - Return true if F is a system header. + bool isSystemHeader(const FileEntry* F) const; /// DiscardUntilEndOfDirective - Read and discard all tokens remaining on the /// current line until the tok::eom token is found. |