parent
41ee792832
commit
5cebab12d5
|
@ -0,0 +1,392 @@
|
||||||
|
//===--- 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
|
||||||
|
|
||||||
|
#include "Sema.h"
|
||||||
|
|
||||||
|
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.
|
||||||
|
///
|
||||||
|
/// 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 {
|
||||||
|
/// @brief No entity found met the criteria.
|
||||||
|
NotFound = 0,
|
||||||
|
|
||||||
|
/// @brief Name lookup found a single declaration that met the
|
||||||
|
/// criteria. getAsDecl will return this declaration.
|
||||||
|
Found,
|
||||||
|
|
||||||
|
/// @brief Name lookup found a set of overloaded functions that
|
||||||
|
/// met the criteria. getAsDecl will turn this set of overloaded
|
||||||
|
/// functions into an OverloadedFunctionDecl.
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef llvm::SmallVector<NamedDecl*, 4> DeclsTy;
|
||||||
|
typedef DeclsTy::const_iterator iterator;
|
||||||
|
|
||||||
|
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc,
|
||||||
|
Sema::LookupNameKind LookupKind,
|
||||||
|
Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
|
||||||
|
: ResultKind(NotFound),
|
||||||
|
Paths(0),
|
||||||
|
SemaRef(SemaRef),
|
||||||
|
Name(Name),
|
||||||
|
NameLoc(NameLoc),
|
||||||
|
LookupKind(LookupKind),
|
||||||
|
IDNS(0),
|
||||||
|
Redecl(Redecl != Sema::NotForRedeclaration),
|
||||||
|
HideTags(true),
|
||||||
|
Diagnose(Redecl == Sema::NotForRedeclaration)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/// 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),
|
||||||
|
SemaRef(Other.SemaRef),
|
||||||
|
Name(Other.Name),
|
||||||
|
NameLoc(Other.NameLoc),
|
||||||
|
LookupKind(Other.LookupKind),
|
||||||
|
IDNS(Other.IDNS),
|
||||||
|
Redecl(Other.Redecl),
|
||||||
|
HideTags(Other.HideTags),
|
||||||
|
Diagnose(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~LookupResult() {
|
||||||
|
if (Diagnose) diagnose();
|
||||||
|
if (Paths) deletePaths(Paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the name to look up.
|
||||||
|
DeclarationName getLookupName() const {
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The identifier namespace of this lookup. This information is
|
||||||
|
/// private to the lookup routines.
|
||||||
|
unsigned getIdentifierNamespace() const {
|
||||||
|
assert(IDNS);
|
||||||
|
return IDNS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIdentifierNamespace(unsigned NS) {
|
||||||
|
IDNS = NS;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isAmbiguous() const {
|
||||||
|
return getResultKind() == Ambiguous;
|
||||||
|
}
|
||||||
|
|
||||||
|
LookupResultKind getResultKind() const {
|
||||||
|
sanity();
|
||||||
|
return ResultKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
AmbiguityKind getAmbiguityKind() const {
|
||||||
|
assert(isAmbiguous());
|
||||||
|
return Ambiguity;
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator begin() const { return Decls.begin(); }
|
||||||
|
iterator end() const { return Decls.end(); }
|
||||||
|
|
||||||
|
/// \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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Add a declaration to these results.
|
||||||
|
void addDecl(NamedDecl *D) {
|
||||||
|
Decls.push_back(D);
|
||||||
|
ResultKind = Found;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Add all the declarations from another set of lookup
|
||||||
|
/// results.
|
||||||
|
void addAllDecls(const LookupResult &Other) {
|
||||||
|
Decls.append(Other.begin(), Other.end());
|
||||||
|
ResultKind = Found;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Hides a set of declarations.
|
||||||
|
template <class NamedDeclSet> void hideDecls(const NamedDeclSet &Set) {
|
||||||
|
unsigned I = 0, N = Decls.size();
|
||||||
|
while (I < N) {
|
||||||
|
if (Set.count(Decls[I]))
|
||||||
|
Decls[I] = Decls[--N];
|
||||||
|
else
|
||||||
|
I++;
|
||||||
|
}
|
||||||
|
Decls.set_size(N);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Resolves the kind of the lookup, possibly hiding decls.
|
||||||
|
///
|
||||||
|
/// This should be called in any environment where lookup might
|
||||||
|
/// generate multiple lookup results.
|
||||||
|
void resolveKind();
|
||||||
|
|
||||||
|
/// \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;
|
||||||
|
|
||||||
|
/// \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");
|
||||||
|
return Decls[0]->getUnderlyingDecl();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \brief Clears out any current state and re-initializes for a
|
||||||
|
/// different kind of lookup.
|
||||||
|
void clear(Sema::LookupNameKind Kind) {
|
||||||
|
clear();
|
||||||
|
LookupKind = Kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
||||||
|
return NameLoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void diagnose() {
|
||||||
|
if (isAmbiguous())
|
||||||
|
SemaRef.DiagnoseAmbiguousLookup(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAmbiguous(AmbiguityKind AK) {
|
||||||
|
ResultKind = Ambiguous;
|
||||||
|
Ambiguity = AK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addDeclsFromBasePaths(const CXXBasePaths &P);
|
||||||
|
|
||||||
|
// Sanity checks.
|
||||||
|
void sanity() const {
|
||||||
|
assert(ResultKind != NotFound || Decls.size() == 0);
|
||||||
|
assert(ResultKind != Found || Decls.size() == 1);
|
||||||
|
assert(ResultKind == NotFound || ResultKind == Found ||
|
||||||
|
ResultKind == FoundUnresolvedValue ||
|
||||||
|
(ResultKind == Ambiguous && Ambiguity == AmbiguousBaseSubobjects)
|
||||||
|
|| Decls.size() > 1);
|
||||||
|
assert((Paths != NULL) == (ResultKind == Ambiguous &&
|
||||||
|
(Ambiguity == AmbiguousBaseSubobjectTypes ||
|
||||||
|
Ambiguity == AmbiguousBaseSubobjects)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void deletePaths(CXXBasePaths *);
|
||||||
|
|
||||||
|
// Results.
|
||||||
|
LookupResultKind ResultKind;
|
||||||
|
AmbiguityKind Ambiguity; // ill-defined unless ambiguous
|
||||||
|
DeclsTy Decls;
|
||||||
|
CXXBasePaths *Paths;
|
||||||
|
|
||||||
|
// Parameters.
|
||||||
|
Sema &SemaRef;
|
||||||
|
DeclarationName Name;
|
||||||
|
SourceLocation NameLoc;
|
||||||
|
SourceRange NameContextRange;
|
||||||
|
Sema::LookupNameKind LookupKind;
|
||||||
|
unsigned IDNS; // ill-defined until set by lookup
|
||||||
|
bool Redecl;
|
||||||
|
|
||||||
|
/// \brief True if tag declarations should be hidden if non-tags
|
||||||
|
/// are present
|
||||||
|
bool HideTags;
|
||||||
|
|
||||||
|
bool Diagnose;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -93,6 +93,7 @@ namespace clang {
|
||||||
class FunctionProtoType;
|
class FunctionProtoType;
|
||||||
class CXXBasePaths;
|
class CXXBasePaths;
|
||||||
class CXXTemporary;
|
class CXXTemporary;
|
||||||
|
class LookupResult;
|
||||||
|
|
||||||
/// BlockSemaInfo - When a block is being parsed, this contains information
|
/// BlockSemaInfo - When a block is being parsed, this contains information
|
||||||
/// about the block. It is pointed to from Sema::CurBlock.
|
/// about the block. It is pointed to from Sema::CurBlock.
|
||||||
|
@ -1081,382 +1082,12 @@ public:
|
||||||
LookupObjCCategoryImplName
|
LookupObjCCategoryImplName
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Represents the results of name lookup.
|
enum RedeclarationKind {
|
||||||
///
|
NotForRedeclaration,
|
||||||
/// An instance of the LookupResult class captures the results of a
|
ForRedeclaration
|
||||||
/// 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.
|
|
||||||
///
|
|
||||||
/// 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 {
|
|
||||||
/// @brief No entity found met the criteria.
|
|
||||||
NotFound = 0,
|
|
||||||
|
|
||||||
/// @brief Name lookup found a single declaration that met the
|
|
||||||
/// criteria. getAsDecl will return this declaration.
|
|
||||||
Found,
|
|
||||||
|
|
||||||
/// @brief Name lookup found a set of overloaded functions that
|
|
||||||
/// met the criteria. getAsDecl will turn this set of overloaded
|
|
||||||
/// functions into an OverloadedFunctionDecl.
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
enum RedeclarationKind {
|
|
||||||
NotForRedeclaration,
|
|
||||||
ForRedeclaration
|
|
||||||
};
|
|
||||||
|
|
||||||
/// A little identifier for flagging temporary lookup results.
|
|
||||||
enum TemporaryToken {
|
|
||||||
Temporary
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef llvm::SmallVector<NamedDecl*, 4> DeclsTy;
|
|
||||||
typedef DeclsTy::const_iterator iterator;
|
|
||||||
|
|
||||||
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc,
|
|
||||||
LookupNameKind LookupKind,
|
|
||||||
RedeclarationKind Redecl = NotForRedeclaration)
|
|
||||||
: ResultKind(NotFound),
|
|
||||||
Paths(0),
|
|
||||||
SemaRef(SemaRef),
|
|
||||||
Name(Name),
|
|
||||||
NameLoc(NameLoc),
|
|
||||||
LookupKind(LookupKind),
|
|
||||||
IDNS(0),
|
|
||||||
Redecl(Redecl != NotForRedeclaration),
|
|
||||||
HideTags(true),
|
|
||||||
Diagnose(Redecl == NotForRedeclaration)
|
|
||||||
{}
|
|
||||||
|
|
||||||
/// 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),
|
|
||||||
SemaRef(Other.SemaRef),
|
|
||||||
Name(Other.Name),
|
|
||||||
NameLoc(Other.NameLoc),
|
|
||||||
LookupKind(Other.LookupKind),
|
|
||||||
IDNS(Other.IDNS),
|
|
||||||
Redecl(Other.Redecl),
|
|
||||||
HideTags(Other.HideTags),
|
|
||||||
Diagnose(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~LookupResult() {
|
|
||||||
if (Diagnose) diagnose();
|
|
||||||
if (Paths) deletePaths(Paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the name to look up.
|
|
||||||
DeclarationName getLookupName() const {
|
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the kind of lookup to perform.
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The identifier namespace of this lookup. This information is
|
|
||||||
/// private to the lookup routines.
|
|
||||||
unsigned getIdentifierNamespace() const {
|
|
||||||
assert(IDNS);
|
|
||||||
return IDNS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setIdentifierNamespace(unsigned NS) {
|
|
||||||
IDNS = NS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isAmbiguous() const {
|
|
||||||
return getResultKind() == Ambiguous;
|
|
||||||
}
|
|
||||||
|
|
||||||
LookupResultKind getResultKind() const {
|
|
||||||
sanity();
|
|
||||||
return ResultKind;
|
|
||||||
}
|
|
||||||
|
|
||||||
AmbiguityKind getAmbiguityKind() const {
|
|
||||||
assert(isAmbiguous());
|
|
||||||
return Ambiguity;
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator begin() const { return Decls.begin(); }
|
|
||||||
iterator end() const { return Decls.end(); }
|
|
||||||
|
|
||||||
/// \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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Add a declaration to these results.
|
|
||||||
void addDecl(NamedDecl *D) {
|
|
||||||
Decls.push_back(D);
|
|
||||||
ResultKind = Found;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Add all the declarations from another set of lookup
|
|
||||||
/// results.
|
|
||||||
void addAllDecls(const LookupResult &Other) {
|
|
||||||
Decls.append(Other.begin(), Other.end());
|
|
||||||
ResultKind = Found;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Hides a set of declarations.
|
|
||||||
template <class NamedDeclSet> void hideDecls(const NamedDeclSet &Set) {
|
|
||||||
unsigned I = 0, N = Decls.size();
|
|
||||||
while (I < N) {
|
|
||||||
if (Set.count(Decls[I]))
|
|
||||||
Decls[I] = Decls[--N];
|
|
||||||
else
|
|
||||||
I++;
|
|
||||||
}
|
|
||||||
Decls.set_size(N);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Resolves the kind of the lookup, possibly hiding decls.
|
|
||||||
///
|
|
||||||
/// This should be called in any environment where lookup might
|
|
||||||
/// generate multiple lookup results.
|
|
||||||
void resolveKind();
|
|
||||||
|
|
||||||
/// \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;
|
|
||||||
|
|
||||||
/// \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");
|
|
||||||
return Decls[0]->getUnderlyingDecl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Clears out any current state and re-initializes for a
|
|
||||||
/// different kind of lookup.
|
|
||||||
void clear(LookupNameKind Kind) {
|
|
||||||
clear();
|
|
||||||
LookupKind = Kind;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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 {
|
|
||||||
return NameLoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void diagnose() {
|
|
||||||
if (isAmbiguous())
|
|
||||||
SemaRef.DiagnoseAmbiguousLookup(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAmbiguous(AmbiguityKind AK) {
|
|
||||||
ResultKind = Ambiguous;
|
|
||||||
Ambiguity = AK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addDeclsFromBasePaths(const CXXBasePaths &P);
|
|
||||||
|
|
||||||
// Sanity checks.
|
|
||||||
void sanity() const {
|
|
||||||
assert(ResultKind != NotFound || Decls.size() == 0);
|
|
||||||
assert(ResultKind != Found || Decls.size() == 1);
|
|
||||||
assert(ResultKind == NotFound || ResultKind == Found ||
|
|
||||||
ResultKind == FoundUnresolvedValue ||
|
|
||||||
(ResultKind == Ambiguous && Ambiguity == AmbiguousBaseSubobjects)
|
|
||||||
|| Decls.size() > 1);
|
|
||||||
assert((Paths != NULL) == (ResultKind == Ambiguous &&
|
|
||||||
(Ambiguity == AmbiguousBaseSubobjectTypes ||
|
|
||||||
Ambiguity == AmbiguousBaseSubobjects)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void deletePaths(CXXBasePaths *);
|
|
||||||
|
|
||||||
// Results.
|
|
||||||
LookupResultKind ResultKind;
|
|
||||||
AmbiguityKind Ambiguity; // ill-defined unless ambiguous
|
|
||||||
DeclsTy Decls;
|
|
||||||
CXXBasePaths *Paths;
|
|
||||||
|
|
||||||
// Parameters.
|
|
||||||
Sema &SemaRef;
|
|
||||||
DeclarationName Name;
|
|
||||||
SourceLocation NameLoc;
|
|
||||||
SourceRange NameContextRange;
|
|
||||||
LookupNameKind LookupKind;
|
|
||||||
unsigned IDNS; // ill-defined until set by lookup
|
|
||||||
bool Redecl;
|
|
||||||
|
|
||||||
/// \brief True if tag declarations should be hidden if non-tags
|
|
||||||
/// are present
|
|
||||||
bool HideTags;
|
|
||||||
|
|
||||||
bool Diagnose;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
|
|
||||||
|
|
||||||
bool CppLookupName(LookupResult &R, Scope *S);
|
bool CppLookupName(LookupResult &R, Scope *S);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -1497,12 +1128,8 @@ public:
|
||||||
/// ambiguity and overloaded.
|
/// ambiguity and overloaded.
|
||||||
NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
|
NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
|
||||||
LookupNameKind NameKind,
|
LookupNameKind NameKind,
|
||||||
LookupResult::RedeclarationKind Redecl
|
RedeclarationKind Redecl
|
||||||
= LookupResult::NotForRedeclaration) {
|
= NotForRedeclaration);
|
||||||
LookupResult R(*this, Name, SourceLocation(), NameKind, Redecl);
|
|
||||||
LookupName(R, S);
|
|
||||||
return R.getAsSingleDecl(Context);
|
|
||||||
}
|
|
||||||
bool LookupName(LookupResult &R, Scope *S,
|
bool LookupName(LookupResult &R, Scope *S,
|
||||||
bool AllowBuiltinCreation = false);
|
bool AllowBuiltinCreation = false);
|
||||||
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx);
|
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx);
|
||||||
|
@ -4063,7 +3690,6 @@ private:
|
||||||
void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
|
void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
|
// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/Expr.h"
|
#include "clang/AST/Expr.h"
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/DeclTemplate.h"
|
#include "clang/AST/DeclTemplate.h"
|
||||||
#include "clang/AST/ExprCXX.h"
|
#include "clang/AST/ExprCXX.h"
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/APValue.h"
|
#include "clang/AST/APValue.h"
|
||||||
#include "clang/AST/ASTConsumer.h"
|
#include "clang/AST/ASTConsumer.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
|
@ -1426,7 +1427,7 @@ bool Sema::InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
|
||||||
F != FEnd; ++F) {
|
F != FEnd; ++F) {
|
||||||
if ((*F)->getDeclName()) {
|
if ((*F)->getDeclName()) {
|
||||||
LookupResult R(*this, (*F)->getDeclName(), SourceLocation(),
|
LookupResult R(*this, (*F)->getDeclName(), SourceLocation(),
|
||||||
LookupOrdinaryName, LookupResult::ForRedeclaration);
|
LookupOrdinaryName, ForRedeclaration);
|
||||||
LookupQualifiedName(R, Owner);
|
LookupQualifiedName(R, Owner);
|
||||||
NamedDecl *PrevDecl = R.getAsSingleDecl(Context);
|
NamedDecl *PrevDecl = R.getAsSingleDecl(Context);
|
||||||
if (PrevDecl && !isa<TagDecl>(PrevDecl)) {
|
if (PrevDecl && !isa<TagDecl>(PrevDecl)) {
|
||||||
|
@ -1795,7 +1796,7 @@ Sema::HandleDeclarator(Scope *S, Declarator &D,
|
||||||
|
|
||||||
DC = CurContext;
|
DC = CurContext;
|
||||||
LookupResult R(*this, Name, D.getIdentifierLoc(), NameKind,
|
LookupResult R(*this, Name, D.getIdentifierLoc(), NameKind,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
|
|
||||||
LookupName(R, S, NameKind == LookupRedeclarationWithLinkage);
|
LookupName(R, S, NameKind == LookupRedeclarationWithLinkage);
|
||||||
PrevDecl = R.getAsSingleDecl(Context);
|
PrevDecl = R.getAsSingleDecl(Context);
|
||||||
|
@ -1819,7 +1820,7 @@ Sema::HandleDeclarator(Scope *S, Declarator &D,
|
||||||
return DeclPtrTy();
|
return DeclPtrTy();
|
||||||
|
|
||||||
LookupResult Res(*this, Name, D.getIdentifierLoc(), LookupOrdinaryName,
|
LookupResult Res(*this, Name, D.getIdentifierLoc(), LookupOrdinaryName,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
LookupQualifiedName(Res, DC);
|
LookupQualifiedName(Res, DC);
|
||||||
PrevDecl = Res.getAsSingleDecl(Context);
|
PrevDecl = Res.getAsSingleDecl(Context);
|
||||||
|
|
||||||
|
@ -2937,7 +2938,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
|
||||||
NewFD->setInvalidDecl();
|
NewFD->setInvalidDecl();
|
||||||
|
|
||||||
LookupResult Prev(*this, Name, D.getIdentifierLoc(), LookupOrdinaryName,
|
LookupResult Prev(*this, Name, D.getIdentifierLoc(), LookupOrdinaryName,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
LookupQualifiedName(Prev, DC);
|
LookupQualifiedName(Prev, DC);
|
||||||
assert(!Prev.isAmbiguous() &&
|
assert(!Prev.isAmbiguous() &&
|
||||||
"Cannot have an ambiguity in previous-declaration lookup");
|
"Cannot have an ambiguity in previous-declaration lookup");
|
||||||
|
@ -4316,8 +4317,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
|
||||||
bool isStdBadAlloc = false;
|
bool isStdBadAlloc = false;
|
||||||
bool Invalid = false;
|
bool Invalid = false;
|
||||||
|
|
||||||
LookupResult::RedeclarationKind Redecl =
|
RedeclarationKind Redecl = (RedeclarationKind) (TUK != TUK_Reference);
|
||||||
(LookupResult::RedeclarationKind) (TUK != TUK_Reference);
|
|
||||||
|
|
||||||
if (Name && SS.isNotEmpty()) {
|
if (Name && SS.isNotEmpty()) {
|
||||||
// We have a nested-name tag ('struct foo::bar').
|
// We have a nested-name tag ('struct foo::bar').
|
||||||
|
@ -4631,7 +4631,7 @@ CreateNewDecl:
|
||||||
// that is declared in that scope and refers to a type other
|
// that is declared in that scope and refers to a type other
|
||||||
// than the class or enumeration itself.
|
// than the class or enumeration itself.
|
||||||
LookupResult Lookup(*this, Name, NameLoc, LookupOrdinaryName,
|
LookupResult Lookup(*this, Name, NameLoc, LookupOrdinaryName,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
LookupName(Lookup, S);
|
LookupName(Lookup, S);
|
||||||
TypedefDecl *PrevTypedef = 0;
|
TypedefDecl *PrevTypedef = 0;
|
||||||
if (NamedDecl *Prev = Lookup.getAsSingleDecl(Context))
|
if (NamedDecl *Prev = Lookup.getAsSingleDecl(Context))
|
||||||
|
@ -4852,7 +4852,7 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
|
||||||
Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
|
Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
|
||||||
|
|
||||||
NamedDecl *PrevDecl = LookupSingleName(S, II, LookupMemberName,
|
NamedDecl *PrevDecl = LookupSingleName(S, II, LookupMemberName,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
|
|
||||||
if (PrevDecl && PrevDecl->isTemplateParameter()) {
|
if (PrevDecl && PrevDecl->isTemplateParameter()) {
|
||||||
// Maybe we will complain about the shadowed template parameter.
|
// Maybe we will complain about the shadowed template parameter.
|
||||||
|
@ -5238,7 +5238,7 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S,
|
||||||
|
|
||||||
if (II) {
|
if (II) {
|
||||||
NamedDecl *PrevDecl = LookupSingleName(S, II, LookupMemberName,
|
NamedDecl *PrevDecl = LookupSingleName(S, II, LookupMemberName,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S)
|
if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S)
|
||||||
&& !isa<TagDecl>(PrevDecl)) {
|
&& !isa<TagDecl>(PrevDecl)) {
|
||||||
Diag(Loc, diag::err_duplicate_member) << II;
|
Diag(Loc, diag::err_duplicate_member) << II;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/ASTConsumer.h"
|
#include "clang/AST/ASTConsumer.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/CXXInheritance.h"
|
#include "clang/AST/CXXInheritance.h"
|
||||||
|
@ -2639,7 +2640,7 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
|
||||||
|
|
||||||
NamedDecl *PrevDecl
|
NamedDecl *PrevDecl
|
||||||
= LookupSingleName(DeclRegionScope, II, LookupOrdinaryName,
|
= LookupSingleName(DeclRegionScope, II, LookupOrdinaryName,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
|
|
||||||
if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) {
|
if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) {
|
||||||
// This is an extended namespace definition.
|
// This is an extended namespace definition.
|
||||||
|
@ -3028,8 +3029,7 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
|
||||||
|
|
||||||
// Check if we have a previous declaration with the same name.
|
// Check if we have a previous declaration with the same name.
|
||||||
if (NamedDecl *PrevDecl
|
if (NamedDecl *PrevDecl
|
||||||
= LookupSingleName(S, Alias, LookupOrdinaryName,
|
= LookupSingleName(S, Alias, LookupOrdinaryName, ForRedeclaration)) {
|
||||||
LookupResult::ForRedeclaration)) {
|
|
||||||
if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(PrevDecl)) {
|
if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(PrevDecl)) {
|
||||||
// We already have an alias with the same name that points to the same
|
// We already have an alias with the same name that points to the same
|
||||||
// namespace, so don't create a new one.
|
// namespace, so don't create a new one.
|
||||||
|
@ -4676,8 +4676,7 @@ Sema::ActOnFriendFunctionDecl(Scope *S,
|
||||||
// FIXME: handle dependent contexts
|
// FIXME: handle dependent contexts
|
||||||
if (!DC) return DeclPtrTy();
|
if (!DC) return DeclPtrTy();
|
||||||
|
|
||||||
LookupResult R(*this, Name, Loc, LookupOrdinaryName,
|
LookupResult R(*this, Name, Loc, LookupOrdinaryName, ForRedeclaration);
|
||||||
LookupResult::ForRedeclaration);
|
|
||||||
LookupQualifiedName(R, DC);
|
LookupQualifiedName(R, DC);
|
||||||
PrevDecl = R.getAsSingleDecl(Context);
|
PrevDecl = R.getAsSingleDecl(Context);
|
||||||
|
|
||||||
|
@ -4712,8 +4711,7 @@ Sema::ActOnFriendFunctionDecl(Scope *S,
|
||||||
while (DC->isRecord())
|
while (DC->isRecord())
|
||||||
DC = DC->getParent();
|
DC = DC->getParent();
|
||||||
|
|
||||||
LookupResult R(*this, Name, Loc, LookupOrdinaryName,
|
LookupResult R(*this, Name, Loc, LookupOrdinaryName, ForRedeclaration);
|
||||||
LookupResult::ForRedeclaration);
|
|
||||||
LookupQualifiedName(R, DC);
|
LookupQualifiedName(R, DC);
|
||||||
PrevDecl = R.getAsSingleDecl(Context);
|
PrevDecl = R.getAsSingleDecl(Context);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/DeclObjC.h"
|
#include "clang/AST/DeclObjC.h"
|
||||||
#include "clang/AST/DeclTemplate.h"
|
#include "clang/AST/DeclTemplate.h"
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/CXXInheritance.h"
|
#include "clang/AST/CXXInheritance.h"
|
||||||
#include "clang/AST/ExprCXX.h"
|
#include "clang/AST/ExprCXX.h"
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/CXXInheritance.h"
|
#include "clang/AST/CXXInheritance.h"
|
||||||
#include "clang/AST/Decl.h"
|
#include "clang/AST/Decl.h"
|
||||||
|
@ -237,11 +238,11 @@ getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Necessary because CXXBasePaths is not complete in Sema.h
|
// Necessary because CXXBasePaths is not complete in Sema.h
|
||||||
void Sema::LookupResult::deletePaths(CXXBasePaths *Paths) {
|
void LookupResult::deletePaths(CXXBasePaths *Paths) {
|
||||||
delete Paths;
|
delete Paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::LookupResult::resolveKind() {
|
void LookupResult::resolveKind() {
|
||||||
unsigned N = Decls.size();
|
unsigned N = Decls.size();
|
||||||
|
|
||||||
// Fast case: no possible ambiguity.
|
// Fast case: no possible ambiguity.
|
||||||
|
@ -337,7 +338,7 @@ void Sema::LookupResult::resolveKind() {
|
||||||
/// solution, since it causes the OverloadedFunctionDecl to be
|
/// solution, since it causes the OverloadedFunctionDecl to be
|
||||||
/// leaked. FIXME: Eventually, there will be a better way to iterate
|
/// leaked. FIXME: Eventually, there will be a better way to iterate
|
||||||
/// over the set of overloaded functions returned by name lookup.
|
/// over the set of overloaded functions returned by name lookup.
|
||||||
NamedDecl *Sema::LookupResult::getAsSingleDecl(ASTContext &C) const {
|
NamedDecl *LookupResult::getAsSingleDecl(ASTContext &C) const {
|
||||||
size_t size = Decls.size();
|
size_t size = Decls.size();
|
||||||
if (size == 0) return 0;
|
if (size == 0) return 0;
|
||||||
if (size == 1) return (*begin())->getUnderlyingDecl();
|
if (size == 1) return (*begin())->getUnderlyingDecl();
|
||||||
|
@ -362,7 +363,7 @@ NamedDecl *Sema::LookupResult::getAsSingleDecl(ASTContext &C) const {
|
||||||
return Ovl;
|
return Ovl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) {
|
void LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) {
|
||||||
CXXBasePaths::paths_iterator I, E;
|
CXXBasePaths::paths_iterator I, E;
|
||||||
DeclContext::lookup_iterator DI, DE;
|
DeclContext::lookup_iterator DI, DE;
|
||||||
for (I = P.begin(), E = P.end(); I != E; ++I)
|
for (I = P.begin(), E = P.end(); I != E; ++I)
|
||||||
|
@ -370,7 +371,7 @@ void Sema::LookupResult::addDeclsFromBasePaths(const CXXBasePaths &P) {
|
||||||
addDecl(*DI);
|
addDecl(*DI);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::LookupResult::setAmbiguousBaseSubobjects(CXXBasePaths &P) {
|
void LookupResult::setAmbiguousBaseSubobjects(CXXBasePaths &P) {
|
||||||
Paths = new CXXBasePaths;
|
Paths = new CXXBasePaths;
|
||||||
Paths->swap(P);
|
Paths->swap(P);
|
||||||
addDeclsFromBasePaths(*Paths);
|
addDeclsFromBasePaths(*Paths);
|
||||||
|
@ -378,7 +379,7 @@ void Sema::LookupResult::setAmbiguousBaseSubobjects(CXXBasePaths &P) {
|
||||||
setAmbiguous(AmbiguousBaseSubobjects);
|
setAmbiguous(AmbiguousBaseSubobjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) {
|
void LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) {
|
||||||
Paths = new CXXBasePaths;
|
Paths = new CXXBasePaths;
|
||||||
Paths->swap(P);
|
Paths->swap(P);
|
||||||
addDeclsFromBasePaths(*Paths);
|
addDeclsFromBasePaths(*Paths);
|
||||||
|
@ -386,7 +387,7 @@ void Sema::LookupResult::setAmbiguousBaseSubobjectTypes(CXXBasePaths &P) {
|
||||||
setAmbiguous(AmbiguousBaseSubobjectTypes);
|
setAmbiguous(AmbiguousBaseSubobjectTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::LookupResult::print(llvm::raw_ostream &Out) {
|
void LookupResult::print(llvm::raw_ostream &Out) {
|
||||||
Out << Decls.size() << " result(s)";
|
Out << Decls.size() << " result(s)";
|
||||||
if (isAmbiguous()) Out << ", ambiguous";
|
if (isAmbiguous()) Out << ", ambiguous";
|
||||||
if (Paths) Out << ", base paths present";
|
if (Paths) Out << ", base paths present";
|
||||||
|
@ -399,8 +400,7 @@ void Sema::LookupResult::print(llvm::raw_ostream &Out) {
|
||||||
|
|
||||||
// Adds all qualifying matches for a name within a decl context to the
|
// Adds all qualifying matches for a name within a decl context to the
|
||||||
// given lookup result. Returns true if any matches were found.
|
// given lookup result. Returns true if any matches were found.
|
||||||
static bool LookupDirect(Sema::LookupResult &R,
|
static bool LookupDirect(LookupResult &R, const DeclContext *DC) {
|
||||||
const DeclContext *DC) {
|
|
||||||
bool Found = false;
|
bool Found = false;
|
||||||
|
|
||||||
DeclContext::lookup_const_iterator I, E;
|
DeclContext::lookup_const_iterator I, E;
|
||||||
|
@ -414,7 +414,7 @@ static bool LookupDirect(Sema::LookupResult &R,
|
||||||
|
|
||||||
// Performs C++ unqualified lookup into the given file context.
|
// Performs C++ unqualified lookup into the given file context.
|
||||||
static bool
|
static bool
|
||||||
CppNamespaceLookup(Sema::LookupResult &R, ASTContext &Context, DeclContext *NS,
|
CppNamespaceLookup(LookupResult &R, ASTContext &Context, DeclContext *NS,
|
||||||
UnqualUsingDirectiveSet &UDirs) {
|
UnqualUsingDirectiveSet &UDirs) {
|
||||||
|
|
||||||
assert(NS && NS->isFileContext() && "CppNamespaceLookup() requires namespace!");
|
assert(NS && NS->isFileContext() && "CppNamespaceLookup() requires namespace!");
|
||||||
|
@ -768,7 +768,7 @@ bool Sema::LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation) {
|
||||||
/// class or enumeration name if and only if the declarations are
|
/// class or enumeration name if and only if the declarations are
|
||||||
/// from the same namespace; otherwise (the declarations are from
|
/// from the same namespace; otherwise (the declarations are from
|
||||||
/// different namespaces), the program is ill-formed.
|
/// different namespaces), the program is ill-formed.
|
||||||
static bool LookupQualifiedNameInUsingDirectives(Sema::LookupResult &R,
|
static bool LookupQualifiedNameInUsingDirectives(LookupResult &R,
|
||||||
DeclContext *StartDC) {
|
DeclContext *StartDC) {
|
||||||
assert(StartDC->isFileContext() && "start context is not a file context");
|
assert(StartDC->isFileContext() && "start context is not a file context");
|
||||||
|
|
||||||
|
@ -800,7 +800,7 @@ static bool LookupQualifiedNameInUsingDirectives(Sema::LookupResult &R,
|
||||||
bool FoundTag = false;
|
bool FoundTag = false;
|
||||||
bool FoundNonTag = false;
|
bool FoundNonTag = false;
|
||||||
|
|
||||||
Sema::LookupResult LocalR(Sema::LookupResult::Temporary, R);
|
LookupResult LocalR(LookupResult::Temporary, R);
|
||||||
|
|
||||||
bool Found = false;
|
bool Found = false;
|
||||||
while (!Queue.empty()) {
|
while (!Queue.empty()) {
|
||||||
|
@ -810,7 +810,7 @@ static bool LookupQualifiedNameInUsingDirectives(Sema::LookupResult &R,
|
||||||
// We go through some convolutions here to avoid copying results
|
// We go through some convolutions here to avoid copying results
|
||||||
// between LookupResults.
|
// between LookupResults.
|
||||||
bool UseLocal = !R.empty();
|
bool UseLocal = !R.empty();
|
||||||
Sema::LookupResult &DirectR = UseLocal ? LocalR : R;
|
LookupResult &DirectR = UseLocal ? LocalR : R;
|
||||||
bool FoundDirect = LookupDirect(DirectR, ND);
|
bool FoundDirect = LookupDirect(DirectR, ND);
|
||||||
|
|
||||||
if (FoundDirect) {
|
if (FoundDirect) {
|
||||||
|
@ -1601,6 +1601,14 @@ IsAcceptableNonMemberOperatorCandidate(FunctionDecl *Fn,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NamedDecl *Sema::LookupSingleName(Scope *S, DeclarationName Name,
|
||||||
|
LookupNameKind NameKind,
|
||||||
|
RedeclarationKind Redecl) {
|
||||||
|
LookupResult R(*this, Name, SourceLocation(), NameKind, Redecl);
|
||||||
|
LookupName(R, S);
|
||||||
|
return R.getAsSingleDecl(Context);
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Find the protocol with the given name, if any.
|
/// \brief Find the protocol with the given name, if any.
|
||||||
ObjCProtocolDecl *Sema::LookupProtocol(IdentifierInfo *II) {
|
ObjCProtocolDecl *Sema::LookupProtocol(IdentifierInfo *II) {
|
||||||
Decl *D = LookupSingleName(TUScope, II, LookupObjCProtocolName);
|
Decl *D = LookupSingleName(TUScope, II, LookupObjCProtocolName);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/Basic/Diagnostic.h"
|
#include "clang/Basic/Diagnostic.h"
|
||||||
#include "clang/Lex/Preprocessor.h"
|
#include "clang/Lex/Preprocessor.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
//===----------------------------------------------------------------------===/
|
//===----------------------------------------------------------------------===/
|
||||||
|
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "TreeTransform.h"
|
#include "TreeTransform.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/Expr.h"
|
#include "clang/AST/Expr.h"
|
||||||
|
@ -629,7 +630,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
|
||||||
// Find any previous declaration with this name.
|
// Find any previous declaration with this name.
|
||||||
DeclContext *SemanticContext;
|
DeclContext *SemanticContext;
|
||||||
LookupResult Previous(*this, Name, NameLoc, LookupOrdinaryName,
|
LookupResult Previous(*this, Name, NameLoc, LookupOrdinaryName,
|
||||||
LookupResult::ForRedeclaration);
|
ForRedeclaration);
|
||||||
if (SS.isNotEmpty() && !SS.isInvalid()) {
|
if (SS.isNotEmpty() && !SS.isInvalid()) {
|
||||||
if (RequireCompleteDeclContext(SS))
|
if (RequireCompleteDeclContext(SS))
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===/
|
//===----------------------------------------------------------------------===/
|
||||||
#include "Sema.h"
|
#include "Sema.h"
|
||||||
|
#include "Lookup.h"
|
||||||
#include "clang/AST/ASTConsumer.h"
|
#include "clang/AST/ASTConsumer.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/DeclTemplate.h"
|
#include "clang/AST/DeclTemplate.h"
|
||||||
|
@ -684,9 +685,9 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
||||||
// Look only into the namespace where the friend would be declared to
|
// Look only into the namespace where the friend would be declared to
|
||||||
// find a previous declaration. This is the innermost enclosing namespace,
|
// find a previous declaration. This is the innermost enclosing namespace,
|
||||||
// as described in ActOnFriendFunctionDecl.
|
// as described in ActOnFriendFunctionDecl.
|
||||||
Sema::LookupResult R(SemaRef, Function->getDeclName(), SourceLocation(),
|
LookupResult R(SemaRef, Function->getDeclName(), SourceLocation(),
|
||||||
Sema::LookupOrdinaryName,
|
Sema::LookupOrdinaryName,
|
||||||
Sema::LookupResult::ForRedeclaration);
|
Sema::ForRedeclaration);
|
||||||
SemaRef.LookupQualifiedName(R, DC);
|
SemaRef.LookupQualifiedName(R, DC);
|
||||||
|
|
||||||
PrevDecl = R.getAsSingleDecl(SemaRef.Context);
|
PrevDecl = R.getAsSingleDecl(SemaRef.Context);
|
||||||
|
@ -845,9 +846,9 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
|
||||||
NamedDecl *PrevDecl = 0;
|
NamedDecl *PrevDecl = 0;
|
||||||
|
|
||||||
if (!FunctionTemplate || TemplateParams) {
|
if (!FunctionTemplate || TemplateParams) {
|
||||||
Sema::LookupResult R(SemaRef, Name, SourceLocation(),
|
LookupResult R(SemaRef, Name, SourceLocation(),
|
||||||
Sema::LookupOrdinaryName,
|
Sema::LookupOrdinaryName,
|
||||||
Sema::LookupResult::ForRedeclaration);
|
Sema::ForRedeclaration);
|
||||||
SemaRef.LookupQualifiedName(R, Owner);
|
SemaRef.LookupQualifiedName(R, Owner);
|
||||||
PrevDecl = R.getAsSingleDecl(SemaRef.Context);
|
PrevDecl = R.getAsSingleDecl(SemaRef.Context);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue