class DeclContext

Declaration

class DeclContext { /* full declaration omitted */ };

Description

DeclContext - This is used only as base class of specific decl types that can act as declaration contexts. These decls are (only the top classes that directly derive from DeclContext are mentioned, not their subclasses): TranslationUnitDecl ExternCContext NamespaceDecl TagDecl OMPDeclareReductionDecl OMPDeclareMapperDecl FunctionDecl ObjCMethodDecl ObjCContainerDecl LinkageSpecDecl ExportDecl BlockDecl CapturedDecl

Declared at: clang/include/clang/AST/DeclBase.h:1378

Member Variables

private clang::StoredDeclsMap* LookupPtr = nullptr
Pointer to the data structure used to lookup declarations within this context (or a DependentStoredDeclsMap if this is a dependent context). We maintain the invariant that, if the map contains an entry for a DeclarationName (and we haven't lazily omitted anything), then it contains all relevant entries for that name (modulo the hasExternalDecls() flag).
protected anonymous struct / union
protected clang::Decl* FirstDecl = nullptr
FirstDecl - The first declaration stored within this declaration context.
protected clang::Decl* LastDecl = nullptr
LastDecl - The last declaration stored within this declaration context. FIXME: We could probably cache this value somewhere outside of the DeclContext, to reduce the size of DeclContext by another pointer.

Method Overview

Methods

static std::pair<Decl*, Decl*> BuildDeclChain(
    ArrayRef<clang::Decl*> Decls,
    bool FieldsAlreadyLoaded)

Description

Build up a chain of declarations.

Declared at: clang/include/clang/AST/DeclBase.h:1890

Parameters

ArrayRef<clang::Decl*> Decls
bool FieldsAlreadyLoaded

Returns

the first/last pair of declarations.

clang::StoredDeclsMap* CreateStoredDeclsMap(
    clang::ASTContext& C) const

Declared at: clang/include/clang/AST/DeclBase.h:2575

Parameters

clang::ASTContext& C

DeclContext(Decl::Kind K)

Declared at: clang/include/clang/AST/DeclBase.h:1892

Parameters

Decl::Kind K

bool Encloses(const clang::DeclContext* DC) const

Description

Determine whether this declaration context encloses the declaration context DC.

Declared at: clang/include/clang/AST/DeclBase.h:2034

Parameters

const clang::DeclContext* DC

bool Equals(const clang::DeclContext* DC) const

Description

Determine whether this declaration context is equivalent to the declaration context DC.

Declared at: clang/include/clang/AST/DeclBase.h:2028

Parameters

const clang::DeclContext* DC

bool InEnclosingNamespaceSetOf(
    const clang::DeclContext* NS) const

Description

Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [namespace.def]p9. If either context isn't a namespace, this is equivalent to Equals(). The enclosing namespace set of a namespace is the namespace and, if it is inline, its enclosing namespace, recursively.

Declared at: clang/include/clang/AST/DeclBase.h:2087

Parameters

const clang::DeclContext* NS

bool LoadLexicalDeclsFromExternalStorage() const

Declared at: clang/include/clang/AST/DeclBase.h:2565

void addDecl(clang::Decl* D)

Description

Add the declaration D into this context. This routine should be invoked when the declaration D has first been declared, to place D into the context where it was (lexically) defined. Every declaration must be added to one (and only one!) context, where it can be visited via [decls_begin(), decls_end()). Once a declaration has been added to its lexical context, the corresponding DeclContext owns the declaration. If D is also a NamedDecl, it will be made visible within its semantic context via makeDeclVisibleInContext.

Declared at: clang/include/clang/AST/DeclBase.h:2333

Parameters

clang::Decl* D

void addDeclInternal(clang::Decl* D)

Description

Add the declaration D into this context, but suppress searches for external declarations with the same name. Although analogous in function to addDecl, this removes an important check. This is only useful if the Decl is being added in response to an external search; in all other cases, addDecl() is the right function to use. See the ASTImporter for use cases.

Declared at: clang/include/clang/AST/DeclBase.h:2343

Parameters

clang::Decl* D

void addHiddenDecl(clang::Decl* D)

Description

Add the declaration D to this context without modifying any lookup tables. This is useful for some operations in dependent contexts where the semantic context might not be dependent; this basically only happens with friends.

Declared at: clang/include/clang/AST/DeclBase.h:2351

Parameters

clang::Decl* D

clang::StoredDeclsMap* buildLookup()

Description

Ensure the lookup structure is fully-built and return it.

Declared at: clang/include/clang/AST/DeclBase.h:2470

void buildLookupImpl(clang::DeclContext* DCtx,
                     bool Internal)

Declared at: clang/include/clang/AST/DeclBase.h:2578

Parameters

clang::DeclContext* DCtx
bool Internal

static bool classof(const clang::DeclContext* D)

Declared at: clang/include/clang/AST/DeclBase.h:2516

Parameters

const clang::DeclContext* D

static bool classof(const clang::Decl* D)

Declared at: clang/include/clang/AST/DeclBase.h:2515

Parameters

const clang::Decl* D

void collectAllContexts(
    SmallVectorImpl<clang::DeclContext*>&
        Contexts)

Description

Collects all of the declaration contexts that are semantically connected to this declaration context. For declaration contexts that have multiple semantically connected but syntactically distinct contexts, such as C++ namespaces, this routine retrieves the complete set of such declaration contexts in source order. For example, given: The \c Contexts parameter will contain both definitions of N.

Declared at: clang/include/clang/AST/DeclBase.h:2112

Parameters

SmallVectorImpl<clang::DeclContext*>& Contexts
Will be cleared and set to the set of declaration contexts that are semanticaly connected to this declaration context, in source order, including this context (which may be the only result, for non-namespace contexts).

bool containsDecl(clang::Decl* D) const

Description

Checks whether a declaration is in this context.

Declared at: clang/include/clang/AST/DeclBase.h:2357

Parameters

clang::Decl* D

bool containsDeclAndLoad(clang::Decl* D) const

Description

Checks whether a declaration is in this context. This also loads the Decls from the external source before the check.

Declared at: clang/include/clang/AST/DeclBase.h:2361

Parameters

clang::Decl* D

inline clang::DeclContext::ddiag_range ddiags()
    const

Declared at: clang/include/clang/AST/DeclBase.h:2449

clang::DeclContext::decl_range decls() const

Description

decls_begin/decls_end - Iterate over the declarations stored in this context.

Declared at: clang/include/clang/AST/DeclBase.h:2159

clang::DeclContext::decl_iterator decls_begin()
    const

Declared at: clang/include/clang/AST/DeclBase.h:2160

bool decls_empty() const

Declared at: clang/include/clang/AST/DeclBase.h:2162

clang::DeclContext::decl_iterator decls_end()
    const

Declared at: clang/include/clang/AST/DeclBase.h:2161

void dumpDeclContext() const

Declared at: clang/include/clang/AST/DeclBase.h:2518

void dumpLookups(llvm::raw_ostream& OS,
                 bool DumpDecls = false,
                 bool Deserialize = false) const

Declared at: clang/include/clang/AST/DeclBase.h:2520

Parameters

llvm::raw_ostream& OS
bool DumpDecls = false
bool Deserialize = false

void dumpLookups() const

Declared at: clang/include/clang/AST/DeclBase.h:2519

Decl::Kind getDeclKind() const

Declared at: clang/include/clang/AST/DeclBase.h:1897

const char* getDeclKindName() const

Declared at: clang/include/clang/AST/DeclBase.h:1901

const clang::DeclContext*
getEnclosingNamespaceContext() const

Declared at: clang/include/clang/AST/DeclBase.h:2071

clang::DeclContext* getEnclosingNamespaceContext()

Description

Retrieve the nearest enclosing namespace context.

Declared at: clang/include/clang/AST/DeclBase.h:2070

const clang::LinkageSpecDecl* getExternCContext()
    const

Description

Retrieve the nearest enclosing C linkage specification context.

Declared at: clang/include/clang/AST/DeclBase.h:2020

const clang::BlockDecl* getInnermostBlockDecl()
    const

Description

Return this DeclContext if it is a BlockDecl. Otherwise, return the innermost enclosing BlockDecl or null if there are no enclosing blocks.

Declared at: clang/include/clang/AST/DeclBase.h:1941

const clang::DeclContext* getLexicalParent() const

Declared at: clang/include/clang/AST/DeclBase.h:1923

clang::DeclContext* getLexicalParent()

Description

getLexicalParent - Returns the containing lexical DeclContext. May be different from getParent, e.g.: namespace A { struct S; } struct A::S {}; // getParent() == namespace 'A' // getLexicalParent() == translation unit

Declared at: clang/include/clang/AST/DeclBase.h:1920

const clang::DeclContext* getLookupParent() const

Declared at: clang/include/clang/AST/DeclBase.h:1929

clang::DeclContext* getLookupParent()

Declared at: clang/include/clang/AST/DeclBase.h:1927

clang::StoredDeclsMap* getLookupPtr() const

Description

Retrieve the internal representation of the lookup structure. This may omit some names if we are lazily building the structure.

Declared at: clang/include/clang/AST/DeclBase.h:2467

clang::Decl* getNonClosureAncestor()

Description

Find the nearest non-closure ancestor of this context, i.e. the innermost semantic parent of this context which is not a closure. A context may be its own non-closure ancestor.

Declared at: clang/include/clang/AST/DeclBase.h:2039

const clang::Decl* getNonClosureAncestor() const

Declared at: clang/include/clang/AST/DeclBase.h:2040

clang::DeclContext* getNonTransparentContext()

Declared at: clang/include/clang/AST/DeclBase.h:2045

const clang::DeclContext*
getNonTransparentContext() const

Declared at: clang/include/clang/AST/DeclBase.h:2046

clang::RecordDecl* getOuterLexicalRecordContext()

Description

Retrieve the outermost lexically enclosing record context.

Declared at: clang/include/clang/AST/DeclBase.h:2076

const clang::RecordDecl*
getOuterLexicalRecordContext() const

Declared at: clang/include/clang/AST/DeclBase.h:2077

clang::DeclContext* getParent()

Description

getParent - Returns the containing DeclContext.

Declared at: clang/include/clang/AST/DeclBase.h:1904

const clang::DeclContext* getParent() const

Declared at: clang/include/clang/AST/DeclBase.h:1907

clang::ASTContext& getParentASTContext() const

Declared at: clang/include/clang/AST/DeclBase.h:1933

clang::DeclContext* getPrimaryContext()

Description

getPrimaryContext - There may be many different declarations of the same entity (including forward declarations of classes, multiple definitions of namespaces, etc.), each with a different set of declarations. This routine returns the "primary" DeclContext structure, which will contain the information needed to perform name lookup into this context.

Declared at: clang/include/clang/AST/DeclBase.h:2056

const clang::DeclContext* getPrimaryContext()
    const

Declared at: clang/include/clang/AST/DeclBase.h:2057

const clang::DeclContext* getRedeclContext() const

Declared at: clang/include/clang/AST/DeclBase.h:2065

clang::DeclContext* getRedeclContext()

Description

getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same name, or where it is a redeclaration if the two entities are compatible. This skips through transparent contexts.

Declared at: clang/include/clang/AST/DeclBase.h:2064

bool hasExternalLexicalStorage() const

Description

Whether this DeclContext has external storage containing additional declarations that are lexically in this context.

Declared at: clang/include/clang/AST/DeclBase.h:2474

bool hasExternalVisibleStorage() const

Description

Whether this DeclContext has external storage containing additional declarations that are visible in this context.

Declared at: clang/include/clang/AST/DeclBase.h:2486

bool hasLazyExternalLexicalLookups() const

Description

If \c true, the external source may have lexical declarations that are missing from the lookup table.

Declared at: clang/include/clang/AST/DeclBase.h:2554

bool hasLazyLocalLexicalLookups() const

Description

If \c true, this context may have local lexical declarations that are missing from the lookup table.

Declared at: clang/include/clang/AST/DeclBase.h:2542

bool hasNeedToReconcileExternalVisibleStorage()
    const

Description

Whether this declaration context has had externally visible storage added since the last lookup. In this case, \c LookupPtr's invariant may not hold and needs to be fixed before we perform another lookup.

Declared at: clang/include/clang/AST/DeclBase.h:2528

bool isClosure() const

Declared at: clang/include/clang/AST/DeclBase.h:1937

bool isDeclInLexicalTraversal(
    const clang::Decl* D) const

Description

Determine whether the given declaration is stored in the list of declarations lexically within this context.

Declared at: clang/include/clang/AST/DeclBase.h:2500

Parameters

const clang::Decl* D

bool isDependentContext() const

Description

Determines whether this context is dependent on a template parameter.

Declared at: clang/include/clang/AST/DeclBase.h:1996

bool isExternCContext() const

Description

Determines whether this context or some of its ancestors is a linkage specification context that specifies C linkage.

Declared at: clang/include/clang/AST/DeclBase.h:2017

bool isExternCXXContext() const

Description

Determines whether this context or some of its ancestors is a linkage specification context that specifies C++ linkage.

Declared at: clang/include/clang/AST/DeclBase.h:2024

bool isFileContext() const

Declared at: clang/include/clang/AST/DeclBase.h:1974

bool isFunctionOrMethod() const

Declared at: clang/include/clang/AST/DeclBase.h:1956

bool isInlineNamespace() const

Declared at: clang/include/clang/AST/DeclBase.h:1992

bool isLookupContext() const

Description

Test whether the context supports looking up names.

Declared at: clang/include/clang/AST/DeclBase.h:1969

bool isNamespace() const

Declared at: clang/include/clang/AST/DeclBase.h:1988

bool isObjCContainer() const

Declared at: clang/include/clang/AST/DeclBase.h:1943

bool isRecord() const

Declared at: clang/include/clang/AST/DeclBase.h:1983

bool isStdNamespace() const

Declared at: clang/include/clang/AST/DeclBase.h:1990

bool isTranslationUnit() const

Declared at: clang/include/clang/AST/DeclBase.h:1979

bool isTransparentContext() const

Description

isTransparentContext - Determines whether this context is a "transparent" context, meaning that the members declared in this context are semantically declared in the nearest enclosing non-transparent (opaque) context but are lexically declared in this context. For example, consider the enumerators of an enumeration type: Here, E is a transparent context, so its enumerator (Val1) will appear (semantically) that it is in the same context of E. Examples of transparent contexts include: enumerations (except for C++0x scoped enums), and C++ linkage specifications.

Declared at: clang/include/clang/AST/DeclBase.h:2013

void loadLazyLocalLexicalLookups()

Declared at: clang/include/clang/AST/DeclBase.h:2577

void localUncachedLookup(
    clang::DeclarationName Name,
    SmallVectorImpl<clang::NamedDecl*>& Results)

Description

A simplistic name lookup mechanism that performs name lookup into this declaration context without consulting the external source. This function should almost never be used, because it subverts the usual relationship between a DeclContext and the external source. See the ASTImporter for the (few, but important) use cases. FIXME: This is very inefficient; replace uses of it with uses of noload_lookup.

Declared at: clang/include/clang/AST/DeclBase.h:2387

Parameters

clang::DeclarationName Name
SmallVectorImpl<clang::NamedDecl*>& Results

clang::DeclContext::lookup_result lookup(
    clang::DeclarationName Name) const

Description

lookup - Find the declarations (if any) with the given Name in this context. Returns a range of iterators that contains all of the declarations with this name, with object, function, member, and enumerator names preceding any tag name. Note that this routine will not look into parent contexts.

Declared at: clang/include/clang/AST/DeclBase.h:2371

Parameters

clang::DeclarationName Name

clang::DeclContext::lookups_range lookups() const

Declared at: clang/include/clang/AST/DeclBase.h:2412

clang::DeclContext::all_lookups_iterator
lookups_begin() const

Description

Iterators over all possible lookups within this context.

Declared at: clang/include/clang/AST/DeclBase.h:2418

clang::DeclContext::all_lookups_iterator
lookups_end() const

Declared at: clang/include/clang/AST/DeclBase.h:2419

void makeDeclVisibleInContext(clang::NamedDecl* D)

Description

Makes a declaration visible within this context. This routine makes the declaration D visible to name lookup within this context and, if this is a transparent context, within its parent contexts up to the first enclosing non-transparent context. Making a declaration visible within a context does not transfer ownership of a declaration, and a declaration can be visible in many contexts that aren't its lexical context. If D is a redeclaration of an existing declaration that is visible from this context, as determined by NamedDecl::declarationReplaces, the previous declaration will be replaced with D.

Declared at: clang/include/clang/AST/DeclBase.h:2404

Parameters

clang::NamedDecl* D

void makeDeclVisibleInContextImpl(
    clang::NamedDecl* D,
    bool Internal)

Declared at: clang/include/clang/AST/DeclBase.h:2581

Parameters

clang::NamedDecl* D
bool Internal

void makeDeclVisibleInContextInternal(
    clang::NamedDecl* D)

Description

Makes a declaration visible within this context, but suppresses searches for external declarations with the same name. Analogous to makeDeclVisibleInContext, but for the exclusive use of addDeclInternal().

Declared at: clang/include/clang/AST/DeclBase.h:2573

Parameters

clang::NamedDecl* D

void makeDeclVisibleInContextWithFlags(
    clang::NamedDecl* D,
    bool Internal,
    bool Rediscoverable)

Declared at: clang/include/clang/AST/DeclBase.h:2579

Parameters

clang::NamedDecl* D
bool Internal
bool Rediscoverable

clang::DeclContext::decl_range noload_decls()
    const

Description

noload_decls_begin/end - Iterate over the declarations stored in this context that are currently loaded; don't attempt to retrieve anything from an external source.

Declared at: clang/include/clang/AST/DeclBase.h:2167

clang::DeclContext::decl_iterator
noload_decls_begin() const

Declared at: clang/include/clang/AST/DeclBase.h:2170

clang::DeclContext::decl_iterator
noload_decls_end() const

Declared at: clang/include/clang/AST/DeclBase.h:2171

clang::DeclContext::lookup_result noload_lookup(
    clang::DeclarationName Name)

Description

Find the declarations with the given name that are visible within this context; don't attempt to retrieve anything from an external source.

Declared at: clang/include/clang/AST/DeclBase.h:2376

Parameters

clang::DeclarationName Name

clang::DeclContext::lookups_range noload_lookups(
    bool PreserveInternalState) const

Declared at: clang/include/clang/AST/DeclBase.h:2415

Parameters

bool PreserveInternalState

clang::DeclContext::all_lookups_iterator
noload_lookups_begin() const

Description

Iterators over all possible lookups within this context that are currently loaded; don't attempt to retrieve anything from an external source.

Declared at: clang/include/clang/AST/DeclBase.h:2424

clang::DeclContext::all_lookups_iterator
noload_lookups_end() const

Declared at: clang/include/clang/AST/DeclBase.h:2425

void reconcileExternalVisibleStorage() const

Declared at: clang/include/clang/AST/DeclBase.h:2564

void removeDecl(clang::Decl* D)

Description

Removes a declaration from this context.

Declared at: clang/include/clang/AST/DeclBase.h:2354

Parameters

clang::Decl* D

void setHasExternalLexicalStorage(
    bool ES = true) const

Description

State whether this DeclContext has external storage for declarations lexically in this context.

Declared at: clang/include/clang/AST/DeclBase.h:2480

Parameters

bool ES = true

void setHasExternalVisibleStorage(
    bool ES = true) const

Description

State whether this DeclContext has external storage for declarations visible in this context.

Declared at: clang/include/clang/AST/DeclBase.h:2492

Parameters

bool ES = true

void setHasLazyExternalLexicalLookups(
    bool HasLELL = true) const

Description

If \c true, the external source may have lexical declarations that are missing from the lookup table.

Declared at: clang/include/clang/AST/DeclBase.h:2560

Parameters

bool HasLELL = true

void setHasLazyLocalLexicalLookups(
    bool HasLLLL = true) const

Description

If \c true, this context may have local lexical declarations that are missing from the lookup table.

Declared at: clang/include/clang/AST/DeclBase.h:2548

Parameters

bool HasLLLL = true

void setMustBuildLookupTable()

Description

Mark that there are external lexical declarations that we need to include in our lookup table (and that are not available as external visible lookups). These extra lookup results will be found by walking the lexical declarations of this context. This should be used only if setHasExternalLexicalStorage() has been called on any decl context for which this is the primary context.

Declared at: clang/include/clang/AST/DeclBase.h:2459

void setNeedToReconcileExternalVisibleStorage(
    bool Need = true) const

Description

State that this declaration context has had externally visible storage added since the last lookup. In this case, \c LookupPtr's invariant may not hold and needs to be fixed before we perform another lookup.

Declared at: clang/include/clang/AST/DeclBase.h:2536

Parameters

bool Need = true

bool setUseQualifiedLookup(bool use = true) const

Declared at: clang/include/clang/AST/DeclBase.h:2505

Parameters

bool use = true

bool shouldUseQualifiedLookup() const

Declared at: clang/include/clang/AST/DeclBase.h:2511

clang::DeclContext::udir_range using_directives()
    const

Declared at: clang/include/clang/AST/DeclBase.h:2442

~DeclContext()

Declared at: clang/include/clang/AST/DeclBase.h:1895