31 #include "llvm/ADT/SmallVector.h" 32 #include "llvm/ADT/StringExtras.h" 33 #include "llvm/ADT/StringRef.h" 34 #include "llvm/Support/Casting.h" 35 #include "llvm/Support/Compiler.h" 36 #include "llvm/Support/ErrorHandling.h" 37 #include "llvm/Support/MathExtras.h" 38 #include "llvm/Support/raw_ostream.h" 45 using namespace clang;
60 #define ABSTRACT_STMT(STMT) 61 #define STMT(CLASS, PARENT) \ 62 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ 63 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); 64 #include "clang/AST/StmtNodes.inc" 71 return ::operator
new(
bytes,
C, alignment);
81 #define STMT(CLASS, PARENT) \ 82 static_assert(!std::is_polymorphic<CLASS>::value, \ 83 #CLASS " should not be polymorphic!"); 84 #include "clang/AST/StmtNodes.inc" 91 llvm::errs() <<
"\n*** Stmt/Expr Stats:\n";
92 for (
int i = 0;
i != Stmt::lastStmtConstant+1;
i++) {
96 llvm::errs() <<
" " << sum <<
" stmts/exprs total.\n";
98 for (
int i = 0;
i != Stmt::lastStmtConstant+1;
i++) {
108 llvm::errs() <<
"Total bytes = " << sum <<
"\n";
115 bool Stmt::StatisticsEnabled =
false;
117 StatisticsEnabled =
true;
125 if (
auto CapS = dyn_cast_or_null<CapturedStmt>(S))
126 S = CapS->getCapturedStmt();
128 if (
auto AS = dyn_cast_or_null<AttributedStmt>(S))
129 S = AS->getSubStmt();
130 else if (
auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
145 const Stmt *S =
this;
147 if (
const auto *LS = dyn_cast<LabelStmt>(S))
148 S = LS->getSubStmt();
149 else if (
const auto *SC = dyn_cast<SwitchCase>(S))
150 S = SC->getSubStmt();
151 else if (
const auto *AS = dyn_cast<AttributedStmt>(S))
152 S = AS->getSubStmt();
166 static good is_good(good) {
return good(); }
169 template <
class T> good implements_children(children_t T::*) {
172 LLVM_ATTRIBUTE_UNUSED
173 static bad implements_children(children_t
Stmt::*) {
178 template <
class T> good implements_getBeginLoc(getBeginLoc_t T::*) {
181 LLVM_ATTRIBUTE_UNUSED
182 static bad implements_getBeginLoc(getBeginLoc_t
Stmt::*) {
return bad(); }
185 template <
class T> good implements_getEndLoc(getLocEnd_t T::*) {
188 LLVM_ATTRIBUTE_UNUSED
189 static bad implements_getEndLoc(getLocEnd_t
Stmt::*) {
return bad(); }
191 #define ASSERT_IMPLEMENTS_children(type) \ 192 (void) is_good(implements_children(&type::children)) 193 #define ASSERT_IMPLEMENTS_getBeginLoc(type) \ 194 (void)is_good(implements_getBeginLoc(&type::getBeginLoc)) 195 #define ASSERT_IMPLEMENTS_getEndLoc(type) \ 196 (void)is_good(implements_getEndLoc(&type::getEndLoc)) 202 LLVM_ATTRIBUTE_UNUSED
204 #define ABSTRACT_STMT(type) 205 #define STMT(type, base) \ 206 ASSERT_IMPLEMENTS_children(type); \ 207 ASSERT_IMPLEMENTS_getBeginLoc(type); \ 208 ASSERT_IMPLEMENTS_getEndLoc(type); 209 #include "clang/AST/StmtNodes.inc" 213 switch (getStmtClass()) {
215 #define ABSTRACT_STMT(type) 216 #define STMT(type, base) \ 217 case Stmt::type##Class: \ 218 return static_cast<type*>(this)->children(); 219 #include "clang/AST/StmtNodes.inc" 221 llvm_unreachable(
"unknown statement kind!");
232 template <
class S,
class T>
245 return SourceRange(static_cast<const S *>(stmt)->getBeginLoc(),
246 static_cast<const S *>(stmt)->getEndLoc());
252 switch (getStmtClass()) {
254 #define ABSTRACT_STMT(type) 255 #define STMT(type, base) \ 256 case Stmt::type##Class: \ 257 return getSourceRangeImpl<type>(this, &type::getSourceRange); 258 #include "clang/AST/StmtNodes.inc" 260 llvm_unreachable(
"unknown statement kind!");
265 switch (getStmtClass()) {
267 #define ABSTRACT_STMT(type) 268 #define STMT(type, base) \ 269 case Stmt::type##Class: \ 270 return static_cast<const type *>(this)->getBeginLoc(); 271 #include "clang/AST/StmtNodes.inc" 273 llvm_unreachable(
"unknown statement kind");
277 switch (getStmtClass()) {
279 #define ABSTRACT_STMT(type) 280 #define STMT(type, base) \ 281 case Stmt::type##Class: \ 282 return static_cast<const type *>(this)->getEndLoc(); 283 #include "clang/AST/StmtNodes.inc" 285 llvm_unreachable(
"unknown statement kind");
294 :
Stmt(CompoundStmtClass), RBraceLoc(RB) {
295 CompoundStmtBits.NumStmts = Stmts.size();
297 CompoundStmtBits.LBraceLoc = LB;
301 assert(CompoundStmtBits.NumStmts == Stmts.size() &&
302 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
304 std::copy(Stmts.begin(), Stmts.end(), body_begin());
324 const Stmt *S =
this;
326 if (
const auto *E = dyn_cast<Expr>(S))
329 if (
const auto *LS = dyn_cast<LabelStmt>(S))
330 S = LS->getSubStmt();
331 else if (
const auto *AS = dyn_cast<AttributedStmt>(S))
332 S = AS->getSubStmt();
334 llvm_unreachable(
"unknown kind of ValueStmt");
335 }
while (isa<ValueStmt>(S));
341 return getDecl()->getIdentifier()->getNameStart();
347 assert(!Attrs.empty() &&
"Attrs should not be empty");
348 void *Mem = C.
Allocate(totalSizeToAlloc<const Attr *>(Attrs.size()),
355 assert(NumAttrs > 0 &&
"NumAttrs should be greater than zero");
356 void *Mem = C.
Allocate(totalSizeToAlloc<const Attr *>(NumAttrs),
362 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
363 return gccAsmStmt->generateAsmString(C);
364 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
365 return msAsmStmt->generateAsmString(C);
366 llvm_unreachable(
"unknown asm statement kind!");
370 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
371 return gccAsmStmt->getOutputConstraint(i);
372 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
373 return msAsmStmt->getOutputConstraint(i);
374 llvm_unreachable(
"unknown asm statement kind!");
378 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
379 return gccAsmStmt->getOutputExpr(i);
380 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
381 return msAsmStmt->getOutputExpr(i);
382 llvm_unreachable(
"unknown asm statement kind!");
386 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
387 return gccAsmStmt->getInputConstraint(i);
388 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
389 return msAsmStmt->getInputConstraint(i);
390 llvm_unreachable(
"unknown asm statement kind!");
394 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
395 return gccAsmStmt->getInputExpr(i);
396 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
397 return msAsmStmt->getInputExpr(i);
398 llvm_unreachable(
"unknown asm statement kind!");
402 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
403 return gccAsmStmt->getClobber(i);
404 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
405 return msAsmStmt->getClobber(i);
406 llvm_unreachable(
"unknown asm statement kind!");
413 for (
unsigned i = 0, e = getNumOutputs();
i != e; ++
i)
414 if (isOutputPlusConstraint(
i))
420 assert(isOperand() &&
"Only Operands can have modifiers.");
421 return isLetter(Str[0]) ? Str[0] :
'\0';
425 return getClobberStringLiteral(i)->getString();
429 return cast<Expr>(Exprs[
i]);
436 return getOutputConstraintLiteral(i)->getString();
440 return cast<Expr>(Exprs[i + NumOutputs]);
444 Exprs[i + NumOutputs] = E;
448 return cast<AddrLabelExpr>(Exprs[i + NumInputs]);
452 return getLabelExpr(i)->getLabel()->getName();
458 return getInputConstraintLiteral(i)->getString();
461 void GCCAsmStmt::setOutputsAndInputsAndClobbers(
const ASTContext &
C,
469 unsigned NumClobbers) {
470 this->NumOutputs = NumOutputs;
471 this->NumInputs = NumInputs;
472 this->NumClobbers = NumClobbers;
473 this->NumLabels = NumLabels;
474 assert(!(NumOutputs && NumLabels) &&
"asm goto cannot have outputs");
476 unsigned NumExprs = NumOutputs + NumInputs + NumLabels;
480 std::copy(Names, Names + NumExprs, this->Names);
483 this->Exprs =
new (
C)
Stmt*[NumExprs];
484 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
489 std::copy(Constraints, Constraints + NumConstraints, this->Constraints);
493 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
500 unsigned NumPlusOperands = 0;
503 for (
unsigned i = 0, e = getNumOutputs();
i != e; ++
i) {
504 if (getOutputName(
i) == SymbolicName)
508 for (
unsigned i = 0, e = getNumInputs();
i != e; ++
i)
509 if (getInputName(
i) == SymbolicName)
510 return getNumOutputs() + NumPlusOperands +
i;
512 for (
unsigned i = 0, e = getNumLabels(); i != e; ++
i)
513 if (getLabelName(i) == SymbolicName)
514 return i + getNumInputs();
524 const ASTContext &C,
unsigned &DiagOffs)
const {
525 StringRef Str = getAsmString()->getString();
526 const char *StrStart = Str.begin();
527 const char *StrEnd = Str.end();
528 const char *CurPtr = StrStart;
534 for (; CurPtr != StrEnd; ++CurPtr) {
550 std::string CurStringPiece;
554 unsigned LastAsmStringToken = 0;
555 unsigned LastAsmStringOffset = 0;
559 if (CurPtr == StrEnd) {
560 if (!CurStringPiece.empty())
565 char CurChar = *CurPtr++;
567 case '$': CurStringPiece +=
"$$";
continue;
568 case '{': CurStringPiece += (HasVariants ?
"$(" :
"{");
continue;
569 case '|': CurStringPiece += (HasVariants ?
"$|" :
"|");
continue;
570 case '}': CurStringPiece += (HasVariants ?
"$)" :
"}");
continue;
574 CurStringPiece += CurChar;
579 if (CurPtr == StrEnd) {
581 DiagOffs = CurPtr-StrStart-1;
582 return diag::err_asm_invalid_escape;
585 char EscapedChar = *CurPtr++;
586 switch (EscapedChar) {
592 CurStringPiece += EscapedChar;
595 CurStringPiece +=
"${:uid}";
601 if (!CurStringPiece.empty()) {
603 CurStringPiece.clear();
609 const char *
Begin = CurPtr - 1;
610 const char *Percent = Begin - 1;
613 if (CurPtr == StrEnd) {
614 DiagOffs = CurPtr-StrStart-1;
615 return diag::err_asm_invalid_escape;
617 EscapedChar = *CurPtr++;
630 while (CurPtr != StrEnd &&
isDigit(*CurPtr))
631 N = N*10 + ((*CurPtr++)-
'0');
633 unsigned NumOperands = getNumOutputs() + getNumPlusOperands() +
634 getNumInputs() + getNumLabels();
635 if (N >= NumOperands) {
636 DiagOffs = CurPtr-StrStart-1;
637 return diag::err_asm_invalid_operand_number;
641 std::string Str(Begin, CurPtr - Begin);
646 Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
647 &LastAsmStringOffset);
649 CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken,
650 &LastAsmStringOffset);
652 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
657 if (EscapedChar ==
'[') {
658 DiagOffs = CurPtr-StrStart-1;
661 const char *NameEnd = (
const char*)memchr(CurPtr,
']', StrEnd-CurPtr);
662 if (NameEnd ==
nullptr)
663 return diag::err_asm_unterminated_symbolic_operand_name;
664 if (NameEnd == CurPtr)
665 return diag::err_asm_empty_symbolic_operand_name;
667 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
669 int N = getNamedOperand(SymbolicName);
672 DiagOffs = CurPtr-StrStart;
673 return diag::err_asm_unknown_symbolic_operand_name;
677 std::string Str(Begin, NameEnd + 1 - Begin);
682 Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
683 &LastAsmStringOffset);
685 NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken,
686 &LastAsmStringOffset);
688 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
694 DiagOffs = CurPtr-StrStart-1;
695 return diag::err_asm_invalid_escape;
705 AnalyzeAsmString(Pieces, C, DiagOffs);
707 std::string AsmString;
708 for (
const auto &Piece : Pieces) {
709 if (Piece.isString())
710 AsmString += Piece.getString();
711 else if (Piece.getModifier() ==
'\0')
712 AsmString +=
'$' + llvm::utostr(Piece.getOperandNo());
714 AsmString +=
"${" + llvm::utostr(Piece.getOperandNo()) +
':' +
715 Piece.getModifier() +
'}';
727 return cast<Expr>(Exprs[
i]);
731 return cast<Expr>(Exprs[i + NumOutputs]);
735 Exprs[i + NumOutputs] = E;
743 bool issimple,
bool isvolatile,
unsigned numoutputs,
749 :
AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
750 numinputs, numclobbers),
751 RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) {
755 std::copy(names, names + NumExprs, Names);
757 Exprs =
new (
C)
Stmt*[NumExprs];
758 std::copy(exprs, exprs + NumExprs, Exprs);
762 std::copy(constraints, constraints + NumConstraints, Constraints);
765 std::copy(clobbers, clobbers +
NumClobbers, Clobbers);
775 :
AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
776 numinputs, clobbers.size()), LBraceLoc(lbraceloc),
777 EndLoc(endloc), NumAsmToks(asmtoks.size()) {
778 initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
785 void MSAsmStmt::initialize(
const ASTContext &C, StringRef asmstr,
790 assert(NumAsmToks == asmtoks.size());
794 assert(exprs.size() == constraints.size());
798 Exprs =
new (
C)
Stmt*[exprs.size()];
799 std::copy(exprs.begin(), exprs.end(),
Exprs);
801 AsmToks =
new (
C)
Token[asmtoks.size()];
802 std::copy(asmtoks.begin(), asmtoks.end(), AsmToks);
804 Constraints =
new (
C) StringRef[exprs.size()];
805 std::transform(constraints.begin(), constraints.end(), Constraints,
806 [&](StringRef Constraint) {
812 std::transform(clobbers.begin(), clobbers.end(), Clobbers,
813 [&](StringRef Clobber) {
821 :
Stmt(IfStmtClass) {
822 bool HasElse = Else !=
nullptr;
823 bool HasVar = Var !=
nullptr;
824 bool HasInit = Init !=
nullptr;
829 setConstexpr(IsConstexpr);
836 setConditionVariable(Ctx, Var);
845 IfStmt::IfStmt(EmptyShell Empty,
bool HasElse,
bool HasVar,
bool HasInit)
846 :
Stmt(IfStmtClass, Empty) {
855 bool HasElse = Else !=
nullptr;
856 bool HasVar = Var !=
nullptr;
857 bool HasInit = Init !=
nullptr;
859 totalSizeToAlloc<Stmt *, SourceLocation>(
860 NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
863 IfStmt(Ctx, IL, IsConstexpr, Init, Var, Cond, Then, EL, Else);
869 totalSizeToAlloc<Stmt *, SourceLocation>(
870 NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
876 auto *DS = getConditionVariableDeclStmt();
879 return cast<VarDecl>(DS->getSingleDecl());
883 assert(hasVarStorage() &&
884 "This if statement has no storage for a condition variable!");
887 getTrailingObjects<Stmt *>()[varOffset()] =
nullptr;
892 getTrailingObjects<Stmt *>()[varOffset()] =
new (Ctx)
897 return isa<ObjCAvailabilityCheckExpr>(getCond());
903 :
Stmt(ForStmtClass), LParenLoc(LP), RParenLoc(RP)
905 SubExprs[INIT] = Init;
907 SubExprs[COND] = Cond;
909 SubExprs[BODY] = Body;
914 if (!SubExprs[CONDVAR])
917 auto *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
918 return cast<VarDecl>(DS->getSingleDecl());
923 SubExprs[CONDVAR] =
nullptr;
934 :
Stmt(SwitchStmtClass), FirstCase(
nullptr) {
935 bool HasInit = Init !=
nullptr;
936 bool HasVar = Var !=
nullptr;
951 SwitchStmt::SwitchStmt(
EmptyShell Empty,
bool HasInit,
bool HasVar)
952 :
Stmt(SwitchStmtClass, Empty) {
960 bool HasInit = Init !=
nullptr;
961 bool HasVar = Var !=
nullptr;
963 totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
965 return new (Mem)
SwitchStmt(Ctx, Init, Var, Cond);
971 totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
980 return cast<VarDecl>(DS->getSingleDecl());
984 assert(hasVarStorage() &&
985 "This switch statement has no storage for a condition variable!");
988 getTrailingObjects<Stmt *>()[varOffset()] =
nullptr;
993 getTrailingObjects<Stmt *>()[varOffset()] =
new (Ctx)
999 :
Stmt(WhileStmtClass) {
1000 bool HasVar = Var !=
nullptr;
1011 WhileStmt::WhileStmt(
EmptyShell Empty,
bool HasVar)
1012 :
Stmt(WhileStmtClass, Empty) {
1018 bool HasVar = Var !=
nullptr;
1020 Ctx.
Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1022 return new (Mem)
WhileStmt(Ctx, Var, Cond, Body, WL);
1027 Ctx.
Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1036 return cast<VarDecl>(DS->getSingleDecl());
1040 assert(hasVarStorage() &&
1041 "This while statement has no storage for a condition variable!");
1044 getTrailingObjects<Stmt *>()[varOffset()] =
nullptr;
1049 getTrailingObjects<Stmt *>()[varOffset()] =
new (Ctx)
1055 if (
auto *E = dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
1056 return E->getLabel();
1062 :
Stmt(ReturnStmtClass), RetExpr(E) {
1063 bool HasNRVOCandidate = NRVOCandidate !=
nullptr;
1065 if (HasNRVOCandidate)
1066 setNRVOCandidate(NRVOCandidate);
1070 ReturnStmt::ReturnStmt(
EmptyShell Empty,
bool HasNRVOCandidate)
1071 :
Stmt(ReturnStmtClass, Empty) {
1077 bool HasNRVOCandidate = NRVOCandidate !=
nullptr;
1078 void *Mem = Ctx.
Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1080 return new (Mem)
ReturnStmt(RL, E, NRVOCandidate);
1084 bool HasNRVOCandidate) {
1085 void *Mem = Ctx.
Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1094 bool CaseStmtIsGNURange = rhs !=
nullptr;
1096 totalSizeToAlloc<Stmt *, SourceLocation>(
1097 NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1099 return new (Mem)
CaseStmt(lhs, rhs, caseLoc, ellipsisLoc, colonLoc);
1103 bool CaseStmtIsGNURange) {
1105 totalSizeToAlloc<Stmt *, SourceLocation>(
1106 NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1113 :
Stmt(SEHTryStmtClass), IsCXXTry(IsCXXTry), TryLoc(TryLoc) {
1114 Children[TRY] = TryBlock;
1115 Children[HANDLER] = Handler;
1121 return new(
C)
SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
1133 :
Stmt(SEHExceptStmtClass), Loc(Loc) {
1134 Children[FILTER_EXPR] = FilterExpr;
1135 Children[
BLOCK] = Block;
1144 :
Stmt(SEHFinallyStmtClass), Loc(Loc), Block(Block) {}
1153 : VarAndKind(Var, Kind), Loc(Loc) {
1156 assert(!Var &&
"'this' capture cannot have a variable!");
1159 assert(Var &&
"capturing by reference must have a variable!");
1162 assert(Var &&
"capturing by copy must have a variable!");
1169 "captures by copy are expected to have a scalar type!");
1173 "Variable-length array type capture cannot have a variable!");
1180 return VarAndKind.getInt();
1185 "No variable available for 'this' or VAT capture");
1186 return VarAndKind.getPointer();
1193 unsigned FirstCaptureOffset = llvm::alignTo(Size,
alignof(
Capture));
1195 return reinterpret_cast<Capture *
>(
1196 reinterpret_cast<char *
>(
const_cast<CapturedStmt *
>(
this))
1197 + FirstCaptureOffset);
1205 :
Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
1206 CapDeclAndKind(CD,
Kind), TheRecordDecl(RD) {
1207 assert( S &&
"null captured statement");
1208 assert(CD &&
"null captured declaration for captured statement");
1209 assert(RD &&
"null record declaration for captured statement");
1212 Stmt **Stored = getStoredStmts();
1213 for (
unsigned I = 0, N = NumCaptures; I != N; ++I)
1214 *Stored++ = CaptureInits[I];
1220 Capture *Buffer = getStoredCaptures();
1221 std::copy(Captures.begin(), Captures.end(), Buffer);
1224 CapturedStmt::CapturedStmt(
EmptyShell Empty,
unsigned NumCaptures)
1225 :
Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
1227 getStoredStmts()[NumCaptures] =
nullptr;
1245 assert(CaptureInits.size() == Captures.size() &&
"wrong number of arguments");
1247 unsigned Size =
sizeof(
CapturedStmt) +
sizeof(
Stmt *) * (Captures.size() + 1);
1248 if (!Captures.empty()) {
1250 Size = llvm::alignTo(Size,
alignof(
Capture));
1251 Size +=
sizeof(
Capture) * Captures.size();
1254 void *Mem = Context.
Allocate(Size);
1255 return new (Mem)
CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
1259 unsigned NumCaptures) {
1261 if (NumCaptures > 0) {
1263 Size = llvm::alignTo(Size,
alignof(
Capture));
1264 Size +=
sizeof(
Capture) * NumCaptures;
1267 void *Mem = Context.
Allocate(Size);
1273 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1281 return CapDeclAndKind.getPointer();
1285 return CapDeclAndKind.getPointer();
1290 assert(D &&
"null CapturedDecl");
1291 CapDeclAndKind.setPointer(D);
1296 return CapDeclAndKind.getInt();
1301 CapDeclAndKind.setInt(Kind);
1306 if (!I.capturesVariable() && !I.capturesVariableByCopy())
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
void setConditionVariable(const ASTContext &C, VarDecl *V)
Defines the clang::ASTContext interface.
Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var=nullptr)
Create a new capture.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
const DeclStmt * getConditionVariableDeclStmt() const
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
Stmt - This represents one statement.
IfStmt - This represents an if/then/else.
VarDecl * getCapturedVar() const
Retrieve the declaration of the variable being captured.
C Language Family Type Representation.
Represents an attribute applied to a statement.
llvm::iterator_range< child_iterator > child_range
const TargetInfo & getTargetInfo() const
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr *> Attrs, Stmt *SubStmt)
static void addStmtClass(const StmtClass s)
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
void setInputExpr(unsigned i, Expr *E)
void setInputExpr(unsigned i, Expr *E)
Represents a variable declaration or definition.
unsigned AnalyzeAsmString(SmallVectorImpl< AsmStringPiece > &Pieces, const ASTContext &C, unsigned &DiagOffs) const
AnalyzeAsmString - Analyze the asm string of the current asm, decomposing it into pieces...
const char * getName() const
const Expr * getExprStmt() const
Defines the Objective-C statement AST node classes.
static StringRef bytes(const std::vector< T, Allocator > &v)
int getNamedOperand(StringRef SymbolicName) const
getNamedOperand - Given a symbolic operand reference like %[foo], translate this into a numeric value...
Defines the clang::Expr interface and subclasses for C++ expressions.
static struct StmtClassNameTable StmtClassInfo[Stmt::lastStmtConstant+1]
const char * getStmtClassName() const
Represents a struct/union/class.
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
SourceLocation getBeginLoc() const LLVM_READONLY
bool isReferenceType() const
Token - This structure provides full information about a lexed token.
void setCapturedDecl(CapturedDecl *D)
Set the outlined function declaration.
bool hasNoAsmVariants() const
Return true if {|} are normal characters in the asm string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
WhileStmtBitfields WhileStmtBits
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD)
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const Expr * getOutputExpr(unsigned i) const
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Expr * getOutputExpr(unsigned i)
SwitchStmtBitfields SwitchStmtBits
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt *> Stmts, SourceLocation LB, SourceLocation RB)
CaseStmt - Represent a case statement.
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
ReturnStmtBitfields ReturnStmtBits
unsigned getNumPlusOperands() const
getNumPlusOperands - Return the number of output operands that have a "+" constraint.
bool isScalarType() const
Represents the body of a CapturedStmt, and serves as its DeclContext.
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
MSAsmStmt(const ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, bool issimple, bool isvolatile, ArrayRef< Token > asmtoks, unsigned numoutputs, unsigned numinputs, ArrayRef< StringRef > constraints, ArrayRef< Expr *> exprs, StringRef asmstr, ArrayRef< StringRef > clobbers, SourceLocation endloc)
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
StringRef getClobber(unsigned i) const
llvm::iterator_range< const_child_iterator > const_child_range
CompoundStmt - This represents a group of statements like { stmt stmt }.
Describes the capture of either a variable, or 'this', or variable-length array type.
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable for this if statement.
Exposes information about the current target.
This represents one expression.
Stmt * IgnoreContainers(bool IgnoreCaptured=false)
Skip no-op (attributed, compound) container stmts and skip captured stmt at the top, if IgnoreCaptured is true.
const T * castAs() const
Member-template castAs<specific type>.
static ReturnStmt * CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate)
Create an empty return statement, optionally with storage for an NRVO candidate.
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
VariableCaptureKind getCaptureKind() const
Determine the kind of capture.
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
CompoundStmtBitfields CompoundStmtBits
static StringRef copyIntoContext(const ASTContext &C, StringRef str)
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
SourceLocation getEnd() const
Expr * getInputExpr(unsigned i)
Expr * getOutputExpr(unsigned i)
StringRef getClobber(unsigned i) const
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL)
Create a while statement.
The result type of a method or function.
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable of this while statement.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
SourceLocation getEndLoc() const LLVM_READONLY
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
void setConditionVariable(const ASTContext &Ctx, VarDecl *VD)
Set the condition variable in this switch statement.
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond)
Create a switch statement.
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
This captures a statement into a function.
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Encodes a location in the source.
StringRef getLabelName(unsigned i) const
IfStmtBitfields IfStmtBits
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Represents the declaration of a label.
bool capturesVariable() const
Determine whether this capture handles a variable (by reference).
ForStmtBitfields ForStmtBits
GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, unsigned numoutputs, unsigned numinputs, IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, StringLiteral **clobbers, unsigned numlabels, SourceLocation rparenloc)
int64_t getID(const ASTContext &Context) const
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
static WhileStmt * CreateEmpty(const ASTContext &Ctx, bool HasVar)
Create an empty while statement optionally with storage for a condition variable. ...
Expr * getInputExpr(unsigned i)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
A placeholder type used to construct an empty shell of a type, that will be filled in later (e...
void * Allocate(size_t Size, unsigned Align=8) const
AddrLabelExpr - The GNU address of label extension, representing &&label.
Dataflow Directional Tag Classes.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
const Stmt * stripLabelLikeStatements() const
Strip off all label-like statements.
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
static LLVM_ATTRIBUTE_UNUSED void check_implementations()
Check whether the various Stmt classes implement their member functions.
char getModifier() const
getModifier - Get the modifier for this operand, if present.
bool isObjCAvailabilityCheck() const
llvm::BumpPtrAllocator & getAllocator() const
static CompoundStmt * CreateEmpty(const ASTContext &C, unsigned NumStmts)
bool capturesVariableByCopy() const
Determine whether this capture handles a variable by copy.
SwitchStmt - This represents a 'switch' stmt.
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
This file defines OpenMP AST classes for executable directives and clauses.
AddrLabelExpr * getLabelExpr(unsigned i) const
Base for LValueReferenceType and RValueReferenceType.
const Expr * getInputExpr(unsigned i) const
ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP)
SourceManager & getSourceManager()
SEHFinallyStmt * getFinallyHandler() const
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
void Deallocate(void *Ptr) const
Defines the clang::SourceLocation class and associated facilities.
WhileStmt - This represents a 'while' stmt.
static IfStmt * CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar, bool HasInit)
Create an empty IfStmt optionally with storage for an else statement, condition variable and init exp...
VariableCaptureKind
The different capture forms: by 'this', by reference, capture for variable-length array type etc...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
static CaseStmt * CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange)
Build an empty case statement.
CapturedRegionKind
The different kinds of captured statement.
static SwitchStmt * CreateEmpty(const ASTContext &Ctx, bool HasInit, bool HasVar)
Create an empty switch statement optionally with storage for an init expression and a condition varia...
static StmtClassNameTable & getStmtInfoTableEntry(Stmt::StmtClass E)
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
This class handles loading and caching of source files into memory.
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
static void EnableStatistics()
#define BLOCK(DERIVED, BASE)