From 0ad106fec9dd188e20026c80d814f836e15780e3 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 26 Aug 2010 00:52:50 +0000 Subject: [PATCH] Revert r112114, "Pull DelayedDiagnostic and AccessedEntity out into their own header.", it is teh broken. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112123 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/DelayedDiagnostic.h | 168 ------------------------- include/clang/Sema/Sema.h | 142 ++++++++++++++++++++- include/clang/Sema/SemaInternal.h | 9 -- lib/Sema/Sema.cpp | 4 +- lib/Sema/SemaAccess.cpp | 10 +- lib/Sema/SemaDeclAttr.cpp | 4 +- 6 files changed, 144 insertions(+), 193 deletions(-) delete mode 100644 include/clang/Sema/DelayedDiagnostic.h diff --git a/include/clang/Sema/DelayedDiagnostic.h b/include/clang/Sema/DelayedDiagnostic.h deleted file mode 100644 index 655f8332be..0000000000 --- a/include/clang/Sema/DelayedDiagnostic.h +++ /dev/null @@ -1,168 +0,0 @@ -//===--- DelayedDiagnostic.h - Delayed declarator diagnostics ---*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the DelayedDiagnostic class, which is used to -// record diagnostics that are being conditionally produced during -// declarator parsing. Certain kinds of diagnostics --- notably -// deprecation and access control --- are suppressed based on -// semantic properties of the parsed declaration that aren't known -// until it is fully parsed. -// -// This file also defines AccessedEntity. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_SEMA_DELAYED_DIAGNOSTIC_H -#define LLVM_CLANG_SEMA_DELAYED_DIAGNOSTIC_H - -#include "clang/AST/DeclCXX.h" - -namespace clang { -namespace sema { - -/// A declaration being accessed, together with information about how -/// it was accessed. -class AccessedEntity { -public: - /// A member declaration found through lookup. The target is the - /// member. - enum MemberNonce { Member }; - - /// A hierarchy (base-to-derived or derived-to-base) conversion. - /// The target is the base class. - enum BaseNonce { Base }; - - bool isMemberAccess() const { return IsMember; } - - AccessedEntity(ASTContext &Context, - MemberNonce _, - CXXRecordDecl *NamingClass, - DeclAccessPair FoundDecl, - QualType BaseObjectType) - : Access(FoundDecl.getAccess()), IsMember(true), - Target(FoundDecl.getDecl()), NamingClass(NamingClass), - BaseObjectType(BaseObjectType), Diag(0, Context.getDiagAllocator()) { - } - - AccessedEntity(ASTContext &Context, - BaseNonce _, - CXXRecordDecl *BaseClass, - CXXRecordDecl *DerivedClass, - AccessSpecifier Access) - : Access(Access), IsMember(false), - Target(reinterpret_cast(BaseClass)), - NamingClass(DerivedClass), - Diag(0, Context.getDiagAllocator()) { - } - - bool isQuiet() const { return Diag.getDiagID() == 0; } - - AccessSpecifier getAccess() const { return AccessSpecifier(Access); } - - // These apply to member decls... - NamedDecl *getTargetDecl() const { return Target; } - CXXRecordDecl *getNamingClass() const { return NamingClass; } - - // ...and these apply to hierarchy conversions. - CXXRecordDecl *getBaseClass() const { - assert(!IsMember); return reinterpret_cast(Target); - } - CXXRecordDecl *getDerivedClass() const { return NamingClass; } - - /// Retrieves the base object type, important when accessing - /// an instance member. - QualType getBaseObjectType() const { return BaseObjectType; } - - /// Sets a diagnostic to be performed. The diagnostic is given - /// four (additional) arguments: - /// %0 - 0 if the entity was private, 1 if protected - /// %1 - the DeclarationName of the entity - /// %2 - the TypeDecl type of the naming class - /// %3 - the TypeDecl type of the declaring class - void setDiag(const PartialDiagnostic &PDiag) { - assert(isQuiet() && "partial diagnostic already defined"); - Diag = PDiag; - } - PartialDiagnostic &setDiag(unsigned DiagID) { - assert(isQuiet() && "partial diagnostic already defined"); - assert(DiagID && "creating null diagnostic"); - Diag.Reset(DiagID); - return Diag; - } - const PartialDiagnostic &getDiag() const { - return Diag; - } - -private: - unsigned Access : 2; - bool IsMember; - NamedDecl *Target; - CXXRecordDecl *NamingClass; - QualType BaseObjectType; - PartialDiagnostic Diag; -}; - -/// A diagnostic message which has been conditionally emitted pending -/// the complete parsing of the current declaration. -class DelayedDiagnostic { -public: - enum DDKind { Deprecation, Access }; - - unsigned char Kind; // actually a DDKind - bool Triggered; - - SourceLocation Loc; - - union { - /// Deprecation. - struct { NamedDecl *Decl; } DeprecationData; - - /// Access control. - char AccessData[sizeof(AccessedEntity)]; - }; - - void destroy() { - switch (Kind) { - case Access: getAccessData().~AccessedEntity(); break; - case Deprecation: break; - } - } - - static DelayedDiagnostic makeDeprecation(SourceLocation Loc, - NamedDecl *D) { - DelayedDiagnostic DD; - DD.Kind = Deprecation; - DD.Triggered = false; - DD.Loc = Loc; - DD.DeprecationData.Decl = D; - return DD; - } - - static DelayedDiagnostic makeAccess(SourceLocation Loc, - const AccessedEntity &Entity) { - DelayedDiagnostic DD; - DD.Kind = Access; - DD.Triggered = false; - DD.Loc = Loc; - new (&DD.getAccessData()) AccessedEntity(Entity); - return DD; - } - - AccessedEntity &getAccessData() { - return *reinterpret_cast(AccessData); - } - const AccessedEntity &getAccessData() const { - return *reinterpret_cast(AccessData); - } -}; - -} -} - -#endif diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index e6e97dfed5..4bbc021bcd 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -128,7 +128,6 @@ namespace clang { namespace sema { class AccessedEntity; class BlockScopeInfo; - class DelayedDiagnostic; class FunctionScopeInfo; class TemplateDeductionInfo; } @@ -285,9 +284,140 @@ public: /// and must warn if not used. Only contains the first declaration. llvm::SmallVector UnusedFileScopedDecls; + class AccessedEntity { + public: + /// A member declaration found through lookup. The target is the + /// member. + enum MemberNonce { Member }; + + /// A hierarchy (base-to-derived or derived-to-base) conversion. + /// The target is the base class. + enum BaseNonce { Base }; + + bool isMemberAccess() const { return IsMember; } + + AccessedEntity(ASTContext &Context, + MemberNonce _, + CXXRecordDecl *NamingClass, + DeclAccessPair FoundDecl, + QualType BaseObjectType) + : Access(FoundDecl.getAccess()), IsMember(true), + Target(FoundDecl.getDecl()), NamingClass(NamingClass), + BaseObjectType(BaseObjectType), Diag(0, Context.getDiagAllocator()) { + } + + AccessedEntity(ASTContext &Context, + BaseNonce _, + CXXRecordDecl *BaseClass, + CXXRecordDecl *DerivedClass, + AccessSpecifier Access) + : Access(Access), IsMember(false), + Target(reinterpret_cast(BaseClass)), + NamingClass(DerivedClass), + Diag(0, Context.getDiagAllocator()) { + } + + bool isQuiet() const { return Diag.getDiagID() == 0; } + + AccessSpecifier getAccess() const { return AccessSpecifier(Access); } + + // These apply to member decls... + NamedDecl *getTargetDecl() const { return Target; } + CXXRecordDecl *getNamingClass() const { return NamingClass; } + + // ...and these apply to hierarchy conversions. + CXXRecordDecl *getBaseClass() const { + assert(!IsMember); return reinterpret_cast(Target); + } + CXXRecordDecl *getDerivedClass() const { return NamingClass; } + + /// Retrieves the base object type, important when accessing + /// an instance member. + QualType getBaseObjectType() const { return BaseObjectType; } + + /// Sets a diagnostic to be performed. The diagnostic is given + /// four (additional) arguments: + /// %0 - 0 if the entity was private, 1 if protected + /// %1 - the DeclarationName of the entity + /// %2 - the TypeDecl type of the naming class + /// %3 - the TypeDecl type of the declaring class + void setDiag(const PartialDiagnostic &PDiag) { + assert(isQuiet() && "partial diagnostic already defined"); + Diag = PDiag; + } + PartialDiagnostic &setDiag(unsigned DiagID) { + assert(isQuiet() && "partial diagnostic already defined"); + assert(DiagID && "creating null diagnostic"); + Diag.Reset(DiagID); + return Diag; + } + const PartialDiagnostic &getDiag() const { + return Diag; + } + + private: + unsigned Access : 2; + bool IsMember; + NamedDecl *Target; + CXXRecordDecl *NamingClass; + QualType BaseObjectType; + PartialDiagnostic Diag; + }; + + struct DelayedDiagnostic { + enum DDKind { Deprecation, Access }; + + unsigned char Kind; // actually a DDKind + bool Triggered; + + SourceLocation Loc; + + union { + /// Deprecation. + struct { NamedDecl *Decl; } DeprecationData; + + /// Access control. + char AccessData[sizeof(AccessedEntity)]; + }; + + void destroy() { + switch (Kind) { + case Access: getAccessData().~AccessedEntity(); break; + case Deprecation: break; + } + } + + static DelayedDiagnostic makeDeprecation(SourceLocation Loc, + NamedDecl *D) { + DelayedDiagnostic DD; + DD.Kind = Deprecation; + DD.Triggered = false; + DD.Loc = Loc; + DD.DeprecationData.Decl = D; + return DD; + } + + static DelayedDiagnostic makeAccess(SourceLocation Loc, + const AccessedEntity &Entity) { + DelayedDiagnostic DD; + DD.Kind = Access; + DD.Triggered = false; + DD.Loc = Loc; + new (&DD.getAccessData()) AccessedEntity(Entity); + return DD; + } + + AccessedEntity &getAccessData() { + return *reinterpret_cast(AccessData); + } + const AccessedEntity &getAccessData() const { + return *reinterpret_cast(AccessData); + } + }; + /// \brief The stack of diagnostics that were delayed due to being /// produced during the parsing of a declaration. - llvm::SmallVector DelayedDiagnostics; + llvm::SmallVector DelayedDiagnostics; /// \brief The depth of the current ParsingDeclaration stack. /// If nonzero, we are currently parsing a declaration (and @@ -484,7 +614,9 @@ public: SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); /// \brief Build a partial diagnostic. - PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h + PartialDiagnostic PDiag(unsigned DiagID = 0) { + return PartialDiagnostic(DiagID, Context.getDiagAllocator()); + } virtual void DeleteExpr(ExprTy *E); virtual void DeleteStmt(StmtTy *S); @@ -1569,7 +1701,7 @@ public: void PopParsingDeclaration(ParsingDeclStackState S, Decl *D); void EmitDeprecationWarning(NamedDecl *D, SourceLocation Loc); - void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); + void HandleDelayedDeprecationCheck(DelayedDiagnostic &DD, Decl *Ctx); //===--------------------------------------------------------------------===// // Expression Parsing Callbacks: SemaExpr.cpp. @@ -2615,7 +2747,7 @@ public: void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); - void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); + void HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *Ctx); /// A flag to suppress access checking. bool SuppressAccessChecking; diff --git a/include/clang/Sema/SemaInternal.h b/include/clang/Sema/SemaInternal.h index 64b83e3bf6..1871350deb 100644 --- a/include/clang/Sema/SemaInternal.h +++ b/include/clang/Sema/SemaInternal.h @@ -17,14 +17,5 @@ #include "clang/Sema/Sema.h" #include "clang/Sema/SemaDiagnostic.h" -#include "clang/AST/ASTContext.h" - -namespace clang { - -inline PartialDiagnostic Sema::PDiag(unsigned DiagID) { - return PartialDiagnostic(DiagID, Context.getDiagAllocator()); -} - -} #endif diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 2de4d28cab..fd6dcfc095 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#include "clang/Sema/SemaInternal.h" -#include "clang/Sema/DelayedDiagnostic.h" +#include "clang/Sema/Sema.h" +#include "clang/Sema/SemaDiagnostic.h" #include "TargetAttributesSema.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index 7cda7dd172..965ec66a13 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "clang/Sema/SemaInternal.h" -#include "clang/Sema/DelayedDiagnostic.h" #include "clang/Sema/Initialization.h" #include "clang/Sema/Lookup.h" #include "clang/AST/ASTContext.h" @@ -23,7 +22,6 @@ #include "clang/AST/ExprCXX.h" using namespace clang; -using namespace sema; /// A copy of Sema's enum without AR_delayed. enum AccessResult { @@ -134,10 +132,10 @@ struct EffectiveContext { bool Dependent; }; -/// Like sema:;AccessedEntity, but kindly lets us scribble all over +/// Like Sema's AccessedEntity, but kindly lets us scribble all over /// it. -struct AccessTarget : public AccessedEntity { - AccessTarget(const AccessedEntity &Entity) +struct AccessTarget : public Sema::AccessedEntity { + AccessTarget(const Sema::AccessedEntity &Entity) : AccessedEntity(Entity) { initialize(); } @@ -1035,7 +1033,7 @@ static Sema::AccessResult CheckAccess(Sema &S, SourceLocation Loc, // access control. if (S.CurContext->isFileContext() && S.ParsingDeclDepth) { S.DelayedDiagnostics.push_back( - DelayedDiagnostic::makeAccess(Loc, Entity)); + Sema::DelayedDiagnostic::makeAccess(Loc, Entity)); return Sema::AR_delayed; } diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 46623d2818..a2cad6a5d2 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -19,10 +19,8 @@ #include "clang/AST/Expr.h" #include "clang/Basic/TargetInfo.h" #include "clang/Sema/DeclSpec.h" -#include "clang/Sema/DelayedDiagnostic.h" #include "llvm/ADT/StringExtras.h" using namespace clang; -using namespace sema; //===----------------------------------------------------------------------===// // Helper functions @@ -2470,7 +2468,7 @@ static bool isDeclDeprecated(Decl *D) { return false; } -void Sema::HandleDelayedDeprecationCheck(DelayedDiagnostic &DD, +void Sema::HandleDelayedDeprecationCheck(Sema::DelayedDiagnostic &DD, Decl *Ctx) { if (isDeclDeprecated(Ctx)) return; -- 2.40.0