2009-11-18 10:57:50 +03:00
|
|
|
//===--- Lookup.h - Classes for name lookup ---------------------*- 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 LookupResult class, which is integral to
|
|
|
|
// Sema's name-lookup subsystem.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_SEMA_LOOKUP_H
|
|
|
|
#define LLVM_CLANG_SEMA_LOOKUP_H
|
|
|
|
|
2010-08-13 00:07:10 +04:00
|
|
|
#include "clang/Sema/Sema.h"
|
2010-08-25 11:42:41 +04:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-11-18 10:57:50 +03:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
/// @brief Represents the results of name lookup.
|
|
|
|
///
|
|
|
|
/// An instance of the LookupResult class captures the results of a
|
|
|
|
/// single name lookup, which can return no result (nothing found),
|
|
|
|
/// 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.
|
|
|
|
class LookupResult {
|
|
|
|
public:
|
|
|
|
enum LookupResultKind {
|
|
|
|
/// @brief No entity found met the criteria.
|
|
|
|
NotFound = 0,
|
|
|
|
|
2010-01-15 04:44:47 +03:00
|
|
|
/// @brief No entity found met the criteria within the current
|
|
|
|
/// instantiation,, but there were dependent base classes of the
|
|
|
|
/// current instantiation that could not be searched.
|
|
|
|
NotFoundInCurrentInstantiation,
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
/// @brief Name lookup found a single declaration that met the
|
2009-12-02 11:47:38 +03:00
|
|
|
/// criteria. getFoundDecl() will return this declaration.
|
2009-11-18 10:57:50 +03:00
|
|
|
Found,
|
|
|
|
|
|
|
|
/// @brief Name lookup found a set of overloaded functions that
|
2009-12-02 11:47:38 +03:00
|
|
|
/// met the criteria.
|
2009-11-18 10:57:50 +03:00
|
|
|
FoundOverloaded,
|
|
|
|
|
|
|
|
/// @brief Name lookup found an unresolvable value declaration
|
|
|
|
/// and cannot yet complete. This only happens in C++ dependent
|
|
|
|
/// contexts with dependent using declarations.
|
|
|
|
FoundUnresolvedValue,
|
|
|
|
|
|
|
|
/// @brief Name lookup results in an ambiguity; use
|
|
|
|
/// getAmbiguityKind to figure out what kind of ambiguity
|
|
|
|
/// we have.
|
|
|
|
Ambiguous
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AmbiguityKind {
|
|
|
|
/// Name lookup results in an ambiguity because multiple
|
|
|
|
/// entities that meet the lookup criteria were found in
|
|
|
|
/// subobjects of different types. For example:
|
|
|
|
/// @code
|
|
|
|
/// struct A { void f(int); }
|
|
|
|
/// struct B { void f(double); }
|
|
|
|
/// struct C : A, B { };
|
|
|
|
/// void test(C c) {
|
|
|
|
/// c.f(0); // error: A::f and B::f come from subobjects of different
|
|
|
|
/// // types. overload resolution is not performed.
|
|
|
|
/// }
|
|
|
|
/// @endcode
|
|
|
|
AmbiguousBaseSubobjectTypes,
|
|
|
|
|
|
|
|
/// Name lookup results in an ambiguity because multiple
|
|
|
|
/// nonstatic entities that meet the lookup criteria were found
|
|
|
|
/// in different subobjects of the same type. For example:
|
|
|
|
/// @code
|
|
|
|
/// struct A { int x; };
|
|
|
|
/// struct B : A { };
|
|
|
|
/// struct C : A { };
|
|
|
|
/// struct D : B, C { };
|
|
|
|
/// int test(D d) {
|
|
|
|
/// return d.x; // error: 'x' is found in two A subobjects (of B and C)
|
|
|
|
/// }
|
|
|
|
/// @endcode
|
|
|
|
AmbiguousBaseSubobjects,
|
|
|
|
|
|
|
|
/// Name lookup results in an ambiguity because multiple definitions
|
|
|
|
/// of entity that meet the lookup criteria were found in different
|
|
|
|
/// declaration contexts.
|
|
|
|
/// @code
|
|
|
|
/// namespace A {
|
|
|
|
/// int i;
|
|
|
|
/// namespace B { int i; }
|
|
|
|
/// int test() {
|
|
|
|
/// using namespace B;
|
|
|
|
/// return i; // error 'i' is found in namespace A and A::B
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// @endcode
|
|
|
|
AmbiguousReference,
|
|
|
|
|
|
|
|
/// Name lookup results in an ambiguity because an entity with a
|
|
|
|
/// tag name was hidden by an entity with an ordinary name from
|
|
|
|
/// a different context.
|
|
|
|
/// @code
|
|
|
|
/// namespace A { struct Foo {}; }
|
|
|
|
/// namespace B { void Foo(); }
|
|
|
|
/// namespace C {
|
|
|
|
/// using namespace A;
|
|
|
|
/// using namespace B;
|
|
|
|
/// }
|
|
|
|
/// void test() {
|
|
|
|
/// C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
|
|
|
|
/// // different namespace
|
|
|
|
/// }
|
|
|
|
/// @endcode
|
|
|
|
AmbiguousTagHiding
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A little identifier for flagging temporary lookup results.
|
|
|
|
enum TemporaryToken {
|
|
|
|
Temporary
|
|
|
|
};
|
|
|
|
|
2010-01-20 03:46:10 +03:00
|
|
|
typedef UnresolvedSetImpl::iterator iterator;
|
2009-12-18 13:40:03 +03:00
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo,
|
2009-11-18 10:57:50 +03:00
|
|
|
Sema::LookupNameKind LookupKind,
|
|
|
|
Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
|
|
|
|
: ResultKind(NotFound),
|
|
|
|
Paths(0),
|
2010-01-23 03:46:32 +03:00
|
|
|
NamingClass(0),
|
2009-11-18 10:57:50 +03:00
|
|
|
SemaRef(SemaRef),
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo(NameInfo),
|
|
|
|
LookupKind(LookupKind),
|
|
|
|
IDNS(0),
|
|
|
|
Redecl(Redecl != Sema::NotForRedeclaration),
|
|
|
|
HideTags(true),
|
|
|
|
Diagnose(Redecl == Sema::NotForRedeclaration)
|
|
|
|
{
|
|
|
|
configure();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: consider whether this constructor should be restricted to take
|
|
|
|
// as input a const IndentifierInfo* (instead of Name),
|
|
|
|
// forcing other cases towards the constructor taking a DNInfo.
|
|
|
|
LookupResult(Sema &SemaRef, DeclarationName Name,
|
|
|
|
SourceLocation NameLoc, Sema::LookupNameKind LookupKind,
|
|
|
|
Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
|
|
|
|
: ResultKind(NotFound),
|
|
|
|
Paths(0),
|
|
|
|
NamingClass(0),
|
|
|
|
SemaRef(SemaRef),
|
|
|
|
NameInfo(Name, NameLoc),
|
2009-11-18 10:57:50 +03:00
|
|
|
LookupKind(LookupKind),
|
|
|
|
IDNS(0),
|
|
|
|
Redecl(Redecl != Sema::NotForRedeclaration),
|
|
|
|
HideTags(true),
|
|
|
|
Diagnose(Redecl == Sema::NotForRedeclaration)
|
2009-12-18 13:40:03 +03:00
|
|
|
{
|
|
|
|
configure();
|
|
|
|
}
|
2009-11-18 10:57:50 +03:00
|
|
|
|
|
|
|
/// Creates a temporary lookup result, initializing its core data
|
|
|
|
/// using the information from another result. Diagnostics are always
|
|
|
|
/// disabled.
|
|
|
|
LookupResult(TemporaryToken _, const LookupResult &Other)
|
|
|
|
: ResultKind(NotFound),
|
|
|
|
Paths(0),
|
2010-01-23 03:46:32 +03:00
|
|
|
NamingClass(0),
|
2009-11-18 10:57:50 +03:00
|
|
|
SemaRef(Other.SemaRef),
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo(Other.NameInfo),
|
2009-11-18 10:57:50 +03:00
|
|
|
LookupKind(Other.LookupKind),
|
|
|
|
IDNS(Other.IDNS),
|
|
|
|
Redecl(Other.Redecl),
|
|
|
|
HideTags(Other.HideTags),
|
|
|
|
Diagnose(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~LookupResult() {
|
|
|
|
if (Diagnose) diagnose();
|
|
|
|
if (Paths) deletePaths(Paths);
|
|
|
|
}
|
|
|
|
|
2010-08-12 02:01:17 +04:00
|
|
|
/// Gets the name info to look up.
|
|
|
|
const DeclarationNameInfo &getLookupNameInfo() const {
|
|
|
|
return NameInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Sets the name info to look up.
|
|
|
|
void setLookupNameInfo(const DeclarationNameInfo &NameInfo) {
|
|
|
|
this->NameInfo = NameInfo;
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
/// Gets the name to look up.
|
|
|
|
DeclarationName getLookupName() const {
|
2010-08-12 02:01:17 +04:00
|
|
|
return NameInfo.getName();
|
2009-11-18 10:57:50 +03:00
|
|
|
}
|
|
|
|
|
2009-12-30 20:04:44 +03:00
|
|
|
/// \brief Sets the name to look up.
|
|
|
|
void setLookupName(DeclarationName Name) {
|
2010-08-12 02:01:17 +04:00
|
|
|
NameInfo.setName(Name);
|
2009-12-30 20:04:44 +03:00
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
/// Gets the kind of lookup to perform.
|
|
|
|
Sema::LookupNameKind getLookupKind() const {
|
|
|
|
return LookupKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// True if this lookup is just looking for an existing declaration.
|
|
|
|
bool isForRedeclaration() const {
|
|
|
|
return Redecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets whether tag declarations should be hidden by non-tag
|
|
|
|
/// declarations during resolution. The default is true.
|
|
|
|
void setHideTags(bool Hide) {
|
|
|
|
HideTags = Hide;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAmbiguous() const {
|
|
|
|
return getResultKind() == Ambiguous;
|
|
|
|
}
|
|
|
|
|
2009-11-19 01:49:29 +03:00
|
|
|
/// Determines if this names a single result which is not an
|
|
|
|
/// unresolved value using decl. If so, it is safe to call
|
|
|
|
/// getFoundDecl().
|
|
|
|
bool isSingleResult() const {
|
|
|
|
return getResultKind() == Found;
|
|
|
|
}
|
|
|
|
|
2009-11-22 03:44:51 +03:00
|
|
|
/// Determines if the results are overloaded.
|
|
|
|
bool isOverloadedResult() const {
|
|
|
|
return getResultKind() == FoundOverloaded;
|
|
|
|
}
|
|
|
|
|
2009-12-01 01:42:35 +03:00
|
|
|
bool isUnresolvableResult() const {
|
|
|
|
return getResultKind() == FoundUnresolvedValue;
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
LookupResultKind getResultKind() const {
|
|
|
|
sanity();
|
|
|
|
return ResultKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
AmbiguityKind getAmbiguityKind() const {
|
|
|
|
assert(isAmbiguous());
|
|
|
|
return Ambiguity;
|
|
|
|
}
|
|
|
|
|
2010-01-26 06:27:55 +03:00
|
|
|
const UnresolvedSetImpl &asUnresolvedSet() const {
|
|
|
|
return Decls;
|
|
|
|
}
|
|
|
|
|
2010-01-20 03:46:10 +03:00
|
|
|
iterator begin() const { return iterator(Decls.begin()); }
|
|
|
|
iterator end() const { return iterator(Decls.end()); }
|
2009-11-18 10:57:50 +03:00
|
|
|
|
|
|
|
/// \brief Return true if no decls were found
|
|
|
|
bool empty() const { return Decls.empty(); }
|
|
|
|
|
|
|
|
/// \brief Return the base paths structure that's associated with
|
|
|
|
/// these results, or null if none is.
|
|
|
|
CXXBasePaths *getBasePaths() const {
|
|
|
|
return Paths;
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:40:03 +03:00
|
|
|
/// \brief Tests whether the given declaration is acceptable.
|
|
|
|
bool isAcceptableDecl(NamedDecl *D) const {
|
2010-04-24 05:30:58 +04:00
|
|
|
return D->isInIdentifierNamespace(IDNS);
|
2009-12-18 13:40:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the identifier namespace mask for this lookup.
|
|
|
|
unsigned getIdentifierNamespace() const {
|
|
|
|
return IDNS;
|
|
|
|
}
|
|
|
|
|
2010-01-23 03:46:32 +03:00
|
|
|
/// \brief Returns whether these results arose from performing a
|
|
|
|
/// lookup into a class.
|
|
|
|
bool isClassLookup() const {
|
|
|
|
return NamingClass != 0;
|
|
|
|
}
|
|
|
|
|
2011-05-23 07:43:44 +04:00
|
|
|
/// \brief Set whether the name lookup is triggered by a
|
|
|
|
/// using declaration.
|
|
|
|
void setUsingDeclaration(bool U) {
|
|
|
|
UsingDeclaration = U;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns whether the name lookup is triggered by a
|
|
|
|
/// using declaration.
|
|
|
|
bool isUsingDeclaration() const {
|
|
|
|
return UsingDeclaration;
|
|
|
|
}
|
|
|
|
|
2010-01-23 03:46:32 +03:00
|
|
|
/// \brief Returns the 'naming class' for this lookup, i.e. the
|
|
|
|
/// class which was looked into to find these results.
|
|
|
|
///
|
|
|
|
/// C++0x [class.access.base]p5:
|
|
|
|
/// The access to a member is affected by the class in which the
|
|
|
|
/// member is named. This naming class is the class in which the
|
|
|
|
/// member name was looked up and found. [Note: this class can be
|
|
|
|
/// explicit, e.g., when a qualified-id is used, or implicit,
|
|
|
|
/// e.g., when a class member access operator (5.2.5) is used
|
|
|
|
/// (including cases where an implicit "this->" is added). If both
|
|
|
|
/// a class member access operator and a qualified-id are used to
|
|
|
|
/// name the member (as in p->T::m), the class naming the member
|
|
|
|
/// is the class named by the nested-name-specifier of the
|
|
|
|
/// qualified-id (that is, T). -- end note ]
|
|
|
|
///
|
|
|
|
/// This is set by the lookup routines when they find results in a class.
|
|
|
|
CXXRecordDecl *getNamingClass() const {
|
|
|
|
return NamingClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Sets the 'naming class' for this lookup.
|
|
|
|
void setNamingClass(CXXRecordDecl *Record) {
|
|
|
|
NamingClass = Record;
|
|
|
|
}
|
|
|
|
|
2010-04-07 01:38:20 +04:00
|
|
|
/// \brief Returns the base object type associated with this lookup;
|
|
|
|
/// important for [class.protected]. Most lookups do not have an
|
|
|
|
/// associated base object.
|
|
|
|
QualType getBaseObjectType() const {
|
|
|
|
return BaseObjectType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Sets the base object type for this lookup.
|
|
|
|
void setBaseObjectType(QualType T) {
|
|
|
|
BaseObjectType = T;
|
|
|
|
}
|
|
|
|
|
2010-01-21 00:53:11 +03:00
|
|
|
/// \brief Add a declaration to these results with its natural access.
|
2010-01-20 03:46:10 +03:00
|
|
|
/// Does not test the acceptance criteria.
|
2009-11-18 10:57:50 +03:00
|
|
|
void addDecl(NamedDecl *D) {
|
2010-01-21 00:53:11 +03:00
|
|
|
addDecl(D, D->getAccess());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Add a declaration to these results with the given access.
|
|
|
|
/// Does not test the acceptance criteria.
|
|
|
|
void addDecl(NamedDecl *D, AccessSpecifier AS) {
|
|
|
|
Decls.addDecl(D, AS);
|
2009-11-18 10:57:50 +03:00
|
|
|
ResultKind = Found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Add all the declarations from another set of lookup
|
|
|
|
/// results.
|
|
|
|
void addAllDecls(const LookupResult &Other) {
|
2010-01-20 03:46:10 +03:00
|
|
|
Decls.append(Other.Decls.begin(), Other.Decls.end());
|
2009-11-18 10:57:50 +03:00
|
|
|
ResultKind = Found;
|
|
|
|
}
|
|
|
|
|
2010-01-15 04:44:47 +03:00
|
|
|
/// \brief Determine whether no result was found because we could not
|
|
|
|
/// search into dependent base classes of the current instantiation.
|
|
|
|
bool wasNotFoundInCurrentInstantiation() const {
|
|
|
|
return ResultKind == NotFoundInCurrentInstantiation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Note that while no result was found in the current instantiation,
|
|
|
|
/// there were dependent base classes that could not be searched.
|
|
|
|
void setNotFoundInCurrentInstantiation() {
|
|
|
|
assert(ResultKind == NotFound && Decls.empty());
|
|
|
|
ResultKind = NotFoundInCurrentInstantiation;
|
|
|
|
}
|
|
|
|
|
2009-11-19 01:49:29 +03:00
|
|
|
/// \brief Resolves the result kind of the lookup, possibly hiding
|
|
|
|
/// decls.
|
2009-11-18 10:57:50 +03:00
|
|
|
///
|
|
|
|
/// This should be called in any environment where lookup might
|
|
|
|
/// generate multiple lookup results.
|
|
|
|
void resolveKind();
|
|
|
|
|
2009-11-19 01:49:29 +03:00
|
|
|
/// \brief Re-resolves the result kind of the lookup after a set of
|
|
|
|
/// removals has been performed.
|
|
|
|
void resolveKindAfterFilter() {
|
2010-01-15 04:44:47 +03:00
|
|
|
if (Decls.empty()) {
|
|
|
|
if (ResultKind != NotFoundInCurrentInstantiation)
|
|
|
|
ResultKind = NotFound;
|
2010-10-22 21:36:51 +04:00
|
|
|
|
|
|
|
if (Paths) {
|
|
|
|
deletePaths(Paths);
|
|
|
|
Paths = 0;
|
|
|
|
}
|
2010-01-15 04:44:47 +03:00
|
|
|
} else {
|
2010-08-29 00:17:00 +04:00
|
|
|
AmbiguityKind SavedAK = Ambiguity;
|
2009-11-19 01:49:29 +03:00
|
|
|
ResultKind = Found;
|
|
|
|
resolveKind();
|
2010-08-29 00:17:00 +04:00
|
|
|
|
|
|
|
// If we didn't make the lookup unambiguous, restore the old
|
|
|
|
// ambiguity kind.
|
|
|
|
if (ResultKind == Ambiguous) {
|
|
|
|
Ambiguity = SavedAK;
|
|
|
|
} else if (Paths) {
|
2010-04-13 00:54:26 +04:00
|
|
|
deletePaths(Paths);
|
|
|
|
Paths = 0;
|
|
|
|
}
|
2009-11-19 01:49:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 11:51:07 +03:00
|
|
|
template <class DeclClass>
|
|
|
|
DeclClass *getAsSingle() const {
|
|
|
|
if (getResultKind() != Found) return 0;
|
|
|
|
return dyn_cast<DeclClass>(getFoundDecl());
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
/// \brief Fetch the unique decl found by this lookup. Asserts
|
|
|
|
/// that one was found.
|
|
|
|
///
|
|
|
|
/// This is intended for users who have examined the result kind
|
|
|
|
/// and are certain that there is only one result.
|
|
|
|
NamedDecl *getFoundDecl() const {
|
|
|
|
assert(getResultKind() == Found
|
|
|
|
&& "getFoundDecl called on non-unique result");
|
2010-01-20 03:46:10 +03:00
|
|
|
return (*begin())->getUnderlyingDecl();
|
2009-11-18 10:57:50 +03:00
|
|
|
}
|
|
|
|
|
2009-11-19 01:49:29 +03:00
|
|
|
/// Fetches a representative decl. Useful for lazy diagnostics.
|
|
|
|
NamedDecl *getRepresentativeDecl() const {
|
|
|
|
assert(!Decls.empty() && "cannot get representative of empty set");
|
2010-01-20 03:46:10 +03:00
|
|
|
return *begin();
|
2009-11-19 01:49:29 +03:00
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
/// \brief Asks if the result is a single tag decl.
|
|
|
|
bool isSingleTagDecl() const {
|
|
|
|
return getResultKind() == Found && isa<TagDecl>(getFoundDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Make these results show that the name was found in
|
|
|
|
/// base classes of different types.
|
|
|
|
///
|
|
|
|
/// The given paths object is copied and invalidated.
|
|
|
|
void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P);
|
|
|
|
|
|
|
|
/// \brief Make these results show that the name was found in
|
|
|
|
/// distinct base classes of the same type.
|
|
|
|
///
|
|
|
|
/// The given paths object is copied and invalidated.
|
|
|
|
void setAmbiguousBaseSubobjects(CXXBasePaths &P);
|
|
|
|
|
|
|
|
/// \brief Make these results show that the name was found in
|
|
|
|
/// different contexts and a tag decl was hidden by an ordinary
|
|
|
|
/// decl in a different context.
|
|
|
|
void setAmbiguousQualifiedTagHiding() {
|
|
|
|
setAmbiguous(AmbiguousTagHiding);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Clears out any current state.
|
|
|
|
void clear() {
|
|
|
|
ResultKind = NotFound;
|
|
|
|
Decls.clear();
|
|
|
|
if (Paths) deletePaths(Paths);
|
|
|
|
Paths = NULL;
|
2011-03-05 01:32:08 +03:00
|
|
|
NamingClass = 0;
|
2009-11-18 10:57:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Clears out any current state and re-initializes for a
|
|
|
|
/// different kind of lookup.
|
|
|
|
void clear(Sema::LookupNameKind Kind) {
|
|
|
|
clear();
|
|
|
|
LookupKind = Kind;
|
2009-12-18 13:40:03 +03:00
|
|
|
configure();
|
2009-11-18 10:57:50 +03:00
|
|
|
}
|
|
|
|
|
2010-03-26 00:28:06 +03:00
|
|
|
/// \brief Change this lookup's redeclaration kind.
|
|
|
|
void setRedeclarationKind(Sema::RedeclarationKind RK) {
|
|
|
|
Redecl = RK;
|
|
|
|
configure();
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
void print(llvm::raw_ostream &);
|
|
|
|
|
|
|
|
/// Suppress the diagnostics that would normally fire because of this
|
|
|
|
/// lookup. This happens during (e.g.) redeclaration lookups.
|
|
|
|
void suppressDiagnostics() {
|
|
|
|
Diagnose = false;
|
|
|
|
}
|
|
|
|
|
2010-06-16 12:42:20 +04:00
|
|
|
/// Determines whether this lookup is suppressing diagnostics.
|
|
|
|
bool isSuppressingDiagnostics() const {
|
2010-08-13 06:23:42 +04:00
|
|
|
return !Diagnose;
|
2010-06-16 12:42:20 +04:00
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
/// Sets a 'context' source range.
|
|
|
|
void setContextRange(SourceRange SR) {
|
|
|
|
NameContextRange = SR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the source range of the context of this name; for C++
|
|
|
|
/// qualified lookups, this is the source range of the scope
|
|
|
|
/// specifier.
|
|
|
|
SourceRange getContextRange() const {
|
|
|
|
return NameContextRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the location of the identifier. This isn't always defined:
|
|
|
|
/// sometimes we're doing lookups on synthesized names.
|
|
|
|
SourceLocation getNameLoc() const {
|
2010-08-12 02:01:17 +04:00
|
|
|
return NameInfo.getLoc();
|
2009-11-18 10:57:50 +03:00
|
|
|
}
|
|
|
|
|
2009-12-30 20:04:44 +03:00
|
|
|
/// \brief Get the Sema object that this lookup result is searching
|
|
|
|
/// with.
|
|
|
|
Sema &getSema() const { return SemaRef; }
|
|
|
|
|
2009-11-19 01:49:29 +03:00
|
|
|
/// A class for iterating through a result set and possibly
|
|
|
|
/// filtering out results. The results returned are possibly
|
|
|
|
/// sugared.
|
|
|
|
class Filter {
|
|
|
|
LookupResult &Results;
|
2010-01-20 03:46:10 +03:00
|
|
|
LookupResult::iterator I;
|
2009-11-24 22:00:30 +03:00
|
|
|
bool Changed;
|
2009-11-19 01:49:29 +03:00
|
|
|
bool CalledDone;
|
|
|
|
|
|
|
|
friend class LookupResult;
|
|
|
|
Filter(LookupResult &Results)
|
2010-12-02 19:19:31 +03:00
|
|
|
: Results(Results), I(Results.begin()), Changed(false), CalledDone(false)
|
2009-11-19 01:49:29 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
~Filter() {
|
|
|
|
assert(CalledDone &&
|
|
|
|
"LookupResult::Filter destroyed without done() call");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasNext() const {
|
2010-01-20 03:46:10 +03:00
|
|
|
return I != Results.end();
|
2009-11-19 01:49:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NamedDecl *next() {
|
2010-01-20 03:46:10 +03:00
|
|
|
assert(I != Results.end() && "next() called on empty filter");
|
|
|
|
return *I++;
|
2009-11-19 01:49:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Erase the last element returned from this iterator.
|
|
|
|
void erase() {
|
2010-01-20 03:46:10 +03:00
|
|
|
Results.Decls.erase(--I);
|
2009-11-24 22:00:30 +03:00
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
|
2010-01-20 03:46:10 +03:00
|
|
|
/// Replaces the current entry with the given one, preserving the
|
|
|
|
/// access bits.
|
2009-11-24 22:00:30 +03:00
|
|
|
void replace(NamedDecl *D) {
|
2010-01-20 03:46:10 +03:00
|
|
|
Results.Decls.replace(I-1, D);
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Replaces the current entry with the given one.
|
|
|
|
void replace(NamedDecl *D, AccessSpecifier AS) {
|
|
|
|
Results.Decls.replace(I-1, D, AS);
|
2009-11-24 22:00:30 +03:00
|
|
|
Changed = true;
|
2009-11-19 01:49:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void done() {
|
|
|
|
assert(!CalledDone && "done() called twice");
|
|
|
|
CalledDone = true;
|
|
|
|
|
2009-11-24 22:00:30 +03:00
|
|
|
if (Changed)
|
2009-11-19 01:49:29 +03:00
|
|
|
Results.resolveKindAfterFilter();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Create a filter for this result set.
|
|
|
|
Filter makeFilter() {
|
|
|
|
return Filter(*this);
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
private:
|
|
|
|
void diagnose() {
|
|
|
|
if (isAmbiguous())
|
|
|
|
SemaRef.DiagnoseAmbiguousLookup(*this);
|
2010-01-23 03:46:32 +03:00
|
|
|
else if (isClassLookup() && SemaRef.getLangOptions().AccessControl)
|
2010-02-10 12:31:12 +03:00
|
|
|
SemaRef.CheckLookupAccess(*this);
|
2009-11-18 10:57:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void setAmbiguous(AmbiguityKind AK) {
|
|
|
|
ResultKind = Ambiguous;
|
|
|
|
Ambiguity = AK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addDeclsFromBasePaths(const CXXBasePaths &P);
|
2009-12-18 13:40:03 +03:00
|
|
|
void configure();
|
2009-11-18 10:57:50 +03:00
|
|
|
|
|
|
|
// Sanity checks.
|
2010-08-25 09:32:35 +04:00
|
|
|
void sanity() const;
|
2009-11-18 10:57:50 +03:00
|
|
|
|
2009-11-22 03:44:51 +03:00
|
|
|
bool sanityCheckUnresolved() const {
|
2010-01-20 03:46:10 +03:00
|
|
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
2009-11-22 03:44:51 +03:00
|
|
|
if (isa<UnresolvedUsingValueDecl>(*I))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
static void deletePaths(CXXBasePaths *);
|
|
|
|
|
|
|
|
// Results.
|
|
|
|
LookupResultKind ResultKind;
|
|
|
|
AmbiguityKind Ambiguity; // ill-defined unless ambiguous
|
2010-01-20 03:46:10 +03:00
|
|
|
UnresolvedSet<8> Decls;
|
2009-11-18 10:57:50 +03:00
|
|
|
CXXBasePaths *Paths;
|
2010-01-23 03:46:32 +03:00
|
|
|
CXXRecordDecl *NamingClass;
|
2010-04-07 01:38:20 +04:00
|
|
|
QualType BaseObjectType;
|
2009-11-18 10:57:50 +03:00
|
|
|
|
|
|
|
// Parameters.
|
|
|
|
Sema &SemaRef;
|
2010-08-12 02:01:17 +04:00
|
|
|
DeclarationNameInfo NameInfo;
|
2009-11-18 10:57:50 +03:00
|
|
|
SourceRange NameContextRange;
|
|
|
|
Sema::LookupNameKind LookupKind;
|
2009-12-18 13:40:03 +03:00
|
|
|
unsigned IDNS; // set by configure()
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
bool Redecl;
|
|
|
|
|
|
|
|
/// \brief True if tag declarations should be hidden if non-tags
|
|
|
|
/// are present
|
|
|
|
bool HideTags;
|
|
|
|
|
|
|
|
bool Diagnose;
|
2011-05-23 07:43:44 +04:00
|
|
|
|
|
|
|
/// \brief True if the lookup is triggered by a using declaration.
|
|
|
|
/// Necessary to handle a MSVC bug.
|
|
|
|
bool UsingDeclaration;
|
2009-11-18 10:57:50 +03:00
|
|
|
};
|
|
|
|
|
2009-12-30 20:04:44 +03:00
|
|
|
/// \brief Consumes visible declarations found when searching for
|
|
|
|
/// all visible names within a given scope or context.
|
|
|
|
///
|
|
|
|
/// This abstract class is meant to be subclassed by clients of \c
|
|
|
|
/// Sema::LookupVisibleDecls(), each of which should override the \c
|
|
|
|
/// FoundDecl() function to process declarations as they are found.
|
|
|
|
class VisibleDeclConsumer {
|
|
|
|
public:
|
|
|
|
/// \brief Destroys the visible declaration consumer.
|
|
|
|
virtual ~VisibleDeclConsumer();
|
|
|
|
|
|
|
|
/// \brief Invoked each time \p Sema::LookupVisibleDecls() finds a
|
|
|
|
/// declaration visible from the current scope or context.
|
|
|
|
///
|
|
|
|
/// \param ND the declaration found.
|
|
|
|
///
|
|
|
|
/// \param Hiding a declaration that hides the declaration \p ND,
|
|
|
|
/// or NULL if no such declaration exists.
|
2010-01-14 18:47:35 +03:00
|
|
|
///
|
|
|
|
/// \param InBaseClass whether this declaration was found in base
|
|
|
|
/// class of the context we searched.
|
|
|
|
virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding,
|
|
|
|
bool InBaseClass) = 0;
|
2009-12-30 20:04:44 +03:00
|
|
|
};
|
2010-01-26 10:16:45 +03:00
|
|
|
|
|
|
|
/// \brief A class for storing results from argument-dependent lookup.
|
|
|
|
class ADLResult {
|
|
|
|
private:
|
|
|
|
/// A map from canonical decls to the 'most recent' decl.
|
|
|
|
llvm::DenseMap<NamedDecl*, NamedDecl*> Decls;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Adds a new ADL candidate to this map.
|
|
|
|
void insert(NamedDecl *D);
|
|
|
|
|
|
|
|
/// Removes any data associated with a given decl.
|
|
|
|
void erase(NamedDecl *D) {
|
|
|
|
Decls.erase(cast<NamedDecl>(D->getCanonicalDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
class iterator {
|
|
|
|
typedef llvm::DenseMap<NamedDecl*,NamedDecl*>::iterator inner_iterator;
|
|
|
|
inner_iterator iter;
|
|
|
|
|
|
|
|
friend class ADLResult;
|
|
|
|
iterator(const inner_iterator &iter) : iter(iter) {}
|
|
|
|
public:
|
|
|
|
iterator() {}
|
|
|
|
|
|
|
|
iterator &operator++() { ++iter; return *this; }
|
|
|
|
iterator operator++(int) { return iterator(iter++); }
|
|
|
|
|
|
|
|
NamedDecl *operator*() const { return iter->second; }
|
|
|
|
|
|
|
|
bool operator==(const iterator &other) const { return iter == other.iter; }
|
|
|
|
bool operator!=(const iterator &other) const { return iter != other.iter; }
|
|
|
|
};
|
|
|
|
|
|
|
|
iterator begin() { return iterator(Decls.begin()); }
|
|
|
|
iterator end() { return iterator(Decls.end()); }
|
|
|
|
};
|
|
|
|
|
2009-11-18 10:57:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|