ExprObjC.h 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ExprObjC.h - Classes for representing ObjC expressions ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the ExprObjC interface and subclasses.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_AST_EXPROBJC_H
  18. #define LLVM_CLANG_AST_EXPROBJC_H
  19. #include "clang/AST/ComputeDependence.h"
  20. #include "clang/AST/Decl.h"
  21. #include "clang/AST/DeclObjC.h"
  22. #include "clang/AST/DependenceFlags.h"
  23. #include "clang/AST/Expr.h"
  24. #include "clang/AST/OperationKinds.h"
  25. #include "clang/AST/SelectorLocationsKind.h"
  26. #include "clang/AST/Stmt.h"
  27. #include "clang/AST/Type.h"
  28. #include "clang/Basic/IdentifierTable.h"
  29. #include "clang/Basic/LLVM.h"
  30. #include "clang/Basic/SourceLocation.h"
  31. #include "clang/Basic/Specifiers.h"
  32. #include "llvm/ADT/ArrayRef.h"
  33. #include "llvm/ADT/PointerIntPair.h"
  34. #include "llvm/ADT/PointerUnion.h"
  35. #include "llvm/ADT/StringRef.h"
  36. #include "llvm/ADT/iterator_range.h"
  37. #include "llvm/Support/Casting.h"
  38. #include "llvm/Support/Compiler.h"
  39. #include "llvm/Support/TrailingObjects.h"
  40. #include "llvm/Support/VersionTuple.h"
  41. #include "llvm/Support/type_traits.h"
  42. #include <cassert>
  43. #include <cstddef>
  44. #include <cstdint>
  45. #include <optional>
  46. namespace clang {
  47. class ASTContext;
  48. class CXXBaseSpecifier;
  49. /// ObjCStringLiteral, used for Objective-C string literals
  50. /// i.e. @"foo".
  51. class ObjCStringLiteral : public Expr {
  52. Stmt *String;
  53. SourceLocation AtLoc;
  54. public:
  55. ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
  56. : Expr(ObjCStringLiteralClass, T, VK_PRValue, OK_Ordinary), String(SL),
  57. AtLoc(L) {
  58. setDependence(ExprDependence::None);
  59. }
  60. explicit ObjCStringLiteral(EmptyShell Empty)
  61. : Expr(ObjCStringLiteralClass, Empty) {}
  62. StringLiteral *getString() { return cast<StringLiteral>(String); }
  63. const StringLiteral *getString() const { return cast<StringLiteral>(String); }
  64. void setString(StringLiteral *S) { String = S; }
  65. SourceLocation getAtLoc() const { return AtLoc; }
  66. void setAtLoc(SourceLocation L) { AtLoc = L; }
  67. SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
  68. SourceLocation getEndLoc() const LLVM_READONLY { return String->getEndLoc(); }
  69. // Iterators
  70. child_range children() { return child_range(&String, &String+1); }
  71. const_child_range children() const {
  72. return const_child_range(&String, &String + 1);
  73. }
  74. static bool classof(const Stmt *T) {
  75. return T->getStmtClass() == ObjCStringLiteralClass;
  76. }
  77. };
  78. /// ObjCBoolLiteralExpr - Objective-C Boolean Literal.
  79. class ObjCBoolLiteralExpr : public Expr {
  80. bool Value;
  81. SourceLocation Loc;
  82. public:
  83. ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l)
  84. : Expr(ObjCBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary), Value(val),
  85. Loc(l) {
  86. setDependence(ExprDependence::None);
  87. }
  88. explicit ObjCBoolLiteralExpr(EmptyShell Empty)
  89. : Expr(ObjCBoolLiteralExprClass, Empty) {}
  90. bool getValue() const { return Value; }
  91. void setValue(bool V) { Value = V; }
  92. SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
  93. SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
  94. SourceLocation getLocation() const { return Loc; }
  95. void setLocation(SourceLocation L) { Loc = L; }
  96. // Iterators
  97. child_range children() {
  98. return child_range(child_iterator(), child_iterator());
  99. }
  100. const_child_range children() const {
  101. return const_child_range(const_child_iterator(), const_child_iterator());
  102. }
  103. static bool classof(const Stmt *T) {
  104. return T->getStmtClass() == ObjCBoolLiteralExprClass;
  105. }
  106. };
  107. /// ObjCBoxedExpr - used for generalized expression boxing.
  108. /// as in: @(strdup("hello world")), @(random()) or @(view.frame)
  109. /// Also used for boxing non-parenthesized numeric literals;
  110. /// as in: @42 or \@true (c++/objc++) or \@__objc_yes (c/objc).
  111. class ObjCBoxedExpr : public Expr {
  112. Stmt *SubExpr;
  113. ObjCMethodDecl *BoxingMethod;
  114. SourceRange Range;
  115. public:
  116. friend class ASTStmtReader;
  117. ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *method, SourceRange R)
  118. : Expr(ObjCBoxedExprClass, T, VK_PRValue, OK_Ordinary), SubExpr(E),
  119. BoxingMethod(method), Range(R) {
  120. setDependence(computeDependence(this));
  121. }
  122. explicit ObjCBoxedExpr(EmptyShell Empty)
  123. : Expr(ObjCBoxedExprClass, Empty) {}
  124. Expr *getSubExpr() { return cast<Expr>(SubExpr); }
  125. const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
  126. ObjCMethodDecl *getBoxingMethod() const {
  127. return BoxingMethod;
  128. }
  129. // Indicates whether this boxed expression can be emitted as a compile-time
  130. // constant.
  131. bool isExpressibleAsConstantInitializer() const {
  132. return !BoxingMethod && SubExpr;
  133. }
  134. SourceLocation getAtLoc() const { return Range.getBegin(); }
  135. SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
  136. SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
  137. SourceRange getSourceRange() const LLVM_READONLY {
  138. return Range;
  139. }
  140. // Iterators
  141. child_range children() { return child_range(&SubExpr, &SubExpr+1); }
  142. const_child_range children() const {
  143. return const_child_range(&SubExpr, &SubExpr + 1);
  144. }
  145. using const_arg_iterator = ConstExprIterator;
  146. const_arg_iterator arg_begin() const {
  147. return reinterpret_cast<Stmt const * const*>(&SubExpr);
  148. }
  149. const_arg_iterator arg_end() const {
  150. return reinterpret_cast<Stmt const * const*>(&SubExpr + 1);
  151. }
  152. static bool classof(const Stmt *T) {
  153. return T->getStmtClass() == ObjCBoxedExprClass;
  154. }
  155. };
  156. /// ObjCArrayLiteral - used for objective-c array containers; as in:
  157. /// @[@"Hello", NSApp, [NSNumber numberWithInt:42]];
  158. class ObjCArrayLiteral final
  159. : public Expr,
  160. private llvm::TrailingObjects<ObjCArrayLiteral, Expr *> {
  161. unsigned NumElements;
  162. SourceRange Range;
  163. ObjCMethodDecl *ArrayWithObjectsMethod;
  164. ObjCArrayLiteral(ArrayRef<Expr *> Elements,
  165. QualType T, ObjCMethodDecl * Method,
  166. SourceRange SR);
  167. explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
  168. : Expr(ObjCArrayLiteralClass, Empty), NumElements(NumElements) {}
  169. public:
  170. friend class ASTStmtReader;
  171. friend TrailingObjects;
  172. static ObjCArrayLiteral *Create(const ASTContext &C,
  173. ArrayRef<Expr *> Elements,
  174. QualType T, ObjCMethodDecl * Method,
  175. SourceRange SR);
  176. static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
  177. unsigned NumElements);
  178. SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
  179. SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
  180. SourceRange getSourceRange() const LLVM_READONLY { return Range; }
  181. /// Retrieve elements of array of literals.
  182. Expr **getElements() { return getTrailingObjects<Expr *>(); }
  183. /// Retrieve elements of array of literals.
  184. const Expr * const *getElements() const {
  185. return getTrailingObjects<Expr *>();
  186. }
  187. /// getNumElements - Return number of elements of objective-c array literal.
  188. unsigned getNumElements() const { return NumElements; }
  189. /// getElement - Return the Element at the specified index.
  190. Expr *getElement(unsigned Index) {
  191. assert((Index < NumElements) && "Arg access out of range!");
  192. return getElements()[Index];
  193. }
  194. const Expr *getElement(unsigned Index) const {
  195. assert((Index < NumElements) && "Arg access out of range!");
  196. return getElements()[Index];
  197. }
  198. ObjCMethodDecl *getArrayWithObjectsMethod() const {
  199. return ArrayWithObjectsMethod;
  200. }
  201. // Iterators
  202. child_range children() {
  203. return child_range(reinterpret_cast<Stmt **>(getElements()),
  204. reinterpret_cast<Stmt **>(getElements()) + NumElements);
  205. }
  206. const_child_range children() const {
  207. auto Children = const_cast<ObjCArrayLiteral *>(this)->children();
  208. return const_child_range(Children.begin(), Children.end());
  209. }
  210. static bool classof(const Stmt *T) {
  211. return T->getStmtClass() == ObjCArrayLiteralClass;
  212. }
  213. };
  214. /// An element in an Objective-C dictionary literal.
  215. ///
  216. struct ObjCDictionaryElement {
  217. /// The key for the dictionary element.
  218. Expr *Key;
  219. /// The value of the dictionary element.
  220. Expr *Value;
  221. /// The location of the ellipsis, if this is a pack expansion.
  222. SourceLocation EllipsisLoc;
  223. /// The number of elements this pack expansion will expand to, if
  224. /// this is a pack expansion and is known.
  225. std::optional<unsigned> NumExpansions;
  226. /// Determines whether this dictionary element is a pack expansion.
  227. bool isPackExpansion() const { return EllipsisLoc.isValid(); }
  228. };
  229. } // namespace clang
  230. namespace clang {
  231. /// Internal struct for storing Key/value pair.
  232. struct ObjCDictionaryLiteral_KeyValuePair {
  233. Expr *Key;
  234. Expr *Value;
  235. };
  236. /// Internal struct to describes an element that is a pack
  237. /// expansion, used if any of the elements in the dictionary literal
  238. /// are pack expansions.
  239. struct ObjCDictionaryLiteral_ExpansionData {
  240. /// The location of the ellipsis, if this element is a pack
  241. /// expansion.
  242. SourceLocation EllipsisLoc;
  243. /// If non-zero, the number of elements that this pack
  244. /// expansion will expand to (+1).
  245. unsigned NumExpansionsPlusOne;
  246. };
  247. /// ObjCDictionaryLiteral - AST node to represent objective-c dictionary
  248. /// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] };
  249. class ObjCDictionaryLiteral final
  250. : public Expr,
  251. private llvm::TrailingObjects<ObjCDictionaryLiteral,
  252. ObjCDictionaryLiteral_KeyValuePair,
  253. ObjCDictionaryLiteral_ExpansionData> {
  254. /// The number of elements in this dictionary literal.
  255. unsigned NumElements : 31;
  256. /// Determine whether this dictionary literal has any pack expansions.
  257. ///
  258. /// If the dictionary literal has pack expansions, then there will
  259. /// be an array of pack expansion data following the array of
  260. /// key/value pairs, which provide the locations of the ellipses (if
  261. /// any) and number of elements in the expansion (if known). If
  262. /// there are no pack expansions, we optimize away this storage.
  263. unsigned HasPackExpansions : 1;
  264. SourceRange Range;
  265. ObjCMethodDecl *DictWithObjectsMethod;
  266. using KeyValuePair = ObjCDictionaryLiteral_KeyValuePair;
  267. using ExpansionData = ObjCDictionaryLiteral_ExpansionData;
  268. ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK,
  269. bool HasPackExpansions,
  270. QualType T, ObjCMethodDecl *method,
  271. SourceRange SR);
  272. explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
  273. bool HasPackExpansions)
  274. : Expr(ObjCDictionaryLiteralClass, Empty), NumElements(NumElements),
  275. HasPackExpansions(HasPackExpansions) {}
  276. size_t numTrailingObjects(OverloadToken<KeyValuePair>) const {
  277. return NumElements;
  278. }
  279. public:
  280. friend class ASTStmtReader;
  281. friend class ASTStmtWriter;
  282. friend TrailingObjects;
  283. static ObjCDictionaryLiteral *Create(const ASTContext &C,
  284. ArrayRef<ObjCDictionaryElement> VK,
  285. bool HasPackExpansions,
  286. QualType T, ObjCMethodDecl *method,
  287. SourceRange SR);
  288. static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
  289. unsigned NumElements,
  290. bool HasPackExpansions);
  291. /// getNumElements - Return number of elements of objective-c dictionary
  292. /// literal.
  293. unsigned getNumElements() const { return NumElements; }
  294. ObjCDictionaryElement getKeyValueElement(unsigned Index) const {
  295. assert((Index < NumElements) && "Arg access out of range!");
  296. const KeyValuePair &KV = getTrailingObjects<KeyValuePair>()[Index];
  297. ObjCDictionaryElement Result = {KV.Key, KV.Value, SourceLocation(),
  298. std::nullopt};
  299. if (HasPackExpansions) {
  300. const ExpansionData &Expansion =
  301. getTrailingObjects<ExpansionData>()[Index];
  302. Result.EllipsisLoc = Expansion.EllipsisLoc;
  303. if (Expansion.NumExpansionsPlusOne > 0)
  304. Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1;
  305. }
  306. return Result;
  307. }
  308. ObjCMethodDecl *getDictWithObjectsMethod() const {
  309. return DictWithObjectsMethod;
  310. }
  311. SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
  312. SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
  313. SourceRange getSourceRange() const LLVM_READONLY { return Range; }
  314. // Iterators
  315. child_range children() {
  316. // Note: we're taking advantage of the layout of the KeyValuePair struct
  317. // here. If that struct changes, this code will need to change as well.
  318. static_assert(sizeof(KeyValuePair) == sizeof(Stmt *) * 2,
  319. "KeyValuePair is expected size");
  320. return child_range(
  321. reinterpret_cast<Stmt **>(getTrailingObjects<KeyValuePair>()),
  322. reinterpret_cast<Stmt **>(getTrailingObjects<KeyValuePair>()) +
  323. NumElements * 2);
  324. }
  325. const_child_range children() const {
  326. auto Children = const_cast<ObjCDictionaryLiteral *>(this)->children();
  327. return const_child_range(Children.begin(), Children.end());
  328. }
  329. static bool classof(const Stmt *T) {
  330. return T->getStmtClass() == ObjCDictionaryLiteralClass;
  331. }
  332. };
  333. /// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same
  334. /// type and behavior as StringLiteral except that the string initializer is
  335. /// obtained from ASTContext with the encoding type as an argument.
  336. class ObjCEncodeExpr : public Expr {
  337. TypeSourceInfo *EncodedType;
  338. SourceLocation AtLoc, RParenLoc;
  339. public:
  340. ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType, SourceLocation at,
  341. SourceLocation rp)
  342. : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary),
  343. EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {
  344. setDependence(computeDependence(this));
  345. }
  346. explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
  347. SourceLocation getAtLoc() const { return AtLoc; }
  348. void setAtLoc(SourceLocation L) { AtLoc = L; }
  349. SourceLocation getRParenLoc() const { return RParenLoc; }
  350. void setRParenLoc(SourceLocation L) { RParenLoc = L; }
  351. QualType getEncodedType() const { return EncodedType->getType(); }
  352. TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
  353. void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) {
  354. EncodedType = EncType;
  355. }
  356. SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
  357. SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
  358. // Iterators
  359. child_range children() {
  360. return child_range(child_iterator(), child_iterator());
  361. }
  362. const_child_range children() const {
  363. return const_child_range(const_child_iterator(), const_child_iterator());
  364. }
  365. static bool classof(const Stmt *T) {
  366. return T->getStmtClass() == ObjCEncodeExprClass;
  367. }
  368. };
  369. /// ObjCSelectorExpr used for \@selector in Objective-C.
  370. class ObjCSelectorExpr : public Expr {
  371. Selector SelName;
  372. SourceLocation AtLoc, RParenLoc;
  373. public:
  374. ObjCSelectorExpr(QualType T, Selector selInfo, SourceLocation at,
  375. SourceLocation rp)
  376. : Expr(ObjCSelectorExprClass, T, VK_PRValue, OK_Ordinary),
  377. SelName(selInfo), AtLoc(at), RParenLoc(rp) {
  378. setDependence(ExprDependence::None);
  379. }
  380. explicit ObjCSelectorExpr(EmptyShell Empty)
  381. : Expr(ObjCSelectorExprClass, Empty) {}
  382. Selector getSelector() const { return SelName; }
  383. void setSelector(Selector S) { SelName = S; }
  384. SourceLocation getAtLoc() const { return AtLoc; }
  385. SourceLocation getRParenLoc() const { return RParenLoc; }
  386. void setAtLoc(SourceLocation L) { AtLoc = L; }
  387. void setRParenLoc(SourceLocation L) { RParenLoc = L; }
  388. SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
  389. SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
  390. /// getNumArgs - Return the number of actual arguments to this call.
  391. unsigned getNumArgs() const { return SelName.getNumArgs(); }
  392. // Iterators
  393. child_range children() {
  394. return child_range(child_iterator(), child_iterator());
  395. }
  396. const_child_range children() const {
  397. return const_child_range(const_child_iterator(), const_child_iterator());
  398. }
  399. static bool classof(const Stmt *T) {
  400. return T->getStmtClass() == ObjCSelectorExprClass;
  401. }
  402. };
  403. /// ObjCProtocolExpr used for protocol expression in Objective-C.
  404. ///
  405. /// This is used as: \@protocol(foo), as in:
  406. /// \code
  407. /// [obj conformsToProtocol:@protocol(foo)]
  408. /// \endcode
  409. ///
  410. /// The return type is "Protocol*".
  411. class ObjCProtocolExpr : public Expr {
  412. ObjCProtocolDecl *TheProtocol;
  413. SourceLocation AtLoc, ProtoLoc, RParenLoc;
  414. public:
  415. friend class ASTStmtReader;
  416. friend class ASTStmtWriter;
  417. ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, SourceLocation at,
  418. SourceLocation protoLoc, SourceLocation rp)
  419. : Expr(ObjCProtocolExprClass, T, VK_PRValue, OK_Ordinary),
  420. TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {
  421. setDependence(ExprDependence::None);
  422. }
  423. explicit ObjCProtocolExpr(EmptyShell Empty)
  424. : Expr(ObjCProtocolExprClass, Empty) {}
  425. ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
  426. void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
  427. SourceLocation getProtocolIdLoc() const { return ProtoLoc; }
  428. SourceLocation getAtLoc() const { return AtLoc; }
  429. SourceLocation getRParenLoc() const { return RParenLoc; }
  430. void setAtLoc(SourceLocation L) { AtLoc = L; }
  431. void setRParenLoc(SourceLocation L) { RParenLoc = L; }
  432. SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
  433. SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
  434. // Iterators
  435. child_range children() {
  436. return child_range(child_iterator(), child_iterator());
  437. }
  438. const_child_range children() const {
  439. return const_child_range(const_child_iterator(), const_child_iterator());
  440. }
  441. static bool classof(const Stmt *T) {
  442. return T->getStmtClass() == ObjCProtocolExprClass;
  443. }
  444. };
  445. /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
  446. class ObjCIvarRefExpr : public Expr {
  447. ObjCIvarDecl *D;
  448. Stmt *Base;
  449. SourceLocation Loc;
  450. /// OpLoc - This is the location of '.' or '->'
  451. SourceLocation OpLoc;
  452. // True if this is "X->F", false if this is "X.F".
  453. bool IsArrow : 1;
  454. // True if ivar reference has no base (self assumed).
  455. bool IsFreeIvar : 1;
  456. public:
  457. ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l,
  458. SourceLocation oploc, Expr *base, bool arrow = false,
  459. bool freeIvar = false)
  460. : Expr(ObjCIvarRefExprClass, t, VK_LValue,
  461. d->isBitField() ? OK_BitField : OK_Ordinary),
  462. D(d), Base(base), Loc(l), OpLoc(oploc), IsArrow(arrow),
  463. IsFreeIvar(freeIvar) {
  464. setDependence(computeDependence(this));
  465. }
  466. explicit ObjCIvarRefExpr(EmptyShell Empty)
  467. : Expr(ObjCIvarRefExprClass, Empty) {}
  468. ObjCIvarDecl *getDecl() { return D; }
  469. const ObjCIvarDecl *getDecl() const { return D; }
  470. void setDecl(ObjCIvarDecl *d) { D = d; }
  471. const Expr *getBase() const { return cast<Expr>(Base); }
  472. Expr *getBase() { return cast<Expr>(Base); }
  473. void setBase(Expr * base) { Base = base; }
  474. bool isArrow() const { return IsArrow; }
  475. bool isFreeIvar() const { return IsFreeIvar; }
  476. void setIsArrow(bool A) { IsArrow = A; }
  477. void setIsFreeIvar(bool A) { IsFreeIvar = A; }
  478. SourceLocation getLocation() const { return Loc; }
  479. void setLocation(SourceLocation L) { Loc = L; }
  480. SourceLocation getBeginLoc() const LLVM_READONLY {
  481. return isFreeIvar() ? Loc : getBase()->getBeginLoc();
  482. }
  483. SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
  484. SourceLocation getOpLoc() const { return OpLoc; }
  485. void setOpLoc(SourceLocation L) { OpLoc = L; }
  486. // Iterators
  487. child_range children() { return child_range(&Base, &Base+1); }
  488. const_child_range children() const {
  489. return const_child_range(&Base, &Base + 1);
  490. }
  491. static bool classof(const Stmt *T) {
  492. return T->getStmtClass() == ObjCIvarRefExprClass;
  493. }
  494. };
  495. /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
  496. /// property.
  497. class ObjCPropertyRefExpr : public Expr {
  498. private:
  499. /// If the bool is true, this is an implicit property reference; the
  500. /// pointer is an (optional) ObjCMethodDecl and Setter may be set.
  501. /// if the bool is false, this is an explicit property reference;
  502. /// the pointer is an ObjCPropertyDecl and Setter is always null.
  503. llvm::PointerIntPair<NamedDecl *, 1, bool> PropertyOrGetter;
  504. /// Indicates whether the property reference will result in a message
  505. /// to the getter, the setter, or both.
  506. /// This applies to both implicit and explicit property references.
  507. enum MethodRefFlags {
  508. MethodRef_None = 0,
  509. MethodRef_Getter = 0x1,
  510. MethodRef_Setter = 0x2
  511. };
  512. /// Contains the Setter method pointer and MethodRefFlags bit flags.
  513. llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
  514. // FIXME: Maybe we should store the property identifier here,
  515. // because it's not rederivable from the other data when there's an
  516. // implicit property with no getter (because the 'foo' -> 'setFoo:'
  517. // transformation is lossy on the first character).
  518. SourceLocation IdLoc;
  519. /// When the receiver in property access is 'super', this is
  520. /// the location of the 'super' keyword. When it's an interface,
  521. /// this is that interface.
  522. SourceLocation ReceiverLoc;
  523. llvm::PointerUnion<Stmt *, const Type *, ObjCInterfaceDecl *> Receiver;
  524. public:
  525. ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, ExprValueKind VK,
  526. ExprObjectKind OK, SourceLocation l, Expr *base)
  527. : Expr(ObjCPropertyRefExprClass, t, VK, OK), PropertyOrGetter(PD, false),
  528. IdLoc(l), Receiver(base) {
  529. assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
  530. setDependence(computeDependence(this));
  531. }
  532. ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, ExprValueKind VK,
  533. ExprObjectKind OK, SourceLocation l, SourceLocation sl,
  534. QualType st)
  535. : Expr(ObjCPropertyRefExprClass, t, VK, OK), PropertyOrGetter(PD, false),
  536. IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) {
  537. assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
  538. setDependence(computeDependence(this));
  539. }
  540. ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
  541. QualType T, ExprValueKind VK, ExprObjectKind OK,
  542. SourceLocation IdLoc, Expr *Base)
  543. : Expr(ObjCPropertyRefExprClass, T, VK, OK),
  544. PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
  545. IdLoc(IdLoc), Receiver(Base) {
  546. assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
  547. setDependence(computeDependence(this));
  548. }
  549. ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
  550. QualType T, ExprValueKind VK, ExprObjectKind OK,
  551. SourceLocation IdLoc, SourceLocation SuperLoc,
  552. QualType SuperTy)
  553. : Expr(ObjCPropertyRefExprClass, T, VK, OK),
  554. PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
  555. IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) {
  556. assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
  557. setDependence(computeDependence(this));
  558. }
  559. ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
  560. QualType T, ExprValueKind VK, ExprObjectKind OK,
  561. SourceLocation IdLoc, SourceLocation ReceiverLoc,
  562. ObjCInterfaceDecl *Receiver)
  563. : Expr(ObjCPropertyRefExprClass, T, VK, OK),
  564. PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
  565. IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) {
  566. assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
  567. setDependence(computeDependence(this));
  568. }
  569. explicit ObjCPropertyRefExpr(EmptyShell Empty)
  570. : Expr(ObjCPropertyRefExprClass, Empty) {}
  571. bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
  572. bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
  573. ObjCPropertyDecl *getExplicitProperty() const {
  574. assert(!isImplicitProperty());
  575. return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
  576. }
  577. ObjCMethodDecl *getImplicitPropertyGetter() const {
  578. assert(isImplicitProperty());
  579. return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
  580. }
  581. ObjCMethodDecl *getImplicitPropertySetter() const {
  582. assert(isImplicitProperty());
  583. return SetterAndMethodRefFlags.getPointer();
  584. }
  585. Selector getGetterSelector() const {
  586. if (isImplicitProperty())
  587. return getImplicitPropertyGetter()->getSelector();
  588. return getExplicitProperty()->getGetterName();
  589. }
  590. Selector getSetterSelector() const {
  591. if (isImplicitProperty())
  592. return getImplicitPropertySetter()->getSelector();
  593. return getExplicitProperty()->getSetterName();
  594. }
  595. /// True if the property reference will result in a message to the
  596. /// getter.
  597. /// This applies to both implicit and explicit property references.
  598. bool isMessagingGetter() const {
  599. return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
  600. }
  601. /// True if the property reference will result in a message to the
  602. /// setter.
  603. /// This applies to both implicit and explicit property references.
  604. bool isMessagingSetter() const {
  605. return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
  606. }
  607. void setIsMessagingGetter(bool val = true) {
  608. setMethodRefFlag(MethodRef_Getter, val);
  609. }
  610. void setIsMessagingSetter(bool val = true) {
  611. setMethodRefFlag(MethodRef_Setter, val);
  612. }
  613. const Expr *getBase() const {
  614. return cast<Expr>(Receiver.get<Stmt*>());
  615. }
  616. Expr *getBase() {
  617. return cast<Expr>(Receiver.get<Stmt*>());
  618. }
  619. SourceLocation getLocation() const { return IdLoc; }
  620. SourceLocation getReceiverLocation() const { return ReceiverLoc; }
  621. QualType getSuperReceiverType() const {
  622. return QualType(Receiver.get<const Type*>(), 0);
  623. }
  624. ObjCInterfaceDecl *getClassReceiver() const {
  625. return Receiver.get<ObjCInterfaceDecl*>();
  626. }
  627. bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
  628. bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
  629. bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
  630. /// Determine the type of the base, regardless of the kind of receiver.
  631. QualType getReceiverType(const ASTContext &ctx) const;
  632. SourceLocation getBeginLoc() const LLVM_READONLY {
  633. return isObjectReceiver() ? getBase()->getBeginLoc()
  634. : getReceiverLocation();
  635. }
  636. SourceLocation getEndLoc() const LLVM_READONLY { return IdLoc; }
  637. // Iterators
  638. child_range children() {
  639. if (Receiver.is<Stmt*>()) {
  640. Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
  641. return child_range(begin, begin+1);
  642. }
  643. return child_range(child_iterator(), child_iterator());
  644. }
  645. const_child_range children() const {
  646. auto Children = const_cast<ObjCPropertyRefExpr *>(this)->children();
  647. return const_child_range(Children.begin(), Children.end());
  648. }
  649. static bool classof(const Stmt *T) {
  650. return T->getStmtClass() == ObjCPropertyRefExprClass;
  651. }
  652. private:
  653. friend class ASTStmtReader;
  654. friend class ASTStmtWriter;
  655. void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
  656. PropertyOrGetter.setPointer(D);
  657. PropertyOrGetter.setInt(false);
  658. SetterAndMethodRefFlags.setPointer(nullptr);
  659. SetterAndMethodRefFlags.setInt(methRefFlags);
  660. }
  661. void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
  662. unsigned methRefFlags) {
  663. PropertyOrGetter.setPointer(Getter);
  664. PropertyOrGetter.setInt(true);
  665. SetterAndMethodRefFlags.setPointer(Setter);
  666. SetterAndMethodRefFlags.setInt(methRefFlags);
  667. }
  668. void setBase(Expr *Base) { Receiver = Base; }
  669. void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
  670. void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
  671. void setLocation(SourceLocation L) { IdLoc = L; }
  672. void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
  673. void setMethodRefFlag(MethodRefFlags flag, bool val) {
  674. unsigned f = SetterAndMethodRefFlags.getInt();
  675. if (val)
  676. f |= flag;
  677. else
  678. f &= ~flag;
  679. SetterAndMethodRefFlags.setInt(f);
  680. }
  681. };
  682. /// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
  683. /// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
  684. class ObjCSubscriptRefExpr : public Expr {
  685. // Location of ']' in an indexing expression.
  686. SourceLocation RBracket;
  687. // array/dictionary base expression.
  688. // for arrays, this is a numeric expression. For dictionaries, this is
  689. // an objective-c object pointer expression.
  690. enum { BASE, KEY, END_EXPR };
  691. Stmt* SubExprs[END_EXPR];
  692. ObjCMethodDecl *GetAtIndexMethodDecl;
  693. // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
  694. // an indexed object this is null too.
  695. ObjCMethodDecl *SetAtIndexMethodDecl;
  696. public:
  697. ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, ExprValueKind VK,
  698. ExprObjectKind OK, ObjCMethodDecl *getMethod,
  699. ObjCMethodDecl *setMethod, SourceLocation RB)
  700. : Expr(ObjCSubscriptRefExprClass, T, VK, OK), RBracket(RB),
  701. GetAtIndexMethodDecl(getMethod), SetAtIndexMethodDecl(setMethod) {
  702. SubExprs[BASE] = base;
  703. SubExprs[KEY] = key;
  704. setDependence(computeDependence(this));
  705. }
  706. explicit ObjCSubscriptRefExpr(EmptyShell Empty)
  707. : Expr(ObjCSubscriptRefExprClass, Empty) {}
  708. SourceLocation getRBracket() const { return RBracket; }
  709. void setRBracket(SourceLocation RB) { RBracket = RB; }
  710. SourceLocation getBeginLoc() const LLVM_READONLY {
  711. return SubExprs[BASE]->getBeginLoc();
  712. }
  713. SourceLocation getEndLoc() const LLVM_READONLY { return RBracket; }
  714. Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
  715. void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
  716. Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
  717. void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
  718. ObjCMethodDecl *getAtIndexMethodDecl() const {
  719. return GetAtIndexMethodDecl;
  720. }
  721. ObjCMethodDecl *setAtIndexMethodDecl() const {
  722. return SetAtIndexMethodDecl;
  723. }
  724. bool isArraySubscriptRefExpr() const {
  725. return getKeyExpr()->getType()->isIntegralOrEnumerationType();
  726. }
  727. child_range children() {
  728. return child_range(SubExprs, SubExprs+END_EXPR);
  729. }
  730. const_child_range children() const {
  731. return const_child_range(SubExprs, SubExprs + END_EXPR);
  732. }
  733. static bool classof(const Stmt *T) {
  734. return T->getStmtClass() == ObjCSubscriptRefExprClass;
  735. }
  736. private:
  737. friend class ASTStmtReader;
  738. };
  739. /// An expression that sends a message to the given Objective-C
  740. /// object or class.
  741. ///
  742. /// The following contains two message send expressions:
  743. ///
  744. /// \code
  745. /// [[NSString alloc] initWithString:@"Hello"]
  746. /// \endcode
  747. ///
  748. /// The innermost message send invokes the "alloc" class method on the
  749. /// NSString class, while the outermost message send invokes the
  750. /// "initWithString" instance method on the object returned from
  751. /// NSString's "alloc". In all, an Objective-C message send can take
  752. /// on four different (although related) forms:
  753. ///
  754. /// 1. Send to an object instance.
  755. /// 2. Send to a class.
  756. /// 3. Send to the superclass instance of the current class.
  757. /// 4. Send to the superclass of the current class.
  758. ///
  759. /// All four kinds of message sends are modeled by the ObjCMessageExpr
  760. /// class, and can be distinguished via \c getReceiverKind(). Example:
  761. ///
  762. /// The "void *" trailing objects are actually ONE void * (the
  763. /// receiver pointer), and NumArgs Expr *. But due to the
  764. /// implementation of children(), these must be together contiguously.
  765. class ObjCMessageExpr final
  766. : public Expr,
  767. private llvm::TrailingObjects<ObjCMessageExpr, void *, SourceLocation> {
  768. /// Stores either the selector that this message is sending
  769. /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
  770. /// referring to the method that we type-checked against.
  771. uintptr_t SelectorOrMethod = 0;
  772. enum { NumArgsBitWidth = 16 };
  773. /// The number of arguments in the message send, not
  774. /// including the receiver.
  775. unsigned NumArgs : NumArgsBitWidth;
  776. /// The kind of message send this is, which is one of the
  777. /// ReceiverKind values.
  778. ///
  779. /// We pad this out to a byte to avoid excessive masking and shifting.
  780. unsigned Kind : 8;
  781. /// Whether we have an actual method prototype in \c
  782. /// SelectorOrMethod.
  783. ///
  784. /// When non-zero, we have a method declaration; otherwise, we just
  785. /// have a selector.
  786. unsigned HasMethod : 1;
  787. /// Whether this message send is a "delegate init call",
  788. /// i.e. a call of an init method on self from within an init method.
  789. unsigned IsDelegateInitCall : 1;
  790. /// Whether this message send was implicitly generated by
  791. /// the implementation rather than explicitly written by the user.
  792. unsigned IsImplicit : 1;
  793. /// Whether the locations of the selector identifiers are in a
  794. /// "standard" position, a enum SelectorLocationsKind.
  795. unsigned SelLocsKind : 2;
  796. /// When the message expression is a send to 'super', this is
  797. /// the location of the 'super' keyword.
  798. SourceLocation SuperLoc;
  799. /// The source locations of the open and close square
  800. /// brackets ('[' and ']', respectively).
  801. SourceLocation LBracLoc, RBracLoc;
  802. ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
  803. : Expr(ObjCMessageExprClass, Empty), Kind(0), HasMethod(false),
  804. IsDelegateInitCall(false), IsImplicit(false), SelLocsKind(0) {
  805. setNumArgs(NumArgs);
  806. }
  807. ObjCMessageExpr(QualType T, ExprValueKind VK,
  808. SourceLocation LBracLoc,
  809. SourceLocation SuperLoc,
  810. bool IsInstanceSuper,
  811. QualType SuperType,
  812. Selector Sel,
  813. ArrayRef<SourceLocation> SelLocs,
  814. SelectorLocationsKind SelLocsK,
  815. ObjCMethodDecl *Method,
  816. ArrayRef<Expr *> Args,
  817. SourceLocation RBracLoc,
  818. bool isImplicit);
  819. ObjCMessageExpr(QualType T, ExprValueKind VK,
  820. SourceLocation LBracLoc,
  821. TypeSourceInfo *Receiver,
  822. Selector Sel,
  823. ArrayRef<SourceLocation> SelLocs,
  824. SelectorLocationsKind SelLocsK,
  825. ObjCMethodDecl *Method,
  826. ArrayRef<Expr *> Args,
  827. SourceLocation RBracLoc,
  828. bool isImplicit);
  829. ObjCMessageExpr(QualType T, ExprValueKind VK,
  830. SourceLocation LBracLoc,
  831. Expr *Receiver,
  832. Selector Sel,
  833. ArrayRef<SourceLocation> SelLocs,
  834. SelectorLocationsKind SelLocsK,
  835. ObjCMethodDecl *Method,
  836. ArrayRef<Expr *> Args,
  837. SourceLocation RBracLoc,
  838. bool isImplicit);
  839. size_t numTrailingObjects(OverloadToken<void *>) const { return NumArgs + 1; }
  840. void setNumArgs(unsigned Num) {
  841. assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
  842. NumArgs = Num;
  843. }
  844. void initArgsAndSelLocs(ArrayRef<Expr *> Args,
  845. ArrayRef<SourceLocation> SelLocs,
  846. SelectorLocationsKind SelLocsK);
  847. /// Retrieve the pointer value of the message receiver.
  848. void *getReceiverPointer() const { return *getTrailingObjects<void *>(); }
  849. /// Set the pointer value of the message receiver.
  850. void setReceiverPointer(void *Value) {
  851. *getTrailingObjects<void *>() = Value;
  852. }
  853. SelectorLocationsKind getSelLocsKind() const {
  854. return (SelectorLocationsKind)SelLocsKind;
  855. }
  856. bool hasStandardSelLocs() const {
  857. return getSelLocsKind() != SelLoc_NonStandard;
  858. }
  859. /// Get a pointer to the stored selector identifiers locations array.
  860. /// No locations will be stored if HasStandardSelLocs is true.
  861. SourceLocation *getStoredSelLocs() {
  862. return getTrailingObjects<SourceLocation>();
  863. }
  864. const SourceLocation *getStoredSelLocs() const {
  865. return getTrailingObjects<SourceLocation>();
  866. }
  867. /// Get the number of stored selector identifiers locations.
  868. /// No locations will be stored if HasStandardSelLocs is true.
  869. unsigned getNumStoredSelLocs() const {
  870. if (hasStandardSelLocs())
  871. return 0;
  872. return getNumSelectorLocs();
  873. }
  874. static ObjCMessageExpr *alloc(const ASTContext &C,
  875. ArrayRef<Expr *> Args,
  876. SourceLocation RBraceLoc,
  877. ArrayRef<SourceLocation> SelLocs,
  878. Selector Sel,
  879. SelectorLocationsKind &SelLocsK);
  880. static ObjCMessageExpr *alloc(const ASTContext &C,
  881. unsigned NumArgs,
  882. unsigned NumStoredSelLocs);
  883. public:
  884. friend class ASTStmtReader;
  885. friend class ASTStmtWriter;
  886. friend TrailingObjects;
  887. /// The kind of receiver this message is sending to.
  888. enum ReceiverKind {
  889. /// The receiver is a class.
  890. Class = 0,
  891. /// The receiver is an object instance.
  892. Instance,
  893. /// The receiver is a superclass.
  894. SuperClass,
  895. /// The receiver is the instance of the superclass object.
  896. SuperInstance
  897. };
  898. /// Create a message send to super.
  899. ///
  900. /// \param Context The ASTContext in which this expression will be created.
  901. ///
  902. /// \param T The result type of this message.
  903. ///
  904. /// \param VK The value kind of this message. A message returning
  905. /// a l-value or r-value reference will be an l-value or x-value,
  906. /// respectively.
  907. ///
  908. /// \param LBracLoc The location of the open square bracket '['.
  909. ///
  910. /// \param SuperLoc The location of the "super" keyword.
  911. ///
  912. /// \param IsInstanceSuper Whether this is an instance "super"
  913. /// message (otherwise, it's a class "super" message).
  914. ///
  915. /// \param Sel The selector used to determine which method gets called.
  916. ///
  917. /// \param Method The Objective-C method against which this message
  918. /// send was type-checked. May be nullptr.
  919. ///
  920. /// \param Args The message send arguments.
  921. ///
  922. /// \param RBracLoc The location of the closing square bracket ']'.
  923. static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
  924. ExprValueKind VK,
  925. SourceLocation LBracLoc,
  926. SourceLocation SuperLoc,
  927. bool IsInstanceSuper,
  928. QualType SuperType,
  929. Selector Sel,
  930. ArrayRef<SourceLocation> SelLocs,
  931. ObjCMethodDecl *Method,
  932. ArrayRef<Expr *> Args,
  933. SourceLocation RBracLoc,
  934. bool isImplicit);
  935. /// Create a class message send.
  936. ///
  937. /// \param Context The ASTContext in which this expression will be created.
  938. ///
  939. /// \param T The result type of this message.
  940. ///
  941. /// \param VK The value kind of this message. A message returning
  942. /// a l-value or r-value reference will be an l-value or x-value,
  943. /// respectively.
  944. ///
  945. /// \param LBracLoc The location of the open square bracket '['.
  946. ///
  947. /// \param Receiver The type of the receiver, including
  948. /// source-location information.
  949. ///
  950. /// \param Sel The selector used to determine which method gets called.
  951. ///
  952. /// \param Method The Objective-C method against which this message
  953. /// send was type-checked. May be nullptr.
  954. ///
  955. /// \param Args The message send arguments.
  956. ///
  957. /// \param RBracLoc The location of the closing square bracket ']'.
  958. static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
  959. ExprValueKind VK,
  960. SourceLocation LBracLoc,
  961. TypeSourceInfo *Receiver,
  962. Selector Sel,
  963. ArrayRef<SourceLocation> SelLocs,
  964. ObjCMethodDecl *Method,
  965. ArrayRef<Expr *> Args,
  966. SourceLocation RBracLoc,
  967. bool isImplicit);
  968. /// Create an instance message send.
  969. ///
  970. /// \param Context The ASTContext in which this expression will be created.
  971. ///
  972. /// \param T The result type of this message.
  973. ///
  974. /// \param VK The value kind of this message. A message returning
  975. /// a l-value or r-value reference will be an l-value or x-value,
  976. /// respectively.
  977. ///
  978. /// \param LBracLoc The location of the open square bracket '['.
  979. ///
  980. /// \param Receiver The expression used to produce the object that
  981. /// will receive this message.
  982. ///
  983. /// \param Sel The selector used to determine which method gets called.
  984. ///
  985. /// \param Method The Objective-C method against which this message
  986. /// send was type-checked. May be nullptr.
  987. ///
  988. /// \param Args The message send arguments.
  989. ///
  990. /// \param RBracLoc The location of the closing square bracket ']'.
  991. static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
  992. ExprValueKind VK,
  993. SourceLocation LBracLoc,
  994. Expr *Receiver,
  995. Selector Sel,
  996. ArrayRef<SourceLocation> SeLocs,
  997. ObjCMethodDecl *Method,
  998. ArrayRef<Expr *> Args,
  999. SourceLocation RBracLoc,
  1000. bool isImplicit);
  1001. /// Create an empty Objective-C message expression, to be
  1002. /// filled in by subsequent calls.
  1003. ///
  1004. /// \param Context The context in which the message send will be created.
  1005. ///
  1006. /// \param NumArgs The number of message arguments, not including
  1007. /// the receiver.
  1008. static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
  1009. unsigned NumArgs,
  1010. unsigned NumStoredSelLocs);
  1011. /// Indicates whether the message send was implicitly
  1012. /// generated by the implementation. If false, it was written explicitly
  1013. /// in the source code.
  1014. bool isImplicit() const { return IsImplicit; }
  1015. /// Determine the kind of receiver that this message is being
  1016. /// sent to.
  1017. ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
  1018. /// \return the return type of the message being sent.
  1019. /// This is not always the type of the message expression itself because
  1020. /// of references (the expression would not have a reference type).
  1021. /// It is also not always the declared return type of the method because
  1022. /// of `instancetype` (in that case it's an expression type).
  1023. QualType getCallReturnType(ASTContext &Ctx) const;
  1024. /// Source range of the receiver.
  1025. SourceRange getReceiverRange() const;
  1026. /// Determine whether this is an instance message to either a
  1027. /// computed object or to super.
  1028. bool isInstanceMessage() const {
  1029. return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
  1030. }
  1031. /// Determine whether this is an class message to either a
  1032. /// specified class or to super.
  1033. bool isClassMessage() const {
  1034. return getReceiverKind() == Class || getReceiverKind() == SuperClass;
  1035. }
  1036. /// Returns the object expression (receiver) for an instance message,
  1037. /// or null for a message that is not an instance message.
  1038. Expr *getInstanceReceiver() {
  1039. if (getReceiverKind() == Instance)
  1040. return static_cast<Expr *>(getReceiverPointer());
  1041. return nullptr;
  1042. }
  1043. const Expr *getInstanceReceiver() const {
  1044. return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
  1045. }
  1046. /// Turn this message send into an instance message that
  1047. /// computes the receiver object with the given expression.
  1048. void setInstanceReceiver(Expr *rec) {
  1049. Kind = Instance;
  1050. setReceiverPointer(rec);
  1051. }
  1052. /// Returns the type of a class message send, or NULL if the
  1053. /// message is not a class message.
  1054. QualType getClassReceiver() const {
  1055. if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
  1056. return TSInfo->getType();
  1057. return {};
  1058. }
  1059. /// Returns a type-source information of a class message
  1060. /// send, or nullptr if the message is not a class message.
  1061. TypeSourceInfo *getClassReceiverTypeInfo() const {
  1062. if (getReceiverKind() == Class)
  1063. return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
  1064. return nullptr;
  1065. }
  1066. void setClassReceiver(TypeSourceInfo *TSInfo) {
  1067. Kind = Class;
  1068. setReceiverPointer(TSInfo);
  1069. }
  1070. /// Retrieve the location of the 'super' keyword for a class
  1071. /// or instance message to 'super', otherwise an invalid source location.
  1072. SourceLocation getSuperLoc() const {
  1073. if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
  1074. return SuperLoc;
  1075. return SourceLocation();
  1076. }
  1077. /// Retrieve the receiver type to which this message is being directed.
  1078. ///
  1079. /// This routine cross-cuts all of the different kinds of message
  1080. /// sends to determine what the underlying (statically known) type
  1081. /// of the receiver will be; use \c getReceiverKind() to determine
  1082. /// whether the message is a class or an instance method, whether it
  1083. /// is a send to super or not, etc.
  1084. ///
  1085. /// \returns The type of the receiver.
  1086. QualType getReceiverType() const;
  1087. /// Retrieve the Objective-C interface to which this message
  1088. /// is being directed, if known.
  1089. ///
  1090. /// This routine cross-cuts all of the different kinds of message
  1091. /// sends to determine what the underlying (statically known) type
  1092. /// of the receiver will be; use \c getReceiverKind() to determine
  1093. /// whether the message is a class or an instance method, whether it
  1094. /// is a send to super or not, etc.
  1095. ///
  1096. /// \returns The Objective-C interface if known, otherwise nullptr.
  1097. ObjCInterfaceDecl *getReceiverInterface() const;
  1098. /// Retrieve the type referred to by 'super'.
  1099. ///
  1100. /// The returned type will either be an ObjCInterfaceType (for an
  1101. /// class message to super) or an ObjCObjectPointerType that refers
  1102. /// to a class (for an instance message to super);
  1103. QualType getSuperType() const {
  1104. if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
  1105. return QualType::getFromOpaquePtr(getReceiverPointer());
  1106. return QualType();
  1107. }
  1108. void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
  1109. Kind = IsInstanceSuper? SuperInstance : SuperClass;
  1110. SuperLoc = Loc;
  1111. setReceiverPointer(T.getAsOpaquePtr());
  1112. }
  1113. Selector getSelector() const;
  1114. void setSelector(Selector S) {
  1115. HasMethod = false;
  1116. SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
  1117. }
  1118. const ObjCMethodDecl *getMethodDecl() const {
  1119. if (HasMethod)
  1120. return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
  1121. return nullptr;
  1122. }
  1123. ObjCMethodDecl *getMethodDecl() {
  1124. if (HasMethod)
  1125. return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
  1126. return nullptr;
  1127. }
  1128. void setMethodDecl(ObjCMethodDecl *MD) {
  1129. HasMethod = true;
  1130. SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
  1131. }
  1132. ObjCMethodFamily getMethodFamily() const {
  1133. if (HasMethod) return getMethodDecl()->getMethodFamily();
  1134. return getSelector().getMethodFamily();
  1135. }
  1136. /// Return the number of actual arguments in this message,
  1137. /// not counting the receiver.
  1138. unsigned getNumArgs() const { return NumArgs; }
  1139. /// Retrieve the arguments to this message, not including the
  1140. /// receiver.
  1141. Expr **getArgs() {
  1142. return reinterpret_cast<Expr **>(getTrailingObjects<void *>() + 1);
  1143. }
  1144. const Expr * const *getArgs() const {
  1145. return reinterpret_cast<const Expr *const *>(getTrailingObjects<void *>() +
  1146. 1);
  1147. }
  1148. /// getArg - Return the specified argument.
  1149. Expr *getArg(unsigned Arg) {
  1150. assert(Arg < NumArgs && "Arg access out of range!");
  1151. return getArgs()[Arg];
  1152. }
  1153. const Expr *getArg(unsigned Arg) const {
  1154. assert(Arg < NumArgs && "Arg access out of range!");
  1155. return getArgs()[Arg];
  1156. }
  1157. /// setArg - Set the specified argument.
  1158. void setArg(unsigned Arg, Expr *ArgExpr) {
  1159. assert(Arg < NumArgs && "Arg access out of range!");
  1160. getArgs()[Arg] = ArgExpr;
  1161. }
  1162. /// isDelegateInitCall - Answers whether this message send has been
  1163. /// tagged as a "delegate init call", i.e. a call to a method in the
  1164. /// -init family on self from within an -init method implementation.
  1165. bool isDelegateInitCall() const { return IsDelegateInitCall; }
  1166. void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; }
  1167. SourceLocation getLeftLoc() const { return LBracLoc; }
  1168. SourceLocation getRightLoc() const { return RBracLoc; }
  1169. SourceLocation getSelectorStartLoc() const {
  1170. if (isImplicit())
  1171. return getBeginLoc();
  1172. return getSelectorLoc(0);
  1173. }
  1174. SourceLocation getSelectorLoc(unsigned Index) const {
  1175. assert(Index < getNumSelectorLocs() && "Index out of range!");
  1176. if (hasStandardSelLocs())
  1177. return getStandardSelectorLoc(
  1178. Index, getSelector(), getSelLocsKind() == SelLoc_StandardWithSpace,
  1179. llvm::ArrayRef(const_cast<Expr **>(getArgs()), getNumArgs()),
  1180. RBracLoc);
  1181. return getStoredSelLocs()[Index];
  1182. }
  1183. void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
  1184. unsigned getNumSelectorLocs() const {
  1185. if (isImplicit())
  1186. return 0;
  1187. Selector Sel = getSelector();
  1188. if (Sel.isUnarySelector())
  1189. return 1;
  1190. return Sel.getNumArgs();
  1191. }
  1192. void setSourceRange(SourceRange R) {
  1193. LBracLoc = R.getBegin();
  1194. RBracLoc = R.getEnd();
  1195. }
  1196. SourceLocation getBeginLoc() const LLVM_READONLY { return LBracLoc; }
  1197. SourceLocation getEndLoc() const LLVM_READONLY { return RBracLoc; }
  1198. // Iterators
  1199. child_range children();
  1200. const_child_range children() const;
  1201. using arg_iterator = ExprIterator;
  1202. using const_arg_iterator = ConstExprIterator;
  1203. llvm::iterator_range<arg_iterator> arguments() {
  1204. return llvm::make_range(arg_begin(), arg_end());
  1205. }
  1206. llvm::iterator_range<const_arg_iterator> arguments() const {
  1207. return llvm::make_range(arg_begin(), arg_end());
  1208. }
  1209. arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
  1210. arg_iterator arg_end() {
  1211. return reinterpret_cast<Stmt **>(getArgs() + NumArgs);
  1212. }
  1213. const_arg_iterator arg_begin() const {
  1214. return reinterpret_cast<Stmt const * const*>(getArgs());
  1215. }
  1216. const_arg_iterator arg_end() const {
  1217. return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs);
  1218. }
  1219. static bool classof(const Stmt *T) {
  1220. return T->getStmtClass() == ObjCMessageExprClass;
  1221. }
  1222. };
  1223. /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
  1224. /// (similar in spirit to MemberExpr).
  1225. class ObjCIsaExpr : public Expr {
  1226. /// Base - the expression for the base object pointer.
  1227. Stmt *Base;
  1228. /// IsaMemberLoc - This is the location of the 'isa'.
  1229. SourceLocation IsaMemberLoc;
  1230. /// OpLoc - This is the location of '.' or '->'
  1231. SourceLocation OpLoc;
  1232. /// IsArrow - True if this is "X->F", false if this is "X.F".
  1233. bool IsArrow;
  1234. public:
  1235. ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
  1236. QualType ty)
  1237. : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary), Base(base),
  1238. IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {
  1239. setDependence(computeDependence(this));
  1240. }
  1241. /// Build an empty expression.
  1242. explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) {}
  1243. void setBase(Expr *E) { Base = E; }
  1244. Expr *getBase() const { return cast<Expr>(Base); }
  1245. bool isArrow() const { return IsArrow; }
  1246. void setArrow(bool A) { IsArrow = A; }
  1247. /// getMemberLoc - Return the location of the "member", in X->F, it is the
  1248. /// location of 'F'.
  1249. SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
  1250. void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
  1251. SourceLocation getOpLoc() const { return OpLoc; }
  1252. void setOpLoc(SourceLocation L) { OpLoc = L; }
  1253. SourceLocation getBeginLoc() const LLVM_READONLY {
  1254. return getBase()->getBeginLoc();
  1255. }
  1256. SourceLocation getBaseLocEnd() const LLVM_READONLY {
  1257. return getBase()->getEndLoc();
  1258. }
  1259. SourceLocation getEndLoc() const LLVM_READONLY { return IsaMemberLoc; }
  1260. SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
  1261. // Iterators
  1262. child_range children() { return child_range(&Base, &Base+1); }
  1263. const_child_range children() const {
  1264. return const_child_range(&Base, &Base + 1);
  1265. }
  1266. static bool classof(const Stmt *T) {
  1267. return T->getStmtClass() == ObjCIsaExprClass;
  1268. }
  1269. };
  1270. /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
  1271. /// argument by indirect copy-restore in ARC. This is used to support
  1272. /// passing indirect arguments with the wrong lifetime, e.g. when
  1273. /// passing the address of a __strong local variable to an 'out'
  1274. /// parameter. This expression kind is only valid in an "argument"
  1275. /// position to some sort of call expression.
  1276. ///
  1277. /// The parameter must have type 'pointer to T', and the argument must
  1278. /// have type 'pointer to U', where T and U agree except possibly in
  1279. /// qualification. If the argument value is null, then a null pointer
  1280. /// is passed; otherwise it points to an object A, and:
  1281. /// 1. A temporary object B of type T is initialized, either by
  1282. /// zero-initialization (used when initializing an 'out' parameter)
  1283. /// or copy-initialization (used when initializing an 'inout'
  1284. /// parameter).
  1285. /// 2. The address of the temporary is passed to the function.
  1286. /// 3. If the call completes normally, A is move-assigned from B.
  1287. /// 4. Finally, A is destroyed immediately.
  1288. ///
  1289. /// Currently 'T' must be a retainable object lifetime and must be
  1290. /// __autoreleasing; this qualifier is ignored when initializing
  1291. /// the value.
  1292. class ObjCIndirectCopyRestoreExpr : public Expr {
  1293. friend class ASTReader;
  1294. friend class ASTStmtReader;
  1295. Stmt *Operand;
  1296. // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
  1297. explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
  1298. : Expr(ObjCIndirectCopyRestoreExprClass, Empty) {}
  1299. void setShouldCopy(bool shouldCopy) {
  1300. ObjCIndirectCopyRestoreExprBits.ShouldCopy = shouldCopy;
  1301. }
  1302. public:
  1303. ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
  1304. : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary),
  1305. Operand(operand) {
  1306. setShouldCopy(shouldCopy);
  1307. setDependence(computeDependence(this));
  1308. }
  1309. Expr *getSubExpr() { return cast<Expr>(Operand); }
  1310. const Expr *getSubExpr() const { return cast<Expr>(Operand); }
  1311. /// shouldCopy - True if we should do the 'copy' part of the
  1312. /// copy-restore. If false, the temporary will be zero-initialized.
  1313. bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
  1314. child_range children() { return child_range(&Operand, &Operand+1); }
  1315. const_child_range children() const {
  1316. return const_child_range(&Operand, &Operand + 1);
  1317. }
  1318. // Source locations are determined by the subexpression.
  1319. SourceLocation getBeginLoc() const LLVM_READONLY {
  1320. return Operand->getBeginLoc();
  1321. }
  1322. SourceLocation getEndLoc() const LLVM_READONLY {
  1323. return Operand->getEndLoc();
  1324. }
  1325. SourceLocation getExprLoc() const LLVM_READONLY {
  1326. return getSubExpr()->getExprLoc();
  1327. }
  1328. static bool classof(const Stmt *s) {
  1329. return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
  1330. }
  1331. };
  1332. /// An Objective-C "bridged" cast expression, which casts between
  1333. /// Objective-C pointers and C pointers, transferring ownership in the process.
  1334. ///
  1335. /// \code
  1336. /// NSString *str = (__bridge_transfer NSString *)CFCreateString();
  1337. /// \endcode
  1338. class ObjCBridgedCastExpr final
  1339. : public ExplicitCastExpr,
  1340. private llvm::TrailingObjects<ObjCBridgedCastExpr, CXXBaseSpecifier *> {
  1341. friend class ASTStmtReader;
  1342. friend class ASTStmtWriter;
  1343. friend class CastExpr;
  1344. friend TrailingObjects;
  1345. SourceLocation LParenLoc;
  1346. SourceLocation BridgeKeywordLoc;
  1347. unsigned Kind : 2;
  1348. public:
  1349. ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind,
  1350. CastKind CK, SourceLocation BridgeKeywordLoc,
  1351. TypeSourceInfo *TSInfo, Expr *Operand)
  1352. : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(),
  1353. VK_PRValue, CK, Operand, 0, false, TSInfo),
  1354. LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) {}
  1355. /// Construct an empty Objective-C bridged cast.
  1356. explicit ObjCBridgedCastExpr(EmptyShell Shell)
  1357. : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0, false) {}
  1358. SourceLocation getLParenLoc() const { return LParenLoc; }
  1359. /// Determine which kind of bridge is being performed via this cast.
  1360. ObjCBridgeCastKind getBridgeKind() const {
  1361. return static_cast<ObjCBridgeCastKind>(Kind);
  1362. }
  1363. /// Retrieve the kind of bridge being performed as a string.
  1364. StringRef getBridgeKindName() const;
  1365. /// The location of the bridge keyword.
  1366. SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
  1367. SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
  1368. SourceLocation getEndLoc() const LLVM_READONLY {
  1369. return getSubExpr()->getEndLoc();
  1370. }
  1371. static bool classof(const Stmt *T) {
  1372. return T->getStmtClass() == ObjCBridgedCastExprClass;
  1373. }
  1374. };
  1375. /// A runtime availability query.
  1376. ///
  1377. /// There are 2 ways to spell this node:
  1378. /// \code
  1379. /// @available(macos 10.10, ios 8, *); // Objective-C
  1380. /// __builtin_available(macos 10.10, ios 8, *); // C, C++, and Objective-C
  1381. /// \endcode
  1382. ///
  1383. /// Note that we only need to keep track of one \c VersionTuple here, which is
  1384. /// the one that corresponds to the current deployment target. This is meant to
  1385. /// be used in the condition of an \c if, but it is also usable as top level
  1386. /// expressions.
  1387. ///
  1388. class ObjCAvailabilityCheckExpr : public Expr {
  1389. friend class ASTStmtReader;
  1390. VersionTuple VersionToCheck;
  1391. SourceLocation AtLoc, RParen;
  1392. public:
  1393. ObjCAvailabilityCheckExpr(VersionTuple VersionToCheck, SourceLocation AtLoc,
  1394. SourceLocation RParen, QualType Ty)
  1395. : Expr(ObjCAvailabilityCheckExprClass, Ty, VK_PRValue, OK_Ordinary),
  1396. VersionToCheck(VersionToCheck), AtLoc(AtLoc), RParen(RParen) {
  1397. setDependence(ExprDependence::None);
  1398. }
  1399. explicit ObjCAvailabilityCheckExpr(EmptyShell Shell)
  1400. : Expr(ObjCAvailabilityCheckExprClass, Shell) {}
  1401. SourceLocation getBeginLoc() const { return AtLoc; }
  1402. SourceLocation getEndLoc() const { return RParen; }
  1403. SourceRange getSourceRange() const { return {AtLoc, RParen}; }
  1404. /// This may be '*', in which case this should fold to true.
  1405. bool hasVersion() const { return !VersionToCheck.empty(); }
  1406. VersionTuple getVersion() const { return VersionToCheck; }
  1407. child_range children() {
  1408. return child_range(child_iterator(), child_iterator());
  1409. }
  1410. const_child_range children() const {
  1411. return const_child_range(const_child_iterator(), const_child_iterator());
  1412. }
  1413. static bool classof(const Stmt *T) {
  1414. return T->getStmtClass() == ObjCAvailabilityCheckExprClass;
  1415. }
  1416. };
  1417. } // namespace clang
  1418. #endif // LLVM_CLANG_AST_EXPROBJC_H
  1419. #ifdef __GNUC__
  1420. #pragma GCC diagnostic pop
  1421. #endif