clang: lib/AST/ExprClassification.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

20#include "llvm/Support/ErrorHandling.h"

21

22using namespace clang;

23

25

32 const Expr *trueExpr,

33 const Expr *falseExpr);

36

38 assert(!TR->isReferenceType() && "Expressions can't have reference type.");

39

41

42

44

47

48

49

52 }

53

54

55 switch (kind) {

58 break;

61 break;

73 break;

74 }

75

77 if (Loc)

78 modifiable = IsModifiable(Ctx, this, kind, *Loc);

80}

81

82

84 if (T->isRecordType())

86 if (T->isArrayType())

88

89

90

92}

93

95 const Expr *E,

97 switch (Kind) {

104 }

105 llvm_unreachable("Invalid value category of implicit cast.");

106}

107

109

111

114#define ABSTRACT_STMT(Kind)

115#define STMT(Kind, Base) case Expr::Kind##Class:

116#define EXPR(Kind, Base)

117#include "clang/AST/StmtNodes.inc"

118 llvm_unreachable("cannot classify a statement");

119

120

121 case Expr::ObjCIsaExprClass:

122

123 case Expr::ObjCSubscriptRefExprClass:

124 case Expr::ObjCPropertyRefExprClass:

125

126 case Expr::CXXTypeidExprClass:

127 case Expr::CXXUuidofExprClass:

128

129

130 case Expr::UnresolvedLookupExprClass:

131 case Expr::UnresolvedMemberExprClass:

132 case Expr::DependentCoawaitExprClass:

133 case Expr::CXXDependentScopeMemberExprClass:

134 case Expr::DependentScopeDeclRefExprClass:

135

136

137 case Expr::ObjCIvarRefExprClass:

138 case Expr::FunctionParmPackExprClass:

139 case Expr::MSPropertyRefExprClass:

140 case Expr::MSPropertySubscriptExprClass:

141 case Expr::ArraySectionExprClass:

142 case Expr::OMPArrayShapingExprClass:

143 case Expr::OMPIteratorExprClass:

144 case Expr::HLSLOutArgExprClass:

146

147

148 case Expr::StringLiteralClass:

149

150 case Expr::ObjCEncodeExprClass:

151

152

154

155

156

157

158 case Expr::PredefinedExprClass: {

161 if (PE->isTransparent())

163 assert(!SL || SL->isLValue());

165 }

166

167

168

169 case Expr::CompoundLiteralExprClass:

171

172

173 case Expr::CXXBoolLiteralExprClass:

174 case Expr::CXXPseudoDestructorExprClass:

175 case Expr::UnaryExprOrTypeTraitExprClass:

176 case Expr::CXXNewExprClass:

177 case Expr::CXXNullPtrLiteralExprClass:

178 case Expr::ImaginaryLiteralClass:

179 case Expr::GNUNullExprClass:

180 case Expr::OffsetOfExprClass:

181 case Expr::CXXThrowExprClass:

182 case Expr::ShuffleVectorExprClass:

183 case Expr::ConvertVectorExprClass:

184 case Expr::IntegerLiteralClass:

185 case Expr::FixedPointLiteralClass:

186 case Expr::CharacterLiteralClass:

187 case Expr::AddrLabelExprClass:

188 case Expr::CXXDeleteExprClass:

189 case Expr::ImplicitValueInitExprClass:

190 case Expr::BlockExprClass:

191 case Expr::FloatingLiteralClass:

192 case Expr::CXXNoexceptExprClass:

193 case Expr::CXXScalarValueInitExprClass:

194 case Expr::TypeTraitExprClass:

195 case Expr::ArrayTypeTraitExprClass:

196 case Expr::ExpressionTraitExprClass:

197 case Expr::ObjCSelectorExprClass:

198 case Expr::ObjCProtocolExprClass:

199 case Expr::ObjCStringLiteralClass:

200 case Expr::ObjCBoxedExprClass:

201 case Expr::ObjCArrayLiteralClass:

202 case Expr::ObjCDictionaryLiteralClass:

203 case Expr::ObjCBoolLiteralExprClass:

204 case Expr::ObjCAvailabilityCheckExprClass:

205 case Expr::ParenListExprClass:

206 case Expr::SizeOfPackExprClass:

207 case Expr::SubstNonTypeTemplateParmPackExprClass:

208 case Expr::AsTypeExprClass:

209 case Expr::ObjCIndirectCopyRestoreExprClass:

210 case Expr::AtomicExprClass:

211 case Expr::CXXFoldExprClass:

212 case Expr::ArrayInitLoopExprClass:

213 case Expr::ArrayInitIndexExprClass:

214 case Expr::NoInitExprClass:

215 case Expr::DesignatedInitUpdateExprClass:

216 case Expr::SourceLocExprClass:

217 case Expr::ConceptSpecializationExprClass:

218 case Expr::RequiresExprClass:

220

221 case Expr::EmbedExprClass:

222

223

225

226

227 case Expr::CXXThisExprClass:

229

230 case Expr::ConstantExprClass:

232

233

234 case Expr::SubstNonTypeTemplateParmExprClass:

237

238 case Expr::PackIndexingExprClass: {

239

240

244 }

245

246

247

248

249

250 case Expr::ArraySubscriptExprClass:

253 if (Lang.CPlusPlus11) {

254

255

257 if (Base->getType()->isArrayType())

259 }

261

262

263 case Expr::MatrixSubscriptExprClass:

265

266

267

268 case Expr::DeclRefExprClass:

273

274

275 case Expr::MemberExprClass:

277

278 case Expr::UnaryOperatorClass:

280

281

282

283 case UO_Deref:

285

286

287 case UO_Extension:

289

290

291

292 case UO_Real:

293 case UO_Imag: {

297

301 }

302

303

304

305

306 case UO_PreInc:

307 case UO_PreDec:

309

310 default:

312 }

313

314 case Expr::RecoveryExprClass:

315 case Expr::OpaqueValueExprClass:

317

318

319 case Expr::PseudoObjectExprClass:

322

323

324

325 case Expr::ImplicitCastExprClass:

327

328

329

330 case Expr::ParenExprClass:

332

333

334

335

336 case Expr::GenericSelectionExprClass:

340

341 case Expr::BinaryOperatorClass:

342 case Expr::CompoundAssignOperatorClass:

343

344 if (Lang.CPlusPlus)

347

348 case Expr::CallExprClass:

349 case Expr::CXXOperatorCallExprClass:

350 case Expr::CXXMemberCallExprClass:

351 case Expr::UserDefinedLiteralClass:

352 case Expr::CUDAKernelCallExprClass:

354

355 case Expr::CXXRewrittenBinaryOperatorClass:

358

359

360 case Expr::ChooseExprClass:

362

363

364

365 case Expr::ExtVectorElementExprClass:

371

372

373 case Expr::CXXDefaultArgExprClass:

375

376

377 case Expr::CXXDefaultInitExprClass:

379

380

381 case Expr::CXXBindTemporaryExprClass:

383

384

385 case Expr::ExprWithCleanupsClass:

387

388

389 case Expr::CStyleCastExprClass:

390 case Expr::CXXFunctionalCastExprClass:

391 case Expr::CXXStaticCastExprClass:

392 case Expr::CXXDynamicCastExprClass:

393 case Expr::CXXReinterpretCastExprClass:

394 case Expr::CXXConstCastExprClass:

395 case Expr::CXXAddrspaceCastExprClass:

396 case Expr::ObjCBridgedCastExprClass:

397 case Expr::BuiltinBitCastExprClass:

398

401

402 case Expr::CXXUnresolvedConstructExprClass:

405

406 case Expr::BinaryConditionalOperatorClass: {

410 }

411

412 case Expr::ConditionalOperatorClass: {

413

417 }

418

419

420

421 case Expr::ObjCMessageExprClass:

426 }

428

429

430 case Expr::CXXConstructExprClass:

431 case Expr::CXXInheritedCtorInitExprClass:

432 case Expr::CXXTemporaryObjectExprClass:

433 case Expr::LambdaExprClass:

434 case Expr::CXXStdInitializerListExprClass:

436

437 case Expr::VAArgExprClass:

439

440 case Expr::DesignatedInitExprClass:

442

443 case Expr::StmtExprClass: {

445 if (const auto *LastExpr = dyn_cast_or_null(S->body_back()))

448 }

449

450 case Expr::PackExpansionExprClass:

452

453 case Expr::MaterializeTemporaryExprClass:

457

458 case Expr::InitListExprClass:

459

460

461

462

466 "Only 1-element init lists can be glvalues.");

468

469 case Expr::CoawaitExprClass:

470 case Expr::CoyieldExprClass:

472 case Expr::SYCLUniqueStableNameExprClass:

473 case Expr::OpenACCAsteriskSizeExprClass:

475 break;

476

477 case Expr::CXXParenListInitExprClass:

481 }

482

483 llvm_unreachable("unhandled expression kind in classification");

484}

485

486

487

489

490

491

492

493

494

495

496

497 if (const auto *M = dyn_cast(D)) {

498 if (M->isImplicitObjectMemberFunction())

500 if (M->isStatic())

503 }

504

505 bool islvalue;

506 if (const auto *NTTParm = dyn_cast(D))

507 islvalue = NTTParm->getType()->isReferenceType() ||

508 NTTParm->getType()->isRecordType();

509 else

510 islvalue =

515

517}

518

519

520

521

523

525

526

527

528

529

530 if (T->isLValueReferenceType())

533 if (!RV)

535

537}

538

543

544

546

547

548

551

556 }

557

559

560

561

562 if (const auto *Value = dyn_cast(Member))

565

566

567

570

571

572

573

575

582 }

583

584

585

586

587

588 if (const auto *Method = dyn_cast(Member)) {

589 if (Method->isStatic())

591 if (Method->isImplicitObjectMemberFunction())

594 }

595

596

597

599}

600

603 "This is only relevant for C++.");

604

605

606

607

610

611

612

616

617

618

621

622

623

624

625 if (E->getOpcode() == BO_PtrMemD)

630

631

632

633 if (E->getOpcode() == BO_PtrMemI)

638

639

641}

642

646 "This is only relevant for C++.");

647

648

649

650

651 if (True->getType()->isVoidType() || False->getType()->isVoidType()) {

652

653

654

657 if (const Expr *NonThrow = TrueIsThrow ? (FalseIsThrow ? nullptr : False)

658 : (FalseIsThrow ? True : nullptr))

660

661

663 }

664

665

666

667

668

669

673}

674

677

678

680

681

682 if (const auto *CE = dyn_cast(E->IgnoreParens())) {

683 if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) {

684 Loc = CE->getExprLoc();

686 }

687 }

688 }

691

692

693

696

697

698

699 if (const auto *Expr = dyn_cast(E)) {

700 if (Expr->isImplicitProperty() &&

701 Expr->getImplicitPropertySetter() == nullptr)

703 }

704

706

712

713

714 if (CT->isArrayType() &&

715 !(Ctx.getLangOpts().HLSL && CT->isConstantArrayType()))

717

718 if (CT->isIncompleteType())

720

721

722 if (const RecordType *R = CT->getAs())

723 if (R->hasConstFields())

725

727}

728

744 }

745 llvm_unreachable("Unhandled kind");

746}

747

767 }

770 case Cl::CM_Untested: llvm_unreachable("Did not test modifiability");

772 case Cl::CM_RValue: llvm_unreachable("CM_RValue and CL_LValue don't match");

775 llvm_unreachable("CM_LValueCast and CL_LValue don't match");

782 }

783 llvm_unreachable("Unhandled modifiable type");

784}

Defines the clang::ASTContext interface.

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

Defines the C++ template declaration subclasses.

Defines the clang::Expr interface and subclasses for C++ expressions.

static Cl::Kinds ClassifyUnnamed(ASTContext &Ctx, QualType T)

ClassifyUnnamed - Return the classification of an expression yielding an unnamed value of the given t...

Definition ExprClassification.cpp:522

static Cl::Kinds ClassifyConditional(ASTContext &Ctx, const Expr *trueExpr, const Expr *falseExpr)

Definition ExprClassification.cpp:643

static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D)

ClassifyDecl - Return the classification of an expression referencing the given declaration.

Definition ExprClassification.cpp:488

static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E)

Definition ExprClassification.cpp:539

static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E)

Definition ExprClassification.cpp:108

static Cl::Kinds ClassifyExprValueKind(const LangOptions &Lang, const Expr *E, ExprValueKind Kind)

Definition ExprClassification.cpp:94

static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, Cl::Kinds Kind, SourceLocation &Loc)

Definition ExprClassification.cpp:675

Expr::Classification Cl

Definition ExprClassification.cpp:24

static Cl::Kinds ClassifyTemporary(QualType T)

Classify an expression which creates a temporary, based on its type.

Definition ExprClassification.cpp:83

static Cl::Kinds ClassifyBinaryOp(ASTContext &Ctx, const BinaryOperator *E)

Definition ExprClassification.cpp:601

TokenType getType() const

Returns the token's type, e.g.

Expr * getExpr()

Get 'expr' part of the associated expression/statement.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

static CanQualType getCanonicalType(QualType T)

Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...

const LangOptions & getLangOpts() const

A builtin binary operation expression such as "x + y" or "x <= y".

static bool isAssignmentOp(Opcode Opc)

A binding in a decomposition declaration.

bool isConstQualified() const

Qualifiers getQualifiers() const

Retrieve all qualifiers.

CanProxy< U > getAs() const

Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed.

CompoundStmt - This represents a group of statements like { stmt stmt }.

Decl - This represents one declaration (or definition), e.g.

The return type of classify().

ModifiableType

The results of modification testing.

ModifiableType getModifiable() const

Kinds

The various classification results. Most of these mean prvalue.

@ CL_SubObjCPropertySetting

@ CL_DuplicateVectorComponents

This represents one expression.

@ LV_DuplicateVectorComponents

@ LV_InvalidMessageExpression

@ LV_SubObjCPropertySetting

Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const

ClassifyModifiable - 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...

Definition ExprClassification.cpp:749

LValueClassification ClassifyLValue(ASTContext &Ctx) const

Reasons why an expression might not be an l-value.

Definition ExprClassification.cpp:729

ExprValueKind getValueKind() const

getValueKind - The value kind that this expression produces.

Expr * IgnoreParenImpCasts() LLVM_READONLY

Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...

Expr * IgnoreParens() LLVM_READONLY

Skip past any parentheses which might surround this expression until reaching a fixed point.

bool isLValue() const

isLValue - True if this expression is an "l-value" according to the rules of the current language.

ExprObjectKind getObjectKind() const

getObjectKind - The object kind that this expression produces.

@ MLV_DuplicateVectorComponents

@ MLV_InvalidMessageExpression

@ MLV_ConstQualifiedField

@ MLV_SubObjCPropertySetting

Classification Classify(ASTContext &Ctx) const

Classify - Classify this expression according to the C++11 expression taxonomy.

bool hasPlaceholderType() const

Returns whether this expression has a placeholder type.

Represents a member of a struct/union/class.

Represents a field injected from an anonymous union/struct into the parent scope.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

MemberExpr - [C99 6.5.2.3] Structure and Union Members.

ValueDecl * getMemberDecl() const

Retrieve the member declaration to which this expression refers.

This represents a decl that may have a name.

ObjCMethodDecl - Represents an instance or class method declaration.

A (possibly-)qualified type.

bool hasQualifiers() const

Determine whether this type has any qualifiers.

LangAS getAddressSpace() const

An rvalue reference type, per C++11 [dcl.ref].

Encodes a location in the source.

StmtClass getStmtClass() const

StringLiteral - This represents a string literal expression, e.g.

A template parameter object.

bool isReferenceType() const

bool isFunctionType() const

An artificial decl, representing a global anonymous constant value which is uniquified by value withi...

Represents a variable declaration or definition.

The JSON file list parser is used to communicate input to InstallAPI.

CanQual< Type > CanQualType

Represents a canonical, potentially-qualified type.

bool isa(CodeGen::Address addr)

@ OK_ObjCProperty

An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...

const FunctionProtoType * T

ExprValueKind

The categorization of expression values, currently following the C++11 scheme.

@ VK_PRValue

A pr-value expression (in the C++11 taxonomy) produces a temporary value.

@ VK_XValue

An x-value expression is a reference to an object with independent storage but which can be "moved",...

@ VK_LValue

An l-value expression is a reference to an object with independent storage.

U cast(CodeGen::Address addr)