2010-06-28 23:09:07 +08:00
|
|
|
//===--- ExprClassification.cpp - Expression AST Node Implementation ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements Expr::classify.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2010-06-28 23:09:07 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
|
|
|
#include "clang/AST/ExprObjC.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-06-28 23:09:07 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
typedef Expr::Classification Cl;
|
|
|
|
|
|
|
|
static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E);
|
|
|
|
static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D);
|
|
|
|
static Cl::Kinds ClassifyUnnamed(ASTContext &Ctx, QualType T);
|
|
|
|
static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E);
|
|
|
|
static Cl::Kinds ClassifyBinaryOp(ASTContext &Ctx, const BinaryOperator *E);
|
|
|
|
static Cl::Kinds ClassifyConditional(ASTContext &Ctx,
|
2011-02-17 18:25:35 +08:00
|
|
|
const Expr *trueExpr,
|
|
|
|
const Expr *falseExpr);
|
2010-06-28 23:09:07 +08:00
|
|
|
static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E,
|
|
|
|
Cl::Kinds Kind, SourceLocation &Loc);
|
|
|
|
|
|
|
|
Cl Expr::ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const {
|
|
|
|
assert(!TR->isReferenceType() && "Expressions can't have reference type.");
|
|
|
|
|
|
|
|
Cl::Kinds kind = ClassifyInternal(Ctx, this);
|
|
|
|
// C99 6.3.2.1: An lvalue is an expression with an object type or an
|
|
|
|
// incomplete type other than void.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!Ctx.getLangOpts().CPlusPlus) {
|
2010-06-28 23:09:07 +08:00
|
|
|
// Thus, no functions.
|
|
|
|
if (TR->isFunctionType() || TR == Ctx.OverloadTy)
|
|
|
|
kind = Cl::CL_Function;
|
|
|
|
// No void either, but qualified void is OK because it is "other than void".
|
2011-04-20 02:51:51 +08:00
|
|
|
// Void "lvalues" are classified as addressable void values, which are void
|
|
|
|
// expressions whose address can be taken.
|
|
|
|
else if (TR->isVoidType() && !TR.hasQualifiers())
|
|
|
|
kind = (kind == Cl::CL_LValue ? Cl::CL_AddressableVoid : Cl::CL_Void);
|
2010-06-28 23:09:07 +08:00
|
|
|
}
|
|
|
|
|
2010-11-19 03:01:18 +08:00
|
|
|
// Enable this assertion for testing.
|
|
|
|
switch (kind) {
|
|
|
|
case Cl::CL_LValue: assert(getValueKind() == VK_LValue); break;
|
|
|
|
case Cl::CL_XValue: assert(getValueKind() == VK_XValue); break;
|
|
|
|
case Cl::CL_Function:
|
|
|
|
case Cl::CL_Void:
|
2011-04-20 02:51:51 +08:00
|
|
|
case Cl::CL_AddressableVoid:
|
2010-11-19 03:01:18 +08:00
|
|
|
case Cl::CL_DuplicateVectorComponents:
|
|
|
|
case Cl::CL_MemberFunction:
|
|
|
|
case Cl::CL_SubObjCPropertySetting:
|
|
|
|
case Cl::CL_ClassTemporary:
|
2012-06-05 06:27:30 +08:00
|
|
|
case Cl::CL_ArrayTemporary:
|
2011-03-27 03:48:30 +08:00
|
|
|
case Cl::CL_ObjCMessageRValue:
|
2010-11-19 03:01:18 +08:00
|
|
|
case Cl::CL_PRValue: assert(getValueKind() == VK_RValue); break;
|
|
|
|
}
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
Cl::ModifiableType modifiable = Cl::CM_Untested;
|
|
|
|
if (Loc)
|
|
|
|
modifiable = IsModifiable(Ctx, this, kind, *Loc);
|
|
|
|
return Classification(kind, modifiable);
|
|
|
|
}
|
|
|
|
|
2012-06-05 06:27:30 +08:00
|
|
|
/// Classify an expression which creates a temporary, based on its type.
|
|
|
|
static Cl::Kinds ClassifyTemporary(QualType T) {
|
|
|
|
if (T->isRecordType())
|
|
|
|
return Cl::CL_ClassTemporary;
|
|
|
|
if (T->isArrayType())
|
|
|
|
return Cl::CL_ArrayTemporary;
|
|
|
|
|
|
|
|
// No special classification: these don't behave differently from normal
|
|
|
|
// prvalues.
|
|
|
|
return Cl::CL_PRValue;
|
|
|
|
}
|
|
|
|
|
2013-02-02 10:11:36 +08:00
|
|
|
static Cl::Kinds ClassifyExprValueKind(const LangOptions &Lang,
|
|
|
|
const Expr *E,
|
|
|
|
ExprValueKind Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case VK_RValue:
|
|
|
|
return Lang.CPlusPlus ? ClassifyTemporary(E->getType()) : Cl::CL_PRValue;
|
|
|
|
case VK_LValue:
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
case VK_XValue:
|
|
|
|
return Cl::CL_XValue;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid value category of implicit cast.");
|
|
|
|
}
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) {
|
|
|
|
// This function takes the first stab at classifying expressions.
|
2012-03-11 15:00:24 +08:00
|
|
|
const LangOptions &Lang = Ctx.getLangOpts();
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
switch (E->getStmtClass()) {
|
2010-09-15 05:51:42 +08:00
|
|
|
case Stmt::NoStmtClass:
|
2011-02-09 16:16:59 +08:00
|
|
|
#define ABSTRACT_STMT(Kind)
|
2010-09-15 05:51:42 +08:00
|
|
|
#define STMT(Kind, Base) case Expr::Kind##Class:
|
|
|
|
#define EXPR(Kind, Base)
|
|
|
|
#include "clang/AST/StmtNodes.inc"
|
|
|
|
llvm_unreachable("cannot classify a statement");
|
2011-11-28 00:50:07 +08:00
|
|
|
|
|
|
|
// First come the expressions that are always lvalues, unconditionally.
|
2010-06-28 23:09:07 +08:00
|
|
|
case Expr::ObjCIsaExprClass:
|
|
|
|
// C++ [expr.prim.general]p1: A string literal is an lvalue.
|
|
|
|
case Expr::StringLiteralClass:
|
|
|
|
// @encode is equivalent to its string
|
|
|
|
case Expr::ObjCEncodeExprClass:
|
|
|
|
// __func__ and friends are too.
|
|
|
|
case Expr::PredefinedExprClass:
|
|
|
|
// Property references are lvalues
|
2012-03-07 04:05:56 +08:00
|
|
|
case Expr::ObjCSubscriptRefExprClass:
|
2010-06-28 23:09:07 +08:00
|
|
|
case Expr::ObjCPropertyRefExprClass:
|
|
|
|
// C++ [expr.typeid]p1: The result of a typeid expression is an lvalue of...
|
|
|
|
case Expr::CXXTypeidExprClass:
|
|
|
|
// Unresolved lookups get classified as lvalues.
|
|
|
|
// FIXME: Is this wise? Should they get their own kind?
|
|
|
|
case Expr::UnresolvedLookupExprClass:
|
|
|
|
case Expr::UnresolvedMemberExprClass:
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::CXXDependentScopeMemberExprClass:
|
|
|
|
case Expr::DependentScopeDeclRefExprClass:
|
2010-06-28 23:09:07 +08:00
|
|
|
// ObjC instance variables are lvalues
|
|
|
|
// FIXME: ObjC++0x might have different rules
|
|
|
|
case Expr::ObjCIvarRefExprClass:
|
2012-09-12 08:56:43 +08:00
|
|
|
case Expr::FunctionParmPackExprClass:
|
2013-04-16 15:28:30 +08:00
|
|
|
case Expr::MSPropertyRefExprClass:
|
2010-09-15 05:51:42 +08:00
|
|
|
return Cl::CL_LValue;
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
// C99 6.5.2.5p5 says that compound literals are lvalues.
|
2012-06-05 06:27:30 +08:00
|
|
|
// In C++, they're prvalue temporaries.
|
2010-06-28 23:09:07 +08:00
|
|
|
case Expr::CompoundLiteralExprClass:
|
2012-06-05 06:27:30 +08:00
|
|
|
return Ctx.getLangOpts().CPlusPlus ? ClassifyTemporary(E->getType())
|
|
|
|
: Cl::CL_LValue;
|
2010-09-15 05:51:42 +08:00
|
|
|
|
|
|
|
// Expressions that are prvalues.
|
|
|
|
case Expr::CXXBoolLiteralExprClass:
|
|
|
|
case Expr::CXXPseudoDestructorExprClass:
|
2011-03-12 03:24:49 +08:00
|
|
|
case Expr::UnaryExprOrTypeTraitExprClass:
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::CXXNewExprClass:
|
|
|
|
case Expr::CXXThisExprClass:
|
|
|
|
case Expr::CXXNullPtrLiteralExprClass:
|
|
|
|
case Expr::ImaginaryLiteralClass:
|
|
|
|
case Expr::GNUNullExprClass:
|
|
|
|
case Expr::OffsetOfExprClass:
|
|
|
|
case Expr::CXXThrowExprClass:
|
|
|
|
case Expr::ShuffleVectorExprClass:
|
2013-09-18 11:29:45 +08:00
|
|
|
case Expr::ConvertVectorExprClass:
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::IntegerLiteralClass:
|
|
|
|
case Expr::CharacterLiteralClass:
|
|
|
|
case Expr::AddrLabelExprClass:
|
|
|
|
case Expr::CXXDeleteExprClass:
|
|
|
|
case Expr::ImplicitValueInitExprClass:
|
|
|
|
case Expr::BlockExprClass:
|
|
|
|
case Expr::FloatingLiteralClass:
|
|
|
|
case Expr::CXXNoexceptExprClass:
|
|
|
|
case Expr::CXXScalarValueInitExprClass:
|
2012-02-24 15:38:34 +08:00
|
|
|
case Expr::TypeTraitExprClass:
|
2011-04-28 08:16:57 +08:00
|
|
|
case Expr::ArrayTypeTraitExprClass:
|
2011-04-25 14:54:41 +08:00
|
|
|
case Expr::ExpressionTraitExprClass:
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::ObjCSelectorExprClass:
|
|
|
|
case Expr::ObjCProtocolExprClass:
|
|
|
|
case Expr::ObjCStringLiteralClass:
|
2012-04-19 08:25:12 +08:00
|
|
|
case Expr::ObjCBoxedExprClass:
|
2012-03-07 04:05:56 +08:00
|
|
|
case Expr::ObjCArrayLiteralClass:
|
|
|
|
case Expr::ObjCDictionaryLiteralClass:
|
|
|
|
case Expr::ObjCBoolLiteralExprClass:
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::ParenListExprClass:
|
2011-01-05 01:33:58 +08:00
|
|
|
case Expr::SizeOfPackExprClass:
|
2011-01-15 09:15:58 +08:00
|
|
|
case Expr::SubstNonTypeTemplateParmPackExprClass:
|
2011-06-04 08:47:47 +08:00
|
|
|
case Expr::AsTypeExprClass:
|
2011-06-16 07:02:42 +08:00
|
|
|
case Expr::ObjCIndirectCopyRestoreExprClass:
|
2011-10-11 10:20:01 +08:00
|
|
|
case Expr::AtomicExprClass:
|
2010-09-15 05:51:42 +08:00
|
|
|
return Cl::CL_PRValue;
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// Next come the complicated cases.
|
2011-07-15 13:09:51 +08:00
|
|
|
case Expr::SubstNonTypeTemplateParmExprClass:
|
|
|
|
return ClassifyInternal(Ctx,
|
|
|
|
cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement());
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// C++ [expr.sub]p1: The result is an lvalue of type "T".
|
|
|
|
// However, subscripting vector types is more like member access.
|
|
|
|
case Expr::ArraySubscriptExprClass:
|
|
|
|
if (cast<ArraySubscriptExpr>(E)->getBase()->getType()->isVectorType())
|
|
|
|
return ClassifyInternal(Ctx, cast<ArraySubscriptExpr>(E)->getBase());
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
|
|
|
|
// C++ [expr.prim.general]p3: The result is an lvalue if the entity is a
|
|
|
|
// function or variable and a prvalue otherwise.
|
|
|
|
case Expr::DeclRefExprClass:
|
2011-04-12 08:42:48 +08:00
|
|
|
if (E->getType() == Ctx.UnknownAnyTy)
|
|
|
|
return isa<FunctionDecl>(cast<DeclRefExpr>(E)->getDecl())
|
|
|
|
? Cl::CL_PRValue : Cl::CL_LValue;
|
2010-06-28 23:09:07 +08:00
|
|
|
return ClassifyDecl(Ctx, cast<DeclRefExpr>(E)->getDecl());
|
|
|
|
|
|
|
|
// Member access is complex.
|
|
|
|
case Expr::MemberExprClass:
|
|
|
|
return ClassifyMemberExpr(Ctx, cast<MemberExpr>(E));
|
|
|
|
|
|
|
|
case Expr::UnaryOperatorClass:
|
|
|
|
switch (cast<UnaryOperator>(E)->getOpcode()) {
|
|
|
|
// C++ [expr.unary.op]p1: The unary * operator performs indirection:
|
|
|
|
// [...] the result is an lvalue referring to the object or function
|
|
|
|
// to which the expression points.
|
2010-08-25 19:45:40 +08:00
|
|
|
case UO_Deref:
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CL_LValue;
|
|
|
|
|
|
|
|
// GNU extensions, simply look through them.
|
2010-08-25 19:45:40 +08:00
|
|
|
case UO_Extension:
|
2010-06-28 23:09:07 +08:00
|
|
|
return ClassifyInternal(Ctx, cast<UnaryOperator>(E)->getSubExpr());
|
|
|
|
|
2010-11-16 18:08:07 +08:00
|
|
|
// Treat _Real and _Imag basically as if they were member
|
|
|
|
// expressions: l-value only if the operand is a true l-value.
|
|
|
|
case UO_Real:
|
|
|
|
case UO_Imag: {
|
|
|
|
const Expr *Op = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
|
|
|
|
Cl::Kinds K = ClassifyInternal(Ctx, Op);
|
|
|
|
if (K != Cl::CL_LValue) return K;
|
|
|
|
|
2010-12-02 09:19:52 +08:00
|
|
|
if (isa<ObjCPropertyRefExpr>(Op))
|
2010-11-16 18:08:07 +08:00
|
|
|
return Cl::CL_SubObjCPropertySetting;
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
}
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
// C++ [expr.pre.incr]p1: The result is the updated operand; it is an
|
|
|
|
// lvalue, [...]
|
|
|
|
// Not so in C.
|
2010-08-25 19:45:40 +08:00
|
|
|
case UO_PreInc:
|
|
|
|
case UO_PreDec:
|
2010-06-28 23:09:07 +08:00
|
|
|
return Lang.CPlusPlus ? Cl::CL_LValue : Cl::CL_PRValue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Cl::CL_PRValue;
|
|
|
|
}
|
|
|
|
|
2010-11-16 07:31:06 +08:00
|
|
|
case Expr::OpaqueValueExprClass:
|
2011-11-28 00:50:07 +08:00
|
|
|
return ClassifyExprValueKind(Lang, E, E->getValueKind());
|
2010-11-16 07:31:06 +08:00
|
|
|
|
2011-11-06 17:01:30 +08:00
|
|
|
// Pseudo-object expressions can produce l-values with reference magic.
|
|
|
|
case Expr::PseudoObjectExprClass:
|
|
|
|
return ClassifyExprValueKind(Lang, E,
|
|
|
|
cast<PseudoObjectExpr>(E)->getValueKind());
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
// Implicit casts are lvalues if they're lvalue casts. Other than that, we
|
|
|
|
// only specifically record class temporaries.
|
|
|
|
case Expr::ImplicitCastExprClass:
|
2011-11-28 00:50:07 +08:00
|
|
|
return ClassifyExprValueKind(Lang, E, E->getValueKind());
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// C++ [expr.prim.general]p4: The presence of parentheses does not affect
|
|
|
|
// whether the expression is an lvalue.
|
|
|
|
case Expr::ParenExprClass:
|
|
|
|
return ClassifyInternal(Ctx, cast<ParenExpr>(E)->getSubExpr());
|
|
|
|
|
2011-12-24 01:00:35 +08:00
|
|
|
// C11 6.5.1.1p4: [A generic selection] is an lvalue, a function designator,
|
2011-04-15 08:35:48 +08:00
|
|
|
// or a void expression if its result expression is, respectively, an
|
|
|
|
// lvalue, a function designator, or a void expression.
|
|
|
|
case Expr::GenericSelectionExprClass:
|
|
|
|
if (cast<GenericSelectionExpr>(E)->isResultDependent())
|
|
|
|
return Cl::CL_PRValue;
|
|
|
|
return ClassifyInternal(Ctx,cast<GenericSelectionExpr>(E)->getResultExpr());
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
case Expr::BinaryOperatorClass:
|
|
|
|
case Expr::CompoundAssignOperatorClass:
|
|
|
|
// C doesn't have any binary expressions that are lvalues.
|
|
|
|
if (Lang.CPlusPlus)
|
|
|
|
return ClassifyBinaryOp(Ctx, cast<BinaryOperator>(E));
|
|
|
|
return Cl::CL_PRValue;
|
|
|
|
|
|
|
|
case Expr::CallExprClass:
|
|
|
|
case Expr::CXXOperatorCallExprClass:
|
|
|
|
case Expr::CXXMemberCallExprClass:
|
2012-03-07 16:35:16 +08:00
|
|
|
case Expr::UserDefinedLiteralClass:
|
2011-02-10 05:07:24 +08:00
|
|
|
case Expr::CUDAKernelCallExprClass:
|
2010-06-28 23:09:07 +08:00
|
|
|
return ClassifyUnnamed(Ctx, cast<CallExpr>(E)->getCallReturnType());
|
|
|
|
|
|
|
|
// __builtin_choose_expr is equivalent to the chosen expression.
|
|
|
|
case Expr::ChooseExprClass:
|
2013-07-20 08:40:58 +08:00
|
|
|
return ClassifyInternal(Ctx, cast<ChooseExpr>(E)->getChosenSubExpr());
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// Extended vector element access is an lvalue unless there are duplicates
|
|
|
|
// in the shuffle expression.
|
|
|
|
case Expr::ExtVectorElementExprClass:
|
2013-06-18 05:09:57 +08:00
|
|
|
if (cast<ExtVectorElementExpr>(E)->containsDuplicateElements())
|
|
|
|
return Cl::CL_DuplicateVectorComponents;
|
|
|
|
if (cast<ExtVectorElementExpr>(E)->isArrow())
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
return ClassifyInternal(Ctx, cast<ExtVectorElementExpr>(E)->getBase());
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// Simply look at the actual default argument.
|
|
|
|
case Expr::CXXDefaultArgExprClass:
|
|
|
|
return ClassifyInternal(Ctx, cast<CXXDefaultArgExpr>(E)->getExpr());
|
|
|
|
|
2013-04-21 06:23:05 +08:00
|
|
|
// Same idea for default initializers.
|
|
|
|
case Expr::CXXDefaultInitExprClass:
|
|
|
|
return ClassifyInternal(Ctx, cast<CXXDefaultInitExpr>(E)->getExpr());
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
// Same idea for temporary binding.
|
|
|
|
case Expr::CXXBindTemporaryExprClass:
|
|
|
|
return ClassifyInternal(Ctx, cast<CXXBindTemporaryExpr>(E)->getSubExpr());
|
|
|
|
|
2010-12-06 16:20:24 +08:00
|
|
|
// And the cleanups guard.
|
|
|
|
case Expr::ExprWithCleanupsClass:
|
|
|
|
return ClassifyInternal(Ctx, cast<ExprWithCleanups>(E)->getSubExpr());
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// Casts depend completely on the target type. All casts work the same.
|
|
|
|
case Expr::CStyleCastExprClass:
|
|
|
|
case Expr::CXXFunctionalCastExprClass:
|
|
|
|
case Expr::CXXStaticCastExprClass:
|
|
|
|
case Expr::CXXDynamicCastExprClass:
|
|
|
|
case Expr::CXXReinterpretCastExprClass:
|
|
|
|
case Expr::CXXConstCastExprClass:
|
2011-06-16 07:02:42 +08:00
|
|
|
case Expr::ObjCBridgedCastExprClass:
|
2010-06-28 23:09:07 +08:00
|
|
|
// Only in C++ can casts be interesting at all.
|
|
|
|
if (!Lang.CPlusPlus) return Cl::CL_PRValue;
|
|
|
|
return ClassifyUnnamed(Ctx, cast<ExplicitCastExpr>(E)->getTypeAsWritten());
|
|
|
|
|
2011-07-08 23:50:43 +08:00
|
|
|
case Expr::CXXUnresolvedConstructExprClass:
|
|
|
|
return ClassifyUnnamed(Ctx,
|
|
|
|
cast<CXXUnresolvedConstructExpr>(E)->getTypeAsWritten());
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
case Expr::BinaryConditionalOperatorClass: {
|
|
|
|
if (!Lang.CPlusPlus) return Cl::CL_PRValue;
|
|
|
|
const BinaryConditionalOperator *co = cast<BinaryConditionalOperator>(E);
|
|
|
|
return ClassifyConditional(Ctx, co->getTrueExpr(), co->getFalseExpr());
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::ConditionalOperatorClass: {
|
2010-06-28 23:09:07 +08:00
|
|
|
// Once again, only C++ is interesting.
|
|
|
|
if (!Lang.CPlusPlus) return Cl::CL_PRValue;
|
2011-02-17 18:25:35 +08:00
|
|
|
const ConditionalOperator *co = cast<ConditionalOperator>(E);
|
|
|
|
return ClassifyConditional(Ctx, co->getTrueExpr(), co->getFalseExpr());
|
|
|
|
}
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// ObjC message sends are effectively function calls, if the target function
|
|
|
|
// is known.
|
|
|
|
case Expr::ObjCMessageExprClass:
|
|
|
|
if (const ObjCMethodDecl *Method =
|
|
|
|
cast<ObjCMessageExpr>(E)->getMethodDecl()) {
|
2014-01-26 00:55:45 +08:00
|
|
|
Cl::Kinds kind = ClassifyUnnamed(Ctx, Method->getReturnType());
|
2011-03-27 03:48:30 +08:00
|
|
|
return (kind == Cl::CL_PRValue) ? Cl::CL_ObjCMessageRValue : kind;
|
2010-06-28 23:09:07 +08:00
|
|
|
}
|
2010-09-15 05:51:42 +08:00
|
|
|
return Cl::CL_PRValue;
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
// Some C++ expressions are always class temporaries.
|
|
|
|
case Expr::CXXConstructExprClass:
|
|
|
|
case Expr::CXXTemporaryObjectExprClass:
|
2012-02-07 18:09:13 +08:00
|
|
|
case Expr::LambdaExprClass:
|
2013-06-13 06:31:48 +08:00
|
|
|
case Expr::CXXStdInitializerListExprClass:
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CL_ClassTemporary;
|
|
|
|
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::VAArgExprClass:
|
|
|
|
return ClassifyUnnamed(Ctx, E->getType());
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::DesignatedInitExprClass:
|
|
|
|
return ClassifyInternal(Ctx, cast<DesignatedInitExpr>(E)->getInit());
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::StmtExprClass: {
|
|
|
|
const CompoundStmt *S = cast<StmtExpr>(E)->getSubStmt();
|
|
|
|
if (const Expr *LastExpr = dyn_cast_or_null<Expr>(S->body_back()))
|
2010-09-15 09:37:48 +08:00
|
|
|
return ClassifyUnnamed(Ctx, LastExpr->getType());
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CL_PRValue;
|
|
|
|
}
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2010-09-15 05:51:42 +08:00
|
|
|
case Expr::CXXUuidofExprClass:
|
2010-12-17 10:00:06 +08:00
|
|
|
return Cl::CL_LValue;
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2011-01-04 01:17:50 +08:00
|
|
|
case Expr::PackExpansionExprClass:
|
|
|
|
return ClassifyInternal(Ctx, cast<PackExpansionExpr>(E)->getPattern());
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2011-06-22 01:03:29 +08:00
|
|
|
case Expr::MaterializeTemporaryExprClass:
|
2011-06-22 02:20:46 +08:00
|
|
|
return cast<MaterializeTemporaryExpr>(E)->isBoundToLvalueReference()
|
2011-06-22 01:03:29 +08:00
|
|
|
? Cl::CL_LValue
|
|
|
|
: Cl::CL_XValue;
|
2011-11-28 00:50:07 +08:00
|
|
|
|
|
|
|
case Expr::InitListExprClass:
|
|
|
|
// An init list can be an lvalue if it is bound to a reference and
|
|
|
|
// contains only one element. In that case, we look at that element
|
|
|
|
// for an exact classification. Init list creation takes care of the
|
|
|
|
// value kind for us, so we only need to fine-tune.
|
|
|
|
if (E->isRValue())
|
|
|
|
return ClassifyExprValueKind(Lang, E, E->getValueKind());
|
|
|
|
assert(cast<InitListExpr>(E)->getNumInits() == 1 &&
|
|
|
|
"Only 1-element init lists can be glvalues.");
|
|
|
|
return ClassifyInternal(Ctx, cast<InitListExpr>(E)->getInit(0));
|
2010-09-15 05:51:42 +08:00
|
|
|
}
|
2011-11-28 00:50:07 +08:00
|
|
|
|
2010-09-15 05:51:42 +08:00
|
|
|
llvm_unreachable("unhandled expression kind in classification");
|
2010-06-28 23:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ClassifyDecl - Return the classification of an expression referencing the
|
|
|
|
/// given declaration.
|
|
|
|
static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D) {
|
|
|
|
// C++ [expr.prim.general]p6: The result is an lvalue if the entity is a
|
|
|
|
// function, variable, or data member and a prvalue otherwise.
|
|
|
|
// In C, functions are not lvalues.
|
|
|
|
// In addition, NonTypeTemplateParmDecl derives from VarDecl but isn't an
|
|
|
|
// lvalue unless it's a reference type (C++ [temp.param]p6), so we need to
|
|
|
|
// special-case this.
|
2010-08-27 17:08:28 +08:00
|
|
|
|
|
|
|
if (isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance())
|
|
|
|
return Cl::CL_MemberFunction;
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
bool islvalue;
|
|
|
|
if (const NonTypeTemplateParmDecl *NTTParm =
|
|
|
|
dyn_cast<NonTypeTemplateParmDecl>(D))
|
|
|
|
islvalue = NTTParm->getType()->isReferenceType();
|
|
|
|
else
|
|
|
|
islvalue = isa<VarDecl>(D) || isa<FieldDecl>(D) ||
|
2010-11-21 14:08:52 +08:00
|
|
|
isa<IndirectFieldDecl>(D) ||
|
2012-03-11 15:00:24 +08:00
|
|
|
(Ctx.getLangOpts().CPlusPlus &&
|
2010-06-28 23:09:07 +08:00
|
|
|
(isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)));
|
|
|
|
|
|
|
|
return islvalue ? Cl::CL_LValue : Cl::CL_PRValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ClassifyUnnamed - Return the classification of an expression yielding an
|
|
|
|
/// unnamed value of the given type. This applies in particular to function
|
|
|
|
/// calls and casts.
|
|
|
|
static Cl::Kinds ClassifyUnnamed(ASTContext &Ctx, QualType T) {
|
|
|
|
// In C, function calls are always rvalues.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!Ctx.getLangOpts().CPlusPlus) return Cl::CL_PRValue;
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// C++ [expr.call]p10: A function call is an lvalue if the result type is an
|
|
|
|
// lvalue reference type or an rvalue reference to function type, an xvalue
|
2011-08-31 03:58:05 +08:00
|
|
|
// if the result type is an rvalue reference to object type, and a prvalue
|
2010-06-28 23:09:07 +08:00
|
|
|
// otherwise.
|
|
|
|
if (T->isLValueReferenceType())
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
const RValueReferenceType *RV = T->getAs<RValueReferenceType>();
|
|
|
|
if (!RV) // Could still be a class temporary, though.
|
2012-06-05 06:27:30 +08:00
|
|
|
return ClassifyTemporary(T);
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
return RV->getPointeeType()->isFunctionType() ? Cl::CL_LValue : Cl::CL_XValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E) {
|
2011-04-12 08:42:48 +08:00
|
|
|
if (E->getType() == Ctx.UnknownAnyTy)
|
|
|
|
return (isa<FunctionDecl>(E->getMemberDecl())
|
|
|
|
? Cl::CL_PRValue : Cl::CL_LValue);
|
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
// Handle C first, it's easier.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!Ctx.getLangOpts().CPlusPlus) {
|
2010-06-28 23:09:07 +08:00
|
|
|
// C99 6.5.2.3p3
|
|
|
|
// For dot access, the expression is an lvalue if the first part is. For
|
|
|
|
// arrow access, it always is an lvalue.
|
|
|
|
if (E->isArrow())
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
// ObjC property accesses are not lvalues, but get special treatment.
|
2010-11-16 18:08:07 +08:00
|
|
|
Expr *Base = E->getBase()->IgnoreParens();
|
2010-12-02 09:19:52 +08:00
|
|
|
if (isa<ObjCPropertyRefExpr>(Base))
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CL_SubObjCPropertySetting;
|
|
|
|
return ClassifyInternal(Ctx, Base);
|
|
|
|
}
|
|
|
|
|
|
|
|
NamedDecl *Member = E->getMemberDecl();
|
|
|
|
// C++ [expr.ref]p3: E1->E2 is converted to the equivalent form (*(E1)).E2.
|
|
|
|
// C++ [expr.ref]p4: If E2 is declared to have type "reference to T", then
|
|
|
|
// E1.E2 is an lvalue.
|
|
|
|
if (ValueDecl *Value = dyn_cast<ValueDecl>(Member))
|
|
|
|
if (Value->getType()->isReferenceType())
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
|
|
|
|
// Otherwise, one of the following rules applies.
|
|
|
|
// -- If E2 is a static member [...] then E1.E2 is an lvalue.
|
|
|
|
if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord())
|
|
|
|
return Cl::CL_LValue;
|
|
|
|
|
|
|
|
// -- If E2 is a non-static data member [...]. If E1 is an lvalue, then
|
|
|
|
// E1.E2 is an lvalue; if E1 is an xvalue, then E1.E2 is an xvalue;
|
|
|
|
// otherwise, it is a prvalue.
|
|
|
|
if (isa<FieldDecl>(Member)) {
|
|
|
|
// *E1 is an lvalue
|
|
|
|
if (E->isArrow())
|
|
|
|
return Cl::CL_LValue;
|
2010-11-19 03:01:18 +08:00
|
|
|
Expr *Base = E->getBase()->IgnoreParenImpCasts();
|
2010-12-02 09:19:52 +08:00
|
|
|
if (isa<ObjCPropertyRefExpr>(Base))
|
2010-11-19 03:01:18 +08:00
|
|
|
return Cl::CL_SubObjCPropertySetting;
|
2010-06-28 23:09:07 +08:00
|
|
|
return ClassifyInternal(Ctx, E->getBase());
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- If E2 is a [...] member function, [...]
|
|
|
|
// -- If it refers to a static member function [...], then E1.E2 is an
|
|
|
|
// lvalue; [...]
|
|
|
|
// -- Otherwise [...] E1.E2 is a prvalue.
|
|
|
|
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member))
|
|
|
|
return Method->isStatic() ? Cl::CL_LValue : Cl::CL_MemberFunction;
|
|
|
|
|
|
|
|
// -- If E2 is a member enumerator [...], the expression E1.E2 is a prvalue.
|
|
|
|
// So is everything else we haven't handled yet.
|
|
|
|
return Cl::CL_PRValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cl::Kinds ClassifyBinaryOp(ASTContext &Ctx, const BinaryOperator *E) {
|
2012-03-11 15:00:24 +08:00
|
|
|
assert(Ctx.getLangOpts().CPlusPlus &&
|
2010-06-28 23:09:07 +08:00
|
|
|
"This is only relevant for C++.");
|
|
|
|
// C++ [expr.ass]p1: All [...] return an lvalue referring to the left operand.
|
2010-12-04 11:47:34 +08:00
|
|
|
// Except we override this for writes to ObjC properties.
|
2010-06-28 23:09:07 +08:00
|
|
|
if (E->isAssignmentOp())
|
2010-12-04 11:47:34 +08:00
|
|
|
return (E->getLHS()->getObjectKind() == OK_ObjCProperty
|
|
|
|
? Cl::CL_PRValue : Cl::CL_LValue);
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// C++ [expr.comma]p1: the result is of the same value category as its right
|
|
|
|
// operand, [...].
|
2010-08-25 19:45:40 +08:00
|
|
|
if (E->getOpcode() == BO_Comma)
|
2010-06-28 23:09:07 +08:00
|
|
|
return ClassifyInternal(Ctx, E->getRHS());
|
|
|
|
|
|
|
|
// C++ [expr.mptr.oper]p6: The result of a .* expression whose second operand
|
|
|
|
// is a pointer to a data member is of the same value category as its first
|
|
|
|
// operand.
|
2010-08-25 19:45:40 +08:00
|
|
|
if (E->getOpcode() == BO_PtrMemD)
|
2011-10-19 05:02:43 +08:00
|
|
|
return (E->getType()->isFunctionType() ||
|
|
|
|
E->hasPlaceholderType(BuiltinType::BoundMember))
|
2011-05-22 05:04:55 +08:00
|
|
|
? Cl::CL_MemberFunction
|
|
|
|
: ClassifyInternal(Ctx, E->getLHS());
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// C++ [expr.mptr.oper]p6: The result of an ->* expression is an lvalue if its
|
|
|
|
// second operand is a pointer to data member and a prvalue otherwise.
|
2010-08-25 19:45:40 +08:00
|
|
|
if (E->getOpcode() == BO_PtrMemI)
|
2011-10-19 05:02:43 +08:00
|
|
|
return (E->getType()->isFunctionType() ||
|
|
|
|
E->hasPlaceholderType(BuiltinType::BoundMember))
|
2011-05-22 05:04:55 +08:00
|
|
|
? Cl::CL_MemberFunction
|
|
|
|
: Cl::CL_LValue;
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// All other binary operations are prvalues.
|
|
|
|
return Cl::CL_PRValue;
|
|
|
|
}
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
static Cl::Kinds ClassifyConditional(ASTContext &Ctx, const Expr *True,
|
|
|
|
const Expr *False) {
|
2012-03-11 15:00:24 +08:00
|
|
|
assert(Ctx.getLangOpts().CPlusPlus &&
|
2010-06-28 23:09:07 +08:00
|
|
|
"This is only relevant for C++.");
|
|
|
|
|
|
|
|
// C++ [expr.cond]p2
|
2014-01-27 12:19:56 +08:00
|
|
|
// If either the second or the third operand has type (cv) void,
|
|
|
|
// one of the following shall hold:
|
|
|
|
if (True->getType()->isVoidType() || False->getType()->isVoidType()) {
|
|
|
|
// The second or the third operand (but not both) is a (possibly
|
|
|
|
// parenthesized) throw-expression; the result is of the [...] value
|
|
|
|
// category of the other.
|
|
|
|
bool TrueIsThrow = isa<CXXThrowExpr>(True->IgnoreParenImpCasts());
|
|
|
|
bool FalseIsThrow = isa<CXXThrowExpr>(False->IgnoreParenImpCasts());
|
|
|
|
if (const Expr *NonThrow = TrueIsThrow ? (FalseIsThrow ? 0 : False)
|
|
|
|
: (FalseIsThrow ? True : 0))
|
|
|
|
return ClassifyInternal(Ctx, NonThrow);
|
|
|
|
|
|
|
|
// [Otherwise] the result [...] is a prvalue.
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CL_PRValue;
|
2014-01-27 12:19:56 +08:00
|
|
|
}
|
2010-06-28 23:09:07 +08:00
|
|
|
|
|
|
|
// Note that at this point, we have already performed all conversions
|
|
|
|
// according to [expr.cond]p3.
|
|
|
|
// C++ [expr.cond]p4: If the second and third operands are glvalues of the
|
|
|
|
// same value category [...], the result is of that [...] value category.
|
|
|
|
// C++ [expr.cond]p5: Otherwise, the result is a prvalue.
|
|
|
|
Cl::Kinds LCl = ClassifyInternal(Ctx, True),
|
|
|
|
RCl = ClassifyInternal(Ctx, False);
|
|
|
|
return LCl == RCl ? LCl : Cl::CL_PRValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E,
|
|
|
|
Cl::Kinds Kind, SourceLocation &Loc) {
|
|
|
|
// As a general rule, we only care about lvalues. But there are some rvalues
|
|
|
|
// for which we want to generate special results.
|
|
|
|
if (Kind == Cl::CL_PRValue) {
|
|
|
|
// For the sake of better diagnostics, we want to specifically recognize
|
|
|
|
// use of the GCC cast-as-lvalue extension.
|
2010-12-04 11:47:34 +08:00
|
|
|
if (const ExplicitCastExpr *CE =
|
|
|
|
dyn_cast<ExplicitCastExpr>(E->IgnoreParens())) {
|
|
|
|
if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) {
|
|
|
|
Loc = CE->getExprLoc();
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CM_LValueCast;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Kind != Cl::CL_LValue)
|
|
|
|
return Cl::CM_RValue;
|
|
|
|
|
|
|
|
// This is the lvalue case.
|
|
|
|
// Functions are lvalues in C++, but not modifiable. (C++ [basic.lval]p6)
|
2012-03-11 15:00:24 +08:00
|
|
|
if (Ctx.getLangOpts().CPlusPlus && E->getType()->isFunctionType())
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CM_Function;
|
|
|
|
|
|
|
|
// Assignment to a property in ObjC is an implicit setter access. But a
|
|
|
|
// setter might not exist.
|
2010-12-02 09:19:52 +08:00
|
|
|
if (const ObjCPropertyRefExpr *Expr = dyn_cast<ObjCPropertyRefExpr>(E)) {
|
|
|
|
if (Expr->isImplicitProperty() && Expr->getImplicitPropertySetter() == 0)
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CM_NoSetterProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
CanQualType CT = Ctx.getCanonicalType(E->getType());
|
|
|
|
// Const stuff is obviously not modifiable.
|
2012-03-13 08:37:01 +08:00
|
|
|
if (CT.isConstQualified())
|
2010-06-28 23:09:07 +08:00
|
|
|
return Cl::CM_ConstQualified;
|
2013-11-15 02:26:10 +08:00
|
|
|
if (CT.getQualifiers().getAddressSpace() == LangAS::opencl_constant)
|
|
|
|
return Cl::CM_ConstQualified;
|
2012-03-13 04:57:19 +08:00
|
|
|
|
2010-06-28 23:09:07 +08:00
|
|
|
// Arrays are not modifiable, only their elements are.
|
|
|
|
if (CT->isArrayType())
|
|
|
|
return Cl::CM_ArrayType;
|
|
|
|
// Incomplete types are not modifiable.
|
|
|
|
if (CT->isIncompleteType())
|
|
|
|
return Cl::CM_IncompleteType;
|
|
|
|
|
|
|
|
// Records with any const fields (recursively) are not modifiable.
|
|
|
|
if (const RecordType *R = CT->getAs<RecordType>()) {
|
2010-12-06 13:26:58 +08:00
|
|
|
assert((E->getObjectKind() == OK_ObjCProperty ||
|
2012-03-11 15:00:24 +08:00
|
|
|
!Ctx.getLangOpts().CPlusPlus) &&
|
2010-06-28 23:09:07 +08:00
|
|
|
"C++ struct assignment should be resolved by the "
|
|
|
|
"copy assignment operator.");
|
|
|
|
if (R->hasConstFields())
|
|
|
|
return Cl::CM_ConstQualified;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Cl::CM_Modifiable;
|
|
|
|
}
|
|
|
|
|
2010-11-24 13:12:34 +08:00
|
|
|
Expr::LValueClassification Expr::ClassifyLValue(ASTContext &Ctx) const {
|
2010-06-28 23:09:07 +08:00
|
|
|
Classification VC = Classify(Ctx);
|
|
|
|
switch (VC.getKind()) {
|
|
|
|
case Cl::CL_LValue: return LV_Valid;
|
|
|
|
case Cl::CL_XValue: return LV_InvalidExpression;
|
|
|
|
case Cl::CL_Function: return LV_NotObjectType;
|
2011-04-20 02:51:51 +08:00
|
|
|
case Cl::CL_Void: return LV_InvalidExpression;
|
|
|
|
case Cl::CL_AddressableVoid: return LV_IncompleteVoidType;
|
2010-06-28 23:09:07 +08:00
|
|
|
case Cl::CL_DuplicateVectorComponents: return LV_DuplicateVectorComponents;
|
|
|
|
case Cl::CL_MemberFunction: return LV_MemberFunction;
|
|
|
|
case Cl::CL_SubObjCPropertySetting: return LV_SubObjCPropertySetting;
|
|
|
|
case Cl::CL_ClassTemporary: return LV_ClassTemporary;
|
2012-06-05 06:27:30 +08:00
|
|
|
case Cl::CL_ArrayTemporary: return LV_ArrayTemporary;
|
2011-03-27 03:48:30 +08:00
|
|
|
case Cl::CL_ObjCMessageRValue: return LV_InvalidMessageExpression;
|
2010-06-28 23:09:07 +08:00
|
|
|
case Cl::CL_PRValue: return LV_InvalidExpression;
|
|
|
|
}
|
2010-06-29 08:23:11 +08:00
|
|
|
llvm_unreachable("Unhandled kind");
|
2010-06-28 23:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Expr::isModifiableLvalueResult
|
|
|
|
Expr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const {
|
|
|
|
SourceLocation dummy;
|
|
|
|
Classification VC = ClassifyModifiable(Ctx, Loc ? *Loc : dummy);
|
|
|
|
switch (VC.getKind()) {
|
|
|
|
case Cl::CL_LValue: break;
|
|
|
|
case Cl::CL_XValue: return MLV_InvalidExpression;
|
|
|
|
case Cl::CL_Function: return MLV_NotObjectType;
|
2011-04-20 02:51:51 +08:00
|
|
|
case Cl::CL_Void: return MLV_InvalidExpression;
|
|
|
|
case Cl::CL_AddressableVoid: return MLV_IncompleteVoidType;
|
2010-06-28 23:09:07 +08:00
|
|
|
case Cl::CL_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
|
|
|
|
case Cl::CL_MemberFunction: return MLV_MemberFunction;
|
|
|
|
case Cl::CL_SubObjCPropertySetting: return MLV_SubObjCPropertySetting;
|
|
|
|
case Cl::CL_ClassTemporary: return MLV_ClassTemporary;
|
2012-06-05 06:27:30 +08:00
|
|
|
case Cl::CL_ArrayTemporary: return MLV_ArrayTemporary;
|
2011-03-27 03:48:30 +08:00
|
|
|
case Cl::CL_ObjCMessageRValue: return MLV_InvalidMessageExpression;
|
2010-06-28 23:09:07 +08:00
|
|
|
case Cl::CL_PRValue:
|
|
|
|
return VC.getModifiable() == Cl::CM_LValueCast ?
|
|
|
|
MLV_LValueCast : MLV_InvalidExpression;
|
|
|
|
}
|
|
|
|
assert(VC.getKind() == Cl::CL_LValue && "Unhandled kind");
|
|
|
|
switch (VC.getModifiable()) {
|
2010-06-29 08:23:11 +08:00
|
|
|
case Cl::CM_Untested: llvm_unreachable("Did not test modifiability");
|
2010-06-28 23:09:07 +08:00
|
|
|
case Cl::CM_Modifiable: return MLV_Valid;
|
2010-06-29 08:23:11 +08:00
|
|
|
case Cl::CM_RValue: llvm_unreachable("CM_RValue and CL_LValue don't match");
|
2010-06-28 23:09:07 +08:00
|
|
|
case Cl::CM_Function: return MLV_NotObjectType;
|
|
|
|
case Cl::CM_LValueCast:
|
2010-06-29 08:23:11 +08:00
|
|
|
llvm_unreachable("CM_LValueCast and CL_LValue don't match");
|
2010-06-28 23:09:07 +08:00
|
|
|
case Cl::CM_NoSetterProperty: return MLV_NoSetterProperty;
|
|
|
|
case Cl::CM_ConstQualified: return MLV_ConstQualified;
|
|
|
|
case Cl::CM_ArrayType: return MLV_ArrayType;
|
|
|
|
case Cl::CM_IncompleteType: return MLV_IncompleteType;
|
|
|
|
}
|
2010-06-29 08:23:11 +08:00
|
|
|
llvm_unreachable("Unhandled modifiable type");
|
2010-06-28 23:09:07 +08:00
|
|
|
}
|