| 1 | //===- Stmt.h - Classes for representing statements -------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the Stmt interface and subclasses. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CLANG_AST_STMT_H |
| 14 | #define LLVM_CLANG_AST_STMT_H |
| 15 | |
| 16 | #include "clang/AST/APValue.h" |
| 17 | #include "clang/AST/DeclGroup.h" |
| 18 | #include "clang/AST/DependenceFlags.h" |
| 19 | #include "clang/AST/OperationKinds.h" |
| 20 | #include "clang/AST/StmtIterator.h" |
| 21 | #include "clang/Basic/CapturedStmt.h" |
| 22 | #include "clang/Basic/ExpressionTraits.h" |
| 23 | #include "clang/Basic/IdentifierTable.h" |
| 24 | #include "clang/Basic/LLVM.h" |
| 25 | #include "clang/Basic/Lambda.h" |
| 26 | #include "clang/Basic/LangOptions.h" |
| 27 | #include "clang/Basic/OperatorKinds.h" |
| 28 | #include "clang/Basic/SourceLocation.h" |
| 29 | #include "clang/Basic/Specifiers.h" |
| 30 | #include "clang/Basic/TypeTraits.h" |
| 31 | #include "llvm/ADT/APFloat.h" |
| 32 | #include "llvm/ADT/ArrayRef.h" |
| 33 | #include "llvm/ADT/BitmaskEnum.h" |
| 34 | #include "llvm/ADT/PointerIntPair.h" |
| 35 | #include "llvm/ADT/StringRef.h" |
| 36 | #include "llvm/ADT/iterator.h" |
| 37 | #include "llvm/ADT/iterator_range.h" |
| 38 | #include "llvm/Support/Casting.h" |
| 39 | #include "llvm/Support/Compiler.h" |
| 40 | #include "llvm/Support/ErrorHandling.h" |
| 41 | #include <algorithm> |
| 42 | #include <cassert> |
| 43 | #include <cstddef> |
| 44 | #include <iterator> |
| 45 | #include <optional> |
| 46 | #include <string> |
| 47 | |
| 48 | namespace llvm { |
| 49 | |
| 50 | class FoldingSetNodeID; |
| 51 | |
| 52 | } // namespace llvm |
| 53 | |
| 54 | namespace clang { |
| 55 | |
| 56 | class ASTContext; |
| 57 | class Attr; |
| 58 | class CapturedDecl; |
| 59 | class Decl; |
| 60 | class Expr; |
| 61 | class AddrLabelExpr; |
| 62 | class LabelDecl; |
| 63 | class ODRHash; |
| 64 | class PrinterHelper; |
| 65 | struct PrintingPolicy; |
| 66 | class RecordDecl; |
| 67 | class SourceManager; |
| 68 | class StringLiteral; |
| 69 | class Token; |
| 70 | class VarDecl; |
| 71 | enum class CharacterLiteralKind; |
| 72 | enum class ConstantResultStorageKind; |
| 73 | enum class CXXConstructionKind; |
| 74 | enum class CXXNewInitializationStyle; |
| 75 | enum class PredefinedIdentKind; |
| 76 | enum class SourceLocIdentKind; |
| 77 | enum class StringLiteralKind; |
| 78 | |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | // AST classes for statements. |
| 81 | //===----------------------------------------------------------------------===// |
| 82 | |
| 83 | /// Stmt - This represents one statement. |
| 84 | /// |
| 85 | class alignas(void *) Stmt { |
| 86 | public: |
| 87 | enum StmtClass { |
| 88 | NoStmtClass = 0, |
| 89 | #define STMT(CLASS, PARENT) CLASS##Class, |
| 90 | #define STMT_RANGE(BASE, FIRST, LAST) \ |
| 91 | first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class, |
| 92 | #define LAST_STMT_RANGE(BASE, FIRST, LAST) \ |
| 93 | first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class |
| 94 | #define ABSTRACT_STMT(STMT) |
| 95 | #include "clang/AST/StmtNodes.inc" |
| 96 | }; |
| 97 | |
| 98 | // Make vanilla 'new' and 'delete' illegal for Stmts. |
| 99 | protected: |
| 100 | friend class ASTStmtReader; |
| 101 | friend class ASTStmtWriter; |
| 102 | |
| 103 | void *operator new(size_t bytes) noexcept { |
| 104 | llvm_unreachable("Stmts cannot be allocated with regular 'new'." ); |
| 105 | } |
| 106 | |
| 107 | void operator delete(void *data) noexcept { |
| 108 | llvm_unreachable("Stmts cannot be released with regular 'delete'." ); |
| 109 | } |
| 110 | |
| 111 | //===--- Statement bitfields classes ---===// |
| 112 | |
| 113 | #define NumStmtBits 9 |
| 114 | |
| 115 | class StmtBitfields { |
| 116 | friend class ASTStmtReader; |
| 117 | friend class ASTStmtWriter; |
| 118 | friend class Stmt; |
| 119 | |
| 120 | /// The statement class. |
| 121 | LLVM_PREFERRED_TYPE(StmtClass) |
| 122 | unsigned sClass : NumStmtBits; |
| 123 | }; |
| 124 | |
| 125 | class NullStmtBitfields { |
| 126 | friend class ASTStmtReader; |
| 127 | friend class ASTStmtWriter; |
| 128 | friend class NullStmt; |
| 129 | |
| 130 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 131 | unsigned : NumStmtBits; |
| 132 | |
| 133 | /// True if the null statement was preceded by an empty macro, e.g: |
| 134 | /// @code |
| 135 | /// #define CALL(x) |
| 136 | /// CALL(0); |
| 137 | /// @endcode |
| 138 | LLVM_PREFERRED_TYPE(bool) |
| 139 | unsigned HasLeadingEmptyMacro : 1; |
| 140 | |
| 141 | /// The location of the semi-colon. |
| 142 | SourceLocation SemiLoc; |
| 143 | }; |
| 144 | |
| 145 | class CompoundStmtBitfields { |
| 146 | friend class ASTStmtReader; |
| 147 | friend class CompoundStmt; |
| 148 | |
| 149 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 150 | unsigned : NumStmtBits; |
| 151 | |
| 152 | /// True if the compound statement has one or more pragmas that set some |
| 153 | /// floating-point features. |
| 154 | LLVM_PREFERRED_TYPE(bool) |
| 155 | unsigned HasFPFeatures : 1; |
| 156 | |
| 157 | unsigned NumStmts; |
| 158 | }; |
| 159 | |
| 160 | class LabelStmtBitfields { |
| 161 | friend class LabelStmt; |
| 162 | |
| 163 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 164 | unsigned : NumStmtBits; |
| 165 | |
| 166 | SourceLocation IdentLoc; |
| 167 | }; |
| 168 | |
| 169 | class AttributedStmtBitfields { |
| 170 | friend class ASTStmtReader; |
| 171 | friend class AttributedStmt; |
| 172 | |
| 173 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 174 | unsigned : NumStmtBits; |
| 175 | |
| 176 | /// Number of attributes. |
| 177 | unsigned NumAttrs : 32 - NumStmtBits; |
| 178 | |
| 179 | /// The location of the attribute. |
| 180 | SourceLocation AttrLoc; |
| 181 | }; |
| 182 | |
| 183 | class IfStmtBitfields { |
| 184 | friend class ASTStmtReader; |
| 185 | friend class IfStmt; |
| 186 | |
| 187 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 188 | unsigned : NumStmtBits; |
| 189 | |
| 190 | /// Whether this is a constexpr if, or a consteval if, or neither. |
| 191 | LLVM_PREFERRED_TYPE(IfStatementKind) |
| 192 | unsigned Kind : 3; |
| 193 | |
| 194 | /// True if this if statement has storage for an else statement. |
| 195 | LLVM_PREFERRED_TYPE(bool) |
| 196 | unsigned HasElse : 1; |
| 197 | |
| 198 | /// True if this if statement has storage for a variable declaration. |
| 199 | LLVM_PREFERRED_TYPE(bool) |
| 200 | unsigned HasVar : 1; |
| 201 | |
| 202 | /// True if this if statement has storage for an init statement. |
| 203 | LLVM_PREFERRED_TYPE(bool) |
| 204 | unsigned HasInit : 1; |
| 205 | |
| 206 | /// The location of the "if". |
| 207 | SourceLocation IfLoc; |
| 208 | }; |
| 209 | |
| 210 | class SwitchStmtBitfields { |
| 211 | friend class SwitchStmt; |
| 212 | |
| 213 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 214 | unsigned : NumStmtBits; |
| 215 | |
| 216 | /// True if the SwitchStmt has storage for an init statement. |
| 217 | LLVM_PREFERRED_TYPE(bool) |
| 218 | unsigned HasInit : 1; |
| 219 | |
| 220 | /// True if the SwitchStmt has storage for a condition variable. |
| 221 | LLVM_PREFERRED_TYPE(bool) |
| 222 | unsigned HasVar : 1; |
| 223 | |
| 224 | /// If the SwitchStmt is a switch on an enum value, records whether all |
| 225 | /// the enum values were covered by CaseStmts. The coverage information |
| 226 | /// value is meant to be a hint for possible clients. |
| 227 | LLVM_PREFERRED_TYPE(bool) |
| 228 | unsigned AllEnumCasesCovered : 1; |
| 229 | |
| 230 | /// The location of the "switch". |
| 231 | SourceLocation SwitchLoc; |
| 232 | }; |
| 233 | |
| 234 | class WhileStmtBitfields { |
| 235 | friend class ASTStmtReader; |
| 236 | friend class WhileStmt; |
| 237 | |
| 238 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 239 | unsigned : NumStmtBits; |
| 240 | |
| 241 | /// True if the WhileStmt has storage for a condition variable. |
| 242 | LLVM_PREFERRED_TYPE(bool) |
| 243 | unsigned HasVar : 1; |
| 244 | |
| 245 | /// The location of the "while". |
| 246 | SourceLocation WhileLoc; |
| 247 | }; |
| 248 | |
| 249 | class DoStmtBitfields { |
| 250 | friend class DoStmt; |
| 251 | |
| 252 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 253 | unsigned : NumStmtBits; |
| 254 | |
| 255 | /// The location of the "do". |
| 256 | SourceLocation DoLoc; |
| 257 | }; |
| 258 | |
| 259 | class ForStmtBitfields { |
| 260 | friend class ForStmt; |
| 261 | |
| 262 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 263 | unsigned : NumStmtBits; |
| 264 | |
| 265 | /// The location of the "for". |
| 266 | SourceLocation ForLoc; |
| 267 | }; |
| 268 | |
| 269 | class GotoStmtBitfields { |
| 270 | friend class GotoStmt; |
| 271 | friend class IndirectGotoStmt; |
| 272 | |
| 273 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 274 | unsigned : NumStmtBits; |
| 275 | |
| 276 | /// The location of the "goto". |
| 277 | SourceLocation GotoLoc; |
| 278 | }; |
| 279 | |
| 280 | class ContinueStmtBitfields { |
| 281 | friend class ContinueStmt; |
| 282 | |
| 283 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 284 | unsigned : NumStmtBits; |
| 285 | |
| 286 | /// The location of the "continue". |
| 287 | SourceLocation ContinueLoc; |
| 288 | }; |
| 289 | |
| 290 | class BreakStmtBitfields { |
| 291 | friend class BreakStmt; |
| 292 | |
| 293 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 294 | unsigned : NumStmtBits; |
| 295 | |
| 296 | /// The location of the "break". |
| 297 | SourceLocation BreakLoc; |
| 298 | }; |
| 299 | |
| 300 | class ReturnStmtBitfields { |
| 301 | friend class ReturnStmt; |
| 302 | |
| 303 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 304 | unsigned : NumStmtBits; |
| 305 | |
| 306 | /// True if this ReturnStmt has storage for an NRVO candidate. |
| 307 | LLVM_PREFERRED_TYPE(bool) |
| 308 | unsigned HasNRVOCandidate : 1; |
| 309 | |
| 310 | /// The location of the "return". |
| 311 | SourceLocation RetLoc; |
| 312 | }; |
| 313 | |
| 314 | class SwitchCaseBitfields { |
| 315 | friend class SwitchCase; |
| 316 | friend class CaseStmt; |
| 317 | |
| 318 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 319 | unsigned : NumStmtBits; |
| 320 | |
| 321 | /// Used by CaseStmt to store whether it is a case statement |
| 322 | /// of the form case LHS ... RHS (a GNU extension). |
| 323 | LLVM_PREFERRED_TYPE(bool) |
| 324 | unsigned CaseStmtIsGNURange : 1; |
| 325 | |
| 326 | /// The location of the "case" or "default" keyword. |
| 327 | SourceLocation KeywordLoc; |
| 328 | }; |
| 329 | |
| 330 | //===--- Expression bitfields classes ---===// |
| 331 | |
| 332 | class ExprBitfields { |
| 333 | friend class ASTStmtReader; // deserialization |
| 334 | friend class AtomicExpr; // ctor |
| 335 | friend class BlockDeclRefExpr; // ctor |
| 336 | friend class CallExpr; // ctor |
| 337 | friend class CXXConstructExpr; // ctor |
| 338 | friend class CXXDependentScopeMemberExpr; // ctor |
| 339 | friend class CXXNewExpr; // ctor |
| 340 | friend class CXXUnresolvedConstructExpr; // ctor |
| 341 | friend class DeclRefExpr; // computeDependence |
| 342 | friend class DependentScopeDeclRefExpr; // ctor |
| 343 | friend class DesignatedInitExpr; // ctor |
| 344 | friend class Expr; |
| 345 | friend class InitListExpr; // ctor |
| 346 | friend class ObjCArrayLiteral; // ctor |
| 347 | friend class ObjCDictionaryLiteral; // ctor |
| 348 | friend class ObjCMessageExpr; // ctor |
| 349 | friend class OffsetOfExpr; // ctor |
| 350 | friend class OpaqueValueExpr; // ctor |
| 351 | friend class OverloadExpr; // ctor |
| 352 | friend class ParenListExpr; // ctor |
| 353 | friend class PseudoObjectExpr; // ctor |
| 354 | friend class ShuffleVectorExpr; // ctor |
| 355 | |
| 356 | LLVM_PREFERRED_TYPE(StmtBitfields) |
| 357 | unsigned : NumStmtBits; |
| 358 | |
| 359 | LLVM_PREFERRED_TYPE(ExprValueKind) |
| 360 | unsigned ValueKind : 2; |
| 361 | LLVM_PREFERRED_TYPE(ExprObjectKind) |
| 362 | unsigned ObjectKind : 3; |
| 363 | LLVM_PREFERRED_TYPE(ExprDependence) |
| 364 | unsigned Dependent : llvm::BitWidth<ExprDependence>; |
| 365 | }; |
| 366 | enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth<ExprDependence> }; |
| 367 | |
| 368 | class ConstantExprBitfields { |
| 369 | friend class ASTStmtReader; |
| 370 | friend class ASTStmtWriter; |
| 371 | friend class ConstantExpr; |
| 372 | |
| 373 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 374 | unsigned : NumExprBits; |
| 375 | |
| 376 | /// The kind of result that is tail-allocated. |
| 377 | LLVM_PREFERRED_TYPE(ConstantResultStorageKind) |
| 378 | unsigned ResultKind : 2; |
| 379 | |
| 380 | /// The kind of Result as defined by APValue::ValueKind. |
| 381 | LLVM_PREFERRED_TYPE(APValue::ValueKind) |
| 382 | unsigned APValueKind : 4; |
| 383 | |
| 384 | /// When ResultKind == ConstantResultStorageKind::Int64, true if the |
| 385 | /// tail-allocated integer is unsigned. |
| 386 | LLVM_PREFERRED_TYPE(bool) |
| 387 | unsigned IsUnsigned : 1; |
| 388 | |
| 389 | /// When ResultKind == ConstantResultStorageKind::Int64. the BitWidth of the |
| 390 | /// tail-allocated integer. 7 bits because it is the minimal number of bits |
| 391 | /// to represent a value from 0 to 64 (the size of the tail-allocated |
| 392 | /// integer). |
| 393 | unsigned BitWidth : 7; |
| 394 | |
| 395 | /// When ResultKind == ConstantResultStorageKind::APValue, true if the |
| 396 | /// ASTContext will cleanup the tail-allocated APValue. |
| 397 | LLVM_PREFERRED_TYPE(bool) |
| 398 | unsigned HasCleanup : 1; |
| 399 | |
| 400 | /// True if this ConstantExpr was created for immediate invocation. |
| 401 | LLVM_PREFERRED_TYPE(bool) |
| 402 | unsigned IsImmediateInvocation : 1; |
| 403 | }; |
| 404 | |
| 405 | class PredefinedExprBitfields { |
| 406 | friend class ASTStmtReader; |
| 407 | friend class PredefinedExpr; |
| 408 | |
| 409 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 410 | unsigned : NumExprBits; |
| 411 | |
| 412 | LLVM_PREFERRED_TYPE(PredefinedIdentKind) |
| 413 | unsigned Kind : 4; |
| 414 | |
| 415 | /// True if this PredefinedExpr has a trailing "StringLiteral *" |
| 416 | /// for the predefined identifier. |
| 417 | LLVM_PREFERRED_TYPE(bool) |
| 418 | unsigned HasFunctionName : 1; |
| 419 | |
| 420 | /// True if this PredefinedExpr should be treated as a StringLiteral (for |
| 421 | /// MSVC compatibility). |
| 422 | LLVM_PREFERRED_TYPE(bool) |
| 423 | unsigned IsTransparent : 1; |
| 424 | |
| 425 | /// The location of this PredefinedExpr. |
| 426 | SourceLocation Loc; |
| 427 | }; |
| 428 | |
| 429 | class DeclRefExprBitfields { |
| 430 | friend class ASTStmtReader; // deserialization |
| 431 | friend class DeclRefExpr; |
| 432 | |
| 433 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 434 | unsigned : NumExprBits; |
| 435 | |
| 436 | LLVM_PREFERRED_TYPE(bool) |
| 437 | unsigned HasQualifier : 1; |
| 438 | LLVM_PREFERRED_TYPE(bool) |
| 439 | unsigned HasTemplateKWAndArgsInfo : 1; |
| 440 | LLVM_PREFERRED_TYPE(bool) |
| 441 | unsigned HasFoundDecl : 1; |
| 442 | LLVM_PREFERRED_TYPE(bool) |
| 443 | unsigned HadMultipleCandidates : 1; |
| 444 | LLVM_PREFERRED_TYPE(bool) |
| 445 | unsigned RefersToEnclosingVariableOrCapture : 1; |
| 446 | LLVM_PREFERRED_TYPE(bool) |
| 447 | unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1; |
| 448 | LLVM_PREFERRED_TYPE(NonOdrUseReason) |
| 449 | unsigned NonOdrUseReason : 2; |
| 450 | LLVM_PREFERRED_TYPE(bool) |
| 451 | unsigned IsImmediateEscalating : 1; |
| 452 | |
| 453 | /// The location of the declaration name itself. |
| 454 | SourceLocation Loc; |
| 455 | }; |
| 456 | |
| 457 | |
| 458 | class FloatingLiteralBitfields { |
| 459 | friend class FloatingLiteral; |
| 460 | |
| 461 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 462 | unsigned : NumExprBits; |
| 463 | |
| 464 | static_assert( |
| 465 | llvm::APFloat::S_MaxSemantics < 32, |
| 466 | "Too many Semantics enum values to fit in bitfield of size 5" ); |
| 467 | LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics) |
| 468 | unsigned Semantics : 5; // Provides semantics for APFloat construction |
| 469 | LLVM_PREFERRED_TYPE(bool) |
| 470 | unsigned IsExact : 1; |
| 471 | }; |
| 472 | |
| 473 | class StringLiteralBitfields { |
| 474 | friend class ASTStmtReader; |
| 475 | friend class StringLiteral; |
| 476 | |
| 477 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 478 | unsigned : NumExprBits; |
| 479 | |
| 480 | /// The kind of this string literal. |
| 481 | /// One of the enumeration values of StringLiteral::StringKind. |
| 482 | LLVM_PREFERRED_TYPE(StringLiteralKind) |
| 483 | unsigned Kind : 3; |
| 484 | |
| 485 | /// The width of a single character in bytes. Only values of 1, 2, |
| 486 | /// and 4 bytes are supported. StringLiteral::mapCharByteWidth maps |
| 487 | /// the target + string kind to the appropriate CharByteWidth. |
| 488 | unsigned CharByteWidth : 3; |
| 489 | |
| 490 | LLVM_PREFERRED_TYPE(bool) |
| 491 | unsigned IsPascal : 1; |
| 492 | |
| 493 | /// The number of concatenated token this string is made of. |
| 494 | /// This is the number of trailing SourceLocation. |
| 495 | unsigned NumConcatenated; |
| 496 | }; |
| 497 | |
| 498 | class CharacterLiteralBitfields { |
| 499 | friend class CharacterLiteral; |
| 500 | |
| 501 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 502 | unsigned : NumExprBits; |
| 503 | |
| 504 | LLVM_PREFERRED_TYPE(CharacterLiteralKind) |
| 505 | unsigned Kind : 3; |
| 506 | }; |
| 507 | |
| 508 | class UnaryOperatorBitfields { |
| 509 | friend class UnaryOperator; |
| 510 | |
| 511 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 512 | unsigned : NumExprBits; |
| 513 | |
| 514 | LLVM_PREFERRED_TYPE(UnaryOperatorKind) |
| 515 | unsigned Opc : 5; |
| 516 | LLVM_PREFERRED_TYPE(bool) |
| 517 | unsigned CanOverflow : 1; |
| 518 | // |
| 519 | /// This is only meaningful for operations on floating point |
| 520 | /// types when additional values need to be in trailing storage. |
| 521 | /// It is 0 otherwise. |
| 522 | LLVM_PREFERRED_TYPE(bool) |
| 523 | unsigned HasFPFeatures : 1; |
| 524 | |
| 525 | SourceLocation Loc; |
| 526 | }; |
| 527 | |
| 528 | class UnaryExprOrTypeTraitExprBitfields { |
| 529 | friend class UnaryExprOrTypeTraitExpr; |
| 530 | |
| 531 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 532 | unsigned : NumExprBits; |
| 533 | |
| 534 | LLVM_PREFERRED_TYPE(UnaryExprOrTypeTrait) |
| 535 | unsigned Kind : 4; |
| 536 | LLVM_PREFERRED_TYPE(bool) |
| 537 | unsigned IsType : 1; // true if operand is a type, false if an expression. |
| 538 | }; |
| 539 | |
| 540 | class ArrayOrMatrixSubscriptExprBitfields { |
| 541 | friend class ArraySubscriptExpr; |
| 542 | friend class MatrixSubscriptExpr; |
| 543 | |
| 544 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 545 | unsigned : NumExprBits; |
| 546 | |
| 547 | SourceLocation RBracketLoc; |
| 548 | }; |
| 549 | |
| 550 | class CallExprBitfields { |
| 551 | friend class CallExpr; |
| 552 | |
| 553 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 554 | unsigned : NumExprBits; |
| 555 | |
| 556 | unsigned NumPreArgs : 1; |
| 557 | |
| 558 | /// True if the callee of the call expression was found using ADL. |
| 559 | LLVM_PREFERRED_TYPE(bool) |
| 560 | unsigned UsesADL : 1; |
| 561 | |
| 562 | /// True if the call expression has some floating-point features. |
| 563 | LLVM_PREFERRED_TYPE(bool) |
| 564 | unsigned HasFPFeatures : 1; |
| 565 | |
| 566 | /// True if the call expression is a must-elide call to a coroutine. |
| 567 | LLVM_PREFERRED_TYPE(bool) |
| 568 | unsigned IsCoroElideSafe : 1; |
| 569 | |
| 570 | /// Tracks when CallExpr is used to represent an explicit object |
| 571 | /// member function, in order to adjust the begin location. |
| 572 | LLVM_PREFERRED_TYPE(bool) |
| 573 | unsigned ExplicitObjectMemFunUsingMemberSyntax : 1; |
| 574 | |
| 575 | /// Indicates that SourceLocations are cached as |
| 576 | /// Trailing objects. See the definition of CallExpr. |
| 577 | LLVM_PREFERRED_TYPE(bool) |
| 578 | unsigned HasTrailingSourceLoc : 1; |
| 579 | }; |
| 580 | |
| 581 | enum { NumCallExprBits = 25 }; |
| 582 | |
| 583 | class MemberExprBitfields { |
| 584 | friend class ASTStmtReader; |
| 585 | friend class MemberExpr; |
| 586 | |
| 587 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 588 | unsigned : NumExprBits; |
| 589 | |
| 590 | /// IsArrow - True if this is "X->F", false if this is "X.F". |
| 591 | LLVM_PREFERRED_TYPE(bool) |
| 592 | unsigned IsArrow : 1; |
| 593 | |
| 594 | /// True if this member expression used a nested-name-specifier to |
| 595 | /// refer to the member, e.g., "x->Base::f". |
| 596 | LLVM_PREFERRED_TYPE(bool) |
| 597 | unsigned HasQualifier : 1; |
| 598 | |
| 599 | // True if this member expression found its member via a using declaration. |
| 600 | LLVM_PREFERRED_TYPE(bool) |
| 601 | unsigned HasFoundDecl : 1; |
| 602 | |
| 603 | /// True if this member expression specified a template keyword |
| 604 | /// and/or a template argument list explicitly, e.g., x->f<int>, |
| 605 | /// x->template f, x->template f<int>. |
| 606 | /// When true, an ASTTemplateKWAndArgsInfo structure and its |
| 607 | /// TemplateArguments (if any) are present. |
| 608 | LLVM_PREFERRED_TYPE(bool) |
| 609 | unsigned HasTemplateKWAndArgsInfo : 1; |
| 610 | |
| 611 | /// True if this member expression refers to a method that |
| 612 | /// was resolved from an overloaded set having size greater than 1. |
| 613 | LLVM_PREFERRED_TYPE(bool) |
| 614 | unsigned HadMultipleCandidates : 1; |
| 615 | |
| 616 | /// Value of type NonOdrUseReason indicating why this MemberExpr does |
| 617 | /// not constitute an odr-use of the named declaration. Meaningful only |
| 618 | /// when naming a static member. |
| 619 | LLVM_PREFERRED_TYPE(NonOdrUseReason) |
| 620 | unsigned NonOdrUseReason : 2; |
| 621 | |
| 622 | /// This is the location of the -> or . in the expression. |
| 623 | SourceLocation OperatorLoc; |
| 624 | }; |
| 625 | |
| 626 | class CastExprBitfields { |
| 627 | friend class CastExpr; |
| 628 | friend class ImplicitCastExpr; |
| 629 | |
| 630 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 631 | unsigned : NumExprBits; |
| 632 | |
| 633 | LLVM_PREFERRED_TYPE(CastKind) |
| 634 | unsigned Kind : 7; |
| 635 | LLVM_PREFERRED_TYPE(bool) |
| 636 | unsigned PartOfExplicitCast : 1; // Only set for ImplicitCastExpr. |
| 637 | |
| 638 | /// True if the call expression has some floating-point features. |
| 639 | LLVM_PREFERRED_TYPE(bool) |
| 640 | unsigned HasFPFeatures : 1; |
| 641 | |
| 642 | /// The number of CXXBaseSpecifiers in the cast. 14 bits would be enough |
| 643 | /// here. ([implimits] Direct and indirect base classes [16384]). |
| 644 | unsigned BasePathSize; |
| 645 | }; |
| 646 | |
| 647 | class BinaryOperatorBitfields { |
| 648 | friend class BinaryOperator; |
| 649 | |
| 650 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 651 | unsigned : NumExprBits; |
| 652 | |
| 653 | LLVM_PREFERRED_TYPE(BinaryOperatorKind) |
| 654 | unsigned Opc : 6; |
| 655 | |
| 656 | /// This is only meaningful for operations on floating point |
| 657 | /// types when additional values need to be in trailing storage. |
| 658 | /// It is 0 otherwise. |
| 659 | LLVM_PREFERRED_TYPE(bool) |
| 660 | unsigned HasFPFeatures : 1; |
| 661 | |
| 662 | /// Whether or not this BinaryOperator should be excluded from integer |
| 663 | /// overflow sanitization. |
| 664 | LLVM_PREFERRED_TYPE(bool) |
| 665 | unsigned ExcludedOverflowPattern : 1; |
| 666 | |
| 667 | SourceLocation OpLoc; |
| 668 | }; |
| 669 | |
| 670 | class InitListExprBitfields { |
| 671 | friend class InitListExpr; |
| 672 | |
| 673 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 674 | unsigned : NumExprBits; |
| 675 | |
| 676 | /// Whether this initializer list originally had a GNU array-range |
| 677 | /// designator in it. This is a temporary marker used by CodeGen. |
| 678 | LLVM_PREFERRED_TYPE(bool) |
| 679 | unsigned HadArrayRangeDesignator : 1; |
| 680 | }; |
| 681 | |
| 682 | class ParenListExprBitfields { |
| 683 | friend class ASTStmtReader; |
| 684 | friend class ParenListExpr; |
| 685 | |
| 686 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 687 | unsigned : NumExprBits; |
| 688 | |
| 689 | /// The number of expressions in the paren list. |
| 690 | unsigned NumExprs; |
| 691 | }; |
| 692 | |
| 693 | class GenericSelectionExprBitfields { |
| 694 | friend class ASTStmtReader; |
| 695 | friend class GenericSelectionExpr; |
| 696 | |
| 697 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 698 | unsigned : NumExprBits; |
| 699 | |
| 700 | /// The location of the "_Generic". |
| 701 | SourceLocation GenericLoc; |
| 702 | }; |
| 703 | |
| 704 | class PseudoObjectExprBitfields { |
| 705 | friend class ASTStmtReader; // deserialization |
| 706 | friend class PseudoObjectExpr; |
| 707 | |
| 708 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 709 | unsigned : NumExprBits; |
| 710 | |
| 711 | unsigned NumSubExprs : 16; |
| 712 | unsigned ResultIndex : 16; |
| 713 | }; |
| 714 | |
| 715 | class SourceLocExprBitfields { |
| 716 | friend class ASTStmtReader; |
| 717 | friend class SourceLocExpr; |
| 718 | |
| 719 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 720 | unsigned : NumExprBits; |
| 721 | |
| 722 | /// The kind of source location builtin represented by the SourceLocExpr. |
| 723 | /// Ex. __builtin_LINE, __builtin_FUNCTION, etc. |
| 724 | LLVM_PREFERRED_TYPE(SourceLocIdentKind) |
| 725 | unsigned Kind : 3; |
| 726 | }; |
| 727 | |
| 728 | class ParenExprBitfields { |
| 729 | friend class ASTStmtReader; |
| 730 | friend class ASTStmtWriter; |
| 731 | friend class ParenExpr; |
| 732 | |
| 733 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 734 | unsigned : NumExprBits; |
| 735 | |
| 736 | LLVM_PREFERRED_TYPE(bool) |
| 737 | unsigned ProducedByFoldExpansion : 1; |
| 738 | }; |
| 739 | |
| 740 | class ShuffleVectorExprBitfields { |
| 741 | friend class ShuffleVectorExpr; |
| 742 | |
| 743 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 744 | unsigned : NumExprBits; |
| 745 | |
| 746 | unsigned NumExprs; |
| 747 | }; |
| 748 | |
| 749 | class StmtExprBitfields { |
| 750 | friend class ASTStmtReader; |
| 751 | friend class StmtExpr; |
| 752 | |
| 753 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 754 | unsigned : NumExprBits; |
| 755 | |
| 756 | /// The number of levels of template parameters enclosing this statement |
| 757 | /// expression. Used to determine if a statement expression remains |
| 758 | /// dependent after instantiation. |
| 759 | unsigned TemplateDepth; |
| 760 | }; |
| 761 | |
| 762 | class ChooseExprBitfields { |
| 763 | friend class ASTStmtReader; |
| 764 | friend class ChooseExpr; |
| 765 | |
| 766 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 767 | unsigned : NumExprBits; |
| 768 | |
| 769 | LLVM_PREFERRED_TYPE(bool) |
| 770 | bool CondIsTrue : 1; |
| 771 | }; |
| 772 | |
| 773 | //===--- C++ Expression bitfields classes ---===// |
| 774 | |
| 775 | class CXXOperatorCallExprBitfields { |
| 776 | friend class ASTStmtReader; |
| 777 | friend class CXXOperatorCallExpr; |
| 778 | |
| 779 | LLVM_PREFERRED_TYPE(CallExprBitfields) |
| 780 | unsigned : NumCallExprBits; |
| 781 | |
| 782 | /// The kind of this overloaded operator. One of the enumerator |
| 783 | /// value of OverloadedOperatorKind. |
| 784 | LLVM_PREFERRED_TYPE(OverloadedOperatorKind) |
| 785 | unsigned OperatorKind : 6; |
| 786 | }; |
| 787 | |
| 788 | class CXXRewrittenBinaryOperatorBitfields { |
| 789 | friend class ASTStmtReader; |
| 790 | friend class CXXRewrittenBinaryOperator; |
| 791 | |
| 792 | LLVM_PREFERRED_TYPE(CallExprBitfields) |
| 793 | unsigned : NumCallExprBits; |
| 794 | |
| 795 | LLVM_PREFERRED_TYPE(bool) |
| 796 | unsigned IsReversed : 1; |
| 797 | }; |
| 798 | |
| 799 | class CXXBoolLiteralExprBitfields { |
| 800 | friend class CXXBoolLiteralExpr; |
| 801 | |
| 802 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 803 | unsigned : NumExprBits; |
| 804 | |
| 805 | /// The value of the boolean literal. |
| 806 | LLVM_PREFERRED_TYPE(bool) |
| 807 | unsigned Value : 1; |
| 808 | |
| 809 | /// The location of the boolean literal. |
| 810 | SourceLocation Loc; |
| 811 | }; |
| 812 | |
| 813 | class CXXNullPtrLiteralExprBitfields { |
| 814 | friend class CXXNullPtrLiteralExpr; |
| 815 | |
| 816 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 817 | unsigned : NumExprBits; |
| 818 | |
| 819 | /// The location of the null pointer literal. |
| 820 | SourceLocation Loc; |
| 821 | }; |
| 822 | |
| 823 | class CXXThisExprBitfields { |
| 824 | friend class CXXThisExpr; |
| 825 | |
| 826 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 827 | unsigned : NumExprBits; |
| 828 | |
| 829 | /// Whether this is an implicit "this". |
| 830 | LLVM_PREFERRED_TYPE(bool) |
| 831 | unsigned IsImplicit : 1; |
| 832 | |
| 833 | /// Whether there is a lambda with an explicit object parameter that |
| 834 | /// captures this "this" by copy. |
| 835 | LLVM_PREFERRED_TYPE(bool) |
| 836 | unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1; |
| 837 | |
| 838 | /// The location of the "this". |
| 839 | SourceLocation Loc; |
| 840 | }; |
| 841 | |
| 842 | class CXXThrowExprBitfields { |
| 843 | friend class ASTStmtReader; |
| 844 | friend class CXXThrowExpr; |
| 845 | |
| 846 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 847 | unsigned : NumExprBits; |
| 848 | |
| 849 | /// Whether the thrown variable (if any) is in scope. |
| 850 | LLVM_PREFERRED_TYPE(bool) |
| 851 | unsigned IsThrownVariableInScope : 1; |
| 852 | |
| 853 | /// The location of the "throw". |
| 854 | SourceLocation ThrowLoc; |
| 855 | }; |
| 856 | |
| 857 | class CXXDefaultArgExprBitfields { |
| 858 | friend class ASTStmtReader; |
| 859 | friend class CXXDefaultArgExpr; |
| 860 | |
| 861 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 862 | unsigned : NumExprBits; |
| 863 | |
| 864 | /// Whether this CXXDefaultArgExpr rewrote its argument and stores a copy. |
| 865 | LLVM_PREFERRED_TYPE(bool) |
| 866 | unsigned HasRewrittenInit : 1; |
| 867 | |
| 868 | /// The location where the default argument expression was used. |
| 869 | SourceLocation Loc; |
| 870 | }; |
| 871 | |
| 872 | class CXXDefaultInitExprBitfields { |
| 873 | friend class ASTStmtReader; |
| 874 | friend class CXXDefaultInitExpr; |
| 875 | |
| 876 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 877 | unsigned : NumExprBits; |
| 878 | |
| 879 | /// Whether this CXXDefaultInitExprBitfields rewrote its argument and stores |
| 880 | /// a copy. |
| 881 | LLVM_PREFERRED_TYPE(bool) |
| 882 | unsigned HasRewrittenInit : 1; |
| 883 | |
| 884 | /// The location where the default initializer expression was used. |
| 885 | SourceLocation Loc; |
| 886 | }; |
| 887 | |
| 888 | class CXXScalarValueInitExprBitfields { |
| 889 | friend class ASTStmtReader; |
| 890 | friend class CXXScalarValueInitExpr; |
| 891 | |
| 892 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 893 | unsigned : NumExprBits; |
| 894 | |
| 895 | SourceLocation RParenLoc; |
| 896 | }; |
| 897 | |
| 898 | class CXXNewExprBitfields { |
| 899 | friend class ASTStmtReader; |
| 900 | friend class ASTStmtWriter; |
| 901 | friend class CXXNewExpr; |
| 902 | |
| 903 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 904 | unsigned : NumExprBits; |
| 905 | |
| 906 | /// Was the usage ::new, i.e. is the global new to be used? |
| 907 | LLVM_PREFERRED_TYPE(bool) |
| 908 | unsigned IsGlobalNew : 1; |
| 909 | |
| 910 | /// Do we allocate an array? If so, the first trailing "Stmt *" is the |
| 911 | /// size expression. |
| 912 | LLVM_PREFERRED_TYPE(bool) |
| 913 | unsigned IsArray : 1; |
| 914 | |
| 915 | /// Should the alignment be passed to the allocation function? |
| 916 | LLVM_PREFERRED_TYPE(bool) |
| 917 | unsigned ShouldPassAlignment : 1; |
| 918 | |
| 919 | /// Should the type identity be passed to the allocation function? |
| 920 | LLVM_PREFERRED_TYPE(bool) |
| 921 | unsigned ShouldPassTypeIdentity : 1; |
| 922 | |
| 923 | /// If this is an array allocation, does the usual deallocation |
| 924 | /// function for the allocated type want to know the allocated size? |
| 925 | LLVM_PREFERRED_TYPE(bool) |
| 926 | unsigned UsualArrayDeleteWantsSize : 1; |
| 927 | |
| 928 | // Is initializer expr present? |
| 929 | LLVM_PREFERRED_TYPE(bool) |
| 930 | unsigned HasInitializer : 1; |
| 931 | |
| 932 | /// What kind of initializer syntax used? Could be none, parens, or braces. |
| 933 | LLVM_PREFERRED_TYPE(CXXNewInitializationStyle) |
| 934 | unsigned StoredInitializationStyle : 2; |
| 935 | |
| 936 | /// True if the allocated type was expressed as a parenthesized type-id. |
| 937 | LLVM_PREFERRED_TYPE(bool) |
| 938 | unsigned IsParenTypeId : 1; |
| 939 | |
| 940 | /// The number of placement new arguments. |
| 941 | unsigned NumPlacementArgs; |
| 942 | }; |
| 943 | |
| 944 | class CXXDeleteExprBitfields { |
| 945 | friend class ASTStmtReader; |
| 946 | friend class CXXDeleteExpr; |
| 947 | |
| 948 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 949 | unsigned : NumExprBits; |
| 950 | |
| 951 | /// Is this a forced global delete, i.e. "::delete"? |
| 952 | LLVM_PREFERRED_TYPE(bool) |
| 953 | unsigned GlobalDelete : 1; |
| 954 | |
| 955 | /// Is this the array form of delete, i.e. "delete[]"? |
| 956 | LLVM_PREFERRED_TYPE(bool) |
| 957 | unsigned ArrayForm : 1; |
| 958 | |
| 959 | /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is |
| 960 | /// applied to pointer-to-array type (ArrayFormAsWritten will be false |
| 961 | /// while ArrayForm will be true). |
| 962 | LLVM_PREFERRED_TYPE(bool) |
| 963 | unsigned ArrayFormAsWritten : 1; |
| 964 | |
| 965 | /// Does the usual deallocation function for the element type require |
| 966 | /// a size_t argument? |
| 967 | LLVM_PREFERRED_TYPE(bool) |
| 968 | unsigned UsualArrayDeleteWantsSize : 1; |
| 969 | |
| 970 | /// Location of the expression. |
| 971 | SourceLocation Loc; |
| 972 | }; |
| 973 | |
| 974 | class TypeTraitExprBitfields { |
| 975 | friend class ASTStmtReader; |
| 976 | friend class ASTStmtWriter; |
| 977 | friend class TypeTraitExpr; |
| 978 | |
| 979 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 980 | unsigned : NumExprBits; |
| 981 | |
| 982 | /// The kind of type trait, which is a value of a TypeTrait enumerator. |
| 983 | LLVM_PREFERRED_TYPE(TypeTrait) |
| 984 | unsigned Kind : 8; |
| 985 | |
| 986 | LLVM_PREFERRED_TYPE(bool) |
| 987 | unsigned IsBooleanTypeTrait : 1; |
| 988 | |
| 989 | /// If this expression is a non value-dependent boolean trait, |
| 990 | /// this indicates whether the trait evaluated true or false. |
| 991 | LLVM_PREFERRED_TYPE(bool) |
| 992 | unsigned Value : 1; |
| 993 | /// The number of arguments to this type trait. According to [implimits] |
| 994 | /// 8 bits would be enough, but we require (and test for) at least 16 bits |
| 995 | /// to mirror FunctionType. |
| 996 | unsigned NumArgs; |
| 997 | }; |
| 998 | |
| 999 | class DependentScopeDeclRefExprBitfields { |
| 1000 | friend class ASTStmtReader; |
| 1001 | friend class ASTStmtWriter; |
| 1002 | friend class DependentScopeDeclRefExpr; |
| 1003 | |
| 1004 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1005 | unsigned : NumExprBits; |
| 1006 | |
| 1007 | /// Whether the name includes info for explicit template |
| 1008 | /// keyword and arguments. |
| 1009 | LLVM_PREFERRED_TYPE(bool) |
| 1010 | unsigned HasTemplateKWAndArgsInfo : 1; |
| 1011 | }; |
| 1012 | |
| 1013 | class CXXConstructExprBitfields { |
| 1014 | friend class ASTStmtReader; |
| 1015 | friend class CXXConstructExpr; |
| 1016 | |
| 1017 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1018 | unsigned : NumExprBits; |
| 1019 | |
| 1020 | LLVM_PREFERRED_TYPE(bool) |
| 1021 | unsigned Elidable : 1; |
| 1022 | LLVM_PREFERRED_TYPE(bool) |
| 1023 | unsigned HadMultipleCandidates : 1; |
| 1024 | LLVM_PREFERRED_TYPE(bool) |
| 1025 | unsigned ListInitialization : 1; |
| 1026 | LLVM_PREFERRED_TYPE(bool) |
| 1027 | unsigned StdInitListInitialization : 1; |
| 1028 | LLVM_PREFERRED_TYPE(bool) |
| 1029 | unsigned ZeroInitialization : 1; |
| 1030 | LLVM_PREFERRED_TYPE(CXXConstructionKind) |
| 1031 | unsigned ConstructionKind : 3; |
| 1032 | LLVM_PREFERRED_TYPE(bool) |
| 1033 | unsigned IsImmediateEscalating : 1; |
| 1034 | |
| 1035 | SourceLocation Loc; |
| 1036 | }; |
| 1037 | |
| 1038 | class ExprWithCleanupsBitfields { |
| 1039 | friend class ASTStmtReader; // deserialization |
| 1040 | friend class ExprWithCleanups; |
| 1041 | |
| 1042 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1043 | unsigned : NumExprBits; |
| 1044 | |
| 1045 | // When false, it must not have side effects. |
| 1046 | LLVM_PREFERRED_TYPE(bool) |
| 1047 | unsigned CleanupsHaveSideEffects : 1; |
| 1048 | |
| 1049 | unsigned NumObjects : 32 - 1 - NumExprBits; |
| 1050 | }; |
| 1051 | |
| 1052 | class CXXUnresolvedConstructExprBitfields { |
| 1053 | friend class ASTStmtReader; |
| 1054 | friend class CXXUnresolvedConstructExpr; |
| 1055 | |
| 1056 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1057 | unsigned : NumExprBits; |
| 1058 | |
| 1059 | /// The number of arguments used to construct the type. |
| 1060 | unsigned NumArgs; |
| 1061 | }; |
| 1062 | |
| 1063 | class CXXDependentScopeMemberExprBitfields { |
| 1064 | friend class ASTStmtReader; |
| 1065 | friend class CXXDependentScopeMemberExpr; |
| 1066 | |
| 1067 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1068 | unsigned : NumExprBits; |
| 1069 | |
| 1070 | /// Whether this member expression used the '->' operator or |
| 1071 | /// the '.' operator. |
| 1072 | LLVM_PREFERRED_TYPE(bool) |
| 1073 | unsigned IsArrow : 1; |
| 1074 | |
| 1075 | /// Whether this member expression has info for explicit template |
| 1076 | /// keyword and arguments. |
| 1077 | LLVM_PREFERRED_TYPE(bool) |
| 1078 | unsigned HasTemplateKWAndArgsInfo : 1; |
| 1079 | |
| 1080 | /// See getFirstQualifierFoundInScope() and the comment listing |
| 1081 | /// the trailing objects. |
| 1082 | LLVM_PREFERRED_TYPE(bool) |
| 1083 | unsigned HasFirstQualifierFoundInScope : 1; |
| 1084 | |
| 1085 | /// The location of the '->' or '.' operator. |
| 1086 | SourceLocation OperatorLoc; |
| 1087 | }; |
| 1088 | |
| 1089 | class OverloadExprBitfields { |
| 1090 | friend class ASTStmtReader; |
| 1091 | friend class OverloadExpr; |
| 1092 | |
| 1093 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1094 | unsigned : NumExprBits; |
| 1095 | |
| 1096 | /// Whether the name includes info for explicit template |
| 1097 | /// keyword and arguments. |
| 1098 | LLVM_PREFERRED_TYPE(bool) |
| 1099 | unsigned HasTemplateKWAndArgsInfo : 1; |
| 1100 | |
| 1101 | /// Padding used by the derived classes to store various bits. If you |
| 1102 | /// need to add some data here, shrink this padding and add your data |
| 1103 | /// above. NumOverloadExprBits also needs to be updated. |
| 1104 | unsigned : 32 - NumExprBits - 1; |
| 1105 | |
| 1106 | /// The number of results. |
| 1107 | unsigned NumResults; |
| 1108 | }; |
| 1109 | enum { NumOverloadExprBits = NumExprBits + 1 }; |
| 1110 | |
| 1111 | class UnresolvedLookupExprBitfields { |
| 1112 | friend class ASTStmtReader; |
| 1113 | friend class UnresolvedLookupExpr; |
| 1114 | |
| 1115 | LLVM_PREFERRED_TYPE(OverloadExprBitfields) |
| 1116 | unsigned : NumOverloadExprBits; |
| 1117 | |
| 1118 | /// True if these lookup results should be extended by |
| 1119 | /// argument-dependent lookup if this is the operand of a function call. |
| 1120 | LLVM_PREFERRED_TYPE(bool) |
| 1121 | unsigned RequiresADL : 1; |
| 1122 | }; |
| 1123 | static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4, |
| 1124 | "UnresolvedLookupExprBitfields must be <= than 4 bytes to" |
| 1125 | "avoid trashing OverloadExprBitfields::NumResults!" ); |
| 1126 | |
| 1127 | class UnresolvedMemberExprBitfields { |
| 1128 | friend class ASTStmtReader; |
| 1129 | friend class UnresolvedMemberExpr; |
| 1130 | |
| 1131 | LLVM_PREFERRED_TYPE(OverloadExprBitfields) |
| 1132 | unsigned : NumOverloadExprBits; |
| 1133 | |
| 1134 | /// Whether this member expression used the '->' operator or |
| 1135 | /// the '.' operator. |
| 1136 | LLVM_PREFERRED_TYPE(bool) |
| 1137 | unsigned IsArrow : 1; |
| 1138 | |
| 1139 | /// Whether the lookup results contain an unresolved using declaration. |
| 1140 | LLVM_PREFERRED_TYPE(bool) |
| 1141 | unsigned HasUnresolvedUsing : 1; |
| 1142 | }; |
| 1143 | static_assert(sizeof(UnresolvedMemberExprBitfields) <= 4, |
| 1144 | "UnresolvedMemberExprBitfields must be <= than 4 bytes to" |
| 1145 | "avoid trashing OverloadExprBitfields::NumResults!" ); |
| 1146 | |
| 1147 | class CXXNoexceptExprBitfields { |
| 1148 | friend class ASTStmtReader; |
| 1149 | friend class CXXNoexceptExpr; |
| 1150 | |
| 1151 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1152 | unsigned : NumExprBits; |
| 1153 | |
| 1154 | LLVM_PREFERRED_TYPE(bool) |
| 1155 | unsigned Value : 1; |
| 1156 | }; |
| 1157 | |
| 1158 | class SubstNonTypeTemplateParmExprBitfields { |
| 1159 | friend class ASTStmtReader; |
| 1160 | friend class SubstNonTypeTemplateParmExpr; |
| 1161 | |
| 1162 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1163 | unsigned : NumExprBits; |
| 1164 | |
| 1165 | /// The location of the non-type template parameter reference. |
| 1166 | SourceLocation NameLoc; |
| 1167 | }; |
| 1168 | |
| 1169 | class LambdaExprBitfields { |
| 1170 | friend class ASTStmtReader; |
| 1171 | friend class ASTStmtWriter; |
| 1172 | friend class LambdaExpr; |
| 1173 | |
| 1174 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1175 | unsigned : NumExprBits; |
| 1176 | |
| 1177 | /// The default capture kind, which is a value of type |
| 1178 | /// LambdaCaptureDefault. |
| 1179 | LLVM_PREFERRED_TYPE(LambdaCaptureDefault) |
| 1180 | unsigned CaptureDefault : 2; |
| 1181 | |
| 1182 | /// Whether this lambda had an explicit parameter list vs. an |
| 1183 | /// implicit (and empty) parameter list. |
| 1184 | LLVM_PREFERRED_TYPE(bool) |
| 1185 | unsigned ExplicitParams : 1; |
| 1186 | |
| 1187 | /// Whether this lambda had the result type explicitly specified. |
| 1188 | LLVM_PREFERRED_TYPE(bool) |
| 1189 | unsigned ExplicitResultType : 1; |
| 1190 | |
| 1191 | /// The number of captures. |
| 1192 | unsigned NumCaptures : 16; |
| 1193 | }; |
| 1194 | |
| 1195 | class RequiresExprBitfields { |
| 1196 | friend class ASTStmtReader; |
| 1197 | friend class ASTStmtWriter; |
| 1198 | friend class RequiresExpr; |
| 1199 | |
| 1200 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1201 | unsigned : NumExprBits; |
| 1202 | |
| 1203 | LLVM_PREFERRED_TYPE(bool) |
| 1204 | unsigned IsSatisfied : 1; |
| 1205 | SourceLocation RequiresKWLoc; |
| 1206 | }; |
| 1207 | |
| 1208 | class ArrayTypeTraitExprBitfields { |
| 1209 | friend class ArrayTypeTraitExpr; |
| 1210 | friend class ASTStmtReader; |
| 1211 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1212 | unsigned : NumExprBits; |
| 1213 | |
| 1214 | /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned. |
| 1215 | LLVM_PREFERRED_TYPE(ArrayTypeTrait) |
| 1216 | unsigned ATT : 2; |
| 1217 | }; |
| 1218 | |
| 1219 | class ExpressionTraitExprBitfields { |
| 1220 | friend class ExpressionTraitExpr; |
| 1221 | friend class ASTStmtReader; |
| 1222 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1223 | unsigned : NumExprBits; |
| 1224 | |
| 1225 | /// The trait. A ExpressionTrait enum in MSVC compatible unsigned. |
| 1226 | LLVM_PREFERRED_TYPE(ExpressionTrait) |
| 1227 | unsigned ET : 31; |
| 1228 | |
| 1229 | /// The value of the type trait. Unspecified if dependent. |
| 1230 | LLVM_PREFERRED_TYPE(bool) |
| 1231 | unsigned Value : 1; |
| 1232 | }; |
| 1233 | |
| 1234 | class CXXFoldExprBitfields { |
| 1235 | friend class CXXFoldExpr; |
| 1236 | friend class ASTStmtReader; |
| 1237 | friend class ASTStmtWriter; |
| 1238 | |
| 1239 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1240 | unsigned : NumExprBits; |
| 1241 | |
| 1242 | BinaryOperatorKind Opcode; |
| 1243 | }; |
| 1244 | |
| 1245 | class PackIndexingExprBitfields { |
| 1246 | friend class PackIndexingExpr; |
| 1247 | friend class ASTStmtWriter; |
| 1248 | friend class ASTStmtReader; |
| 1249 | |
| 1250 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1251 | unsigned : NumExprBits; |
| 1252 | // The size of the trailing expressions. |
| 1253 | unsigned TransformedExpressions : 31; |
| 1254 | |
| 1255 | LLVM_PREFERRED_TYPE(bool) |
| 1256 | unsigned FullySubstituted : 1; |
| 1257 | }; |
| 1258 | |
| 1259 | //===--- C++ Coroutines bitfields classes ---===// |
| 1260 | |
| 1261 | class CoawaitExprBitfields { |
| 1262 | friend class CoawaitExpr; |
| 1263 | |
| 1264 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1265 | unsigned : NumExprBits; |
| 1266 | |
| 1267 | LLVM_PREFERRED_TYPE(bool) |
| 1268 | unsigned IsImplicit : 1; |
| 1269 | }; |
| 1270 | |
| 1271 | //===--- Obj-C Expression bitfields classes ---===// |
| 1272 | |
| 1273 | class ObjCIndirectCopyRestoreExprBitfields { |
| 1274 | friend class ObjCIndirectCopyRestoreExpr; |
| 1275 | |
| 1276 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1277 | unsigned : NumExprBits; |
| 1278 | |
| 1279 | LLVM_PREFERRED_TYPE(bool) |
| 1280 | unsigned ShouldCopy : 1; |
| 1281 | }; |
| 1282 | |
| 1283 | //===--- Clang Extensions bitfields classes ---===// |
| 1284 | |
| 1285 | class OpaqueValueExprBitfields { |
| 1286 | friend class ASTStmtReader; |
| 1287 | friend class OpaqueValueExpr; |
| 1288 | |
| 1289 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1290 | unsigned : NumExprBits; |
| 1291 | |
| 1292 | /// The OVE is a unique semantic reference to its source expression if this |
| 1293 | /// bit is set to true. |
| 1294 | LLVM_PREFERRED_TYPE(bool) |
| 1295 | unsigned IsUnique : 1; |
| 1296 | |
| 1297 | SourceLocation Loc; |
| 1298 | }; |
| 1299 | |
| 1300 | class ConvertVectorExprBitfields { |
| 1301 | friend class ConvertVectorExpr; |
| 1302 | |
| 1303 | LLVM_PREFERRED_TYPE(ExprBitfields) |
| 1304 | unsigned : NumExprBits; |
| 1305 | |
| 1306 | // |
| 1307 | /// This is only meaningful for operations on floating point |
| 1308 | /// types when additional values need to be in trailing storage. |
| 1309 | /// It is 0 otherwise. |
| 1310 | LLVM_PREFERRED_TYPE(bool) |
| 1311 | unsigned HasFPFeatures : 1; |
| 1312 | }; |
| 1313 | |
| 1314 | union { |
| 1315 | // Same order as in StmtNodes.td. |
| 1316 | // Statements |
| 1317 | StmtBitfields StmtBits; |
| 1318 | NullStmtBitfields NullStmtBits; |
| 1319 | CompoundStmtBitfields CompoundStmtBits; |
| 1320 | LabelStmtBitfields LabelStmtBits; |
| 1321 | AttributedStmtBitfields AttributedStmtBits; |
| 1322 | IfStmtBitfields IfStmtBits; |
| 1323 | SwitchStmtBitfields SwitchStmtBits; |
| 1324 | WhileStmtBitfields WhileStmtBits; |
| 1325 | DoStmtBitfields DoStmtBits; |
| 1326 | ForStmtBitfields ForStmtBits; |
| 1327 | GotoStmtBitfields GotoStmtBits; |
| 1328 | ContinueStmtBitfields ContinueStmtBits; |
| 1329 | BreakStmtBitfields BreakStmtBits; |
| 1330 | ReturnStmtBitfields ReturnStmtBits; |
| 1331 | SwitchCaseBitfields SwitchCaseBits; |
| 1332 | |
| 1333 | // Expressions |
| 1334 | ExprBitfields ExprBits; |
| 1335 | ConstantExprBitfields ConstantExprBits; |
| 1336 | PredefinedExprBitfields PredefinedExprBits; |
| 1337 | DeclRefExprBitfields DeclRefExprBits; |
| 1338 | FloatingLiteralBitfields FloatingLiteralBits; |
| 1339 | StringLiteralBitfields StringLiteralBits; |
| 1340 | CharacterLiteralBitfields CharacterLiteralBits; |
| 1341 | UnaryOperatorBitfields UnaryOperatorBits; |
| 1342 | UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits; |
| 1343 | ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits; |
| 1344 | CallExprBitfields CallExprBits; |
| 1345 | MemberExprBitfields MemberExprBits; |
| 1346 | CastExprBitfields CastExprBits; |
| 1347 | BinaryOperatorBitfields BinaryOperatorBits; |
| 1348 | InitListExprBitfields InitListExprBits; |
| 1349 | ParenListExprBitfields ParenListExprBits; |
| 1350 | GenericSelectionExprBitfields GenericSelectionExprBits; |
| 1351 | PseudoObjectExprBitfields PseudoObjectExprBits; |
| 1352 | SourceLocExprBitfields SourceLocExprBits; |
| 1353 | ParenExprBitfields ParenExprBits; |
| 1354 | ShuffleVectorExprBitfields ShuffleVectorExprBits; |
| 1355 | |
| 1356 | // GNU Extensions. |
| 1357 | StmtExprBitfields StmtExprBits; |
| 1358 | ChooseExprBitfields ChooseExprBits; |
| 1359 | |
| 1360 | // C++ Expressions |
| 1361 | CXXOperatorCallExprBitfields CXXOperatorCallExprBits; |
| 1362 | CXXRewrittenBinaryOperatorBitfields CXXRewrittenBinaryOperatorBits; |
| 1363 | CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits; |
| 1364 | CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits; |
| 1365 | CXXThisExprBitfields CXXThisExprBits; |
| 1366 | CXXThrowExprBitfields CXXThrowExprBits; |
| 1367 | CXXDefaultArgExprBitfields CXXDefaultArgExprBits; |
| 1368 | CXXDefaultInitExprBitfields CXXDefaultInitExprBits; |
| 1369 | CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits; |
| 1370 | CXXNewExprBitfields CXXNewExprBits; |
| 1371 | CXXDeleteExprBitfields CXXDeleteExprBits; |
| 1372 | TypeTraitExprBitfields TypeTraitExprBits; |
| 1373 | DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits; |
| 1374 | CXXConstructExprBitfields CXXConstructExprBits; |
| 1375 | ExprWithCleanupsBitfields ExprWithCleanupsBits; |
| 1376 | CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits; |
| 1377 | CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits; |
| 1378 | OverloadExprBitfields OverloadExprBits; |
| 1379 | UnresolvedLookupExprBitfields UnresolvedLookupExprBits; |
| 1380 | UnresolvedMemberExprBitfields UnresolvedMemberExprBits; |
| 1381 | CXXNoexceptExprBitfields CXXNoexceptExprBits; |
| 1382 | SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits; |
| 1383 | LambdaExprBitfields LambdaExprBits; |
| 1384 | RequiresExprBitfields RequiresExprBits; |
| 1385 | ArrayTypeTraitExprBitfields ArrayTypeTraitExprBits; |
| 1386 | ExpressionTraitExprBitfields ExpressionTraitExprBits; |
| 1387 | CXXFoldExprBitfields CXXFoldExprBits; |
| 1388 | PackIndexingExprBitfields PackIndexingExprBits; |
| 1389 | |
| 1390 | // C++ Coroutines expressions |
| 1391 | CoawaitExprBitfields CoawaitBits; |
| 1392 | |
| 1393 | // Obj-C Expressions |
| 1394 | ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits; |
| 1395 | |
| 1396 | // Clang Extensions |
| 1397 | OpaqueValueExprBitfields OpaqueValueExprBits; |
| 1398 | ConvertVectorExprBitfields ConvertVectorExprBits; |
| 1399 | }; |
| 1400 | |
| 1401 | public: |
| 1402 | // Only allow allocation of Stmts using the allocator in ASTContext |
| 1403 | // or by doing a placement new. |
| 1404 | void* operator new(size_t bytes, const ASTContext& C, |
| 1405 | unsigned alignment = 8); |
| 1406 | |
| 1407 | void* operator new(size_t bytes, const ASTContext* C, |
| 1408 | unsigned alignment = 8) { |
| 1409 | return operator new(bytes, C: *C, alignment); |
| 1410 | } |
| 1411 | |
| 1412 | void *operator new(size_t bytes, void *mem) noexcept { return mem; } |
| 1413 | |
| 1414 | void operator delete(void *, const ASTContext &, unsigned) noexcept {} |
| 1415 | void operator delete(void *, const ASTContext *, unsigned) noexcept {} |
| 1416 | void operator delete(void *, size_t) noexcept {} |
| 1417 | void operator delete(void *, void *) noexcept {} |
| 1418 | |
| 1419 | public: |
| 1420 | /// A placeholder type used to construct an empty shell of a |
| 1421 | /// type, that will be filled in later (e.g., by some |
| 1422 | /// de-serialization). |
| 1423 | struct EmptyShell {}; |
| 1424 | |
| 1425 | /// The likelihood of a branch being taken. |
| 1426 | enum Likelihood { |
| 1427 | LH_Unlikely = -1, ///< Branch has the [[unlikely]] attribute. |
| 1428 | LH_None, ///< No attribute set or branches of the IfStmt have |
| 1429 | ///< the same attribute. |
| 1430 | LH_Likely ///< Branch has the [[likely]] attribute. |
| 1431 | }; |
| 1432 | |
| 1433 | protected: |
| 1434 | /// Iterator for iterating over Stmt * arrays that contain only T *. |
| 1435 | /// |
| 1436 | /// This is needed because AST nodes use Stmt* arrays to store |
| 1437 | /// references to children (to be compatible with StmtIterator). |
| 1438 | template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *> |
| 1439 | struct CastIterator |
| 1440 | : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *, |
| 1441 | std::random_access_iterator_tag, TPtr> { |
| 1442 | using Base = typename CastIterator::iterator_adaptor_base; |
| 1443 | |
| 1444 | CastIterator() : Base(nullptr) {} |
| 1445 | CastIterator(StmtPtr *I) : Base(I) {} |
| 1446 | |
| 1447 | typename Base::value_type operator*() const { |
| 1448 | return cast_or_null<T>(*this->I); |
| 1449 | } |
| 1450 | }; |
| 1451 | |
| 1452 | /// Const iterator for iterating over Stmt * arrays that contain only T *. |
| 1453 | template <typename T> |
| 1454 | using ConstCastIterator = CastIterator<T, const T *const, const Stmt *const>; |
| 1455 | |
| 1456 | using ExprIterator = CastIterator<Expr>; |
| 1457 | using ConstExprIterator = ConstCastIterator<Expr>; |
| 1458 | |
| 1459 | private: |
| 1460 | /// Whether statistic collection is enabled. |
| 1461 | static bool StatisticsEnabled; |
| 1462 | |
| 1463 | protected: |
| 1464 | /// Construct an empty statement. |
| 1465 | explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {} |
| 1466 | |
| 1467 | public: |
| 1468 | Stmt() = delete; |
| 1469 | Stmt(const Stmt &) = delete; |
| 1470 | Stmt(Stmt &&) = delete; |
| 1471 | Stmt &operator=(const Stmt &) = delete; |
| 1472 | Stmt &operator=(Stmt &&) = delete; |
| 1473 | |
| 1474 | Stmt(StmtClass SC) { |
| 1475 | static_assert(sizeof(*this) <= 8, |
| 1476 | "changing bitfields changed sizeof(Stmt)" ); |
| 1477 | static_assert(sizeof(*this) % alignof(void *) == 0, |
| 1478 | "Insufficient alignment!" ); |
| 1479 | StmtBits.sClass = SC; |
| 1480 | if (StatisticsEnabled) Stmt::addStmtClass(s: SC); |
| 1481 | } |
| 1482 | |
| 1483 | StmtClass getStmtClass() const { |
| 1484 | return static_cast<StmtClass>(StmtBits.sClass); |
| 1485 | } |
| 1486 | |
| 1487 | const char *getStmtClassName() const; |
| 1488 | |
| 1489 | /// SourceLocation tokens are not useful in isolation - they are low level |
| 1490 | /// value objects created/interpreted by SourceManager. We assume AST |
| 1491 | /// clients will have a pointer to the respective SourceManager. |
| 1492 | SourceRange getSourceRange() const LLVM_READONLY; |
| 1493 | SourceLocation getBeginLoc() const LLVM_READONLY; |
| 1494 | SourceLocation getEndLoc() const LLVM_READONLY; |
| 1495 | |
| 1496 | // global temp stats (until we have a per-module visitor) |
| 1497 | static void addStmtClass(const StmtClass s); |
| 1498 | static void EnableStatistics(); |
| 1499 | static void PrintStats(); |
| 1500 | |
| 1501 | /// \returns the likelihood of a set of attributes. |
| 1502 | static Likelihood getLikelihood(ArrayRef<const Attr *> Attrs); |
| 1503 | |
| 1504 | /// \returns the likelihood of a statement. |
| 1505 | static Likelihood getLikelihood(const Stmt *S); |
| 1506 | |
| 1507 | /// \returns the likelihood attribute of a statement. |
| 1508 | static const Attr *getLikelihoodAttr(const Stmt *S); |
| 1509 | |
| 1510 | /// \returns the likelihood of the 'then' branch of an 'if' statement. The |
| 1511 | /// 'else' branch is required to determine whether both branches specify the |
| 1512 | /// same likelihood, which affects the result. |
| 1513 | static Likelihood getLikelihood(const Stmt *Then, const Stmt *Else); |
| 1514 | |
| 1515 | /// \returns whether the likelihood of the branches of an if statement are |
| 1516 | /// conflicting. When the first element is \c true there's a conflict and |
| 1517 | /// the Attr's are the conflicting attributes of the Then and Else Stmt. |
| 1518 | static std::tuple<bool, const Attr *, const Attr *> |
| 1519 | determineLikelihoodConflict(const Stmt *Then, const Stmt *Else); |
| 1520 | |
| 1521 | /// Dumps the specified AST fragment and all subtrees to |
| 1522 | /// \c llvm::errs(). |
| 1523 | void dump() const; |
| 1524 | void dump(raw_ostream &OS, const ASTContext &Context) const; |
| 1525 | |
| 1526 | /// \return Unique reproducible object identifier |
| 1527 | int64_t getID(const ASTContext &Context) const; |
| 1528 | |
| 1529 | /// dumpColor - same as dump(), but forces color highlighting. |
| 1530 | void dumpColor() const; |
| 1531 | |
| 1532 | /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST |
| 1533 | /// back to its original source language syntax. |
| 1534 | void dumpPretty(const ASTContext &Context) const; |
| 1535 | void printPretty(raw_ostream &OS, PrinterHelper *Helper, |
| 1536 | const PrintingPolicy &Policy, unsigned Indentation = 0, |
| 1537 | StringRef NewlineSymbol = "\n" , |
| 1538 | const ASTContext *Context = nullptr) const; |
| 1539 | void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper, |
| 1540 | const PrintingPolicy &Policy, |
| 1541 | unsigned Indentation = 0, |
| 1542 | StringRef NewlineSymbol = "\n" , |
| 1543 | const ASTContext *Context = nullptr) const; |
| 1544 | |
| 1545 | /// Pretty-prints in JSON format. |
| 1546 | void printJson(raw_ostream &Out, PrinterHelper *Helper, |
| 1547 | const PrintingPolicy &Policy, bool AddQuotes) const; |
| 1548 | |
| 1549 | /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only |
| 1550 | /// works on systems with GraphViz (Mac OS X) or dot+gv installed. |
| 1551 | void viewAST() const; |
| 1552 | |
| 1553 | /// Skip no-op (attributed, compound) container stmts and skip captured |
| 1554 | /// stmt at the top, if \a IgnoreCaptured is true. |
| 1555 | Stmt *IgnoreContainers(bool IgnoreCaptured = false); |
| 1556 | const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const { |
| 1557 | return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured); |
| 1558 | } |
| 1559 | |
| 1560 | const Stmt *stripLabelLikeStatements() const; |
| 1561 | Stmt *stripLabelLikeStatements() { |
| 1562 | return const_cast<Stmt*>( |
| 1563 | const_cast<const Stmt*>(this)->stripLabelLikeStatements()); |
| 1564 | } |
| 1565 | |
| 1566 | /// Child Iterators: All subclasses must implement 'children' |
| 1567 | /// to permit easy iteration over the substatements/subexpressions of an |
| 1568 | /// AST node. This permits easy iteration over all nodes in the AST. |
| 1569 | using child_iterator = StmtIterator; |
| 1570 | using const_child_iterator = ConstStmtIterator; |
| 1571 | |
| 1572 | using child_range = llvm::iterator_range<child_iterator>; |
| 1573 | using const_child_range = llvm::iterator_range<const_child_iterator>; |
| 1574 | |
| 1575 | child_range children(); |
| 1576 | |
| 1577 | const_child_range children() const { |
| 1578 | auto Children = const_cast<Stmt *>(this)->children(); |
| 1579 | return const_child_range(Children.begin(), Children.end()); |
| 1580 | } |
| 1581 | |
| 1582 | child_iterator child_begin() { return children().begin(); } |
| 1583 | child_iterator child_end() { return children().end(); } |
| 1584 | |
| 1585 | const_child_iterator child_begin() const { return children().begin(); } |
| 1586 | const_child_iterator child_end() const { return children().end(); } |
| 1587 | |
| 1588 | /// Produce a unique representation of the given statement. |
| 1589 | /// |
| 1590 | /// \param ID once the profiling operation is complete, will contain |
| 1591 | /// the unique representation of the given statement. |
| 1592 | /// |
| 1593 | /// \param Context the AST context in which the statement resides |
| 1594 | /// |
| 1595 | /// \param Canonical whether the profile should be based on the canonical |
| 1596 | /// representation of this statement (e.g., where non-type template |
| 1597 | /// parameters are identified by index/level rather than their |
| 1598 | /// declaration pointers) or the exact representation of the statement as |
| 1599 | /// written in the source. |
| 1600 | /// \param ProfileLambdaExpr whether or not to profile lambda expressions. |
| 1601 | /// When false, the lambda expressions are never considered to be equal to |
| 1602 | /// other lambda expressions. When true, the lambda expressions with the same |
| 1603 | /// implementation will be considered to be the same. ProfileLambdaExpr should |
| 1604 | /// only be true when we try to merge two declarations within modules. |
| 1605 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 1606 | bool Canonical, bool ProfileLambdaExpr = false) const; |
| 1607 | |
| 1608 | /// Calculate a unique representation for a statement that is |
| 1609 | /// stable across compiler invocations. |
| 1610 | /// |
| 1611 | /// \param ID profile information will be stored in ID. |
| 1612 | /// |
| 1613 | /// \param Hash an ODRHash object which will be called where pointers would |
| 1614 | /// have been used in the Profile function. |
| 1615 | void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const; |
| 1616 | }; |
| 1617 | |
| 1618 | /// DeclStmt - Adaptor class for mixing declarations with statements and |
| 1619 | /// expressions. For example, CompoundStmt mixes statements, expressions |
| 1620 | /// and declarations (variables, types). Another example is ForStmt, where |
| 1621 | /// the first statement can be an expression or a declaration. |
| 1622 | class DeclStmt : public Stmt { |
| 1623 | DeclGroupRef DG; |
| 1624 | SourceLocation StartLoc, EndLoc; |
| 1625 | |
| 1626 | public: |
| 1627 | DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc) |
| 1628 | : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {} |
| 1629 | |
| 1630 | /// Build an empty declaration statement. |
| 1631 | explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {} |
| 1632 | |
| 1633 | /// isSingleDecl - This method returns true if this DeclStmt refers |
| 1634 | /// to a single Decl. |
| 1635 | bool isSingleDecl() const { return DG.isSingleDecl(); } |
| 1636 | |
| 1637 | const Decl *getSingleDecl() const { return DG.getSingleDecl(); } |
| 1638 | Decl *getSingleDecl() { return DG.getSingleDecl(); } |
| 1639 | |
| 1640 | const DeclGroupRef getDeclGroup() const { return DG; } |
| 1641 | DeclGroupRef getDeclGroup() { return DG; } |
| 1642 | void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } |
| 1643 | |
| 1644 | void setStartLoc(SourceLocation L) { StartLoc = L; } |
| 1645 | SourceLocation getEndLoc() const { return EndLoc; } |
| 1646 | void setEndLoc(SourceLocation L) { EndLoc = L; } |
| 1647 | |
| 1648 | SourceLocation getBeginLoc() const LLVM_READONLY { return StartLoc; } |
| 1649 | |
| 1650 | static bool classof(const Stmt *T) { |
| 1651 | return T->getStmtClass() == DeclStmtClass; |
| 1652 | } |
| 1653 | |
| 1654 | // Iterators over subexpressions. |
| 1655 | child_range children() { |
| 1656 | return child_range(child_iterator(DG.begin(), DG.end()), |
| 1657 | child_iterator(DG.end(), DG.end())); |
| 1658 | } |
| 1659 | |
| 1660 | const_child_range children() const { |
| 1661 | auto Children = const_cast<DeclStmt *>(this)->children(); |
| 1662 | return const_child_range(Children); |
| 1663 | } |
| 1664 | |
| 1665 | using decl_iterator = DeclGroupRef::iterator; |
| 1666 | using const_decl_iterator = DeclGroupRef::const_iterator; |
| 1667 | using decl_range = llvm::iterator_range<decl_iterator>; |
| 1668 | using decl_const_range = llvm::iterator_range<const_decl_iterator>; |
| 1669 | |
| 1670 | decl_range decls() { return decl_range(decl_begin(), decl_end()); } |
| 1671 | |
| 1672 | decl_const_range decls() const { |
| 1673 | return decl_const_range(decl_begin(), decl_end()); |
| 1674 | } |
| 1675 | |
| 1676 | decl_iterator decl_begin() { return DG.begin(); } |
| 1677 | decl_iterator decl_end() { return DG.end(); } |
| 1678 | const_decl_iterator decl_begin() const { return DG.begin(); } |
| 1679 | const_decl_iterator decl_end() const { return DG.end(); } |
| 1680 | |
| 1681 | using reverse_decl_iterator = std::reverse_iterator<decl_iterator>; |
| 1682 | |
| 1683 | reverse_decl_iterator decl_rbegin() { |
| 1684 | return reverse_decl_iterator(decl_end()); |
| 1685 | } |
| 1686 | |
| 1687 | reverse_decl_iterator decl_rend() { |
| 1688 | return reverse_decl_iterator(decl_begin()); |
| 1689 | } |
| 1690 | }; |
| 1691 | |
| 1692 | /// NullStmt - This is the null statement ";": C99 6.8.3p3. |
| 1693 | /// |
| 1694 | class NullStmt : public Stmt { |
| 1695 | public: |
| 1696 | NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false) |
| 1697 | : Stmt(NullStmtClass) { |
| 1698 | NullStmtBits.HasLeadingEmptyMacro = hasLeadingEmptyMacro; |
| 1699 | setSemiLoc(L); |
| 1700 | } |
| 1701 | |
| 1702 | /// Build an empty null statement. |
| 1703 | explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {} |
| 1704 | |
| 1705 | SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; } |
| 1706 | void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; } |
| 1707 | |
| 1708 | bool hasLeadingEmptyMacro() const { |
| 1709 | return NullStmtBits.HasLeadingEmptyMacro; |
| 1710 | } |
| 1711 | |
| 1712 | SourceLocation getBeginLoc() const { return getSemiLoc(); } |
| 1713 | SourceLocation getEndLoc() const { return getSemiLoc(); } |
| 1714 | |
| 1715 | static bool classof(const Stmt *T) { |
| 1716 | return T->getStmtClass() == NullStmtClass; |
| 1717 | } |
| 1718 | |
| 1719 | child_range children() { |
| 1720 | return child_range(child_iterator(), child_iterator()); |
| 1721 | } |
| 1722 | |
| 1723 | const_child_range children() const { |
| 1724 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 1725 | } |
| 1726 | }; |
| 1727 | |
| 1728 | /// CompoundStmt - This represents a group of statements like { stmt stmt }. |
| 1729 | class CompoundStmt final |
| 1730 | : public Stmt, |
| 1731 | private llvm::TrailingObjects<CompoundStmt, Stmt *, FPOptionsOverride> { |
| 1732 | friend class ASTStmtReader; |
| 1733 | friend TrailingObjects; |
| 1734 | |
| 1735 | /// The location of the opening "{". |
| 1736 | SourceLocation LBraceLoc; |
| 1737 | |
| 1738 | /// The location of the closing "}". |
| 1739 | SourceLocation RBraceLoc; |
| 1740 | |
| 1741 | CompoundStmt(ArrayRef<Stmt *> Stmts, FPOptionsOverride FPFeatures, |
| 1742 | SourceLocation LB, SourceLocation RB); |
| 1743 | explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {} |
| 1744 | |
| 1745 | void setStmts(ArrayRef<Stmt *> Stmts); |
| 1746 | |
| 1747 | /// Set FPOptionsOverride in trailing storage. Used only by Serialization. |
| 1748 | void setStoredFPFeatures(FPOptionsOverride F) { |
| 1749 | assert(hasStoredFPFeatures()); |
| 1750 | *getTrailingObjects<FPOptionsOverride>() = F; |
| 1751 | } |
| 1752 | |
| 1753 | size_t numTrailingObjects(OverloadToken<Stmt *>) const { |
| 1754 | return CompoundStmtBits.NumStmts; |
| 1755 | } |
| 1756 | |
| 1757 | public: |
| 1758 | static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts, |
| 1759 | FPOptionsOverride FPFeatures, SourceLocation LB, |
| 1760 | SourceLocation RB); |
| 1761 | |
| 1762 | // Build an empty compound statement with a location. |
| 1763 | explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {} |
| 1764 | |
| 1765 | CompoundStmt(SourceLocation Loc, SourceLocation EndLoc) |
| 1766 | : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) { |
| 1767 | CompoundStmtBits.NumStmts = 0; |
| 1768 | CompoundStmtBits.HasFPFeatures = 0; |
| 1769 | } |
| 1770 | |
| 1771 | // Build an empty compound statement. |
| 1772 | static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts, |
| 1773 | bool HasFPFeatures); |
| 1774 | |
| 1775 | bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } |
| 1776 | unsigned size() const { return CompoundStmtBits.NumStmts; } |
| 1777 | |
| 1778 | bool hasStoredFPFeatures() const { return CompoundStmtBits.HasFPFeatures; } |
| 1779 | |
| 1780 | /// Get FPOptionsOverride from trailing storage. |
| 1781 | FPOptionsOverride getStoredFPFeatures() const { |
| 1782 | assert(hasStoredFPFeatures()); |
| 1783 | return *getTrailingObjects<FPOptionsOverride>(); |
| 1784 | } |
| 1785 | |
| 1786 | /// Get the store FPOptionsOverride or default if not stored. |
| 1787 | FPOptionsOverride getStoredFPFeaturesOrDefault() const { |
| 1788 | return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride(); |
| 1789 | } |
| 1790 | |
| 1791 | using body_iterator = Stmt **; |
| 1792 | using body_range = llvm::iterator_range<body_iterator>; |
| 1793 | |
| 1794 | body_range body() { return body_range(body_begin(), body_end()); } |
| 1795 | body_iterator body_begin() { return getTrailingObjects<Stmt *>(); } |
| 1796 | body_iterator body_end() { return body_begin() + size(); } |
| 1797 | Stmt *body_front() { return !body_empty() ? body_begin()[0] : nullptr; } |
| 1798 | |
| 1799 | Stmt *body_back() { |
| 1800 | return !body_empty() ? body_begin()[size() - 1] : nullptr; |
| 1801 | } |
| 1802 | |
| 1803 | using const_body_iterator = Stmt *const *; |
| 1804 | using body_const_range = llvm::iterator_range<const_body_iterator>; |
| 1805 | |
| 1806 | body_const_range body() const { |
| 1807 | return body_const_range(body_begin(), body_end()); |
| 1808 | } |
| 1809 | |
| 1810 | const_body_iterator body_begin() const { |
| 1811 | return getTrailingObjects<Stmt *>(); |
| 1812 | } |
| 1813 | |
| 1814 | const_body_iterator body_end() const { return body_begin() + size(); } |
| 1815 | |
| 1816 | const Stmt *body_front() const { |
| 1817 | return !body_empty() ? body_begin()[0] : nullptr; |
| 1818 | } |
| 1819 | |
| 1820 | const Stmt *body_back() const { |
| 1821 | return !body_empty() ? body_begin()[size() - 1] : nullptr; |
| 1822 | } |
| 1823 | |
| 1824 | using reverse_body_iterator = std::reverse_iterator<body_iterator>; |
| 1825 | |
| 1826 | reverse_body_iterator body_rbegin() { |
| 1827 | return reverse_body_iterator(body_end()); |
| 1828 | } |
| 1829 | |
| 1830 | reverse_body_iterator body_rend() { |
| 1831 | return reverse_body_iterator(body_begin()); |
| 1832 | } |
| 1833 | |
| 1834 | using const_reverse_body_iterator = |
| 1835 | std::reverse_iterator<const_body_iterator>; |
| 1836 | |
| 1837 | const_reverse_body_iterator body_rbegin() const { |
| 1838 | return const_reverse_body_iterator(body_end()); |
| 1839 | } |
| 1840 | |
| 1841 | const_reverse_body_iterator body_rend() const { |
| 1842 | return const_reverse_body_iterator(body_begin()); |
| 1843 | } |
| 1844 | |
| 1845 | // Get the Stmt that StmtExpr would consider to be the result of this |
| 1846 | // compound statement. This is used by StmtExpr to properly emulate the GCC |
| 1847 | // compound expression extension, which ignores trailing NullStmts when |
| 1848 | // getting the result of the expression. |
| 1849 | // i.e. ({ 5;;; }) |
| 1850 | // ^^ ignored |
| 1851 | // If we don't find something that isn't a NullStmt, just return the last |
| 1852 | // Stmt. |
| 1853 | Stmt *getStmtExprResult() { |
| 1854 | for (auto *B : llvm::reverse(body())) { |
| 1855 | if (!isa<NullStmt>(B)) |
| 1856 | return B; |
| 1857 | } |
| 1858 | return body_back(); |
| 1859 | } |
| 1860 | |
| 1861 | const Stmt *getStmtExprResult() const { |
| 1862 | return const_cast<CompoundStmt *>(this)->getStmtExprResult(); |
| 1863 | } |
| 1864 | |
| 1865 | SourceLocation getBeginLoc() const { return LBraceLoc; } |
| 1866 | SourceLocation getEndLoc() const { return RBraceLoc; } |
| 1867 | |
| 1868 | SourceLocation getLBracLoc() const { return LBraceLoc; } |
| 1869 | SourceLocation getRBracLoc() const { return RBraceLoc; } |
| 1870 | |
| 1871 | static bool classof(const Stmt *T) { |
| 1872 | return T->getStmtClass() == CompoundStmtClass; |
| 1873 | } |
| 1874 | |
| 1875 | // Iterators |
| 1876 | child_range children() { return child_range(body_begin(), body_end()); } |
| 1877 | |
| 1878 | const_child_range children() const { |
| 1879 | return const_child_range(body_begin(), body_end()); |
| 1880 | } |
| 1881 | }; |
| 1882 | |
| 1883 | // SwitchCase is the base class for CaseStmt and DefaultStmt, |
| 1884 | class SwitchCase : public Stmt { |
| 1885 | protected: |
| 1886 | /// The location of the ":". |
| 1887 | SourceLocation ColonLoc; |
| 1888 | |
| 1889 | // The location of the "case" or "default" keyword. Stored in SwitchCaseBits. |
| 1890 | // SourceLocation KeywordLoc; |
| 1891 | |
| 1892 | /// A pointer to the following CaseStmt or DefaultStmt class, |
| 1893 | /// used by SwitchStmt. |
| 1894 | SwitchCase *NextSwitchCase = nullptr; |
| 1895 | |
| 1896 | SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc) |
| 1897 | : Stmt(SC), ColonLoc(ColonLoc) { |
| 1898 | setKeywordLoc(KWLoc); |
| 1899 | } |
| 1900 | |
| 1901 | SwitchCase(StmtClass SC, EmptyShell) : Stmt(SC) {} |
| 1902 | |
| 1903 | public: |
| 1904 | const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } |
| 1905 | SwitchCase *getNextSwitchCase() { return NextSwitchCase; } |
| 1906 | void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } |
| 1907 | |
| 1908 | SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; } |
| 1909 | void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; } |
| 1910 | SourceLocation getColonLoc() const { return ColonLoc; } |
| 1911 | void setColonLoc(SourceLocation L) { ColonLoc = L; } |
| 1912 | |
| 1913 | inline Stmt *getSubStmt(); |
| 1914 | const Stmt *getSubStmt() const { |
| 1915 | return const_cast<SwitchCase *>(this)->getSubStmt(); |
| 1916 | } |
| 1917 | |
| 1918 | SourceLocation getBeginLoc() const { return getKeywordLoc(); } |
| 1919 | inline SourceLocation getEndLoc() const LLVM_READONLY; |
| 1920 | |
| 1921 | static bool classof(const Stmt *T) { |
| 1922 | return T->getStmtClass() == CaseStmtClass || |
| 1923 | T->getStmtClass() == DefaultStmtClass; |
| 1924 | } |
| 1925 | }; |
| 1926 | |
| 1927 | /// CaseStmt - Represent a case statement. It can optionally be a GNU case |
| 1928 | /// statement of the form LHS ... RHS representing a range of cases. |
| 1929 | class CaseStmt final |
| 1930 | : public SwitchCase, |
| 1931 | private llvm::TrailingObjects<CaseStmt, Stmt *, SourceLocation> { |
| 1932 | friend TrailingObjects; |
| 1933 | |
| 1934 | // CaseStmt is followed by several trailing objects, some of which optional. |
| 1935 | // Note that it would be more convenient to put the optional trailing objects |
| 1936 | // at the end but this would impact children(). |
| 1937 | // The trailing objects are in order: |
| 1938 | // |
| 1939 | // * A "Stmt *" for the LHS of the case statement. Always present. |
| 1940 | // |
| 1941 | // * A "Stmt *" for the RHS of the case statement. This is a GNU extension |
| 1942 | // which allow ranges in cases statement of the form LHS ... RHS. |
| 1943 | // Present if and only if caseStmtIsGNURange() is true. |
| 1944 | // |
| 1945 | // * A "Stmt *" for the substatement of the case statement. Always present. |
| 1946 | // |
| 1947 | // * A SourceLocation for the location of the ... if this is a case statement |
| 1948 | // with a range. Present if and only if caseStmtIsGNURange() is true. |
| 1949 | enum { LhsOffset = 0, SubStmtOffsetFromRhs = 1 }; |
| 1950 | enum { NumMandatoryStmtPtr = 2 }; |
| 1951 | |
| 1952 | unsigned numTrailingObjects(OverloadToken<Stmt *>) const { |
| 1953 | return NumMandatoryStmtPtr + caseStmtIsGNURange(); |
| 1954 | } |
| 1955 | |
| 1956 | unsigned lhsOffset() const { return LhsOffset; } |
| 1957 | unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); } |
| 1958 | unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; } |
| 1959 | |
| 1960 | /// Build a case statement assuming that the storage for the |
| 1961 | /// trailing objects has been properly allocated. |
| 1962 | CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, |
| 1963 | SourceLocation ellipsisLoc, SourceLocation colonLoc) |
| 1964 | : SwitchCase(CaseStmtClass, caseLoc, colonLoc) { |
| 1965 | // Handle GNU case statements of the form LHS ... RHS. |
| 1966 | bool IsGNURange = rhs != nullptr; |
| 1967 | SwitchCaseBits.CaseStmtIsGNURange = IsGNURange; |
| 1968 | setLHS(lhs); |
| 1969 | setSubStmt(nullptr); |
| 1970 | if (IsGNURange) { |
| 1971 | setRHS(rhs); |
| 1972 | setEllipsisLoc(ellipsisLoc); |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | /// Build an empty switch case statement. |
| 1977 | explicit CaseStmt(EmptyShell Empty, bool CaseStmtIsGNURange) |
| 1978 | : SwitchCase(CaseStmtClass, Empty) { |
| 1979 | SwitchCaseBits.CaseStmtIsGNURange = CaseStmtIsGNURange; |
| 1980 | } |
| 1981 | |
| 1982 | public: |
| 1983 | /// Build a case statement. |
| 1984 | static CaseStmt *Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, |
| 1985 | SourceLocation caseLoc, SourceLocation ellipsisLoc, |
| 1986 | SourceLocation colonLoc); |
| 1987 | |
| 1988 | /// Build an empty case statement. |
| 1989 | static CaseStmt *CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange); |
| 1990 | |
| 1991 | /// True if this case statement is of the form case LHS ... RHS, which |
| 1992 | /// is a GNU extension. In this case the RHS can be obtained with getRHS() |
| 1993 | /// and the location of the ellipsis can be obtained with getEllipsisLoc(). |
| 1994 | bool caseStmtIsGNURange() const { return SwitchCaseBits.CaseStmtIsGNURange; } |
| 1995 | |
| 1996 | SourceLocation getCaseLoc() const { return getKeywordLoc(); } |
| 1997 | void setCaseLoc(SourceLocation L) { setKeywordLoc(L); } |
| 1998 | |
| 1999 | /// Get the location of the ... in a case statement of the form LHS ... RHS. |
| 2000 | SourceLocation getEllipsisLoc() const { |
| 2001 | return caseStmtIsGNURange() ? *getTrailingObjects<SourceLocation>() |
| 2002 | : SourceLocation(); |
| 2003 | } |
| 2004 | |
| 2005 | /// Set the location of the ... in a case statement of the form LHS ... RHS. |
| 2006 | /// Assert that this case statement is of this form. |
| 2007 | void setEllipsisLoc(SourceLocation L) { |
| 2008 | assert( |
| 2009 | caseStmtIsGNURange() && |
| 2010 | "setEllipsisLoc but this is not a case stmt of the form LHS ... RHS!" ); |
| 2011 | *getTrailingObjects<SourceLocation>() = L; |
| 2012 | } |
| 2013 | |
| 2014 | Expr *getLHS() { |
| 2015 | return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]); |
| 2016 | } |
| 2017 | |
| 2018 | const Expr *getLHS() const { |
| 2019 | return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]); |
| 2020 | } |
| 2021 | |
| 2022 | void setLHS(Expr *Val) { |
| 2023 | getTrailingObjects<Stmt *>()[lhsOffset()] = reinterpret_cast<Stmt *>(Val); |
| 2024 | } |
| 2025 | |
| 2026 | Expr *getRHS() { |
| 2027 | return caseStmtIsGNURange() ? reinterpret_cast<Expr *>( |
| 2028 | getTrailingObjects<Stmt *>()[rhsOffset()]) |
| 2029 | : nullptr; |
| 2030 | } |
| 2031 | |
| 2032 | const Expr *getRHS() const { |
| 2033 | return caseStmtIsGNURange() ? reinterpret_cast<Expr *>( |
| 2034 | getTrailingObjects<Stmt *>()[rhsOffset()]) |
| 2035 | : nullptr; |
| 2036 | } |
| 2037 | |
| 2038 | void setRHS(Expr *Val) { |
| 2039 | assert(caseStmtIsGNURange() && |
| 2040 | "setRHS but this is not a case stmt of the form LHS ... RHS!" ); |
| 2041 | getTrailingObjects<Stmt *>()[rhsOffset()] = reinterpret_cast<Stmt *>(Val); |
| 2042 | } |
| 2043 | |
| 2044 | Stmt *getSubStmt() { return getTrailingObjects<Stmt *>()[subStmtOffset()]; } |
| 2045 | const Stmt *getSubStmt() const { |
| 2046 | return getTrailingObjects<Stmt *>()[subStmtOffset()]; |
| 2047 | } |
| 2048 | |
| 2049 | void setSubStmt(Stmt *S) { |
| 2050 | getTrailingObjects<Stmt *>()[subStmtOffset()] = S; |
| 2051 | } |
| 2052 | |
| 2053 | SourceLocation getBeginLoc() const { return getKeywordLoc(); } |
| 2054 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 2055 | // Handle deeply nested case statements with iteration instead of recursion. |
| 2056 | const CaseStmt *CS = this; |
| 2057 | while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) |
| 2058 | CS = CS2; |
| 2059 | |
| 2060 | return CS->getSubStmt()->getEndLoc(); |
| 2061 | } |
| 2062 | |
| 2063 | static bool classof(const Stmt *T) { |
| 2064 | return T->getStmtClass() == CaseStmtClass; |
| 2065 | } |
| 2066 | |
| 2067 | // Iterators |
| 2068 | child_range children() { |
| 2069 | return child_range(getTrailingObjects<Stmt *>(), |
| 2070 | getTrailingObjects<Stmt *>() + |
| 2071 | numTrailingObjects(OverloadToken<Stmt *>())); |
| 2072 | } |
| 2073 | |
| 2074 | const_child_range children() const { |
| 2075 | return const_child_range(getTrailingObjects<Stmt *>(), |
| 2076 | getTrailingObjects<Stmt *>() + |
| 2077 | numTrailingObjects(OverloadToken<Stmt *>())); |
| 2078 | } |
| 2079 | }; |
| 2080 | |
| 2081 | class DefaultStmt : public SwitchCase { |
| 2082 | Stmt *SubStmt; |
| 2083 | |
| 2084 | public: |
| 2085 | DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) |
| 2086 | : SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {} |
| 2087 | |
| 2088 | /// Build an empty default statement. |
| 2089 | explicit DefaultStmt(EmptyShell Empty) |
| 2090 | : SwitchCase(DefaultStmtClass, Empty) {} |
| 2091 | |
| 2092 | Stmt *getSubStmt() { return SubStmt; } |
| 2093 | const Stmt *getSubStmt() const { return SubStmt; } |
| 2094 | void setSubStmt(Stmt *S) { SubStmt = S; } |
| 2095 | |
| 2096 | SourceLocation getDefaultLoc() const { return getKeywordLoc(); } |
| 2097 | void setDefaultLoc(SourceLocation L) { setKeywordLoc(L); } |
| 2098 | |
| 2099 | SourceLocation getBeginLoc() const { return getKeywordLoc(); } |
| 2100 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 2101 | return SubStmt->getEndLoc(); |
| 2102 | } |
| 2103 | |
| 2104 | static bool classof(const Stmt *T) { |
| 2105 | return T->getStmtClass() == DefaultStmtClass; |
| 2106 | } |
| 2107 | |
| 2108 | // Iterators |
| 2109 | child_range children() { return child_range(&SubStmt, &SubStmt + 1); } |
| 2110 | |
| 2111 | const_child_range children() const { |
| 2112 | return const_child_range(&SubStmt, &SubStmt + 1); |
| 2113 | } |
| 2114 | }; |
| 2115 | |
| 2116 | SourceLocation SwitchCase::getEndLoc() const { |
| 2117 | if (const auto *CS = dyn_cast<CaseStmt>(this)) |
| 2118 | return CS->getEndLoc(); |
| 2119 | else if (const auto *DS = dyn_cast<DefaultStmt>(this)) |
| 2120 | return DS->getEndLoc(); |
| 2121 | llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!" ); |
| 2122 | } |
| 2123 | |
| 2124 | Stmt *SwitchCase::getSubStmt() { |
| 2125 | if (auto *CS = dyn_cast<CaseStmt>(this)) |
| 2126 | return CS->getSubStmt(); |
| 2127 | else if (auto *DS = dyn_cast<DefaultStmt>(this)) |
| 2128 | return DS->getSubStmt(); |
| 2129 | llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!" ); |
| 2130 | } |
| 2131 | |
| 2132 | /// Represents a statement that could possibly have a value and type. This |
| 2133 | /// covers expression-statements, as well as labels and attributed statements. |
| 2134 | /// |
| 2135 | /// Value statements have a special meaning when they are the last non-null |
| 2136 | /// statement in a GNU statement expression, where they determine the value |
| 2137 | /// of the statement expression. |
| 2138 | class ValueStmt : public Stmt { |
| 2139 | protected: |
| 2140 | using Stmt::Stmt; |
| 2141 | |
| 2142 | public: |
| 2143 | const Expr *getExprStmt() const; |
| 2144 | Expr *getExprStmt() { |
| 2145 | const ValueStmt *ConstThis = this; |
| 2146 | return const_cast<Expr*>(ConstThis->getExprStmt()); |
| 2147 | } |
| 2148 | |
| 2149 | static bool classof(const Stmt *T) { |
| 2150 | return T->getStmtClass() >= firstValueStmtConstant && |
| 2151 | T->getStmtClass() <= lastValueStmtConstant; |
| 2152 | } |
| 2153 | }; |
| 2154 | |
| 2155 | /// LabelStmt - Represents a label, which has a substatement. For example: |
| 2156 | /// foo: return; |
| 2157 | class LabelStmt : public ValueStmt { |
| 2158 | LabelDecl *TheDecl; |
| 2159 | Stmt *SubStmt; |
| 2160 | bool SideEntry = false; |
| 2161 | |
| 2162 | public: |
| 2163 | /// Build a label statement. |
| 2164 | LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) |
| 2165 | : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) { |
| 2166 | setIdentLoc(IL); |
| 2167 | } |
| 2168 | |
| 2169 | /// Build an empty label statement. |
| 2170 | explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {} |
| 2171 | |
| 2172 | SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; } |
| 2173 | void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; } |
| 2174 | |
| 2175 | LabelDecl *getDecl() const { return TheDecl; } |
| 2176 | void setDecl(LabelDecl *D) { TheDecl = D; } |
| 2177 | |
| 2178 | const char *getName() const; |
| 2179 | Stmt *getSubStmt() { return SubStmt; } |
| 2180 | |
| 2181 | const Stmt *getSubStmt() const { return SubStmt; } |
| 2182 | void setSubStmt(Stmt *SS) { SubStmt = SS; } |
| 2183 | |
| 2184 | SourceLocation getBeginLoc() const { return getIdentLoc(); } |
| 2185 | SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();} |
| 2186 | |
| 2187 | child_range children() { return child_range(&SubStmt, &SubStmt + 1); } |
| 2188 | |
| 2189 | const_child_range children() const { |
| 2190 | return const_child_range(&SubStmt, &SubStmt + 1); |
| 2191 | } |
| 2192 | |
| 2193 | static bool classof(const Stmt *T) { |
| 2194 | return T->getStmtClass() == LabelStmtClass; |
| 2195 | } |
| 2196 | bool isSideEntry() const { return SideEntry; } |
| 2197 | void setSideEntry(bool SE) { SideEntry = SE; } |
| 2198 | }; |
| 2199 | |
| 2200 | /// Represents an attribute applied to a statement. |
| 2201 | /// |
| 2202 | /// Represents an attribute applied to a statement. For example: |
| 2203 | /// [[omp::for(...)]] for (...) { ... } |
| 2204 | class AttributedStmt final |
| 2205 | : public ValueStmt, |
| 2206 | private llvm::TrailingObjects<AttributedStmt, const Attr *> { |
| 2207 | friend class ASTStmtReader; |
| 2208 | friend TrailingObjects; |
| 2209 | |
| 2210 | Stmt *SubStmt; |
| 2211 | |
| 2212 | AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs, |
| 2213 | Stmt *SubStmt) |
| 2214 | : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) { |
| 2215 | AttributedStmtBits.NumAttrs = Attrs.size(); |
| 2216 | AttributedStmtBits.AttrLoc = Loc; |
| 2217 | std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr()); |
| 2218 | } |
| 2219 | |
| 2220 | explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) |
| 2221 | : ValueStmt(AttributedStmtClass, Empty) { |
| 2222 | AttributedStmtBits.NumAttrs = NumAttrs; |
| 2223 | AttributedStmtBits.AttrLoc = SourceLocation{}; |
| 2224 | std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr); |
| 2225 | } |
| 2226 | |
| 2227 | const Attr *const *getAttrArrayPtr() const { return getTrailingObjects(); } |
| 2228 | const Attr **getAttrArrayPtr() { return getTrailingObjects(); } |
| 2229 | |
| 2230 | public: |
| 2231 | static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc, |
| 2232 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
| 2233 | |
| 2234 | // Build an empty attributed statement. |
| 2235 | static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs); |
| 2236 | |
| 2237 | SourceLocation getAttrLoc() const { return AttributedStmtBits.AttrLoc; } |
| 2238 | ArrayRef<const Attr *> getAttrs() const { |
| 2239 | return llvm::ArrayRef(getAttrArrayPtr(), AttributedStmtBits.NumAttrs); |
| 2240 | } |
| 2241 | |
| 2242 | Stmt *getSubStmt() { return SubStmt; } |
| 2243 | const Stmt *getSubStmt() const { return SubStmt; } |
| 2244 | |
| 2245 | SourceLocation getBeginLoc() const { return getAttrLoc(); } |
| 2246 | SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();} |
| 2247 | |
| 2248 | child_range children() { return child_range(&SubStmt, &SubStmt + 1); } |
| 2249 | |
| 2250 | const_child_range children() const { |
| 2251 | return const_child_range(&SubStmt, &SubStmt + 1); |
| 2252 | } |
| 2253 | |
| 2254 | static bool classof(const Stmt *T) { |
| 2255 | return T->getStmtClass() == AttributedStmtClass; |
| 2256 | } |
| 2257 | }; |
| 2258 | |
| 2259 | /// IfStmt - This represents an if/then/else. |
| 2260 | class IfStmt final |
| 2261 | : public Stmt, |
| 2262 | private llvm::TrailingObjects<IfStmt, Stmt *, SourceLocation> { |
| 2263 | friend TrailingObjects; |
| 2264 | |
| 2265 | // IfStmt is followed by several trailing objects, some of which optional. |
| 2266 | // Note that it would be more convenient to put the optional trailing |
| 2267 | // objects at then end but this would change the order of the children. |
| 2268 | // The trailing objects are in order: |
| 2269 | // |
| 2270 | // * A "Stmt *" for the init statement. |
| 2271 | // Present if and only if hasInitStorage(). |
| 2272 | // |
| 2273 | // * A "Stmt *" for the condition variable. |
| 2274 | // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *". |
| 2275 | // |
| 2276 | // * A "Stmt *" for the condition. |
| 2277 | // Always present. This is in fact a "Expr *". |
| 2278 | // |
| 2279 | // * A "Stmt *" for the then statement. |
| 2280 | // Always present. |
| 2281 | // |
| 2282 | // * A "Stmt *" for the else statement. |
| 2283 | // Present if and only if hasElseStorage(). |
| 2284 | // |
| 2285 | // * A "SourceLocation" for the location of the "else". |
| 2286 | // Present if and only if hasElseStorage(). |
| 2287 | enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 }; |
| 2288 | enum { NumMandatoryStmtPtr = 2 }; |
| 2289 | SourceLocation LParenLoc; |
| 2290 | SourceLocation RParenLoc; |
| 2291 | |
| 2292 | unsigned numTrailingObjects(OverloadToken<Stmt *>) const { |
| 2293 | return NumMandatoryStmtPtr + hasElseStorage() + hasVarStorage() + |
| 2294 | hasInitStorage(); |
| 2295 | } |
| 2296 | |
| 2297 | unsigned numTrailingObjects(OverloadToken<SourceLocation>) const { |
| 2298 | return hasElseStorage(); |
| 2299 | } |
| 2300 | |
| 2301 | unsigned initOffset() const { return InitOffset; } |
| 2302 | unsigned varOffset() const { return InitOffset + hasInitStorage(); } |
| 2303 | unsigned condOffset() const { |
| 2304 | return InitOffset + hasInitStorage() + hasVarStorage(); |
| 2305 | } |
| 2306 | unsigned thenOffset() const { return condOffset() + ThenOffsetFromCond; } |
| 2307 | unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; } |
| 2308 | |
| 2309 | /// Build an if/then/else statement. |
| 2310 | IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, |
| 2311 | Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, |
| 2312 | SourceLocation RParenLoc, Stmt *Then, SourceLocation EL, Stmt *Else); |
| 2313 | |
| 2314 | /// Build an empty if/then/else statement. |
| 2315 | explicit IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit); |
| 2316 | |
| 2317 | public: |
| 2318 | /// Create an IfStmt. |
| 2319 | static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL, |
| 2320 | IfStatementKind Kind, Stmt *Init, VarDecl *Var, |
| 2321 | Expr *Cond, SourceLocation LPL, SourceLocation RPL, |
| 2322 | Stmt *Then, SourceLocation EL = SourceLocation(), |
| 2323 | Stmt *Else = nullptr); |
| 2324 | |
| 2325 | /// Create an empty IfStmt optionally with storage for an else statement, |
| 2326 | /// condition variable and init expression. |
| 2327 | static IfStmt *CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar, |
| 2328 | bool HasInit); |
| 2329 | |
| 2330 | /// True if this IfStmt has the storage for an init statement. |
| 2331 | bool hasInitStorage() const { return IfStmtBits.HasInit; } |
| 2332 | |
| 2333 | /// True if this IfStmt has storage for a variable declaration. |
| 2334 | bool hasVarStorage() const { return IfStmtBits.HasVar; } |
| 2335 | |
| 2336 | /// True if this IfStmt has storage for an else statement. |
| 2337 | bool hasElseStorage() const { return IfStmtBits.HasElse; } |
| 2338 | |
| 2339 | Expr *getCond() { |
| 2340 | return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]); |
| 2341 | } |
| 2342 | |
| 2343 | const Expr *getCond() const { |
| 2344 | return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]); |
| 2345 | } |
| 2346 | |
| 2347 | void setCond(Expr *Cond) { |
| 2348 | getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond); |
| 2349 | } |
| 2350 | |
| 2351 | Stmt *getThen() { return getTrailingObjects<Stmt *>()[thenOffset()]; } |
| 2352 | const Stmt *getThen() const { |
| 2353 | return getTrailingObjects<Stmt *>()[thenOffset()]; |
| 2354 | } |
| 2355 | |
| 2356 | void setThen(Stmt *Then) { |
| 2357 | getTrailingObjects<Stmt *>()[thenOffset()] = Then; |
| 2358 | } |
| 2359 | |
| 2360 | Stmt *getElse() { |
| 2361 | return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()] |
| 2362 | : nullptr; |
| 2363 | } |
| 2364 | |
| 2365 | const Stmt *getElse() const { |
| 2366 | return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()] |
| 2367 | : nullptr; |
| 2368 | } |
| 2369 | |
| 2370 | void setElse(Stmt *Else) { |
| 2371 | assert(hasElseStorage() && |
| 2372 | "This if statement has no storage for an else statement!" ); |
| 2373 | getTrailingObjects<Stmt *>()[elseOffset()] = Else; |
| 2374 | } |
| 2375 | |
| 2376 | /// Retrieve the variable declared in this "if" statement, if any. |
| 2377 | /// |
| 2378 | /// In the following example, "x" is the condition variable. |
| 2379 | /// \code |
| 2380 | /// if (int x = foo()) { |
| 2381 | /// printf("x is %d", x); |
| 2382 | /// } |
| 2383 | /// \endcode |
| 2384 | VarDecl *getConditionVariable(); |
| 2385 | const VarDecl *getConditionVariable() const { |
| 2386 | return const_cast<IfStmt *>(this)->getConditionVariable(); |
| 2387 | } |
| 2388 | |
| 2389 | /// Set the condition variable for this if statement. |
| 2390 | /// The if statement must have storage for the condition variable. |
| 2391 | void setConditionVariable(const ASTContext &Ctx, VarDecl *V); |
| 2392 | |
| 2393 | /// If this IfStmt has a condition variable, return the faux DeclStmt |
| 2394 | /// associated with the creation of that condition variable. |
| 2395 | DeclStmt *getConditionVariableDeclStmt() { |
| 2396 | return hasVarStorage() ? static_cast<DeclStmt *>( |
| 2397 | getTrailingObjects<Stmt *>()[varOffset()]) |
| 2398 | : nullptr; |
| 2399 | } |
| 2400 | |
| 2401 | const DeclStmt *getConditionVariableDeclStmt() const { |
| 2402 | return hasVarStorage() ? static_cast<DeclStmt *>( |
| 2403 | getTrailingObjects<Stmt *>()[varOffset()]) |
| 2404 | : nullptr; |
| 2405 | } |
| 2406 | |
| 2407 | void setConditionVariableDeclStmt(DeclStmt *CondVar) { |
| 2408 | assert(hasVarStorage()); |
| 2409 | getTrailingObjects<Stmt *>()[varOffset()] = CondVar; |
| 2410 | } |
| 2411 | |
| 2412 | Stmt *getInit() { |
| 2413 | return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()] |
| 2414 | : nullptr; |
| 2415 | } |
| 2416 | |
| 2417 | const Stmt *getInit() const { |
| 2418 | return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()] |
| 2419 | : nullptr; |
| 2420 | } |
| 2421 | |
| 2422 | void setInit(Stmt *Init) { |
| 2423 | assert(hasInitStorage() && |
| 2424 | "This if statement has no storage for an init statement!" ); |
| 2425 | getTrailingObjects<Stmt *>()[initOffset()] = Init; |
| 2426 | } |
| 2427 | |
| 2428 | SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; } |
| 2429 | void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; } |
| 2430 | |
| 2431 | SourceLocation getElseLoc() const { |
| 2432 | return hasElseStorage() ? *getTrailingObjects<SourceLocation>() |
| 2433 | : SourceLocation(); |
| 2434 | } |
| 2435 | |
| 2436 | void setElseLoc(SourceLocation ElseLoc) { |
| 2437 | assert(hasElseStorage() && |
| 2438 | "This if statement has no storage for an else statement!" ); |
| 2439 | *getTrailingObjects<SourceLocation>() = ElseLoc; |
| 2440 | } |
| 2441 | |
| 2442 | bool isConsteval() const { |
| 2443 | return getStatementKind() == IfStatementKind::ConstevalNonNegated || |
| 2444 | getStatementKind() == IfStatementKind::ConstevalNegated; |
| 2445 | } |
| 2446 | |
| 2447 | bool isNonNegatedConsteval() const { |
| 2448 | return getStatementKind() == IfStatementKind::ConstevalNonNegated; |
| 2449 | } |
| 2450 | |
| 2451 | bool isNegatedConsteval() const { |
| 2452 | return getStatementKind() == IfStatementKind::ConstevalNegated; |
| 2453 | } |
| 2454 | |
| 2455 | bool isConstexpr() const { |
| 2456 | return getStatementKind() == IfStatementKind::Constexpr; |
| 2457 | } |
| 2458 | |
| 2459 | void setStatementKind(IfStatementKind Kind) { |
| 2460 | IfStmtBits.Kind = static_cast<unsigned>(Kind); |
| 2461 | } |
| 2462 | |
| 2463 | IfStatementKind getStatementKind() const { |
| 2464 | return static_cast<IfStatementKind>(IfStmtBits.Kind); |
| 2465 | } |
| 2466 | |
| 2467 | /// If this is an 'if constexpr', determine which substatement will be taken. |
| 2468 | /// Otherwise, or if the condition is value-dependent, returns std::nullopt. |
| 2469 | std::optional<const Stmt *> getNondiscardedCase(const ASTContext &Ctx) const; |
| 2470 | std::optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx); |
| 2471 | |
| 2472 | bool isObjCAvailabilityCheck() const; |
| 2473 | |
| 2474 | SourceLocation getBeginLoc() const { return getIfLoc(); } |
| 2475 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 2476 | if (getElse()) |
| 2477 | return getElse()->getEndLoc(); |
| 2478 | return getThen()->getEndLoc(); |
| 2479 | } |
| 2480 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 2481 | void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } |
| 2482 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 2483 | void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; } |
| 2484 | |
| 2485 | // Iterators over subexpressions. The iterators will include iterating |
| 2486 | // over the initialization expression referenced by the condition variable. |
| 2487 | child_range children() { |
| 2488 | // We always store a condition, but there is none for consteval if |
| 2489 | // statements, so skip it. |
| 2490 | return child_range(getTrailingObjects<Stmt *>() + |
| 2491 | (isConsteval() ? thenOffset() : 0), |
| 2492 | getTrailingObjects<Stmt *>() + |
| 2493 | numTrailingObjects(OverloadToken<Stmt *>())); |
| 2494 | } |
| 2495 | |
| 2496 | const_child_range children() const { |
| 2497 | // We always store a condition, but there is none for consteval if |
| 2498 | // statements, so skip it. |
| 2499 | return const_child_range(getTrailingObjects<Stmt *>() + |
| 2500 | (isConsteval() ? thenOffset() : 0), |
| 2501 | getTrailingObjects<Stmt *>() + |
| 2502 | numTrailingObjects(OverloadToken<Stmt *>())); |
| 2503 | } |
| 2504 | |
| 2505 | static bool classof(const Stmt *T) { |
| 2506 | return T->getStmtClass() == IfStmtClass; |
| 2507 | } |
| 2508 | }; |
| 2509 | |
| 2510 | /// SwitchStmt - This represents a 'switch' stmt. |
| 2511 | class SwitchStmt final : public Stmt, |
| 2512 | private llvm::TrailingObjects<SwitchStmt, Stmt *> { |
| 2513 | friend TrailingObjects; |
| 2514 | |
| 2515 | /// Points to a linked list of case and default statements. |
| 2516 | SwitchCase *FirstCase = nullptr; |
| 2517 | |
| 2518 | // SwitchStmt is followed by several trailing objects, |
| 2519 | // some of which optional. Note that it would be more convenient to |
| 2520 | // put the optional trailing objects at the end but this would change |
| 2521 | // the order in children(). |
| 2522 | // The trailing objects are in order: |
| 2523 | // |
| 2524 | // * A "Stmt *" for the init statement. |
| 2525 | // Present if and only if hasInitStorage(). |
| 2526 | // |
| 2527 | // * A "Stmt *" for the condition variable. |
| 2528 | // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *". |
| 2529 | // |
| 2530 | // * A "Stmt *" for the condition. |
| 2531 | // Always present. This is in fact an "Expr *". |
| 2532 | // |
| 2533 | // * A "Stmt *" for the body. |
| 2534 | // Always present. |
| 2535 | enum { InitOffset = 0, BodyOffsetFromCond = 1 }; |
| 2536 | enum { NumMandatoryStmtPtr = 2 }; |
| 2537 | SourceLocation LParenLoc; |
| 2538 | SourceLocation RParenLoc; |
| 2539 | |
| 2540 | unsigned numTrailingStatements() const { |
| 2541 | return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage(); |
| 2542 | } |
| 2543 | |
| 2544 | unsigned initOffset() const { return InitOffset; } |
| 2545 | unsigned varOffset() const { return InitOffset + hasInitStorage(); } |
| 2546 | unsigned condOffset() const { |
| 2547 | return InitOffset + hasInitStorage() + hasVarStorage(); |
| 2548 | } |
| 2549 | unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; } |
| 2550 | |
| 2551 | /// Build a switch statement. |
| 2552 | SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, |
| 2553 | SourceLocation LParenLoc, SourceLocation RParenLoc); |
| 2554 | |
| 2555 | /// Build a empty switch statement. |
| 2556 | explicit SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar); |
| 2557 | |
| 2558 | public: |
| 2559 | /// Create a switch statement. |
| 2560 | static SwitchStmt *Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, |
| 2561 | Expr *Cond, SourceLocation LParenLoc, |
| 2562 | SourceLocation RParenLoc); |
| 2563 | |
| 2564 | /// Create an empty switch statement optionally with storage for |
| 2565 | /// an init expression and a condition variable. |
| 2566 | static SwitchStmt *CreateEmpty(const ASTContext &Ctx, bool HasInit, |
| 2567 | bool HasVar); |
| 2568 | |
| 2569 | /// True if this SwitchStmt has storage for an init statement. |
| 2570 | bool hasInitStorage() const { return SwitchStmtBits.HasInit; } |
| 2571 | |
| 2572 | /// True if this SwitchStmt has storage for a condition variable. |
| 2573 | bool hasVarStorage() const { return SwitchStmtBits.HasVar; } |
| 2574 | |
| 2575 | Expr *getCond() { |
| 2576 | return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]); |
| 2577 | } |
| 2578 | |
| 2579 | const Expr *getCond() const { |
| 2580 | return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]); |
| 2581 | } |
| 2582 | |
| 2583 | void setCond(Expr *Cond) { |
| 2584 | getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond); |
| 2585 | } |
| 2586 | |
| 2587 | Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; } |
| 2588 | const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; } |
| 2589 | |
| 2590 | void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; } |
| 2591 | |
| 2592 | Stmt *getInit() { |
| 2593 | return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr; |
| 2594 | } |
| 2595 | |
| 2596 | const Stmt *getInit() const { |
| 2597 | return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr; |
| 2598 | } |
| 2599 | |
| 2600 | void setInit(Stmt *Init) { |
| 2601 | assert(hasInitStorage() && |
| 2602 | "This switch statement has no storage for an init statement!" ); |
| 2603 | getTrailingObjects()[initOffset()] = Init; |
| 2604 | } |
| 2605 | |
| 2606 | /// Retrieve the variable declared in this "switch" statement, if any. |
| 2607 | /// |
| 2608 | /// In the following example, "x" is the condition variable. |
| 2609 | /// \code |
| 2610 | /// switch (int x = foo()) { |
| 2611 | /// case 0: break; |
| 2612 | /// // ... |
| 2613 | /// } |
| 2614 | /// \endcode |
| 2615 | VarDecl *getConditionVariable(); |
| 2616 | const VarDecl *getConditionVariable() const { |
| 2617 | return const_cast<SwitchStmt *>(this)->getConditionVariable(); |
| 2618 | } |
| 2619 | |
| 2620 | /// Set the condition variable in this switch statement. |
| 2621 | /// The switch statement must have storage for it. |
| 2622 | void setConditionVariable(const ASTContext &Ctx, VarDecl *VD); |
| 2623 | |
| 2624 | /// If this SwitchStmt has a condition variable, return the faux DeclStmt |
| 2625 | /// associated with the creation of that condition variable. |
| 2626 | DeclStmt *getConditionVariableDeclStmt() { |
| 2627 | return hasVarStorage() |
| 2628 | ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()]) |
| 2629 | : nullptr; |
| 2630 | } |
| 2631 | |
| 2632 | const DeclStmt *getConditionVariableDeclStmt() const { |
| 2633 | return hasVarStorage() |
| 2634 | ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()]) |
| 2635 | : nullptr; |
| 2636 | } |
| 2637 | |
| 2638 | void setConditionVariableDeclStmt(DeclStmt *CondVar) { |
| 2639 | assert(hasVarStorage()); |
| 2640 | getTrailingObjects()[varOffset()] = CondVar; |
| 2641 | } |
| 2642 | |
| 2643 | SwitchCase *getSwitchCaseList() { return FirstCase; } |
| 2644 | const SwitchCase *getSwitchCaseList() const { return FirstCase; } |
| 2645 | void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } |
| 2646 | |
| 2647 | SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; } |
| 2648 | void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; } |
| 2649 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 2650 | void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } |
| 2651 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 2652 | void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; } |
| 2653 | |
| 2654 | void setBody(Stmt *S, SourceLocation SL) { |
| 2655 | setBody(S); |
| 2656 | setSwitchLoc(SL); |
| 2657 | } |
| 2658 | |
| 2659 | void addSwitchCase(SwitchCase *SC) { |
| 2660 | assert(!SC->getNextSwitchCase() && |
| 2661 | "case/default already added to a switch" ); |
| 2662 | SC->setNextSwitchCase(FirstCase); |
| 2663 | FirstCase = SC; |
| 2664 | } |
| 2665 | |
| 2666 | /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a |
| 2667 | /// switch over an enum value then all cases have been explicitly covered. |
| 2668 | void setAllEnumCasesCovered() { SwitchStmtBits.AllEnumCasesCovered = true; } |
| 2669 | |
| 2670 | /// Returns true if the SwitchStmt is a switch of an enum value and all cases |
| 2671 | /// have been explicitly covered. |
| 2672 | bool isAllEnumCasesCovered() const { |
| 2673 | return SwitchStmtBits.AllEnumCasesCovered; |
| 2674 | } |
| 2675 | |
| 2676 | SourceLocation getBeginLoc() const { return getSwitchLoc(); } |
| 2677 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 2678 | return getBody() ? getBody()->getEndLoc() |
| 2679 | : reinterpret_cast<const Stmt *>(getCond())->getEndLoc(); |
| 2680 | } |
| 2681 | |
| 2682 | // Iterators |
| 2683 | child_range children() { |
| 2684 | return child_range(getTrailingObjects(), |
| 2685 | getTrailingObjects() + numTrailingStatements()); |
| 2686 | } |
| 2687 | |
| 2688 | const_child_range children() const { |
| 2689 | return const_child_range(getTrailingObjects(), |
| 2690 | getTrailingObjects() + numTrailingStatements()); |
| 2691 | } |
| 2692 | |
| 2693 | static bool classof(const Stmt *T) { |
| 2694 | return T->getStmtClass() == SwitchStmtClass; |
| 2695 | } |
| 2696 | }; |
| 2697 | |
| 2698 | /// WhileStmt - This represents a 'while' stmt. |
| 2699 | class WhileStmt final : public Stmt, |
| 2700 | private llvm::TrailingObjects<WhileStmt, Stmt *> { |
| 2701 | friend TrailingObjects; |
| 2702 | |
| 2703 | // WhileStmt is followed by several trailing objects, |
| 2704 | // some of which optional. Note that it would be more |
| 2705 | // convenient to put the optional trailing object at the end |
| 2706 | // but this would affect children(). |
| 2707 | // The trailing objects are in order: |
| 2708 | // |
| 2709 | // * A "Stmt *" for the condition variable. |
| 2710 | // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *". |
| 2711 | // |
| 2712 | // * A "Stmt *" for the condition. |
| 2713 | // Always present. This is in fact an "Expr *". |
| 2714 | // |
| 2715 | // * A "Stmt *" for the body. |
| 2716 | // Always present. |
| 2717 | // |
| 2718 | enum { VarOffset = 0, BodyOffsetFromCond = 1 }; |
| 2719 | enum { NumMandatoryStmtPtr = 2 }; |
| 2720 | |
| 2721 | SourceLocation LParenLoc, RParenLoc; |
| 2722 | |
| 2723 | unsigned varOffset() const { return VarOffset; } |
| 2724 | unsigned condOffset() const { return VarOffset + hasVarStorage(); } |
| 2725 | unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; } |
| 2726 | |
| 2727 | unsigned numTrailingStatements() const { |
| 2728 | return NumMandatoryStmtPtr + hasVarStorage(); |
| 2729 | } |
| 2730 | |
| 2731 | /// Build a while statement. |
| 2732 | WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, |
| 2733 | SourceLocation WL, SourceLocation LParenLoc, |
| 2734 | SourceLocation RParenLoc); |
| 2735 | |
| 2736 | /// Build an empty while statement. |
| 2737 | explicit WhileStmt(EmptyShell Empty, bool HasVar); |
| 2738 | |
| 2739 | public: |
| 2740 | /// Create a while statement. |
| 2741 | static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, |
| 2742 | Stmt *Body, SourceLocation WL, |
| 2743 | SourceLocation LParenLoc, SourceLocation RParenLoc); |
| 2744 | |
| 2745 | /// Create an empty while statement optionally with storage for |
| 2746 | /// a condition variable. |
| 2747 | static WhileStmt *CreateEmpty(const ASTContext &Ctx, bool HasVar); |
| 2748 | |
| 2749 | /// True if this WhileStmt has storage for a condition variable. |
| 2750 | bool hasVarStorage() const { return WhileStmtBits.HasVar; } |
| 2751 | |
| 2752 | Expr *getCond() { |
| 2753 | return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]); |
| 2754 | } |
| 2755 | |
| 2756 | const Expr *getCond() const { |
| 2757 | return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]); |
| 2758 | } |
| 2759 | |
| 2760 | void setCond(Expr *Cond) { |
| 2761 | getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond); |
| 2762 | } |
| 2763 | |
| 2764 | Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; } |
| 2765 | const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; } |
| 2766 | |
| 2767 | void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; } |
| 2768 | |
| 2769 | /// Retrieve the variable declared in this "while" statement, if any. |
| 2770 | /// |
| 2771 | /// In the following example, "x" is the condition variable. |
| 2772 | /// \code |
| 2773 | /// while (int x = random()) { |
| 2774 | /// // ... |
| 2775 | /// } |
| 2776 | /// \endcode |
| 2777 | VarDecl *getConditionVariable(); |
| 2778 | const VarDecl *getConditionVariable() const { |
| 2779 | return const_cast<WhileStmt *>(this)->getConditionVariable(); |
| 2780 | } |
| 2781 | |
| 2782 | /// Set the condition variable of this while statement. |
| 2783 | /// The while statement must have storage for it. |
| 2784 | void setConditionVariable(const ASTContext &Ctx, VarDecl *V); |
| 2785 | |
| 2786 | /// If this WhileStmt has a condition variable, return the faux DeclStmt |
| 2787 | /// associated with the creation of that condition variable. |
| 2788 | DeclStmt *getConditionVariableDeclStmt() { |
| 2789 | return hasVarStorage() |
| 2790 | ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()]) |
| 2791 | : nullptr; |
| 2792 | } |
| 2793 | |
| 2794 | const DeclStmt *getConditionVariableDeclStmt() const { |
| 2795 | return hasVarStorage() |
| 2796 | ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()]) |
| 2797 | : nullptr; |
| 2798 | } |
| 2799 | |
| 2800 | void setConditionVariableDeclStmt(DeclStmt *CondVar) { |
| 2801 | assert(hasVarStorage()); |
| 2802 | getTrailingObjects()[varOffset()] = CondVar; |
| 2803 | } |
| 2804 | |
| 2805 | SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; } |
| 2806 | void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; } |
| 2807 | |
| 2808 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 2809 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
| 2810 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 2811 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
| 2812 | |
| 2813 | SourceLocation getBeginLoc() const { return getWhileLoc(); } |
| 2814 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 2815 | return getBody()->getEndLoc(); |
| 2816 | } |
| 2817 | |
| 2818 | static bool classof(const Stmt *T) { |
| 2819 | return T->getStmtClass() == WhileStmtClass; |
| 2820 | } |
| 2821 | |
| 2822 | // Iterators |
| 2823 | child_range children() { |
| 2824 | return child_range(getTrailingObjects(), |
| 2825 | getTrailingObjects() + numTrailingStatements()); |
| 2826 | } |
| 2827 | |
| 2828 | const_child_range children() const { |
| 2829 | return const_child_range(getTrailingObjects(), |
| 2830 | getTrailingObjects() + numTrailingStatements()); |
| 2831 | } |
| 2832 | }; |
| 2833 | |
| 2834 | /// DoStmt - This represents a 'do/while' stmt. |
| 2835 | class DoStmt : public Stmt { |
| 2836 | enum { BODY, COND, END_EXPR }; |
| 2837 | Stmt *SubExprs[END_EXPR]; |
| 2838 | SourceLocation WhileLoc; |
| 2839 | SourceLocation RParenLoc; // Location of final ')' in do stmt condition. |
| 2840 | |
| 2841 | public: |
| 2842 | DoStmt(Stmt *Body, Expr *Cond, SourceLocation DL, SourceLocation WL, |
| 2843 | SourceLocation RP) |
| 2844 | : Stmt(DoStmtClass), WhileLoc(WL), RParenLoc(RP) { |
| 2845 | setCond(Cond); |
| 2846 | setBody(Body); |
| 2847 | setDoLoc(DL); |
| 2848 | } |
| 2849 | |
| 2850 | /// Build an empty do-while statement. |
| 2851 | explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {} |
| 2852 | |
| 2853 | Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); } |
| 2854 | const Expr *getCond() const { |
| 2855 | return reinterpret_cast<Expr *>(SubExprs[COND]); |
| 2856 | } |
| 2857 | |
| 2858 | void setCond(Expr *Cond) { SubExprs[COND] = reinterpret_cast<Stmt *>(Cond); } |
| 2859 | |
| 2860 | Stmt *getBody() { return SubExprs[BODY]; } |
| 2861 | const Stmt *getBody() const { return SubExprs[BODY]; } |
| 2862 | void setBody(Stmt *Body) { SubExprs[BODY] = Body; } |
| 2863 | |
| 2864 | SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; } |
| 2865 | void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; } |
| 2866 | SourceLocation getWhileLoc() const { return WhileLoc; } |
| 2867 | void setWhileLoc(SourceLocation L) { WhileLoc = L; } |
| 2868 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 2869 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
| 2870 | |
| 2871 | SourceLocation getBeginLoc() const { return getDoLoc(); } |
| 2872 | SourceLocation getEndLoc() const { return getRParenLoc(); } |
| 2873 | |
| 2874 | static bool classof(const Stmt *T) { |
| 2875 | return T->getStmtClass() == DoStmtClass; |
| 2876 | } |
| 2877 | |
| 2878 | // Iterators |
| 2879 | child_range children() { |
| 2880 | return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
| 2881 | } |
| 2882 | |
| 2883 | const_child_range children() const { |
| 2884 | return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
| 2885 | } |
| 2886 | }; |
| 2887 | |
| 2888 | /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of |
| 2889 | /// the init/cond/inc parts of the ForStmt will be null if they were not |
| 2890 | /// specified in the source. |
| 2891 | class ForStmt : public Stmt { |
| 2892 | friend class ASTStmtReader; |
| 2893 | |
| 2894 | enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; |
| 2895 | Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. |
| 2896 | SourceLocation LParenLoc, RParenLoc; |
| 2897 | |
| 2898 | public: |
| 2899 | ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, |
| 2900 | Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, |
| 2901 | SourceLocation RP); |
| 2902 | |
| 2903 | /// Build an empty for statement. |
| 2904 | explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {} |
| 2905 | |
| 2906 | Stmt *getInit() { return SubExprs[INIT]; } |
| 2907 | |
| 2908 | /// Retrieve the variable declared in this "for" statement, if any. |
| 2909 | /// |
| 2910 | /// In the following example, "y" is the condition variable. |
| 2911 | /// \code |
| 2912 | /// for (int x = random(); int y = mangle(x); ++x) { |
| 2913 | /// // ... |
| 2914 | /// } |
| 2915 | /// \endcode |
| 2916 | VarDecl *getConditionVariable() const; |
| 2917 | void setConditionVariable(const ASTContext &C, VarDecl *V); |
| 2918 | |
| 2919 | /// If this ForStmt has a condition variable, return the faux DeclStmt |
| 2920 | /// associated with the creation of that condition variable. |
| 2921 | DeclStmt *getConditionVariableDeclStmt() { |
| 2922 | return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); |
| 2923 | } |
| 2924 | |
| 2925 | const DeclStmt *getConditionVariableDeclStmt() const { |
| 2926 | return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); |
| 2927 | } |
| 2928 | |
| 2929 | void setConditionVariableDeclStmt(DeclStmt *CondVar) { |
| 2930 | SubExprs[CONDVAR] = CondVar; |
| 2931 | } |
| 2932 | |
| 2933 | Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } |
| 2934 | Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } |
| 2935 | Stmt *getBody() { return SubExprs[BODY]; } |
| 2936 | |
| 2937 | const Stmt *getInit() const { return SubExprs[INIT]; } |
| 2938 | const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} |
| 2939 | const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } |
| 2940 | const Stmt *getBody() const { return SubExprs[BODY]; } |
| 2941 | |
| 2942 | void setInit(Stmt *S) { SubExprs[INIT] = S; } |
| 2943 | void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } |
| 2944 | void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } |
| 2945 | void setBody(Stmt *S) { SubExprs[BODY] = S; } |
| 2946 | |
| 2947 | SourceLocation getForLoc() const { return ForStmtBits.ForLoc; } |
| 2948 | void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; } |
| 2949 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 2950 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
| 2951 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 2952 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
| 2953 | |
| 2954 | SourceLocation getBeginLoc() const { return getForLoc(); } |
| 2955 | SourceLocation getEndLoc() const { return getBody()->getEndLoc(); } |
| 2956 | |
| 2957 | static bool classof(const Stmt *T) { |
| 2958 | return T->getStmtClass() == ForStmtClass; |
| 2959 | } |
| 2960 | |
| 2961 | // Iterators |
| 2962 | child_range children() { |
| 2963 | return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); |
| 2964 | } |
| 2965 | |
| 2966 | const_child_range children() const { |
| 2967 | return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR); |
| 2968 | } |
| 2969 | }; |
| 2970 | |
| 2971 | /// GotoStmt - This represents a direct goto. |
| 2972 | class GotoStmt : public Stmt { |
| 2973 | LabelDecl *Label; |
| 2974 | SourceLocation LabelLoc; |
| 2975 | |
| 2976 | public: |
| 2977 | GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL) |
| 2978 | : Stmt(GotoStmtClass), Label(label), LabelLoc(LL) { |
| 2979 | setGotoLoc(GL); |
| 2980 | } |
| 2981 | |
| 2982 | /// Build an empty goto statement. |
| 2983 | explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {} |
| 2984 | |
| 2985 | LabelDecl *getLabel() const { return Label; } |
| 2986 | void setLabel(LabelDecl *D) { Label = D; } |
| 2987 | |
| 2988 | SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; } |
| 2989 | void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; } |
| 2990 | SourceLocation getLabelLoc() const { return LabelLoc; } |
| 2991 | void setLabelLoc(SourceLocation L) { LabelLoc = L; } |
| 2992 | |
| 2993 | SourceLocation getBeginLoc() const { return getGotoLoc(); } |
| 2994 | SourceLocation getEndLoc() const { return getLabelLoc(); } |
| 2995 | |
| 2996 | static bool classof(const Stmt *T) { |
| 2997 | return T->getStmtClass() == GotoStmtClass; |
| 2998 | } |
| 2999 | |
| 3000 | // Iterators |
| 3001 | child_range children() { |
| 3002 | return child_range(child_iterator(), child_iterator()); |
| 3003 | } |
| 3004 | |
| 3005 | const_child_range children() const { |
| 3006 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3007 | } |
| 3008 | }; |
| 3009 | |
| 3010 | /// IndirectGotoStmt - This represents an indirect goto. |
| 3011 | class IndirectGotoStmt : public Stmt { |
| 3012 | SourceLocation StarLoc; |
| 3013 | Stmt *Target; |
| 3014 | |
| 3015 | public: |
| 3016 | IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, Expr *target) |
| 3017 | : Stmt(IndirectGotoStmtClass), StarLoc(starLoc) { |
| 3018 | setTarget(target); |
| 3019 | setGotoLoc(gotoLoc); |
| 3020 | } |
| 3021 | |
| 3022 | /// Build an empty indirect goto statement. |
| 3023 | explicit IndirectGotoStmt(EmptyShell Empty) |
| 3024 | : Stmt(IndirectGotoStmtClass, Empty) {} |
| 3025 | |
| 3026 | void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; } |
| 3027 | SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; } |
| 3028 | void setStarLoc(SourceLocation L) { StarLoc = L; } |
| 3029 | SourceLocation getStarLoc() const { return StarLoc; } |
| 3030 | |
| 3031 | Expr *getTarget() { return reinterpret_cast<Expr *>(Target); } |
| 3032 | const Expr *getTarget() const { |
| 3033 | return reinterpret_cast<const Expr *>(Target); |
| 3034 | } |
| 3035 | void setTarget(Expr *E) { Target = reinterpret_cast<Stmt *>(E); } |
| 3036 | |
| 3037 | /// getConstantTarget - Returns the fixed target of this indirect |
| 3038 | /// goto, if one exists. |
| 3039 | LabelDecl *getConstantTarget(); |
| 3040 | const LabelDecl *getConstantTarget() const { |
| 3041 | return const_cast<IndirectGotoStmt *>(this)->getConstantTarget(); |
| 3042 | } |
| 3043 | |
| 3044 | SourceLocation getBeginLoc() const { return getGotoLoc(); } |
| 3045 | SourceLocation getEndLoc() const LLVM_READONLY { return Target->getEndLoc(); } |
| 3046 | |
| 3047 | static bool classof(const Stmt *T) { |
| 3048 | return T->getStmtClass() == IndirectGotoStmtClass; |
| 3049 | } |
| 3050 | |
| 3051 | // Iterators |
| 3052 | child_range children() { return child_range(&Target, &Target + 1); } |
| 3053 | |
| 3054 | const_child_range children() const { |
| 3055 | return const_child_range(&Target, &Target + 1); |
| 3056 | } |
| 3057 | }; |
| 3058 | |
| 3059 | /// ContinueStmt - This represents a continue. |
| 3060 | class ContinueStmt : public Stmt { |
| 3061 | public: |
| 3062 | ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass) { |
| 3063 | setContinueLoc(CL); |
| 3064 | } |
| 3065 | |
| 3066 | /// Build an empty continue statement. |
| 3067 | explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) {} |
| 3068 | |
| 3069 | SourceLocation getContinueLoc() const { return ContinueStmtBits.ContinueLoc; } |
| 3070 | void setContinueLoc(SourceLocation L) { ContinueStmtBits.ContinueLoc = L; } |
| 3071 | |
| 3072 | SourceLocation getBeginLoc() const { return getContinueLoc(); } |
| 3073 | SourceLocation getEndLoc() const { return getContinueLoc(); } |
| 3074 | |
| 3075 | static bool classof(const Stmt *T) { |
| 3076 | return T->getStmtClass() == ContinueStmtClass; |
| 3077 | } |
| 3078 | |
| 3079 | // Iterators |
| 3080 | child_range children() { |
| 3081 | return child_range(child_iterator(), child_iterator()); |
| 3082 | } |
| 3083 | |
| 3084 | const_child_range children() const { |
| 3085 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3086 | } |
| 3087 | }; |
| 3088 | |
| 3089 | /// BreakStmt - This represents a break. |
| 3090 | class BreakStmt : public Stmt { |
| 3091 | public: |
| 3092 | BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass) { |
| 3093 | setBreakLoc(BL); |
| 3094 | } |
| 3095 | |
| 3096 | /// Build an empty break statement. |
| 3097 | explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) {} |
| 3098 | |
| 3099 | SourceLocation getBreakLoc() const { return BreakStmtBits.BreakLoc; } |
| 3100 | void setBreakLoc(SourceLocation L) { BreakStmtBits.BreakLoc = L; } |
| 3101 | |
| 3102 | SourceLocation getBeginLoc() const { return getBreakLoc(); } |
| 3103 | SourceLocation getEndLoc() const { return getBreakLoc(); } |
| 3104 | |
| 3105 | static bool classof(const Stmt *T) { |
| 3106 | return T->getStmtClass() == BreakStmtClass; |
| 3107 | } |
| 3108 | |
| 3109 | // Iterators |
| 3110 | child_range children() { |
| 3111 | return child_range(child_iterator(), child_iterator()); |
| 3112 | } |
| 3113 | |
| 3114 | const_child_range children() const { |
| 3115 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3116 | } |
| 3117 | }; |
| 3118 | |
| 3119 | /// ReturnStmt - This represents a return, optionally of an expression: |
| 3120 | /// return; |
| 3121 | /// return 4; |
| 3122 | /// |
| 3123 | /// Note that GCC allows return with no argument in a function declared to |
| 3124 | /// return a value, and it allows returning a value in functions declared to |
| 3125 | /// return void. We explicitly model this in the AST, which means you can't |
| 3126 | /// depend on the return type of the function and the presence of an argument. |
| 3127 | class ReturnStmt final |
| 3128 | : public Stmt, |
| 3129 | private llvm::TrailingObjects<ReturnStmt, const VarDecl *> { |
| 3130 | friend TrailingObjects; |
| 3131 | |
| 3132 | /// The return expression. |
| 3133 | Stmt *RetExpr; |
| 3134 | |
| 3135 | // ReturnStmt is followed optionally by a trailing "const VarDecl *" |
| 3136 | // for the NRVO candidate. Present if and only if hasNRVOCandidate(). |
| 3137 | |
| 3138 | /// True if this ReturnStmt has storage for an NRVO candidate. |
| 3139 | bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; } |
| 3140 | |
| 3141 | /// Build a return statement. |
| 3142 | ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate); |
| 3143 | |
| 3144 | /// Build an empty return statement. |
| 3145 | explicit ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate); |
| 3146 | |
| 3147 | public: |
| 3148 | /// Create a return statement. |
| 3149 | static ReturnStmt *Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, |
| 3150 | const VarDecl *NRVOCandidate); |
| 3151 | |
| 3152 | /// Create an empty return statement, optionally with |
| 3153 | /// storage for an NRVO candidate. |
| 3154 | static ReturnStmt *CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate); |
| 3155 | |
| 3156 | Expr *getRetValue() { return reinterpret_cast<Expr *>(RetExpr); } |
| 3157 | const Expr *getRetValue() const { return reinterpret_cast<Expr *>(RetExpr); } |
| 3158 | void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt *>(E); } |
| 3159 | |
| 3160 | /// Retrieve the variable that might be used for the named return |
| 3161 | /// value optimization. |
| 3162 | /// |
| 3163 | /// The optimization itself can only be performed if the variable is |
| 3164 | /// also marked as an NRVO object. |
| 3165 | const VarDecl *getNRVOCandidate() const { |
| 3166 | return hasNRVOCandidate() ? *getTrailingObjects() : nullptr; |
| 3167 | } |
| 3168 | |
| 3169 | /// Set the variable that might be used for the named return value |
| 3170 | /// optimization. The return statement must have storage for it, |
| 3171 | /// which is the case if and only if hasNRVOCandidate() is true. |
| 3172 | void setNRVOCandidate(const VarDecl *Var) { |
| 3173 | assert(hasNRVOCandidate() && |
| 3174 | "This return statement has no storage for an NRVO candidate!" ); |
| 3175 | *getTrailingObjects() = Var; |
| 3176 | } |
| 3177 | |
| 3178 | SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; } |
| 3179 | void setReturnLoc(SourceLocation L) { ReturnStmtBits.RetLoc = L; } |
| 3180 | |
| 3181 | SourceLocation getBeginLoc() const { return getReturnLoc(); } |
| 3182 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 3183 | return RetExpr ? RetExpr->getEndLoc() : getReturnLoc(); |
| 3184 | } |
| 3185 | |
| 3186 | static bool classof(const Stmt *T) { |
| 3187 | return T->getStmtClass() == ReturnStmtClass; |
| 3188 | } |
| 3189 | |
| 3190 | // Iterators |
| 3191 | child_range children() { |
| 3192 | if (RetExpr) |
| 3193 | return child_range(&RetExpr, &RetExpr + 1); |
| 3194 | return child_range(child_iterator(), child_iterator()); |
| 3195 | } |
| 3196 | |
| 3197 | const_child_range children() const { |
| 3198 | if (RetExpr) |
| 3199 | return const_child_range(&RetExpr, &RetExpr + 1); |
| 3200 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3201 | } |
| 3202 | }; |
| 3203 | |
| 3204 | /// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt. |
| 3205 | class AsmStmt : public Stmt { |
| 3206 | protected: |
| 3207 | friend class ASTStmtReader; |
| 3208 | |
| 3209 | SourceLocation AsmLoc; |
| 3210 | |
| 3211 | /// True if the assembly statement does not have any input or output |
| 3212 | /// operands. |
| 3213 | bool IsSimple; |
| 3214 | |
| 3215 | /// If true, treat this inline assembly as having side effects. |
| 3216 | /// This assembly statement should not be optimized, deleted or moved. |
| 3217 | bool IsVolatile; |
| 3218 | |
| 3219 | unsigned NumOutputs; |
| 3220 | unsigned NumInputs; |
| 3221 | unsigned NumClobbers; |
| 3222 | |
| 3223 | Stmt **Exprs = nullptr; |
| 3224 | |
| 3225 | AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile, |
| 3226 | unsigned numoutputs, unsigned numinputs, unsigned numclobbers) |
| 3227 | : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile), |
| 3228 | NumOutputs(numoutputs), NumInputs(numinputs), |
| 3229 | NumClobbers(numclobbers) {} |
| 3230 | |
| 3231 | public: |
| 3232 | /// Build an empty inline-assembly statement. |
| 3233 | explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {} |
| 3234 | |
| 3235 | SourceLocation getAsmLoc() const { return AsmLoc; } |
| 3236 | void setAsmLoc(SourceLocation L) { AsmLoc = L; } |
| 3237 | |
| 3238 | bool isSimple() const { return IsSimple; } |
| 3239 | void setSimple(bool V) { IsSimple = V; } |
| 3240 | |
| 3241 | bool isVolatile() const { return IsVolatile; } |
| 3242 | void setVolatile(bool V) { IsVolatile = V; } |
| 3243 | |
| 3244 | SourceLocation getBeginLoc() const LLVM_READONLY { return {}; } |
| 3245 | SourceLocation getEndLoc() const LLVM_READONLY { return {}; } |
| 3246 | |
| 3247 | //===--- Asm String Analysis ---===// |
| 3248 | |
| 3249 | /// Assemble final IR asm string. |
| 3250 | std::string generateAsmString(const ASTContext &C) const; |
| 3251 | |
| 3252 | //===--- Output operands ---===// |
| 3253 | |
| 3254 | unsigned getNumOutputs() const { return NumOutputs; } |
| 3255 | |
| 3256 | /// getOutputConstraint - Return the constraint string for the specified |
| 3257 | /// output operand. All output constraints are known to be non-empty (either |
| 3258 | /// '=' or '+'). |
| 3259 | std::string getOutputConstraint(unsigned i) const; |
| 3260 | |
| 3261 | /// isOutputPlusConstraint - Return true if the specified output constraint |
| 3262 | /// is a "+" constraint (which is both an input and an output) or false if it |
| 3263 | /// is an "=" constraint (just an output). |
| 3264 | bool isOutputPlusConstraint(unsigned i) const { |
| 3265 | return getOutputConstraint(i)[0] == '+'; |
| 3266 | } |
| 3267 | |
| 3268 | const Expr *getOutputExpr(unsigned i) const; |
| 3269 | |
| 3270 | /// getNumPlusOperands - Return the number of output operands that have a "+" |
| 3271 | /// constraint. |
| 3272 | unsigned getNumPlusOperands() const; |
| 3273 | |
| 3274 | //===--- Input operands ---===// |
| 3275 | |
| 3276 | unsigned getNumInputs() const { return NumInputs; } |
| 3277 | |
| 3278 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 3279 | /// constraints, these can be empty. |
| 3280 | std::string getInputConstraint(unsigned i) const; |
| 3281 | |
| 3282 | const Expr *getInputExpr(unsigned i) const; |
| 3283 | |
| 3284 | //===--- Other ---===// |
| 3285 | |
| 3286 | unsigned getNumClobbers() const { return NumClobbers; } |
| 3287 | std::string getClobber(unsigned i) const; |
| 3288 | |
| 3289 | static bool classof(const Stmt *T) { |
| 3290 | return T->getStmtClass() == GCCAsmStmtClass || |
| 3291 | T->getStmtClass() == MSAsmStmtClass; |
| 3292 | } |
| 3293 | |
| 3294 | // Input expr iterators. |
| 3295 | |
| 3296 | using inputs_iterator = ExprIterator; |
| 3297 | using const_inputs_iterator = ConstExprIterator; |
| 3298 | using inputs_range = llvm::iterator_range<inputs_iterator>; |
| 3299 | using inputs_const_range = llvm::iterator_range<const_inputs_iterator>; |
| 3300 | |
| 3301 | inputs_iterator begin_inputs() { |
| 3302 | return &Exprs[0] + NumOutputs; |
| 3303 | } |
| 3304 | |
| 3305 | inputs_iterator end_inputs() { |
| 3306 | return &Exprs[0] + NumOutputs + NumInputs; |
| 3307 | } |
| 3308 | |
| 3309 | inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); } |
| 3310 | |
| 3311 | const_inputs_iterator begin_inputs() const { |
| 3312 | return &Exprs[0] + NumOutputs; |
| 3313 | } |
| 3314 | |
| 3315 | const_inputs_iterator end_inputs() const { |
| 3316 | return &Exprs[0] + NumOutputs + NumInputs; |
| 3317 | } |
| 3318 | |
| 3319 | inputs_const_range inputs() const { |
| 3320 | return inputs_const_range(begin_inputs(), end_inputs()); |
| 3321 | } |
| 3322 | |
| 3323 | // Output expr iterators. |
| 3324 | |
| 3325 | using outputs_iterator = ExprIterator; |
| 3326 | using const_outputs_iterator = ConstExprIterator; |
| 3327 | using outputs_range = llvm::iterator_range<outputs_iterator>; |
| 3328 | using outputs_const_range = llvm::iterator_range<const_outputs_iterator>; |
| 3329 | |
| 3330 | outputs_iterator begin_outputs() { |
| 3331 | return &Exprs[0]; |
| 3332 | } |
| 3333 | |
| 3334 | outputs_iterator end_outputs() { |
| 3335 | return &Exprs[0] + NumOutputs; |
| 3336 | } |
| 3337 | |
| 3338 | outputs_range outputs() { |
| 3339 | return outputs_range(begin_outputs(), end_outputs()); |
| 3340 | } |
| 3341 | |
| 3342 | const_outputs_iterator begin_outputs() const { |
| 3343 | return &Exprs[0]; |
| 3344 | } |
| 3345 | |
| 3346 | const_outputs_iterator end_outputs() const { |
| 3347 | return &Exprs[0] + NumOutputs; |
| 3348 | } |
| 3349 | |
| 3350 | outputs_const_range outputs() const { |
| 3351 | return outputs_const_range(begin_outputs(), end_outputs()); |
| 3352 | } |
| 3353 | |
| 3354 | child_range children() { |
| 3355 | return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); |
| 3356 | } |
| 3357 | |
| 3358 | const_child_range children() const { |
| 3359 | return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); |
| 3360 | } |
| 3361 | }; |
| 3362 | |
| 3363 | /// This represents a GCC inline-assembly statement extension. |
| 3364 | class GCCAsmStmt : public AsmStmt { |
| 3365 | friend class ASTStmtReader; |
| 3366 | |
| 3367 | SourceLocation RParenLoc; |
| 3368 | Expr *AsmStr; |
| 3369 | |
| 3370 | // FIXME: If we wanted to, we could allocate all of these in one big array. |
| 3371 | Expr **Constraints = nullptr; |
| 3372 | Expr **Clobbers = nullptr; |
| 3373 | IdentifierInfo **Names = nullptr; |
| 3374 | unsigned NumLabels = 0; |
| 3375 | |
| 3376 | public: |
| 3377 | GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, |
| 3378 | bool isvolatile, unsigned numoutputs, unsigned numinputs, |
| 3379 | IdentifierInfo **names, Expr **constraints, Expr **exprs, |
| 3380 | Expr *asmstr, unsigned numclobbers, Expr **clobbers, |
| 3381 | unsigned numlabels, SourceLocation rparenloc); |
| 3382 | |
| 3383 | /// Build an empty inline-assembly statement. |
| 3384 | explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {} |
| 3385 | |
| 3386 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 3387 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
| 3388 | |
| 3389 | //===--- Asm String Analysis ---===// |
| 3390 | |
| 3391 | const Expr *getAsmStringExpr() const { return AsmStr; } |
| 3392 | Expr *getAsmStringExpr() { return AsmStr; } |
| 3393 | void setAsmStringExpr(Expr *E) { AsmStr = E; } |
| 3394 | |
| 3395 | std::string getAsmString() const; |
| 3396 | |
| 3397 | /// AsmStringPiece - this is part of a decomposed asm string specification |
| 3398 | /// (for use with the AnalyzeAsmString function below). An asm string is |
| 3399 | /// considered to be a concatenation of these parts. |
| 3400 | class AsmStringPiece { |
| 3401 | public: |
| 3402 | enum Kind { |
| 3403 | String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". |
| 3404 | Operand // Operand reference, with optional modifier %c4. |
| 3405 | }; |
| 3406 | |
| 3407 | private: |
| 3408 | Kind MyKind; |
| 3409 | std::string Str; |
| 3410 | unsigned OperandNo; |
| 3411 | |
| 3412 | // Source range for operand references. |
| 3413 | CharSourceRange Range; |
| 3414 | |
| 3415 | public: |
| 3416 | AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} |
| 3417 | AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin, |
| 3418 | SourceLocation End) |
| 3419 | : MyKind(Operand), Str(S), OperandNo(OpNo), |
| 3420 | Range(CharSourceRange::getCharRange(B: Begin, E: End)) {} |
| 3421 | |
| 3422 | bool isString() const { return MyKind == String; } |
| 3423 | bool isOperand() const { return MyKind == Operand; } |
| 3424 | |
| 3425 | const std::string &getString() const { return Str; } |
| 3426 | |
| 3427 | unsigned getOperandNo() const { |
| 3428 | assert(isOperand()); |
| 3429 | return OperandNo; |
| 3430 | } |
| 3431 | |
| 3432 | CharSourceRange getRange() const { |
| 3433 | assert(isOperand() && "Range is currently used only for Operands." ); |
| 3434 | return Range; |
| 3435 | } |
| 3436 | |
| 3437 | /// getModifier - Get the modifier for this operand, if present. This |
| 3438 | /// returns '\0' if there was no modifier. |
| 3439 | char getModifier() const; |
| 3440 | }; |
| 3441 | |
| 3442 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 3443 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 3444 | /// true, otherwise return false. This handles canonicalization and |
| 3445 | /// translation of strings from GCC syntax to LLVM IR syntax, and handles |
| 3446 | //// flattening of named references like %[foo] to Operand AsmStringPiece's. |
| 3447 | unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces, |
| 3448 | const ASTContext &C, unsigned &DiagOffs) const; |
| 3449 | |
| 3450 | /// Assemble final IR asm string. |
| 3451 | std::string generateAsmString(const ASTContext &C) const; |
| 3452 | |
| 3453 | //===--- Output operands ---===// |
| 3454 | |
| 3455 | IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; } |
| 3456 | |
| 3457 | StringRef getOutputName(unsigned i) const { |
| 3458 | if (IdentifierInfo *II = getOutputIdentifier(i)) |
| 3459 | return II->getName(); |
| 3460 | |
| 3461 | return {}; |
| 3462 | } |
| 3463 | |
| 3464 | std::string getOutputConstraint(unsigned i) const; |
| 3465 | |
| 3466 | const Expr *getOutputConstraintExpr(unsigned i) const { |
| 3467 | return Constraints[i]; |
| 3468 | } |
| 3469 | Expr *getOutputConstraintExpr(unsigned i) { return Constraints[i]; } |
| 3470 | |
| 3471 | Expr *getOutputExpr(unsigned i); |
| 3472 | |
| 3473 | const Expr *getOutputExpr(unsigned i) const { |
| 3474 | return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i); |
| 3475 | } |
| 3476 | |
| 3477 | //===--- Input operands ---===// |
| 3478 | |
| 3479 | IdentifierInfo *getInputIdentifier(unsigned i) const { |
| 3480 | return Names[i + NumOutputs]; |
| 3481 | } |
| 3482 | |
| 3483 | StringRef getInputName(unsigned i) const { |
| 3484 | if (IdentifierInfo *II = getInputIdentifier(i)) |
| 3485 | return II->getName(); |
| 3486 | |
| 3487 | return {}; |
| 3488 | } |
| 3489 | |
| 3490 | std::string getInputConstraint(unsigned i) const; |
| 3491 | |
| 3492 | const Expr *getInputConstraintExpr(unsigned i) const { |
| 3493 | return Constraints[i + NumOutputs]; |
| 3494 | } |
| 3495 | Expr *getInputConstraintExpr(unsigned i) { |
| 3496 | return Constraints[i + NumOutputs]; |
| 3497 | } |
| 3498 | |
| 3499 | Expr *getInputExpr(unsigned i); |
| 3500 | void setInputExpr(unsigned i, Expr *E); |
| 3501 | |
| 3502 | const Expr *getInputExpr(unsigned i) const { |
| 3503 | return const_cast<GCCAsmStmt*>(this)->getInputExpr(i); |
| 3504 | } |
| 3505 | |
| 3506 | static std::string (const Expr *E); |
| 3507 | |
| 3508 | //===--- Labels ---===// |
| 3509 | |
| 3510 | bool isAsmGoto() const { |
| 3511 | return NumLabels > 0; |
| 3512 | } |
| 3513 | |
| 3514 | unsigned getNumLabels() const { |
| 3515 | return NumLabels; |
| 3516 | } |
| 3517 | |
| 3518 | IdentifierInfo *getLabelIdentifier(unsigned i) const { |
| 3519 | return Names[i + NumOutputs + NumInputs]; |
| 3520 | } |
| 3521 | |
| 3522 | AddrLabelExpr *getLabelExpr(unsigned i) const; |
| 3523 | StringRef getLabelName(unsigned i) const; |
| 3524 | using labels_iterator = CastIterator<AddrLabelExpr>; |
| 3525 | using const_labels_iterator = ConstCastIterator<AddrLabelExpr>; |
| 3526 | using labels_range = llvm::iterator_range<labels_iterator>; |
| 3527 | using labels_const_range = llvm::iterator_range<const_labels_iterator>; |
| 3528 | |
| 3529 | labels_iterator begin_labels() { |
| 3530 | return &Exprs[0] + NumOutputs + NumInputs; |
| 3531 | } |
| 3532 | |
| 3533 | labels_iterator end_labels() { |
| 3534 | return &Exprs[0] + NumOutputs + NumInputs + NumLabels; |
| 3535 | } |
| 3536 | |
| 3537 | labels_range labels() { |
| 3538 | return labels_range(begin_labels(), end_labels()); |
| 3539 | } |
| 3540 | |
| 3541 | const_labels_iterator begin_labels() const { |
| 3542 | return &Exprs[0] + NumOutputs + NumInputs; |
| 3543 | } |
| 3544 | |
| 3545 | const_labels_iterator end_labels() const { |
| 3546 | return &Exprs[0] + NumOutputs + NumInputs + NumLabels; |
| 3547 | } |
| 3548 | |
| 3549 | labels_const_range labels() const { |
| 3550 | return labels_const_range(begin_labels(), end_labels()); |
| 3551 | } |
| 3552 | |
| 3553 | private: |
| 3554 | void setOutputsAndInputsAndClobbers(const ASTContext &C, |
| 3555 | IdentifierInfo **Names, |
| 3556 | Expr **Constraints, Stmt **Exprs, |
| 3557 | unsigned NumOutputs, unsigned NumInputs, |
| 3558 | unsigned NumLabels, Expr **Clobbers, |
| 3559 | unsigned NumClobbers); |
| 3560 | |
| 3561 | public: |
| 3562 | //===--- Other ---===// |
| 3563 | |
| 3564 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 3565 | /// translate this into a numeric value needed to reference the same operand. |
| 3566 | /// This returns -1 if the operand name is invalid. |
| 3567 | int getNamedOperand(StringRef SymbolicName) const; |
| 3568 | |
| 3569 | std::string getClobber(unsigned i) const; |
| 3570 | |
| 3571 | Expr *getClobberExpr(unsigned i) { return Clobbers[i]; } |
| 3572 | const Expr *getClobberExpr(unsigned i) const { return Clobbers[i]; } |
| 3573 | |
| 3574 | SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; } |
| 3575 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
| 3576 | |
| 3577 | static bool classof(const Stmt *T) { |
| 3578 | return T->getStmtClass() == GCCAsmStmtClass; |
| 3579 | } |
| 3580 | }; |
| 3581 | |
| 3582 | /// This represents a Microsoft inline-assembly statement extension. |
| 3583 | class MSAsmStmt : public AsmStmt { |
| 3584 | friend class ASTStmtReader; |
| 3585 | |
| 3586 | SourceLocation LBraceLoc, EndLoc; |
| 3587 | StringRef AsmStr; |
| 3588 | |
| 3589 | unsigned NumAsmToks = 0; |
| 3590 | |
| 3591 | Token *AsmToks = nullptr; |
| 3592 | StringRef *Constraints = nullptr; |
| 3593 | StringRef *Clobbers = nullptr; |
| 3594 | |
| 3595 | public: |
| 3596 | MSAsmStmt(const ASTContext &C, SourceLocation asmloc, |
| 3597 | SourceLocation lbraceloc, bool issimple, bool isvolatile, |
| 3598 | ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs, |
| 3599 | ArrayRef<StringRef> constraints, |
| 3600 | ArrayRef<Expr*> exprs, StringRef asmstr, |
| 3601 | ArrayRef<StringRef> clobbers, SourceLocation endloc); |
| 3602 | |
| 3603 | /// Build an empty MS-style inline-assembly statement. |
| 3604 | explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {} |
| 3605 | |
| 3606 | SourceLocation getLBraceLoc() const { return LBraceLoc; } |
| 3607 | void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } |
| 3608 | SourceLocation getEndLoc() const { return EndLoc; } |
| 3609 | void setEndLoc(SourceLocation L) { EndLoc = L; } |
| 3610 | |
| 3611 | bool hasBraces() const { return LBraceLoc.isValid(); } |
| 3612 | |
| 3613 | unsigned getNumAsmToks() { return NumAsmToks; } |
| 3614 | Token *getAsmToks() { return AsmToks; } |
| 3615 | |
| 3616 | //===--- Asm String Analysis ---===// |
| 3617 | StringRef getAsmString() const { return AsmStr; } |
| 3618 | |
| 3619 | /// Assemble final IR asm string. |
| 3620 | std::string generateAsmString(const ASTContext &C) const; |
| 3621 | |
| 3622 | //===--- Output operands ---===// |
| 3623 | |
| 3624 | StringRef getOutputConstraint(unsigned i) const { |
| 3625 | assert(i < NumOutputs); |
| 3626 | return Constraints[i]; |
| 3627 | } |
| 3628 | |
| 3629 | Expr *getOutputExpr(unsigned i); |
| 3630 | |
| 3631 | const Expr *getOutputExpr(unsigned i) const { |
| 3632 | return const_cast<MSAsmStmt*>(this)->getOutputExpr(i); |
| 3633 | } |
| 3634 | |
| 3635 | //===--- Input operands ---===// |
| 3636 | |
| 3637 | StringRef getInputConstraint(unsigned i) const { |
| 3638 | assert(i < NumInputs); |
| 3639 | return Constraints[i + NumOutputs]; |
| 3640 | } |
| 3641 | |
| 3642 | Expr *getInputExpr(unsigned i); |
| 3643 | void setInputExpr(unsigned i, Expr *E); |
| 3644 | |
| 3645 | const Expr *getInputExpr(unsigned i) const { |
| 3646 | return const_cast<MSAsmStmt*>(this)->getInputExpr(i); |
| 3647 | } |
| 3648 | |
| 3649 | //===--- Other ---===// |
| 3650 | |
| 3651 | ArrayRef<StringRef> getAllConstraints() const { |
| 3652 | return llvm::ArrayRef(Constraints, NumInputs + NumOutputs); |
| 3653 | } |
| 3654 | |
| 3655 | ArrayRef<StringRef> getClobbers() const { |
| 3656 | return llvm::ArrayRef(Clobbers, NumClobbers); |
| 3657 | } |
| 3658 | |
| 3659 | ArrayRef<Expr*> getAllExprs() const { |
| 3660 | return llvm::ArrayRef(reinterpret_cast<Expr **>(Exprs), |
| 3661 | NumInputs + NumOutputs); |
| 3662 | } |
| 3663 | |
| 3664 | StringRef getClobber(unsigned i) const { return getClobbers()[i]; } |
| 3665 | |
| 3666 | private: |
| 3667 | void initialize(const ASTContext &C, StringRef AsmString, |
| 3668 | ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints, |
| 3669 | ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers); |
| 3670 | |
| 3671 | public: |
| 3672 | SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; } |
| 3673 | |
| 3674 | static bool classof(const Stmt *T) { |
| 3675 | return T->getStmtClass() == MSAsmStmtClass; |
| 3676 | } |
| 3677 | |
| 3678 | child_range children() { |
| 3679 | return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]); |
| 3680 | } |
| 3681 | |
| 3682 | const_child_range children() const { |
| 3683 | return const_child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]); |
| 3684 | } |
| 3685 | }; |
| 3686 | |
| 3687 | class SEHExceptStmt : public Stmt { |
| 3688 | friend class ASTReader; |
| 3689 | friend class ASTStmtReader; |
| 3690 | |
| 3691 | SourceLocation Loc; |
| 3692 | Stmt *Children[2]; |
| 3693 | |
| 3694 | enum { FILTER_EXPR, BLOCK }; |
| 3695 | |
| 3696 | SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block); |
| 3697 | explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {} |
| 3698 | |
| 3699 | public: |
| 3700 | static SEHExceptStmt* Create(const ASTContext &C, |
| 3701 | SourceLocation ExceptLoc, |
| 3702 | Expr *FilterExpr, |
| 3703 | Stmt *Block); |
| 3704 | |
| 3705 | SourceLocation getBeginLoc() const LLVM_READONLY { return getExceptLoc(); } |
| 3706 | |
| 3707 | SourceLocation getExceptLoc() const { return Loc; } |
| 3708 | SourceLocation getEndLoc() const { return getBlock()->getEndLoc(); } |
| 3709 | |
| 3710 | Expr *getFilterExpr() const { |
| 3711 | return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); |
| 3712 | } |
| 3713 | |
| 3714 | CompoundStmt *getBlock() const { |
| 3715 | return cast<CompoundStmt>(Children[BLOCK]); |
| 3716 | } |
| 3717 | |
| 3718 | child_range children() { |
| 3719 | return child_range(Children, Children+2); |
| 3720 | } |
| 3721 | |
| 3722 | const_child_range children() const { |
| 3723 | return const_child_range(Children, Children + 2); |
| 3724 | } |
| 3725 | |
| 3726 | static bool classof(const Stmt *T) { |
| 3727 | return T->getStmtClass() == SEHExceptStmtClass; |
| 3728 | } |
| 3729 | }; |
| 3730 | |
| 3731 | class SEHFinallyStmt : public Stmt { |
| 3732 | friend class ASTReader; |
| 3733 | friend class ASTStmtReader; |
| 3734 | |
| 3735 | SourceLocation Loc; |
| 3736 | Stmt *Block; |
| 3737 | |
| 3738 | SEHFinallyStmt(SourceLocation Loc, Stmt *Block); |
| 3739 | explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {} |
| 3740 | |
| 3741 | public: |
| 3742 | static SEHFinallyStmt* Create(const ASTContext &C, |
| 3743 | SourceLocation FinallyLoc, |
| 3744 | Stmt *Block); |
| 3745 | |
| 3746 | SourceLocation getBeginLoc() const LLVM_READONLY { return getFinallyLoc(); } |
| 3747 | |
| 3748 | SourceLocation getFinallyLoc() const { return Loc; } |
| 3749 | SourceLocation getEndLoc() const { return Block->getEndLoc(); } |
| 3750 | |
| 3751 | CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); } |
| 3752 | |
| 3753 | child_range children() { |
| 3754 | return child_range(&Block,&Block+1); |
| 3755 | } |
| 3756 | |
| 3757 | const_child_range children() const { |
| 3758 | return const_child_range(&Block, &Block + 1); |
| 3759 | } |
| 3760 | |
| 3761 | static bool classof(const Stmt *T) { |
| 3762 | return T->getStmtClass() == SEHFinallyStmtClass; |
| 3763 | } |
| 3764 | }; |
| 3765 | |
| 3766 | class SEHTryStmt : public Stmt { |
| 3767 | friend class ASTReader; |
| 3768 | friend class ASTStmtReader; |
| 3769 | |
| 3770 | bool IsCXXTry; |
| 3771 | SourceLocation TryLoc; |
| 3772 | Stmt *Children[2]; |
| 3773 | |
| 3774 | enum { TRY = 0, HANDLER = 1 }; |
| 3775 | |
| 3776 | SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' |
| 3777 | SourceLocation TryLoc, |
| 3778 | Stmt *TryBlock, |
| 3779 | Stmt *Handler); |
| 3780 | |
| 3781 | explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {} |
| 3782 | |
| 3783 | public: |
| 3784 | static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry, |
| 3785 | SourceLocation TryLoc, Stmt *TryBlock, |
| 3786 | Stmt *Handler); |
| 3787 | |
| 3788 | SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); } |
| 3789 | |
| 3790 | SourceLocation getTryLoc() const { return TryLoc; } |
| 3791 | SourceLocation getEndLoc() const { return Children[HANDLER]->getEndLoc(); } |
| 3792 | |
| 3793 | bool getIsCXXTry() const { return IsCXXTry; } |
| 3794 | |
| 3795 | CompoundStmt* getTryBlock() const { |
| 3796 | return cast<CompoundStmt>(Children[TRY]); |
| 3797 | } |
| 3798 | |
| 3799 | Stmt *getHandler() const { return Children[HANDLER]; } |
| 3800 | |
| 3801 | /// Returns 0 if not defined |
| 3802 | SEHExceptStmt *getExceptHandler() const; |
| 3803 | SEHFinallyStmt *getFinallyHandler() const; |
| 3804 | |
| 3805 | child_range children() { |
| 3806 | return child_range(Children, Children+2); |
| 3807 | } |
| 3808 | |
| 3809 | const_child_range children() const { |
| 3810 | return const_child_range(Children, Children + 2); |
| 3811 | } |
| 3812 | |
| 3813 | static bool classof(const Stmt *T) { |
| 3814 | return T->getStmtClass() == SEHTryStmtClass; |
| 3815 | } |
| 3816 | }; |
| 3817 | |
| 3818 | /// Represents a __leave statement. |
| 3819 | class SEHLeaveStmt : public Stmt { |
| 3820 | SourceLocation LeaveLoc; |
| 3821 | |
| 3822 | public: |
| 3823 | explicit SEHLeaveStmt(SourceLocation LL) |
| 3824 | : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {} |
| 3825 | |
| 3826 | /// Build an empty __leave statement. |
| 3827 | explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {} |
| 3828 | |
| 3829 | SourceLocation getLeaveLoc() const { return LeaveLoc; } |
| 3830 | void setLeaveLoc(SourceLocation L) { LeaveLoc = L; } |
| 3831 | |
| 3832 | SourceLocation getBeginLoc() const LLVM_READONLY { return LeaveLoc; } |
| 3833 | SourceLocation getEndLoc() const LLVM_READONLY { return LeaveLoc; } |
| 3834 | |
| 3835 | static bool classof(const Stmt *T) { |
| 3836 | return T->getStmtClass() == SEHLeaveStmtClass; |
| 3837 | } |
| 3838 | |
| 3839 | // Iterators |
| 3840 | child_range children() { |
| 3841 | return child_range(child_iterator(), child_iterator()); |
| 3842 | } |
| 3843 | |
| 3844 | const_child_range children() const { |
| 3845 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3846 | } |
| 3847 | }; |
| 3848 | |
| 3849 | /// This captures a statement into a function. For example, the following |
| 3850 | /// pragma annotated compound statement can be represented as a CapturedStmt, |
| 3851 | /// and this compound statement is the body of an anonymous outlined function. |
| 3852 | /// @code |
| 3853 | /// #pragma omp parallel |
| 3854 | /// { |
| 3855 | /// compute(); |
| 3856 | /// } |
| 3857 | /// @endcode |
| 3858 | class CapturedStmt : public Stmt { |
| 3859 | public: |
| 3860 | /// The different capture forms: by 'this', by reference, capture for |
| 3861 | /// variable-length array type etc. |
| 3862 | enum VariableCaptureKind { |
| 3863 | VCK_This, |
| 3864 | VCK_ByRef, |
| 3865 | VCK_ByCopy, |
| 3866 | VCK_VLAType, |
| 3867 | }; |
| 3868 | |
| 3869 | /// Describes the capture of either a variable, or 'this', or |
| 3870 | /// variable-length array type. |
| 3871 | class Capture { |
| 3872 | llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind; |
| 3873 | SourceLocation Loc; |
| 3874 | |
| 3875 | Capture() = default; |
| 3876 | |
| 3877 | public: |
| 3878 | friend class ASTStmtReader; |
| 3879 | friend class CapturedStmt; |
| 3880 | |
| 3881 | /// Create a new capture. |
| 3882 | /// |
| 3883 | /// \param Loc The source location associated with this capture. |
| 3884 | /// |
| 3885 | /// \param Kind The kind of capture (this, ByRef, ...). |
| 3886 | /// |
| 3887 | /// \param Var The variable being captured, or null if capturing this. |
| 3888 | Capture(SourceLocation Loc, VariableCaptureKind Kind, |
| 3889 | VarDecl *Var = nullptr); |
| 3890 | |
| 3891 | /// Determine the kind of capture. |
| 3892 | VariableCaptureKind getCaptureKind() const; |
| 3893 | |
| 3894 | /// Retrieve the source location at which the variable or 'this' was |
| 3895 | /// first used. |
| 3896 | SourceLocation getLocation() const { return Loc; } |
| 3897 | |
| 3898 | /// Determine whether this capture handles the C++ 'this' pointer. |
| 3899 | bool capturesThis() const { return getCaptureKind() == VCK_This; } |
| 3900 | |
| 3901 | /// Determine whether this capture handles a variable (by reference). |
| 3902 | bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; } |
| 3903 | |
| 3904 | /// Determine whether this capture handles a variable by copy. |
| 3905 | bool capturesVariableByCopy() const { |
| 3906 | return getCaptureKind() == VCK_ByCopy; |
| 3907 | } |
| 3908 | |
| 3909 | /// Determine whether this capture handles a variable-length array |
| 3910 | /// type. |
| 3911 | bool capturesVariableArrayType() const { |
| 3912 | return getCaptureKind() == VCK_VLAType; |
| 3913 | } |
| 3914 | |
| 3915 | /// Retrieve the declaration of the variable being captured. |
| 3916 | /// |
| 3917 | /// This operation is only valid if this capture captures a variable. |
| 3918 | VarDecl *getCapturedVar() const; |
| 3919 | }; |
| 3920 | |
| 3921 | private: |
| 3922 | /// The number of variable captured, including 'this'. |
| 3923 | unsigned NumCaptures; |
| 3924 | |
| 3925 | /// The pointer part is the implicit the outlined function and the |
| 3926 | /// int part is the captured region kind, 'CR_Default' etc. |
| 3927 | llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind; |
| 3928 | |
| 3929 | /// The record for captured variables, a RecordDecl or CXXRecordDecl. |
| 3930 | RecordDecl *TheRecordDecl = nullptr; |
| 3931 | |
| 3932 | /// Construct a captured statement. |
| 3933 | CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures, |
| 3934 | ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD); |
| 3935 | |
| 3936 | /// Construct an empty captured statement. |
| 3937 | CapturedStmt(EmptyShell Empty, unsigned NumCaptures); |
| 3938 | |
| 3939 | Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); } |
| 3940 | |
| 3941 | Stmt *const *getStoredStmts() const { |
| 3942 | return reinterpret_cast<Stmt *const *>(this + 1); |
| 3943 | } |
| 3944 | |
| 3945 | Capture *getStoredCaptures() const; |
| 3946 | |
| 3947 | void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; } |
| 3948 | |
| 3949 | public: |
| 3950 | friend class ASTStmtReader; |
| 3951 | |
| 3952 | static CapturedStmt *Create(const ASTContext &Context, Stmt *S, |
| 3953 | CapturedRegionKind Kind, |
| 3954 | ArrayRef<Capture> Captures, |
| 3955 | ArrayRef<Expr *> CaptureInits, |
| 3956 | CapturedDecl *CD, RecordDecl *RD); |
| 3957 | |
| 3958 | static CapturedStmt *CreateDeserialized(const ASTContext &Context, |
| 3959 | unsigned NumCaptures); |
| 3960 | |
| 3961 | /// Retrieve the statement being captured. |
| 3962 | Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; } |
| 3963 | const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; } |
| 3964 | |
| 3965 | /// Retrieve the outlined function declaration. |
| 3966 | CapturedDecl *getCapturedDecl(); |
| 3967 | const CapturedDecl *getCapturedDecl() const; |
| 3968 | |
| 3969 | /// Set the outlined function declaration. |
| 3970 | void setCapturedDecl(CapturedDecl *D); |
| 3971 | |
| 3972 | /// Retrieve the captured region kind. |
| 3973 | CapturedRegionKind getCapturedRegionKind() const; |
| 3974 | |
| 3975 | /// Set the captured region kind. |
| 3976 | void setCapturedRegionKind(CapturedRegionKind Kind); |
| 3977 | |
| 3978 | /// Retrieve the record declaration for captured variables. |
| 3979 | const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; } |
| 3980 | |
| 3981 | /// Set the record declaration for captured variables. |
| 3982 | void setCapturedRecordDecl(RecordDecl *D) { |
| 3983 | assert(D && "null RecordDecl" ); |
| 3984 | TheRecordDecl = D; |
| 3985 | } |
| 3986 | |
| 3987 | /// True if this variable has been captured. |
| 3988 | bool capturesVariable(const VarDecl *Var) const; |
| 3989 | |
| 3990 | /// An iterator that walks over the captures. |
| 3991 | using capture_iterator = Capture *; |
| 3992 | using const_capture_iterator = const Capture *; |
| 3993 | using capture_range = llvm::iterator_range<capture_iterator>; |
| 3994 | using capture_const_range = llvm::iterator_range<const_capture_iterator>; |
| 3995 | |
| 3996 | capture_range captures() { |
| 3997 | return capture_range(capture_begin(), capture_end()); |
| 3998 | } |
| 3999 | capture_const_range captures() const { |
| 4000 | return capture_const_range(capture_begin(), capture_end()); |
| 4001 | } |
| 4002 | |
| 4003 | /// Retrieve an iterator pointing to the first capture. |
| 4004 | capture_iterator capture_begin() { return getStoredCaptures(); } |
| 4005 | const_capture_iterator capture_begin() const { return getStoredCaptures(); } |
| 4006 | |
| 4007 | /// Retrieve an iterator pointing past the end of the sequence of |
| 4008 | /// captures. |
| 4009 | capture_iterator capture_end() const { |
| 4010 | return getStoredCaptures() + NumCaptures; |
| 4011 | } |
| 4012 | |
| 4013 | /// Retrieve the number of captures, including 'this'. |
| 4014 | unsigned capture_size() const { return NumCaptures; } |
| 4015 | |
| 4016 | /// Iterator that walks over the capture initialization arguments. |
| 4017 | using capture_init_iterator = Expr **; |
| 4018 | using capture_init_range = llvm::iterator_range<capture_init_iterator>; |
| 4019 | |
| 4020 | /// Const iterator that walks over the capture initialization |
| 4021 | /// arguments. |
| 4022 | using const_capture_init_iterator = Expr *const *; |
| 4023 | using const_capture_init_range = |
| 4024 | llvm::iterator_range<const_capture_init_iterator>; |
| 4025 | |
| 4026 | capture_init_range capture_inits() { |
| 4027 | return capture_init_range(capture_init_begin(), capture_init_end()); |
| 4028 | } |
| 4029 | |
| 4030 | const_capture_init_range capture_inits() const { |
| 4031 | return const_capture_init_range(capture_init_begin(), capture_init_end()); |
| 4032 | } |
| 4033 | |
| 4034 | /// Retrieve the first initialization argument. |
| 4035 | capture_init_iterator capture_init_begin() { |
| 4036 | return reinterpret_cast<Expr **>(getStoredStmts()); |
| 4037 | } |
| 4038 | |
| 4039 | const_capture_init_iterator capture_init_begin() const { |
| 4040 | return reinterpret_cast<Expr *const *>(getStoredStmts()); |
| 4041 | } |
| 4042 | |
| 4043 | /// Retrieve the iterator pointing one past the last initialization |
| 4044 | /// argument. |
| 4045 | capture_init_iterator capture_init_end() { |
| 4046 | return capture_init_begin() + NumCaptures; |
| 4047 | } |
| 4048 | |
| 4049 | const_capture_init_iterator capture_init_end() const { |
| 4050 | return capture_init_begin() + NumCaptures; |
| 4051 | } |
| 4052 | |
| 4053 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 4054 | return getCapturedStmt()->getBeginLoc(); |
| 4055 | } |
| 4056 | |
| 4057 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 4058 | return getCapturedStmt()->getEndLoc(); |
| 4059 | } |
| 4060 | |
| 4061 | SourceRange getSourceRange() const LLVM_READONLY { |
| 4062 | return getCapturedStmt()->getSourceRange(); |
| 4063 | } |
| 4064 | |
| 4065 | static bool classof(const Stmt *T) { |
| 4066 | return T->getStmtClass() == CapturedStmtClass; |
| 4067 | } |
| 4068 | |
| 4069 | child_range children(); |
| 4070 | |
| 4071 | const_child_range children() const; |
| 4072 | }; |
| 4073 | |
| 4074 | } // namespace clang |
| 4075 | |
| 4076 | #endif // LLVM_CLANG_AST_STMT_H |
| 4077 | |