diff options
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index e28492b57956..54918c560b65 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -2770,10 +2770,7 @@ bool Sema::LookupInSuper(LookupResult &R, CXXRecordDecl *Class) { // members of Class itself. That is, the naming class is Class, and the // access includes the access of the base. for (const auto &BaseSpec : Class->bases()) { - CXXRecordDecl *RD = - cast<CXXRecordDecl>( - BaseSpec.getType()->castAs<RecordType>()->getOriginalDecl()) - ->getDefinitionOrSelf(); + auto *RD = BaseSpec.getType()->castAsCXXRecordDecl(); LookupResult Result(*this, R.getLookupNameInfo(), R.getLookupKind()); Result.setBaseObjectType(Context.getCanonicalTagType(Class)); LookupQualifiedName(Result, RD); @@ -3114,17 +3111,15 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, // Visit the base classes. for (const auto &Base : Class->bases()) { - const RecordType *BaseType = Base.getType()->getAs<RecordType>(); + CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl(); // In dependent contexts, we do ADL twice, and the first time around, // the base type might be a dependent TemplateSpecializationType, or a // TemplateTypeParmType. If that happens, simply ignore it. // FIXME: If we want to support export, we probably need to add the // namespace of the template in a TemplateSpecializationType, or even // the classes and namespaces of known non-dependent arguments. - if (!BaseType) + if (!BaseDecl) continue; - CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(BaseType->getOriginalDecl()) - ->getDefinitionOrSelf(); if (Result.addClassTransitive(BaseDecl)) { // Find the associated namespace for this base class. DeclContext *BaseCtx = BaseDecl->getDeclContext(); @@ -3209,8 +3204,7 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType Ty) { // member’s class; else it has no associated class. case Type::Enum: { // FIXME: This should use the original decl. - EnumDecl *Enum = - cast<EnumType>(T)->getOriginalDecl()->getDefinitionOrSelf(); + auto *Enum = T->castAsEnumDecl(); DeclContext *Ctx = Enum->getDeclContext(); if (CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx)) @@ -4262,10 +4256,9 @@ private: continue; RD = TD->getTemplatedDecl(); } else { - const auto *Record = BaseType->getAs<RecordType>(); - if (!Record) + RD = BaseType->getAsCXXRecordDecl(); + if (!RD) continue; - RD = Record->getOriginalDecl()->getDefinitionOrSelf(); } // FIXME: It would be nice to be able to determine whether referencing @@ -4460,26 +4453,28 @@ void Sema::LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, H.lookupVisibleDecls(*this, Ctx, Kind, IncludeGlobalScope); } +LabelDecl *Sema::LookupExistingLabel(IdentifierInfo *II, SourceLocation Loc) { + NamedDecl *Res = LookupSingleName(CurScope, II, Loc, LookupLabel, + RedeclarationKind::NotForRedeclaration); + // If we found a label, check to see if it is in the same context as us. + // When in a Block, we don't want to reuse a label in an enclosing function. + if (!Res || Res->getDeclContext() != CurContext) + return nullptr; + return cast<LabelDecl>(Res); +} + LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc, SourceLocation GnuLabelLoc) { - // Do a lookup to see if we have a label with this name already. - NamedDecl *Res = nullptr; - if (GnuLabelLoc.isValid()) { // Local label definitions always shadow existing labels. - Res = LabelDecl::Create(Context, CurContext, Loc, II, GnuLabelLoc); + auto *Res = LabelDecl::Create(Context, CurContext, Loc, II, GnuLabelLoc); Scope *S = CurScope; PushOnScopeChains(Res, S, true); return cast<LabelDecl>(Res); } // Not a GNU local label. - Res = LookupSingleName(CurScope, II, Loc, LookupLabel, - RedeclarationKind::NotForRedeclaration); - // If we found a label, check to see if it is in the same context as us. - // When in a Block, we don't want to reuse a label in an enclosing function. - if (Res && Res->getDeclContext() != CurContext) - Res = nullptr; + LabelDecl *Res = LookupExistingLabel(II, Loc); if (!Res) { // If not forward referenced or defined already, create the backing decl. Res = LabelDecl::Create(Context, CurContext, Loc, II); @@ -4487,7 +4482,7 @@ LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc, assert(S && "Not in a function?"); PushOnScopeChains(Res, S, true); } - return cast<LabelDecl>(Res); + return Res; } //===----------------------------------------------------------------------===// @@ -4581,7 +4576,7 @@ static void getNestedNameSpecifierIdentifiers( TemplateName Name = cast<TemplateSpecializationType>(T)->getTemplateName(); if (const QualifiedTemplateName *QTN = - Name.getAsAdjustedQualifiedTemplateName()) { + Name.getAsQualifiedTemplateName()) { getNestedNameSpecifierIdentifiers(QTN->getQualifier(), Identifiers); Name = QTN->getUnderlyingTemplate(); } |
