diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-28 06:00:51 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-28 06:00:51 +0000 |
commit | d93256e55673a17d18543397ec462416acb13792 (patch) | |
tree | 5b150fa660dcb777d022715e66051091d9bb9ffa /include/clang/Basic | |
parent | a8d8fec7876666d90bb2a144d3b832b2d89a088a (diff) |
Introduce serialization and deserialization of diagnostic information
so that CIndex can report diagnostics through the normal mechanisms
even when executing Clang in a separate process. This applies both
when performing code completion and when using ASTs as an intermediary
for clang_createTranslationUnitFromSourceFile().
The serialized format is not perfect at the moment, because it does
not encapsulate macro-instantiation information. Instead, it maps all
source locations back to the instantiation location. However, it does
maintain source-range and fix-it information. To get perfect fidelity
from the serialized format would require serializing a large chunk of
the source manager; at present, it isn't clear if this code will live
long enough for that to matter.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94740 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic')
-rw-r--r-- | include/clang/Basic/Diagnostic.h | 19 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticFrontendKinds.td | 2 | ||||
-rw-r--r-- | include/clang/Basic/SourceManager.h | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index c5d6d7c713..1f7cd07c60 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -23,16 +23,19 @@ namespace llvm { template <typename T> class SmallVectorImpl; + class raw_ostream; } namespace clang { class DeclContext; class DiagnosticBuilder; class DiagnosticClient; + class FileManager; class IdentifierInfo; class LangOptions; class PartialDiagnostic; class Preprocessor; + class SourceManager; class SourceRange; // Import the diagnostic enums themselves. @@ -400,6 +403,13 @@ public: /// \brief Clear out the current diagnostic. void Clear() { CurDiagID = ~0U; } + /// Deserialize - Deserialize the first diagnostic within the memory + /// [Memory, MemoryEnd), producing a new diagnostic builder describing the + /// deserialized diagnostic. If the memory does not contain a + /// diagnostic, returns a diagnostic builder with no diagnostic ID. + DiagnosticBuilder Deserialize(FileManager &FM, SourceManager &SM, + const char *&Memory, const char *MemoryEnd); + private: /// getDiagnosticMappingInfo - Return the mapping info currently set for the /// specified builtin diagnostic. This returns the high bit encoding, or zero @@ -568,6 +578,9 @@ public: /// been emitted. ~DiagnosticBuilder() { Emit(); } + /// isActive - Determine whether this diagnostic is still active. + bool isActive() const { return DiagObj != 0; } + /// Operator bool: conversion of DiagnosticBuilder to bool always returns /// true. This allows is to be used in boolean error contexts like: /// return Diag(...); @@ -786,6 +799,12 @@ public: /// output buffer using the arguments stored in this diagnostic. void FormatDiagnostic(const char *DiagStr, const char *DiagEnd, llvm::SmallVectorImpl<char> &OutStr) const; + + /// Serialize - Serialize the given diagnostic (with its diagnostic + /// level) to the given stream. Serialization is a lossy operation, + /// since the specific diagnostic ID and any macro-instantiation + /// information is lost. + void Serialize(Diagnostic::Level DiagLevel, llvm::raw_ostream &OS) const; }; /// DiagnosticClient - This is an abstract interface implemented by clients of diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td index 59287b3def..01104fc543 100644 --- a/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/include/clang/Basic/DiagnosticFrontendKinds.td @@ -19,6 +19,8 @@ def err_fe_invalid_code_complete_file : Error< "cannot locate code-completion file %0">, DefaultFatal; def err_fe_stdout_binary : Error<"unable to change standard output to binary">, DefaultFatal; +def err_fe_stderr_binary : Error<"unable to change standard error to binary">, + DefaultFatal; def err_fe_dependency_file_requires_MT : Error< "-dependency-file requires at least one -MT option">; def err_fe_incompatible_options : Error< diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 59984e7ee8..15ece68510 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -669,6 +669,9 @@ public: ::const_iterator fileinfo_iterator; fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); } fileinfo_iterator fileinfo_end() const { return FileInfos.end(); } + bool hasFileInfo(const FileEntry *File) const { + return FileInfos.find(File) != FileInfos.end(); + } /// PrintStats - Print statistics to stderr. /// |