diff --git a/clang/lib/Sema/Lookup.h b/clang/lib/Sema/Lookup.h index e2134a2683d6..61d8a4ea3335 100644 --- a/clang/lib/Sema/Lookup.h +++ b/clang/lib/Sema/Lookup.h @@ -26,13 +26,6 @@ namespace clang { /// a single declaration, a set of overloaded functions, or an /// ambiguity. Use the getKind() method to determine which of these /// results occurred for a given lookup. -/// -/// Any non-ambiguous lookup can be converted into a single -/// (possibly NULL) @c NamedDecl* via the getAsSingleDecl() method. -/// This permits the common-case usage in C and Objective-C where -/// name lookup will always return a single declaration. Use of -/// this is largely deprecated; callers should handle the possibility -/// of multiple declarations. class LookupResult { public: enum LookupResultKind { @@ -282,13 +275,6 @@ public: } } - /// \brief Fetch this as an unambiguous single declaration - /// (possibly an overloaded one). - /// - /// This is deprecated; users should be written to handle - /// ambiguous and overloaded lookups. - NamedDecl *getAsSingleDecl(ASTContext &Context) const; - template DeclClass *getAsSingle() const { if (getResultKind() != Found) return 0; diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index 8503887a6171..98880e9d5f8c 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -1160,7 +1160,7 @@ public: } /// \brief Look up a name, looking for a single declaration. Return - /// null if no unambiguous results were found. + /// null if the results were absent, ambiguous, or overloaded. /// /// It is preferable to use the elaborated form and explicitly handle /// ambiguity and overloaded. diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index 5769716b33ea..095f537f7102 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -183,20 +183,19 @@ void Sema::ActOnPragmaUnused(const Token *Identifiers, unsigned NumIdentifiers, LookupResult Lookup(*this, Name, Tok.getLocation(), LookupOrdinaryName); LookupParsedName(Lookup, curScope, NULL, true); - NamedDecl *ND = Lookup.getAsSingleDecl(Context); - - if (!ND) { + if (Lookup.empty()) { Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var) << Name << SourceRange(Tok.getLocation()); continue; } - if (!isa(ND) || !cast(ND)->hasLocalStorage()) { + VarDecl *VD = Lookup.getAsSingle(); + if (!VD || !VD->hasLocalStorage()) { Diag(PragmaLoc, diag::warn_pragma_unused_expected_localvar) << Name << SourceRange(Tok.getLocation()); continue; } - ND->addAttr(::new (Context) UnusedAttr()); + VD->addAttr(::new (Context) UnusedAttr()); } } diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index 34a5b784d49b..14db77440fed 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -313,7 +313,10 @@ NamedDecl *Sema::FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS) { LookupName(Found, S); assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet"); - NamedDecl *Result = Found.getAsSingleDecl(Context); + if (!Found.isSingleResult()) + return 0; + + NamedDecl *Result = Found.getFoundDecl(); if (isAcceptableNestedNameSpecifier(Result)) return Result; @@ -414,7 +417,7 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, } // FIXME: Deal with ambiguities cleanly. - NamedDecl *SD = Found.getAsSingleDecl(Context); + NamedDecl *SD = Found.getAsSingle(); if (isAcceptableNestedNameSpecifier(SD)) { if (!ObjectType.isNull() && !ObjectTypeSearchedInScope) { // C++ [basic.lookup.classref]p4: @@ -429,7 +432,7 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, if (S) { LookupResult FoundOuter(*this, &II, IdLoc, LookupNestedNameSpecifierName); LookupName(FoundOuter, S); - OuterDecl = FoundOuter.getAsSingleDecl(Context); + OuterDecl = FoundOuter.getAsSingle(); } else OuterDecl = ScopeLookupResult; @@ -469,14 +472,13 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, // If we didn't find anything during our lookup, try again with // ordinary name lookup, which can help us produce better error // messages. - if (!SD) { + if (Found.empty()) { Found.clear(LookupOrdinaryName); LookupName(Found, S); - SD = Found.getAsSingleDecl(Context); } unsigned DiagID; - if (SD) + if (!Found.empty()) DiagID = diag::err_expected_class_or_namespace; else if (SS.isSet()) { Diag(IdLoc, diag::err_no_member) << &II << LookupCtx << SS.getRange(); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index c87899b7f83f..76b726fe3390 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -229,7 +229,7 @@ DeclSpec::TST Sema::isTagName(IdentifierInfo &II, Scope *S) { LookupName(R, S, false); R.suppressDiagnostics(); if (R.getResultKind() == LookupResult::Found) - if (const TagDecl *TD = dyn_cast(R.getAsSingleDecl(Context))) { + if (const TagDecl *TD = R.getAsSingle()) { switch (TD->getTagKind()) { case TagDecl::TK_struct: return DeclSpec::TST_struct; case TagDecl::TK_union: return DeclSpec::TST_union; @@ -4734,10 +4734,7 @@ CreateNewDecl: LookupResult Lookup(*this, Name, NameLoc, LookupOrdinaryName, ForRedeclaration); LookupName(Lookup, S); - TypedefDecl *PrevTypedef = 0; - if (NamedDecl *Prev = Lookup.getAsSingleDecl(Context)) - PrevTypedef = dyn_cast(Prev); - + TypedefDecl *PrevTypedef = Lookup.getAsSingle(); NamedDecl *PrevTypedefNamed = PrevTypedef; if (PrevTypedef && isDeclInScope(PrevTypedefNamed, SearchDC, S) && Context.getCanonicalType(Context.getTypeDeclType(PrevTypedef)) != diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index de1816c92b7e..01c77966244b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -6370,8 +6370,7 @@ Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, LookupResult R(*this, OC.U.IdentInfo, OC.LocStart, LookupMemberName); LookupQualifiedName(R, RD); - FieldDecl *MemberDecl - = dyn_cast_or_null(R.getAsSingleDecl(Context)); + FieldDecl *MemberDecl = R.getAsSingle(); // FIXME: Leaks Res if (!MemberDecl) return ExprError(Diag(BuiltinLoc, diag::err_no_member) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index e626aff38bef..f5f712a0a5e2 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -37,8 +37,7 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, IdentifierInfo *TypeInfoII = &PP.getIdentifierTable().get("type_info"); LookupResult R(*this, TypeInfoII, SourceLocation(), LookupTagName); LookupQualifiedName(R, StdNamespace); - Decl *TypeInfoDecl = R.getAsSingleDecl(Context); - RecordDecl *TypeInfoRecordDecl = dyn_cast_or_null(TypeInfoDecl); + RecordDecl *TypeInfoRecordDecl = R.getAsSingle(); if (!TypeInfoRecordDecl) return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid)); diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 8f0982740d4a..f8cb5f037ec0 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -337,44 +337,6 @@ void LookupResult::resolveKind() { ResultKind = LookupResult::Found; } -/// @brief Converts the result of name lookup into a single (possible -/// NULL) pointer to a declaration. -/// -/// The resulting declaration will either be the declaration we found -/// (if only a single declaration was found), an -/// OverloadedFunctionDecl (if an overloaded function was found), or -/// NULL (if no declaration was found). This conversion must not be -/// used anywhere where name lookup could result in an ambiguity. -/// -/// The OverloadedFunctionDecl conversion is meant as a stop-gap -/// solution, since it causes the OverloadedFunctionDecl to be -/// leaked. FIXME: Eventually, there will be a better way to iterate -/// over the set of overloaded functions returned by name lookup. -NamedDecl *LookupResult::getAsSingleDecl(ASTContext &C) const { - size_t size = Decls.size(); - if (size == 0) return 0; - if (size == 1) return (*begin())->getUnderlyingDecl(); - - if (isAmbiguous()) return 0; - - iterator I = begin(), E = end(); - - OverloadedFunctionDecl *Ovl - = OverloadedFunctionDecl::Create(C, (*I)->getDeclContext(), - (*I)->getDeclName()); - for (; I != E; ++I) { - NamedDecl *ND = (*I)->getUnderlyingDecl(); - assert(ND->isFunctionOrFunctionTemplate()); - if (isa(ND)) - Ovl->addOverload(cast(ND)); - else - Ovl->addOverload(cast(ND)); - // FIXME: UnresolvedUsingDecls. - } - - return Ovl; -} - void LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) { CXXBasePaths::paths_iterator I, E; DeclContext::lookup_iterator DI, DE; @@ -1610,7 +1572,7 @@ NamedDecl *Sema::LookupSingleName(Scope *S, DeclarationName Name, RedeclarationKind Redecl) { LookupResult R(*this, Name, SourceLocation(), NameKind, Redecl); LookupName(R, S); - return R.getAsSingleDecl(Context); + return R.getAsSingle(); } /// \brief Find the protocol with the given name, if any. diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index f5e5569f64cf..db0e921189f9 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4397,8 +4397,7 @@ Sema::DeclResult Sema::ActOnExplicitInstantiation(Scope *S, if (Previous.isAmbiguous()) return true; - VarDecl *Prev = dyn_cast_or_null( - Previous.getAsSingleDecl(Context)); + VarDecl *Prev = Previous.getAsSingle(); if (!Prev || !Prev->isStaticDataMember()) { // We expect to see a data data member here. Diag(D.getIdentifierLoc(), diag::err_explicit_instantiation_not_known)