clang API Documentation

Defines | Functions | Variables
SemaLookup.cpp File Reference
#include "clang/Sema/Lookup.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclLookups.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Lex/ModuleLoader.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ExternalSemaSource.h"
#include "clang/Sema/Overload.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/TemplateDeduction.h"
#include "clang/Sema/TypoCorrection.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/ADT/edit_distance.h"
#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include "clang/AST/TypeNodes.def"
Include dependency graph for SemaLookup.cpp:

Go to the source code of this file.

Defines

#define TYPE(Class, Base)
#define DEPENDENT_TYPE(Class, Base)   case Type::Class:
#define NON_CANONICAL_TYPE(Class, Base)   case Type::Class:
#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)   case Type::Class:
#define ABSTRACT_TYPE(Class, Base)

Functions

static unsigned getIDNS (Sema::LookupNameKind NameKind, bool CPlusPlus, bool Redeclaration)
static DeclContextgetContextForScopeMatching (Decl *D)
static bool LookupBuiltin (Sema &S, LookupResult &R)
 Lookup a builtin function, when name lookup would otherwise fail.
static bool CanDeclareSpecialMemberFunction (const CXXRecordDecl *Class)
 Determine whether we can declare a special member function within the class at this point.
static bool isImplicitlyDeclaredMemberFunctionName (DeclarationName Name)
 Determine whether this is the name of an implicitly-declared special member function.
static void DeclareImplicitMemberFunctionsWithName (Sema &S, DeclarationName Name, const DeclContext *DC)
 If there are any implicit member functions with the given name that need to be declared in the given declaration context, do so.
static bool LookupDirect (Sema &S, LookupResult &R, const DeclContext *DC)
static bool CppNamespaceLookup (Sema &S, LookupResult &R, ASTContext &Context, DeclContext *NS, UnqualUsingDirectiveSet &UDirs)
static bool isNamespaceOrTranslationUnitScope (Scope *S)
static std::pair< DeclContext
*, bool
findOuterContext (Scope *S)
static DeclgetInstantiatedFrom (Decl *D, MemberSpecializationInfo *MSInfo)
 Find the declaration that a class temploid member specialization was instantiated from, or the member itself if it is an explicit specialization.
static ModulegetDefiningModule (Decl *Entity)
 Find the module in which the given declaration was defined.
static NamedDeclfindAcceptableDecl (Sema &SemaRef, NamedDecl *D)
 Retrieve the visible declaration corresponding to D, if any.
static bool LookupQualifiedNameInUsingDirectives (Sema &S, LookupResult &R, DeclContext *StartDC)
 Perform qualified name lookup in the namespaces nominated by using directives by the given context.
static bool LookupAnyMember (const CXXBaseSpecifier *Specifier, CXXBasePath &Path, void *Name)
 Callback that looks for any member of a class with the given name.
template<typename InputIterator >
static bool HasOnlyStaticMembers (InputIterator First, InputIterator Last)
 Determine whether the given set of member declarations contains only static members, nested types, and enumerators.
static void addAssociatedClassesAndNamespaces (AssociatedLookup &Result, QualType T)
static void CollectEnclosingNamespace (Sema::AssociatedNamespaceSet &Namespaces, DeclContext *Ctx)
static void addAssociatedClassesAndNamespaces (AssociatedLookup &Result, const TemplateArgument &Arg)
static void addAssociatedClassesAndNamespaces (AssociatedLookup &Result, CXXRecordDecl *Class)
static void LookupVisibleDecls (DeclContext *Ctx, LookupResult &Result, bool QualifiedNameLookup, bool InBaseClass, VisibleDeclConsumer &Consumer, VisibleDeclsRecord &Visited)
static void LookupVisibleDecls (Scope *S, LookupResult &Result, UnqualUsingDirectiveSet &UDirs, VisibleDeclConsumer &Consumer, VisibleDeclsRecord &Visited)
static bool isCandidateViable (CorrectionCandidateCallback &CCC, TypoCorrection &Candidate)
static void LookupPotentialTypoResult (Sema &SemaRef, LookupResult &Res, IdentifierInfo *Name, Scope *S, CXXScopeSpec *SS, DeclContext *MemberContext, bool EnteringContext, bool isObjCIvarLookup, bool FindHidden)
 Perform name lookup for a possible result for typo correction.
static void checkCorrectionVisibility (Sema &SemaRef, TypoCorrection &TC)
 Check whether the declarations found for a typo correction are visible, and if none of them are, convert the correction to an 'import a module' correction.
static void getNestedNameSpecifierIdentifiers (NestedNameSpecifier *NNS, SmallVectorImpl< const IdentifierInfo * > &Identifiers)
static void AddKeywordsToConsumer (Sema &SemaRef, TypoCorrectionConsumer &Consumer, Scope *S, CorrectionCandidateCallback &CCC, bool AfterNestedNameSpecifier)
 Add keywords to the consumer as possible typo corrections.
static const NamedDeclgetDefinitionToImport (const NamedDecl *D)

Variables

static const unsigned MaxTypoDistanceResultSets = 5

Define Documentation

#define ABSTRACT_TYPE (   Class,
  Base 
)
#define DEPENDENT_TYPE (   Class,
  Base 
)    case Type::Class:
#define NON_CANONICAL_TYPE (   Class,
  Base 
)    case Type::Class:
#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE (   Class,
  Base 
)    case Type::Class:
#define TYPE (   Class,
  Base 
)

Function Documentation

static void addAssociatedClassesAndNamespaces ( AssociatedLookup &  Result,
QualType  T 
) [static]
static void addAssociatedClassesAndNamespaces ( AssociatedLookup &  Result,
const TemplateArgument Arg 
) [static]
static void addAssociatedClassesAndNamespaces ( AssociatedLookup &  Result,
CXXRecordDecl Class 
) [static]
static void AddKeywordsToConsumer ( Sema SemaRef,
TypoCorrectionConsumer Consumer,
Scope S,
CorrectionCandidateCallback CCC,
bool  AfterNestedNameSpecifier 
) [static]
static bool CanDeclareSpecialMemberFunction ( const CXXRecordDecl Class) [static]
static void checkCorrectionVisibility ( Sema SemaRef,
TypoCorrection TC 
) [static]

Check whether the declarations found for a typo correction are visible, and if none of them are, convert the correction to an 'import a module' correction.

Definition at line 3284 of file SemaLookup.cpp.

References clang::TypoCorrection::begin(), clang::TypoCorrection::end(), findAcceptableDecl(), clang::LookupResult::isVisible(), clang::TypoCorrection::setCorrectionDecls(), and clang::TypoCorrection::setRequiresImport().

Referenced by clang::TypoCorrectionConsumer::addCorrection(), and clang::Sema::CorrectTypo().

static void CollectEnclosingNamespace ( Sema::AssociatedNamespaceSet Namespaces,
DeclContext Ctx 
) [static]
static bool CppNamespaceLookup ( Sema S,
LookupResult R,
ASTContext Context,
DeclContext NS,
UnqualUsingDirectiveSet &  UDirs 
) [static]
static void DeclareImplicitMemberFunctionsWithName ( Sema S,
DeclarationName  Name,
const DeclContext DC 
) [static]
static NamedDecl* findAcceptableDecl ( Sema SemaRef,
NamedDecl D 
) [static]

Retrieve the visible declaration corresponding to D, if any.

This routine determines whether the declaration D is visible in the current module, with the current imports. If not, it checks whether any redeclaration of D is visible, and if so, returns that declaration.

Returns:
D, or a visible previous declaration of D, whichever is more recent and visible. If no declaration of D is visible, returns null.

Definition at line 1254 of file SemaLookup.cpp.

References clang::LookupResult::isVisible(), and clang::Decl::redecls().

Referenced by checkCorrectionVisibility(), and clang::TypoCorrectionConsumer::FoundDecl().

static std::pair<DeclContext *, bool> findOuterContext ( Scope S) [static]
static DeclContext* getContextForScopeMatching ( Decl D) [static]

Get a representative context for a declaration such that two declarations will have the same context if they were found within the same scope.

Definition at line 340 of file SemaLookup.cpp.

References clang::Decl::getDeclContext(), clang::Decl::getLexicalDeclContext(), clang::DeclContext::getRedeclContext(), and clang::DeclContext::isFunctionOrMethod().

Referenced by clang::LookupResult::resolveKind().

static Module* getDefiningModule ( Decl Entity) [static]
static const NamedDecl* getDefinitionToImport ( const NamedDecl D) [static]

Find which declaration we should import to provide the definition of the given declaration.

Definition at line 4509 of file SemaLookup.cpp.

Referenced by clang::Sema::diagnoseTypo().

static unsigned getIDNS ( Sema::LookupNameKind  NameKind,
bool  CPlusPlus,
bool  Redeclaration 
) [inline, static]
static Decl* getInstantiatedFrom ( Decl D,
MemberSpecializationInfo MSInfo 
) [static]

Find the declaration that a class temploid member specialization was instantiated from, or the member itself if it is an explicit specialization.

Definition at line 1166 of file SemaLookup.cpp.

References clang::MemberSpecializationInfo::getInstantiatedFrom(), and clang::MemberSpecializationInfo::isExplicitSpecialization().

Referenced by getDefiningModule().

static void getNestedNameSpecifierIdentifiers ( NestedNameSpecifier NNS,
SmallVectorImpl< const IdentifierInfo * > &  Identifiers 
) [static]
template<typename InputIterator >
static bool HasOnlyStaticMembers ( InputIterator  First,
InputIterator  Last 
) [static]

Determine whether the given set of member declarations contains only static members, nested types, and enumerators.

Definition at line 1532 of file SemaLookup.cpp.

References clang::NamedDecl::getUnderlyingDecl(), and clang::LangAS::Last.

Referenced by clang::Sema::LookupQualifiedName().

static bool isCandidateViable ( CorrectionCandidateCallback CCC,
TypoCorrection Candidate 
) [static]
static bool isNamespaceOrTranslationUnitScope ( Scope S) [static]
static bool LookupAnyMember ( const CXXBaseSpecifier Specifier,
CXXBasePath Path,
void *  Name 
) [static]

Callback that looks for any member of a class with the given name.

Definition at line 1519 of file SemaLookup.cpp.

References clang::CXXBasePath::Decls, clang::Type::getAs(), clang::DeclarationName::getFromOpaquePtr(), clang::CXXBaseSpecifier::getType(), and clang::DeclContext::lookup().

Referenced by clang::Sema::LookupQualifiedName().

static bool LookupBuiltin ( Sema S,
LookupResult R 
) [static]
static bool LookupDirect ( Sema S,
LookupResult R,
const DeclContext DC 
) [static]
static void LookupPotentialTypoResult ( Sema SemaRef,
LookupResult Res,
IdentifierInfo Name,
Scope S,
CXXScopeSpec SS,
DeclContext MemberContext,
bool  EnteringContext,
bool  isObjCIvarLookup,
bool  FindHidden 
) [static]
static bool LookupQualifiedNameInUsingDirectives ( Sema S,
LookupResult R,
DeclContext StartDC 
) [static]

Perform qualified name lookup in the namespaces nominated by using directives by the given context.

C++98 [namespace.qual]p2: Given X::m (where X is a user-declared namespace), or given ::m (where X is the global namespace), let S be the set of all declarations of m in X and in the transitive closure of all namespaces nominated by using-directives in X and its used namespaces, except that using-directives are ignored in any namespace, including X, directly containing one or more declarations of m. No namespace is searched more than once in the lookup of a name. If S is the empty set, the program is ill-formed. Otherwise, if S has exactly one member, or if the context of the reference is a using-declaration (namespace.udecl), S is the required set of declarations of m. Otherwise if the use of m is not one that allows a unique declaration to be chosen from S, the program is ill-formed.

C++98 [namespace.qual]p5: During the lookup of a qualified namespace member name, if the lookup finds more than one declaration of the member, and if one declaration introduces a class name or enumeration name and the other declarations either introduce the same object, the same enumerator or a set of functions, the non-type name hides the class or enumeration name if and only if the declarations are from the same namespace; otherwise (the declarations are from different namespaces), the program is ill-formed.

Definition at line 1436 of file SemaLookup.cpp.

References clang::LookupResult::addAllDecls(), clang::LookupResult::clear(), clang::LookupResult::empty(), clang::DeclContext::isFileContext(), clang::LookupResult::isSingleTagDecl(), LookupDirect(), clang::LookupResult::resolveKind(), clang::LookupResult::setAmbiguousQualifiedTagHiding(), clang::LookupResult::Temporary, and clang::DeclContext::using_directives().

Referenced by clang::Sema::LookupQualifiedName().

static void LookupVisibleDecls ( DeclContext Ctx,
LookupResult Result,
bool  QualifiedNameLookup,
bool  InBaseClass,
VisibleDeclConsumer Consumer,
VisibleDeclsRecord &  Visited 
) [static]
static void LookupVisibleDecls ( Scope S,
LookupResult Result,
UnqualUsingDirectiveSet &  UDirs,
VisibleDeclConsumer Consumer,
VisibleDeclsRecord &  Visited 
) [static]

Variable Documentation

const unsigned MaxTypoDistanceResultSets = 5 [static]

Definition at line 3420 of file SemaLookup.cpp.

Referenced by clang::TypoCorrectionConsumer::addCorrection().