diff options
46 files changed, 159 insertions, 224 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index a23447197b..c0d191e565 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -18,6 +18,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/VersionTuple.h" #include "clang/AST/Decl.h" #include "clang/AST/NestedNameSpecifier.h" @@ -48,7 +49,6 @@ namespace clang { class ExternalASTSource; class ASTMutationListener; class IdentifierTable; - class PartialDiagnosticStorageAllocator; class SelectorTable; class SourceManager; class TargetInfo; @@ -346,7 +346,7 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> { mutable llvm::BumpPtrAllocator BumpAlloc; /// \brief Allocator for partial diagnostics. - PartialDiagnosticStorageAllocator *DiagAllocator; + PartialDiagnostic::StorageAllocator DiagAllocator; /// \brief The current C++ ABI. OwningPtr<CXXABI> ABI; @@ -391,8 +391,8 @@ public: /// Return the total memory used for various side tables. size_t getSideTableAllocatedMemory() const; - PartialDiagnosticStorageAllocator &getDiagAllocator() { - return *DiagAllocator; + PartialDiagnostic::StorageAllocator &getDiagAllocator() { + return DiagAllocator; } const TargetInfo &getTargetInfo() const { return *Target; } diff --git a/include/clang/AST/CanonicalType.h b/include/clang/AST/CanonicalType.h index 5b27b4e1fa..38e6b41977 100644 --- a/include/clang/AST/CanonicalType.h +++ b/include/clang/AST/CanonicalType.h @@ -200,7 +200,11 @@ inline CanQualType Type::getCanonicalTypeUnqualified() const { return CanQualType::CreateUnsafe(getCanonicalTypeInternal()); } -const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, CanQualType T); +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + CanQualType T) { + DB << static_cast<QualType>(T); + return DB; +} //----------------------------------------------------------------------------// // Internal proxy classes used by canonical types diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 37c962357d..24d2d85385 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -41,11 +41,7 @@ class TypeLoc; class UnresolvedSetImpl; class LabelStmt; class Module; - -// Forward declare PartialDiagnosticAt. -// FIXME: This shouldn't be here. -typedef std::pair<SourceLocation, PartialDiagnostic> PartialDiagnosticAt; - + /// \brief A container of type source information. /// /// A client can read the relevant info using TypeLoc wrappers, e.g: @@ -3179,11 +3175,18 @@ public: /// Insertion operator for diagnostics. This allows sending NamedDecl's /// into a diagnostic with <<. -const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, - const NamedDecl* ND); - -const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, - const NamedDecl* ND); +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + const NamedDecl* ND) { + DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), + DiagnosticsEngine::ak_nameddecl); + return DB; +} +inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, + const NamedDecl* ND) { + PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND), + DiagnosticsEngine::ak_nameddecl); + return PD; +} template<typename decl_type> void Redeclarable<decl_type>::setPreviousDeclaration(decl_type *PrevDecl) { diff --git a/include/clang/AST/DeclarationName.h b/include/clang/AST/DeclarationName.h index 0d87e2671c..2170f2b1ef 100644 --- a/include/clang/AST/DeclarationName.h +++ b/include/clang/AST/DeclarationName.h @@ -16,6 +16,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/AST/Type.h" #include "clang/AST/CanonicalType.h" +#include "clang/Basic/PartialDiagnostic.h" namespace llvm { template <typename T> struct DenseMapInfo; @@ -516,16 +517,24 @@ public: /// Insertion operator for diagnostics. This allows sending DeclarationName's /// into a diagnostic with <<. -const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, - DeclarationName N); +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + DeclarationName N) { + DB.AddTaggedVal(N.getAsOpaqueInteger(), + DiagnosticsEngine::ak_declarationname); + return DB; +} /// Insertion operator for partial diagnostics. This allows binding /// DeclarationName's into a partial diagnostic with <<. -const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, - DeclarationName N); +inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, + DeclarationName N) { + PD.AddTaggedVal(N.getAsOpaqueInteger(), + DiagnosticsEngine::ak_declarationname); + return PD; +} inline raw_ostream &operator<<(raw_ostream &OS, - DeclarationNameInfo DNInfo) { + DeclarationNameInfo DNInfo) { DNInfo.printName(OS); return OS; } diff --git a/include/clang/AST/Mangle.h b/include/clang/AST/Mangle.h index ed392ab6b6..ca22ed6a0d 100644 --- a/include/clang/AST/Mangle.h +++ b/include/clang/AST/Mangle.h @@ -27,8 +27,6 @@ namespace clang { class CXXConstructorDecl; class CXXDestructorDecl; class CXXMethodDecl; - class DeclContext; - class DiagnosticsEngine; class FunctionDecl; class NamedDecl; class ObjCMethodDecl; diff --git a/include/clang/AST/NestedNameSpecifier.h b/include/clang/AST/NestedNameSpecifier.h index 8d4a53f23e..bda2d31fd5 100644 --- a/include/clang/AST/NestedNameSpecifier.h +++ b/include/clang/AST/NestedNameSpecifier.h @@ -14,14 +14,13 @@ #ifndef LLVM_CLANG_AST_NESTEDNAMESPECIFIER_H #define LLVM_CLANG_AST_NESTEDNAMESPECIFIER_H -#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/Diagnostic.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/PointerIntPair.h" namespace clang { class ASTContext; -class DiagnosticBuilder; class NamespaceAliasDecl; class NamespaceDecl; class IdentifierInfo; @@ -465,8 +464,12 @@ public: /// Insertion operator for diagnostics. This allows sending /// NestedNameSpecifiers into a diagnostic with <<. -const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, - NestedNameSpecifier *NNS); +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + NestedNameSpecifier *NNS) { + DB.AddTaggedVal(reinterpret_cast<intptr_t>(NNS), + DiagnosticsEngine::ak_nestednamespec); + return DB; +} } diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index b989d55500..641f732c59 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -14,9 +14,11 @@ #ifndef LLVM_CLANG_AST_TYPE_H #define LLVM_CLANG_AST_TYPE_H +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/Linkage.h" +#include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/Visibility.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/TemplateName.h" @@ -92,7 +94,6 @@ namespace clang { class ExtQuals; class ExtQualsTypeCommonBase; struct PrintingPolicy; - class PartialDiagnostic; template <typename> class CanQual; typedef CanQual<Type> CanQualType; @@ -4801,11 +4802,21 @@ inline const Type *Type::getBaseElementTypeUnsafe() const { /// Insertion operator for diagnostics. This allows sending QualType's into a /// diagnostic with <<. -const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, QualType T); +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + QualType T) { + DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), + DiagnosticsEngine::ak_qualtype); + return DB; +} /// Insertion operator for partial diagnostics. This allows sending QualType's /// into a diagnostic with <<. -const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, QualType T); +inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, + QualType T) { + PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), + DiagnosticsEngine::ak_qualtype); + return PD; +} // Helper class template that is used by Type::getAs to ensure that one does // not try to look through a qualified type to get to an array type. diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index b9815125c3..224f1a45d1 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -601,7 +601,6 @@ private: friend class DiagnosticBuilder; friend class Diagnostic; friend class PartialDiagnostic; - friend struct PartialDiagnosticStorage; friend class DiagnosticErrorTrap; /// CurDiagLoc - This is the location of the current diagnostic that is in diff --git a/include/clang/Basic/PartialDiagnostic.h b/include/clang/Basic/PartialDiagnostic.h index 7bc9f54655..f6092e6858 100644 --- a/include/clang/Basic/PartialDiagnostic.h +++ b/include/clang/Basic/PartialDiagnostic.h @@ -23,87 +23,91 @@ namespace clang { -struct PartialDiagnosticStorage { - PartialDiagnosticStorage() : NumDiagArgs(0), NumDiagRanges(0) { } - +class PartialDiagnostic { +public: enum { - /// MaxArguments - The maximum number of arguments we can hold. We - /// currently only support up to 10 arguments (%0-%9). - /// A single diagnostic with more than that almost certainly has to - /// be simplified anyway. + // The MaxArguments and MaxFixItHints member enum values from + // DiagnosticsEngine are private but DiagnosticsEngine declares + // PartialDiagnostic a friend. These enum values are redeclared + // here so that the nested Storage class below can access them. MaxArguments = DiagnosticsEngine::MaxArguments }; - /// NumDiagArgs - This contains the number of entries in Arguments. - unsigned char NumDiagArgs; - - /// NumDiagRanges - This is the number of ranges in the DiagRanges array. - unsigned char NumDiagRanges; - - /// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum - /// values, with one for each argument. This specifies whether the argument - /// is in DiagArgumentsStr or in DiagArguments. - unsigned char DiagArgumentsKind[MaxArguments]; - - /// DiagArgumentsVal - The values for the various substitution positions. - /// This is used when the argument is not an std::string. The specific value - /// is mangled into an intptr_t and the interpretation depends on exactly - /// what sort of argument kind it is. - intptr_t DiagArgumentsVal[MaxArguments]; - - /// \brief The values for the various substitution positions that have - /// string arguments. - std::string DiagArgumentsStr[MaxArguments]; - - /// DiagRanges - The list of ranges added to this diagnostic. It currently - /// only support 10 ranges, could easily be extended if needed. - CharSourceRange DiagRanges[10]; - - /// FixItHints - If valid, provides a hint with some code - /// to insert, remove, or modify at a particular position. - SmallVector<FixItHint, 6> FixItHints; -}; - -/// \brief An allocator for Storage objects, which uses a small cache to -/// objects, used to reduce malloc()/free() traffic for partial diagnostics. -class PartialDiagnosticStorageAllocator { - static const unsigned NumCached = 16; - typedef PartialDiagnosticStorage Storage; - Storage Cached[NumCached]; - Storage *FreeList[NumCached]; - unsigned NumFreeListEntries; - -public: - PartialDiagnosticStorageAllocator(); - ~PartialDiagnosticStorageAllocator(); - - /// \brief Allocate new storage. - Storage *Allocate() { - if (NumFreeListEntries == 0) - return new Storage; - - Storage *Result = FreeList[--NumFreeListEntries]; - Result->NumDiagArgs = 0; - Result->NumDiagRanges = 0; - Result->FixItHints.clear(); - return Result; - } + struct Storage { + Storage() : NumDiagArgs(0), NumDiagRanges(0) { } + + enum { + /// MaxArguments - The maximum number of arguments we can hold. We + /// currently only support up to 10 arguments (%0-%9). + /// A single diagnostic with more than that almost certainly has to + /// be simplified anyway. + MaxArguments = PartialDiagnostic::MaxArguments + }; + + /// NumDiagArgs - This contains the number of entries in Arguments. + unsigned char NumDiagArgs; + + /// NumDiagRanges - This is the number of ranges in the DiagRanges array. + unsigned char NumDiagRanges; + + /// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum + /// values, with one for each argument. This specifies whether the argument + /// is in DiagArgumentsStr or in DiagArguments. + unsigned char DiagArgumentsKind[MaxArguments]; + + /// DiagArgumentsVal - The values for the various substitution positions. + /// This is used when the argument is not an std::string. The specific value + /// is mangled into an intptr_t and the interpretation depends on exactly + /// what sort of argument kind it is. + intptr_t DiagArgumentsVal[MaxArguments]; + + /// \brief The values for the various substitution positions that have + /// string arguments. + std::string DiagArgumentsStr[MaxArguments]; + + /// DiagRanges - The list of ranges added to this diagnostic. It currently + /// only support 10 ranges, could easily be extended if needed. + CharSourceRange DiagRanges[10]; + + /// FixItHints - If valid, provides a hint with some code + /// to insert, remove, or modify at a particular position. + SmallVector<FixItHint, 6> FixItHints; + }; - /// \brief Free the given storage object. - void Deallocate(Storage *S) { - if (S >= Cached && S <= Cached + NumCached) { - FreeList[NumFreeListEntries++] = S; - return; + /// \brief An allocator for Storage objects, which uses a small cache to + /// objects, used to reduce malloc()/free() traffic for partial diagnostics. + class StorageAllocator { + static const unsigned NumCached = 16; + Storage Cached[NumCached]; + Storage *FreeList[NumCached]; + unsigned NumFreeListEntries; + + public: + StorageAllocator(); + ~StorageAllocator(); + + /// \brief Allocate new storage. + Storage *Allocate() { + if (NumFreeListEntries == 0) + return new Storage; + + Storage *Result = FreeList[--NumFreeListEntries]; + Result->NumDiagArgs = 0; + Result->NumDiagRanges = 0; + Result->FixItHints.clear(); + return Result; } - delete S; - } -}; + /// \brief Free the given storage object. + void Deallocate(Storage *S) { + if (S >= Cached && S <= Cached + NumCached) { + FreeList[NumFreeListEntries++] = S; + return; + } -class PartialDiagnostic { -public: - typedef PartialDiagnosticStorage Storage; - typedef PartialDiagnosticStorageAllocator StorageAllocator; + delete S; + } + }; private: // NOTE: Sema assumes that PartialDiagnostic is location-invariant diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 987d6167c6..19e8521ea1 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -16,6 +16,7 @@ #include "clang/Lex/DirectoryLookup.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Basic/DiagnosticIDs.h" #include "llvm/ADT/StringRef.h" #include <string> @@ -157,10 +158,9 @@ public: } /// PragmaDiagnostic - This callback is invoked when a - /// #pragma gcc diagnostic directive is read. - /// Mapping is an element of the diag::Mapping enum. + /// #pragma gcc dianostic directive is read. virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, - unsigned mapping, StringRef Str) { + diag::Mapping mapping, StringRef Str) { } /// MacroExpands - This is called by @@ -303,7 +303,7 @@ public: } virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, - unsigned mapping, StringRef Str) { + diag::Mapping mapping, StringRef Str) { First->PragmaDiagnostic(Loc, Namespace, mapping, Str); Second->PragmaDiagnostic(Loc, Namespace, mapping, Str); } diff --git a/include/clang/Lex/PTHManager.h b/include/clang/Lex/PTHManager.h index 6ae3a7167e..25a49038a8 100644 --- a/include/clang/Lex/PTHManager.h +++ b/include/clang/Lex/PTHManager.h @@ -17,6 +17,7 @@ #include "clang/Lex/PTHLexer.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/Diagnostic.h" #include "llvm/ADT/DenseMap.h" #include "llvm/Support/Allocator.h" #include <string> diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 77dc2348a5..9c3b64abb0 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -21,6 +21,7 @@ #include "clang/Lex/TokenLexer.h" #include "clang/Lex/PTHManager.h" #include "clang/Basic/Builtins.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/DenseMap.h" @@ -60,7 +61,7 @@ class ModuleLoader; /// like the #include stack, token expansion, etc. /// class Preprocessor : public llvm::RefCountedBase<Preprocessor> { - DiagnosticsEngine *Diags; + DiagnosticsEngine *Diags; LangOptions &Features; const TargetInfo *Target; FileManager &FileMgr; @@ -728,7 +729,12 @@ public: bool isCodeCompletionReached() const { return CodeCompletionReached; } /// \brief Note that we hit the code-completion point. - void setCodeCompletionReached(); + void setCodeCompletionReached() { + assert(isCodeCompletionEnabled() && "Code-completion not enabled!"); + CodeCompletionReached = true; + // Silence any diagnostics that occur after we hit the code-completion. + getDiagnostics().setSuppressAllDiagnostics(true); + } /// \brief The location of the currently-active #pragma clang /// arc_cf_code_audited begin. Returns an invalid location if there @@ -758,9 +764,13 @@ public: /// Diag - Forwarding function for diagnostics. This emits a diagnostic at /// the specified Token's location, translating the token's start /// position in the current buffer into a SourcePosition object for rendering. - DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const; + DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const { + return Diags->Report(Loc, DiagID); + } - DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const; + DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const { + return Diags->Report(Tok.getLocation(), DiagID); + } /// getSpelling() - Return the 'spelling' of the token at the given /// location; does not go up to the spelling location or down to the diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 832c47d6af..c77b68f9da 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -24,7 +24,6 @@ namespace clang { class Decl; -class Preprocessor; /// \brief Default priority values for code-completion results based /// on their kind. diff --git a/include/clang/Sema/DelayedDiagnostic.h b/include/clang/Sema/DelayedDiagnostic.h index 235f634385..dd2603dbc3 100644 --- a/include/clang/Sema/DelayedDiagnostic.h +++ b/include/clang/Sema/DelayedDiagnostic.h @@ -22,7 +22,6 @@ #define LLVM_CLANG_SEMA_DELAYED_DIAGNOSTIC_H #include "clang/AST/DeclCXX.h" -#include "clang/Basic/PartialDiagnostic.h" namespace clang { namespace sema { diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index e7a1864030..e7441ada13 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -30,7 +30,6 @@ #include "clang/AST/ExternalASTSource.h" #include "clang/AST/TypeLoc.h" #include "clang/Lex/ModuleLoader.h" -#include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/TemplateKinds.h" #include "clang/Basic/TypeTraits.h" diff --git a/include/clang/Sema/SemaFixItUtils.h b/include/clang/Sema/SemaFixItUtils.h index 84e03d8242..fffca67914 100644 --- a/include/clang/Sema/SemaFixItUtils.h +++ b/include/clang/Sema/SemaFixItUtils.h @@ -14,7 +14,6 @@ #define LLVM_CLANG_SEMA_FIXITUTILS_H #include "clang/AST/Expr.h" -#include "clang/Basic/Diagnostic.h" namespace clang { diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index e36f3a00a6..f6a2c4817a 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -43,7 +43,6 @@ class ASTContext; class NestedNameSpecifier; class CXXBaseSpecifier; class CXXCtorInitializer; -class DiagnosticsEngine; class FPOptions; class HeaderSearch; class IdentifierResolver; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 416045e234..069f1068da 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -24,7 +24,6 @@ #include "clang/AST/RecordLayout.h" #include "clang/AST/Mangle.h" #include "clang/Basic/Builtins.h" -#include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/SmallString.h" @@ -242,9 +241,6 @@ ASTContext::ASTContext(LangOptions& LOpts, SourceManager &SM, LastSDM(0, 0), UniqueBlockByRefTypeID(0) { - // Create a new allocator for partial diagnostics. - DiagAllocator = new (BumpAlloc) PartialDiagnosticStorageAllocator; - if (size_reserve > 0) Types.reserve(size_reserve); TUDecl = TranslationUnitDecl::Create(*this); @@ -289,9 +285,6 @@ ASTContext::~ASTContext() { AEnd = DeclAttrs.end(); A != AEnd; ++ |