DeclSpec.h 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- DeclSpec.h - Parsed declaration specifiers -------------*- 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. /// \file
  15. /// This file defines the classes used to store parsed information about
  16. /// declaration-specifiers and declarators.
  17. ///
  18. /// \verbatim
  19. /// static const int volatile x, *y, *(*(*z)[10])(const void *x);
  20. /// ------------------------- - -- ---------------------------
  21. /// declaration-specifiers \ | /
  22. /// declarators
  23. /// \endverbatim
  24. ///
  25. //===----------------------------------------------------------------------===//
  26. #ifndef LLVM_CLANG_SEMA_DECLSPEC_H
  27. #define LLVM_CLANG_SEMA_DECLSPEC_H
  28. #include "clang/AST/DeclCXX.h"
  29. #include "clang/AST/DeclObjCCommon.h"
  30. #include "clang/AST/NestedNameSpecifier.h"
  31. #include "clang/Basic/ExceptionSpecificationType.h"
  32. #include "clang/Basic/Lambda.h"
  33. #include "clang/Basic/OperatorKinds.h"
  34. #include "clang/Basic/Specifiers.h"
  35. #include "clang/Lex/Token.h"
  36. #include "clang/Sema/Ownership.h"
  37. #include "clang/Sema/ParsedAttr.h"
  38. #include "llvm/ADT/SmallVector.h"
  39. #include "llvm/Support/Compiler.h"
  40. #include "llvm/Support/ErrorHandling.h"
  41. namespace clang {
  42. class ASTContext;
  43. class CXXRecordDecl;
  44. class TypeLoc;
  45. class LangOptions;
  46. class IdentifierInfo;
  47. class NamespaceAliasDecl;
  48. class NamespaceDecl;
  49. class ObjCDeclSpec;
  50. class Sema;
  51. class Declarator;
  52. struct TemplateIdAnnotation;
  53. /// Represents a C++ nested-name-specifier or a global scope specifier.
  54. ///
  55. /// These can be in 3 states:
  56. /// 1) Not present, identified by isEmpty()
  57. /// 2) Present, identified by isNotEmpty()
  58. /// 2.a) Valid, identified by isValid()
  59. /// 2.b) Invalid, identified by isInvalid().
  60. ///
  61. /// isSet() is deprecated because it mostly corresponded to "valid" but was
  62. /// often used as if it meant "present".
  63. ///
  64. /// The actual scope is described by getScopeRep().
  65. class CXXScopeSpec {
  66. SourceRange Range;
  67. NestedNameSpecifierLocBuilder Builder;
  68. public:
  69. SourceRange getRange() const { return Range; }
  70. void setRange(SourceRange R) { Range = R; }
  71. void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); }
  72. void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); }
  73. SourceLocation getBeginLoc() const { return Range.getBegin(); }
  74. SourceLocation getEndLoc() const { return Range.getEnd(); }
  75. /// Retrieve the representation of the nested-name-specifier.
  76. NestedNameSpecifier *getScopeRep() const {
  77. return Builder.getRepresentation();
  78. }
  79. /// Extend the current nested-name-specifier by another
  80. /// nested-name-specifier component of the form 'type::'.
  81. ///
  82. /// \param Context The AST context in which this nested-name-specifier
  83. /// resides.
  84. ///
  85. /// \param TemplateKWLoc The location of the 'template' keyword, if present.
  86. ///
  87. /// \param TL The TypeLoc that describes the type preceding the '::'.
  88. ///
  89. /// \param ColonColonLoc The location of the trailing '::'.
  90. void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL,
  91. SourceLocation ColonColonLoc);
  92. /// Extend the current nested-name-specifier by another
  93. /// nested-name-specifier component of the form 'identifier::'.
  94. ///
  95. /// \param Context The AST context in which this nested-name-specifier
  96. /// resides.
  97. ///
  98. /// \param Identifier The identifier.
  99. ///
  100. /// \param IdentifierLoc The location of the identifier.
  101. ///
  102. /// \param ColonColonLoc The location of the trailing '::'.
  103. void Extend(ASTContext &Context, IdentifierInfo *Identifier,
  104. SourceLocation IdentifierLoc, SourceLocation ColonColonLoc);
  105. /// Extend the current nested-name-specifier by another
  106. /// nested-name-specifier component of the form 'namespace::'.
  107. ///
  108. /// \param Context The AST context in which this nested-name-specifier
  109. /// resides.
  110. ///
  111. /// \param Namespace The namespace.
  112. ///
  113. /// \param NamespaceLoc The location of the namespace name.
  114. ///
  115. /// \param ColonColonLoc The location of the trailing '::'.
  116. void Extend(ASTContext &Context, NamespaceDecl *Namespace,
  117. SourceLocation NamespaceLoc, SourceLocation ColonColonLoc);
  118. /// Extend the current nested-name-specifier by another
  119. /// nested-name-specifier component of the form 'namespace-alias::'.
  120. ///
  121. /// \param Context The AST context in which this nested-name-specifier
  122. /// resides.
  123. ///
  124. /// \param Alias The namespace alias.
  125. ///
  126. /// \param AliasLoc The location of the namespace alias
  127. /// name.
  128. ///
  129. /// \param ColonColonLoc The location of the trailing '::'.
  130. void Extend(ASTContext &Context, NamespaceAliasDecl *Alias,
  131. SourceLocation AliasLoc, SourceLocation ColonColonLoc);
  132. /// Turn this (empty) nested-name-specifier into the global
  133. /// nested-name-specifier '::'.
  134. void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc);
  135. /// Turns this (empty) nested-name-specifier into '__super'
  136. /// nested-name-specifier.
  137. ///
  138. /// \param Context The AST context in which this nested-name-specifier
  139. /// resides.
  140. ///
  141. /// \param RD The declaration of the class in which nested-name-specifier
  142. /// appeared.
  143. ///
  144. /// \param SuperLoc The location of the '__super' keyword.
  145. /// name.
  146. ///
  147. /// \param ColonColonLoc The location of the trailing '::'.
  148. void MakeSuper(ASTContext &Context, CXXRecordDecl *RD,
  149. SourceLocation SuperLoc, SourceLocation ColonColonLoc);
  150. /// Make a new nested-name-specifier from incomplete source-location
  151. /// information.
  152. ///
  153. /// FIXME: This routine should be used very, very rarely, in cases where we
  154. /// need to synthesize a nested-name-specifier. Most code should instead use
  155. /// \c Adopt() with a proper \c NestedNameSpecifierLoc.
  156. void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier,
  157. SourceRange R);
  158. /// Adopt an existing nested-name-specifier (with source-range
  159. /// information).
  160. void Adopt(NestedNameSpecifierLoc Other);
  161. /// Retrieve a nested-name-specifier with location information, copied
  162. /// into the given AST context.
  163. ///
  164. /// \param Context The context into which this nested-name-specifier will be
  165. /// copied.
  166. NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const;
  167. /// Retrieve the location of the name in the last qualifier
  168. /// in this nested name specifier.
  169. ///
  170. /// For example, the location of \c bar
  171. /// in
  172. /// \verbatim
  173. /// \::foo::bar<0>::
  174. /// ^~~
  175. /// \endverbatim
  176. SourceLocation getLastQualifierNameLoc() const;
  177. /// No scope specifier.
  178. bool isEmpty() const { return Range.isInvalid() && getScopeRep() == nullptr; }
  179. /// A scope specifier is present, but may be valid or invalid.
  180. bool isNotEmpty() const { return !isEmpty(); }
  181. /// An error occurred during parsing of the scope specifier.
  182. bool isInvalid() const { return Range.isValid() && getScopeRep() == nullptr; }
  183. /// A scope specifier is present, and it refers to a real scope.
  184. bool isValid() const { return getScopeRep() != nullptr; }
  185. /// Indicate that this nested-name-specifier is invalid.
  186. void SetInvalid(SourceRange R) {
  187. assert(R.isValid() && "Must have a valid source range");
  188. if (Range.getBegin().isInvalid())
  189. Range.setBegin(R.getBegin());
  190. Range.setEnd(R.getEnd());
  191. Builder.Clear();
  192. }
  193. /// Deprecated. Some call sites intend isNotEmpty() while others intend
  194. /// isValid().
  195. bool isSet() const { return getScopeRep() != nullptr; }
  196. void clear() {
  197. Range = SourceRange();
  198. Builder.Clear();
  199. }
  200. /// Retrieve the data associated with the source-location information.
  201. char *location_data() const { return Builder.getBuffer().first; }
  202. /// Retrieve the size of the data associated with source-location
  203. /// information.
  204. unsigned location_size() const { return Builder.getBuffer().second; }
  205. };
  206. /// Captures information about "declaration specifiers".
  207. ///
  208. /// "Declaration specifiers" encompasses storage-class-specifiers,
  209. /// type-specifiers, type-qualifiers, and function-specifiers.
  210. class DeclSpec {
  211. public:
  212. /// storage-class-specifier
  213. /// \note The order of these enumerators is important for diagnostics.
  214. enum SCS {
  215. SCS_unspecified = 0,
  216. SCS_typedef,
  217. SCS_extern,
  218. SCS_static,
  219. SCS_auto,
  220. SCS_register,
  221. SCS_private_extern,
  222. SCS_mutable
  223. };
  224. // Import thread storage class specifier enumeration and constants.
  225. // These can be combined with SCS_extern and SCS_static.
  226. typedef ThreadStorageClassSpecifier TSCS;
  227. static const TSCS TSCS_unspecified = clang::TSCS_unspecified;
  228. static const TSCS TSCS___thread = clang::TSCS___thread;
  229. static const TSCS TSCS_thread_local = clang::TSCS_thread_local;
  230. static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local;
  231. enum TSC {
  232. TSC_unspecified,
  233. TSC_imaginary,
  234. TSC_complex
  235. };
  236. // Import type specifier type enumeration and constants.
  237. typedef TypeSpecifierType TST;
  238. static const TST TST_unspecified = clang::TST_unspecified;
  239. static const TST TST_void = clang::TST_void;
  240. static const TST TST_char = clang::TST_char;
  241. static const TST TST_wchar = clang::TST_wchar;
  242. static const TST TST_char8 = clang::TST_char8;
  243. static const TST TST_char16 = clang::TST_char16;
  244. static const TST TST_char32 = clang::TST_char32;
  245. static const TST TST_int = clang::TST_int;
  246. static const TST TST_int128 = clang::TST_int128;
  247. static const TST TST_bitint = clang::TST_bitint;
  248. static const TST TST_half = clang::TST_half;
  249. static const TST TST_BFloat16 = clang::TST_BFloat16;
  250. static const TST TST_float = clang::TST_float;
  251. static const TST TST_double = clang::TST_double;
  252. static const TST TST_float16 = clang::TST_Float16;
  253. static const TST TST_accum = clang::TST_Accum;
  254. static const TST TST_fract = clang::TST_Fract;
  255. static const TST TST_float128 = clang::TST_float128;
  256. static const TST TST_ibm128 = clang::TST_ibm128;
  257. static const TST TST_bool = clang::TST_bool;
  258. static const TST TST_decimal32 = clang::TST_decimal32;
  259. static const TST TST_decimal64 = clang::TST_decimal64;
  260. static const TST TST_decimal128 = clang::TST_decimal128;
  261. static const TST TST_enum = clang::TST_enum;
  262. static const TST TST_union = clang::TST_union;
  263. static const TST TST_struct = clang::TST_struct;
  264. static const TST TST_interface = clang::TST_interface;
  265. static const TST TST_class = clang::TST_class;
  266. static const TST TST_typename = clang::TST_typename;
  267. static const TST TST_typeofType = clang::TST_typeofType;
  268. static const TST TST_typeofExpr = clang::TST_typeofExpr;
  269. static const TST TST_decltype = clang::TST_decltype;
  270. static const TST TST_decltype_auto = clang::TST_decltype_auto;
  271. static const TST TST_underlyingType = clang::TST_underlyingType;
  272. static const TST TST_auto = clang::TST_auto;
  273. static const TST TST_auto_type = clang::TST_auto_type;
  274. static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
  275. static const TST TST_atomic = clang::TST_atomic;
  276. #define GENERIC_IMAGE_TYPE(ImgType, Id) \
  277. static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
  278. #include "clang/Basic/OpenCLImageTypes.def"
  279. static const TST TST_error = clang::TST_error;
  280. // type-qualifiers
  281. enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ.
  282. TQ_unspecified = 0,
  283. TQ_const = 1,
  284. TQ_restrict = 2,
  285. TQ_volatile = 4,
  286. TQ_unaligned = 8,
  287. // This has no corresponding Qualifiers::TQ value, because it's not treated
  288. // as a qualifier in our type system.
  289. TQ_atomic = 16
  290. };
  291. /// ParsedSpecifiers - Flags to query which specifiers were applied. This is
  292. /// returned by getParsedSpecifiers.
  293. enum ParsedSpecifiers {
  294. PQ_None = 0,
  295. PQ_StorageClassSpecifier = 1,
  296. PQ_TypeSpecifier = 2,
  297. PQ_TypeQualifier = 4,
  298. PQ_FunctionSpecifier = 8
  299. // FIXME: Attributes should be included here.
  300. };
  301. private:
  302. // storage-class-specifier
  303. /*SCS*/unsigned StorageClassSpec : 3;
  304. /*TSCS*/unsigned ThreadStorageClassSpec : 2;
  305. unsigned SCS_extern_in_linkage_spec : 1;
  306. // type-specifier
  307. /*TypeSpecifierWidth*/ unsigned TypeSpecWidth : 2;
  308. /*TSC*/unsigned TypeSpecComplex : 2;
  309. /*TSS*/unsigned TypeSpecSign : 2;
  310. /*TST*/unsigned TypeSpecType : 6;
  311. unsigned TypeAltiVecVector : 1;
  312. unsigned TypeAltiVecPixel : 1;
  313. unsigned TypeAltiVecBool : 1;
  314. unsigned TypeSpecOwned : 1;
  315. unsigned TypeSpecPipe : 1;
  316. unsigned TypeSpecSat : 1;
  317. unsigned ConstrainedAuto : 1;
  318. // type-qualifiers
  319. unsigned TypeQualifiers : 5; // Bitwise OR of TQ.
  320. // function-specifier
  321. unsigned FS_inline_specified : 1;
  322. unsigned FS_forceinline_specified: 1;
  323. unsigned FS_virtual_specified : 1;
  324. unsigned FS_noreturn_specified : 1;
  325. // friend-specifier
  326. unsigned Friend_specified : 1;
  327. // constexpr-specifier
  328. unsigned ConstexprSpecifier : 2;
  329. union {
  330. UnionParsedType TypeRep;
  331. Decl *DeclRep;
  332. Expr *ExprRep;
  333. TemplateIdAnnotation *TemplateIdRep;
  334. };
  335. /// ExplicitSpecifier - Store information about explicit spicifer.
  336. ExplicitSpecifier FS_explicit_specifier;
  337. // attributes.
  338. ParsedAttributes Attrs;
  339. // Scope specifier for the type spec, if applicable.
  340. CXXScopeSpec TypeScope;
  341. // SourceLocation info. These are null if the item wasn't specified or if
  342. // the setting was synthesized.
  343. SourceRange Range;
  344. SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc;
  345. SourceRange TSWRange;
  346. SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc;
  347. /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
  348. /// typename, then this is the location of the named type (if present);
  349. /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
  350. /// TSTNameLoc provides source range info for tag types.
  351. SourceLocation TSTNameLoc;
  352. SourceRange TypeofParensRange;
  353. SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
  354. TQ_unalignedLoc;
  355. SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc;
  356. SourceLocation FS_explicitCloseParenLoc;
  357. SourceLocation FS_forceinlineLoc;
  358. SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
  359. SourceLocation TQ_pipeLoc;
  360. WrittenBuiltinSpecs writtenBS;
  361. void SaveWrittenBuiltinSpecs();
  362. ObjCDeclSpec *ObjCQualifiers;
  363. static bool isTypeRep(TST T) {
  364. return (T == TST_typename || T == TST_typeofType ||
  365. T == TST_underlyingType || T == TST_atomic);
  366. }
  367. static bool isExprRep(TST T) {
  368. return (T == TST_typeofExpr || T == TST_decltype || T == TST_bitint);
  369. }
  370. static bool isTemplateIdRep(TST T) {
  371. return (T == TST_auto || T == TST_decltype_auto);
  372. }
  373. DeclSpec(const DeclSpec &) = delete;
  374. void operator=(const DeclSpec &) = delete;
  375. public:
  376. static bool isDeclRep(TST T) {
  377. return (T == TST_enum || T == TST_struct ||
  378. T == TST_interface || T == TST_union ||
  379. T == TST_class);
  380. }
  381. DeclSpec(AttributeFactory &attrFactory)
  382. : StorageClassSpec(SCS_unspecified),
  383. ThreadStorageClassSpec(TSCS_unspecified),
  384. SCS_extern_in_linkage_spec(false),
  385. TypeSpecWidth(static_cast<unsigned>(TypeSpecifierWidth::Unspecified)),
  386. TypeSpecComplex(TSC_unspecified),
  387. TypeSpecSign(static_cast<unsigned>(TypeSpecifierSign::Unspecified)),
  388. TypeSpecType(TST_unspecified), TypeAltiVecVector(false),
  389. TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false),
  390. TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false),
  391. TypeQualifiers(TQ_unspecified), FS_inline_specified(false),
  392. FS_forceinline_specified(false), FS_virtual_specified(false),
  393. FS_noreturn_specified(false), Friend_specified(false),
  394. ConstexprSpecifier(
  395. static_cast<unsigned>(ConstexprSpecKind::Unspecified)),
  396. Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {}
  397. // storage-class-specifier
  398. SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
  399. TSCS getThreadStorageClassSpec() const {
  400. return (TSCS)ThreadStorageClassSpec;
  401. }
  402. bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
  403. void setExternInLinkageSpec(bool Value) {
  404. SCS_extern_in_linkage_spec = Value;
  405. }
  406. SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
  407. SourceLocation getThreadStorageClassSpecLoc() const {
  408. return ThreadStorageClassSpecLoc;
  409. }
  410. void ClearStorageClassSpecs() {
  411. StorageClassSpec = DeclSpec::SCS_unspecified;
  412. ThreadStorageClassSpec = DeclSpec::TSCS_unspecified;
  413. SCS_extern_in_linkage_spec = false;
  414. StorageClassSpecLoc = SourceLocation();
  415. ThreadStorageClassSpecLoc = SourceLocation();
  416. }
  417. void ClearTypeSpecType() {
  418. TypeSpecType = DeclSpec::TST_unspecified;
  419. TypeSpecOwned = false;
  420. TSTLoc = SourceLocation();
  421. }
  422. // type-specifier
  423. TypeSpecifierWidth getTypeSpecWidth() const {
  424. return static_cast<TypeSpecifierWidth>(TypeSpecWidth);
  425. }
  426. TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
  427. TypeSpecifierSign getTypeSpecSign() const {
  428. return static_cast<TypeSpecifierSign>(TypeSpecSign);
  429. }
  430. TST getTypeSpecType() const { return (TST)TypeSpecType; }
  431. bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
  432. bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
  433. bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
  434. bool isTypeSpecOwned() const { return TypeSpecOwned; }
  435. bool isTypeRep() const { return isTypeRep((TST) TypeSpecType); }
  436. bool isTypeSpecPipe() const { return TypeSpecPipe; }
  437. bool isTypeSpecSat() const { return TypeSpecSat; }
  438. bool isConstrainedAuto() const { return ConstrainedAuto; }
  439. ParsedType getRepAsType() const {
  440. assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
  441. return TypeRep;
  442. }
  443. Decl *getRepAsDecl() const {
  444. assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
  445. return DeclRep;
  446. }
  447. Expr *getRepAsExpr() const {
  448. assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
  449. return ExprRep;
  450. }
  451. TemplateIdAnnotation *getRepAsTemplateId() const {
  452. assert(isTemplateIdRep((TST) TypeSpecType) &&
  453. "DeclSpec does not store a template id");
  454. return TemplateIdRep;
  455. }
  456. CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
  457. const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
  458. SourceRange getSourceRange() const LLVM_READONLY { return Range; }
  459. SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
  460. SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
  461. SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
  462. SourceRange getTypeSpecWidthRange() const { return TSWRange; }
  463. SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
  464. SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
  465. SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
  466. SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
  467. SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
  468. SourceLocation getTypeSpecTypeNameLoc() const {
  469. assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename);
  470. return TSTNameLoc;
  471. }
  472. SourceRange getTypeofParensRange() const { return TypeofParensRange; }
  473. void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; }
  474. bool hasAutoTypeSpec() const {
  475. return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type ||
  476. TypeSpecType == TST_decltype_auto);
  477. }
  478. bool hasTagDefinition() const;
  479. /// Turn a type-specifier-type into a string like "_Bool" or "union".
  480. static const char *getSpecifierName(DeclSpec::TST T,
  481. const PrintingPolicy &Policy);
  482. static const char *getSpecifierName(DeclSpec::TQ Q);
  483. static const char *getSpecifierName(TypeSpecifierSign S);
  484. static const char *getSpecifierName(DeclSpec::TSC C);
  485. static const char *getSpecifierName(TypeSpecifierWidth W);
  486. static const char *getSpecifierName(DeclSpec::SCS S);
  487. static const char *getSpecifierName(DeclSpec::TSCS S);
  488. static const char *getSpecifierName(ConstexprSpecKind C);
  489. // type-qualifiers
  490. /// getTypeQualifiers - Return a set of TQs.
  491. unsigned getTypeQualifiers() const { return TypeQualifiers; }
  492. SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
  493. SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
  494. SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
  495. SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }
  496. SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }
  497. SourceLocation getPipeLoc() const { return TQ_pipeLoc; }
  498. /// Clear out all of the type qualifiers.
  499. void ClearTypeQualifiers() {
  500. TypeQualifiers = 0;
  501. TQ_constLoc = SourceLocation();
  502. TQ_restrictLoc = SourceLocation();
  503. TQ_volatileLoc = SourceLocation();
  504. TQ_atomicLoc = SourceLocation();
  505. TQ_unalignedLoc = SourceLocation();
  506. TQ_pipeLoc = SourceLocation();
  507. }
  508. // function-specifier
  509. bool isInlineSpecified() const {
  510. return FS_inline_specified | FS_forceinline_specified;
  511. }
  512. SourceLocation getInlineSpecLoc() const {
  513. return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc;
  514. }
  515. ExplicitSpecifier getExplicitSpecifier() const {
  516. return FS_explicit_specifier;
  517. }
  518. bool isVirtualSpecified() const { return FS_virtual_specified; }
  519. SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
  520. bool hasExplicitSpecifier() const {
  521. return FS_explicit_specifier.isSpecified();
  522. }
  523. SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
  524. SourceRange getExplicitSpecRange() const {
  525. return FS_explicit_specifier.getExpr()
  526. ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc)
  527. : SourceRange(FS_explicitLoc);
  528. }
  529. bool isNoreturnSpecified() const { return FS_noreturn_specified; }
  530. SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; }
  531. void ClearFunctionSpecs() {
  532. FS_inline_specified = false;
  533. FS_inlineLoc = SourceLocation();
  534. FS_forceinline_specified = false;
  535. FS_forceinlineLoc = SourceLocation();
  536. FS_virtual_specified = false;
  537. FS_virtualLoc = SourceLocation();
  538. FS_explicit_specifier = ExplicitSpecifier();
  539. FS_explicitLoc = SourceLocation();
  540. FS_explicitCloseParenLoc = SourceLocation();
  541. FS_noreturn_specified = false;
  542. FS_noreturnLoc = SourceLocation();
  543. }
  544. /// This method calls the passed in handler on each CVRU qual being
  545. /// set.
  546. /// Handle - a handler to be invoked.
  547. void forEachCVRUQualifier(
  548. llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
  549. /// This method calls the passed in handler on each qual being
  550. /// set.
  551. /// Handle - a handler to be invoked.
  552. void forEachQualifier(
  553. llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
  554. /// Return true if any type-specifier has been found.
  555. bool hasTypeSpecifier() const {
  556. return getTypeSpecType() != DeclSpec::TST_unspecified ||
  557. getTypeSpecWidth() != TypeSpecifierWidth::Unspecified ||
  558. getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
  559. getTypeSpecSign() != TypeSpecifierSign::Unspecified;
  560. }
  561. /// Return a bitmask of which flavors of specifiers this
  562. /// DeclSpec includes.
  563. unsigned getParsedSpecifiers() const;
  564. /// isEmpty - Return true if this declaration specifier is completely empty:
  565. /// no tokens were parsed in the production of it.
  566. bool isEmpty() const {
  567. return getParsedSpecifiers() == DeclSpec::PQ_None;
  568. }
  569. void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
  570. void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
  571. /// These methods set the specified attribute of the DeclSpec and
  572. /// return false if there was no error. If an error occurs (for
  573. /// example, if we tried to set "auto" on a spec with "extern"
  574. /// already set), they return true and set PrevSpec and DiagID
  575. /// such that
  576. /// Diag(Loc, DiagID) << PrevSpec;
  577. /// will yield a useful result.
  578. ///
  579. /// TODO: use a more general approach that still allows these
  580. /// diagnostics to be ignored when desired.
  581. bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
  582. const char *&PrevSpec, unsigned &DiagID,
  583. const PrintingPolicy &Policy);
  584. bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
  585. const char *&PrevSpec, unsigned &DiagID);
  586. bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc,
  587. const char *&PrevSpec, unsigned &DiagID,
  588. const PrintingPolicy &Policy);
  589. bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
  590. unsigned &DiagID);
  591. bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc,
  592. const char *&PrevSpec, unsigned &DiagID);
  593. bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
  594. unsigned &DiagID, const PrintingPolicy &Policy);
  595. bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
  596. unsigned &DiagID, ParsedType Rep,
  597. const PrintingPolicy &Policy);
  598. bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
  599. unsigned &DiagID, TypeResult Rep,
  600. const PrintingPolicy &Policy) {
  601. if (Rep.isInvalid())
  602. return SetTypeSpecError();
  603. return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Rep.get(), Policy);
  604. }
  605. bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
  606. unsigned &DiagID, Decl *Rep, bool Owned,
  607. const PrintingPolicy &Policy);
  608. bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
  609. SourceLocation TagNameLoc, const char *&PrevSpec,
  610. unsigned &DiagID, ParsedType Rep,
  611. const PrintingPolicy &Policy);
  612. bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
  613. SourceLocation TagNameLoc, const char *&PrevSpec,
  614. unsigned &DiagID, Decl *Rep, bool Owned,
  615. const PrintingPolicy &Policy);
  616. bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
  617. unsigned &DiagID, TemplateIdAnnotation *Rep,
  618. const PrintingPolicy &Policy);
  619. bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
  620. unsigned &DiagID, Expr *Rep,
  621. const PrintingPolicy &policy);
  622. bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
  623. const char *&PrevSpec, unsigned &DiagID,
  624. const PrintingPolicy &Policy);
  625. bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
  626. const char *&PrevSpec, unsigned &DiagID,
  627. const PrintingPolicy &Policy);
  628. bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
  629. const char *&PrevSpec, unsigned &DiagID,
  630. const PrintingPolicy &Policy);
  631. bool SetTypePipe(bool isPipe, SourceLocation Loc,
  632. const char *&PrevSpec, unsigned &DiagID,
  633. const PrintingPolicy &Policy);
  634. bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth,
  635. const char *&PrevSpec, unsigned &DiagID,
  636. const PrintingPolicy &Policy);
  637. bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
  638. unsigned &DiagID);
  639. bool SetTypeSpecError();
  640. void UpdateDeclRep(Decl *Rep) {
  641. assert(isDeclRep((TST) TypeSpecType));
  642. DeclRep = Rep;
  643. }
  644. void UpdateTypeRep(ParsedType Rep) {
  645. assert(isTypeRep((TST) TypeSpecType));
  646. TypeRep = Rep;
  647. }
  648. void UpdateExprRep(Expr *Rep) {
  649. assert(isExprRep((TST) TypeSpecType));
  650. ExprRep = Rep;
  651. }
  652. bool SetTypeQual(TQ T, SourceLocation Loc);
  653. bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
  654. unsigned &DiagID, const LangOptions &Lang);
  655. bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
  656. unsigned &DiagID);
  657. bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
  658. unsigned &DiagID);
  659. bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
  660. unsigned &DiagID);
  661. bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
  662. unsigned &DiagID, ExplicitSpecifier ExplicitSpec,
  663. SourceLocation CloseParenLoc);
  664. bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec,
  665. unsigned &DiagID);
  666. bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
  667. unsigned &DiagID);
  668. bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
  669. unsigned &DiagID);
  670. bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc,
  671. const char *&PrevSpec, unsigned &DiagID);
  672. bool isFriendSpecified() const { return Friend_specified; }
  673. SourceLocation getFriendSpecLoc() const { return FriendLoc; }
  674. bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
  675. SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
  676. ConstexprSpecKind getConstexprSpecifier() const {
  677. return ConstexprSpecKind(ConstexprSpecifier);
  678. }
  679. SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
  680. bool hasConstexprSpecifier() const {
  681. return getConstexprSpecifier() != ConstexprSpecKind::Unspecified;
  682. }
  683. void ClearConstexprSpec() {
  684. ConstexprSpecifier = static_cast<unsigned>(ConstexprSpecKind::Unspecified);
  685. ConstexprLoc = SourceLocation();
  686. }
  687. AttributePool &getAttributePool() const {
  688. return Attrs.getPool();
  689. }
  690. /// Concatenates two attribute lists.
  691. ///
  692. /// The GCC attribute syntax allows for the following:
  693. ///
  694. /// \code
  695. /// short __attribute__(( unused, deprecated ))
  696. /// int __attribute__(( may_alias, aligned(16) )) var;
  697. /// \endcode
  698. ///
  699. /// This declares 4 attributes using 2 lists. The following syntax is
  700. /// also allowed and equivalent to the previous declaration.
  701. ///
  702. /// \code
  703. /// short __attribute__((unused)) __attribute__((deprecated))
  704. /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
  705. /// \endcode
  706. ///
  707. void addAttributes(ParsedAttributesView &AL) {
  708. Attrs.addAll(AL.begin(), AL.end());
  709. }
  710. bool hasAttributes() const { return !Attrs.empty(); }
  711. ParsedAttributes &getAttributes() { return Attrs; }
  712. const ParsedAttributes &getAttributes() const { return Attrs; }
  713. void takeAttributesFrom(ParsedAttributes &attrs) {
  714. Attrs.takeAllFrom(attrs);
  715. }
  716. /// Finish - This does final analysis of the declspec, issuing diagnostics for
  717. /// things like "_Imaginary" (lacking an FP type). After calling this method,
  718. /// DeclSpec is guaranteed self-consistent, even if an error occurred.
  719. void Finish(Sema &S, const PrintingPolicy &Policy);
  720. const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
  721. return writtenBS;
  722. }
  723. ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
  724. void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
  725. /// Checks if this DeclSpec can stand alone, without a Declarator.
  726. ///
  727. /// Only tag declspecs can stand alone.
  728. bool isMissingDeclaratorOk();
  729. };
  730. /// Captures information about "declaration specifiers" specific to
  731. /// Objective-C.
  732. class ObjCDeclSpec {
  733. public:
  734. /// ObjCDeclQualifier - Qualifier used on types in method
  735. /// declarations. Not all combinations are sensible. Parameters
  736. /// can be one of { in, out, inout } with one of { bycopy, byref }.
  737. /// Returns can either be { oneway } or not.
  738. ///
  739. /// This should be kept in sync with Decl::ObjCDeclQualifier.
  740. enum ObjCDeclQualifier {
  741. DQ_None = 0x0,
  742. DQ_In = 0x1,
  743. DQ_Inout = 0x2,
  744. DQ_Out = 0x4,
  745. DQ_Bycopy = 0x8,
  746. DQ_Byref = 0x10,
  747. DQ_Oneway = 0x20,
  748. DQ_CSNullability = 0x40
  749. };
  750. ObjCDeclSpec()
  751. : objcDeclQualifier(DQ_None),
  752. PropertyAttributes(ObjCPropertyAttribute::kind_noattr), Nullability(0),
  753. GetterName(nullptr), SetterName(nullptr) {}
  754. ObjCDeclQualifier getObjCDeclQualifier() const {
  755. return (ObjCDeclQualifier)objcDeclQualifier;
  756. }
  757. void setObjCDeclQualifier(ObjCDeclQualifier DQVal) {
  758. objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal);
  759. }
  760. void clearObjCDeclQualifier(ObjCDeclQualifier DQVal) {
  761. objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier & ~DQVal);
  762. }
  763. ObjCPropertyAttribute::Kind getPropertyAttributes() const {
  764. return ObjCPropertyAttribute::Kind(PropertyAttributes);
  765. }
  766. void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal) {
  767. PropertyAttributes =
  768. (ObjCPropertyAttribute::Kind)(PropertyAttributes | PRVal);
  769. }
  770. NullabilityKind getNullability() const {
  771. assert(
  772. ((getObjCDeclQualifier() & DQ_CSNullability) ||
  773. (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
  774. "Objective-C declspec doesn't have nullability");
  775. return static_cast<NullabilityKind>(Nullability);
  776. }
  777. SourceLocation getNullabilityLoc() const {
  778. assert(
  779. ((getObjCDeclQualifier() & DQ_CSNullability) ||
  780. (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
  781. "Objective-C declspec doesn't have nullability");
  782. return NullabilityLoc;
  783. }
  784. void setNullability(SourceLocation loc, NullabilityKind kind) {
  785. assert(
  786. ((getObjCDeclQualifier() & DQ_CSNullability) ||
  787. (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) &&
  788. "Set the nullability declspec or property attribute first");
  789. Nullability = static_cast<unsigned>(kind);
  790. NullabilityLoc = loc;
  791. }
  792. const IdentifierInfo *getGetterName() const { return GetterName; }
  793. IdentifierInfo *getGetterName() { return GetterName; }
  794. SourceLocation getGetterNameLoc() const { return GetterNameLoc; }
  795. void setGetterName(IdentifierInfo *name, SourceLocation loc) {
  796. GetterName = name;
  797. GetterNameLoc = loc;
  798. }
  799. const IdentifierInfo *getSetterName() const { return SetterName; }
  800. IdentifierInfo *getSetterName() { return SetterName; }
  801. SourceLocation getSetterNameLoc() const { return SetterNameLoc; }
  802. void setSetterName(IdentifierInfo *name, SourceLocation loc) {
  803. SetterName = name;
  804. SetterNameLoc = loc;
  805. }
  806. private:
  807. // FIXME: These two are unrelated and mutually exclusive. So perhaps
  808. // we can put them in a union to reflect their mutual exclusivity
  809. // (space saving is negligible).
  810. unsigned objcDeclQualifier : 7;
  811. // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttribute::Kind
  812. unsigned PropertyAttributes : NumObjCPropertyAttrsBits;
  813. unsigned Nullability : 2;
  814. SourceLocation NullabilityLoc;
  815. IdentifierInfo *GetterName; // getter name or NULL if no getter
  816. IdentifierInfo *SetterName; // setter name or NULL if no setter
  817. SourceLocation GetterNameLoc; // location of the getter attribute's value
  818. SourceLocation SetterNameLoc; // location of the setter attribute's value
  819. };
  820. /// Describes the kind of unqualified-id parsed.
  821. enum class UnqualifiedIdKind {
  822. /// An identifier.
  823. IK_Identifier,
  824. /// An overloaded operator name, e.g., operator+.
  825. IK_OperatorFunctionId,
  826. /// A conversion function name, e.g., operator int.
  827. IK_ConversionFunctionId,
  828. /// A user-defined literal name, e.g., operator "" _i.
  829. IK_LiteralOperatorId,
  830. /// A constructor name.
  831. IK_ConstructorName,
  832. /// A constructor named via a template-id.
  833. IK_ConstructorTemplateId,
  834. /// A destructor name.
  835. IK_DestructorName,
  836. /// A template-id, e.g., f<int>.
  837. IK_TemplateId,
  838. /// An implicit 'self' parameter
  839. IK_ImplicitSelfParam,
  840. /// A deduction-guide name (a template-name)
  841. IK_DeductionGuideName
  842. };
  843. /// Represents a C++ unqualified-id that has been parsed.
  844. class UnqualifiedId {
  845. private:
  846. UnqualifiedId(const UnqualifiedId &Other) = delete;
  847. const UnqualifiedId &operator=(const UnqualifiedId &) = delete;
  848. public:
  849. /// Describes the kind of unqualified-id parsed.
  850. UnqualifiedIdKind Kind;
  851. struct OFI {
  852. /// The kind of overloaded operator.
  853. OverloadedOperatorKind Operator;
  854. /// The source locations of the individual tokens that name
  855. /// the operator, e.g., the "new", "[", and "]" tokens in
  856. /// operator new [].
  857. ///
  858. /// Different operators have different numbers of tokens in their name,
  859. /// up to three. Any remaining source locations in this array will be
  860. /// set to an invalid value for operators with fewer than three tokens.
  861. SourceLocation SymbolLocations[3];
  862. };
  863. /// Anonymous union that holds extra data associated with the
  864. /// parsed unqualified-id.
  865. union {
  866. /// When Kind == IK_Identifier, the parsed identifier, or when
  867. /// Kind == IK_UserLiteralId, the identifier suffix.
  868. IdentifierInfo *Identifier;
  869. /// When Kind == IK_OperatorFunctionId, the overloaded operator
  870. /// that we parsed.
  871. struct OFI OperatorFunctionId;
  872. /// When Kind == IK_ConversionFunctionId, the type that the
  873. /// conversion function names.
  874. UnionParsedType ConversionFunctionId;
  875. /// When Kind == IK_ConstructorName, the class-name of the type
  876. /// whose constructor is being referenced.
  877. UnionParsedType ConstructorName;
  878. /// When Kind == IK_DestructorName, the type referred to by the
  879. /// class-name.
  880. UnionParsedType DestructorName;
  881. /// When Kind == IK_DeductionGuideName, the parsed template-name.
  882. UnionParsedTemplateTy TemplateName;
  883. /// When Kind == IK_TemplateId or IK_ConstructorTemplateId,
  884. /// the template-id annotation that contains the template name and
  885. /// template arguments.
  886. TemplateIdAnnotation *TemplateId;
  887. };
  888. /// The location of the first token that describes this unqualified-id,
  889. /// which will be the location of the identifier, "operator" keyword,
  890. /// tilde (for a destructor), or the template name of a template-id.
  891. SourceLocation StartLocation;
  892. /// The location of the last token that describes this unqualified-id.
  893. SourceLocation EndLocation;
  894. UnqualifiedId()
  895. : Kind(UnqualifiedIdKind::IK_Identifier), Identifier(nullptr) {}
  896. /// Clear out this unqualified-id, setting it to default (invalid)
  897. /// state.
  898. void clear() {
  899. Kind = UnqualifiedIdKind::IK_Identifier;
  900. Identifier = nullptr;
  901. StartLocation = SourceLocation();
  902. EndLocation = SourceLocation();
  903. }
  904. /// Determine whether this unqualified-id refers to a valid name.
  905. bool isValid() const { return StartLocation.isValid(); }
  906. /// Determine whether this unqualified-id refers to an invalid name.
  907. bool isInvalid() const { return !isValid(); }
  908. /// Determine what kind of name we have.
  909. UnqualifiedIdKind getKind() const { return Kind; }
  910. /// Specify that this unqualified-id was parsed as an identifier.
  911. ///
  912. /// \param Id the parsed identifier.
  913. /// \param IdLoc the location of the parsed identifier.
  914. void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) {
  915. Kind = UnqualifiedIdKind::IK_Identifier;
  916. Identifier = const_cast<IdentifierInfo *>(Id);
  917. StartLocation = EndLocation = IdLoc;
  918. }
  919. /// Specify that this unqualified-id was parsed as an
  920. /// operator-function-id.
  921. ///
  922. /// \param OperatorLoc the location of the 'operator' keyword.
  923. ///
  924. /// \param Op the overloaded operator.
  925. ///
  926. /// \param SymbolLocations the locations of the individual operator symbols
  927. /// in the operator.
  928. void setOperatorFunctionId(SourceLocation OperatorLoc,
  929. OverloadedOperatorKind Op,
  930. SourceLocation SymbolLocations[3]);
  931. /// Specify that this unqualified-id was parsed as a
  932. /// conversion-function-id.
  933. ///
  934. /// \param OperatorLoc the location of the 'operator' keyword.
  935. ///
  936. /// \param Ty the type to which this conversion function is converting.
  937. ///
  938. /// \param EndLoc the location of the last token that makes up the type name.
  939. void setConversionFunctionId(SourceLocation OperatorLoc,
  940. ParsedType Ty,
  941. SourceLocation EndLoc) {
  942. Kind = UnqualifiedIdKind::IK_ConversionFunctionId;
  943. StartLocation = OperatorLoc;
  944. EndLocation = EndLoc;
  945. ConversionFunctionId = Ty;
  946. }
  947. /// Specific that this unqualified-id was parsed as a
  948. /// literal-operator-id.
  949. ///
  950. /// \param Id the parsed identifier.
  951. ///
  952. /// \param OpLoc the location of the 'operator' keyword.
  953. ///
  954. /// \param IdLoc the location of the identifier.
  955. void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc,
  956. SourceLocation IdLoc) {
  957. Kind = UnqualifiedIdKind::IK_LiteralOperatorId;
  958. Identifier = const_cast<IdentifierInfo *>(Id);
  959. StartLocation = OpLoc;
  960. EndLocation = IdLoc;
  961. }
  962. /// Specify that this unqualified-id was parsed as a constructor name.
  963. ///
  964. /// \param ClassType the class type referred to by the constructor name.
  965. ///
  966. /// \param ClassNameLoc the location of the class name.
  967. ///
  968. /// \param EndLoc the location of the last token that makes up the type name.
  969. void setConstructorName(ParsedType ClassType,
  970. SourceLocation ClassNameLoc,
  971. SourceLocation EndLoc) {
  972. Kind = UnqualifiedIdKind::IK_ConstructorName;
  973. StartLocation = ClassNameLoc;
  974. EndLocation = EndLoc;
  975. ConstructorName = ClassType;
  976. }
  977. /// Specify that this unqualified-id was parsed as a
  978. /// template-id that names a constructor.
  979. ///
  980. /// \param TemplateId the template-id annotation that describes the parsed
  981. /// template-id. This UnqualifiedId instance will take ownership of the
  982. /// \p TemplateId and will free it on destruction.
  983. void setConstructorTemplateId(TemplateIdAnnotation *TemplateId);
  984. /// Specify that this unqualified-id was parsed as a destructor name.
  985. ///
  986. /// \param TildeLoc the location of the '~' that introduces the destructor
  987. /// name.
  988. ///
  989. /// \param ClassType the name of the class referred to by the destructor name.
  990. void setDestructorName(SourceLocation TildeLoc,
  991. ParsedType ClassType,
  992. SourceLocation EndLoc) {
  993. Kind = UnqualifiedIdKind::IK_DestructorName;
  994. StartLocation = TildeLoc;
  995. EndLocation = EndLoc;
  996. DestructorName = ClassType;
  997. }
  998. /// Specify that this unqualified-id was parsed as a template-id.
  999. ///
  1000. /// \param TemplateId the template-id annotation that describes the parsed
  1001. /// template-id. This UnqualifiedId instance will take ownership of the
  1002. /// \p TemplateId and will free it on destruction.
  1003. void setTemplateId(TemplateIdAnnotation *TemplateId);
  1004. /// Specify that this unqualified-id was parsed as a template-name for
  1005. /// a deduction-guide.
  1006. ///
  1007. /// \param Template The parsed template-name.
  1008. /// \param TemplateLoc The location of the parsed template-name.
  1009. void setDeductionGuideName(ParsedTemplateTy Template,
  1010. SourceLocation TemplateLoc) {
  1011. Kind = UnqualifiedIdKind::IK_DeductionGuideName;
  1012. TemplateName = Template;
  1013. StartLocation = EndLocation = TemplateLoc;
  1014. }
  1015. /// Specify that this unqualified-id is an implicit 'self'
  1016. /// parameter.
  1017. ///
  1018. /// \param Id the identifier.
  1019. void setImplicitSelfParam(const IdentifierInfo *Id) {
  1020. Kind = UnqualifiedIdKind::IK_ImplicitSelfParam;
  1021. Identifier = const_cast<IdentifierInfo *>(Id);
  1022. StartLocation = EndLocation = SourceLocation();
  1023. }
  1024. /// Return the source range that covers this unqualified-id.
  1025. SourceRange getSourceRange() const LLVM_READONLY {
  1026. return SourceRange(StartLocation, EndLocation);
  1027. }
  1028. SourceLocation getBeginLoc() const LLVM_READONLY { return StartLocation; }
  1029. SourceLocation getEndLoc() const LLVM_READONLY { return EndLocation; }
  1030. };
  1031. /// A set of tokens that has been cached for later parsing.
  1032. typedef SmallVector<Token, 4> CachedTokens;
  1033. /// One instance of this struct is used for each type in a
  1034. /// declarator that is parsed.
  1035. ///
  1036. /// This is intended to be a small value object.
  1037. struct DeclaratorChunk {
  1038. DeclaratorChunk() {};
  1039. enum {
  1040. Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe
  1041. } Kind;
  1042. /// Loc - The place where this type was defined.
  1043. SourceLocation Loc;
  1044. /// EndLoc - If valid, the place where this chunck ends.
  1045. SourceLocation EndLoc;
  1046. SourceRange getSourceRange() const {
  1047. if (EndLoc.isInvalid())
  1048. return SourceRange(Loc, Loc);
  1049. return SourceRange(Loc, EndLoc);
  1050. }
  1051. ParsedAttributesView AttrList;
  1052. struct PointerTypeInfo {
  1053. /// The type qualifiers: const/volatile/restrict/unaligned/atomic.
  1054. unsigned TypeQuals : 5;
  1055. /// The location of the const-qualifier, if any.
  1056. SourceLocation ConstQualLoc;
  1057. /// The location of the volatile-qualifier, if any.
  1058. SourceLocation VolatileQualLoc;
  1059. /// The location of the restrict-qualifier, if any.
  1060. SourceLocation RestrictQualLoc;
  1061. /// The location of the _Atomic-qualifier, if any.
  1062. SourceLocation AtomicQualLoc;
  1063. /// The location of the __unaligned-qualifier, if any.
  1064. SourceLocation UnalignedQualLoc;
  1065. void destroy() {
  1066. }
  1067. };
  1068. struct ReferenceTypeInfo {
  1069. /// The type qualifier: restrict. [GNU] C++ extension
  1070. bool HasRestrict : 1;
  1071. /// True if this is an lvalue reference, false if it's an rvalue reference.
  1072. bool LValueRef : 1;
  1073. void destroy() {
  1074. }
  1075. };
  1076. struct ArrayTypeInfo {
  1077. /// The type qualifiers for the array:
  1078. /// const/volatile/restrict/__unaligned/_Atomic.
  1079. unsigned TypeQuals : 5;
  1080. /// True if this dimension included the 'static' keyword.
  1081. unsigned hasStatic : 1;
  1082. /// True if this dimension was [*]. In this case, NumElts is null.
  1083. unsigned isStar : 1;
  1084. /// This is the size of the array, or null if [] or [*] was specified.
  1085. /// Since the parser is multi-purpose, and we don't want to impose a root
  1086. /// expression class on all clients, NumElts is untyped.
  1087. Expr *NumElts;
  1088. void destroy() {}
  1089. };
  1090. /// ParamInfo - An array of paraminfo objects is allocated whenever a function
  1091. /// declarator is parsed. There are two interesting styles of parameters
  1092. /// here:
  1093. /// K&R-style identifier lists and parameter type lists. K&R-style identifier
  1094. /// lists will have information about the identifier, but no type information.
  1095. /// Parameter type lists will have type info (if the actions module provides
  1096. /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'.
  1097. struct ParamInfo {
  1098. IdentifierInfo *Ident;
  1099. SourceLocation IdentLoc;
  1100. Decl *Param;
  1101. /// DefaultArgTokens - When the parameter's default argument
  1102. /// cannot be parsed immediately (because it occurs within the
  1103. /// declaration of a member function), it will be stored here as a
  1104. /// sequence of tokens to be parsed once the class definition is
  1105. /// complete. Non-NULL indicates that there is a default argument.
  1106. std::unique_ptr<CachedTokens> DefaultArgTokens;
  1107. ParamInfo() = default;
  1108. ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
  1109. Decl *param,
  1110. std::unique_ptr<CachedTokens> DefArgTokens = nullptr)
  1111. : Ident(ident), IdentLoc(iloc), Param(param),
  1112. DefaultArgTokens(std::move(DefArgTokens)) {}
  1113. };
  1114. struct TypeAndRange {
  1115. ParsedType Ty;
  1116. SourceRange Range;
  1117. };
  1118. struct FunctionTypeInfo {
  1119. /// hasPrototype - This is true if the function had at least one typed
  1120. /// parameter. If the function is () or (a,b,c), then it has no prototype,
  1121. /// and is treated as a K&R-style function.
  1122. unsigned hasPrototype : 1;
  1123. /// isVariadic - If this function has a prototype, and if that
  1124. /// proto ends with ',...)', this is true. When true, EllipsisLoc
  1125. /// contains the location of the ellipsis.
  1126. unsigned isVariadic : 1;
  1127. /// Can this declaration be a constructor-style initializer?
  1128. unsigned isAmbiguous : 1;
  1129. /// Whether the ref-qualifier (if any) is an lvalue reference.
  1130. /// Otherwise, it's an rvalue reference.
  1131. unsigned RefQualifierIsLValueRef : 1;
  1132. /// ExceptionSpecType - An ExceptionSpecificationType value.
  1133. unsigned ExceptionSpecType : 4;
  1134. /// DeleteParams - If this is true, we need to delete[] Params.
  1135. unsigned DeleteParams : 1;
  1136. /// HasTrailingReturnType - If this is true, a trailing return type was
  1137. /// specified.
  1138. unsigned HasTrailingReturnType : 1;
  1139. /// The location of the left parenthesis in the source.
  1140. SourceLocation LParenLoc;
  1141. /// When isVariadic is true, the location of the ellipsis in the source.
  1142. SourceLocation EllipsisLoc;
  1143. /// The location of the right parenthesis in the source.
  1144. SourceLocation RParenLoc;
  1145. /// NumParams - This is the number of formal parameters specified by the
  1146. /// declarator.
  1147. unsigned NumParams;
  1148. /// NumExceptionsOrDecls - This is the number of types in the
  1149. /// dynamic-exception-decl, if the function has one. In C, this is the
  1150. /// number of declarations in the function prototype.
  1151. unsigned NumExceptionsOrDecls;
  1152. /// The location of the ref-qualifier, if any.
  1153. ///
  1154. /// If this is an invalid location, there is no ref-qualifier.
  1155. SourceLocation RefQualifierLoc;
  1156. /// The location of the 'mutable' qualifer in a lambda-declarator, if
  1157. /// any.
  1158. SourceLocation MutableLoc;
  1159. /// The beginning location of the exception specification, if any.
  1160. SourceLocation ExceptionSpecLocBeg;
  1161. /// The end location of the exception specification, if any.
  1162. SourceLocation ExceptionSpecLocEnd;
  1163. /// Params - This is a pointer to a new[]'d array of ParamInfo objects that
  1164. /// describe the parameters specified by this function declarator. null if
  1165. /// there are no parameters specified.
  1166. ParamInfo *Params;
  1167. /// DeclSpec for the function with the qualifier related info.
  1168. DeclSpec *MethodQualifiers;
  1169. /// AtttibuteFactory for the MethodQualifiers.
  1170. AttributeFactory *QualAttrFactory;
  1171. union {
  1172. /// Pointer to a new[]'d array of TypeAndRange objects that
  1173. /// contain the types in the function's dynamic exception specification
  1174. /// and their locations, if there is one.
  1175. TypeAndRange *Exceptions;
  1176. /// Pointer to the expression in the noexcept-specifier of this
  1177. /// function, if it has one.
  1178. Expr *NoexceptExpr;
  1179. /// Pointer to the cached tokens for an exception-specification
  1180. /// that has not yet been parsed.
  1181. CachedTokens *ExceptionSpecTokens;
  1182. /// Pointer to a new[]'d array of declarations that need to be available
  1183. /// for lookup inside the function body, if one exists. Does not exist in
  1184. /// C++.
  1185. NamedDecl **DeclsInPrototype;
  1186. };
  1187. /// If HasTrailingReturnType is true, this is the trailing return
  1188. /// type specified.
  1189. UnionParsedType TrailingReturnType;
  1190. /// If HasTrailingReturnType is true, this is the location of the trailing
  1191. /// return type.
  1192. SourceLocation TrailingReturnTypeLoc;
  1193. /// Reset the parameter list to having zero parameters.
  1194. ///
  1195. /// This is used in various places for error recovery.
  1196. void freeParams() {
  1197. for (unsigned I = 0; I < NumParams; ++I)
  1198. Params[I].DefaultArgTokens.reset();
  1199. if (DeleteParams) {
  1200. delete[] Params;
  1201. DeleteParams = false;
  1202. }
  1203. NumParams = 0;
  1204. }
  1205. void destroy() {
  1206. freeParams();
  1207. delete QualAttrFactory;
  1208. delete MethodQualifiers;
  1209. switch (getExceptionSpecType()) {
  1210. default:
  1211. break;
  1212. case EST_Dynamic:
  1213. delete[] Exceptions;
  1214. break;
  1215. case EST_Unparsed:
  1216. delete ExceptionSpecTokens;
  1217. break;
  1218. case EST_None:
  1219. if (NumExceptionsOrDecls != 0)
  1220. delete[] DeclsInPrototype;
  1221. break;
  1222. }
  1223. }
  1224. DeclSpec &getOrCreateMethodQualifiers() {
  1225. if (!MethodQualifiers) {
  1226. QualAttrFactory = new AttributeFactory();
  1227. MethodQualifiers = new DeclSpec(*QualAttrFactory);
  1228. }
  1229. return *MethodQualifiers;
  1230. }
  1231. /// isKNRPrototype - Return true if this is a K&R style identifier list,
  1232. /// like "void foo(a,b,c)". In a function definition, this will be followed
  1233. /// by the parameter type definitions.
  1234. bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; }
  1235. SourceLocation getLParenLoc() const { return LParenLoc; }
  1236. SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
  1237. SourceLocation getRParenLoc() const { return RParenLoc; }
  1238. SourceLocation getExceptionSpecLocBeg() const {
  1239. return ExceptionSpecLocBeg;
  1240. }
  1241. SourceLocation getExceptionSpecLocEnd() const {
  1242. return ExceptionSpecLocEnd;
  1243. }
  1244. SourceRange getExceptionSpecRange() const {
  1245. return SourceRange(getExceptionSpecLocBeg(), getExceptionSpecLocEnd());
  1246. }
  1247. /// Retrieve the location of the ref-qualifier, if any.
  1248. SourceLocation getRefQualifierLoc() const { return RefQualifierLoc; }
  1249. /// Retrieve the location of the 'const' qualifier.
  1250. SourceLocation getConstQualifierLoc() const {
  1251. assert(MethodQualifiers);
  1252. return MethodQualifiers->getConstSpecLoc();
  1253. }
  1254. /// Retrieve the location of the 'volatile' qualifier.
  1255. SourceLocation getVolatileQualifierLoc() const {
  1256. assert(MethodQualifiers);
  1257. return MethodQualifiers->getVolatileSpecLoc();
  1258. }
  1259. /// Retrieve the location of the 'restrict' qualifier.
  1260. SourceLocation getRestrictQualifierLoc() const {
  1261. assert(MethodQualifiers);
  1262. return MethodQualifiers->getRestrictSpecLoc();
  1263. }
  1264. /// Retrieve the location of the 'mutable' qualifier, if any.
  1265. SourceLocation getMutableLoc() const { return MutableLoc; }
  1266. /// Determine whether this function declaration contains a
  1267. /// ref-qualifier.
  1268. bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
  1269. /// Determine whether this lambda-declarator contains a 'mutable'
  1270. /// qualifier.
  1271. bool hasMutableQualifier() const { return getMutableLoc().isValid(); }
  1272. /// Determine whether this method has qualifiers.
  1273. bool hasMethodTypeQualifiers() const {
  1274. return MethodQualifiers && (MethodQualifiers->getTypeQualifiers() ||
  1275. MethodQualifiers->getAttributes().size());
  1276. }
  1277. /// Get the type of exception specification this function has.
  1278. ExceptionSpecificationType getExceptionSpecType() const {
  1279. return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
  1280. }
  1281. /// Get the number of dynamic exception specifications.
  1282. unsigned getNumExceptions() const {
  1283. assert(ExceptionSpecType != EST_None);
  1284. return NumExceptionsOrDecls;
  1285. }
  1286. /// Get the non-parameter decls defined within this function
  1287. /// prototype. Typically these are tag declarations.
  1288. ArrayRef<NamedDecl *> getDeclsInPrototype() const {
  1289. assert(ExceptionSpecType == EST_None);
  1290. return llvm::makeArrayRef(DeclsInPrototype, NumExceptionsOrDecls);
  1291. }
  1292. /// Determine whether this function declarator had a
  1293. /// trailing-return-type.
  1294. bool hasTrailingReturnType() const { return HasTrailingReturnType; }
  1295. /// Get the trailing-return-type for this function declarator.
  1296. ParsedType getTrailingReturnType() const {
  1297. assert(HasTrailingReturnType);
  1298. return TrailingReturnType;
  1299. }
  1300. /// Get the trailing-return-type location for this function declarator.
  1301. SourceLocation getTrailingReturnTypeLoc() const {
  1302. assert(HasTrailingReturnType);
  1303. return TrailingReturnTypeLoc;
  1304. }
  1305. };
  1306. struct BlockPointerTypeInfo {
  1307. /// For now, sema will catch these as invalid.
  1308. /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
  1309. unsigned TypeQuals : 5;
  1310. void destroy() {
  1311. }
  1312. };
  1313. struct MemberPointerTypeInfo {
  1314. /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
  1315. unsigned TypeQuals : 5;
  1316. /// Location of the '*' token.
  1317. SourceLocation StarLoc;
  1318. // CXXScopeSpec has a constructor, so it can't be a direct member.
  1319. // So we need some pointer-aligned storage and a bit of trickery.
  1320. alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)];
  1321. CXXScopeSpec &Scope() {
  1322. return *reinterpret_cast<CXXScopeSpec *>(ScopeMem);
  1323. }
  1324. const CXXScopeSpec &Scope() const {
  1325. return *reinterpret_cast<const CXXScopeSpec *>(ScopeMem);
  1326. }
  1327. void destroy() {
  1328. Scope().~CXXScopeSpec();
  1329. }
  1330. };
  1331. struct PipeTypeInfo {
  1332. /// The access writes.
  1333. unsigned AccessWrites : 3;
  1334. void destroy() {}
  1335. };
  1336. union {
  1337. PointerTypeInfo Ptr;
  1338. ReferenceTypeInfo Ref;
  1339. ArrayTypeInfo Arr;
  1340. FunctionTypeInfo Fun;
  1341. BlockPointerTypeInfo Cls;
  1342. MemberPointerTypeInfo Mem;
  1343. PipeTypeInfo PipeInfo;
  1344. };
  1345. void destroy() {
  1346. switch (Kind) {
  1347. case DeclaratorChunk::Function: return Fun.destroy();
  1348. case DeclaratorChunk::Pointer: return Ptr.destroy();
  1349. case DeclaratorChunk::BlockPointer: return Cls.destroy();
  1350. case DeclaratorChunk::Reference: return Ref.destroy();
  1351. case DeclaratorChunk::Array: return Arr.destroy();
  1352. case DeclaratorChunk::MemberPointer: return Mem.destroy();
  1353. case DeclaratorChunk::Paren: return;
  1354. case DeclaratorChunk::Pipe: return PipeInfo.destroy();
  1355. }
  1356. }
  1357. /// If there are attributes applied to this declaratorchunk, return
  1358. /// them.
  1359. const ParsedAttributesView &getAttrs() const { return AttrList; }
  1360. ParsedAttributesView &getAttrs() { return AttrList; }
  1361. /// Return a DeclaratorChunk for a pointer.
  1362. static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc,
  1363. SourceLocation ConstQualLoc,
  1364. SourceLocation VolatileQualLoc,
  1365. SourceLocation RestrictQualLoc,
  1366. SourceLocation AtomicQualLoc,
  1367. SourceLocation UnalignedQualLoc) {
  1368. DeclaratorChunk I;
  1369. I.Kind = Pointer;
  1370. I.Loc = Loc;
  1371. new (&I.Ptr) PointerTypeInfo;
  1372. I.Ptr.TypeQuals = TypeQuals;
  1373. I.Ptr.ConstQualLoc = ConstQualLoc;
  1374. I.Ptr.VolatileQualLoc = VolatileQualLoc;
  1375. I.Ptr.RestrictQualLoc = RestrictQualLoc;
  1376. I.Ptr.AtomicQualLoc = AtomicQualLoc;
  1377. I.Ptr.UnalignedQualLoc = UnalignedQualLoc;
  1378. return I;
  1379. }
  1380. /// Return a DeclaratorChunk for a reference.
  1381. static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc,
  1382. bool lvalue) {
  1383. DeclaratorChunk I;
  1384. I.Kind = Reference;
  1385. I.Loc = Loc;
  1386. I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0;
  1387. I.Ref.LValueRef = lvalue;
  1388. return I;
  1389. }
  1390. /// Return a DeclaratorChunk for an array.
  1391. static DeclaratorChunk getArray(unsigned TypeQuals,
  1392. bool isStatic, bool isStar, Expr *NumElts,
  1393. SourceLocation LBLoc, SourceLocation RBLoc) {
  1394. DeclaratorChunk I;
  1395. I.Kind = Array;
  1396. I.Loc = LBLoc;
  1397. I.EndLoc = RBLoc;
  1398. I.Arr.TypeQuals = TypeQuals;
  1399. I.Arr.hasStatic = isStatic;
  1400. I.Arr.isStar = isStar;
  1401. I.Arr.NumElts = NumElts;
  1402. return I;
  1403. }
  1404. /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
  1405. /// "TheDeclarator" is the declarator that this will be added to.
  1406. static DeclaratorChunk getFunction(bool HasProto,
  1407. bool IsAmbiguous,
  1408. SourceLocation LParenLoc,
  1409. ParamInfo *Params, unsigned NumParams,
  1410. SourceLocation EllipsisLoc,
  1411. SourceLocation RParenLoc,
  1412. bool RefQualifierIsLvalueRef,
  1413. SourceLocation RefQualifierLoc,
  1414. SourceLocation MutableLoc,
  1415. ExceptionSpecificationType ESpecType,
  1416. SourceRange ESpecRange,
  1417. ParsedType *Exceptions,
  1418. SourceRange *ExceptionRanges,
  1419. unsigned NumExceptions,
  1420. Expr *NoexceptExpr,
  1421. CachedTokens *ExceptionSpecTokens,
  1422. ArrayRef<NamedDecl *> DeclsInPrototype,
  1423. SourceLocation LocalRangeBegin,
  1424. SourceLocation LocalRangeEnd,
  1425. Declarator &TheDeclarator,
  1426. TypeResult TrailingReturnType =
  1427. TypeResult(),
  1428. SourceLocation TrailingReturnTypeLoc =
  1429. SourceLocation(),
  1430. DeclSpec *MethodQualifiers = nullptr);
  1431. /// Return a DeclaratorChunk for a block.
  1432. static DeclaratorChunk getBlockPointer(unsigned TypeQuals,
  1433. SourceLocation Loc) {
  1434. DeclaratorChunk I;
  1435. I.Kind = BlockPointer;
  1436. I.Loc = Loc;
  1437. I.Cls.TypeQuals = TypeQuals;
  1438. return I;
  1439. }
  1440. /// Return a DeclaratorChunk for a block.
  1441. static DeclaratorChunk getPipe(unsigned TypeQuals,
  1442. SourceLocation Loc) {
  1443. DeclaratorChunk I;
  1444. I.Kind = Pipe;
  1445. I.Loc = Loc;
  1446. I.Cls.TypeQuals = TypeQuals;
  1447. return I;
  1448. }
  1449. static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS,
  1450. unsigned TypeQuals,
  1451. SourceLocation StarLoc,
  1452. SourceLocation EndLoc) {
  1453. DeclaratorChunk I;
  1454. I.Kind = MemberPointer;
  1455. I.Loc = SS.getBeginLoc();
  1456. I.EndLoc = EndLoc;
  1457. new (&I.Mem) MemberPointerTypeInfo;
  1458. I.Mem.StarLoc = StarLoc;
  1459. I.Mem.TypeQuals = TypeQuals;
  1460. new (I.Mem.ScopeMem) CXXScopeSpec(SS);
  1461. return I;
  1462. }
  1463. /// Return a DeclaratorChunk for a paren.
  1464. static DeclaratorChunk getParen(SourceLocation LParenLoc,
  1465. SourceLocation RParenLoc) {
  1466. DeclaratorChunk I;
  1467. I.Kind = Paren;
  1468. I.Loc = LParenLoc;
  1469. I.EndLoc = RParenLoc;
  1470. return I;
  1471. }
  1472. bool isParen() const {
  1473. return Kind == Paren;
  1474. }
  1475. };
  1476. /// A parsed C++17 decomposition declarator of the form
  1477. /// '[' identifier-list ']'
  1478. class DecompositionDeclarator {
  1479. public:
  1480. struct Binding {
  1481. IdentifierInfo *Name;
  1482. SourceLocation NameLoc;
  1483. };
  1484. private:
  1485. /// The locations of the '[' and ']' tokens.
  1486. SourceLocation LSquareLoc, RSquareLoc;
  1487. /// The bindings.
  1488. Binding *Bindings;
  1489. unsigned NumBindings : 31;
  1490. unsigned DeleteBindings : 1;
  1491. friend class Declarator;
  1492. public:
  1493. DecompositionDeclarator()
  1494. : Bindings(nullptr), NumBindings(0), DeleteBindings(false) {}
  1495. DecompositionDeclarator(const DecompositionDeclarator &G) = delete;
  1496. DecompositionDeclarator &operator=(const DecompositionDeclarator &G) = delete;
  1497. ~DecompositionDeclarator() {
  1498. if (DeleteBindings)
  1499. delete[] Bindings;
  1500. }
  1501. void clear() {
  1502. LSquareLoc = RSquareLoc = SourceLocation();
  1503. if (DeleteBindings)
  1504. delete[] Bindings;
  1505. Bindings = nullptr;
  1506. NumBindings = 0;
  1507. DeleteBindings = false;
  1508. }
  1509. ArrayRef<Binding> bindings() const {
  1510. return llvm::makeArrayRef(Bindings, NumBindings);
  1511. }
  1512. bool isSet() const { return LSquareLoc.isValid(); }
  1513. SourceLocation getLSquareLoc() const { return LSquareLoc; }
  1514. SourceLocation getRSquareLoc() const { return RSquareLoc; }
  1515. SourceRange getSourceRange() const {
  1516. return SourceRange(LSquareLoc, RSquareLoc);
  1517. }
  1518. };
  1519. /// Described the kind of function definition (if any) provided for
  1520. /// a function.
  1521. enum class FunctionDefinitionKind {
  1522. Declaration,
  1523. Definition,
  1524. Defaulted,
  1525. Deleted
  1526. };
  1527. enum class DeclaratorContext {
  1528. File, // File scope declaration.
  1529. Prototype, // Within a function prototype.
  1530. ObjCResult, // An ObjC method result type.
  1531. ObjCParameter, // An ObjC method parameter type.
  1532. KNRTypeList, // K&R type definition list for formals.
  1533. TypeName, // Abstract declarator for types.
  1534. FunctionalCast, // Type in a C++ functional cast expression.
  1535. Member, // Struct/Union field.
  1536. Block, // Declaration within a block in a function.
  1537. ForInit, // Declaration within first part of a for loop.
  1538. SelectionInit, // Declaration within optional init stmt of if/switch.
  1539. Condition, // Condition declaration in a C++ if/switch/while/for.
  1540. TemplateParam, // Within a template parameter list.
  1541. CXXNew, // C++ new-expression.
  1542. CXXCatch, // C++ catch exception-declaration
  1543. ObjCCatch, // Objective-C catch exception-declaration
  1544. BlockLiteral, // Block literal declarator.
  1545. LambdaExpr, // Lambda-expression declarator.
  1546. LambdaExprParameter, // Lambda-expression parameter declarator.
  1547. ConversionId, // C++ conversion-type-id.
  1548. TrailingReturn, // C++11 trailing-type-specifier.
  1549. TrailingReturnVar, // C++11 trailing-type-specifier for variable.
  1550. TemplateArg, // Any template argument (in template argument list).
  1551. TemplateTypeArg, // Template type argument (in default argument).
  1552. AliasDecl, // C++11 alias-declaration.
  1553. AliasTemplate, // C++11 alias-declaration template.
  1554. RequiresExpr // C++2a requires-expression.
  1555. };
  1556. /// Information about one declarator, including the parsed type
  1557. /// information and the identifier.
  1558. ///
  1559. /// When the declarator is fully formed, this is turned into the appropriate
  1560. /// Decl object.
  1561. ///
  1562. /// Declarators come in two types: normal declarators and abstract declarators.
  1563. /// Abstract declarators are used when parsing types, and don't have an
  1564. /// identifier. Normal declarators do have ID's.
  1565. ///
  1566. /// Instances of this class should be a transient object that lives on the
  1567. /// stack, not objects that are allocated in large quantities on the heap.
  1568. class Declarator {
  1569. private:
  1570. const DeclSpec &DS;
  1571. CXXScopeSpec SS;
  1572. UnqualifiedId Name;
  1573. SourceRange Range;
  1574. /// Where we are parsing this declarator.
  1575. DeclaratorContext Context;
  1576. /// The C++17 structured binding, if any. This is an alternative to a Name.
  1577. DecompositionDeclarator BindingGroup;
  1578. /// DeclTypeInfo - This holds each type that the declarator includes as it is
  1579. /// parsed. This is pushed from the identifier out, which means that element
  1580. /// #0 will be the most closely bound to the identifier, and
  1581. /// DeclTypeInfo.back() will be the least closely bound.
  1582. SmallVector<DeclaratorChunk, 8> DeclTypeInfo;
  1583. /// InvalidType - Set by Sema::GetTypeForDeclarator().
  1584. unsigned InvalidType : 1;
  1585. /// GroupingParens - Set by Parser::ParseParenDeclarator().
  1586. unsigned GroupingParens : 1;
  1587. /// FunctionDefinition - Is this Declarator for a function or member
  1588. /// definition and, if so, what kind?
  1589. ///
  1590. /// Actually a FunctionDefinitionKind.
  1591. unsigned FunctionDefinition : 2;
  1592. /// Is this Declarator a redeclaration?
  1593. unsigned Redeclaration : 1;
  1594. /// true if the declaration is preceded by \c __extension__.
  1595. unsigned Extension : 1;
  1596. /// Indicates whether this is an Objective-C instance variable.
  1597. unsigned ObjCIvar : 1;
  1598. /// Indicates whether this is an Objective-C 'weak' property.
  1599. unsigned ObjCWeakProperty : 1;
  1600. /// Indicates whether the InlineParams / InlineBindings storage has been used.
  1601. unsigned InlineStorageUsed : 1;
  1602. /// Indicates whether this declarator has an initializer.
  1603. unsigned HasInitializer : 1;
  1604. /// Attrs - Attributes.
  1605. ParsedAttributes Attrs;
  1606. /// The asm label, if specified.
  1607. Expr *AsmLabel;
  1608. /// \brief The constraint-expression specified by the trailing
  1609. /// requires-clause, or null if no such clause was specified.
  1610. Expr *TrailingRequiresClause;
  1611. /// If this declarator declares a template, its template parameter lists.
  1612. ArrayRef<TemplateParameterList *> TemplateParameterLists;
  1613. /// If the declarator declares an abbreviated function template, the innermost
  1614. /// template parameter list containing the invented and explicit template
  1615. /// parameters (if any).
  1616. TemplateParameterList *InventedTemplateParameterList;
  1617. #ifndef _MSC_VER
  1618. union {
  1619. #endif
  1620. /// InlineParams - This is a local array used for the first function decl
  1621. /// chunk to avoid going to the heap for the common case when we have one
  1622. /// function chunk in the declarator.
  1623. DeclaratorChunk::ParamInfo InlineParams[16];
  1624. DecompositionDeclarator::Binding InlineBindings[16];
  1625. #ifndef _MSC_VER
  1626. };
  1627. #endif
  1628. /// If this is the second or subsequent declarator in this declaration,
  1629. /// the location of the comma before this declarator.
  1630. SourceLocation CommaLoc;
  1631. /// If provided, the source location of the ellipsis used to describe
  1632. /// this declarator as a parameter pack.
  1633. SourceLocation EllipsisLoc;
  1634. friend struct DeclaratorChunk;
  1635. public:
  1636. Declarator(const DeclSpec &ds, DeclaratorContext C)
  1637. : DS(ds), Range(ds.getSourceRange()), Context(C),
  1638. InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
  1639. GroupingParens(false), FunctionDefinition(static_cast<unsigned>(
  1640. FunctionDefinitionKind::Declaration)),
  1641. Redeclaration(false), Extension(false), ObjCIvar(false),
  1642. ObjCWeakProperty(false), InlineStorageUsed(false),
  1643. HasInitializer(false), Attrs(ds.getAttributePool().getFactory()),
  1644. AsmLabel(nullptr), TrailingRequiresClause(nullptr),
  1645. InventedTemplateParameterList(nullptr) {}
  1646. ~Declarator() {
  1647. clear();
  1648. }
  1649. /// getDeclSpec - Return the declaration-specifier that this declarator was
  1650. /// declared with.
  1651. const DeclSpec &getDeclSpec() const { return DS; }
  1652. /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This
  1653. /// should be used with extreme care: declspecs can often be shared between
  1654. /// multiple declarators, so mutating the DeclSpec affects all of the
  1655. /// Declarators. This should only be done when the declspec is known to not
  1656. /// be shared or when in error recovery etc.
  1657. DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); }
  1658. AttributePool &getAttributePool() const {
  1659. return Attrs.getPool();
  1660. }
  1661. /// getCXXScopeSpec - Return the C++ scope specifier (global scope or
  1662. /// nested-name-specifier) that is part of the declarator-id.
  1663. const CXXScopeSpec &getCXXScopeSpec() const { return SS; }
  1664. CXXScopeSpec &getCXXScopeSpec() { return SS; }
  1665. /// Retrieve the name specified by this declarator.
  1666. UnqualifiedId &getName() { return Name; }
  1667. const DecompositionDeclarator &getDecompositionDeclarator() const {
  1668. return BindingGroup;
  1669. }
  1670. DeclaratorContext getContext() const { return Context; }
  1671. bool isPrototypeContext() const {
  1672. return (Context == DeclaratorContext::Prototype ||
  1673. Context == DeclaratorContext::ObjCParameter ||
  1674. Context == DeclaratorContext::ObjCResult ||
  1675. Context == DeclaratorContext::LambdaExprParameter);
  1676. }
  1677. /// Get the source range that spans this declarator.
  1678. SourceRange getSourceRange() const LLVM_READONLY { return Range; }
  1679. SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
  1680. SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
  1681. void SetSourceRange(SourceRange R) { Range = R; }
  1682. /// SetRangeBegin - Set the start of the source range to Loc, unless it's
  1683. /// invalid.
  1684. void SetRangeBegin(SourceLocation Loc) {
  1685. if (!Loc.isInvalid())
  1686. Range.setBegin(Loc);
  1687. }
  1688. /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
  1689. void SetRangeEnd(SourceLocation Loc) {
  1690. if (!Loc.isInvalid())
  1691. Range.setEnd(Loc);
  1692. }
  1693. /// ExtendWithDeclSpec - Extend the declarator source range to include the
  1694. /// given declspec, unless its location is invalid. Adopts the range start if
  1695. /// the current range start is invalid.
  1696. void ExtendWithDeclSpec(const DeclSpec &DS) {
  1697. SourceRange SR = DS.getSourceRange();
  1698. if (Range.getBegin().isInvalid())
  1699. Range.setBegin(SR.getBegin());
  1700. if (!SR.getEnd().isInvalid())
  1701. Range.setEnd(SR.getEnd());
  1702. }
  1703. /// Reset the contents of this Declarator.
  1704. void clear() {
  1705. SS.clear();
  1706. Name.clear();
  1707. Range = DS.getSourceRange();
  1708. BindingGroup.clear();
  1709. for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i)
  1710. DeclTypeInfo[i].destroy();
  1711. DeclTypeInfo.clear();
  1712. Attrs.clear();
  1713. AsmLabel = nullptr;
  1714. InlineStorageUsed = false;
  1715. HasInitializer = false;
  1716. ObjCIvar = false;
  1717. ObjCWeakProperty = false;
  1718. CommaLoc = SourceLocation();
  1719. EllipsisLoc = SourceLocation();
  1720. }
  1721. /// mayOmitIdentifier - Return true if the identifier is either optional or
  1722. /// not allowed. This is true for typenames, prototypes, and template
  1723. /// parameter lists.
  1724. bool mayOmitIdentifier() const {
  1725. switch (Context) {
  1726. case DeclaratorContext::File:
  1727. case DeclaratorContext::KNRTypeList:
  1728. case DeclaratorContext::Member:
  1729. case DeclaratorContext::Block:
  1730. case DeclaratorContext::ForInit:
  1731. case DeclaratorContext::SelectionInit:
  1732. case DeclaratorContext::Condition:
  1733. return false;
  1734. case DeclaratorContext::TypeName:
  1735. case DeclaratorContext::FunctionalCast:
  1736. case DeclaratorContext::AliasDecl:
  1737. case DeclaratorContext::AliasTemplate:
  1738. case DeclaratorContext::Prototype:
  1739. case DeclaratorContext::LambdaExprParameter:
  1740. case DeclaratorContext::ObjCParameter:
  1741. case DeclaratorContext::ObjCResult:
  1742. case DeclaratorContext::TemplateParam:
  1743. case DeclaratorContext::CXXNew:
  1744. case DeclaratorContext::CXXCatch:
  1745. case DeclaratorContext::ObjCCatch:
  1746. case DeclaratorContext::BlockLiteral:
  1747. case DeclaratorContext::LambdaExpr:
  1748. case DeclaratorContext::ConversionId:
  1749. case DeclaratorContext::TemplateArg:
  1750. case DeclaratorContext::TemplateTypeArg:
  1751. case DeclaratorContext::TrailingReturn:
  1752. case DeclaratorContext::TrailingReturnVar:
  1753. case DeclaratorContext::RequiresExpr:
  1754. return true;
  1755. }
  1756. llvm_unreachable("unknown context kind!");
  1757. }
  1758. /// mayHaveIdentifier - Return true if the identifier is either optional or
  1759. /// required. This is true for normal declarators and prototypes, but not
  1760. /// typenames.
  1761. bool mayHaveIdentifier() const {
  1762. switch (Context) {
  1763. case DeclaratorContext::File:
  1764. case DeclaratorContext::KNRTypeList:
  1765. case DeclaratorContext::Member:
  1766. case DeclaratorContext::Block:
  1767. case DeclaratorContext::ForInit:
  1768. case DeclaratorContext::SelectionInit:
  1769. case DeclaratorContext::Condition:
  1770. case DeclaratorContext::Prototype:
  1771. case DeclaratorContext::LambdaExprParameter:
  1772. case DeclaratorContext::TemplateParam:
  1773. case DeclaratorContext::CXXCatch:
  1774. case DeclaratorContext::ObjCCatch:
  1775. case DeclaratorContext::RequiresExpr:
  1776. return true;
  1777. case DeclaratorContext::TypeName:
  1778. case DeclaratorContext::FunctionalCast:
  1779. case DeclaratorContext::CXXNew:
  1780. case DeclaratorContext::AliasDecl:
  1781. case DeclaratorContext::AliasTemplate:
  1782. case DeclaratorContext::ObjCParameter:
  1783. case DeclaratorContext::ObjCResult:
  1784. case DeclaratorContext::BlockLiteral:
  1785. case DeclaratorContext::LambdaExpr:
  1786. case DeclaratorContext::ConversionId:
  1787. case DeclaratorContext::TemplateArg:
  1788. case DeclaratorContext::TemplateTypeArg:
  1789. case DeclaratorContext::TrailingReturn:
  1790. case DeclaratorContext::TrailingReturnVar:
  1791. return false;
  1792. }
  1793. llvm_unreachable("unknown context kind!");
  1794. }
  1795. /// Return true if the context permits a C++17 decomposition declarator.
  1796. bool mayHaveDecompositionDeclarator() const {
  1797. switch (Context) {
  1798. case DeclaratorContext::File:
  1799. // FIXME: It's not clear that the proposal meant to allow file-scope
  1800. // structured bindings, but it does.
  1801. case DeclaratorContext::Block:
  1802. case DeclaratorContext::ForInit:
  1803. case DeclaratorContext::SelectionInit:
  1804. case DeclaratorContext::Condition:
  1805. return true;
  1806. case DeclaratorContext::Member:
  1807. case DeclaratorContext::Prototype:
  1808. case DeclaratorContext::TemplateParam:
  1809. case DeclaratorContext::RequiresExpr:
  1810. // Maybe one day...
  1811. return false;
  1812. // These contexts don't allow any kind of non-abstract declarator.
  1813. case DeclaratorContext::KNRTypeList:
  1814. case DeclaratorContext::TypeName:
  1815. case DeclaratorContext::FunctionalCast:
  1816. case DeclaratorContext::AliasDecl:
  1817. case DeclaratorContext::AliasTemplate:
  1818. case DeclaratorContext::LambdaExprParameter:
  1819. case DeclaratorContext::ObjCParameter:
  1820. case DeclaratorContext::ObjCResult:
  1821. case DeclaratorContext::CXXNew:
  1822. case DeclaratorContext::CXXCatch:
  1823. case DeclaratorContext::ObjCCatch:
  1824. case DeclaratorContext::BlockLiteral:
  1825. case DeclaratorContext::LambdaExpr:
  1826. case DeclaratorContext::ConversionId:
  1827. case DeclaratorContext::TemplateArg:
  1828. case DeclaratorContext::TemplateTypeArg:
  1829. case DeclaratorContext::TrailingReturn:
  1830. case DeclaratorContext::TrailingReturnVar:
  1831. return false;
  1832. }
  1833. llvm_unreachable("unknown context kind!");
  1834. }
  1835. /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be
  1836. /// followed by a C++ direct initializer, e.g. "int x(1);".
  1837. bool mayBeFollowedByCXXDirectInit() const {
  1838. if (hasGroupingParens()) return false;
  1839. if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
  1840. return false;
  1841. if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern &&
  1842. Context != DeclaratorContext::File)
  1843. return false;
  1844. // Special names can't have direct initializers.
  1845. if (Name.getKind() != UnqualifiedIdKind::IK_Identifier)
  1846. return false;
  1847. switch (Context) {
  1848. case DeclaratorContext::File:
  1849. case DeclaratorContext::Block:
  1850. case DeclaratorContext::ForInit:
  1851. case DeclaratorContext::SelectionInit:
  1852. case DeclaratorContext::TrailingReturnVar:
  1853. return true;
  1854. case DeclaratorContext::Condition:
  1855. // This may not be followed by a direct initializer, but it can't be a
  1856. // function declaration either, and we'd prefer to perform a tentative
  1857. // parse in order to produce the right diagnostic.
  1858. return true;
  1859. case DeclaratorContext::KNRTypeList:
  1860. case DeclaratorContext::Member:
  1861. case DeclaratorContext::Prototype:
  1862. case DeclaratorContext::LambdaExprParameter:
  1863. case DeclaratorContext::ObjCParameter:
  1864. case DeclaratorContext::ObjCResult:
  1865. case DeclaratorContext::TemplateParam:
  1866. case DeclaratorContext::CXXCatch:
  1867. case DeclaratorContext::ObjCCatch:
  1868. case DeclaratorContext::TypeName:
  1869. case DeclaratorContext::FunctionalCast: // FIXME
  1870. case DeclaratorContext::CXXNew:
  1871. case DeclaratorContext::AliasDecl:
  1872. case DeclaratorContext::AliasTemplate:
  1873. case DeclaratorContext::BlockLiteral:
  1874. case DeclaratorContext::LambdaExpr:
  1875. case DeclaratorContext::ConversionId:
  1876. case DeclaratorContext::TemplateArg:
  1877. case DeclaratorContext::TemplateTypeArg:
  1878. case DeclaratorContext::TrailingReturn:
  1879. case DeclaratorContext::RequiresExpr:
  1880. return false;
  1881. }
  1882. llvm_unreachable("unknown context kind!");
  1883. }
  1884. /// isPastIdentifier - Return true if we have parsed beyond the point where
  1885. /// the name would appear. (This may happen even if we haven't actually parsed
  1886. /// a name, perhaps because this context doesn't require one.)
  1887. bool isPastIdentifier() const { return Name.isValid(); }
  1888. /// hasName - Whether this declarator has a name, which might be an
  1889. /// identifier (accessible via getIdentifier()) or some kind of
  1890. /// special C++ name (constructor, destructor, etc.), or a structured
  1891. /// binding (which is not exactly a name, but occupies the same position).
  1892. bool hasName() const {
  1893. return Name.getKind() != UnqualifiedIdKind::IK_Identifier ||
  1894. Name.Identifier || isDecompositionDeclarator();
  1895. }
  1896. /// Return whether this declarator is a decomposition declarator.
  1897. bool isDecompositionDeclarator() const {
  1898. return BindingGroup.isSet();
  1899. }
  1900. IdentifierInfo *getIdentifier() const {
  1901. if (Name.getKind() == UnqualifiedIdKind::IK_Identifier)
  1902. return Name.Identifier;
  1903. return nullptr;
  1904. }
  1905. SourceLocation getIdentifierLoc() const { return Name.StartLocation; }
  1906. /// Set the name of this declarator to be the given identifier.
  1907. void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) {
  1908. Name.setIdentifier(Id, IdLoc);
  1909. }
  1910. /// Set the decomposition bindings for this declarator.
  1911. void
  1912. setDecompositionBindings(SourceLocation LSquareLoc,
  1913. ArrayRef<DecompositionDeclarator::Binding> Bindings,
  1914. SourceLocation RSquareLoc);
  1915. /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
  1916. /// EndLoc, which should be the last token of the chunk.
  1917. /// This function takes attrs by R-Value reference because it takes ownership
  1918. /// of those attributes from the parameter.
  1919. void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs,
  1920. SourceLocation EndLoc) {
  1921. DeclTypeInfo.push_back(TI);
  1922. DeclTypeInfo.back().getAttrs().addAll(attrs.begin(), attrs.end());
  1923. getAttributePool().takeAllFrom(attrs.getPool());
  1924. if (!EndLoc.isInvalid())
  1925. SetRangeEnd(EndLoc);
  1926. }
  1927. /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to
  1928. /// EndLoc, which should be the last token of the chunk.
  1929. void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) {
  1930. DeclTypeInfo.push_back(TI);
  1931. if (!EndLoc.isInvalid())
  1932. SetRangeEnd(EndLoc);
  1933. }
  1934. /// Add a new innermost chunk to this declarator.
  1935. void AddInnermostTypeInfo(const DeclaratorChunk &TI) {
  1936. DeclTypeInfo.insert(DeclTypeInfo.begin(), TI);
  1937. }
  1938. /// Return the number of types applied to this declarator.
  1939. unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); }
  1940. /// Return the specified TypeInfo from this declarator. TypeInfo #0 is
  1941. /// closest to the identifier.
  1942. const DeclaratorChunk &getTypeObject(unsigned i) const {
  1943. assert(i < DeclTypeInfo.size() && "Invalid type chunk");
  1944. return DeclTypeInfo[i];
  1945. }
  1946. DeclaratorChunk &getTypeObject(unsigned i) {
  1947. assert(i < DeclTypeInfo.size() && "Invalid type chunk");
  1948. return DeclTypeInfo[i];
  1949. }
  1950. typedef SmallVectorImpl<DeclaratorChunk>::const_iterator type_object_iterator;
  1951. typedef llvm::iterator_range<type_object_iterator> type_object_range;
  1952. /// Returns the range of type objects, from the identifier outwards.
  1953. type_object_range type_objects() const {
  1954. return type_object_range(DeclTypeInfo.begin(), DeclTypeInfo.end());
  1955. }
  1956. void DropFirstTypeObject() {
  1957. assert(!DeclTypeInfo.empty() && "No type chunks to drop.");
  1958. DeclTypeInfo.front().destroy();
  1959. DeclTypeInfo.erase(DeclTypeInfo.begin());
  1960. }
  1961. /// Return the innermost (closest to the declarator) chunk of this
  1962. /// declarator that is not a parens chunk, or null if there are no
  1963. /// non-parens chunks.
  1964. const DeclaratorChunk *getInnermostNonParenChunk() const {
  1965. for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
  1966. if (!DeclTypeInfo[i].isParen())
  1967. return &DeclTypeInfo[i];
  1968. }
  1969. return nullptr;
  1970. }
  1971. /// Return the outermost (furthest from the declarator) chunk of
  1972. /// this declarator that is not a parens chunk, or null if there are
  1973. /// no non-parens chunks.
  1974. const DeclaratorChunk *getOutermostNonParenChunk() const {
  1975. for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) {
  1976. if (!DeclTypeInfo[i-1].isParen())
  1977. return &DeclTypeInfo[i-1];
  1978. }
  1979. return nullptr;
  1980. }
  1981. /// isArrayOfUnknownBound - This method returns true if the declarator
  1982. /// is a declarator for an array of unknown bound (looking through
  1983. /// parentheses).
  1984. bool isArrayOfUnknownBound() const {
  1985. const DeclaratorChunk *chunk = getInnermostNonParenChunk();
  1986. return (chunk && chunk->Kind == DeclaratorChunk::Array &&
  1987. !chunk->Arr.NumElts);
  1988. }
  1989. /// isFunctionDeclarator - This method returns true if the declarator
  1990. /// is a function declarator (looking through parentheses).
  1991. /// If true is returned, then the reference type parameter idx is
  1992. /// assigned with the index of the declaration chunk.
  1993. bool isFunctionDeclarator(unsigned& idx) const {
  1994. for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) {
  1995. switch (DeclTypeInfo[i].Kind) {
  1996. case DeclaratorChunk::Function:
  1997. idx = i;
  1998. return true;
  1999. case DeclaratorChunk::Paren:
  2000. continue;
  2001. case DeclaratorChunk::Pointer:
  2002. case DeclaratorChunk::Reference:
  2003. case DeclaratorChunk::Array:
  2004. case DeclaratorChunk::BlockPointer:
  2005. case DeclaratorChunk::MemberPointer:
  2006. case DeclaratorChunk::Pipe:
  2007. return false;
  2008. }
  2009. llvm_unreachable("Invalid type chunk");
  2010. }
  2011. return false;
  2012. }
  2013. /// isFunctionDeclarator - Once this declarator is fully parsed and formed,
  2014. /// this method returns true if the identifier is a function declarator
  2015. /// (looking through parentheses).
  2016. bool isFunctionDeclarator() const {
  2017. unsigned index;
  2018. return isFunctionDeclarator(index);
  2019. }
  2020. /// getFunctionTypeInfo - Retrieves the function type info object
  2021. /// (looking through parentheses).
  2022. DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() {
  2023. assert(isFunctionDeclarator() && "Not a function declarator!");
  2024. unsigned index = 0;
  2025. isFunctionDeclarator(index);
  2026. return DeclTypeInfo[index].Fun;
  2027. }
  2028. /// getFunctionTypeInfo - Retrieves the function type info object
  2029. /// (looking through parentheses).
  2030. const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const {
  2031. return const_cast<Declarator*>(this)->getFunctionTypeInfo();
  2032. }
  2033. /// Determine whether the declaration that will be produced from
  2034. /// this declaration will be a function.
  2035. ///
  2036. /// A declaration can declare a function even if the declarator itself
  2037. /// isn't a function declarator, if the type specifier refers to a function
  2038. /// type. This routine checks for both cases.
  2039. bool isDeclarationOfFunction() const;
  2040. /// Return true if this declaration appears in a context where a
  2041. /// function declarator would be a function declaration.
  2042. bool isFunctionDeclarationContext() const {
  2043. if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
  2044. return false;
  2045. switch (Context) {
  2046. case DeclaratorContext::File:
  2047. case DeclaratorContext::Member:
  2048. case DeclaratorContext::Block:
  2049. case DeclaratorContext::ForInit:
  2050. case DeclaratorContext::SelectionInit:
  2051. return true;
  2052. case DeclaratorContext::Condition:
  2053. case DeclaratorContext::KNRTypeList:
  2054. case DeclaratorContext::TypeName:
  2055. case DeclaratorContext::FunctionalCast:
  2056. case DeclaratorContext::AliasDecl:
  2057. case DeclaratorContext::AliasTemplate:
  2058. case DeclaratorContext::Prototype:
  2059. case DeclaratorContext::LambdaExprParameter:
  2060. case DeclaratorContext::ObjCParameter:
  2061. case DeclaratorContext::ObjCResult:
  2062. case DeclaratorContext::TemplateParam:
  2063. case DeclaratorContext::CXXNew:
  2064. case DeclaratorContext::CXXCatch:
  2065. case DeclaratorContext::ObjCCatch:
  2066. case DeclaratorContext::BlockLiteral:
  2067. case DeclaratorContext::LambdaExpr:
  2068. case DeclaratorContext::ConversionId:
  2069. case DeclaratorContext::TemplateArg:
  2070. case DeclaratorContext::TemplateTypeArg:
  2071. case DeclaratorContext::TrailingReturn:
  2072. case DeclaratorContext::TrailingReturnVar:
  2073. case DeclaratorContext::RequiresExpr:
  2074. return false;
  2075. }
  2076. llvm_unreachable("unknown context kind!");
  2077. }
  2078. /// Determine whether this declaration appears in a context where an
  2079. /// expression could appear.
  2080. bool isExpressionContext() const {
  2081. switch (Context) {
  2082. case DeclaratorContext::File:
  2083. case DeclaratorContext::KNRTypeList:
  2084. case DeclaratorContext::Member:
  2085. // FIXME: sizeof(...) permits an expression.
  2086. case DeclaratorContext::TypeName:
  2087. case DeclaratorContext::FunctionalCast:
  2088. case DeclaratorContext::AliasDecl:
  2089. case DeclaratorContext::AliasTemplate:
  2090. case DeclaratorContext::Prototype:
  2091. case DeclaratorContext::LambdaExprParameter:
  2092. case DeclaratorContext::ObjCParameter:
  2093. case DeclaratorContext::ObjCResult:
  2094. case DeclaratorContext::TemplateParam:
  2095. case DeclaratorContext::CXXNew:
  2096. case DeclaratorContext::CXXCatch:
  2097. case DeclaratorContext::ObjCCatch:
  2098. case DeclaratorContext::BlockLiteral:
  2099. case DeclaratorContext::LambdaExpr:
  2100. case DeclaratorContext::ConversionId:
  2101. case DeclaratorContext::TrailingReturn:
  2102. case DeclaratorContext::TrailingReturnVar:
  2103. case DeclaratorContext::TemplateTypeArg:
  2104. case DeclaratorContext::RequiresExpr:
  2105. return false;
  2106. case DeclaratorContext::Block:
  2107. case DeclaratorContext::ForInit:
  2108. case DeclaratorContext::SelectionInit:
  2109. case DeclaratorContext::Condition:
  2110. case DeclaratorContext::TemplateArg:
  2111. return true;
  2112. }
  2113. llvm_unreachable("unknown context kind!");
  2114. }
  2115. /// Return true if a function declarator at this position would be a
  2116. /// function declaration.
  2117. bool isFunctionDeclaratorAFunctionDeclaration() const {
  2118. if (!isFunctionDeclarationContext())
  2119. return false;
  2120. for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I)
  2121. if (getTypeObject(I).Kind != DeclaratorChunk::Paren)
  2122. return false;
  2123. return true;
  2124. }
  2125. /// Determine whether a trailing return type was written (at any
  2126. /// level) within this declarator.
  2127. bool hasTrailingReturnType() const {
  2128. for (const auto &Chunk : type_objects())
  2129. if (Chunk.Kind == DeclaratorChunk::Function &&
  2130. Chunk.Fun.hasTrailingReturnType())
  2131. return true;
  2132. return false;
  2133. }
  2134. /// Get the trailing return type appearing (at any level) within this
  2135. /// declarator.
  2136. ParsedType getTrailingReturnType() const {
  2137. for (const auto &Chunk : type_objects())
  2138. if (Chunk.Kind == DeclaratorChunk::Function &&
  2139. Chunk.Fun.hasTrailingReturnType())
  2140. return Chunk.Fun.getTrailingReturnType();
  2141. return ParsedType();
  2142. }
  2143. /// \brief Sets a trailing requires clause for this declarator.
  2144. void setTrailingRequiresClause(Expr *TRC) {
  2145. TrailingRequiresClause = TRC;
  2146. SetRangeEnd(TRC->getEndLoc());
  2147. }
  2148. /// \brief Sets a trailing requires clause for this declarator.
  2149. Expr *getTrailingRequiresClause() {
  2150. return TrailingRequiresClause;
  2151. }
  2152. /// \brief Determine whether a trailing requires clause was written in this
  2153. /// declarator.
  2154. bool hasTrailingRequiresClause() const {
  2155. return TrailingRequiresClause != nullptr;
  2156. }
  2157. /// Sets the template parameter lists that preceded the declarator.
  2158. void setTemplateParameterLists(ArrayRef<TemplateParameterList *> TPLs) {
  2159. TemplateParameterLists = TPLs;
  2160. }
  2161. /// The template parameter lists that preceded the declarator.
  2162. ArrayRef<TemplateParameterList *> getTemplateParameterLists() const {
  2163. return TemplateParameterLists;
  2164. }
  2165. /// Sets the template parameter list generated from the explicit template
  2166. /// parameters along with any invented template parameters from
  2167. /// placeholder-typed parameters.
  2168. void setInventedTemplateParameterList(TemplateParameterList *Invented) {
  2169. InventedTemplateParameterList = Invented;
  2170. }
  2171. /// The template parameter list generated from the explicit template
  2172. /// parameters along with any invented template parameters from
  2173. /// placeholder-typed parameters, if there were any such parameters.
  2174. TemplateParameterList * getInventedTemplateParameterList() const {
  2175. return InventedTemplateParameterList;
  2176. }
  2177. /// takeAttributes - Takes attributes from the given parsed-attributes
  2178. /// set and add them to this declarator.
  2179. ///
  2180. /// These examples both add 3 attributes to "var":
  2181. /// short int var __attribute__((aligned(16),common,deprecated));
  2182. /// short int x, __attribute__((aligned(16)) var
  2183. /// __attribute__((common,deprecated));
  2184. ///
  2185. /// Also extends the range of the declarator.
  2186. void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) {
  2187. Attrs.takeAllFrom(attrs);
  2188. if (!lastLoc.isInvalid())
  2189. SetRangeEnd(lastLoc);
  2190. }
  2191. const ParsedAttributes &getAttributes() const { return Attrs; }
  2192. ParsedAttributes &getAttributes() { return Attrs; }
  2193. /// hasAttributes - do we contain any attributes?
  2194. bool hasAttributes() const {
  2195. if (!getAttributes().empty() || getDeclSpec().hasAttributes())
  2196. return true;
  2197. for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i)
  2198. if (!getTypeObject(i).getAttrs().empty())
  2199. return true;
  2200. return false;
  2201. }
  2202. /// Return a source range list of C++11 attributes associated
  2203. /// with the declarator.
  2204. void getCXX11AttributeRanges(SmallVectorImpl<SourceRange> &Ranges) {
  2205. for (const ParsedAttr &AL : Attrs)
  2206. if (AL.isCXX11Attribute())
  2207. Ranges.push_back(AL.getRange());
  2208. }
  2209. void setAsmLabel(Expr *E) { AsmLabel = E; }
  2210. Expr *getAsmLabel() const { return AsmLabel; }
  2211. void setExtension(bool Val = true) { Extension = Val; }
  2212. bool getExtension() const { return Extension; }
  2213. void setObjCIvar(bool Val = true) { ObjCIvar = Val; }
  2214. bool isObjCIvar() const { return ObjCIvar; }
  2215. void setObjCWeakProperty(bool Val = true) { ObjCWeakProperty = Val; }
  2216. bool isObjCWeakProperty() const { return ObjCWeakProperty; }
  2217. void setInvalidType(bool Val = true) { InvalidType = Val; }
  2218. bool isInvalidType() const {
  2219. return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error;
  2220. }
  2221. void setGroupingParens(bool flag) { GroupingParens = flag; }
  2222. bool hasGroupingParens() const { return GroupingParens; }
  2223. bool isFirstDeclarator() const { return !CommaLoc.isValid(); }
  2224. SourceLocation getCommaLoc() const { return CommaLoc; }
  2225. void setCommaLoc(SourceLocation CL) { CommaLoc = CL; }
  2226. bool hasEllipsis() const { return EllipsisLoc.isValid(); }
  2227. SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
  2228. void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; }
  2229. void setFunctionDefinitionKind(FunctionDefinitionKind Val) {
  2230. FunctionDefinition = static_cast<unsigned>(Val);
  2231. }
  2232. bool isFunctionDefinition() const {
  2233. return getFunctionDefinitionKind() != FunctionDefinitionKind::Declaration;
  2234. }
  2235. FunctionDefinitionKind getFunctionDefinitionKind() const {
  2236. return (FunctionDefinitionKind)FunctionDefinition;
  2237. }
  2238. void setHasInitializer(bool Val = true) { HasInitializer = Val; }
  2239. bool hasInitializer() const { return HasInitializer; }
  2240. /// Returns true if this declares a real member and not a friend.
  2241. bool isFirstDeclarationOfMember() {
  2242. return getContext() == DeclaratorContext::Member &&
  2243. !getDeclSpec().isFriendSpecified();
  2244. }
  2245. /// Returns true if this declares a static member. This cannot be called on a
  2246. /// declarator outside of a MemberContext because we won't know until
  2247. /// redeclaration time if the decl is static.
  2248. bool isStaticMember();
  2249. /// Returns true if this declares a constructor or a destructor.
  2250. bool isCtorOrDtor();
  2251. void setRedeclaration(bool Val) { Redeclaration = Val; }
  2252. bool isRedeclaration() const { return Redeclaration; }
  2253. };
  2254. /// This little struct is used to capture information about
  2255. /// structure field declarators, which is basically just a bitfield size.
  2256. struct FieldDeclarator {
  2257. Declarator D;
  2258. Expr *BitfieldSize;
  2259. explicit FieldDeclarator(const DeclSpec &DS)
  2260. : D(DS, DeclaratorContext::Member), BitfieldSize(nullptr) {}
  2261. };
  2262. /// Represents a C++11 virt-specifier-seq.
  2263. class VirtSpecifiers {
  2264. public:
  2265. enum Specifier {
  2266. VS_None = 0,
  2267. VS_Override = 1,
  2268. VS_Final = 2,
  2269. VS_Sealed = 4,
  2270. // Represents the __final keyword, which is legal for gcc in pre-C++11 mode.
  2271. VS_GNU_Final = 8,
  2272. VS_Abstract = 16
  2273. };
  2274. VirtSpecifiers() : Specifiers(0), LastSpecifier(VS_None) { }
  2275. bool SetSpecifier(Specifier VS, SourceLocation Loc,
  2276. const char *&PrevSpec);
  2277. bool isUnset() const { return Specifiers == 0; }
  2278. bool isOverrideSpecified() const { return Specifiers & VS_Override; }
  2279. SourceLocation getOverrideLoc() const { return VS_overrideLoc; }
  2280. bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed | VS_GNU_Final); }
  2281. bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; }
  2282. SourceLocation getFinalLoc() const { return VS_finalLoc; }
  2283. SourceLocation getAbstractLoc() const { return VS_abstractLoc; }
  2284. void clear() { Specifiers = 0; }
  2285. static const char *getSpecifierName(Specifier VS);
  2286. SourceLocation getFirstLocation() const { return FirstLocation; }
  2287. SourceLocation getLastLocation() const { return LastLocation; }
  2288. Specifier getLastSpecifier() const { return LastSpecifier; }
  2289. private:
  2290. unsigned Specifiers;
  2291. Specifier LastSpecifier;
  2292. SourceLocation VS_overrideLoc, VS_finalLoc, VS_abstractLoc;
  2293. SourceLocation FirstLocation;
  2294. SourceLocation LastLocation;
  2295. };
  2296. enum class LambdaCaptureInitKind {
  2297. NoInit, //!< [a]
  2298. CopyInit, //!< [a = b], [a = {b}]
  2299. DirectInit, //!< [a(b)]
  2300. ListInit //!< [a{b}]
  2301. };
  2302. /// Represents a complete lambda introducer.
  2303. struct LambdaIntroducer {
  2304. /// An individual capture in a lambda introducer.
  2305. struct LambdaCapture {
  2306. LambdaCaptureKind Kind;
  2307. SourceLocation Loc;
  2308. IdentifierInfo *Id;
  2309. SourceLocation EllipsisLoc;
  2310. LambdaCaptureInitKind InitKind;
  2311. ExprResult Init;
  2312. ParsedType InitCaptureType;
  2313. SourceRange ExplicitRange;
  2314. LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc,
  2315. IdentifierInfo *Id, SourceLocation EllipsisLoc,
  2316. LambdaCaptureInitKind InitKind, ExprResult Init,
  2317. ParsedType InitCaptureType,
  2318. SourceRange ExplicitRange)
  2319. : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc),
  2320. InitKind(InitKind), Init(Init), InitCaptureType(InitCaptureType),
  2321. ExplicitRange(ExplicitRange) {}
  2322. };
  2323. SourceRange Range;
  2324. SourceLocation DefaultLoc;
  2325. LambdaCaptureDefault Default;
  2326. SmallVector<LambdaCapture, 4> Captures;
  2327. LambdaIntroducer()
  2328. : Default(LCD_None) {}
  2329. /// Append a capture in a lambda introducer.
  2330. void addCapture(LambdaCaptureKind Kind,
  2331. SourceLocation Loc,
  2332. IdentifierInfo* Id,
  2333. SourceLocation EllipsisLoc,
  2334. LambdaCaptureInitKind InitKind,
  2335. ExprResult Init,
  2336. ParsedType InitCaptureType,
  2337. SourceRange ExplicitRange) {
  2338. Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init,
  2339. InitCaptureType, ExplicitRange));
  2340. }
  2341. };
  2342. struct InventedTemplateParameterInfo {
  2343. /// The number of parameters in the template parameter list that were
  2344. /// explicitly specified by the user, as opposed to being invented by use
  2345. /// of an auto parameter.
  2346. unsigned NumExplicitTemplateParams = 0;
  2347. /// If this is a generic lambda or abbreviated function template, use this
  2348. /// as the depth of each 'auto' parameter, during initial AST construction.
  2349. unsigned AutoTemplateParameterDepth = 0;
  2350. /// Store the list of the template parameters for a generic lambda or an
  2351. /// abbreviated function template.
  2352. /// If this is a generic lambda or abbreviated function template, this holds
  2353. /// the explicit template parameters followed by the auto parameters
  2354. /// converted into TemplateTypeParmDecls.
  2355. /// It can be used to construct the generic lambda or abbreviated template's
  2356. /// template parameter list during initial AST construction.
  2357. SmallVector<NamedDecl*, 4> TemplateParams;
  2358. };
  2359. } // end namespace clang
  2360. #endif // LLVM_CLANG_SEMA_DECLSPEC_H
  2361. #ifdef __GNUC__
  2362. #pragma GCC diagnostic pop
  2363. #endif