aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-10-09 21:13:30 +0000
committerJohn McCall <rjmccall@apple.com>2009-10-09 21:13:30 +0000
commitf36e02d4aff98bf2e52e342e0038d4172fbb5e64 (patch)
treede0e84cc5c69c3749a01794221565dcbe5d22614 /lib/Sema/SemaDeclCXX.cpp
parentd7e5bdb23c6ba2786cf94788c9af555e2c1276ce (diff)
Refactor the LookupResult API to simplify most common operations. Require users to
pass a LookupResult reference to lookup routines. Call out uses which assume a single result. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83674 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--lib/Sema/SemaDeclCXX.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index abe20408cc..fb0e144036 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2490,8 +2490,8 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
// original-namespace-definition is the name of the namespace. Subsequently
// in that declarative region, it is treated as an original-namespace-name.
- NamedDecl *PrevDecl = LookupName(DeclRegionScope, II, LookupOrdinaryName,
- true);
+ NamedDecl *PrevDecl
+ = LookupSingleName(DeclRegionScope, II, LookupOrdinaryName, true);
if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) {
// This is an extended namespace definition.
@@ -2599,13 +2599,14 @@ Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S,
UsingDirectiveDecl *UDir = 0;
// Lookup namespace name.
- LookupResult R = LookupParsedName(S, &SS, NamespcName,
- LookupNamespaceName, false);
+ LookupResult R;
+ LookupParsedName(R, S, &SS, NamespcName, LookupNamespaceName, false);
if (R.isAmbiguous()) {
DiagnoseAmbiguousLookup(R, NamespcName, IdentLoc);
return DeclPtrTy();
}
- if (NamedDecl *NS = R) {
+ if (!R.empty()) {
+ NamedDecl *NS = R.getFoundDecl();
assert(isa<NamespaceDecl>(NS) && "expected namespace decl");
// C++ [namespace.udir]p1:
// A using-directive specifies that the names in the nominated
@@ -2746,15 +2747,16 @@ NamedDecl *Sema::BuildUsingDeclaration(SourceLocation UsingLoc,
// Lookup target name.
- LookupResult R = LookupQualifiedName(LookupContext,
- Name, LookupOrdinaryName);
+ LookupResult R;
+ LookupQualifiedName(R, LookupContext, Name, LookupOrdinaryName);
- if (!R) {
+ if (R.empty()) {
DiagnoseMissingMember(IdentLoc, Name, NNS, SS.getRange());
return 0;
}
- NamedDecl *ND = R.getAsDecl();
+ // FIXME: handle ambiguity?
+ NamedDecl *ND = R.getAsSingleDecl(Context);
if (IsTypeName && !isa<TypeDecl>(ND)) {
Diag(IdentLoc, diag::err_using_typename_non_type);
@@ -2790,14 +2792,17 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
IdentifierInfo *Ident) {
// Lookup the namespace name.
- LookupResult R = LookupParsedName(S, &SS, Ident, LookupNamespaceName, false);
+ LookupResult R;
+ LookupParsedName(R, S, &SS, Ident, LookupNamespaceName, false);
// Check if we have a previous declaration with the same name.
- if (NamedDecl *PrevDecl = LookupName(S, Alias, LookupOrdinaryName, true)) {
+ if (NamedDecl *PrevDecl
+ = LookupSingleName(S, Alias, LookupOrdinaryName, true)) {
if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(PrevDecl)) {
// We already have an alias with the same name that points to the same
// namespace, so don't create a new one.
- if (!R.isAmbiguous() && AD->getNamespace() == getNamespaceDecl(R))
+ if (!R.isAmbiguous() && !R.empty() &&
+ AD->getNamespace() == getNamespaceDecl(R.getFoundDecl()))
return DeclPtrTy();
}
@@ -2813,7 +2818,7 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
return DeclPtrTy();
}
- if (!R) {
+ if (R.empty()) {
Diag(NamespaceLoc, diag::err_expected_namespace_name) << SS.getRange();
return DeclPtrTy();
}
@@ -2822,7 +2827,7 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc,
Alias, SS.getRange(),
(NestedNameSpecifier *)SS.getScopeRep(),
- IdentLoc, R);
+ IdentLoc, R.getFoundDecl());
CurContext->addDecl(AliasDecl);
return DeclPtrTy::make(AliasDecl);
@@ -4151,7 +4156,7 @@ Sema::DeclPtrTy Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) {
bool Invalid = D.isInvalidType();
IdentifierInfo *II = D.getIdentifier();
- if (NamedDecl *PrevDecl = LookupName(S, II, LookupOrdinaryName)) {
+ if (NamedDecl *PrevDecl = LookupSingleName(S, II, LookupOrdinaryName)) {
// The scope should be freshly made just for us. There is just no way
// it contains any previous declaration.
assert(!S->isDeclScope(DeclPtrTy::make(PrevDecl)));
@@ -4398,7 +4403,9 @@ Sema::ActOnFriendFunctionDecl(Scope *S,
// FIXME: handle dependent contexts
if (!DC) return DeclPtrTy();
- PrevDecl = LookupQualifiedName(DC, Name, LookupOrdinaryName, true);
+ LookupResult R;
+ LookupQualifiedName(R, DC, Name, LookupOrdinaryName, true);
+ PrevDecl = R.getAsSingleDecl(Context);
// If searching in that context implicitly found a declaration in
// a different context, treat it like it wasn't found at all.
@@ -4431,7 +4438,9 @@ Sema::ActOnFriendFunctionDecl(Scope *S,
while (DC->isRecord())
DC = DC->getParent();
- PrevDecl = LookupQualifiedName(DC, Name, LookupOrdinaryName, true);
+ LookupResult R;
+ LookupQualifiedName(R, DC, Name, LookupOrdinaryName, true);
+ PrevDecl = R.getAsSingleDecl(Context);
// TODO: decide what we think about using declarations.
if (PrevDecl)