class Declarator

Declaration

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

Description

Information about one declarator, including the parsed type information and the identifier. When the declarator is fully formed, this is turned into the appropriate Decl object. Declarators come in two types: normal declarators and abstract declarators. Abstract declarators are used when parsing types, and don't have an identifier. Normal declarators do have ID's. Instances of this class should be a transient object that lives on the stack, not objects that are allocated in large quantities on the heap.

Declared at: clang/include/clang/Sema/DeclSpec.h:1805

Member Variables

private const clang::DeclSpec& DS
private clang::CXXScopeSpec SS
private clang::UnqualifiedId Name
private clang::SourceRange Range
private clang::DeclaratorContext Context
Where we are parsing this declarator.
private clang::DecompositionDeclarator BindingGroup
The C++17 structured binding, if any. This is an alternative to a Name.
private SmallVector<clang::DeclaratorChunk, 8> DeclTypeInfo
DeclTypeInfo - This holds each type that the declarator includes as it is parsed. This is pushed from the identifier out, which means that element #0 will be the most closely bound to the identifier, and DeclTypeInfo.back() will be the least closely bound.
private unsigned int InvalidType
InvalidType - Set by Sema::GetTypeForDeclarator().
private unsigned int GroupingParens
GroupingParens - Set by Parser::ParseParenDeclarator().
private unsigned int FunctionDefinition
Actually a FunctionDefinitionKind.
private unsigned int Redeclaration
Is this Declarator a redeclaration?
private unsigned int Extension
true if the declaration is preceded by \c __extension__.
private unsigned int ObjCIvar
Indicates whether this is an Objective-C instance variable.
private unsigned int ObjCWeakProperty
Indicates whether this is an Objective-C 'weak' property.
private unsigned int InlineStorageUsed
Indicates whether the InlineParams / InlineBindings storage has been used.
private unsigned int HasInitializer
Indicates whether this declarator has an initializer.
private clang::ParsedAttributes Attrs
Attributes attached to the declarator.
private const clang::ParsedAttributesView& DeclarationAttrs
Attributes attached to the declaration. See also documentation for the corresponding constructor parameter.
private clang::Expr* AsmLabel
The asm label, if specified.
private clang::Expr* TrailingRequiresClause
private ArrayRef<clang::TemplateParameterList*> TemplateParameterLists
If this declarator declares a template, its template parameter lists.
private clang::TemplateParameterList* InventedTemplateParameterList
If the declarator declares an abbreviated function template, the innermost template parameter list containing the invented and explicit template parameters (if any).
private anonymous struct / union
private clang::SourceLocation CommaLoc
If this is the second or subsequent declarator in this declaration, the location of the comma before this declarator.
private clang::SourceLocation EllipsisLoc
If provided, the source location of the ellipsis used to describe this declarator as a parameter pack.

Method Overview

Methods

void AddInnermostTypeInfo(
    const clang::DeclaratorChunk& TI)

Description

Add a new innermost chunk to this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2265

Parameters

const clang::DeclaratorChunk& TI

void AddTypeInfo(const clang::DeclaratorChunk& TI,
                 clang::ParsedAttributes&& attrs,
                 clang::SourceLocation EndLoc)

Description

AddTypeInfo - Add a chunk to this declarator. Also extend the range to EndLoc, which should be the last token of the chunk. This function takes attrs by R-Value reference because it takes ownership of those attributes from the parameter.

Declared at: clang/include/clang/Sema/DeclSpec.h:2245

Parameters

const clang::DeclaratorChunk& TI
clang::ParsedAttributes&& attrs
clang::SourceLocation EndLoc

void AddTypeInfo(const clang::DeclaratorChunk& TI,
                 clang::SourceLocation EndLoc)

Description

AddTypeInfo - Add a chunk to this declarator. Also extend the range to EndLoc, which should be the last token of the chunk.

Declared at: clang/include/clang/Sema/DeclSpec.h:2257

Parameters

const clang::DeclaratorChunk& TI
clang::SourceLocation EndLoc

Declarator(const clang::DeclSpec& DS,
           const clang::ParsedAttributesView&
               DeclarationAttrs,
           clang::DeclaratorContext C)

Description

`DS` and `DeclarationAttrs` must outlive the `Declarator`. In particular, take care not to pass temporary objects for these parameters. `DeclarationAttrs` contains [[]] attributes from the attribute-specifier-seq at the beginning of a declaration, which appertain to the declared entity itself. Attributes with other syntax (e.g. GNU) should not be placed in this attribute list; if they occur at the beginning of a declaration, they apply to the `DeclSpec` and should be attached to that instead. Here is an example of an attribute associated with a declaration: [[deprecated]] int x, y; This attribute appertains to all of the entities declared in the declaration, i.e. `x` and `y` in this case.

Declared at: clang/include/clang/Sema/DeclSpec.h:1916

Parameters

const clang::DeclSpec& DS
const clang::ParsedAttributesView& DeclarationAttrs
clang::DeclaratorContext C

void DropFirstTypeObject()

Declared at: clang/include/clang/Sema/DeclSpec.h:2291

void ExtendWithDeclSpec(const clang::DeclSpec& DS)

Description

ExtendWithDeclSpec - Extend the declarator source range to include the given declspec, unless its location is invalid. Adopts the range start if the current range start is invalid.

Declared at: clang/include/clang/Sema/DeclSpec.h:1994

Parameters

const clang::DeclSpec& DS

void SetIdentifier(clang::IdentifierInfo* Id,
                   clang::SourceLocation IdLoc)

Description

Set the name of this declarator to be the given identifier.

Declared at: clang/include/clang/Sema/DeclSpec.h:2231

Parameters

clang::IdentifierInfo* Id
clang::SourceLocation IdLoc

void SetRangeBegin(clang::SourceLocation Loc)

Description

SetRangeBegin - Set the start of the source range to Loc, unless it's invalid.

Declared at: clang/include/clang/Sema/DeclSpec.h:1982

Parameters

clang::SourceLocation Loc

void SetRangeEnd(clang::SourceLocation Loc)

Description

SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.

Declared at: clang/include/clang/Sema/DeclSpec.h:1987

Parameters

clang::SourceLocation Loc

void SetSourceRange(clang::SourceRange R)

Declared at: clang/include/clang/Sema/DeclSpec.h:1979

Parameters

clang::SourceRange R

void clear()

Description

Reset the contents of this Declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2003

clang::Expr* getAsmLabel() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2586

clang::AttributePool& getAttributePool() const

Declared at: clang/include/clang/Sema/DeclSpec.h:1949

clang::ParsedAttributes& getAttributes()

Declared at: clang/include/clang/Sema/DeclSpec.h:2560

const clang::ParsedAttributes& getAttributes()
    const

Declared at: clang/include/clang/Sema/DeclSpec.h:2559

clang::SourceLocation getBeginLoc() const

Declared at: clang/include/clang/Sema/DeclSpec.h:1976

void getCXX11AttributeRanges(
    SmallVectorImpl<clang::SourceRange>& Ranges)

Description

Return a source range list of C++11 attributes associated with the declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2579

Parameters

SmallVectorImpl<clang::SourceRange>& Ranges

clang::CXXScopeSpec& getCXXScopeSpec()

Declared at: clang/include/clang/Sema/DeclSpec.h:1956

const clang::CXXScopeSpec& getCXXScopeSpec() const

Description

getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part of the declarator-id.

Declared at: clang/include/clang/Sema/DeclSpec.h:1955

clang::SourceLocation getCommaLoc() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2606

clang::DeclaratorContext getContext() const

Declared at: clang/include/clang/Sema/DeclSpec.h:1965

const clang::DeclSpec& getDeclSpec() const

Description

getDeclSpec - Return the declaration-specifier that this declarator was declared with.

Declared at: clang/include/clang/Sema/DeclSpec.h:1940

const clang::ParsedAttributesView&
getDeclarationAttributes() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2562

const clang::DecompositionDeclarator&
getDecompositionDeclarator() const

Declared at: clang/include/clang/Sema/DeclSpec.h:1961

clang::SourceLocation getEllipsisLoc() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2610

clang::SourceLocation getEndLoc() const

Declared at: clang/include/clang/Sema/DeclSpec.h:1977

bool getExtension() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2589

clang::FunctionDefinitionKind
getFunctionDefinitionKind() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2621

DeclaratorChunk::FunctionTypeInfo&
getFunctionTypeInfo()

Description

getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).

Declared at: clang/include/clang/Sema/DeclSpec.h:2363

const DeclaratorChunk::FunctionTypeInfo&
getFunctionTypeInfo() const

Description

getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).

Declared at: clang/include/clang/Sema/DeclSpec.h:2372

clang::IdentifierInfo* getIdentifier() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2222

clang::SourceLocation getIdentifierLoc() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2228

const clang::DeclaratorChunk*
getInnermostNonParenChunk() const

Description

Return the innermost (closest to the declarator) chunk of this declarator that is not a parens chunk, or null if there are no non-parens chunks.

Declared at: clang/include/clang/Sema/DeclSpec.h:2300

clang::TemplateParameterList*
getInventedTemplateParameterList() const

Description

The template parameter list generated from the explicit template parameters along with any invented template parameters from placeholder-typed parameters, if there were any such parameters.

Declared at: clang/include/clang/Sema/DeclSpec.h:2539

clang::DeclSpec& getMutableDeclSpec()

Description

getMutableDeclSpec - Return a non-const version of the DeclSpec. This should be used with extreme care: declspecs can often be shared between multiple declarators, so mutating the DeclSpec affects all of the Declarators. This should only be done when the declspec is known to not be shared or when in error recovery etc.

Declared at: clang/include/clang/Sema/DeclSpec.h:1947

clang::UnqualifiedId& getName()

Description

Retrieve the name specified by this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:1959

unsigned int getNumTypeObjects() const

Description

Return the number of types applied to this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2270

const clang::DeclaratorChunk*
getOutermostNonParenChunk() const

Description

Return the outermost (furthest from the declarator) chunk of this declarator that is not a parens chunk, or null if there are no non-parens chunks.

Declared at: clang/include/clang/Sema/DeclSpec.h:2311

clang::SourceRange getSourceRange() const

Description

Get the source range that spans this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:1975

ArrayRef<clang::TemplateParameterList*>
getTemplateParameterLists() const

Description

The template parameter lists that preceded the declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2525

clang::Expr* getTrailingRequiresClause()

Description

Sets a trailing requires clause for this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2509

clang::ParsedType getTrailingReturnType() const

Description

Get the trailing return type appearing (at any level) within this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2493

const clang::DeclaratorChunk& getTypeObject(
    unsigned int i) const

Description

Return the specified TypeInfo from this declarator. TypeInfo #0 is closest to the identifier.

Declared at: clang/include/clang/Sema/DeclSpec.h:2274

Parameters

unsigned int i

clang::DeclaratorChunk& getTypeObject(
    unsigned int i)

Declared at: clang/include/clang/Sema/DeclSpec.h:2278

Parameters

unsigned int i

bool hasAttributes() const

Description

hasAttributes - do we contain any attributes?

Declared at: clang/include/clang/Sema/DeclSpec.h:2567

bool hasEllipsis() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2609

bool hasGroupingParens() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2603

bool hasInitializer() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2626

bool hasName() const

Description

hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentifier()) or some kind of special C++ name (constructor, destructor, etc.), or a structured binding (which is not exactly a name, but occupies the same position).

Declared at: clang/include/clang/Sema/DeclSpec.h:2212

bool hasTrailingRequiresClause() const

Description

Determine whether a trailing requires clause was written in this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2515

bool hasTrailingReturnType() const

Description

Determine whether a trailing return type was written (at any level) within this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2484

bool isArrayOfUnknownBound() const

Description

isArrayOfUnknownBound - This method returns true if the declarator is a declarator for an array of unknown bound (looking through parentheses).

Declared at: clang/include/clang/Sema/DeclSpec.h:2322

bool isCtorOrDtor()

Description

Returns true if this declares a constructor or a destructor.

Declared at: clang/include/clang/Sema/DeclSpec.h:2640

bool isDeclarationOfFunction() const

Description

Determine whether the declaration that will be produced from this declaration will be a function. A declaration can declare a function even if the declarator itself isn't a function declarator, if the type specifier refers to a function type. This routine checks for both cases.

Declared at: clang/include/clang/Sema/DeclSpec.h:2382

bool isDecompositionDeclarator() const

Description

Return whether this declarator is a decomposition declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2218

bool isExpressionContext() const

Description

Determine whether this declaration appears in a context where an expression could appear.

Declared at: clang/include/clang/Sema/DeclSpec.h:2428

bool isFirstDeclarationOfMember()

Description

Returns true if this declares a real member and not a friend.

Declared at: clang/include/clang/Sema/DeclSpec.h:2629

bool isFirstDeclarator() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2605

bool isFunctionDeclarationContext() const

Description

Return true if this declaration appears in a context where a function declarator would be a function declaration.

Declared at: clang/include/clang/Sema/DeclSpec.h:2386

bool isFunctionDeclarator(unsigned int& idx) const

Description

isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking through parentheses). If true is returned, then the reference type parameter idx is assigned with the index of the declaration chunk.

Declared at: clang/include/clang/Sema/DeclSpec.h:2332

Parameters

unsigned int& idx

bool isFunctionDeclarator() const

Description

isFunctionDeclarator - Once this declarator is fully parsed and formed, this method returns true if the identifier is a function declarator (looking through parentheses).

Declared at: clang/include/clang/Sema/DeclSpec.h:2356

bool isFunctionDeclaratorAFunctionDeclaration()
    const

Description

Return true if a function declarator at this position would be a function declaration.

Declared at: clang/include/clang/Sema/DeclSpec.h:2471

bool isFunctionDefinition() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2617

bool isInvalidType() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2598

bool isObjCIvar() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2592

bool isObjCWeakProperty() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2595

bool isPastIdentifier() const

Description

isPastIdentifier - Return true if we have parsed beyond the point where the name would appear. (This may happen even if we haven't actually parsed a name, perhaps because this context doesn't require one.)

Declared at: clang/include/clang/Sema/DeclSpec.h:2206

bool isPrototypeContext() const

Declared at: clang/include/clang/Sema/DeclSpec.h:1967

bool isRedeclaration() const

Declared at: clang/include/clang/Sema/DeclSpec.h:2643

bool isStaticMember()

Description

Returns true if this declares a static member. This cannot be called on a declarator outside of a MemberContext because we won't know until redeclaration time if the decl is static.

Declared at: clang/include/clang/Sema/DeclSpec.h:2637

bool mayBeFollowedByCXXDirectInit() const

Description

mayBeFollowedByCXXDirectInit - Return true if the declarator can be followed by a C++ direct initializer, e.g. "int x(1);".

Declared at: clang/include/clang/Sema/DeclSpec.h:2148

bool mayHaveDecompositionDeclarator() const

Description

Return true if the context permits a C++17 decomposition declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2103

bool mayHaveIdentifier() const

Description

mayHaveIdentifier - Return true if the identifier is either optional or required. This is true for normal declarators and prototypes, but not typenames.

Declared at: clang/include/clang/Sema/DeclSpec.h:2065

bool mayOmitIdentifier() const

Description

mayOmitIdentifier - Return true if the identifier is either optional or not allowed. This is true for typenames, prototypes, and template parameter lists.

Declared at: clang/include/clang/Sema/DeclSpec.h:2025

void setAsmLabel(clang::Expr* E)

Declared at: clang/include/clang/Sema/DeclSpec.h:2585

Parameters

clang::Expr* E

void setCommaLoc(clang::SourceLocation CL)

Declared at: clang/include/clang/Sema/DeclSpec.h:2607

Parameters

clang::SourceLocation CL

void setDecompositionBindings(
    clang::SourceLocation LSquareLoc,
    ArrayRef<DecompositionDeclarator::Binding>
        Bindings,
    clang::SourceLocation RSquareLoc)

Description

Set the decomposition bindings for this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2237

Parameters

clang::SourceLocation LSquareLoc
ArrayRef<DecompositionDeclarator::Binding> Bindings
clang::SourceLocation RSquareLoc

void setEllipsisLoc(clang::SourceLocation EL)

Declared at: clang/include/clang/Sema/DeclSpec.h:2611

Parameters

clang::SourceLocation EL

void setExtension(bool Val = true)

Declared at: clang/include/clang/Sema/DeclSpec.h:2588

Parameters

bool Val = true

void setFunctionDefinitionKind(
    clang::FunctionDefinitionKind Val)

Declared at: clang/include/clang/Sema/DeclSpec.h:2613

Parameters

clang::FunctionDefinitionKind Val

void setGroupingParens(bool flag)

Declared at: clang/include/clang/Sema/DeclSpec.h:2602

Parameters

bool flag

void setHasInitializer(bool Val = true)

Declared at: clang/include/clang/Sema/DeclSpec.h:2625

Parameters

bool Val = true

void setInvalidType(bool Val = true)

Declared at: clang/include/clang/Sema/DeclSpec.h:2597

Parameters

bool Val = true

void setInventedTemplateParameterList(
    clang::TemplateParameterList* Invented)

Description

Sets the template parameter list generated from the explicit template parameters along with any invented template parameters from placeholder-typed parameters.

Declared at: clang/include/clang/Sema/DeclSpec.h:2532

Parameters

clang::TemplateParameterList* Invented

void setObjCIvar(bool Val = true)

Declared at: clang/include/clang/Sema/DeclSpec.h:2591

Parameters

bool Val = true

void setObjCWeakProperty(bool Val = true)

Declared at: clang/include/clang/Sema/DeclSpec.h:2594

Parameters

bool Val = true

void setRedeclaration(bool Val)

Declared at: clang/include/clang/Sema/DeclSpec.h:2642

Parameters

bool Val

void setTemplateParameterLists(
    ArrayRef<clang::TemplateParameterList*> TPLs)

Description

Sets the template parameter lists that preceded the declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2520

Parameters

ArrayRef<clang::TemplateParameterList*> TPLs

void setTrailingRequiresClause(clang::Expr* TRC)

Description

Sets a trailing requires clause for this declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2502

Parameters

clang::Expr* TRC

void takeAttributes(
    clang::ParsedAttributes& attrs)

Description

takeAttributes - Takes attributes from the given parsed-attributes set and add them to this declarator. These examples both add 3 attributes to "var": short int var __attribute__((aligned(16),common,deprecated)); short int x, __attribute__((aligned(16)) var __attribute__((common,deprecated)); Also extends the range of the declarator.

Declared at: clang/include/clang/Sema/DeclSpec.h:2552

Parameters

clang::ParsedAttributes& attrs

clang::Declarator::type_object_range
type_objects() const

Description

Returns the range of type objects, from the identifier outwards.

Declared at: clang/include/clang/Sema/DeclSpec.h:2287

~Declarator()

Declared at: clang/include/clang/Sema/DeclSpec.h:1935