13 #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
14 #define LLVM_CLANG_SEMA_INITIALIZATION_H
23 #include "llvm/ADT/PointerIntPair.h"
24 #include "llvm/ADT/SmallVector.h"
29 class CXXBaseSpecifier;
107 mutable unsigned ManglingNumber;
123 IdentifierInfo *VarID;
164 InitializedEntity(VarDecl *Var)
171 InitializedEntity(
EntityKind Kind, SourceLocation Loc, QualType Type,
173 : Kind(Kind), Parent(nullptr), Type(Type), ManglingNumber(0)
180 InitializedEntity(FieldDecl *Member,
const InitializedEntity *Parent)
186 const InitializedEntity &Parent);
189 InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
194 Capture.Location = Loc.getRawEncoding();
214 bool Consumed = (Context.
getLangOpts().ObjCAutoRefCount &&
215 Parm->
hasAttr<NSConsumedAttr>());
221 Entity.Parent =
nullptr;
223 = (
static_cast<uintptr_t
>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
235 Entity.Parent =
nullptr;
289 bool IsInheritedVirtualBase);
421 return Capture.VarID->getName();
441 unsigned dumpImpl(raw_ostream &OS)
const;
473 InitContext Context : 8;
476 SourceLocation Locations[3];
478 InitializationKind(
InitKind Kind, InitContext Context, SourceLocation Loc1,
479 SourceLocation Loc2, SourceLocation Loc3)
480 : Kind(Kind), Context(Context)
493 InitLoc, LParenLoc, RParenLoc);
498 InitLoc, InitLoc, InitLoc);
515 IC_CStyleCast, StartLoc, TypeRange.
getBegin(),
523 IC_FunctionalCast, TypeRange.
getBegin(),
530 bool AllowExplicitConvs =
false) {
532 AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
533 InitLoc, EqualLoc, EqualLoc);
545 bool isImplicit =
false) {
547 InitLoc, LParenLoc, RParenLoc);
557 return Context >= IC_StaticCast;
562 return Context >= IC_CStyleCast;
567 return Context == IC_CStyleCast;
572 return Context == IC_FunctionalCast;
591 assert(Kind ==
IK_Copy &&
"Only copy initialization has an '='");
606 return !
isCopyInit() || Context == IC_ExplicitConvs;
613 "Only direct- and value-initialization have parentheses");
850 std::string ZeroInitializationFixit;
857 ZeroInitializationFixit = Fixit;
858 ZeroInitializationFixitLoc = L;
889 bool TopLevelOfInitList =
false);
892 bool TopLevelOfInitList);
967 bool *isInitializerConstant,
977 bool HadMultipleCandidates);
1013 bool HadMultipleCandidates);
1032 QualType T,
bool TopLevelOfInitList =
false);
1045 bool HadMultipleCandidates,
1046 bool FromInitList,
bool AsInitList);
1097 this->Failure = Failure;
1099 "Incomplete type failure requires a type!");
1109 return FailedCandidateSet;
1115 return FailedOverloadResult;
1121 FailedIncompleteType = IncompleteType;
1127 assert(
Failed() &&
"Not an initialization failure!");
1133 void dump(raw_ostream &OS)
const;
1142 #endif // LLVM_CLANG_SEMA_INITIALIZATION_H
Perform a derived-to-base cast, producing an lvalue.
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args)
Diagnose an potentially-invalid initialization sequence.
void SetZeroInitializationFixit(const std::string &Fixit, SourceLocation L)
Call for initializations are invalid but that would be valid zero initialzations if Fixit was applied...
unsigned Index
When Kind == EK_ArrayElement, EK_VectorElement, or EK_ComplexElement, the index of the array or vecto...
step_iterator step_end() const
bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer, bool *isInitializerConstant, APValue *ConstantValue) const
Returns whether the last step in this initialization sequence is a narrowing conversion, defined by C++0x [dcl.init.list]p7.
Produce an Objective-C object pointer.
void AddOCLZeroEventStep(QualType T)
Add a step to initialize an OpenCL event_t from a NULL constant.
Initializing char array with wide string literal.
static InitializedEntity InitializeException(SourceLocation ThrowLoc, QualType Type, bool NRVO)
Create the initialization entity for an exception object.
Perform an implicit conversion sequence without narrowing.
An initialization that "converts" an Objective-C object (not a point to an object) to another Objecti...
Perform a qualification conversion, producing an rvalue.
SmallVectorImpl< Step >::const_iterator step_iterator
uintptr_t Base
When Kind == EK_Base, the base specifier that provides the base class. The lower bit specifies whethe...
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
The entity being initialized is a variable.
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
Overloading for a user-defined conversion failed.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
A container of type source information.
void AddAddressOverloadResolutionStep(FunctionDecl *Function, DeclAccessPair Found, bool HadMultipleCandidates)
Add a new step in the initialization that resolves the address of an overloaded function to a specifi...
Perform a derived-to-base cast, producing an xvalue.
The entity being initialized is a base member subobject.
bool isFunctionalCast() const
Determine whether this is a functional-style cast.
List-copy-initialization chose an explicit constructor.
Represents a C++ constructor within a class.
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
The entity being initialized is a function parameter; function is member of group of audited CF APIs...
Initialize an OpenCL sampler from an integer.
EntityKind getKind() const
Determine the kind of initialization.
QualType getVariableArrayDecayedType(QualType Ty) const
Returns a vla type where known sizes are replaced with [*].
void AddCAssignmentStep(QualType T)
Add a C assignment step.
Initialization by string.
SourceRange getParenRange() const
Retrieve the source range containing the locations of the open and closing parentheses for value and ...
Non-const lvalue reference binding to an lvalue of unrelated type.
step_iterator step_begin() const
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
SourceLocation getThrowLoc() const
Determine the location of the 'throw' keyword when initializing an exception object.
Perform a derived-to-base cast, producing an rvalue.
void AddReferenceBindingStep(QualType T, bool BindingTemporary)
Add a new step binding a reference to an object.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index...
ParmVarDecl - Represents a parameter to a function.
The entity being initialized is a temporary object.
bool allowExplicitConversionFunctionsInRefBinding() const
Retrieve whether this initialization allows the use of explicit conversion functions when binding a r...
void InitializeFrom(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList)
Construct a std::initializer_list from an initializer list.
void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic)
Add steps to unwrap a initializer list for a reference around a single element and rewrap it at the e...
bool isDirectReferenceBinding() const
Determine whether this initialization is a direct reference binding (C++ [dcl.init.ref]).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ImplicitConversionSequence * ICS
When Kind = SK_ConversionSequence, the implicit conversion sequence.
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
DeclaratorDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
SourceLocation getReturnLoc() const
Determine the location of the 'return' keyword when initializing the result of a function call...
Rewrap the single-element initializer list for a reference.
void AddOCLSamplerInitStep(QualType T)
Add a step to initialize an OpenCL sampler from an integer constant.
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
~InitializationSequence()
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Perform initialization via a constructor taking a single std::initializer_list argument.
Describes an C or C++ initializer list.
static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo)
Create the initialization entity for a temporary.
const LangOptions & getLangOpts() const
EntityKind
Specifies the kind of entity being initialized.
static InitializedEntity InitializeDelegation(QualType Type)
Create the initialization entity for a delegated constructor.
StepKind Kind
The kind of conversion or initialization step we are taking.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
Variable-length array must not have an initializer.
Initialization of an incomplete type.
The entity being initialized is a non-static data member subobject.
static InitializationKind CreateValue(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool isImplicit=false)
Create a value initialization.
Unwrap the single-element initializer list for a reference.
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence...
The entity being initialized is an element of a vector. or vector.
bool isAmbiguous() const
Determine whether this initialization failed due to an ambiguity.
Perform initialization via a constructor.
Perform a user-defined conversion, either via a conversion function or via a constructor.
Implicit conversion failed.
The entity being initialized is a function parameter.
static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type)
Create the initialization entity for an object allocated via new.
Perform an implicit conversion sequence.
bool isInheritedVirtualBase() const
Return whether the base is an inherited virtual base.
Sema - This implements semantic analysis and AST building for C.
Overloading for list-initialization by constructor failed.
Perform list-initialization without a constructor.
Reference binding drops qualifiers.
void AddObjCObjectConversionStep(QualType T)
Add an Objective-C object conversion step, which is always a no-op.
Cannot resolve the address of an overloaded function.
Represents a ValueDecl that came out of a declarator. Contains type source information through TypeSo...
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a member subobject.
FieldDecl * getAnonField() const
The entity being initialized is a field of block descriptor for the copied-in c++ object...
Initializing wide char array with incompatible wide string literal.
The entity being initialized is the real or imaginary part of a complex number.
Implicit conversion failed.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
static InitializationKind CreateFunctionalCast(SourceRange TypeRange, bool InitList)
Create a direct initialization for a functional cast.
uintptr_t Parameter
When Kind == EK_Parameter, the ParmVarDecl, with the low bit indicating whether the parameter is "con...
The entity being initialized is an object (or array of objects) allocated via new.
Perform a qualification conversion, producing an xvalue.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
Initializing a wide char array with narrow string literal.
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
Passing zero to a function where OpenCL event_t is expected.
void AddConstructorInitializationStep(CXXConstructorDecl *Constructor, AccessSpecifier Access, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
Resolve the address of an overloaded function to a specific function declaration. ...
void AddArrayInitStep(QualType T)
Add an array initialization step.
The entity being initialized is an exception object that is being thrown.
struct F Function
When Kind == SK_ResolvedOverloadedFunction or Kind == SK_UserConversion, the function that the expres...
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
Initializer has a placeholder type which cannot be resolved by initialization.
FailureKind getFailureKind() const
Determine why initialization failed.
void AddStringInitStep(QualType T)
Add a string init step.
The result type of a method or function.
Pass an object by indirect restore.
InitKind getKind() const
Determine the initialization kind.
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
static InitializedEntity InitializeMember(IndirectFieldDecl *Member, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a member subobject.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
FailureKind
Describes why initialization failed.
Too many initializers for scalar.
List initialization failed at some point.
Perform a conversion adding _Atomic to a type.
void AddListInitializationStep(QualType T)
Add a list-initialization step.
Perform a qualification conversion, producing an lvalue.
void AddLValueToRValueStep(QualType Ty)
Add a new step that performs a load of the given type.
Reference binding to an lvalue.
SequenceKind
Describes the kind of initialization sequence computed.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
Reference initialization from an initializer list.
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda...
StepKind
Describes the kind of a particular step in an initialization sequence.
TypeSourceInfo * TypeInfo
When Kind == EK_Temporary or EK_CompoundLiteralInit, the type source information for the temporary...
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm, QualType Type)
Create the initialization entity for a parameter, but use another type.
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
bool isExplicitCast() const
Determine whether this initialization is an explicit cast.
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
Initialization of some unused destination type with an initializer list.
static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI)
Create the entity for a compound literal initializer.
The entity being initialized is the result of a function call.
The entity being implicitly initialized back to the formal result type.
Zero-initialize the object.
The entity being initialized is the initializer for a compound literal.
void AddExtraneousCopyToTemporary(QualType T)
Add a new step that makes an extraneous copy of the input to a temporary of the same class type...
Describes the kind of initialization being performed, along with location information for tokens rela...
The entity being initialized is an element of an array.
StringRef getCapturedVarName() const
For a lambda capture, return the capture's name.
bool isCStyleOrFunctionalCast() const
Determine whether this initialization is a C-style cast.
Overloading for initialization by constructor failed.
SourceLocation getBegin() const
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
void AddAtomicConversionStep(QualType Ty)
Add a new step that performs conversion from non-atomic to atomic type.
bool HadMultipleCandidates
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
enum SequenceKind getKind() const
Determine the kind of initialization sequence computed.
QualType getType() const
Return the type wrapped by this type source info.
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn't a C-style or functional cast.
Pass an object by indirect copy-and-restore.
Rvalue reference binding to an lvalue.
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
bool isCStyleCast() const
Determine whether this is a C-style cast.
Array must be initialized with an initializer list or a string literal.
Non-constant array initializer.
void setIncompleteTypeFailure(QualType IncompleteType)
Note that this initialization sequence failed due to an incomplete type.
A single step in the initialization sequence.
static InitializedEntity InitializeParameter(ASTContext &Context, QualType Type, bool Consumed)
Create the initialization entity for a parameter that is only known by its type.
Array must be initialized with an initializer list or a wide string literal.
Too many initializers provided for a reference.
Perform a load from a glvalue, producing an rvalue.
DeclaratorDecl * VariableOrMember
When Kind == EK_Variable, or EK_Member, the VarDecl or FieldDecl, respectively.
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
Overloading due to reference initialization failed.
bool isParameterKind() const
static InitializedEntity InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase)
Create the initialization entity for a base class subobject.
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
Array must be initialized with an initializer list.
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
Reference binding failed.
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
Represents a base class of a C++ class.
QualType getType() const
Retrieve type being initialized.
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload...
bool AllowExplicit() const
Retrieve whether this initialization allows the use of explicit constructors.
void AddUserConversionStep(FunctionDecl *Function, DeclAccessPair FoundDecl, QualType T, bool HadMultipleCandidates)
Add a new step invoking a conversion function, which is either a constructor or a conversion function...
bool Failed() const
Determine whether the initialization sequence is invalid.
Defines the clang::SourceLocation class and associated facilities.
Describes the sequence of initializations required to initialize a given object or reference with a s...
static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, QualType Type)
Create the initialization entity for a related result.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Perform initialization via a constructor, taking arguments from a single InitListExpr.
The entity being initialized is the field that captures a variable in a lambda.
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
InitializationSequence(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList=false)
Try to perform initialization of the given entity, creating a record of the steps required to perform...
void setParameterCFAudited()
bool isImplicitValueInit() const
Determine whether this initialization is an implicit value-initialization, e.g., as occurs during agg...
unsigned allocateManglingNumber() const
ObjCMethodDecl * MethodDecl
When Kind == EK_RelatedResult, the ObjectiveC method where result type was implicitly changed to acco...
Reference binding to a temporary.
DeclarationName getName() const
Retrieve the name of the entity being initialized.
The initialization is being done by a delegating constructor.
void AddQualificationConversionStep(QualType Ty, ExprValueKind Category)
Add a new step that performs a qualification conversion to the given type.
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
A failed initialization sequence. The failure kind tells what happened.
Array initialization (from an array rvalue). This is a GNU C extension.
InitKind
The kind of initialization being performed.
Default-initialization of a 'const' object.
void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, QualType T, bool TopLevelOfInitList=false)
Add a new step that applies an implicit conversion sequence.
A trivial tuple used to represent a source range.
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes...
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element's index.
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
Describes an entity that is being initialized.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
Direct list-initialization.
Array initialization from a parenthesized initializer list. This is a GNU C++ extension.
Non-const lvalue reference binding to a temporary.