Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 1 | //===- Stmt.cpp - Statement AST Node Implementation -----------------------===// |
Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the Stmt class and statement subclasses. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 13 | #include "clang/AST/Stmt.h" |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/ASTDiagnostic.h" |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/AST/DeclGroup.h" |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 19 | #include "clang/AST/ExprCXX.h" |
Steve Naroff | 021ca18 | 2008-05-29 21:12:08 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExprObjC.h" |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprOpenMP.h" |
Chris Lattner | f0b64d7 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtCXX.h" |
| 23 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 24 | #include "clang/AST/StmtOpenMP.h" |
Sebastian Redl | 54c04d4 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 25 | #include "clang/AST/Type.h" |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 26 | #include "clang/Basic/CharInfo.h" |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 27 | #include "clang/Basic/LLVM.h" |
| 28 | #include "clang/Basic/SourceLocation.h" |
Chris Lattner | 1a8f394 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 29 | #include "clang/Basic/TargetInfo.h" |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Token.h" |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallVector.h" |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 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" |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 38 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 39 | #include <algorithm> |
| 40 | #include <cassert> |
| 41 | #include <cstring> |
| 42 | #include <string> |
| 43 | #include <utility> |
| 44 | |
Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 45 | using namespace clang; |
| 46 | |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 47 | static struct StmtClassNameTable { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 48 | const char *Name; |
| 49 | unsigned Counter; |
| 50 | unsigned Size; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 51 | } StmtClassInfo[Stmt::lastStmtConstant+1]; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 52 | |
| 53 | static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { |
| 54 | static bool Initialized = false; |
| 55 | if (Initialized) |
| 56 | return StmtClassInfo[E]; |
| 57 | |
Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 58 | // Initialize the table on the first use. |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 59 | Initialized = true; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 60 | #define ABSTRACT_STMT(STMT) |
Douglas Gregor | be35ce9 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 61 | #define STMT(CLASS, PARENT) \ |
| 62 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 63 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 64 | #include "clang/AST/StmtNodes.inc" |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 65 | |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 66 | return StmtClassInfo[E]; |
| 67 | } |
| 68 | |
Craig Topper | 3793291 | 2013-08-18 10:09:15 +0000 | [diff] [blame] | 69 | void *Stmt::operator new(size_t bytes, const ASTContext& C, |
Craig Topper | 5a05001 | 2013-08-18 17:45:38 +0000 | [diff] [blame] | 70 | unsigned alignment) { |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 71 | return ::operator new(bytes, C, alignment); |
| 72 | } |
| 73 | |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 74 | const char *Stmt::getStmtClassName() const { |
John McCall | 925b1662 | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 75 | return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 76 | } |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 77 | |
Bruno Ricci | 65034b8 | 2018-12-04 16:04:19 +0000 | [diff] [blame] | 78 | // Check that no statement / expression class is polymorphic. LLVM style RTTI |
| 79 | // should be used instead. If absolutely needed an exception can still be added |
| 80 | // here by defining the appropriate macro (but please don't do this). |
| 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" |
| 85 | |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 86 | void Stmt::PrintStats() { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 87 | // Ensure the table is primed. |
| 88 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 89 | |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 90 | unsigned sum = 0; |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 91 | llvm::errs() << "\n*** Stmt/Expr Stats:\n"; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 92 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 93 | if (StmtClassInfo[i].Name == nullptr) continue; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 94 | sum += StmtClassInfo[i].Counter; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 95 | } |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 96 | llvm::errs() << " " << sum << " stmts/exprs total.\n"; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 97 | sum = 0; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 98 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 99 | if (StmtClassInfo[i].Name == nullptr) continue; |
Douglas Gregor | a30d046 | 2009-05-26 14:40:08 +0000 | [diff] [blame] | 100 | if (StmtClassInfo[i].Counter == 0) continue; |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 101 | llvm::errs() << " " << StmtClassInfo[i].Counter << " " |
| 102 | << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size |
| 103 | << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size |
| 104 | << " bytes)\n"; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 105 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 106 | } |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 107 | |
| 108 | llvm::errs() << "Total bytes = " << sum << "\n"; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 112 | ++getStmtInfoTableEntry(s).Counter; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Daniel Dunbar | 6290557 | 2012-03-05 21:42:49 +0000 | [diff] [blame] | 115 | bool Stmt::StatisticsEnabled = false; |
| 116 | void Stmt::EnableStatistics() { |
| 117 | StatisticsEnabled = true; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 120 | /// Skip no-op (attributed, compound) container stmts and skip captured |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 121 | /// stmt at the top, if \a IgnoreCaptured is true. |
| 122 | Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) { |
| 123 | Stmt *S = this; |
| 124 | if (IgnoreCaptured) |
| 125 | if (auto CapS = dyn_cast_or_null<CapturedStmt>(S)) |
| 126 | S = CapS->getCapturedStmt(); |
| 127 | while (true) { |
| 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)) { |
| 131 | if (CS->size() != 1) |
| 132 | break; |
| 133 | S = CS->body_back(); |
| 134 | } else |
| 135 | break; |
| 136 | } |
| 137 | return S; |
| 138 | } |
| 139 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 140 | /// Strip off all label-like statements. |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 141 | /// |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 142 | /// This will strip off label statements, case statements, attributed |
| 143 | /// statements and default statements recursively. |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 144 | const Stmt *Stmt::stripLabelLikeStatements() const { |
| 145 | const Stmt *S = this; |
| 146 | while (true) { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 147 | if (const auto *LS = dyn_cast<LabelStmt>(S)) |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 148 | S = LS->getSubStmt(); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 149 | else if (const auto *SC = dyn_cast<SwitchCase>(S)) |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 150 | S = SC->getSubStmt(); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 151 | else if (const auto *AS = dyn_cast<AttributedStmt>(S)) |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 152 | S = AS->getSubStmt(); |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 153 | else |
| 154 | return S; |
| 155 | } |
| 156 | } |
| 157 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 158 | namespace { |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 159 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 160 | struct good {}; |
| 161 | struct bad {}; |
John McCall | f75152f | 2011-02-09 08:31:17 +0000 | [diff] [blame] | 162 | |
| 163 | // These silly little functions have to be static inline to suppress |
| 164 | // unused warnings, and they have to be defined to suppress other |
| 165 | // warnings. |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 166 | static good is_good(good) { return good(); } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 167 | |
| 168 | typedef Stmt::child_range children_t(); |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 169 | template <class T> good implements_children(children_t T::*) { |
| 170 | return good(); |
| 171 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 172 | LLVM_ATTRIBUTE_UNUSED |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 173 | static bad implements_children(children_t Stmt::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 174 | return bad(); |
| 175 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 176 | |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 177 | typedef SourceLocation getBeginLoc_t() const; |
| 178 | template <class T> good implements_getBeginLoc(getBeginLoc_t T::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 179 | return good(); |
| 180 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 181 | LLVM_ATTRIBUTE_UNUSED |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 182 | static bad implements_getBeginLoc(getBeginLoc_t Stmt::*) { return bad(); } |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 183 | |
| 184 | typedef SourceLocation getLocEnd_t() const; |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 185 | template <class T> good implements_getEndLoc(getLocEnd_t T::*) { |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 186 | return good(); |
| 187 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 188 | LLVM_ATTRIBUTE_UNUSED |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 189 | static bad implements_getEndLoc(getLocEnd_t Stmt::*) { return bad(); } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 190 | |
| 191 | #define ASSERT_IMPLEMENTS_children(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 192 | (void) is_good(implements_children(&type::children)) |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 193 | #define ASSERT_IMPLEMENTS_getBeginLoc(type) \ |
| 194 | (void)is_good(implements_getBeginLoc(&type::getBeginLoc)) |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 195 | #define ASSERT_IMPLEMENTS_getEndLoc(type) \ |
| 196 | (void)is_good(implements_getEndLoc(&type::getEndLoc)) |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 197 | |
| 198 | } // namespace |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 199 | |
| 200 | /// Check whether the various Stmt classes implement their member |
| 201 | /// functions. |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 202 | LLVM_ATTRIBUTE_UNUSED |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 203 | static inline void check_implementations() { |
| 204 | #define ABSTRACT_STMT(type) |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 205 | #define STMT(type, base) \ |
| 206 | ASSERT_IMPLEMENTS_children(type); \ |
| 207 | ASSERT_IMPLEMENTS_getBeginLoc(type); \ |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 208 | ASSERT_IMPLEMENTS_getEndLoc(type); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 209 | #include "clang/AST/StmtNodes.inc" |
| 210 | } |
| 211 | |
| 212 | Stmt::child_range Stmt::children() { |
| 213 | switch (getStmtClass()) { |
| 214 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 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" |
| 220 | } |
| 221 | llvm_unreachable("unknown statement kind!"); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 224 | // Amusing macro metaprogramming hack: check whether a class provides |
| 225 | // a more specific implementation of getSourceRange. |
| 226 | // |
| 227 | // See also Expr.cpp:getExprLoc(). |
| 228 | namespace { |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 229 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 230 | /// This implementation is used when a class provides a custom |
| 231 | /// implementation of getSourceRange. |
| 232 | template <class S, class T> |
| 233 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 234 | SourceRange (T::*v)() const) { |
| 235 | return static_cast<const S*>(stmt)->getSourceRange(); |
| 236 | } |
| 237 | |
| 238 | /// This implementation is used when a class doesn't provide a custom |
| 239 | /// implementation of getSourceRange. Overload resolution should pick it over |
| 240 | /// the implementation above because it's more specialized according to |
| 241 | /// function template partial ordering. |
| 242 | template <class S> |
| 243 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 244 | SourceRange (Stmt::*v)() const) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 245 | return SourceRange(static_cast<const S *>(stmt)->getBeginLoc(), |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 246 | static_cast<const S *>(stmt)->getEndLoc()); |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 247 | } |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 248 | |
| 249 | } // namespace |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 250 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 251 | SourceRange Stmt::getSourceRange() const { |
| 252 | switch (getStmtClass()) { |
| 253 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 254 | #define ABSTRACT_STMT(type) |
| 255 | #define STMT(type, base) \ |
| 256 | case Stmt::type##Class: \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 257 | return getSourceRangeImpl<type>(this, &type::getSourceRange); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 258 | #include "clang/AST/StmtNodes.inc" |
| 259 | } |
| 260 | llvm_unreachable("unknown statement kind!"); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Stephen Kelly | 724e9e5 | 2018-08-09 20:05:03 +0000 | [diff] [blame] | 263 | SourceLocation Stmt::getBeginLoc() const { |
| 264 | // llvm::errs() << "getBeginLoc() for " << getStmtClassName() << "\n"; |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 265 | switch (getStmtClass()) { |
| 266 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 267 | #define ABSTRACT_STMT(type) |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 268 | #define STMT(type, base) \ |
| 269 | case Stmt::type##Class: \ |
| 270 | return static_cast<const type *>(this)->getBeginLoc(); |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 271 | #include "clang/AST/StmtNodes.inc" |
| 272 | } |
| 273 | llvm_unreachable("unknown statement kind"); |
| 274 | } |
| 275 | |
Stephen Kelly | 02a67ba | 2018-08-09 20:05:47 +0000 | [diff] [blame] | 276 | SourceLocation Stmt::getEndLoc() const { |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 277 | switch (getStmtClass()) { |
| 278 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 279 | #define ABSTRACT_STMT(type) |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 280 | #define STMT(type, base) \ |
| 281 | case Stmt::type##Class: \ |
| 282 | return static_cast<const type *>(this)->getEndLoc(); |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 283 | #include "clang/AST/StmtNodes.inc" |
| 284 | } |
| 285 | llvm_unreachable("unknown statement kind"); |
| 286 | } |
| 287 | |
George Karpenkov | 5eb4cc6 | 2018-09-15 02:01:47 +0000 | [diff] [blame] | 288 | int64_t Stmt::getID(const ASTContext &Context) const { |
Artem Dergachev | 057647d | 2018-12-03 22:19:05 +0000 | [diff] [blame] | 289 | return Context.getAllocator().identifyKnownAlignedObject<Stmt>(this); |
George Karpenkov | 5eb4cc6 | 2018-09-15 02:01:47 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 292 | CompoundStmt::CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB, |
| 293 | SourceLocation RB) |
Bruno Ricci | 41d11c0 | 2018-10-27 18:43:27 +0000 | [diff] [blame] | 294 | : Stmt(CompoundStmtClass), RBraceLoc(RB) { |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 295 | CompoundStmtBits.NumStmts = Stmts.size(); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 296 | setStmts(Stmts); |
Bruno Ricci | 41d11c0 | 2018-10-27 18:43:27 +0000 | [diff] [blame] | 297 | CompoundStmtBits.LBraceLoc = LB; |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 300 | void CompoundStmt::setStmts(ArrayRef<Stmt *> Stmts) { |
Craig Topper | 9ee84ad | 2015-12-04 05:01:44 +0000 | [diff] [blame] | 301 | assert(CompoundStmtBits.NumStmts == Stmts.size() && |
| 302 | "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 303 | |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 304 | std::copy(Stmts.begin(), Stmts.end(), body_begin()); |
| 305 | } |
| 306 | |
| 307 | CompoundStmt *CompoundStmt::Create(const ASTContext &C, ArrayRef<Stmt *> Stmts, |
| 308 | SourceLocation LB, SourceLocation RB) { |
| 309 | void *Mem = |
| 310 | C.Allocate(totalSizeToAlloc<Stmt *>(Stmts.size()), alignof(CompoundStmt)); |
| 311 | return new (Mem) CompoundStmt(Stmts, LB, RB); |
| 312 | } |
| 313 | |
| 314 | CompoundStmt *CompoundStmt::CreateEmpty(const ASTContext &C, |
| 315 | unsigned NumStmts) { |
| 316 | void *Mem = |
| 317 | C.Allocate(totalSizeToAlloc<Stmt *>(NumStmts), alignof(CompoundStmt)); |
| 318 | CompoundStmt *New = new (Mem) CompoundStmt(EmptyShell()); |
| 319 | New->CompoundStmtBits.NumStmts = NumStmts; |
| 320 | return New; |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 321 | } |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 322 | |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 323 | const Expr *ValueStmt::getExprStmt() const { |
| 324 | const Stmt *S = this; |
| 325 | do { |
| 326 | if (const auto *E = dyn_cast<Expr>(S)) |
| 327 | return E; |
| 328 | |
| 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(); |
| 333 | else |
| 334 | llvm_unreachable("unknown kind of ValueStmt"); |
| 335 | } while (isa<ValueStmt>(S)); |
| 336 | |
| 337 | return nullptr; |
| 338 | } |
| 339 | |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 340 | const char *LabelStmt::getName() const { |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 341 | return getDecl()->getIdentifier()->getNameStart(); |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 344 | AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 345 | ArrayRef<const Attr*> Attrs, |
| 346 | Stmt *SubStmt) { |
Aaron Ballman | f3d9b09 | 2014-05-13 14:55:01 +0000 | [diff] [blame] | 347 | assert(!Attrs.empty() && "Attrs should not be empty"); |
Benjamin Kramer | 917fdbe | 2017-12-24 16:24:11 +0000 | [diff] [blame] | 348 | void *Mem = C.Allocate(totalSizeToAlloc<const Attr *>(Attrs.size()), |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 349 | alignof(AttributedStmt)); |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 350 | return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); |
| 351 | } |
| 352 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 353 | AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, |
| 354 | unsigned NumAttrs) { |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 355 | assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); |
Benjamin Kramer | 917fdbe | 2017-12-24 16:24:11 +0000 | [diff] [blame] | 356 | void *Mem = C.Allocate(totalSizeToAlloc<const Attr *>(NumAttrs), |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 357 | alignof(AttributedStmt)); |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 358 | return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); |
| 359 | } |
| 360 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 361 | std::string AsmStmt::generateAsmString(const ASTContext &C) const { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 362 | if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 363 | return gccAsmStmt->generateAsmString(C); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 364 | if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 365 | return msAsmStmt->generateAsmString(C); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 366 | llvm_unreachable("unknown asm statement kind!"); |
| 367 | } |
| 368 | |
| 369 | StringRef AsmStmt::getOutputConstraint(unsigned i) const { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 370 | if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 371 | return gccAsmStmt->getOutputConstraint(i); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 372 | if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 373 | return msAsmStmt->getOutputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 374 | llvm_unreachable("unknown asm statement kind!"); |
| 375 | } |
| 376 | |
| 377 | const Expr *AsmStmt::getOutputExpr(unsigned i) const { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 378 | if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 379 | return gccAsmStmt->getOutputExpr(i); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 380 | if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 381 | return msAsmStmt->getOutputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 382 | llvm_unreachable("unknown asm statement kind!"); |
| 383 | } |
| 384 | |
| 385 | StringRef AsmStmt::getInputConstraint(unsigned i) const { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 386 | if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 387 | return gccAsmStmt->getInputConstraint(i); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 388 | if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 389 | return msAsmStmt->getInputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 390 | llvm_unreachable("unknown asm statement kind!"); |
| 391 | } |
| 392 | |
| 393 | const Expr *AsmStmt::getInputExpr(unsigned i) const { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 394 | if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 395 | return gccAsmStmt->getInputExpr(i); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 396 | if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 397 | return msAsmStmt->getInputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 398 | llvm_unreachable("unknown asm statement kind!"); |
| 399 | } |
| 400 | |
| 401 | StringRef AsmStmt::getClobber(unsigned i) const { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 402 | if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 403 | return gccAsmStmt->getClobber(i); |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 404 | if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 405 | return msAsmStmt->getClobber(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 406 | llvm_unreachable("unknown asm statement kind!"); |
| 407 | } |
| 408 | |
Chad Rosier | a1b5c8c | 2012-08-28 00:24:05 +0000 | [diff] [blame] | 409 | /// getNumPlusOperands - Return the number of output operands that have a "+" |
| 410 | /// constraint. |
| 411 | unsigned AsmStmt::getNumPlusOperands() const { |
| 412 | unsigned Res = 0; |
| 413 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) |
| 414 | if (isOutputPlusConstraint(i)) |
| 415 | ++Res; |
| 416 | return Res; |
| 417 | } |
| 418 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 419 | char GCCAsmStmt::AsmStringPiece::getModifier() const { |
| 420 | assert(isOperand() && "Only Operands can have modifiers."); |
| 421 | return isLetter(Str[0]) ? Str[0] : '\0'; |
| 422 | } |
| 423 | |
Chad Rosier | 6100ae1 | 2012-08-27 23:47:56 +0000 | [diff] [blame] | 424 | StringRef GCCAsmStmt::getClobber(unsigned i) const { |
| 425 | return getClobberStringLiteral(i)->getString(); |
| 426 | } |
| 427 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 428 | Expr *GCCAsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 429 | return cast<Expr>(Exprs[i]); |
| 430 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 431 | |
| 432 | /// getOutputConstraint - Return the constraint string for the specified |
| 433 | /// output operand. All output constraints are known to be non-empty (either |
| 434 | /// '=' or '+'). |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 435 | StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 436 | return getOutputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 437 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 438 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 439 | Expr *GCCAsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 440 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 441 | } |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 442 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 443 | void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { |
Chris Lattner | 93ede02 | 2011-02-21 22:09:29 +0000 | [diff] [blame] | 444 | Exprs[i + NumOutputs] = E; |
| 445 | } |
| 446 | |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 447 | AddrLabelExpr *GCCAsmStmt::getLabelExpr(unsigned i) const { |
| 448 | return cast<AddrLabelExpr>(Exprs[i + NumInputs]); |
| 449 | } |
| 450 | |
| 451 | StringRef GCCAsmStmt::getLabelName(unsigned i) const { |
| 452 | return getLabelExpr(i)->getLabel()->getName(); |
| 453 | } |
| 454 | |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 455 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 456 | /// constraints, these can be empty. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 457 | StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 458 | return getInputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 461 | void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, |
| 462 | IdentifierInfo **Names, |
| 463 | StringLiteral **Constraints, |
| 464 | Stmt **Exprs, |
| 465 | unsigned NumOutputs, |
| 466 | unsigned NumInputs, |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 467 | unsigned NumLabels, |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 468 | StringLiteral **Clobbers, |
| 469 | unsigned NumClobbers) { |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 470 | this->NumOutputs = NumOutputs; |
| 471 | this->NumInputs = NumInputs; |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 472 | this->NumClobbers = NumClobbers; |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 473 | this->NumLabels = NumLabels; |
| 474 | assert(!(NumOutputs && NumLabels) && "asm goto cannot have outputs"); |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 475 | |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 476 | unsigned NumExprs = NumOutputs + NumInputs + NumLabels; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 477 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 478 | C.Deallocate(this->Names); |
| 479 | this->Names = new (C) IdentifierInfo*[NumExprs]; |
| 480 | std::copy(Names, Names + NumExprs, this->Names); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 481 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 482 | C.Deallocate(this->Exprs); |
| 483 | this->Exprs = new (C) Stmt*[NumExprs]; |
| 484 | std::copy(Exprs, Exprs + NumExprs, this->Exprs); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 485 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 486 | C.Deallocate(this->Constraints); |
| 487 | this->Constraints = new (C) StringLiteral*[NumExprs]; |
| 488 | std::copy(Constraints, Constraints + NumExprs, this->Constraints); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 489 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 490 | C.Deallocate(this->Clobbers); |
| 491 | this->Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 492 | std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers); |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 493 | } |
| 494 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 495 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 496 | /// translate this into a numeric value needed to reference the same operand. |
| 497 | /// This returns -1 if the operand name is invalid. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 498 | int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 499 | unsigned NumPlusOperands = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 501 | // Check if this is an output operand. |
| 502 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { |
| 503 | if (getOutputName(i) == SymbolicName) |
| 504 | return i; |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 505 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 507 | for (unsigned i = 0, e = getNumInputs(); i != e; ++i) |
| 508 | if (getInputName(i) == SymbolicName) |
| 509 | return getNumOutputs() + NumPlusOperands + i; |
| 510 | |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 511 | for (unsigned i = 0, e = getNumLabels(); i != e; ++i) |
| 512 | if (getLabelName(i) == SymbolicName) |
| 513 | return i + getNumInputs(); |
| 514 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 515 | // Not found. |
| 516 | return -1; |
| 517 | } |
| 518 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 519 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 520 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 521 | /// true, otherwise return false. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 522 | unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 523 | const ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 524 | StringRef Str = getAsmString()->getString(); |
Benjamin Kramer | 35b077e | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 525 | const char *StrStart = Str.begin(); |
| 526 | const char *StrEnd = Str.end(); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 527 | const char *CurPtr = StrStart; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 529 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 530 | // string to escape $'s. |
| 531 | if (isSimple()) { |
| 532 | std::string Result; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 533 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 534 | switch (*CurPtr) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 535 | case '$': |
| 536 | Result += "$$"; |
| 537 | break; |
| 538 | default: |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 539 | Result += *CurPtr; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 540 | break; |
| 541 | } |
| 542 | } |
| 543 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 544 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | // CurStringPiece - The current string that we are building up as we scan the |
| 548 | // asm string. |
| 549 | std::string CurStringPiece; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | |
Douglas Gregor | e8bbc12 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 551 | bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 552 | |
Richard Smith | d18ab80 | 2016-05-16 22:52:23 +0000 | [diff] [blame] | 553 | unsigned LastAsmStringToken = 0; |
| 554 | unsigned LastAsmStringOffset = 0; |
| 555 | |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 556 | while (true) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 557 | // Done with the string? |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 558 | if (CurPtr == StrEnd) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 559 | if (!CurStringPiece.empty()) |
| 560 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 561 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 562 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 563 | |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 564 | char CurChar = *CurPtr++; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 565 | switch (CurChar) { |
| 566 | case '$': CurStringPiece += "$$"; continue; |
Chris Lattner | 1a8f394 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 567 | case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue; |
| 568 | case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue; |
| 569 | case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 570 | case '%': |
| 571 | break; |
| 572 | default: |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 573 | CurStringPiece += CurChar; |
| 574 | continue; |
| 575 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 576 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 577 | // Escaped "%" character in asm string. |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 578 | if (CurPtr == StrEnd) { |
| 579 | // % at end of string is invalid (no escape). |
| 580 | DiagOffs = CurPtr-StrStart-1; |
| 581 | return diag::err_asm_invalid_escape; |
| 582 | } |
Michael Zuckerman | 2460bad | 2016-10-31 15:27:54 +0000 | [diff] [blame] | 583 | // Handle escaped char and continue looping over the asm string. |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 584 | char EscapedChar = *CurPtr++; |
Michael Zuckerman | 2460bad | 2016-10-31 15:27:54 +0000 | [diff] [blame] | 585 | switch (EscapedChar) { |
| 586 | default: |
| 587 | break; |
| 588 | case '%': // %% -> % |
| 589 | case '{': // %{ -> { |
| 590 | case '}': // %} -> } |
| 591 | CurStringPiece += EscapedChar; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 592 | continue; |
Michael Zuckerman | 2460bad | 2016-10-31 15:27:54 +0000 | [diff] [blame] | 593 | case '=': // %= -> Generate a unique ID. |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 594 | CurStringPiece += "${:uid}"; |
| 595 | continue; |
| 596 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 597 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 598 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 599 | // add it to the Pieces list. |
| 600 | if (!CurStringPiece.empty()) { |
| 601 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 602 | CurStringPiece.clear(); |
| 603 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 605 | // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that |
| 606 | // don't (e.g., %x4). 'x' following the '%' is the constraint modifier. |
| 607 | |
| 608 | const char *Begin = CurPtr - 1; // Points to the character following '%'. |
| 609 | const char *Percent = Begin - 1; // Points to '%'. |
| 610 | |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 611 | if (isLetter(EscapedChar)) { |
Benjamin Kramer | e87c38b | 2011-07-05 11:13:37 +0000 | [diff] [blame] | 612 | if (CurPtr == StrEnd) { // Premature end. |
| 613 | DiagOffs = CurPtr-StrStart-1; |
| 614 | return diag::err_asm_invalid_escape; |
| 615 | } |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 616 | EscapedChar = *CurPtr++; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 617 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 619 | const TargetInfo &TI = C.getTargetInfo(); |
| 620 | const SourceManager &SM = C.getSourceManager(); |
| 621 | const LangOptions &LO = C.getLangOpts(); |
| 622 | |
| 623 | // Handle operands that don't have asmSymbolicName (e.g., %x4). |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 624 | if (isDigit(EscapedChar)) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 625 | // %n - Assembler operand n |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 626 | unsigned N = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 628 | --CurPtr; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 629 | while (CurPtr != StrEnd && isDigit(*CurPtr)) |
Chris Lattner | 84f3afa | 2009-03-11 23:09:16 +0000 | [diff] [blame] | 630 | N = N*10 + ((*CurPtr++)-'0'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 631 | |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 632 | unsigned NumOperands = getNumOutputs() + getNumPlusOperands() + |
| 633 | getNumInputs() + getNumLabels(); |
Chris Lattner | 1431192 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 634 | if (N >= NumOperands) { |
| 635 | DiagOffs = CurPtr-StrStart-1; |
| 636 | return diag::err_asm_invalid_operand_number; |
| 637 | } |
| 638 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 639 | // Str contains "x4" (Operand without the leading %). |
| 640 | std::string Str(Begin, CurPtr - Begin); |
| 641 | |
| 642 | // (BeginLoc, EndLoc) represents the range of the operand we are currently |
| 643 | // processing. Unlike Str, the range includes the leading '%'. |
Richard Smith | d18ab80 | 2016-05-16 22:52:23 +0000 | [diff] [blame] | 644 | SourceLocation BeginLoc = getAsmString()->getLocationOfByte( |
| 645 | Percent - StrStart, SM, LO, TI, &LastAsmStringToken, |
| 646 | &LastAsmStringOffset); |
| 647 | SourceLocation EndLoc = getAsmString()->getLocationOfByte( |
| 648 | CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken, |
| 649 | &LastAsmStringOffset); |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 650 | |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 651 | Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 652 | continue; |
| 653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 654 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 655 | // Handle operands that have asmSymbolicName (e.g., %x[foo]). |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 656 | if (EscapedChar == '[') { |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 657 | DiagOffs = CurPtr-StrStart-1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 659 | // Find the ']'. |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 660 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 661 | if (NameEnd == nullptr) |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 662 | return diag::err_asm_unterminated_symbolic_operand_name; |
| 663 | if (NameEnd == CurPtr) |
| 664 | return diag::err_asm_empty_symbolic_operand_name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 666 | StringRef SymbolicName(CurPtr, NameEnd - CurPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 667 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 668 | int N = getNamedOperand(SymbolicName); |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 669 | if (N == -1) { |
| 670 | // Verify that an operand with that name exists. |
| 671 | DiagOffs = CurPtr-StrStart; |
| 672 | return diag::err_asm_unknown_symbolic_operand_name; |
| 673 | } |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 674 | |
| 675 | // Str contains "x[foo]" (Operand without the leading %). |
| 676 | std::string Str(Begin, NameEnd + 1 - Begin); |
| 677 | |
| 678 | // (BeginLoc, EndLoc) represents the range of the operand we are currently |
| 679 | // processing. Unlike Str, the range includes the leading '%'. |
Richard Smith | d18ab80 | 2016-05-16 22:52:23 +0000 | [diff] [blame] | 680 | SourceLocation BeginLoc = getAsmString()->getLocationOfByte( |
| 681 | Percent - StrStart, SM, LO, TI, &LastAsmStringToken, |
| 682 | &LastAsmStringOffset); |
| 683 | SourceLocation EndLoc = getAsmString()->getLocationOfByte( |
| 684 | NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken, |
| 685 | &LastAsmStringOffset); |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 686 | |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 687 | Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 688 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 689 | CurPtr = NameEnd+1; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 690 | continue; |
| 691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Chris Lattner | 0cdaa2e | 2009-03-10 23:57:07 +0000 | [diff] [blame] | 693 | DiagOffs = CurPtr-StrStart-1; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 694 | return diag::err_asm_invalid_escape; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 697 | |
| 698 | /// Assemble final IR asm string (GCC-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 699 | std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 700 | // Analyze the asm string to decompose it into its pieces. We know that Sema |
| 701 | // has already done this, so it is guaranteed to be successful. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 702 | SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 703 | unsigned DiagOffs; |
| 704 | AnalyzeAsmString(Pieces, C, DiagOffs); |
| 705 | |
| 706 | std::string AsmString; |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 707 | for (const auto &Piece : Pieces) { |
| 708 | if (Piece.isString()) |
| 709 | AsmString += Piece.getString(); |
| 710 | else if (Piece.getModifier() == '\0') |
| 711 | AsmString += '$' + llvm::utostr(Piece.getOperandNo()); |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 712 | else |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 713 | AsmString += "${" + llvm::utostr(Piece.getOperandNo()) + ':' + |
| 714 | Piece.getModifier() + '}'; |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 715 | } |
| 716 | return AsmString; |
| 717 | } |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 718 | |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 719 | /// Assemble final IR asm string (MS-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 720 | std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 721 | // FIXME: This needs to be translated into the IR string representation. |
Chad Rosier | 0bca469 | 2012-08-28 20:33:49 +0000 | [diff] [blame] | 722 | return AsmStr; |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 725 | Expr *MSAsmStmt::getOutputExpr(unsigned i) { |
| 726 | return cast<Expr>(Exprs[i]); |
| 727 | } |
| 728 | |
| 729 | Expr *MSAsmStmt::getInputExpr(unsigned i) { |
| 730 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 731 | } |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 732 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 733 | void MSAsmStmt::setInputExpr(unsigned i, Expr *E) { |
| 734 | Exprs[i + NumOutputs] = E; |
| 735 | } |
| 736 | |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 737 | //===----------------------------------------------------------------------===// |
| 738 | // Constructors |
| 739 | //===----------------------------------------------------------------------===// |
| 740 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 741 | GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, |
| 742 | bool issimple, bool isvolatile, unsigned numoutputs, |
| 743 | unsigned numinputs, IdentifierInfo **names, |
| 744 | StringLiteral **constraints, Expr **exprs, |
| 745 | StringLiteral *asmstr, unsigned numclobbers, |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 746 | StringLiteral **clobbers, unsigned numlabels, |
| 747 | SourceLocation rparenloc) |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 748 | : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
Jennifer Yu | 954ec09 | 2019-05-30 01:05:46 +0000 | [diff] [blame] | 749 | numinputs, numclobbers), |
| 750 | RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) { |
| 751 | unsigned NumExprs = NumOutputs + NumInputs + NumLabels; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 752 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 753 | Names = new (C) IdentifierInfo*[NumExprs]; |
| 754 | std::copy(names, names + NumExprs, Names); |
| 755 | |
| 756 | Exprs = new (C) Stmt*[NumExprs]; |
| 757 | std::copy(exprs, exprs + NumExprs, Exprs); |
| 758 | |
| 759 | Constraints = new (C) StringLiteral*[NumExprs]; |
| 760 | std::copy(constraints, constraints + NumExprs, Constraints); |
| 761 | |
| 762 | Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 763 | std::copy(clobbers, clobbers + NumClobbers, Clobbers); |
Anders Carlsson | 94ea8aa | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 766 | MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 767 | SourceLocation lbraceloc, bool issimple, bool isvolatile, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 768 | ArrayRef<Token> asmtoks, unsigned numoutputs, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 769 | unsigned numinputs, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 770 | ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, |
| 771 | StringRef asmstr, ArrayRef<StringRef> clobbers, |
| 772 | SourceLocation endloc) |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 773 | : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 774 | numinputs, clobbers.size()), LBraceLoc(lbraceloc), |
| 775 | EndLoc(endloc), NumAsmToks(asmtoks.size()) { |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 776 | initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); |
| 777 | } |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 778 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 779 | static StringRef copyIntoContext(const ASTContext &C, StringRef str) { |
Benjamin Kramer | 2ab0d88 | 2015-08-04 12:34:23 +0000 | [diff] [blame] | 780 | return str.copy(C); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 783 | void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 784 | ArrayRef<Token> asmtoks, |
| 785 | ArrayRef<StringRef> constraints, |
| 786 | ArrayRef<Expr*> exprs, |
| 787 | ArrayRef<StringRef> clobbers) { |
| 788 | assert(NumAsmToks == asmtoks.size()); |
| 789 | assert(NumClobbers == clobbers.size()); |
| 790 | |
Craig Topper | caf138e | 2015-12-05 07:41:42 +0000 | [diff] [blame] | 791 | assert(exprs.size() == NumOutputs + NumInputs); |
| 792 | assert(exprs.size() == constraints.size()); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 793 | |
| 794 | AsmStr = copyIntoContext(C, asmstr); |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 795 | |
Craig Topper | caf138e | 2015-12-05 07:41:42 +0000 | [diff] [blame] | 796 | Exprs = new (C) Stmt*[exprs.size()]; |
| 797 | std::copy(exprs.begin(), exprs.end(), Exprs); |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 798 | |
Craig Topper | caf138e | 2015-12-05 07:41:42 +0000 | [diff] [blame] | 799 | AsmToks = new (C) Token[asmtoks.size()]; |
| 800 | std::copy(asmtoks.begin(), asmtoks.end(), AsmToks); |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 801 | |
Craig Topper | caf138e | 2015-12-05 07:41:42 +0000 | [diff] [blame] | 802 | Constraints = new (C) StringRef[exprs.size()]; |
| 803 | std::transform(constraints.begin(), constraints.end(), Constraints, |
| 804 | [&](StringRef Constraint) { |
| 805 | return copyIntoContext(C, Constraint); |
| 806 | }); |
Chad Rosier | 3dd7bf2 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 807 | |
Chad Rosier | baf53f9 | 2012-08-10 21:36:25 +0000 | [diff] [blame] | 808 | Clobbers = new (C) StringRef[NumClobbers]; |
Craig Topper | caf138e | 2015-12-05 07:41:42 +0000 | [diff] [blame] | 809 | // FIXME: Avoid the allocation/copy if at all possible. |
| 810 | std::transform(clobbers.begin(), clobbers.end(), Clobbers, |
| 811 | [&](StringRef Clobber) { |
| 812 | return copyIntoContext(C, Clobber); |
| 813 | }); |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 816 | IfStmt::IfStmt(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr, |
| 817 | Stmt *Init, VarDecl *Var, Expr *Cond, Stmt *Then, |
| 818 | SourceLocation EL, Stmt *Else) |
| 819 | : Stmt(IfStmtClass) { |
| 820 | bool HasElse = Else != nullptr; |
| 821 | bool HasVar = Var != nullptr; |
| 822 | bool HasInit = Init != nullptr; |
| 823 | IfStmtBits.HasElse = HasElse; |
| 824 | IfStmtBits.HasVar = HasVar; |
| 825 | IfStmtBits.HasInit = HasInit; |
| 826 | |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 827 | setConstexpr(IsConstexpr); |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 828 | |
| 829 | setCond(Cond); |
| 830 | setThen(Then); |
| 831 | if (HasElse) |
| 832 | setElse(Else); |
| 833 | if (HasVar) |
| 834 | setConditionVariable(Ctx, Var); |
| 835 | if (HasInit) |
| 836 | setInit(Init); |
| 837 | |
| 838 | setIfLoc(IL); |
| 839 | if (HasElse) |
| 840 | setElseLoc(EL); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 841 | } |
| 842 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 843 | IfStmt::IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit) |
| 844 | : Stmt(IfStmtClass, Empty) { |
| 845 | IfStmtBits.HasElse = HasElse; |
| 846 | IfStmtBits.HasVar = HasVar; |
| 847 | IfStmtBits.HasInit = HasInit; |
| 848 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 849 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 850 | IfStmt *IfStmt::Create(const ASTContext &Ctx, SourceLocation IL, |
| 851 | bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond, |
| 852 | Stmt *Then, SourceLocation EL, Stmt *Else) { |
| 853 | bool HasElse = Else != nullptr; |
| 854 | bool HasVar = Var != nullptr; |
| 855 | bool HasInit = Init != nullptr; |
| 856 | void *Mem = Ctx.Allocate( |
| 857 | totalSizeToAlloc<Stmt *, SourceLocation>( |
| 858 | NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse), |
| 859 | alignof(IfStmt)); |
| 860 | return new (Mem) |
| 861 | IfStmt(Ctx, IL, IsConstexpr, Init, Var, Cond, Then, EL, Else); |
| 862 | } |
| 863 | |
| 864 | IfStmt *IfStmt::CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar, |
| 865 | bool HasInit) { |
| 866 | void *Mem = Ctx.Allocate( |
| 867 | totalSizeToAlloc<Stmt *, SourceLocation>( |
| 868 | NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse), |
| 869 | alignof(IfStmt)); |
| 870 | return new (Mem) IfStmt(EmptyShell(), HasElse, HasVar, HasInit); |
| 871 | } |
| 872 | |
| 873 | VarDecl *IfStmt::getConditionVariable() { |
| 874 | auto *DS = getConditionVariableDeclStmt(); |
| 875 | if (!DS) |
| 876 | return nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 877 | return cast<VarDecl>(DS->getSingleDecl()); |
| 878 | } |
| 879 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 880 | void IfStmt::setConditionVariable(const ASTContext &Ctx, VarDecl *V) { |
| 881 | assert(hasVarStorage() && |
| 882 | "This if statement has no storage for a condition variable!"); |
| 883 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 884 | if (!V) { |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 885 | getTrailingObjects<Stmt *>()[varOffset()] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 886 | return; |
| 887 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 888 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 889 | SourceRange VarRange = V->getSourceRange(); |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 890 | getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx) |
| 891 | DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Erik Pilkington | 5cd5717 | 2016-08-16 17:44:11 +0000 | [diff] [blame] | 894 | bool IfStmt::isObjCAvailabilityCheck() const { |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 895 | return isa<ObjCAvailabilityCheckExpr>(getCond()); |
Erik Pilkington | 5cd5717 | 2016-08-16 17:44:11 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 898 | ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 899 | Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 900 | SourceLocation RP) |
Bruno Ricci | 41d11c0 | 2018-10-27 18:43:27 +0000 | [diff] [blame] | 901 | : Stmt(ForStmtClass), LParenLoc(LP), RParenLoc(RP) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 902 | { |
| 903 | SubExprs[INIT] = Init; |
| 904 | setConditionVariable(C, condVar); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 905 | SubExprs[COND] = Cond; |
| 906 | SubExprs[INC] = Inc; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 907 | SubExprs[BODY] = Body; |
Bruno Ricci | 41d11c0 | 2018-10-27 18:43:27 +0000 | [diff] [blame] | 908 | ForStmtBits.ForLoc = FL; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | VarDecl *ForStmt::getConditionVariable() const { |
| 912 | if (!SubExprs[CONDVAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 913 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 914 | |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 915 | auto *DS = cast<DeclStmt>(SubExprs[CONDVAR]); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 916 | return cast<VarDecl>(DS->getSingleDecl()); |
| 917 | } |
| 918 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 919 | void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 920 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 921 | SubExprs[CONDVAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 922 | return; |
| 923 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 924 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 925 | SourceRange VarRange = V->getSourceRange(); |
| 926 | SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 927 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 930 | SwitchStmt::SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, |
| 931 | Expr *Cond) |
| 932 | : Stmt(SwitchStmtClass), FirstCase(nullptr) { |
| 933 | bool HasInit = Init != nullptr; |
| 934 | bool HasVar = Var != nullptr; |
| 935 | SwitchStmtBits.HasInit = HasInit; |
| 936 | SwitchStmtBits.HasVar = HasVar; |
| 937 | SwitchStmtBits.AllEnumCasesCovered = false; |
| 938 | |
| 939 | setCond(Cond); |
| 940 | setBody(nullptr); |
| 941 | if (HasInit) |
| 942 | setInit(Init); |
| 943 | if (HasVar) |
| 944 | setConditionVariable(Ctx, Var); |
| 945 | |
| 946 | setSwitchLoc(SourceLocation{}); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 949 | SwitchStmt::SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar) |
| 950 | : Stmt(SwitchStmtClass, Empty) { |
| 951 | SwitchStmtBits.HasInit = HasInit; |
| 952 | SwitchStmtBits.HasVar = HasVar; |
| 953 | SwitchStmtBits.AllEnumCasesCovered = false; |
| 954 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 955 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 956 | SwitchStmt *SwitchStmt::Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, |
| 957 | Expr *Cond) { |
| 958 | bool HasInit = Init != nullptr; |
| 959 | bool HasVar = Var != nullptr; |
| 960 | void *Mem = Ctx.Allocate( |
| 961 | totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar), |
| 962 | alignof(SwitchStmt)); |
| 963 | return new (Mem) SwitchStmt(Ctx, Init, Var, Cond); |
| 964 | } |
| 965 | |
| 966 | SwitchStmt *SwitchStmt::CreateEmpty(const ASTContext &Ctx, bool HasInit, |
| 967 | bool HasVar) { |
| 968 | void *Mem = Ctx.Allocate( |
| 969 | totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar), |
| 970 | alignof(SwitchStmt)); |
| 971 | return new (Mem) SwitchStmt(EmptyShell(), HasInit, HasVar); |
| 972 | } |
| 973 | |
| 974 | VarDecl *SwitchStmt::getConditionVariable() { |
| 975 | auto *DS = getConditionVariableDeclStmt(); |
| 976 | if (!DS) |
| 977 | return nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 978 | return cast<VarDecl>(DS->getSingleDecl()); |
| 979 | } |
| 980 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 981 | void SwitchStmt::setConditionVariable(const ASTContext &Ctx, VarDecl *V) { |
| 982 | assert(hasVarStorage() && |
| 983 | "This switch statement has no storage for a condition variable!"); |
| 984 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 985 | if (!V) { |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 986 | getTrailingObjects<Stmt *>()[varOffset()] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 987 | return; |
| 988 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 989 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 990 | SourceRange VarRange = V->getSourceRange(); |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 991 | getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx) |
| 992 | DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 995 | WhileStmt::WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, |
| 996 | Stmt *Body, SourceLocation WL) |
| 997 | : Stmt(WhileStmtClass) { |
| 998 | bool HasVar = Var != nullptr; |
| 999 | WhileStmtBits.HasVar = HasVar; |
| 1000 | |
| 1001 | setCond(Cond); |
| 1002 | setBody(Body); |
| 1003 | if (HasVar) |
| 1004 | setConditionVariable(Ctx, Var); |
| 1005 | |
| 1006 | setWhileLoc(WL); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 1009 | WhileStmt::WhileStmt(EmptyShell Empty, bool HasVar) |
| 1010 | : Stmt(WhileStmtClass, Empty) { |
| 1011 | WhileStmtBits.HasVar = HasVar; |
| 1012 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 1013 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 1014 | WhileStmt *WhileStmt::Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, |
| 1015 | Stmt *Body, SourceLocation WL) { |
| 1016 | bool HasVar = Var != nullptr; |
| 1017 | void *Mem = |
| 1018 | Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar), |
| 1019 | alignof(WhileStmt)); |
| 1020 | return new (Mem) WhileStmt(Ctx, Var, Cond, Body, WL); |
| 1021 | } |
| 1022 | |
| 1023 | WhileStmt *WhileStmt::CreateEmpty(const ASTContext &Ctx, bool HasVar) { |
| 1024 | void *Mem = |
| 1025 | Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar), |
| 1026 | alignof(WhileStmt)); |
| 1027 | return new (Mem) WhileStmt(EmptyShell(), HasVar); |
| 1028 | } |
| 1029 | |
| 1030 | VarDecl *WhileStmt::getConditionVariable() { |
| 1031 | auto *DS = getConditionVariableDeclStmt(); |
| 1032 | if (!DS) |
| 1033 | return nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 1034 | return cast<VarDecl>(DS->getSingleDecl()); |
| 1035 | } |
| 1036 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 1037 | void WhileStmt::setConditionVariable(const ASTContext &Ctx, VarDecl *V) { |
| 1038 | assert(hasVarStorage() && |
| 1039 | "This while statement has no storage for a condition variable!"); |
| 1040 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 1041 | if (!V) { |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 1042 | getTrailingObjects<Stmt *>()[varOffset()] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 1043 | return; |
| 1044 | } |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 1045 | |
| 1046 | SourceRange VarRange = V->getSourceRange(); |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 1047 | getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx) |
| 1048 | DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1051 | // IndirectGotoStmt |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1052 | LabelDecl *IndirectGotoStmt::getConstantTarget() { |
Eugene Zelenko | 7855e77 | 2018-04-03 00:11:50 +0000 | [diff] [blame] | 1053 | if (auto *E = dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 1054 | return E->getLabel(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1055 | return nullptr; |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 1056 | } |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1057 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1058 | // ReturnStmt |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 1059 | ReturnStmt::ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) |
| 1060 | : Stmt(ReturnStmtClass), RetExpr(E) { |
| 1061 | bool HasNRVOCandidate = NRVOCandidate != nullptr; |
| 1062 | ReturnStmtBits.HasNRVOCandidate = HasNRVOCandidate; |
| 1063 | if (HasNRVOCandidate) |
| 1064 | setNRVOCandidate(NRVOCandidate); |
| 1065 | setReturnLoc(RL); |
Ted Kremenek | c6501db | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 1066 | } |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 1067 | |
| 1068 | ReturnStmt::ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate) |
| 1069 | : Stmt(ReturnStmtClass, Empty) { |
| 1070 | ReturnStmtBits.HasNRVOCandidate = HasNRVOCandidate; |
| 1071 | } |
| 1072 | |
| 1073 | ReturnStmt *ReturnStmt::Create(const ASTContext &Ctx, SourceLocation RL, |
| 1074 | Expr *E, const VarDecl *NRVOCandidate) { |
| 1075 | bool HasNRVOCandidate = NRVOCandidate != nullptr; |
| 1076 | void *Mem = Ctx.Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate), |
| 1077 | alignof(ReturnStmt)); |
| 1078 | return new (Mem) ReturnStmt(RL, E, NRVOCandidate); |
| 1079 | } |
| 1080 | |
| 1081 | ReturnStmt *ReturnStmt::CreateEmpty(const ASTContext &Ctx, |
| 1082 | bool HasNRVOCandidate) { |
| 1083 | void *Mem = Ctx.Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate), |
| 1084 | alignof(ReturnStmt)); |
| 1085 | return new (Mem) ReturnStmt(EmptyShell(), HasNRVOCandidate); |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1086 | } |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1087 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 1088 | // CaseStmt |
| 1089 | CaseStmt *CaseStmt::Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, |
| 1090 | SourceLocation caseLoc, SourceLocation ellipsisLoc, |
| 1091 | SourceLocation colonLoc) { |
| 1092 | bool CaseStmtIsGNURange = rhs != nullptr; |
| 1093 | void *Mem = Ctx.Allocate( |
| 1094 | totalSizeToAlloc<Stmt *, SourceLocation>( |
| 1095 | NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange), |
| 1096 | alignof(CaseStmt)); |
| 1097 | return new (Mem) CaseStmt(lhs, rhs, caseLoc, ellipsisLoc, colonLoc); |
| 1098 | } |
| 1099 | |
| 1100 | CaseStmt *CaseStmt::CreateEmpty(const ASTContext &Ctx, |
| 1101 | bool CaseStmtIsGNURange) { |
| 1102 | void *Mem = Ctx.Allocate( |
| 1103 | totalSizeToAlloc<Stmt *, SourceLocation>( |
| 1104 | NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange), |
| 1105 | alignof(CaseStmt)); |
| 1106 | return new (Mem) CaseStmt(EmptyShell(), CaseStmtIsGNURange); |
| 1107 | } |
| 1108 | |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 1109 | SEHTryStmt::SEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1110 | Stmt *Handler) |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 1111 | : Stmt(SEHTryStmtClass), IsCXXTry(IsCXXTry), TryLoc(TryLoc) { |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1112 | Children[TRY] = TryBlock; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1113 | Children[HANDLER] = Handler; |
| 1114 | } |
| 1115 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1116 | SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1117 | SourceLocation TryLoc, Stmt *TryBlock, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1118 | Stmt *Handler) { |
| 1119 | return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | SEHExceptStmt* SEHTryStmt::getExceptHandler() const { |
| 1123 | return dyn_cast<SEHExceptStmt>(getHandler()); |
| 1124 | } |
| 1125 | |
| 1126 | SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { |
| 1127 | return dyn_cast<SEHFinallyStmt>(getHandler()); |
| 1128 | } |
| 1129 | |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 1130 | SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block) |
| 1131 | : Stmt(SEHExceptStmtClass), Loc(Loc) { |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 1132 | Children[FILTER_EXPR] = FilterExpr; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1133 | Children[BLOCK] = Block; |
| 1134 | } |
| 1135 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1136 | SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, |
| 1137 | Expr *FilterExpr, Stmt *Block) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1138 | return new(C) SEHExceptStmt(Loc,FilterExpr,Block); |
| 1139 | } |
| 1140 | |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 1141 | SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, Stmt *Block) |
| 1142 | : Stmt(SEHFinallyStmtClass), Loc(Loc), Block(Block) {} |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1143 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1144 | SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1145 | Stmt *Block) { |
| 1146 | return new(C)SEHFinallyStmt(Loc,Block); |
| 1147 | } |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1148 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1149 | CapturedStmt::Capture::Capture(SourceLocation Loc, VariableCaptureKind Kind, |
| 1150 | VarDecl *Var) |
| 1151 | : VarAndKind(Var, Kind), Loc(Loc) { |
| 1152 | switch (Kind) { |
| 1153 | case VCK_This: |
| 1154 | assert(!Var && "'this' capture cannot have a variable!"); |
| 1155 | break; |
| 1156 | case VCK_ByRef: |
| 1157 | assert(Var && "capturing by reference must have a variable!"); |
| 1158 | break; |
| 1159 | case VCK_ByCopy: |
| 1160 | assert(Var && "capturing by copy must have a variable!"); |
| 1161 | assert( |
| 1162 | (Var->getType()->isScalarType() || (Var->getType()->isReferenceType() && |
| 1163 | Var->getType() |
| 1164 | ->castAs<ReferenceType>() |
| 1165 | ->getPointeeType() |
| 1166 | ->isScalarType())) && |
| 1167 | "captures by copy are expected to have a scalar type!"); |
| 1168 | break; |
| 1169 | case VCK_VLAType: |
| 1170 | assert(!Var && |
| 1171 | "Variable-length array type capture cannot have a variable!"); |
| 1172 | break; |
| 1173 | } |
| 1174 | } |
| 1175 | |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 1176 | CapturedStmt::VariableCaptureKind |
| 1177 | CapturedStmt::Capture::getCaptureKind() const { |
| 1178 | return VarAndKind.getInt(); |
| 1179 | } |
| 1180 | |
| 1181 | VarDecl *CapturedStmt::Capture::getCapturedVar() const { |
| 1182 | assert((capturesVariable() || capturesVariableByCopy()) && |
| 1183 | "No variable available for 'this' or VAT capture"); |
| 1184 | return VarAndKind.getPointer(); |
| 1185 | } |
| 1186 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1187 | CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { |
| 1188 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1189 | |
| 1190 | // Offset of the first Capture object. |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 1191 | unsigned FirstCaptureOffset = llvm::alignTo(Size, alignof(Capture)); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1192 | |
| 1193 | return reinterpret_cast<Capture *>( |
| 1194 | reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) |
| 1195 | + FirstCaptureOffset); |
| 1196 | } |
| 1197 | |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1198 | CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, |
| 1199 | ArrayRef<Capture> Captures, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1200 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1201 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1202 | RecordDecl *RD) |
| 1203 | : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1204 | CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1205 | assert( S && "null captured statement"); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1206 | assert(CD && "null captured declaration for captured statement"); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1207 | assert(RD && "null record declaration for captured statement"); |
| 1208 | |
| 1209 | // Copy initialization expressions. |
| 1210 | Stmt **Stored = getStoredStmts(); |
| 1211 | for (unsigned I = 0, N = NumCaptures; I != N; ++I) |
| 1212 | *Stored++ = CaptureInits[I]; |
| 1213 | |
| 1214 | // Copy the statement being captured. |
| 1215 | *Stored = S; |
| 1216 | |
| 1217 | // Copy all Capture objects. |
| 1218 | Capture *Buffer = getStoredCaptures(); |
| 1219 | std::copy(Captures.begin(), Captures.end(), Buffer); |
| 1220 | } |
| 1221 | |
| 1222 | CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) |
| 1223 | : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 1224 | CapDeclAndKind(nullptr, CR_Default) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1225 | getStoredStmts()[NumCaptures] = nullptr; |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1228 | CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1229 | CapturedRegionKind Kind, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1230 | ArrayRef<Capture> Captures, |
| 1231 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1232 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1233 | RecordDecl *RD) { |
| 1234 | // The layout is |
| 1235 | // |
| 1236 | // ----------------------------------------------------------- |
| 1237 | // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | |
| 1238 | // ----------------^-------------------^---------------------- |
| 1239 | // getStoredStmts() getStoredCaptures() |
| 1240 | // |
| 1241 | // where S is the statement being captured. |
| 1242 | // |
| 1243 | assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); |
| 1244 | |
| 1245 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); |
| 1246 | if (!Captures.empty()) { |
| 1247 | // Realign for the following Capture array. |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 1248 | Size = llvm::alignTo(Size, alignof(Capture)); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1249 | Size += sizeof(Capture) * Captures.size(); |
| 1250 | } |
| 1251 | |
| 1252 | void *Mem = Context.Allocate(Size); |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1253 | return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1256 | CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1257 | unsigned NumCaptures) { |
| 1258 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1259 | if (NumCaptures > 0) { |
| 1260 | // Realign for the following Capture array. |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 1261 | Size = llvm::alignTo(Size, alignof(Capture)); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1262 | Size += sizeof(Capture) * NumCaptures; |
| 1263 | } |
| 1264 | |
| 1265 | void *Mem = Context.Allocate(Size); |
| 1266 | return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); |
| 1267 | } |
| 1268 | |
| 1269 | Stmt::child_range CapturedStmt::children() { |
Simon Pilgrim | 2c51880 | 2017-03-30 14:13:19 +0000 | [diff] [blame] | 1270 | // Children are captured field initializers. |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1271 | return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Bruno Ricci | 0618650 | 2019-04-12 15:36:02 +0000 | [diff] [blame] | 1274 | Stmt::const_child_range CapturedStmt::children() const { |
| 1275 | return const_child_range(getStoredStmts(), getStoredStmts() + NumCaptures); |
| 1276 | } |
| 1277 | |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 1278 | CapturedDecl *CapturedStmt::getCapturedDecl() { |
| 1279 | return CapDeclAndKind.getPointer(); |
| 1280 | } |
Eugene Zelenko | 1eab6c1 | 2017-11-14 23:35:42 +0000 | [diff] [blame] | 1281 | |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 1282 | const CapturedDecl *CapturedStmt::getCapturedDecl() const { |
| 1283 | return CapDeclAndKind.getPointer(); |
| 1284 | } |
| 1285 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1286 | /// Set the outlined function declaration. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 1287 | void CapturedStmt::setCapturedDecl(CapturedDecl *D) { |
| 1288 | assert(D && "null CapturedDecl"); |
| 1289 | CapDeclAndKind.setPointer(D); |
| 1290 | } |
| 1291 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1292 | /// Retrieve the captured region kind. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 1293 | CapturedRegionKind CapturedStmt::getCapturedRegionKind() const { |
| 1294 | return CapDeclAndKind.getInt(); |
| 1295 | } |
| 1296 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1297 | /// Set the captured region kind. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 1298 | void CapturedStmt::setCapturedRegionKind(CapturedRegionKind Kind) { |
| 1299 | CapDeclAndKind.setInt(Kind); |
| 1300 | } |
| 1301 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1302 | bool CapturedStmt::capturesVariable(const VarDecl *Var) const { |
Aaron Ballman | c656303a | 2014-03-14 18:08:33 +0000 | [diff] [blame] | 1303 | for (const auto &I : captures()) { |
Alexey Bataev | 2c84541 | 2017-05-15 16:26:15 +0000 | [diff] [blame] | 1304 | if (!I.capturesVariable() && !I.capturesVariableByCopy()) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1305 | continue; |
Alexey Bataev | e85de8f | 2017-09-20 20:11:31 +0000 | [diff] [blame] | 1306 | if (I.getCapturedVar()->getCanonicalDecl() == Var->getCanonicalDecl()) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1307 | return true; |
| 1308 | } |
| 1309 | |
| 1310 | return false; |
| 1311 | } |