gcc-cp-fe.def 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /* Interface between GCC C++ FE and GDB -*- c -*-
  2. Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. /* Push namespace NAME as the current binding level, to which
  15. newly-introduced decls will be bound. An empty string identifies
  16. the global namespace, whereas NULL identifies an anonymous
  17. namespace. A namespace named NAME is created in the current scope,
  18. if needed.
  19. If the newly-created namespace is to be an inline namespace, see
  20. make_namespace_inline. */
  21. GCC_METHOD1 (int /* bool */, push_namespace,
  22. const char *) /* Argument NAME. */
  23. /* Push TYPE as the current binding level, making its members visible
  24. for name lookup. The current scope before the call must be the
  25. scope in which the class was declared. This should be used if the
  26. definition of a class is already finished, but one wishes to define
  27. a nested class, or to enter the scope of one of its member
  28. functions. */
  29. GCC_METHOD1 (int /* bool */, push_class,
  30. gcc_type) /* Argument TYPE. */
  31. /* Push FUNCTION_DECL as the current (empty) binding level (see
  32. reactivate_decl). The current enclosing scope before the call must
  33. be the scope in which the function was declared. */
  34. GCC_METHOD1 (int /* bool */, push_function,
  35. gcc_decl) /* Argument FUNCTION_DECL. */
  36. /* Make DECL visible (again?) within SCOPE. When SCOPE is NULL, it
  37. means the current scope; if it is not NULL, it must name a function
  38. that is currently active, even if not at the top of the binding
  39. chain.
  40. This function can be used to make e.g. a global function or
  41. variable visible in a namespace or local scope (overriding another
  42. enclosing definition of the same name), but its most common
  43. expected use of this primitive, that gives it its name, is to make
  44. declarations visible again after reentering a function scope,
  45. because when a function is entered with push_function, that does
  46. NOT make any of the declarations nested in it visible for name
  47. lookup.
  48. There is a reason/excuse for that: unlike namespaces and classes,
  49. G++ doesn't ever have to reenter function scopes, so its name
  50. resolution infrastructure is not prepared to do that. But wait,
  51. there is also a good use for this apparent limitation: a function
  52. may contain multiple scopes (blocks), and the name may be bound to
  53. different symbols in each of these scopes. With this interface, as
  54. we reenter a function scope, we may choose which symbols to make
  55. visible for the code snippet, or, if there could be template
  56. functions in local scopes, for unresolved names in nested template
  57. class default arguments, or in nested template function signatures.
  58. As for making a local declaration visible for the code snippet,
  59. there are two possibilities: a) introduce it upfront, while
  60. entering the scope for the user expression (see the enter_scope
  61. callback, called by g++ when encountering the push_user_expression
  62. pragma), which might save some scope switching and reactivate_decl
  63. (though this can't be helped if some declarations have to be
  64. introduced and discarded, because of multiple definitions of the
  65. same name in different scopes within a function: they have to be
  66. defined in discriminator order); or b) introduce it when its name
  67. is looked up, entering the scope, introducing the declaration,
  68. leaving the scope, and then reactivating the declaration in its
  69. local scope.
  70. Here's some more detail on how reactivate_decl works. Say there's
  71. a function foo whose body looks like this:
  72. {
  73. {
  74. // point 1
  75. class c {} o __attribute__ ((__used__)); // c , o
  76. }
  77. struct c {
  78. void f() {
  79. // point 2
  80. }
  81. } o __attribute__ ((__used__)); // c_0, o_0
  82. {
  83. class c {} p __attribute__ ((__used__)); // c_1, p
  84. // point 3
  85. o.f();
  86. }
  87. }
  88. When we are about to define class c at point 1, we enter the
  89. function foo scope, and since no symbols are visible at point 1, we
  90. proceed to declare class c. We may then define the class right
  91. away, or, if we leave the function scope, and we later wish to
  92. define it, or to define object o, we can reenter the scope and just
  93. use the previously-obtained gcc_decl to define the class, without
  94. having to reactivate the declaration.
  95. Now, if we are to set up the binding context for point 2, we have
  96. to define c_0::f, and in order to do so, we have to declare and
  97. define c_0. Before we can declare c_0, we MUST at least declare c.
  98. As a general rule, before we can declare or define any local name
  99. with a discriminator, we have to at least declare any other
  100. occurrences of the same name in the same enclosing entity with
  101. lower or absent discriminator.
  102. So, we declare c, then we leave the function scope and reenter it
  103. so as to declare c_0 (also with name "c", which is why we have to
  104. leave and reenter the function scope, otherwise we would get an
  105. error because of the duplicate definition; g++ will assign a
  106. discriminator because it still remembers there was an earlier
  107. declaration of c_0 within the function, it's just no longer in
  108. scope), then we can define c_0, including its member function f.
  109. Likewise, if we wish to define o_0, we have to define o first. If
  110. we wish to declare (and maybe then define) c_1, we have to at least
  111. declare (c and then) c_0 first.
  112. Then, as we set up the binding context to compile a code snippet at
  113. point 3, we may choose to activate c_1, o_0 and p upfront,
  114. declaring and discarding c, c_0 and o, and then reentering the
  115. funciton scope to declare c_1, o_0 and p; or we can wait for oracle
  116. lookups of c, o or p. If c is looked up, and the debugger resolves
  117. c in the scope to c_1, it is expected to enter the function scope
  118. from the top level, declare c, leave it, reenter it, declare c_0,
  119. leave it, reenter it, declare c_1, leave it, and then reactivate
  120. c_1 in the function scope. If c_1 is needed as a complete type,
  121. the definition may be given right after the declaration, or the
  122. scope will have to be reentered in order to define the class.
  123. . If the code snippet is at point 2, we don't need to (re)activate
  124. any declaration: nothing from any local scope is visible. Just
  125. entering the scope of the class containing member function f
  126. reactivates the names of its members, including the class name
  127. itself. */
  128. GCC_METHOD2 (int /* bool */, reactivate_decl,
  129. gcc_decl, /* Argument DECL. */
  130. gcc_decl) /* Argument SCOPE. */
  131. /* Pop the namespace last entered with push_namespace, or class last
  132. entered with push_class, or function last entered with
  133. push_function, restoring the binding level in effect before the
  134. matching push_* call. */
  135. GCC_METHOD0 (int /* bool */, pop_binding_level)
  136. /* Return the NAMESPACE_DECL, TYPE_DECL or FUNCTION_DECL of the
  137. binding level that would be popped by pop_scope. */
  138. GCC_METHOD0 (gcc_decl, get_current_binding_level_decl)
  139. /* Make the current binding level an inline namespace. It must be a
  140. namespace to begin with. It is safe to call this more than once
  141. for the same namespace, but after the first call, subsequent ones
  142. will not return a success status. */
  143. GCC_METHOD0 (int /* bool */, make_namespace_inline)
  144. /* Add USED_NS to the namespaces used by the current binding level.
  145. Use get_current_binding_level_decl to obtain USED_NS's
  146. gcc_decl. */
  147. GCC_METHOD1 (int /* bool */, add_using_namespace,
  148. gcc_decl) /* Argument USED_NS. */
  149. /* Introduce a namespace alias declaration, as in:
  150. namespace foo = [... ::] bar;
  151. After this call, namespace TARGET will be visible as ALIAS within
  152. the current namespace. Get the declaration for TARGET by calling
  153. get_current_binding_level_decl after pushing into it. */
  154. GCC_METHOD2 (int /* bool */, add_namespace_alias,
  155. const char *, /* Argument ALIAS. */
  156. gcc_decl) /* Argument TARGET. */
  157. /* Introduce a using declaration, as in:
  158. using foo::bar;
  159. The TARGET decl names the qualifying scope (foo:: above) and the
  160. identifier (bar), but that does not mean that only TARGET will be
  161. brought into the current scope: all bindings of TARGET's identifier
  162. in the qualifying scope will be brought in.
  163. FLAGS should specify GCC_CP_SYMBOL_USING. If the current scope is
  164. a class scope, visibility flags must be supplied.
  165. Even when TARGET is template dependent, we don't need to specify
  166. whether or not it is a typename: the supplied declaration (that
  167. could be a template-dependent type converted to declaration by
  168. get_type_decl) indicates so. */
  169. GCC_METHOD2 (int /* bool */, add_using_decl,
  170. enum gcc_cp_symbol_kind, /* Argument FLAGS. */
  171. gcc_decl) /* Argument TARGET. */
  172. /* Create a new "decl" in GCC, and bind it in the current binding
  173. level. A decl is a declaration, basically a kind of symbol.
  174. NAME is the name of the new symbol. SYM_KIND is the kind of
  175. symbol being requested. SYM_TYPE is the new symbol's C++ type;
  176. except for labels, where this is not meaningful and should be
  177. zero. If SUBSTITUTION_NAME is not NULL, then a reference to this
  178. decl in the source will later be substituted with a dereference
  179. of a variable of the given name. Otherwise, for symbols having
  180. an address (e.g., functions), ADDRESS is the address. FILENAME
  181. and LINE_NUMBER refer to the symbol's source location. If this
  182. is not known, FILENAME can be NULL and LINE_NUMBER can be 0.
  183. This function returns the new decl.
  184. Use this function to register typedefs, functions and variables to
  185. namespace and local binding levels, and typedefs, member functions
  186. (static or not), and static data members to class binding levels.
  187. Class members must have their access controls specified with
  188. GCC_CP_ACCESS_* flags in SYM_KIND.
  189. Note that, since access controls are disabled, we have no means to
  190. express private, protected and public.
  191. There are various flags that can be set in SYM_KIND to specify
  192. additional semantics. Look for GCC_CP_FLAGs in the definition of
  193. enum gcc_cp_symbol_kind in gcc-cp-interface.h.
  194. In order to define member functions, pass GCC_CP_SYMBOL_FUNCTION in
  195. SYM_KIND, and a function_type for static member functions or a
  196. method type for non-static member functions, including constructors
  197. and destructors. Use build_function_type to create a function
  198. type; for a method type, start by creating a function type without
  199. any compiler-introduced artificial arguments (the implicit this
  200. pointer, and the __in_chrg added to constructors and destructors,
  201. and __vtt_parm added to the former), and then use build_method_type
  202. to create the method type out of the class type and the function
  203. type.
  204. For operator functions, set GCC_CP_FLAG_SPECIAL_FUNCTION in
  205. SYM_KIND, in addition to any other applicable flags, and pass as
  206. NAME a string starting with the two-character mangling for operator
  207. name: "ps" for unary plus, "mL" for multiply and assign, *=; etc.
  208. Use "cv" for type converstion operators (the target type portion
  209. may be omitted, as it is taken from the return type in SYM_TYPE).
  210. For operator"", use "li" followed by the identifier (the mangled
  211. name mandates digits specifying the length of the identifier; if
  212. present, they determine the end of the identifier, otherwise, the
  213. identifier extents to the end of the string, so that "li3_Kme" and
  214. "li_Km" are equivalent).
  215. Constructors and destructors need special care, because for each
  216. constructor and destructor there may be multiple clones defined
  217. internally by the compiler. With build_decl, you can introduce the
  218. base declaration of a constructor or a destructor, setting
  219. GCC_CP_FLAG_SPECIAL_FUNCTION the flag and using names starting with
  220. capital "C" or "D", respectively, followed by a digit (see below),
  221. a blank, or NUL ('\0'). DO NOT supply an ADDRESS or a
  222. SUBSTITUTION_NAME to build_decl, it would be meaningless (and
  223. rejected) for the base declaration; use define_cdtor_clone to
  224. introduce the address of each clone. For constructor templates,
  225. declare the template with build_decl, and then, for each
  226. specialization, introduce it with
  227. build_function_template_specialization, and then define the
  228. addresses of each of its clones with define_cdtor_clone.
  229. NAMEs for GCC_CP_FLAG_SPECIAL_FUNCTION:
  230. NAME meaning
  231. C? constructor base declaration (? may be 1, 2, 4, blank or NUL)
  232. D? destructor base declaration (? may be 0, 1, 2, 4, blank or NUL)
  233. nw operator new
  234. na operator new[]
  235. dl operator delete
  236. da operator delete[]
  237. ps operator + (unary)
  238. ng operator - (unary)
  239. ad operator & (unary)
  240. de operator * (unary)
  241. co operator ~
  242. pl operator +
  243. mi operator -
  244. ml operator *
  245. dv operator /
  246. rm operator %
  247. an operator &
  248. or operator |
  249. eo operator ^
  250. aS operator =
  251. pL operator +=
  252. mI operator -=
  253. mL operator *=
  254. dV operator /=
  255. rM operator %=
  256. aN operator &=
  257. oR operator |=
  258. eO operator ^=
  259. ls operator <<
  260. rs operator >>
  261. lS operator <<=
  262. rS operator >>=
  263. eq operator ==
  264. ne operator !=
  265. lt operator <
  266. gt operator >
  267. le operator <=
  268. ge operator >=
  269. nt operator !
  270. aa operator &&
  271. oo operator ||
  272. pp operator ++
  273. mm operator --
  274. cm operator ,
  275. pm operator ->*
  276. pt operator ->
  277. cl operator ()
  278. ix operator []
  279. qu operator ?
  280. cv operator <T> (conversion operator)
  281. li<id> operator "" <id>
  282. FIXME: How about attributes? */
  283. GCC_METHOD7 (gcc_decl, build_decl,
  284. const char *, /* Argument NAME. */
  285. enum gcc_cp_symbol_kind, /* Argument SYM_KIND. */
  286. gcc_type, /* Argument SYM_TYPE. */
  287. const char *, /* Argument SUBSTITUTION_NAME. */
  288. gcc_address, /* Argument ADDRESS. */
  289. const char *, /* Argument FILENAME. */
  290. unsigned int) /* Argument LINE_NUMBER. */
  291. /* Supply the ADDRESS of one of the multiple clones of constructor or
  292. destructor CDTOR. The clone is specified by NAME, using the
  293. following name mangling conventions:
  294. C1 in-charge constructor
  295. C2 not-in-charge constructor
  296. C4 unified constructor
  297. D0 deleting destructor
  298. D1 in-charge destructor
  299. D2 not-in-charge destructor
  300. D4 unified destructor
  301. The following information is not necessary to use the API.
  302. C1 initializes an instance of the class (rather than of derived
  303. classes), including virtual base classes, whereas C2 initializes a
  304. sub-object (of the given class type) of an instance of some derived
  305. class (or a full object that doesn't have any virtual base
  306. classes).
  307. D0 and D1 destruct an instance of the class, including virtual base
  308. classes, but only the former calls operator delete to release the
  309. object's storage at the end; D2 destructs a sub-object (of the
  310. given class type) of an instance of a derived class (or a full
  311. object that doesn't have any virtual base classes).
  312. The [CD]4 manglings (and symbol definitions) are non-standard, but
  313. GCC uses them in some cases: rather than assuming they are
  314. in-charge or not-in-charge, they test the implicit argument that
  315. the others ignore to tell how to behave. These are used instead of
  316. cloning when we just can't use aliases. */
  317. GCC_METHOD3 (gcc_decl, define_cdtor_clone,
  318. const char *, /* Argument NAME. */
  319. gcc_decl, /* Argument CDTOR. */
  320. gcc_address) /* Argument ADDRESS. */
  321. /* Return the type associated with the given declaration. This is
  322. most useful to obtain the type associated with a forward-declared
  323. class, because it is the gcc_type, rather than the gcc_decl, that
  324. has to be used to build other types, but build_decl returns a
  325. gcc_decl rather than a gcc_type. This call can in theory be used
  326. to obtain the type from any other declaration; it is supposed to
  327. return the same type that was supplied when the declaration was
  328. created. */
  329. GCC_METHOD1 (gcc_type, get_decl_type,
  330. gcc_decl) /* Argument DECL. */
  331. /* Return the declaration for a type. */
  332. GCC_METHOD1 (gcc_decl, get_type_decl,
  333. gcc_type) /* Argument TYPE. */
  334. /* Declare DECL as a friend of the current class scope, if TYPE is
  335. NULL, or of TYPE itself otherwise. DECL may be a function or a
  336. class, be they template generics, template specializations or not
  337. templates. TYPE must be a class type (not a template generic).
  338. The add_friend call cannot introduce a declaration; even if the
  339. friend is first declared as a friend in the source code, the
  340. declaration belongs in the enclosing namespace, so it must be
  341. introduced in that namespace, and the resulting declaration can
  342. then be made a friend.
  343. DECL cannot, however, be a member of a template class generic,
  344. because we have no means to introduce their declarations. This
  345. interface has no notion of definitions for template generics. As a
  346. consequence, users of this interface must introduce each friend
  347. template member specialization separately, i.e., instead of:
  348. template <typename T> friend struct X<T>::M;
  349. they must be declared as if they were:
  350. friend struct X<onetype>::M;
  351. friend struct X<anothertype>::M;
  352. ... for each specialization of X.
  353. Specializations of a template can have each others' members as
  354. friends:
  355. template <typename T> class foo {
  356. int f();
  357. template <typename U> friend int foo<U>::f();
  358. };
  359. It wouldn't always be possible to define all specializations of a
  360. template class before introducing the friend declarations in their
  361. expanded, per-specialization form.
  362. In order to simplify such friend declarations, and to enable
  363. incremental friend declarations as template specializations are
  364. introduced, add_friend can be called after the befriending class is
  365. fully defined, passing it a non-NULL TYPE argument naming the
  366. befriending class type. */
  367. GCC_METHOD2 (int /* bool */, add_friend,
  368. gcc_decl, /* Argument DECL. */
  369. gcc_type) /* Argument TYPE. */
  370. /* Return the type of a pointer to a given base type. */
  371. GCC_METHOD1 (gcc_type, build_pointer_type,
  372. gcc_type) /* Argument BASE_TYPE. */
  373. /* Return the type of a reference to a given base type. */
  374. GCC_METHOD2 (gcc_type, build_reference_type,
  375. gcc_type, /* Argument BASE_TYPE. */
  376. enum gcc_cp_ref_qualifiers) /* Argument RQUALS. */
  377. /* Create a new pointer-to-member type. MEMBER_TYPE is the data
  378. member type, while CLASS_TYPE is the class type containing the data
  379. member. For pointers to member functions, MEMBER_TYPE must be a
  380. method type, and CLASS_TYPE must be specified even though it might
  381. be possible to extract it from the method type. */
  382. GCC_METHOD2 (gcc_type, build_pointer_to_member_type,
  383. gcc_type, /* Argument CLASS_TYPE. */
  384. gcc_type) /* Argument MEMBER_TYPE. */
  385. /* Start a template parameter list scope and enters it, so that
  386. subsequent build_type_template_parameter and
  387. build_value_template_parameter calls create template parameters in
  388. the list. The list is closed by a build_decl call with
  389. GCC_CP_SYMBOL_FUNCTION or GCC_CP_SYMBOL_CLASS, that, when the scope
  390. is a template parameter list, declares a template function or a
  391. template class with the then-closed parameter list. The scope in
  392. which the new declaration is to be introduced by build_decl must be
  393. entered before calling start_template_decl, and build_decl returns
  394. to that scope, from the template parameter list scope, before
  395. introducing the declaration. */
  396. GCC_METHOD0 (int /* bool */, start_template_decl)
  397. /* Build a typename template-parameter (e.g., the T in template
  398. <typename T = X>). Either PACK_P should be nonzero, to indicate an
  399. argument pack (the last argument in a variadic template argument
  400. list, as in template <typename... T>), or DEFAULT_TYPE may be
  401. non-NULL to set the default type argument (e.g. X) for the template
  402. parameter. FILENAME and LINE_NUMBER may specify the source
  403. location in which the template parameter was declared. */
  404. GCC_METHOD5 (gcc_type, build_type_template_parameter,
  405. const char *, /* Argument ID. */
  406. int /* bool */, /* Argument PACK_P. */
  407. gcc_type, /* Argument DEFAULT_TYPE. */
  408. const char *, /* Argument FILENAME. */
  409. unsigned int) /* Argument LINE_NUMBER. */
  410. /* Build a template template-parameter (e.g., the T in template
  411. <template <[...]> class T = X>). DEFAULT_TEMPL may be non-NULL to
  412. set the default type-template argument (e.g. X) for the template
  413. template parameter. FILENAME and LINE_NUMBER may specify the
  414. source location in which the template parameter was declared. */
  415. GCC_METHOD5 (gcc_utempl, build_template_template_parameter,
  416. const char *, /* Argument ID. */
  417. int /* bool */, /* Argument PACK_P. */
  418. gcc_utempl, /* Argument DEFAULT_TEMPL. */
  419. const char *, /* Argument FILENAME. */
  420. unsigned int) /* Argument LINE_NUMBER. */
  421. /* Build a value template-parameter (e.g., the V in template <typename
  422. T, T V> or in template <int V = X>). DEFAULT_VALUE may be non-NULL
  423. to set the default value argument for the template parameter (e.g.,
  424. X). FILENAME and LINE_NUMBER may specify the source location in
  425. which the template parameter was declared. */
  426. GCC_METHOD5 (gcc_decl, build_value_template_parameter,
  427. gcc_type, /* Argument TYPE. */
  428. const char *, /* Argument ID. */
  429. gcc_expr, /* Argument DEFAULT_VALUE. */
  430. const char *, /* Argument FILENAME. */
  431. unsigned int) /* Argument LINE_NUMBER. */
  432. /* Build a template-dependent typename (e.g., typename T::bar or
  433. typename T::template bart<X>). ENCLOSING_TYPE should be the
  434. template-dependent nested name specifier (e.g., T), ID should be
  435. the name of the member of the ENCLOSING_TYPE (e.g., bar or bart),
  436. and TARGS should be non-NULL and specify the template arguments
  437. (e.g. <X>) iff ID is to name a class template.
  438. In this and other calls, a template-dependent nested name specifier
  439. may be a template class parameter (build_type_template_parameter),
  440. a specialization (returned by build_dependent_type_template_id) of
  441. a template template parameter (returned by
  442. build_template_template_parameter) or a member type thereof
  443. (returned by build_dependent_typename itself). */
  444. GCC_METHOD3 (gcc_type, build_dependent_typename,
  445. gcc_type, /* Argument ENCLOSING_TYPE. */
  446. const char *, /* Argument ID. */
  447. const struct gcc_cp_template_args *) /* Argument TARGS. */
  448. /* Build a template-dependent class template (e.g., T::template bart).
  449. ENCLOSING_TYPE should be the template-dependent nested name
  450. specifier (e.g., T), ID should be the name of the class template
  451. member of the ENCLOSING_TYPE (e.g., bart). */
  452. GCC_METHOD2 (gcc_utempl, build_dependent_class_template,
  453. gcc_type, /* Argument ENCLOSING_TYPE. */
  454. const char *) /* Argument ID. */
  455. /* Build a template-dependent type template-id (e.g., T<A>).
  456. TEMPLATE_DECL should be a template template parameter (e.g., the T
  457. in template <template <[...]> class T = X>), and TARGS should
  458. specify the template arguments (e.g. <A>). */
  459. GCC_METHOD2 (gcc_type, build_dependent_type_template_id,
  460. gcc_utempl, /* Argument TEMPLATE_DECL. */
  461. const struct gcc_cp_template_args *) /* Argument TARGS. */
  462. /* Build a template-dependent expression (e.g., S::val or S::template
  463. mtf<X>, or unqualified f or template tf<X>).
  464. ENCLOSING_SCOPE should be a template-dependent nested name
  465. specifier (e.g., T), a resolved namespace or class decl, or NULL
  466. for unqualified names; ID should be the name of the member of the
  467. ENCLOSING_SCOPE (e.g., val or mtf) or unqualified overloaded
  468. function; and TARGS should list template arguments (e.g. <X>) when
  469. mtf or tf are to name a template function, or be NULL otherwise.
  470. Unqualified names and namespace- or class-qualified names can only
  471. resolve to overloaded functions, to be used in contexts that
  472. involve overload resolution that cannot be resolved because of
  473. template-dependent argument or return types, such as call
  474. expressions with template-dependent arguments, conversion
  475. expressions to function types with template-dependent argument
  476. types or the like. Other cases of unqualified or
  477. non-template-dependent-qualified names should NOT use this
  478. function, and use decl_expr to convert the appropriate function or
  479. object declaration to an expression.
  480. If ID is the name of a special member function, FLAGS should be
  481. GCC_CP_SYMBOL_FUNCTION|GCC_CP_FLAG_SPECIAL_FUNCTION, and ID should
  482. be one of the encodings for special member functions documented in
  483. build_decl. Otherwise, FLAGS should be GCC_CP_SYMBOL_MASK, which
  484. suggests the symbol kind is not known (though we know it is not a
  485. type).
  486. If ID denotes a conversion operator, CONV_TYPE should name the
  487. target type of the conversion. Otherwise, CONV_TYPE must be
  488. NULL. */
  489. GCC_METHOD5 (gcc_expr, build_dependent_expr,
  490. gcc_decl, /* Argument ENCLOSING_SCOPE. */
  491. enum gcc_cp_symbol_kind, /* Argument FLAGS. */
  492. const char *, /* Argument NAME. */
  493. gcc_type, /* Argument CONV_TYPE. */
  494. const struct gcc_cp_template_args *) /* Argument TARGS. */
  495. /* Build a gcc_expr for the value VALUE in type TYPE. */
  496. GCC_METHOD2 (gcc_expr, build_literal_expr,
  497. gcc_type, /* Argument TYPE. */
  498. unsigned long) /* Argument VALUE. */
  499. /* Build a gcc_expr that denotes DECL, the declaration of a variable
  500. or function in namespace scope, or of a static member variable or
  501. function. Use QUALIFIED_P to build the operand of unary & so as to
  502. compute a pointer-to-member, rather than a regular pointer. */
  503. GCC_METHOD2 (gcc_expr, build_decl_expr,
  504. gcc_decl, /* Argument DECL. */
  505. int /* bool */) /* Argument QUALIFIED_P. */
  506. /* Build a gcc_expr that denotes the unary operation UNARY_OP applied
  507. to the gcc_expr OPERAND. For non-expr operands, see
  508. unary_type_expr. Besides the UNARY_OP encodings used for operator
  509. names, we support "pp_" for preincrement, and "mm_" for
  510. predecrement, "nx" for noexcept, "tw" for throw, "tr" for rethrow
  511. (pass NULL as the operand), "te" for typeid, "sz" for sizeof, "az"
  512. for alignof, "dl" for delete, "gsdl" for ::delete, "da" for
  513. delete[], "gsda" for ::delete[], "sp" for pack expansion, "sZ" for
  514. sizeof...(function argument pack). */
  515. GCC_METHOD2 (gcc_expr, build_unary_expr,
  516. const char *, /* Argument UNARY_OP. */
  517. gcc_expr) /* Argument OPERAND. */
  518. /* Build a gcc_expr that denotes the binary operation BINARY_OP
  519. applied to gcc_exprs OPERAND1 and OPERAND2. Besides the BINARY_OP
  520. encodings used for operator names, we support "ds" for the operator
  521. token ".*" and "dt" for the operator token ".". When using
  522. operators that take a name as their second operand ("." and "->")
  523. use decl_expr to convert the gcc_decl of the member name to a
  524. gcc_expr, if the member name wasn't created with
  525. e.g. build_dependent_expr. */
  526. GCC_METHOD3 (gcc_expr, build_binary_expr,
  527. const char *, /* Argument BINARY_OP. */
  528. gcc_expr, /* Argument OPERAND1. */
  529. gcc_expr) /* Argument OPERAND2. */
  530. /* Build a gcc_expr that denotes the ternary operation TERNARY_OP
  531. applied to gcc_exprs OPERAND1, OPERAND2 and OPERAND3. The only
  532. supported TERNARY_OP is "qu", for the "?:" operator. */
  533. GCC_METHOD4 (gcc_expr, build_ternary_expr,
  534. const char *, /* Argument TERNARY_OP. */
  535. gcc_expr, /* Argument OPERAND1. */
  536. gcc_expr, /* Argument OPERAND2. */
  537. gcc_expr) /* Argument OPERAND3. */
  538. /* Build a gcc_expr that denotes the unary operation UNARY_OP applied
  539. to the gcc_type OPERAND. Supported unary operations taking types
  540. are "ti" for typeid, "st" for sizeof, "at" for alignof, and "sZ"
  541. for sizeof...(template argument pack). */
  542. GCC_METHOD2 (gcc_expr, build_unary_type_expr,
  543. const char *, /* Argument UNARY_OP. */
  544. gcc_type) /* Argument OPERAND. */
  545. /* Build a gcc_expr that denotes the binary operation BINARY_OP
  546. applied to gcc_type OPERAND1 and gcc_expr OPERAND2. Use this for
  547. all kinds of (single-argument) type casts ("dc", "sc", "cc", "rc"
  548. for dynamic, static, const and reinterpret casts, respectively;
  549. "cv" for functional or C-style casts). */
  550. GCC_METHOD3 (gcc_expr, build_cast_expr,
  551. const char *, /* Argument BINARY_OP. */
  552. gcc_type, /* Argument OPERAND1. */
  553. gcc_expr) /* Argument OPERAND2. */
  554. /* Build a gcc_expr that denotes the conversion of an expression list
  555. VALUES to TYPE, with ("tl") or without ("cv") braces, or a braced
  556. initializer list of unspecified type (e.g., a component of another
  557. braced initializer list; pass "il" for CONV_OP, and NULL for
  558. TYPE). */
  559. GCC_METHOD3 (gcc_expr, build_expression_list_expr,
  560. const char *, /* Argument CONV_OP. */
  561. gcc_type, /* Argument TYPE. */
  562. const struct gcc_cp_function_args *) /* Argument VALUES. */
  563. /* Build a gcc_expr that denotes a new ("nw") or new[] ("na")
  564. expression of TYPE, with or without a GLOBAL_NS qualifier (prefix
  565. the NEW_OP with "gs"), with or without PLACEMENT, with or without
  566. INITIALIZER. If it's not a placement new, PLACEMENT must be NULL
  567. (rather than a zero-length placement arg list). If there's no
  568. specified initializer, INITIALIZER must be NULL; a zero-length arg
  569. list stands for a default initializer. */
  570. GCC_METHOD4 (gcc_expr, build_new_expr,
  571. const char *, /* Argument NEW_OP. */
  572. const struct gcc_cp_function_args *, /* Argument PLACEMENT. */
  573. gcc_type, /* Argument TYPE. */
  574. const struct gcc_cp_function_args *) /* Argument INITIALIZER. */
  575. /* Return a call expression that calls CALLABLE with arguments ARGS.
  576. CALLABLE may be a function, a callable object, a pointer to
  577. function, an unresolved expression, an unresolved overload set, an
  578. object expression combined with a member function overload set or a
  579. pointer-to-member. If QUALIFIED_P, CALLABLE will be interpreted as
  580. a qualified name, preventing virtual function dispatch. */
  581. GCC_METHOD3 (gcc_expr, build_call_expr,
  582. gcc_expr, /* Argument CALLABLE. */
  583. int /* bool */, /* Argument QUALIFIED_P. */
  584. const struct gcc_cp_function_args *) /* Argument ARGS. */
  585. /* Return the type of the gcc_expr OPERAND.
  586. Use this for decltype.
  587. For decltype (auto), pass a NULL OPERAND.
  588. Note: for template-dependent expressions, the result is NULL,
  589. because the type is only computed when template argument
  590. substitution is performed. */
  591. GCC_METHOD1 (gcc_type, get_expr_type,
  592. gcc_expr) /* Argument OPERAND. */
  593. /* Introduce a specialization of a template function.
  594. TEMPLATE_DECL is the template function, and TARGS are the arguments
  595. for the specialization. ADDRESS is the address of the
  596. specialization. FILENAME and LINE_NUMBER specify the source
  597. location associated with the template function specialization. */
  598. GCC_METHOD5 (gcc_decl, build_function_template_specialization,
  599. gcc_decl, /* Argument TEMPLATE_DECL. */
  600. const struct gcc_cp_template_args *, /* Argument TARGS. */
  601. gcc_address, /* Argument ADDRESS. */
  602. const char *, /* Argument FILENAME. */
  603. unsigned int) /* Argument LINE_NUMBER. */
  604. /* Specialize a template class as an incomplete type. A definition
  605. can be supplied later, with start_class_type.
  606. TEMPLATE_DECL is the template class, and TARGS are the arguments
  607. for the specialization. FILENAME and LINE_NUMBER specify the
  608. source location associated with the template class
  609. specialization. */
  610. GCC_METHOD4 (gcc_decl, build_class_template_specialization,
  611. gcc_decl, /* Argument TEMPLATE_DECL. */
  612. const struct gcc_cp_template_args *, /* Argument TARGS. */
  613. const char *, /* Argument FILENAME. */
  614. unsigned int) /* Argument LINE_NUMBER. */
  615. /* Start defining a 'class', 'struct' or 'union' type, entering its
  616. own binding level. Initially it has no fields.
  617. TYPEDECL is the forward-declaration of the type, returned by
  618. build_decl. BASE_CLASSES indicate the base classes of class NAME.
  619. FILENAME and LINE_NUMBER specify the source location associated
  620. with the class definition, should they be different from those of
  621. the forward declaration. */
  622. GCC_METHOD4 (gcc_type, start_class_type,
  623. gcc_decl, /* Argument TYPEDECL. */
  624. const struct gcc_vbase_array *,/* Argument BASE_CLASSES. */
  625. const char *, /* Argument FILENAME. */
  626. unsigned int) /* Argument LINE_NUMBER. */
  627. /* Create a new closure class type, record it as the
  628. DISCRIMINATOR-numbered closure type in the current scope (or
  629. associated with EXTRA_SCOPE, if non-NULL), and enter the closure
  630. type's own binding level. This primitive would sort of combine
  631. build_decl and start_class_type, if they could be used to introduce
  632. a closure type. Initially it has no fields.
  633. FILENAME and LINE_NUMBER specify the source location associated
  634. with the class. EXTRA_SCOPE, if non-NULL, must be a PARM_DECL of
  635. the current function, or a FIELD_DECL of the current class. If it
  636. is NULL, the current scope must be a function. */
  637. GCC_METHOD5 (gcc_type, start_closure_class_type,
  638. int, /* Argument DISCRIMINATOR. */
  639. gcc_decl, /* Argument EXTRA_SCOPE. */
  640. enum gcc_cp_symbol_kind, /* Argument FLAGS. */
  641. const char *, /* Argument FILENAME. */
  642. unsigned int) /* Argument LINE_NUMBER. */
  643. /* Add a non-static data member to the most-recently-started
  644. unfinished struct or union type. FIELD_NAME is the field's name.
  645. FIELD_TYPE is the type of the field. BITSIZE and BITPOS indicate
  646. where in the struct the field occurs. */
  647. GCC_METHOD5 (gcc_decl, build_field,
  648. const char *, /* Argument FIELD_NAME. */
  649. gcc_type, /* Argument FIELD_TYPE. */
  650. enum gcc_cp_symbol_kind, /* Argument FIELD_FLAGS. */
  651. unsigned long, /* Argument BITSIZE. */
  652. unsigned long) /* Argument BITPOS. */
  653. /* After all the fields have been added to a struct, class or union,
  654. the struct or union type must be "finished". This does some final
  655. cleanups in GCC, and pops to the binding level that was in effect
  656. before the matching start_class_type or
  657. start_closure_class_type. */
  658. GCC_METHOD1 (int /* bool */, finish_class_type,
  659. unsigned long) /* Argument SIZE_IN_BYTES. */
  660. /* Create a new 'enum' type, and record it in the current binding
  661. level. The new type initially has no associated constants.
  662. NAME is the enum name. FILENAME and LINE_NUMBER specify its source
  663. location. */
  664. GCC_METHOD5 (gcc_type, start_enum_type,
  665. const char *, /* Argument NAME. */
  666. gcc_type, /* Argument UNDERLYING_INT_TYPE. */
  667. enum gcc_cp_symbol_kind, /* Argument FLAGS. */
  668. const char *, /* Argument FILENAME. */
  669. unsigned int) /* Argument LINE_NUMBER. */
  670. /* Add a new constant to an enum type. NAME is the constant's name
  671. and VALUE is its value. Returns a gcc_decl for the constant. */
  672. GCC_METHOD3 (gcc_decl, build_enum_constant,
  673. gcc_type, /* Argument ENUM_TYPE. */
  674. const char *, /* Argument NAME. */
  675. unsigned long) /* Argument VALUE. */
  676. /* After all the constants have been added to an enum, the type must
  677. be "finished". This does some final cleanups in GCC. */
  678. GCC_METHOD1 (int /* bool */, finish_enum_type,
  679. gcc_type) /* Argument ENUM_TYPE. */
  680. /* Create a new function type. RETURN_TYPE is the type returned by
  681. the function, and ARGUMENT_TYPES is a vector, of length NARGS, of
  682. the argument types. IS_VARARGS is true if the function is
  683. varargs. */
  684. GCC_METHOD3 (gcc_type, build_function_type,
  685. gcc_type, /* Argument RETURN_TYPE. */
  686. const struct gcc_type_array *,/* Argument ARGUMENT_TYPES. */
  687. int /* bool */) /* Argument IS_VARARGS. */
  688. /* Create a variant of a function type with an exception
  689. specification. FUNCTION_TYPE is a function or method type.
  690. EXCEPT_TYPES is an array with the list of exception types. Zero as
  691. the array length implies throw() AKA noexcept(true); NULL as the
  692. pointer to gcc_type_array implies noexcept(false), which is almost
  693. equivalent (but distinguishable by the compiler) to an unspecified
  694. exception list. */
  695. GCC_METHOD2 (gcc_type, build_exception_spec_variant,
  696. gcc_type, /* Argument FUNCTION_TYPE. */
  697. const struct gcc_type_array *)/* Argument EXCEPT_TYPES. */
  698. /* Create a new non-static member function type. FUNC_TYPE is the
  699. method prototype, without the implicit THIS pointer, added as a
  700. pointer to the QUALS-qualified CLASS_TYPE. If CLASS_TYPE is NULL,
  701. this creates a cv-qualified (member) function type not associated
  702. with any specific class, as needed to support "typedef void f(int)
  703. const;", which can later be used to declare member functions and
  704. pointers to member functions. */
  705. GCC_METHOD4 (gcc_type, build_method_type,
  706. gcc_type, /* Argument CLASS_TYPE. */
  707. gcc_type, /* Argument FUNC_TYPE. */
  708. enum gcc_cp_qualifiers, /* Argument QUALS. */
  709. enum gcc_cp_ref_qualifiers) /* Argument RQUALS. */
  710. /* Return a declaration for the (INDEX - 1)th argument of
  711. FUNCTION_DECL, i.e., for the first argument, use zero as the index.
  712. If FUNCTION_DECL is a non-static member function, use -1 to get the
  713. implicit THIS parameter. */
  714. GCC_METHOD2 (gcc_decl, get_function_parameter_decl,
  715. gcc_decl, /* Argument FUNCTION_DECL. */
  716. int) /* Argument INDEX. */
  717. /* Return a lambda expr that constructs an instance of CLOSURE_TYPE.
  718. Only lambda exprs without any captures can be correctly created
  719. through these mechanisms; that's all we need to support lambdas
  720. expressions in default parameters, the only kind that may have to
  721. be introduced through this interface. */
  722. GCC_METHOD1 (gcc_expr, build_lambda_expr,
  723. gcc_type) /* Argument CLOSURE_TYPE. */
  724. /* Return an integer type with the given properties. If BUILTIN_NAME
  725. is non-NULL, it must name a builtin integral type with the given
  726. signedness and size, and that is the type that will be returned. */
  727. GCC_METHOD3 (gcc_type, get_int_type,
  728. int /* bool */, /* Argument IS_UNSIGNED. */
  729. unsigned long, /* Argument SIZE_IN_BYTES. */
  730. const char *) /* Argument BUILTIN_NAME. */
  731. /* Return the 'char' type, a distinct type from both 'signed char' and
  732. 'unsigned char' returned by int_type. */
  733. GCC_METHOD0 (gcc_type, get_char_type)
  734. /* Return a floating point type with the given properties. If BUILTIN_NAME
  735. is non-NULL, it must name a builtin integral type with the given
  736. signedness and size, and that is the type that will be returned. */
  737. GCC_METHOD2 (gcc_type, get_float_type,
  738. unsigned long, /* Argument SIZE_IN_BYTES. */
  739. const char *) /* Argument BUILTIN_NAME. */
  740. /* Return the 'void' type. */
  741. GCC_METHOD0 (gcc_type, get_void_type)
  742. /* Return the 'bool' type. */
  743. GCC_METHOD0 (gcc_type, get_bool_type)
  744. /* Return the std::nullptr_t type. */
  745. GCC_METHOD0 (gcc_type, get_nullptr_type)
  746. /* Return the nullptr constant. */
  747. GCC_METHOD0 (gcc_expr, get_nullptr_constant)
  748. /* Create a new array type. If NUM_ELEMENTS is -1, then the array
  749. is assumed to have an unknown length. */
  750. GCC_METHOD2 (gcc_type, build_array_type,
  751. gcc_type, /* Argument ELEMENT_TYPE. */
  752. int) /* Argument NUM_ELEMENTS. */
  753. /* Create a new array type. NUM_ELEMENTS is a template-dependent
  754. expression. */
  755. GCC_METHOD2 (gcc_type, build_dependent_array_type,
  756. gcc_type, /* Argument ELEMENT_TYPE. */
  757. gcc_expr) /* Argument NUM_ELEMENTS. */
  758. /* Create a new variably-sized array type. UPPER_BOUND_NAME is the
  759. name of a local variable that holds the upper bound of the array;
  760. it is one less than the array size. */
  761. GCC_METHOD2 (gcc_type, build_vla_array_type,
  762. gcc_type, /* Argument ELEMENT_TYPE. */
  763. const char *) /* Argument UPPER_BOUND_NAME. */
  764. /* Return a qualified variant of a given base type. QUALIFIERS says
  765. which qualifiers to use; it is composed of or'd together
  766. constants from 'enum gcc_cp_qualifiers'. */
  767. GCC_METHOD2 (gcc_type, build_qualified_type,
  768. gcc_type, /* Argument UNQUALIFIED_TYPE. */
  769. enum gcc_cp_qualifiers) /* Argument QUALIFIERS. */
  770. /* Build a complex type given its element type. */
  771. GCC_METHOD1 (gcc_type, build_complex_type,
  772. gcc_type) /* Argument ELEMENT_TYPE. */
  773. /* Build a vector type given its element type and number of
  774. elements. */
  775. GCC_METHOD2 (gcc_type, build_vector_type,
  776. gcc_type, /* Argument ELEMENT_TYPE. */
  777. int) /* Argument NUM_ELEMENTS. */
  778. /* Build a constant. NAME is the constant's name and VALUE is its
  779. value. FILENAME and LINE_NUMBER refer to the type's source
  780. location. If this is not known, FILENAME can be NULL and
  781. LINE_NUMBER can be 0. */
  782. GCC_METHOD5 (int /* bool */, build_constant,
  783. gcc_type, /* Argument TYPE. */
  784. const char *, /* Argument NAME. */
  785. unsigned long, /* Argument VALUE. */
  786. const char *, /* Argument FILENAME. */
  787. unsigned int) /* Argument LINE_NUMBER. */
  788. /* Emit an error and return an error type object. */
  789. GCC_METHOD1 (gcc_type, error,
  790. const char *) /* Argument MESSAGE. */
  791. /* Declare a static_assert with the given CONDITION and ERRORMSG at
  792. FILENAME:LINE_NUMBER. */
  793. GCC_METHOD4 (int /* bool */, add_static_assert,
  794. gcc_expr, /* Argument CONDITION. */
  795. const char *, /* Argument ERRORMSG. */
  796. const char *, /* Argument FILENAME. */
  797. unsigned int) /* Argument LINE_NUMBER. */
  798. #if 0
  799. /* FIXME: We don't want to expose the internal implementation detail
  800. that default parms are stored in function types, and it's not clear
  801. how this or other approaches would interact with the type sharing
  802. of e.g. ctor clones, so we're leaving this out, since default args
  803. are not even present in debug information anyway. Besides, the set
  804. of default args for a function may grow within its scope, and vary
  805. independently in other scopes. */
  806. /* Create a modified version of a function type that has default
  807. values for some of its arguments. The returned type should ONLY be
  808. used to define functions or methods, never to declare parameters,
  809. variables, types or the like.
  810. DEFAULTS must have at most as many N_ELEMENTS as there are
  811. arguments without default values in FUNCTION_TYPE. Say, if
  812. FUNCTION_TYPE has an argument list such as (T1, T2, T3, T4 = V0)
  813. and DEFAULTS has 2 elements (V1, V2), the returned type will have
  814. the following argument list: (T1, T2 = V1, T3 = V2, T4 = V0).
  815. Any NULL expressions in DEFAULTS will be marked as deferred, and
  816. they should be filled in with set_deferred_function_default_args. */
  817. GCC_METHOD2 (gcc_type, add_function_default_args,
  818. gcc_type, /* Argument FUNCTION_TYPE. */
  819. const struct gcc_cp_function_args *) /* Argument DEFAULTS. */
  820. /* Fill in the first deferred default args in FUNCTION_DECL with the
  821. expressions given in DEFAULTS. This can be used when the
  822. declaration of a parameter is needed to create a default
  823. expression, such as taking the size of an earlier parameter, or
  824. building a lambda expression in the parameter's context. */
  825. GCC_METHOD2 (int /* bool */, set_deferred_function_default_args,
  826. gcc_decl, /* Argument FUNCTION_DECL. */
  827. const struct gcc_cp_function_args *) /* Argument DEFAULTS. */
  828. #endif
  829. /* When you add entry points, add them at the end, so that the new API
  830. version remains compatible with the old version.
  831. The following conventions have been observed as to naming entry points:
  832. - build_* creates (and maybe records) something and returns it;
  833. - add_* creates and records something, but doesn't return it;
  834. - get_* obtains something without creating it;
  835. - start_* marks the beginning of a compound (type, list, ...);
  836. - finish_* completes the compound when needed.
  837. Entry points that return an int (bool) and don't have a return value
  838. specification return nonzero (true) on success and zero (false) on
  839. failure. This is in line with libcc1's conventions of returning a
  840. zero-initialized value in case of e.g. a transport error. */