DeclSpec.h 101 KB

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