clang  3.8.0
Stmt.cpp
Go to the documentation of this file.
1 //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Stmt class and statement subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/ExprCXX.h"
17 #include "clang/AST/ExprObjC.h"
18 #include "clang/AST/ExprOpenMP.h"
19 #include "clang/AST/Stmt.h"
20 #include "clang/AST/StmtCXX.h"
21 #include "clang/AST/StmtObjC.h"
22 #include "clang/AST/StmtOpenMP.h"
23 #include "clang/AST/Type.h"
24 #include "clang/Basic/CharInfo.h"
25 #include "clang/Basic/TargetInfo.h"
26 #include "clang/Lex/Token.h"
27 #include "llvm/ADT/StringExtras.h"
28 #include "llvm/Support/raw_ostream.h"
29 using namespace clang;
30 
31 static struct StmtClassNameTable {
32  const char *Name;
33  unsigned Counter;
34  unsigned Size;
35 } StmtClassInfo[Stmt::lastStmtConstant+1];
36 
37 static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
38  static bool Initialized = false;
39  if (Initialized)
40  return StmtClassInfo[E];
41 
42  // Intialize the table on the first use.
43  Initialized = true;
44 #define ABSTRACT_STMT(STMT)
45 #define STMT(CLASS, PARENT) \
46  StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
47  StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
48 #include "clang/AST/StmtNodes.inc"
49 
50  return StmtClassInfo[E];
51 }
52 
53 void *Stmt::operator new(size_t bytes, const ASTContext& C,
54  unsigned alignment) {
55  return ::operator new(bytes, C, alignment);
56 }
57 
58 const char *Stmt::getStmtClassName() const {
59  return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
60 }
61 
62 void Stmt::PrintStats() {
63  // Ensure the table is primed.
64  getStmtInfoTableEntry(Stmt::NullStmtClass);
65 
66  unsigned sum = 0;
67  llvm::errs() << "\n*** Stmt/Expr Stats:\n";
68  for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
69  if (StmtClassInfo[i].Name == nullptr) continue;
70  sum += StmtClassInfo[i].Counter;
71  }
72  llvm::errs() << " " << sum << " stmts/exprs total.\n";
73  sum = 0;
74  for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
75  if (StmtClassInfo[i].Name == nullptr) continue;
76  if (StmtClassInfo[i].Counter == 0) continue;
77  llvm::errs() << " " << StmtClassInfo[i].Counter << " "
78  << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
79  << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
80  << " bytes)\n";
82  }
83 
84  llvm::errs() << "Total bytes = " << sum << "\n";
85 }
86 
87 void Stmt::addStmtClass(StmtClass s) {
89 }
90 
91 bool Stmt::StatisticsEnabled = false;
92 void Stmt::EnableStatistics() {
93  StatisticsEnabled = true;
94 }
95 
96 Stmt *Stmt::IgnoreImplicit() {
97  Stmt *s = this;
98 
99  if (auto *ewc = dyn_cast<ExprWithCleanups>(s))
100  s = ewc->getSubExpr();
101 
102  if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s))
103  s = mte->GetTemporaryExpr();
104 
105  if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s))
106  s = bte->getSubExpr();
107 
108  while (auto *ice = dyn_cast<ImplicitCastExpr>(s))
109  s = ice->getSubExpr();
110 
111  return s;
112 }
113 
114 /// \brief Skip no-op (attributed, compound) container stmts and skip captured
115 /// stmt at the top, if \a IgnoreCaptured is true.
116 Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) {
117  Stmt *S = this;
118  if (IgnoreCaptured)
119  if (auto CapS = dyn_cast_or_null<CapturedStmt>(S))
120  S = CapS->getCapturedStmt();
121  while (true) {
122  if (auto AS = dyn_cast_or_null<AttributedStmt>(S))
123  S = AS->getSubStmt();
124  else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
125  if (CS->size() != 1)
126  break;
127  S = CS->body_back();
128  } else
129  break;
130  }
131  return S;
132 }
133 
134 /// \brief Strip off all label-like statements.
135 ///
136 /// This will strip off label statements, case statements, attributed
137 /// statements and default statements recursively.
138 const Stmt *Stmt::stripLabelLikeStatements() const {
139  const Stmt *S = this;
140  while (true) {
141  if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
142  S = LS->getSubStmt();
143  else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
144  S = SC->getSubStmt();
145  else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
146  S = AS->getSubStmt();
147  else
148  return S;
149  }
150 }
151 
152 namespace {
153  struct good {};
154  struct bad {};
155 
156  // These silly little functions have to be static inline to suppress
157  // unused warnings, and they have to be defined to suppress other
158  // warnings.
159  static inline good is_good(good) { return good(); }
160 
161  typedef Stmt::child_range children_t();
162  template <class T> good implements_children(children_t T::*) {
163  return good();
164  }
165  LLVM_ATTRIBUTE_UNUSED
166  static inline bad implements_children(children_t Stmt::*) {
167  return bad();
168  }
169 
170  typedef SourceLocation getLocStart_t() const;
171  template <class T> good implements_getLocStart(getLocStart_t T::*) {
172  return good();
173  }
174  LLVM_ATTRIBUTE_UNUSED
175  static inline bad implements_getLocStart(getLocStart_t Stmt::*) {
176  return bad();
177  }
178 
179  typedef SourceLocation getLocEnd_t() const;
180  template <class T> good implements_getLocEnd(getLocEnd_t T::*) {
181  return good();
182  }
183  LLVM_ATTRIBUTE_UNUSED
184  static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) {
185  return bad();
186  }
187 
188 #define ASSERT_IMPLEMENTS_children(type) \
189  (void) is_good(implements_children(&type::children))
190 #define ASSERT_IMPLEMENTS_getLocStart(type) \
191  (void) is_good(implements_getLocStart(&type::getLocStart))
192 #define ASSERT_IMPLEMENTS_getLocEnd(type) \
193  (void) is_good(implements_getLocEnd(&type::getLocEnd))
194 }
195 
196 /// Check whether the various Stmt classes implement their member
197 /// functions.
198 LLVM_ATTRIBUTE_UNUSED
199 static inline void check_implementations() {
200 #define ABSTRACT_STMT(type)
201 #define STMT(type, base) \
202  ASSERT_IMPLEMENTS_children(type); \
203  ASSERT_IMPLEMENTS_getLocStart(type); \
204  ASSERT_IMPLEMENTS_getLocEnd(type);
205 #include "clang/AST/StmtNodes.inc"
206 }
207 
208 Stmt::child_range Stmt::children() {
209  switch (getStmtClass()) {
210  case Stmt::NoStmtClass: llvm_unreachable("statement without class");
211 #define ABSTRACT_STMT(type)
212 #define STMT(type, base) \
213  case Stmt::type##Class: \
214  return static_cast<type*>(this)->children();
215 #include "clang/AST/StmtNodes.inc"
216  }
217  llvm_unreachable("unknown statement kind!");
218 }
219 
220 // Amusing macro metaprogramming hack: check whether a class provides
221 // a more specific implementation of getSourceRange.
222 //
223 // See also Expr.cpp:getExprLoc().
224 namespace {
225  /// This implementation is used when a class provides a custom
226  /// implementation of getSourceRange.
227  template <class S, class T>
228  SourceRange getSourceRangeImpl(const Stmt *stmt,
229  SourceRange (T::*v)() const) {
230  return static_cast<const S*>(stmt)->getSourceRange();
231  }
232 
233  /// This implementation is used when a class doesn't provide a custom
234  /// implementation of getSourceRange. Overload resolution should pick it over
235  /// the implementation above because it's more specialized according to
236  /// function template partial ordering.
237  template <class S>
238  SourceRange getSourceRangeImpl(const Stmt *stmt,
239  SourceRange (Stmt::*v)() const) {
240  return SourceRange(static_cast<const S*>(stmt)->getLocStart(),
241  static_cast<const S*>(stmt)->getLocEnd());
242  }
243 }
244 
245 SourceRange Stmt::getSourceRange() const {
246  switch (getStmtClass()) {
247  case Stmt::NoStmtClass: llvm_unreachable("statement without class");
248 #define ABSTRACT_STMT(type)
249 #define STMT(type, base) \
250  case Stmt::type##Class: \
251  return getSourceRangeImpl<type>(this, &type::getSourceRange);
252 #include "clang/AST/StmtNodes.inc"
253  }
254  llvm_unreachable("unknown statement kind!");
255 }
256 
257 SourceLocation Stmt::getLocStart() const {
258 // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
259  switch (getStmtClass()) {
260  case Stmt::NoStmtClass: llvm_unreachable("statement without class");
261 #define ABSTRACT_STMT(type)
262 #define STMT(type, base) \
263  case Stmt::type##Class: \
264  return static_cast<const type*>(this)->getLocStart();
265 #include "clang/AST/StmtNodes.inc"
266  }
267  llvm_unreachable("unknown statement kind");
268 }
269 
270 SourceLocation Stmt::getLocEnd() const {
271  switch (getStmtClass()) {
272  case Stmt::NoStmtClass: llvm_unreachable("statement without class");
273 #define ABSTRACT_STMT(type)
274 #define STMT(type, base) \
275  case Stmt::type##Class: \
276  return static_cast<const type*>(this)->getLocEnd();
277 #include "clang/AST/StmtNodes.inc"
278  }
279  llvm_unreachable("unknown statement kind");
280 }
281 
284  : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {
285  CompoundStmtBits.NumStmts = Stmts.size();
286  assert(CompoundStmtBits.NumStmts == Stmts.size() &&
287  "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
288 
289  if (Stmts.size() == 0) {
290  Body = nullptr;
291  return;
292  }
293 
294  Body = new (C) Stmt*[Stmts.size()];
295  std::copy(Stmts.begin(), Stmts.end(), Body);
296 }
297 
299  if (Body)
300  C.Deallocate(Body);
301  CompoundStmtBits.NumStmts = Stmts.size();
302  assert(CompoundStmtBits.NumStmts == Stmts.size() &&
303  "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
304 
305  Body = new (C) Stmt*[Stmts.size()];
306  std::copy(Stmts.begin(), Stmts.end(), Body);
307 }
308 
309 const char *LabelStmt::getName() const {
310  return getDecl()->getIdentifier()->getNameStart();
311 }
312 
314  ArrayRef<const Attr*> Attrs,
315  Stmt *SubStmt) {
316  assert(!Attrs.empty() && "Attrs should not be empty");
317  void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(),
318  llvm::alignOf<AttributedStmt>());
319  return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
320 }
321 
323  unsigned NumAttrs) {
324  assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
325  void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs,
326  llvm::alignOf<AttributedStmt>());
327  return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
328 }
329 
330 std::string AsmStmt::generateAsmString(const ASTContext &C) const {
331  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
332  return gccAsmStmt->generateAsmString(C);
333  if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
334  return msAsmStmt->generateAsmString(C);
335  llvm_unreachable("unknown asm statement kind!");
336 }
337 
338 StringRef AsmStmt::getOutputConstraint(unsigned i) const {
339  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
340  return gccAsmStmt->getOutputConstraint(i);
341  if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
342  return msAsmStmt->getOutputConstraint(i);
343  llvm_unreachable("unknown asm statement kind!");
344 }
345 
346 const Expr *AsmStmt::getOutputExpr(unsigned i) const {
347  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
348  return gccAsmStmt->getOutputExpr(i);
349  if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
350  return msAsmStmt->getOutputExpr(i);
351  llvm_unreachable("unknown asm statement kind!");
352 }
353 
354 StringRef AsmStmt::getInputConstraint(unsigned i) const {
355  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
356  return gccAsmStmt->getInputConstraint(i);
357  if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
358  return msAsmStmt->getInputConstraint(i);
359  llvm_unreachable("unknown asm statement kind!");
360 }
361 
362 const Expr *AsmStmt::getInputExpr(unsigned i) const {
363  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
364  return gccAsmStmt->getInputExpr(i);
365  if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
366  return msAsmStmt->getInputExpr(i);
367  llvm_unreachable("unknown asm statement kind!");
368 }
369 
370 StringRef AsmStmt::getClobber(unsigned i) const {
371  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
372  return gccAsmStmt->getClobber(i);
373  if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
374  return msAsmStmt->getClobber(i);
375  llvm_unreachable("unknown asm statement kind!");
376 }
377 
378 /// getNumPlusOperands - Return the number of output operands that have a "+"
379 /// constraint.
380 unsigned AsmStmt::getNumPlusOperands() const {
381  unsigned Res = 0;
382  for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
383  if (isOutputPlusConstraint(i))
384  ++Res;
385  return Res;
386 }
387 
389  assert(isOperand() && "Only Operands can have modifiers.");
390  return isLetter(Str[0]) ? Str[0] : '\0';
391 }
392 
393 StringRef GCCAsmStmt::getClobber(unsigned i) const {
394  return getClobberStringLiteral(i)->getString();
395 }
396 
398  return cast<Expr>(Exprs[i]);
399 }
400 
401 /// getOutputConstraint - Return the constraint string for the specified
402 /// output operand. All output constraints are known to be non-empty (either
403 /// '=' or '+').
404 StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
406 }
407 
409  return cast<Expr>(Exprs[i + NumOutputs]);
410 }
411 void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
412  Exprs[i + NumOutputs] = E;
413 }
414 
415 /// getInputConstraint - Return the specified input constraint. Unlike output
416 /// constraints, these can be empty.
417 StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
419 }
420 
421 void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
422  IdentifierInfo **Names,
423  StringLiteral **Constraints,
424  Stmt **Exprs,
425  unsigned NumOutputs,
426  unsigned NumInputs,
427  StringLiteral **Clobbers,
428  unsigned NumClobbers) {
429  this->NumOutputs = NumOutputs;
430  this->NumInputs = NumInputs;
431  this->NumClobbers = NumClobbers;
432 
433  unsigned NumExprs = NumOutputs + NumInputs;
434 
435  C.Deallocate(this->Names);
436  this->Names = new (C) IdentifierInfo*[NumExprs];
437  std::copy(Names, Names + NumExprs, this->Names);
438 
439  C.Deallocate(this->Exprs);
440  this->Exprs = new (C) Stmt*[NumExprs];
441  std::copy(Exprs, Exprs + NumExprs, this->Exprs);
442 
443  C.Deallocate(this->Constraints);
444  this->Constraints = new (C) StringLiteral*[NumExprs];
445  std::copy(Constraints, Constraints + NumExprs, this->Constraints);
446 
447  C.Deallocate(this->Clobbers);
448  this->Clobbers = new (C) StringLiteral*[NumClobbers];
449  std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
450 }
451 
452 /// getNamedOperand - Given a symbolic operand reference like %[foo],
453 /// translate this into a numeric value needed to reference the same operand.
454 /// This returns -1 if the operand name is invalid.
455 int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
456  unsigned NumPlusOperands = 0;
457 
458  // Check if this is an output operand.
459  for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
460  if (getOutputName(i) == SymbolicName)
461  return i;
462  }
463 
464  for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
465  if (getInputName(i) == SymbolicName)
466  return getNumOutputs() + NumPlusOperands + i;
467 
468  // Not found.
469  return -1;
470 }
471 
472 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
473 /// it into pieces. If the asm string is erroneous, emit errors and return
474 /// true, otherwise return false.
476  const ASTContext &C, unsigned &DiagOffs) const {
477  StringRef Str = getAsmString()->getString();
478  const char *StrStart = Str.begin();
479  const char *StrEnd = Str.end();
480  const char *CurPtr = StrStart;
481 
482  // "Simple" inline asms have no constraints or operands, just convert the asm
483  // string to escape $'s.
484  if (isSimple()) {
485  std::string Result;
486  for (; CurPtr != StrEnd; ++CurPtr) {
487  switch (*CurPtr) {
488  case '$':
489  Result += "$$";
490  break;
491  default:
492  Result += *CurPtr;
493  break;
494  }
495  }
496  Pieces.push_back(AsmStringPiece(Result));
497  return 0;
498  }
499 
500  // CurStringPiece - The current string that we are building up as we scan the
501  // asm string.
502  std::string CurStringPiece;
503 
504  bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
505 
506  while (1) {
507  // Done with the string?
508  if (CurPtr == StrEnd) {
509  if (!CurStringPiece.empty())
510  Pieces.push_back(AsmStringPiece(CurStringPiece));
511  return 0;
512  }
513 
514  char CurChar = *CurPtr++;
515  switch (CurChar) {
516  case '$': CurStringPiece += "$$"; continue;
517  case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
518  case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
519  case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
520  case '%':
521  break;
522  default:
523  CurStringPiece += CurChar;
524  continue;
525  }
526 
527  // Escaped "%" character in asm string.
528  if (CurPtr == StrEnd) {
529  // % at end of string is invalid (no escape).
530  DiagOffs = CurPtr-StrStart-1;
531  return diag::err_asm_invalid_escape;
532  }
533 
534  char EscapedChar = *CurPtr++;
535  if (EscapedChar == '%') { // %% -> %
536  // Escaped percentage sign.
537  CurStringPiece += '%';
538  continue;
539  }
540 
541  if (EscapedChar == '=') { // %= -> Generate an unique ID.
542  CurStringPiece += "${:uid}";
543  continue;
544  }
545 
546  // Otherwise, we have an operand. If we have accumulated a string so far,
547  // add it to the Pieces list.
548  if (!CurStringPiece.empty()) {
549  Pieces.push_back(AsmStringPiece(CurStringPiece));
550  CurStringPiece.clear();
551  }
552 
553  // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
554  // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
555 
556  const char *Begin = CurPtr - 1; // Points to the character following '%'.
557  const char *Percent = Begin - 1; // Points to '%'.
558 
559  if (isLetter(EscapedChar)) {
560  if (CurPtr == StrEnd) { // Premature end.
561  DiagOffs = CurPtr-StrStart-1;
562  return diag::err_asm_invalid_escape;
563  }
564  EscapedChar = *CurPtr++;
565  }
566 
567  const TargetInfo &TI = C.getTargetInfo();
568  const SourceManager &SM = C.getSourceManager();
569  const LangOptions &LO = C.getLangOpts();
570 
571  // Handle operands that don't have asmSymbolicName (e.g., %x4).
572  if (isDigit(EscapedChar)) {
573  // %n - Assembler operand n
574  unsigned N = 0;
575 
576  --CurPtr;
577  while (CurPtr != StrEnd && isDigit(*CurPtr))
578  N = N*10 + ((*CurPtr++)-'0');
579 
580  unsigned NumOperands =
582  if (N >= NumOperands) {
583  DiagOffs = CurPtr-StrStart-1;
584  return diag::err_asm_invalid_operand_number;
585  }
586 
587  // Str contains "x4" (Operand without the leading %).
588  std::string Str(Begin, CurPtr - Begin);
589 
590  // (BeginLoc, EndLoc) represents the range of the operand we are currently
591  // processing. Unlike Str, the range includes the leading '%'.
592  SourceLocation BeginLoc =
593  getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
594  SourceLocation EndLoc =
595  getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI);
596 
597  Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
598  continue;
599  }
600 
601  // Handle operands that have asmSymbolicName (e.g., %x[foo]).
602  if (EscapedChar == '[') {
603  DiagOffs = CurPtr-StrStart-1;
604 
605  // Find the ']'.
606  const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
607  if (NameEnd == nullptr)
608  return diag::err_asm_unterminated_symbolic_operand_name;
609  if (NameEnd == CurPtr)
610  return diag::err_asm_empty_symbolic_operand_name;
611 
612  StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
613 
614  int N = getNamedOperand(SymbolicName);
615  if (N == -1) {
616  // Verify that an operand with that name exists.
617  DiagOffs = CurPtr-StrStart;
618  return diag::err_asm_unknown_symbolic_operand_name;
619  }
620 
621  // Str contains "x[foo]" (Operand without the leading %).
622  std::string Str(Begin, NameEnd + 1 - Begin);
623 
624  // (BeginLoc, EndLoc) represents the range of the operand we are currently
625  // processing. Unlike Str, the range includes the leading '%'.
626  SourceLocation BeginLoc =
627  getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
628  SourceLocation EndLoc =
629  getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI);
630 
631  Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
632 
633  CurPtr = NameEnd+1;
634  continue;
635  }
636 
637  DiagOffs = CurPtr-StrStart-1;
638  return diag::err_asm_invalid_escape;
639  }
640 }
641 
642 /// Assemble final IR asm string (GCC-style).
643 std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
644  // Analyze the asm string to decompose it into its pieces. We know that Sema
645  // has already done this, so it is guaranteed to be successful.
647  unsigned DiagOffs;
648  AnalyzeAsmString(Pieces, C, DiagOffs);
649 
650  std::string AsmString;
651  for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
652  if (Pieces[i].isString())
653  AsmString += Pieces[i].getString();
654  else if (Pieces[i].getModifier() == '\0')
655  AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
656  else
657  AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
658  Pieces[i].getModifier() + '}';
659  }
660  return AsmString;
661 }
662 
663 /// Assemble final IR asm string (MS-style).
664 std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
665  // FIXME: This needs to be translated into the IR string representation.
666  return AsmStr;
667 }
668 
670  return cast<Expr>(Exprs[i]);
671 }
672 
674  return cast<Expr>(Exprs[i + NumOutputs]);
675 }
676 void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
677  Exprs[i + NumOutputs] = E;
678 }
679 
680 //===----------------------------------------------------------------------===//
681 // Constructors
682 //===----------------------------------------------------------------------===//
683 
685  bool issimple, bool isvolatile, unsigned numoutputs,
686  unsigned numinputs, IdentifierInfo **names,
687  StringLiteral **constraints, Expr **exprs,
688  StringLiteral *asmstr, unsigned numclobbers,
689  StringLiteral **clobbers, SourceLocation rparenloc)
690  : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
691  numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) {
692 
693  unsigned NumExprs = NumOutputs + NumInputs;
694 
695  Names = new (C) IdentifierInfo*[NumExprs];
696  std::copy(names, names + NumExprs, Names);
697 
698  Exprs = new (C) Stmt*[NumExprs];
699  std::copy(exprs, exprs + NumExprs, Exprs);
700 
701  Constraints = new (C) StringLiteral*[NumExprs];
702  std::copy(constraints, constraints + NumExprs, Constraints);
703 
704  Clobbers = new (C) StringLiteral*[NumClobbers];
705  std::copy(clobbers, clobbers + NumClobbers, Clobbers);
706 }
707 
709  SourceLocation lbraceloc, bool issimple, bool isvolatile,
710  ArrayRef<Token> asmtoks, unsigned numoutputs,
711  unsigned numinputs,
712  ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
713  StringRef asmstr, ArrayRef<StringRef> clobbers,
714  SourceLocation endloc)
715  : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
716  numinputs, clobbers.size()), LBraceLoc(lbraceloc),
717  EndLoc(endloc), NumAsmToks(asmtoks.size()) {
718 
719  initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
720 }
721 
722 static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
723  return str.copy(C);
724 }
725 
726 void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
727  ArrayRef<Token> asmtoks,
728  ArrayRef<StringRef> constraints,
729  ArrayRef<Expr*> exprs,
730  ArrayRef<StringRef> clobbers) {
731  assert(NumAsmToks == asmtoks.size());
732  assert(NumClobbers == clobbers.size());
733 
734  assert(exprs.size() == NumOutputs + NumInputs);
735  assert(exprs.size() == constraints.size());
736 
737  AsmStr = copyIntoContext(C, asmstr);
738 
739  Exprs = new (C) Stmt*[exprs.size()];
740  std::copy(exprs.begin(), exprs.end(), Exprs);
741 
742  AsmToks = new (C) Token[asmtoks.size()];
743  std::copy(asmtoks.begin(), asmtoks.end(), AsmToks);
744 
745  Constraints = new (C) StringRef[exprs.size()];
746  std::transform(constraints.begin(), constraints.end(), Constraints,
747  [&](StringRef Constraint) {
748  return copyIntoContext(C, Constraint);
749  });
750 
751  Clobbers = new (C) StringRef[NumClobbers];
752  // FIXME: Avoid the allocation/copy if at all possible.
753  std::transform(clobbers.begin(), clobbers.end(), Clobbers,
754  [&](StringRef Clobber) {
755  return copyIntoContext(C, Clobber);
756  });
757 }
758 
760  Stmt *then, SourceLocation EL, Stmt *elsev)
761  : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
762 {
763  setConditionVariable(C, var);
764  SubExprs[COND] = cond;
765  SubExprs[THEN] = then;
766  SubExprs[ELSE] = elsev;
767 }
768 
770  if (!SubExprs[VAR])
771  return nullptr;
772 
773  DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
774  return cast<VarDecl>(DS->getSingleDecl());
775 }
776 
778  if (!V) {
779  SubExprs[VAR] = nullptr;
780  return;
781  }
782 
783  SourceRange VarRange = V->getSourceRange();
784  SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
785  VarRange.getEnd());
786 }
787 
788 ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
789  Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
790  SourceLocation RP)
791  : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
792 {
793  SubExprs[INIT] = Init;
794  setConditionVariable(C, condVar);
795  SubExprs[COND] = Cond;
796  SubExprs[INC] = Inc;
797  SubExprs[BODY] = Body;
798 }
799 
801  if (!SubExprs[CONDVAR])
802  return nullptr;
803 
804  DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
805  return cast<VarDecl>(DS->getSingleDecl());
806 }
807 
809  if (!V) {
810  SubExprs[CONDVAR] = nullptr;
811  return;
812  }
813 
814  SourceRange VarRange = V->getSourceRange();
815  SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
816  VarRange.getEnd());
817 }
818 
820  : Stmt(SwitchStmtClass), FirstCase(nullptr, false) {
821  setConditionVariable(C, Var);
822  SubExprs[COND] = cond;
823  SubExprs[BODY] = nullptr;
824 }
825 
827  if (!SubExprs[VAR])
828  return nullptr;
829 
830  DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
831  return cast<VarDecl>(DS->getSingleDecl());
832 }
833 
835  if (!V) {
836  SubExprs[VAR] = nullptr;
837  return;
838  }
839 
840  SourceRange VarRange = V->getSourceRange();
841  SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
842  VarRange.getEnd());
843 }
844 
846  if (isa<CaseStmt>(this))
847  return cast<CaseStmt>(this)->getSubStmt();
848  return cast<DefaultStmt>(this)->getSubStmt();
849 }
850 
851 WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
852  SourceLocation WL)
853  : Stmt(WhileStmtClass) {
854  setConditionVariable(C, Var);
855  SubExprs[COND] = cond;
856  SubExprs[BODY] = body;
857  WhileLoc = WL;
858 }
859 
861  if (!SubExprs[VAR])
862  return nullptr;
863 
864  DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
865  return cast<VarDecl>(DS->getSingleDecl());
866 }
867 
869  if (!V) {
870  SubExprs[VAR] = nullptr;
871  return;
872  }
873 
874  SourceRange VarRange = V->getSourceRange();
875  SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
876  VarRange.getEnd());
877 }
878 
879 // IndirectGotoStmt
881  if (AddrLabelExpr *E =
882  dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
883  return E->getLabel();
884  return nullptr;
885 }
886 
887 // ReturnStmt
889  return cast_or_null<Expr>(RetExpr);
890 }
892  return cast_or_null<Expr>(RetExpr);
893 }
894 
895 SEHTryStmt::SEHTryStmt(bool IsCXXTry,
896  SourceLocation TryLoc,
897  Stmt *TryBlock,
898  Stmt *Handler)
899  : Stmt(SEHTryStmtClass),
900  IsCXXTry(IsCXXTry),
901  TryLoc(TryLoc)
902 {
903  Children[TRY] = TryBlock;
904  Children[HANDLER] = Handler;
905 }
906 
907 SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
908  SourceLocation TryLoc, Stmt *TryBlock,
909  Stmt *Handler) {
910  return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
911 }
912 
914  return dyn_cast<SEHExceptStmt>(getHandler());
915 }
916 
918  return dyn_cast<SEHFinallyStmt>(getHandler());
919 }
920 
921 SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
922  Expr *FilterExpr,
923  Stmt *Block)
924  : Stmt(SEHExceptStmtClass),
925  Loc(Loc)
926 {
927  Children[FILTER_EXPR] = FilterExpr;
928  Children[BLOCK] = Block;
929 }
930 
932  Expr *FilterExpr, Stmt *Block) {
933  return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
934 }
935 
936 SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
937  Stmt *Block)
938  : Stmt(SEHFinallyStmtClass),
939  Loc(Loc),
940  Block(Block)
941 {}
942 
944  Stmt *Block) {
945  return new(C)SEHFinallyStmt(Loc,Block);
946 }
947 
949  VarDecl *Var)
950  : VarAndKind(Var, Kind), Loc(Loc) {
951  switch (Kind) {
952  case VCK_This:
953  assert(!Var && "'this' capture cannot have a variable!");
954  break;
955  case VCK_ByRef:
956  assert(Var && "capturing by reference must have a variable!");
957  break;
958  case VCK_ByCopy:
959  assert(Var && "capturing by copy must have a variable!");
960  assert(
961  (Var->getType()->isScalarType() || (Var->getType()->isReferenceType() &&
962  Var->getType()
963  ->castAs<ReferenceType>()
964  ->getPointeeType()
965  ->isScalarType())) &&
966  "captures by copy are expected to have a scalar type!");
967  break;
968  case VCK_VLAType:
969  assert(!Var &&
970  "Variable-length array type capture cannot have a variable!");
971  break;
972  }
973 }
974 
977  return VarAndKind.getInt();
978 }
979 
981  assert((capturesVariable() || capturesVariableByCopy()) &&
982  "No variable available for 'this' or VAT capture");
983  return VarAndKind.getPointer();
984 }
985 
986 CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
987  unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
988 
989  // Offset of the first Capture object.
990  unsigned FirstCaptureOffset =
991  llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
992 
993  return reinterpret_cast<Capture *>(
994  reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
995  + FirstCaptureOffset);
996 }
997 
998 CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
999  ArrayRef<Capture> Captures,
1000  ArrayRef<Expr *> CaptureInits,
1001  CapturedDecl *CD,
1002  RecordDecl *RD)
1003  : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
1004  CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
1005  assert( S && "null captured statement");
1006  assert(CD && "null captured declaration for captured statement");
1007  assert(RD && "null record declaration for captured statement");
1008 
1009  // Copy initialization expressions.
1010  Stmt **Stored = getStoredStmts();
1011  for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1012  *Stored++ = CaptureInits[I];
1013 
1014  // Copy the statement being captured.
1015  *Stored = S;
1016 
1017  // Copy all Capture objects.
1018  Capture *Buffer = getStoredCaptures();
1019  std::copy(Captures.begin(), Captures.end(), Buffer);
1020 }
1021 
1022 CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
1023  : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
1024  CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) {
1025  getStoredStmts()[NumCaptures] = nullptr;
1026 }
1027 
1029  CapturedRegionKind Kind,
1030  ArrayRef<Capture> Captures,
1031  ArrayRef<Expr *> CaptureInits,
1032  CapturedDecl *CD,
1033  RecordDecl *RD) {
1034  // The layout is
1035  //
1036  // -----------------------------------------------------------
1037  // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
1038  // ----------------^-------------------^----------------------
1039  // getStoredStmts() getStoredCaptures()
1040  //
1041  // where S is the statement being captured.
1042  //
1043  assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
1044 
1045  unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
1046  if (!Captures.empty()) {
1047  // Realign for the following Capture array.
1048  Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1049  Size += sizeof(Capture) * Captures.size();
1050  }
1051 
1052  void *Mem = Context.Allocate(Size);
1053  return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
1054 }
1055 
1057  unsigned NumCaptures) {
1058  unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1059  if (NumCaptures > 0) {
1060  // Realign for the following Capture array.
1061  Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1062  Size += sizeof(Capture) * NumCaptures;
1063  }
1064 
1065  void *Mem = Context.Allocate(Size);
1066  return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
1067 }
1068 
1069 Stmt::child_range CapturedStmt::children() {
1070  // Children are captured field initilizers.
1071  return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1072 }
1073 
1075  return CapDeclAndKind.getPointer();
1076 }
1078  return CapDeclAndKind.getPointer();
1079 }
1080 
1081 /// \brief Set the outlined function declaration.
1083  assert(D && "null CapturedDecl");
1084  CapDeclAndKind.setPointer(D);
1085 }
1086 
1087 /// \brief Retrieve the captured region kind.
1089  return CapDeclAndKind.getInt();
1090 }
1091 
1092 /// \brief Set the captured region kind.
1094  CapDeclAndKind.setInt(Kind);
1095 }
1096 
1097 bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
1098  for (const auto &I : captures()) {
1099  if (!I.capturesVariable())
1100  continue;
1101 
1102  // This does not handle variable redeclarations. This should be
1103  // extended to capture variables with redeclarations, for example
1104  // a thread-private variable in OpenMP.
1105  if (I.getCapturedVar() == Var)
1106  return true;
1107  }
1108 
1109  return false;
1110 }
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
Definition: Stmt.cpp:322
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition: Stmt.cpp:808
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var=nullptr)
Create a new capture.
Definition: Stmt.cpp:948
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:1543
unsigned getNumOutputs() const
Definition: Stmt.h:1440
static LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
Definition: CharInfo.h:94
void setStmts(const ASTContext &C, ArrayRef< Stmt * > Stmts)
Definition: Stmt.cpp:298
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:164
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Definition: ASTMatchers.h:876
const char * Name
Definition: Stmt.cpp:32
C Language Family Type Representation.
const Expr * getOutputExpr(unsigned i) const
Definition: Stmt.cpp:346
static LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
Definition: CharInfo.h:112
Represents an attribute applied to a statement.
Definition: Stmt.h:818
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, SourceLocation rparenloc)
Definition: Stmt.cpp:684
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr * > CaptureInits, CapturedDecl *CD, RecordDecl *RD)
Definition: Stmt.cpp:1028
std::unique_ptr< llvm::MemoryBuffer > Buffer
unsigned NumOutputs
Definition: Stmt.h:1403
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition: Stmt.cpp:800
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition: Stmt.cpp:868
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:643
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:676
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:411
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
VarDecl * getCapturedVar() const
Retrieve the declaration of the variable being captured.
Definition: Stmt.cpp:980
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition: Stmt.cpp:1088
Defines the Objective-C statement AST node classes.
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:68
Defines the clang::Expr interface and subclasses for C++ expressions.
static struct StmtClassNameTable StmtClassInfo[Stmt::lastStmtConstant+1]
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:777
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
Definition: Stmt.h:1450
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3166
One of these records is kept for each identifier that is lexed.
bool isScalarType() const
Definition: Type.h:5581
unsigned getNumInputs() const
Definition: Stmt.h:1462
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4381
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, SourceLocation WL)
Definition: Stmt.cpp:851
bool isReferenceType() const
Definition: Type.h:5314
void Deallocate(void *Ptr) const
Definition: ASTContext.h:566
Token - This structure provides full information about a lexed token.
Definition: Token.h:37
void setCapturedDecl(CapturedDecl *D)
Set the outlined function declaration.
Definition: Stmt.cpp:1082
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
OpenMPLinearClauseKind getModifier() const
Return modifier.
SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond)
Definition: Stmt.cpp:819
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition: Stmt.cpp:338
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:580
const LangOptions & getLangOpts() const
Definition: ASTContext.h:596
StringRef getClobber(unsigned i) const
Definition: Stmt.cpp:393
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:397
StringLiteral * getClobberStringLiteral(unsigned i)
Definition: Stmt.h:1707
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3560
detail::InMemoryDirectory::const_iterator I
QualType getType() const
Definition: Decl.h:530
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Definition: Stmt.cpp:907
unsigned NumClobbers
Definition: Stmt.h:1405
Describes the capture of either a variable, or 'this', or variable-length array type.
Definition: Stmt.h:1997
Stmt * getHandler() const
Definition: Stmt.h:1933
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition: Stmt.cpp:417
bool hasNoAsmVariants() const
Return true if {|} are normal characters in the asm string.
ASTContext * Context
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:330
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:664
SourceManager & SM
Exposes information about the current target.
LabelDecl * getDecl() const
Definition: Stmt.h:794
Expr - This represents one expression.
Definition: Expr.h:104
const Expr * getInputExpr(unsigned i) const
Definition: Stmt.cpp:362
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
Definition: Stmt.cpp:1097
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "while" statement, if any.
Definition: Stmt.cpp:860
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
Definition: Stmt.h:1577
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
Definition: Stmt.cpp:880
child_range children()
Definition: Stmt.cpp:1069
StringRef getInputName(unsigned i) const
Definition: Stmt.h:1665
static StringRef copyIntoContext(const ASTContext &C, StringRef str)
Definition: Stmt.cpp:722
This represents a Microsoft inline-assembly statement extension.
Definition: Stmt.h:1722
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:673
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:669
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:313
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition: Stmt.cpp:354
The result type of a method or function.
do v
Definition: arm_acle.h:77
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:943
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
Definition: Stmt.h:1392
const StringLiteral * getAsmString() const
Definition: Stmt.h:1570
#define false
Definition: stdbool.h:33
Kind
This captures a statement into a function.
Definition: Stmt.h:1984
Encodes a location in the source.
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition: Stmt.cpp:388
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
VariableCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: Stmt.cpp:976
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:431
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:355
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)
Definition: Stmt.cpp:708
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition: Stmt.cpp:834
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "switch" statement, if any.
Definition: Stmt.cpp:826
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Definition: Stmt.cpp:913
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:408
SourceLocation getBegin() const
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:5706
StringRef getOutputName(unsigned i) const
Definition: Stmt.h:1637
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1840
const Decl * getSingleDecl() const
Definition: Stmt.h:449
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:3317
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "if" statement, if any.
Definition: Stmt.cpp:769
CompoundStmt(const ASTContext &C, ArrayRef< Stmt * > Stmts, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:282
child_range children()
unsigned AnalyzeAsmString(SmallVectorImpl< AsmStringPiece > &Pieces, const ASTContext &C, unsigned &DiagOffs) const
AnalyzeAsmString - Analyze the asm string of the current asm, decomposing it into pieces...
Definition: Stmt.cpp:475
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
Definition: Stmt.cpp:1056
unsigned Counter
Definition: Stmt.cpp:33
const StringLiteral * getOutputConstraintLiteral(unsigned i) const
Definition: Stmt.h:1646
StringRef getString() const
Definition: Expr.h:1500
static LLVM_ATTRIBUTE_UNUSED void check_implementations()
Check whether the various Stmt classes implement their member functions.
Definition: Stmt.cpp:199
detail::InMemoryDirectory::const_iterator E
const Expr * getRetValue() const
Definition: Stmt.cpp:888
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition: Stmt.cpp:777
This file defines OpenMP AST classes for executable directives and clauses.
int getNamedOperand(StringRef SymbolicName) const
getNamedOperand - Given a symbolic operand reference like %[foo], translate this into a numeric value...
Definition: Stmt.cpp:455
unsigned getNumPlusOperands() const
getNumPlusOperands - Return the number of output operands that have a "+" constraint.
Definition: Stmt.cpp:380
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2287
ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP)
Definition: Stmt.cpp:788
StringRef getClobber(unsigned i) const
Definition: Stmt.cpp:370
Stmt * getSubStmt()
Definition: Stmt.cpp:845
SourceManager & getSourceManager()
Definition: ASTContext.h:553
Stmt ** Exprs
Definition: Stmt.h:1407
Expr * getTarget()
Definition: Stmt.h:1255
IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, Stmt *then, SourceLocation EL=SourceLocation(), Stmt *elsev=nullptr)
Definition: Stmt.cpp:759
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1074
const StringLiteral * getInputConstraintLiteral(unsigned i) const
Definition: Stmt.h:1674
unsigned Size
Definition: Stmt.cpp:34
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:560
VariableCaptureKind
The different capture forms: by 'this', by reference, capture for variable-length array type etc...
Definition: Stmt.h:1988
bool isSimple() const
Definition: Stmt.h:1424
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1452
Defines the clang::TargetInfo interface.
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition: Stmt.cpp:404
capture_range captures()
Definition: Stmt.h:2118
CapturedRegionKind
The different kinds of captured statement.
Definition: CapturedStmt.h:17
static StmtClassNameTable & getStmtInfoTableEntry(Stmt::StmtClass E)
Definition: Stmt.cpp:37
A trivial tuple used to represent a source range.
unsigned NumInputs
Definition: Stmt.h:1404
SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, const TargetInfo &Target, unsigned *StartToken=nullptr, unsigned *StartTokenByteOffset=nullptr) const
getLocationOfByte - Return a source location that points to the specified byte of this string literal...
Definition: Expr.cpp:1009
const char * getName() const
Definition: Stmt.cpp:309
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
Definition: Stmt.cpp:931
This class handles loading and caching of source files into memory.
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
Definition: Stmt.cpp:1093
Attr - This represents one attribute.
Definition: Attr.h:44
SEHFinallyStmt * getFinallyHandler() const
Definition: Stmt.cpp:917
#define BLOCK(DERIVED, BASE)
Definition: Template.h:423