From: Aaron Ballman Date: Wed, 15 Oct 2014 15:37:51 +0000 (+0000) Subject: Turned Sema::HandleDelayedAvailabilityCheck into a static function; NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8261ffe673b7686c15ed8ce034c24085c6d03d6;p=clang Turned Sema::HandleDelayedAvailabilityCheck into a static function; NFC. Did a bit of drive-by reformatting as well since it required rearranging some other static functions in the file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219795 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index fa53a3812e..4cd4c57c33 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -3267,8 +3267,6 @@ public: const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess); - void HandleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); - bool makeUnavailableInSystemHeader(SourceLocation loc, StringRef message); diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 406e511651..d252bdcea5 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4911,61 +4911,6 @@ static void handleDelayedForbiddenType(Sema &S, DelayedDiagnostic &diag, diag.Triggered = true; } -void Sema::PopParsingDeclaration(ParsingDeclState state, Decl *decl) { - assert(DelayedDiagnostics.getCurrentPool()); - DelayedDiagnosticPool &poppedPool = *DelayedDiagnostics.getCurrentPool(); - DelayedDiagnostics.popWithoutEmitting(state); - - // When delaying diagnostics to run in the context of a parsed - // declaration, we only want to actually emit anything if parsing - // succeeds. - if (!decl) return; - - // We emit all the active diagnostics in this pool or any of its - // parents. In general, we'll get one pool for the decl spec - // and a child pool for each declarator; in a decl group like: - // deprecated_typedef foo, *bar, baz(); - // only the declarator pops will be passed decls. This is correct; - // we really do need to consider delayed diagnostics from the decl spec - // for each of the different declarations. - const DelayedDiagnosticPool *pool = &poppedPool; - do { - for (DelayedDiagnosticPool::pool_iterator - i = pool->pool_begin(), e = pool->pool_end(); i != e; ++i) { - // This const_cast is a bit lame. Really, Triggered should be mutable. - DelayedDiagnostic &diag = const_cast(*i); - if (diag.Triggered) - continue; - - switch (diag.Kind) { - case DelayedDiagnostic::Deprecation: - case DelayedDiagnostic::Unavailable: - // Don't bother giving deprecation/unavailable diagnostics if - // the decl is invalid. - if (!decl->isInvalidDecl()) - HandleDelayedAvailabilityCheck(diag, decl); - break; - - case DelayedDiagnostic::Access: - HandleDelayedAccessCheck(diag, decl); - break; - - case DelayedDiagnostic::ForbiddenType: - handleDelayedForbiddenType(*this, diag, decl); - break; - } - } - } while ((pool = pool->getParent())); -} - -/// Given a set of delayed diagnostics, re-emit them as if they had -/// been delayed in the current context instead of in the given pool. -/// Essentially, this just moves them to the current pool. -void Sema::redelayDiagnostics(DelayedDiagnosticPool &pool) { - DelayedDiagnosticPool *curPool = DelayedDiagnostics.getCurrentPool(); - assert(curPool && "re-emitting in undelayed context not supported"); - curPool->steal(pool); -} static bool isDeclDeprecated(Decl *D) { do { @@ -4989,17 +4934,12 @@ static bool isDeclUnavailable(Decl *D) { return false; } -static void -DoEmitAvailabilityWarning(Sema &S, - DelayedDiagnostic::DDKind K, - Decl *Ctx, - const NamedDecl *D, - StringRef Message, - SourceLocation Loc, - const ObjCInterfaceDecl *UnknownObjCClass, - const ObjCPropertyDecl *ObjCProperty, - bool ObjCPropertyAccess) { - +static void DoEmitAvailabilityWarning(Sema &S, DelayedDiagnostic::DDKind K, + Decl *Ctx, const NamedDecl *D, + StringRef Message, SourceLocation Loc, + const ObjCInterfaceDecl *UnknownObjCClass, + const ObjCPropertyDecl *ObjCProperty, + bool ObjCPropertyAccess) { // Diagnostics for deprecated or unavailable. unsigned diag, diag_message, diag_fwdclass_message; @@ -5011,30 +4951,30 @@ DoEmitAvailabilityWarning(Sema &S, // Don't warn if our current context is deprecated or unavailable. switch (K) { - case DelayedDiagnostic::Deprecation: - if (isDeclDeprecated(Ctx)) - return; - diag = !ObjCPropertyAccess ? diag::warn_deprecated - : diag::warn_property_method_deprecated; - diag_message = diag::warn_deprecated_message; - diag_fwdclass_message = diag::warn_deprecated_fwdclass_message; - property_note_select = /* deprecated */ 0; - available_here_select_kind = /* deprecated */ 2; - break; + case DelayedDiagnostic::Deprecation: + if (isDeclDeprecated(Ctx)) + return; + diag = !ObjCPropertyAccess ? diag::warn_deprecated + : diag::warn_property_method_deprecated; + diag_message = diag::warn_deprecated_message; + diag_fwdclass_message = diag::warn_deprecated_fwdclass_message; + property_note_select = /* deprecated */ 0; + available_here_select_kind = /* deprecated */ 2; + break; - case DelayedDiagnostic::Unavailable: - if (isDeclUnavailable(Ctx)) - return; - diag = !ObjCPropertyAccess ? diag::err_unavailable - : diag::err_property_method_unavailable; - diag_message = diag::err_unavailable_message; - diag_fwdclass_message = diag::warn_unavailable_fwdclass_message; - property_note_select = /* unavailable */ 1; - available_here_select_kind = /* unavailable */ 0; - break; + case DelayedDiagnostic::Unavailable: + if (isDeclUnavailable(Ctx)) + return; + diag = !ObjCPropertyAccess ? diag::err_unavailable + : diag::err_property_method_unavailable; + diag_message = diag::err_unavailable_message; + diag_fwdclass_message = diag::warn_unavailable_fwdclass_message; + property_note_select = /* unavailable */ 1; + available_here_select_kind = /* unavailable */ 0; + break; - default: - llvm_unreachable("Neither a deprecation or unavailable kind"); + default: + llvm_unreachable("Neither a deprecation or unavailable kind"); } DeclarationName Name = D->getDeclName(); @@ -5042,34 +4982,86 @@ DoEmitAvailabilityWarning(Sema &S, S.Diag(Loc, diag_message) << Name << Message; if (ObjCProperty) S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute) - << ObjCProperty->getDeclName() << property_note_select; + << ObjCProperty->getDeclName() << property_note_select; } else if (!UnknownObjCClass) { S.Diag(Loc, diag) << Name; if (ObjCProperty) S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute) - << ObjCProperty->getDeclName() << property_note_select; + << ObjCProperty->getDeclName() << property_note_select; } else { S.Diag(Loc, diag_fwdclass_message) << Name; S.Diag(UnknownObjCClass->getLocation(), diag::note_forward_class); } S.Diag(D->getLocation(), diag::note_availability_specified_here) - << D << available_here_select_kind; + << D << available_here_select_kind; } -void Sema::HandleDelayedAvailabilityCheck(DelayedDiagnostic &DD, - Decl *Ctx) { +static void handleDelayedAvailabilityCheck(Sema &S, DelayedDiagnostic &DD, + Decl *Ctx) { DD.Triggered = true; - DoEmitAvailabilityWarning(*this, - (DelayedDiagnostic::DDKind) DD.Kind, - Ctx, - DD.getDeprecationDecl(), - DD.getDeprecationMessage(), - DD.Loc, - DD.getUnknownObjCClass(), + DoEmitAvailabilityWarning(S, (DelayedDiagnostic::DDKind)DD.Kind, Ctx, + DD.getDeprecationDecl(), DD.getDeprecationMessage(), + DD.Loc, DD.getUnknownObjCClass(), DD.getObjCProperty(), false); } +void Sema::PopParsingDeclaration(ParsingDeclState state, Decl *decl) { + assert(DelayedDiagnostics.getCurrentPool()); + DelayedDiagnosticPool &poppedPool = *DelayedDiagnostics.getCurrentPool(); + DelayedDiagnostics.popWithoutEmitting(state); + + // When delaying diagnostics to run in the context of a parsed + // declaration, we only want to actually emit anything if parsing + // succeeds. + if (!decl) return; + + // We emit all the active diagnostics in this pool or any of its + // parents. In general, we'll get one pool for the decl spec + // and a child pool for each declarator; in a decl group like: + // deprecated_typedef foo, *bar, baz(); + // only the declarator pops will be passed decls. This is correct; + // we really do need to consider delayed diagnostics from the decl spec + // for each of the different declarations. + const DelayedDiagnosticPool *pool = &poppedPool; + do { + for (DelayedDiagnosticPool::pool_iterator + i = pool->pool_begin(), e = pool->pool_end(); i != e; ++i) { + // This const_cast is a bit lame. Really, Triggered should be mutable. + DelayedDiagnostic &diag = const_cast(*i); + if (diag.Triggered) + continue; + + switch (diag.Kind) { + case DelayedDiagnostic::Deprecation: + case DelayedDiagnostic::Unavailable: + // Don't bother giving deprecation/unavailable diagnostics if + // the decl is invalid. + if (!decl->isInvalidDecl()) + handleDelayedAvailabilityCheck(*this, diag, decl); + break; + + case DelayedDiagnostic::Access: + HandleDelayedAccessCheck(diag, decl); + break; + + case DelayedDiagnostic::ForbiddenType: + handleDelayedForbiddenType(*this, diag, decl); + break; + } + } + } while ((pool = pool->getParent())); +} + +/// Given a set of delayed diagnostics, re-emit them as if they had +/// been delayed in the current context instead of in the given pool. +/// Essentially, this just moves them to the current pool. +void Sema::redelayDiagnostics(DelayedDiagnosticPool &pool) { + DelayedDiagnosticPool *curPool = DelayedDiagnostics.getCurrentPool(); + assert(curPool && "re-emitting in undelayed context not supported"); + curPool->steal(pool); +} + void Sema::EmitAvailabilityWarning(AvailabilityDiagnostic AD, NamedDecl *D, StringRef Message, SourceLocation Loc,