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.");
106 switch (E->getStmtClass()) {
107 case Stmt::NoStmtClass:
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::CXXDependentScopeMemberExprClass:
133 case Expr::DependentScopeDeclRefExprClass:
136 case Expr::ObjCIvarRefExprClass:
137 case Expr::FunctionParmPackExprClass:
138 case Expr::MSPropertyRefExprClass:
139 case Expr::MSPropertySubscriptExprClass:
140 case Expr::OMPArraySectionExprClass:
145 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::NoInitExprClass:
190 case Expr::DesignatedInitUpdateExprClass:
191 case Expr::CoyieldExprClass:
195 case Expr::SubstNonTypeTemplateParmExprClass:
197 cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement());
201 case Expr::ArraySubscriptExprClass:
202 if (cast<ArraySubscriptExpr>(E)->getBase()->getType()->isVectorType())
208 case Expr::DeclRefExprClass:
210 return isa<FunctionDecl>(cast<DeclRefExpr>(E)->getDecl())
212 return ClassifyDecl(Ctx, cast<DeclRefExpr>(E)->getDecl());
215 case Expr::MemberExprClass:
218 case Expr::UnaryOperatorClass:
219 switch (cast<UnaryOperator>(E)->getOpcode()) {
238 if (isa<ObjCPropertyRefExpr>(Op))
254 case Expr::OpaqueValueExprClass:
258 case Expr::PseudoObjectExprClass:
260 cast<PseudoObjectExpr>(E)->getValueKind());
264 case Expr::ImplicitCastExprClass:
269 case Expr::ParenExprClass:
275 case Expr::GenericSelectionExprClass:
276 if (cast<GenericSelectionExpr>(E)->isResultDependent())
278 return ClassifyInternal(Ctx,cast<GenericSelectionExpr>(E)->getResultExpr());
280 case Expr::BinaryOperatorClass:
281 case Expr::CompoundAssignOperatorClass:
287 case Expr::CallExprClass:
288 case Expr::CXXOperatorCallExprClass:
289 case Expr::CXXMemberCallExprClass:
290 case Expr::UserDefinedLiteralClass:
291 case Expr::CUDAKernelCallExprClass:
292 return ClassifyUnnamed(Ctx, cast<CallExpr>(E)->getCallReturnType(Ctx));
295 case Expr::ChooseExprClass:
300 case Expr::ExtVectorElementExprClass:
301 if (cast<ExtVectorElementExpr>(E)->containsDuplicateElements())
303 if (cast<ExtVectorElementExpr>(E)->isArrow())
308 case Expr::CXXDefaultArgExprClass:
312 case Expr::CXXDefaultInitExprClass:
316 case Expr::CXXBindTemporaryExprClass:
320 case Expr::ExprWithCleanupsClass:
324 case Expr::CStyleCastExprClass:
325 case Expr::CXXFunctionalCastExprClass:
326 case Expr::CXXStaticCastExprClass:
327 case Expr::CXXDynamicCastExprClass:
328 case Expr::CXXReinterpretCastExprClass:
329 case Expr::CXXConstCastExprClass:
330 case Expr::ObjCBridgedCastExprClass:
333 return ClassifyUnnamed(Ctx, cast<ExplicitCastExpr>(E)->getTypeAsWritten());
335 case Expr::CXXUnresolvedConstructExprClass:
337 cast<CXXUnresolvedConstructExpr>(E)->getTypeAsWritten());
339 case Expr::BinaryConditionalOperatorClass: {
345 case Expr::ConditionalOperatorClass: {
354 case Expr::ObjCMessageExprClass:
356 cast<ObjCMessageExpr>(E)->getMethodDecl()) {
363 case Expr::CXXConstructExprClass:
364 case Expr::CXXInheritedCtorInitExprClass:
365 case Expr::CXXTemporaryObjectExprClass:
366 case Expr::LambdaExprClass:
367 case Expr::CXXStdInitializerListExprClass:
370 case Expr::VAArgExprClass:
373 case Expr::DesignatedInitExprClass:
376 case Expr::StmtExprClass: {
378 if (
const Expr *LastExpr = dyn_cast_or_null<Expr>(S->
body_back()))
383 case Expr::CXXUuidofExprClass:
386 case Expr::PackExpansionExprClass:
389 case Expr::MaterializeTemporaryExprClass:
390 return cast<MaterializeTemporaryExpr>(
E)->isBoundToLvalueReference()
394 case Expr::InitListExprClass:
401 assert(cast<InitListExpr>(E)->getNumInits() == 1 &&
402 "Only 1-element init lists can be glvalues.");
405 case Expr::CoawaitExprClass:
409 llvm_unreachable(
"unhandled expression kind in classification");
422 if (isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance())
427 dyn_cast<NonTypeTemplateParmDecl>(D))
428 islvalue = NTTParm->getType()->isReferenceType();
430 islvalue = isa<VarDecl>(D) || isa<FieldDecl>(D) ||
431 isa<IndirectFieldDecl>(D) ||
433 (isa<FunctionDecl>(D) || isa<MSPropertyDecl>(D) ||
434 isa<FunctionTemplateDecl>(D)));
470 return Cl::CL_LValue;
473 if (isa<ObjCPropertyRefExpr>(Base))
483 if (
Value->getType()->isReferenceType())
484 return Cl::CL_LValue;
488 if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord())
489 return Cl::CL_LValue;
494 if (isa<FieldDecl>(Member)) {
497 return Cl::CL_LValue;
499 if (isa<ObjCPropertyRefExpr>(Base))
518 "This is only relevant for C++.");
554 "This is only relevant for C++.");
565 if (
const Expr *NonThrow = TrueIsThrow ? (FalseIsThrow ?
nullptr : False)
566 : (FalseIsThrow ? True :
nullptr))
592 if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) {
593 Loc = CE->getExprLoc();
609 if (
Expr->isImplicitProperty() &&
610 Expr->getImplicitPropertySetter() ==
nullptr)
622 if (CT->isArrayType())
625 if (CT->isIncompleteType())
630 if (R->hasConstFields())
652 llvm_unreachable(
"Unhandled kind");
679 case Cl::CM_RValue: llvm_unreachable(
"CM_RValue and CL_LValue don't match");
682 llvm_unreachable(
"CM_LValueCast and CL_LValue don't match");
689 llvm_unreachable(
"Unhandled modifiable type");
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Defines the clang::ASTContext interface.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
A (possibly-)qualified type.
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
bool isRecordType() const
Defines the C++ template declaration subclasses.
bool isConstQualified() const
static Cl::Kinds ClassifyExprValueKind(const LangOptions &Lang, const Expr *E, ExprValueKind Kind)
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.
ObjCMethodDecl - Represents an instance or class method declaration.
static bool isAssignmentOp(Opcode Opc)
Defines the clang::Expr interface and subclasses for C++ expressions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isReferenceType() const
static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, Cl::Kinds Kind, SourceLocation &Loc)
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].
const LangOptions & getLangOpts() const
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
An x-value expression is a reference to an object with independent storage but which can be "moved"...
A builtin binary operation expression such as "x + y" or "x <= y".
ConditionalOperator - The ?: ternary operator.
Expr * getFalseExpr() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
The return type of classify().
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.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Qualifiers getQualifiers() const
Retrieve all qualifiers.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
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...
ModifiableType
The results of modification testing.
Expr * getTrueExpr() const
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.
static Cl::Kinds ClassifyTemporary(QualType T)
Classify an expression which creates a temporary, based on its type.
static Cl::Kinds ClassifyBinaryOp(ASTContext &Ctx, const BinaryOperator *E)
static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D)
ClassifyDecl - Return the classification of an expression referencing the given declaration.
ModifiableType getModifiable() const
detail::InMemoryDirectory::const_iterator E
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool isLValueReferenceType() 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...
const T * getAs() const
Member-template getAs<specific type>'.
bool isFunctionType() const
unsigned getAddressSpace() const
QualType getPointeeType() const
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
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.
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)
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
An l-value expression is a reference to an object with independent storage.
NamedDecl - This represents a decl with a name.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.