21 #include "llvm/Support/ErrorHandling.h" 22 using namespace clang;
33 const Expr *falseExpr);
38 assert(!TR->
isReferenceType() &&
"Expressions can't have reference type.");
73 return Classification(kind, modifiable);
99 llvm_unreachable(
"Invalid value category of implicit cast.");
108 #define ABSTRACT_STMT(Kind) 109 #define STMT(Kind, Base) case Expr::Kind##Class: 110 #define EXPR(Kind, Base) 111 #include "clang/AST/StmtNodes.inc" 112 llvm_unreachable(
"cannot classify a statement");
115 case Expr::ObjCIsaExprClass:
117 case Expr::StringLiteralClass:
119 case Expr::ObjCEncodeExprClass:
121 case Expr::PredefinedExprClass:
123 case Expr::ObjCSubscriptRefExprClass:
124 case Expr::ObjCPropertyRefExprClass:
126 case Expr::CXXTypeidExprClass:
129 case Expr::UnresolvedLookupExprClass:
130 case Expr::UnresolvedMemberExprClass:
131 case Expr::TypoExprClass:
132 case Expr::DependentCoawaitExprClass:
133 case Expr::CXXDependentScopeMemberExprClass:
134 case Expr::DependentScopeDeclRefExprClass:
137 case Expr::ObjCIvarRefExprClass:
138 case Expr::FunctionParmPackExprClass:
139 case Expr::MSPropertyRefExprClass:
140 case Expr::MSPropertySubscriptExprClass:
141 case Expr::OMPArraySectionExprClass:
146 case Expr::CompoundLiteralExprClass:
150 case Expr::CXXBoolLiteralExprClass:
151 case Expr::CXXPseudoDestructorExprClass:
152 case Expr::UnaryExprOrTypeTraitExprClass:
153 case Expr::CXXNewExprClass:
154 case Expr::CXXThisExprClass:
155 case Expr::CXXNullPtrLiteralExprClass:
156 case Expr::ImaginaryLiteralClass:
157 case Expr::GNUNullExprClass:
158 case Expr::OffsetOfExprClass:
159 case Expr::CXXThrowExprClass:
160 case Expr::ShuffleVectorExprClass:
161 case Expr::ConvertVectorExprClass:
162 case Expr::IntegerLiteralClass:
163 case Expr::CharacterLiteralClass:
164 case Expr::AddrLabelExprClass:
165 case Expr::CXXDeleteExprClass:
166 case Expr::ImplicitValueInitExprClass:
167 case Expr::BlockExprClass:
168 case Expr::FloatingLiteralClass:
169 case Expr::CXXNoexceptExprClass:
170 case Expr::CXXScalarValueInitExprClass:
171 case Expr::TypeTraitExprClass:
172 case Expr::ArrayTypeTraitExprClass:
173 case Expr::ExpressionTraitExprClass:
174 case Expr::ObjCSelectorExprClass:
175 case Expr::ObjCProtocolExprClass:
176 case Expr::ObjCStringLiteralClass:
177 case Expr::ObjCBoxedExprClass:
178 case Expr::ObjCArrayLiteralClass:
179 case Expr::ObjCDictionaryLiteralClass:
180 case Expr::ObjCBoolLiteralExprClass:
181 case Expr::ObjCAvailabilityCheckExprClass:
182 case Expr::ParenListExprClass:
183 case Expr::SizeOfPackExprClass:
184 case Expr::SubstNonTypeTemplateParmPackExprClass:
185 case Expr::AsTypeExprClass:
186 case Expr::ObjCIndirectCopyRestoreExprClass:
187 case Expr::AtomicExprClass:
188 case Expr::CXXFoldExprClass:
189 case Expr::ArrayInitLoopExprClass:
190 case Expr::ArrayInitIndexExprClass:
191 case Expr::NoInitExprClass:
192 case Expr::DesignatedInitUpdateExprClass:
196 case Expr::SubstNonTypeTemplateParmExprClass:
198 cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement());
204 case Expr::ArraySubscriptExprClass:
205 if (cast<ArraySubscriptExpr>(E)->getBase()->
getType()->isVectorType())
207 if (Lang.CPlusPlus11) {
210 auto *
Base = cast<ArraySubscriptExpr>(E)->getBase()->IgnoreImpCasts();
211 if (
Base->getType()->isArrayType())
218 case Expr::DeclRefExprClass:
220 return isa<FunctionDecl>(cast<DeclRefExpr>(E)->getDecl())
222 return ClassifyDecl(Ctx, cast<DeclRefExpr>(E)->getDecl());
225 case Expr::MemberExprClass:
228 case Expr::UnaryOperatorClass:
229 switch (cast<UnaryOperator>(E)->
getOpcode()) {
248 if (isa<ObjCPropertyRefExpr>(Op))
264 case Expr::OpaqueValueExprClass:
268 case Expr::PseudoObjectExprClass:
274 case Expr::ImplicitCastExprClass:
279 case Expr::ParenExprClass:
285 case Expr::GenericSelectionExprClass:
286 if (cast<GenericSelectionExpr>(E)->isResultDependent())
288 return ClassifyInternal(Ctx,cast<GenericSelectionExpr>(E)->getResultExpr());
290 case Expr::BinaryOperatorClass:
291 case Expr::CompoundAssignOperatorClass:
297 case Expr::CallExprClass:
298 case Expr::CXXOperatorCallExprClass:
299 case Expr::CXXMemberCallExprClass:
300 case Expr::UserDefinedLiteralClass:
301 case Expr::CUDAKernelCallExprClass:
302 return ClassifyUnnamed(Ctx, cast<CallExpr>(E)->getCallReturnType(Ctx));
305 case Expr::ChooseExprClass:
310 case Expr::ExtVectorElementExprClass:
311 if (cast<ExtVectorElementExpr>(E)->containsDuplicateElements())
313 if (cast<ExtVectorElementExpr>(E)->isArrow())
318 case Expr::CXXDefaultArgExprClass:
322 case Expr::CXXDefaultInitExprClass:
326 case Expr::CXXBindTemporaryExprClass:
330 case Expr::ExprWithCleanupsClass:
334 case Expr::CStyleCastExprClass:
335 case Expr::CXXFunctionalCastExprClass:
336 case Expr::CXXStaticCastExprClass:
337 case Expr::CXXDynamicCastExprClass:
338 case Expr::CXXReinterpretCastExprClass:
339 case Expr::CXXConstCastExprClass:
340 case Expr::ObjCBridgedCastExprClass:
343 return ClassifyUnnamed(Ctx, cast<ExplicitCastExpr>(E)->getTypeAsWritten());
345 case Expr::CXXUnresolvedConstructExprClass:
347 cast<CXXUnresolvedConstructExpr>(E)->getTypeAsWritten());
349 case Expr::BinaryConditionalOperatorClass: {
355 case Expr::ConditionalOperatorClass: {
364 case Expr::ObjCMessageExprClass:
366 cast<ObjCMessageExpr>(E)->getMethodDecl()) {
373 case Expr::CXXConstructExprClass:
374 case Expr::CXXInheritedCtorInitExprClass:
375 case Expr::CXXTemporaryObjectExprClass:
376 case Expr::LambdaExprClass:
377 case Expr::CXXStdInitializerListExprClass:
380 case Expr::VAArgExprClass:
383 case Expr::DesignatedInitExprClass:
386 case Expr::StmtExprClass: {
387 const CompoundStmt *S = cast<StmtExpr>(E)->getSubStmt();
388 if (
const Expr *LastExpr = dyn_cast_or_null<Expr>(S->
body_back()))
393 case Expr::CXXUuidofExprClass:
396 case Expr::PackExpansionExprClass:
399 case Expr::MaterializeTemporaryExprClass:
400 return cast<MaterializeTemporaryExpr>(E)->isBoundToLvalueReference()
404 case Expr::InitListExprClass:
411 assert(cast<InitListExpr>(E)->getNumInits() == 1 &&
412 "Only 1-element init lists can be glvalues.");
415 case Expr::CoawaitExprClass:
416 case Expr::CoyieldExprClass:
417 return ClassifyInternal(Ctx, cast<CoroutineSuspendExpr>(E)->getResumeExpr());
420 llvm_unreachable(
"unhandled expression kind in classification");
433 if (isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance())
438 dyn_cast<NonTypeTemplateParmDecl>(D))
439 islvalue = NTTParm->getType()->isReferenceType();
441 islvalue = isa<VarDecl>(D) || isa<FieldDecl>(D) ||
442 isa<IndirectFieldDecl>(D) ||
443 isa<BindingDecl>(D) ||
445 (isa<FunctionDecl>(D) || isa<MSPropertyDecl>(D) ||
446 isa<FunctionTemplateDecl>(D)));
482 return Cl::CL_LValue;
485 if (isa<ObjCPropertyRefExpr>(Base))
495 if (
Value->getType()->isReferenceType())
496 return Cl::CL_LValue;
501 return Cl::CL_LValue;
506 if (isa<FieldDecl>(Member)) {
509 return Cl::CL_LValue;
511 if (isa<ObjCPropertyRefExpr>(Base))
530 "This is only relevant for C++.");
566 "This is only relevant for C++.");
577 if (
const Expr *NonThrow = TrueIsThrow ? (FalseIsThrow ?
nullptr : False)
578 : (FalseIsThrow ? True :
nullptr))
604 if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) {
605 Loc = CE->getExprLoc();
621 if (
Expr->isImplicitProperty() &&
622 Expr->getImplicitPropertySetter() ==
nullptr)
635 if (CT->isArrayType())
638 if (CT->isIncompleteType())
643 if (R->hasConstFields())
665 llvm_unreachable(
"Unhandled kind");
692 case Cl::CM_RValue: llvm_unreachable(
"CM_RValue and CL_LValue don't match");
695 llvm_unreachable(
"CM_LValueCast and CL_LValue don't match");
703 llvm_unreachable(
"Unhandled modifiable type");
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
bool isConstQualified() const
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
bool isRecordType() const
Decl - This represents one declaration (or definition), e.g.
Defines the C++ template declaration subclasses.
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
static Cl::Kinds ClassifyExprValueKind(const LangOptions &Lang, const Expr *E, ExprValueKind Kind)
const T * getAs() const
Member-template getAs<specific type>'.
ObjCMethodDecl - Represents an instance or class method declaration.
static bool isAssignmentOp(Opcode Opc)
Defines the clang::Expr interface and subclasses for C++ expressions.
Qualifiers getQualifiers() const
Retrieve all qualifiers.
Expr * getFalseExpr() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, Cl::Kinds Kind, SourceLocation &Loc)
bool isReferenceType() const
Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const
ClassifyModifiable - Classify this expression according to the C++11 expression taxonomy, and see if it is valid on the left side of an assignment.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
An rvalue reference type, per C++11 [dcl.ref].
An x-value expression is a reference to an object with independent storage but which can be "moved"...
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
A builtin binary operation expression such as "x + y" or "x <= y".
LangAS getAddressSpace() const
ConditionalOperator - The ?: ternary operator.
CompoundStmt - This represents a group of statements like { stmt stmt }.
The return type of classify().
bool hasQualifiers() const
Determine whether this type has any qualifiers.
Kinds
The various classification results. Most of these mean prvalue.
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
QualType getPointeeType() const
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
const FunctionProtoType * T
DeclContext * getDeclContext()
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
ModifiableType
The results of modification testing.
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
static Cl::Kinds ClassifyUnnamed(ASTContext &Ctx, QualType T)
ClassifyUnnamed - Return the classification of an expression yielding an unnamed value of the given t...
static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E)
Encodes a location in the source.
Represents a static or instance method of a struct/union/class.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, does not have an incomplet...
static Cl::Kinds ClassifyTemporary(QualType T)
Classify an expression which creates a temporary, based on its type.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
static Cl::Kinds ClassifyBinaryOp(ASTContext &Ctx, const BinaryOperator *E)
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Dataflow Directional Tag Classes.
ModifiableType getModifiable() const
BinaryOperator::Opcode getOpcode(const SymExpr *SE)
static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D)
ClassifyDecl - Return the classification of an expression referencing the given declaration.
StmtClass getStmtClass() const
ExplicitCastExpr - An explicit cast written in the source code.
static Cl::Kinds ClassifyConditional(ASTContext &Ctx, const Expr *trueExpr, const Expr *falseExpr)
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
bool isFunctionType() const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool isLValueReferenceType() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Expr * getTrueExpr() const
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E)
An l-value expression is a reference to an object with independent storage.
NamedDecl - This represents a decl with a name.
const LangOptions & getLangOpts() const
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.