expop.h 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212
  1. /* Definitions for expressions in GDB
  2. Copyright (C) 2020-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  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. #ifndef EXPOP_H
  15. #define EXPOP_H
  16. #include "block.h"
  17. #include "c-lang.h"
  18. #include "cp-abi.h"
  19. #include "expression.h"
  20. #include "objfiles.h"
  21. #include "gdbsupport/traits.h"
  22. #include "gdbsupport/enum-flags.h"
  23. struct agent_expr;
  24. struct axs_value;
  25. extern void gen_expr_binop (struct expression *exp,
  26. enum exp_opcode op,
  27. expr::operation *lhs, expr::operation *rhs,
  28. struct agent_expr *ax, struct axs_value *value);
  29. extern void gen_expr_structop (struct expression *exp,
  30. enum exp_opcode op,
  31. expr::operation *lhs,
  32. const char *name,
  33. struct agent_expr *ax, struct axs_value *value);
  34. extern void gen_expr_unop (struct expression *exp,
  35. enum exp_opcode op,
  36. expr::operation *lhs,
  37. struct agent_expr *ax, struct axs_value *value);
  38. extern struct value *eval_op_scope (struct type *expect_type,
  39. struct expression *exp,
  40. enum noside noside,
  41. struct type *type, const char *string);
  42. extern struct value *eval_op_var_msym_value (struct type *expect_type,
  43. struct expression *exp,
  44. enum noside noside,
  45. bool outermost_p,
  46. bound_minimal_symbol msymbol);
  47. extern struct value *eval_op_var_entry_value (struct type *expect_type,
  48. struct expression *exp,
  49. enum noside noside, symbol *sym);
  50. extern struct value *eval_op_func_static_var (struct type *expect_type,
  51. struct expression *exp,
  52. enum noside noside,
  53. value *func, const char *var);
  54. extern struct value *eval_op_register (struct type *expect_type,
  55. struct expression *exp,
  56. enum noside noside, const char *name);
  57. extern struct value *eval_op_ternop (struct type *expect_type,
  58. struct expression *exp,
  59. enum noside noside,
  60. struct value *array, struct value *low,
  61. struct value *upper);
  62. extern struct value *eval_op_structop_struct (struct type *expect_type,
  63. struct expression *exp,
  64. enum noside noside,
  65. struct value *arg1,
  66. const char *string);
  67. extern struct value *eval_op_structop_ptr (struct type *expect_type,
  68. struct expression *exp,
  69. enum noside noside,
  70. struct value *arg1,
  71. const char *string);
  72. extern struct value *eval_op_member (struct type *expect_type,
  73. struct expression *exp,
  74. enum noside noside,
  75. struct value *arg1, struct value *arg2);
  76. extern struct value *eval_op_add (struct type *expect_type,
  77. struct expression *exp,
  78. enum noside noside,
  79. struct value *arg1, struct value *arg2);
  80. extern struct value *eval_op_sub (struct type *expect_type,
  81. struct expression *exp,
  82. enum noside noside,
  83. struct value *arg1, struct value *arg2);
  84. extern struct value *eval_op_binary (struct type *expect_type,
  85. struct expression *exp,
  86. enum noside noside, enum exp_opcode op,
  87. struct value *arg1, struct value *arg2);
  88. extern struct value *eval_op_subscript (struct type *expect_type,
  89. struct expression *exp,
  90. enum noside noside, enum exp_opcode op,
  91. struct value *arg1,
  92. struct value *arg2);
  93. extern struct value *eval_op_equal (struct type *expect_type,
  94. struct expression *exp,
  95. enum noside noside, enum exp_opcode op,
  96. struct value *arg1,
  97. struct value *arg2);
  98. extern struct value *eval_op_notequal (struct type *expect_type,
  99. struct expression *exp,
  100. enum noside noside, enum exp_opcode op,
  101. struct value *arg1,
  102. struct value *arg2);
  103. extern struct value *eval_op_less (struct type *expect_type,
  104. struct expression *exp,
  105. enum noside noside, enum exp_opcode op,
  106. struct value *arg1,
  107. struct value *arg2);
  108. extern struct value *eval_op_gtr (struct type *expect_type,
  109. struct expression *exp,
  110. enum noside noside, enum exp_opcode op,
  111. struct value *arg1,
  112. struct value *arg2);
  113. extern struct value *eval_op_geq (struct type *expect_type,
  114. struct expression *exp,
  115. enum noside noside, enum exp_opcode op,
  116. struct value *arg1,
  117. struct value *arg2);
  118. extern struct value *eval_op_leq (struct type *expect_type,
  119. struct expression *exp,
  120. enum noside noside, enum exp_opcode op,
  121. struct value *arg1,
  122. struct value *arg2);
  123. extern struct value *eval_op_repeat (struct type *expect_type,
  124. struct expression *exp,
  125. enum noside noside, enum exp_opcode op,
  126. struct value *arg1,
  127. struct value *arg2);
  128. extern struct value *eval_op_plus (struct type *expect_type,
  129. struct expression *exp,
  130. enum noside noside, enum exp_opcode op,
  131. struct value *arg1);
  132. extern struct value *eval_op_neg (struct type *expect_type,
  133. struct expression *exp,
  134. enum noside noside, enum exp_opcode op,
  135. struct value *arg1);
  136. extern struct value *eval_op_complement (struct type *expect_type,
  137. struct expression *exp,
  138. enum noside noside,
  139. enum exp_opcode op,
  140. struct value *arg1);
  141. extern struct value *eval_op_lognot (struct type *expect_type,
  142. struct expression *exp,
  143. enum noside noside,
  144. enum exp_opcode op,
  145. struct value *arg1);
  146. extern struct value *eval_op_preinc (struct type *expect_type,
  147. struct expression *exp,
  148. enum noside noside,
  149. enum exp_opcode op,
  150. struct value *arg1);
  151. extern struct value *eval_op_predec (struct type *expect_type,
  152. struct expression *exp,
  153. enum noside noside,
  154. enum exp_opcode op,
  155. struct value *arg1);
  156. extern struct value *eval_op_postinc (struct type *expect_type,
  157. struct expression *exp,
  158. enum noside noside,
  159. enum exp_opcode op,
  160. struct value *arg1);
  161. extern struct value *eval_op_postdec (struct type *expect_type,
  162. struct expression *exp,
  163. enum noside noside,
  164. enum exp_opcode op,
  165. struct value *arg1);
  166. extern struct value *eval_op_ind (struct type *expect_type,
  167. struct expression *exp,
  168. enum noside noside,
  169. struct value *arg1);
  170. extern struct value *eval_op_type (struct type *expect_type,
  171. struct expression *exp,
  172. enum noside noside, struct type *type);
  173. extern struct value *eval_op_alignof (struct type *expect_type,
  174. struct expression *exp,
  175. enum noside noside,
  176. struct value *arg1);
  177. extern struct value *eval_op_memval (struct type *expect_type,
  178. struct expression *exp,
  179. enum noside noside,
  180. struct value *arg1, struct type *type);
  181. extern struct value *eval_binop_assign_modify (struct type *expect_type,
  182. struct expression *exp,
  183. enum noside noside,
  184. enum exp_opcode op,
  185. struct value *arg1,
  186. struct value *arg2);
  187. namespace expr
  188. {
  189. class ada_component;
  190. /* The check_objfile overloads are used to check whether a particular
  191. component of some operation references an objfile. The passed-in
  192. objfile will never be a debug objfile. */
  193. /* See if EXP_OBJFILE matches OBJFILE. */
  194. static inline bool
  195. check_objfile (struct objfile *exp_objfile, struct objfile *objfile)
  196. {
  197. if (exp_objfile->separate_debug_objfile_backlink)
  198. exp_objfile = exp_objfile->separate_debug_objfile_backlink;
  199. return exp_objfile == objfile;
  200. }
  201. static inline bool
  202. check_objfile (struct type *type, struct objfile *objfile)
  203. {
  204. struct objfile *ty_objfile = type->objfile_owner ();
  205. if (ty_objfile != nullptr)
  206. return check_objfile (ty_objfile, objfile);
  207. return false;
  208. }
  209. static inline bool
  210. check_objfile (struct symbol *sym, struct objfile *objfile)
  211. {
  212. return check_objfile (symbol_objfile (sym), objfile);
  213. }
  214. static inline bool
  215. check_objfile (const struct block *block, struct objfile *objfile)
  216. {
  217. return check_objfile (block_objfile (block), objfile);
  218. }
  219. static inline bool
  220. check_objfile (const block_symbol &sym, struct objfile *objfile)
  221. {
  222. return (check_objfile (sym.symbol, objfile)
  223. || check_objfile (sym.block, objfile));
  224. }
  225. static inline bool
  226. check_objfile (bound_minimal_symbol minsym, struct objfile *objfile)
  227. {
  228. return check_objfile (minsym.objfile, objfile);
  229. }
  230. static inline bool
  231. check_objfile (internalvar *ivar, struct objfile *objfile)
  232. {
  233. return false;
  234. }
  235. static inline bool
  236. check_objfile (const std::string &str, struct objfile *objfile)
  237. {
  238. return false;
  239. }
  240. static inline bool
  241. check_objfile (const operation_up &op, struct objfile *objfile)
  242. {
  243. return op->uses_objfile (objfile);
  244. }
  245. static inline bool
  246. check_objfile (enum exp_opcode val, struct objfile *objfile)
  247. {
  248. return false;
  249. }
  250. static inline bool
  251. check_objfile (ULONGEST val, struct objfile *objfile)
  252. {
  253. return false;
  254. }
  255. template<typename T>
  256. static inline bool
  257. check_objfile (enum_flags<T> val, struct objfile *objfile)
  258. {
  259. return false;
  260. }
  261. template<typename T>
  262. static inline bool
  263. check_objfile (const std::vector<T> &collection, struct objfile *objfile)
  264. {
  265. for (const auto &item : collection)
  266. {
  267. if (check_objfile (item, objfile))
  268. return true;
  269. }
  270. return false;
  271. }
  272. template<typename S, typename T>
  273. static inline bool
  274. check_objfile (const std::pair<S, T> &item, struct objfile *objfile)
  275. {
  276. return (check_objfile (item.first, objfile)
  277. || check_objfile (item.second, objfile));
  278. }
  279. extern bool check_objfile (const std::unique_ptr<ada_component> &comp,
  280. struct objfile *objfile);
  281. static inline void
  282. dump_for_expression (struct ui_file *stream, int depth,
  283. const operation_up &op)
  284. {
  285. op->dump (stream, depth);
  286. }
  287. extern void dump_for_expression (struct ui_file *stream, int depth,
  288. enum exp_opcode op);
  289. extern void dump_for_expression (struct ui_file *stream, int depth,
  290. const std::string &str);
  291. extern void dump_for_expression (struct ui_file *stream, int depth,
  292. struct type *type);
  293. extern void dump_for_expression (struct ui_file *stream, int depth,
  294. CORE_ADDR addr);
  295. extern void dump_for_expression (struct ui_file *stream, int depth,
  296. internalvar *ivar);
  297. extern void dump_for_expression (struct ui_file *stream, int depth,
  298. symbol *sym);
  299. extern void dump_for_expression (struct ui_file *stream, int depth,
  300. const block_symbol &sym);
  301. extern void dump_for_expression (struct ui_file *stream, int depth,
  302. bound_minimal_symbol msym);
  303. extern void dump_for_expression (struct ui_file *stream, int depth,
  304. const block *bl);
  305. extern void dump_for_expression (struct ui_file *stream, int depth,
  306. type_instance_flags flags);
  307. extern void dump_for_expression (struct ui_file *stream, int depth,
  308. enum c_string_type_values flags);
  309. extern void dump_for_expression (struct ui_file *stream, int depth,
  310. enum range_flag flags);
  311. extern void dump_for_expression (struct ui_file *stream, int depth,
  312. const std::unique_ptr<ada_component> &comp);
  313. template<typename T>
  314. void
  315. dump_for_expression (struct ui_file *stream, int depth,
  316. const std::vector<T> &vals)
  317. {
  318. gdb_printf (stream, _("%*sVector:\n"), depth, "");
  319. for (auto &item : vals)
  320. dump_for_expression (stream, depth + 1, item);
  321. }
  322. template<typename X, typename Y>
  323. void
  324. dump_for_expression (struct ui_file *stream, int depth,
  325. const std::pair<X, Y> &vals)
  326. {
  327. dump_for_expression (stream, depth, vals.first);
  328. dump_for_expression (stream, depth, vals.second);
  329. }
  330. /* Base class for most concrete operations. This class holds data,
  331. specified via template parameters, and supplies generic
  332. implementations of the 'dump' and 'uses_objfile' methods. */
  333. template<typename... Arg>
  334. class tuple_holding_operation : public operation
  335. {
  336. public:
  337. explicit tuple_holding_operation (Arg... args)
  338. : m_storage (std::forward<Arg> (args)...)
  339. {
  340. }
  341. DISABLE_COPY_AND_ASSIGN (tuple_holding_operation);
  342. bool uses_objfile (struct objfile *objfile) const override
  343. {
  344. return do_check_objfile<0, Arg...> (objfile, m_storage);
  345. }
  346. void dump (struct ui_file *stream, int depth) const override
  347. {
  348. dump_for_expression (stream, depth, opcode ());
  349. do_dump<0, Arg...> (stream, depth + 1, m_storage);
  350. }
  351. protected:
  352. /* Storage for the data. */
  353. std::tuple<Arg...> m_storage;
  354. private:
  355. /* do_dump does the work of dumping the data. */
  356. template<int I, typename... T>
  357. typename std::enable_if<I == sizeof... (T), void>::type
  358. do_dump (struct ui_file *stream, int depth, const std::tuple<T...> &value)
  359. const
  360. {
  361. }
  362. template<int I, typename... T>
  363. typename std::enable_if<I < sizeof... (T), void>::type
  364. do_dump (struct ui_file *stream, int depth, const std::tuple<T...> &value)
  365. const
  366. {
  367. dump_for_expression (stream, depth, std::get<I> (value));
  368. do_dump<I + 1, T...> (stream, depth, value);
  369. }
  370. /* do_check_objfile does the work of checking whether this object
  371. refers to OBJFILE. */
  372. template<int I, typename... T>
  373. typename std::enable_if<I == sizeof... (T), bool>::type
  374. do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
  375. const
  376. {
  377. return false;
  378. }
  379. template<int I, typename... T>
  380. typename std::enable_if<I < sizeof... (T), bool>::type
  381. do_check_objfile (struct objfile *objfile, const std::tuple<T...> &value)
  382. const
  383. {
  384. if (check_objfile (std::get<I> (value), objfile))
  385. return true;
  386. return do_check_objfile<I + 1, T...> (objfile, value);
  387. }
  388. };
  389. /* The check_constant overloads are used to decide whether a given
  390. concrete operation is a constant. This is done by checking the
  391. operands. */
  392. static inline bool
  393. check_constant (const operation_up &item)
  394. {
  395. return item->constant_p ();
  396. }
  397. static inline bool
  398. check_constant (bound_minimal_symbol msym)
  399. {
  400. return false;
  401. }
  402. static inline bool
  403. check_constant (struct type *type)
  404. {
  405. return true;
  406. }
  407. static inline bool
  408. check_constant (const struct block *block)
  409. {
  410. return true;
  411. }
  412. static inline bool
  413. check_constant (const std::string &str)
  414. {
  415. return true;
  416. }
  417. static inline bool
  418. check_constant (ULONGEST cst)
  419. {
  420. return true;
  421. }
  422. static inline bool
  423. check_constant (struct symbol *sym)
  424. {
  425. enum address_class sc = sym->aclass ();
  426. return (sc == LOC_BLOCK
  427. || sc == LOC_CONST
  428. || sc == LOC_CONST_BYTES
  429. || sc == LOC_LABEL);
  430. }
  431. static inline bool
  432. check_constant (const block_symbol &sym)
  433. {
  434. /* We know the block is constant, so we only need to check the
  435. symbol. */
  436. return check_constant (sym.symbol);
  437. }
  438. template<typename T>
  439. static inline bool
  440. check_constant (const std::vector<T> &collection)
  441. {
  442. for (const auto &item : collection)
  443. if (!check_constant (item))
  444. return false;
  445. return true;
  446. }
  447. template<typename S, typename T>
  448. static inline bool
  449. check_constant (const std::pair<S, T> &item)
  450. {
  451. return check_constant (item.first) && check_constant (item.second);
  452. }
  453. /* Base class for concrete operations. This class supplies an
  454. implementation of 'constant_p' that works by checking the
  455. operands. */
  456. template<typename... Arg>
  457. class maybe_constant_operation
  458. : public tuple_holding_operation<Arg...>
  459. {
  460. public:
  461. using tuple_holding_operation<Arg...>::tuple_holding_operation;
  462. bool constant_p () const override
  463. {
  464. return do_check_constant<0, Arg...> (this->m_storage);
  465. }
  466. private:
  467. template<int I, typename... T>
  468. typename std::enable_if<I == sizeof... (T), bool>::type
  469. do_check_constant (const std::tuple<T...> &value) const
  470. {
  471. return true;
  472. }
  473. template<int I, typename... T>
  474. typename std::enable_if<I < sizeof... (T), bool>::type
  475. do_check_constant (const std::tuple<T...> &value) const
  476. {
  477. if (!check_constant (std::get<I> (value)))
  478. return false;
  479. return do_check_constant<I + 1, T...> (value);
  480. }
  481. };
  482. /* A floating-point constant. The constant is encoded in the target
  483. format. */
  484. typedef std::array<gdb_byte, 16> float_data;
  485. /* An operation that holds a floating-point constant of a given
  486. type.
  487. This does not need the facilities provided by
  488. tuple_holding_operation, so it does not use it. */
  489. class float_const_operation
  490. : public operation
  491. {
  492. public:
  493. float_const_operation (struct type *type, float_data data)
  494. : m_type (type),
  495. m_data (data)
  496. {
  497. }
  498. value *evaluate (struct type *expect_type,
  499. struct expression *exp,
  500. enum noside noside) override
  501. {
  502. return value_from_contents (m_type, m_data.data ());
  503. }
  504. enum exp_opcode opcode () const override
  505. { return OP_FLOAT; }
  506. bool constant_p () const override
  507. { return true; }
  508. void dump (struct ui_file *stream, int depth) const override;
  509. private:
  510. struct type *m_type;
  511. float_data m_data;
  512. };
  513. class scope_operation
  514. : public maybe_constant_operation<struct type *, std::string>
  515. {
  516. public:
  517. using maybe_constant_operation::maybe_constant_operation;
  518. value *evaluate (struct type *expect_type,
  519. struct expression *exp,
  520. enum noside noside) override
  521. {
  522. return eval_op_scope (expect_type, exp, noside,
  523. std::get<0> (m_storage),
  524. std::get<1> (m_storage).c_str ());
  525. }
  526. value *evaluate_for_address (struct expression *exp,
  527. enum noside noside) override;
  528. value *evaluate_funcall (struct type *expect_type,
  529. struct expression *exp,
  530. enum noside noside,
  531. const std::vector<operation_up> &args) override;
  532. enum exp_opcode opcode () const override
  533. { return OP_SCOPE; }
  534. protected:
  535. void do_generate_ax (struct expression *exp,
  536. struct agent_expr *ax,
  537. struct axs_value *value,
  538. struct type *cast_type)
  539. override;
  540. };
  541. /* Compute the value of a variable. */
  542. class var_value_operation
  543. : public maybe_constant_operation<block_symbol>
  544. {
  545. public:
  546. using maybe_constant_operation::maybe_constant_operation;
  547. value *evaluate (struct type *expect_type,
  548. struct expression *exp,
  549. enum noside noside) override;
  550. value *evaluate_with_coercion (struct expression *exp,
  551. enum noside noside) override;
  552. value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
  553. override;
  554. value *evaluate_for_cast (struct type *expect_type,
  555. struct expression *exp,
  556. enum noside noside) override;
  557. value *evaluate_for_address (struct expression *exp, enum noside noside)
  558. override;
  559. value *evaluate_funcall (struct type *expect_type,
  560. struct expression *exp,
  561. enum noside noside,
  562. const std::vector<operation_up> &args) override;
  563. enum exp_opcode opcode () const override
  564. { return OP_VAR_VALUE; }
  565. /* Return the symbol referenced by this object. */
  566. symbol *get_symbol () const
  567. {
  568. return std::get<0> (m_storage).symbol;
  569. }
  570. protected:
  571. void do_generate_ax (struct expression *exp,
  572. struct agent_expr *ax,
  573. struct axs_value *value,
  574. struct type *cast_type)
  575. override;
  576. };
  577. class long_const_operation
  578. : public tuple_holding_operation<struct type *, LONGEST>
  579. {
  580. public:
  581. using tuple_holding_operation::tuple_holding_operation;
  582. value *evaluate (struct type *expect_type,
  583. struct expression *exp,
  584. enum noside noside) override
  585. {
  586. return value_from_longest (std::get<0> (m_storage),
  587. std::get<1> (m_storage));
  588. }
  589. enum exp_opcode opcode () const override
  590. { return OP_LONG; }
  591. bool constant_p () const override
  592. { return true; }
  593. protected:
  594. void do_generate_ax (struct expression *exp,
  595. struct agent_expr *ax,
  596. struct axs_value *value,
  597. struct type *cast_type)
  598. override;
  599. };
  600. class var_msym_value_operation
  601. : public maybe_constant_operation<bound_minimal_symbol>
  602. {
  603. public:
  604. using maybe_constant_operation::maybe_constant_operation;
  605. value *evaluate (struct type *expect_type,
  606. struct expression *exp,
  607. enum noside noside) override
  608. {
  609. return eval_op_var_msym_value (expect_type, exp, noside, m_outermost,
  610. std::get<0> (m_storage));
  611. }
  612. value *evaluate_for_sizeof (struct expression *exp, enum noside noside)
  613. override;
  614. value *evaluate_for_address (struct expression *exp, enum noside noside)
  615. override;
  616. value *evaluate_for_cast (struct type *expect_type,
  617. struct expression *exp,
  618. enum noside noside) override;
  619. value *evaluate_funcall (struct type *expect_type,
  620. struct expression *exp,
  621. enum noside noside,
  622. const std::vector<operation_up> &args) override
  623. {
  624. const char *name = std::get<0> (m_storage).minsym->print_name ();
  625. return operation::evaluate_funcall (expect_type, exp, noside, name, args);
  626. }
  627. enum exp_opcode opcode () const override
  628. { return OP_VAR_MSYM_VALUE; }
  629. void set_outermost () override
  630. {
  631. m_outermost = true;
  632. }
  633. protected:
  634. /* True if this is the outermost operation in the expression. */
  635. bool m_outermost = false;
  636. void do_generate_ax (struct expression *exp,
  637. struct agent_expr *ax,
  638. struct axs_value *value,
  639. struct type *cast_type)
  640. override;
  641. };
  642. class var_entry_value_operation
  643. : public tuple_holding_operation<symbol *>
  644. {
  645. public:
  646. using tuple_holding_operation::tuple_holding_operation;
  647. value *evaluate (struct type *expect_type,
  648. struct expression *exp,
  649. enum noside noside) override
  650. {
  651. return eval_op_var_entry_value (expect_type, exp, noside,
  652. std::get<0> (m_storage));
  653. }
  654. enum exp_opcode opcode () const override
  655. { return OP_VAR_ENTRY_VALUE; }
  656. };
  657. class func_static_var_operation
  658. : public maybe_constant_operation<operation_up, std::string>
  659. {
  660. public:
  661. using maybe_constant_operation::maybe_constant_operation;
  662. value *evaluate (struct type *expect_type,
  663. struct expression *exp,
  664. enum noside noside) override
  665. {
  666. value *func = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  667. return eval_op_func_static_var (expect_type, exp, noside, func,
  668. std::get<1> (m_storage).c_str ());
  669. }
  670. enum exp_opcode opcode () const override
  671. { return OP_FUNC_STATIC_VAR; }
  672. };
  673. class last_operation
  674. : public tuple_holding_operation<int>
  675. {
  676. public:
  677. using tuple_holding_operation::tuple_holding_operation;
  678. value *evaluate (struct type *expect_type,
  679. struct expression *exp,
  680. enum noside noside) override
  681. {
  682. return access_value_history (std::get<0> (m_storage));
  683. }
  684. enum exp_opcode opcode () const override
  685. { return OP_LAST; }
  686. };
  687. class register_operation
  688. : public tuple_holding_operation<std::string>
  689. {
  690. public:
  691. using tuple_holding_operation::tuple_holding_operation;
  692. value *evaluate (struct type *expect_type,
  693. struct expression *exp,
  694. enum noside noside) override
  695. {
  696. return eval_op_register (expect_type, exp, noside,
  697. std::get<0> (m_storage).c_str ());
  698. }
  699. enum exp_opcode opcode () const override
  700. { return OP_REGISTER; }
  701. /* Return the name of the register. */
  702. const char *get_name () const
  703. {
  704. return std::get<0> (m_storage).c_str ();
  705. }
  706. protected:
  707. void do_generate_ax (struct expression *exp,
  708. struct agent_expr *ax,
  709. struct axs_value *value,
  710. struct type *cast_type)
  711. override;
  712. };
  713. class bool_operation
  714. : public tuple_holding_operation<bool>
  715. {
  716. public:
  717. using tuple_holding_operation::tuple_holding_operation;
  718. value *evaluate (struct type *expect_type,
  719. struct expression *exp,
  720. enum noside noside) override
  721. {
  722. struct type *type = language_bool_type (exp->language_defn, exp->gdbarch);
  723. return value_from_longest (type, std::get<0> (m_storage));
  724. }
  725. enum exp_opcode opcode () const override
  726. { return OP_BOOL; }
  727. bool constant_p () const override
  728. { return true; }
  729. };
  730. class internalvar_operation
  731. : public tuple_holding_operation<internalvar *>
  732. {
  733. public:
  734. using tuple_holding_operation::tuple_holding_operation;
  735. value *evaluate (struct type *expect_type,
  736. struct expression *exp,
  737. enum noside noside) override
  738. {
  739. return value_of_internalvar (exp->gdbarch,
  740. std::get<0> (m_storage));
  741. }
  742. internalvar *get_internalvar () const
  743. {
  744. return std::get<0> (m_storage);
  745. }
  746. enum exp_opcode opcode () const override
  747. { return OP_INTERNALVAR; }
  748. protected:
  749. void do_generate_ax (struct expression *exp,
  750. struct agent_expr *ax,
  751. struct axs_value *value,
  752. struct type *cast_type)
  753. override;
  754. };
  755. class string_operation
  756. : public tuple_holding_operation<std::string>
  757. {
  758. public:
  759. using tuple_holding_operation::tuple_holding_operation;
  760. value *evaluate (struct type *expect_type,
  761. struct expression *exp,
  762. enum noside noside) override;
  763. enum exp_opcode opcode () const override
  764. { return OP_STRING; }
  765. };
  766. class ternop_slice_operation
  767. : public maybe_constant_operation<operation_up, operation_up, operation_up>
  768. {
  769. public:
  770. using maybe_constant_operation::maybe_constant_operation;
  771. value *evaluate (struct type *expect_type,
  772. struct expression *exp,
  773. enum noside noside) override
  774. {
  775. struct value *array
  776. = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  777. struct value *low
  778. = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  779. struct value *upper
  780. = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
  781. return eval_op_ternop (expect_type, exp, noside, array, low, upper);
  782. }
  783. enum exp_opcode opcode () const override
  784. { return TERNOP_SLICE; }
  785. };
  786. class ternop_cond_operation
  787. : public maybe_constant_operation<operation_up, operation_up, operation_up>
  788. {
  789. public:
  790. using maybe_constant_operation::maybe_constant_operation;
  791. value *evaluate (struct type *expect_type,
  792. struct expression *exp,
  793. enum noside noside) override
  794. {
  795. struct value *val
  796. = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  797. if (value_logical_not (val))
  798. return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
  799. return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  800. }
  801. enum exp_opcode opcode () const override
  802. { return TERNOP_COND; }
  803. protected:
  804. void do_generate_ax (struct expression *exp,
  805. struct agent_expr *ax,
  806. struct axs_value *value,
  807. struct type *cast_type)
  808. override;
  809. };
  810. class complex_operation
  811. : public maybe_constant_operation<operation_up, operation_up, struct type *>
  812. {
  813. public:
  814. using maybe_constant_operation::maybe_constant_operation;
  815. value *evaluate (struct type *expect_type,
  816. struct expression *exp,
  817. enum noside noside) override
  818. {
  819. value *real = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  820. value *imag = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  821. return value_literal_complex (real, imag,
  822. std::get<2> (m_storage));
  823. }
  824. enum exp_opcode opcode () const override
  825. { return OP_COMPLEX; }
  826. };
  827. class structop_base_operation
  828. : public tuple_holding_operation<operation_up, std::string>
  829. {
  830. public:
  831. /* Used for completion. Return the field name. */
  832. const std::string &get_string () const
  833. {
  834. return std::get<1> (m_storage);
  835. }
  836. value *evaluate_funcall (struct type *expect_type,
  837. struct expression *exp,
  838. enum noside noside,
  839. const std::vector<operation_up> &args) override;
  840. /* Try to complete this operation in the context of EXP. TRACKER is
  841. the completion tracker to update. Return true if completion was
  842. possible, false otherwise. */
  843. virtual bool complete (struct expression *exp, completion_tracker &tracker)
  844. {
  845. return complete (exp, tracker, "");
  846. }
  847. protected:
  848. /* Do the work of the public 'complete' method. PREFIX is prepended
  849. to each result. */
  850. bool complete (struct expression *exp, completion_tracker &tracker,
  851. const char *prefix);
  852. using tuple_holding_operation::tuple_holding_operation;
  853. };
  854. class structop_operation
  855. : public structop_base_operation
  856. {
  857. public:
  858. using structop_base_operation::structop_base_operation;
  859. value *evaluate (struct type *expect_type,
  860. struct expression *exp,
  861. enum noside noside) override
  862. {
  863. value *val =std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  864. return eval_op_structop_struct (expect_type, exp, noside, val,
  865. std::get<1> (m_storage).c_str ());
  866. }
  867. enum exp_opcode opcode () const override
  868. { return STRUCTOP_STRUCT; }
  869. protected:
  870. void do_generate_ax (struct expression *exp,
  871. struct agent_expr *ax,
  872. struct axs_value *value,
  873. struct type *cast_type)
  874. override
  875. {
  876. gen_expr_structop (exp, STRUCTOP_STRUCT,
  877. std::get<0> (this->m_storage).get (),
  878. std::get<1> (this->m_storage).c_str (),
  879. ax, value);
  880. }
  881. };
  882. class structop_ptr_operation
  883. : public structop_base_operation
  884. {
  885. public:
  886. using structop_base_operation::structop_base_operation;
  887. value *evaluate (struct type *expect_type,
  888. struct expression *exp,
  889. enum noside noside) override
  890. {
  891. value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  892. return eval_op_structop_ptr (expect_type, exp, noside, val,
  893. std::get<1> (m_storage).c_str ());
  894. }
  895. enum exp_opcode opcode () const override
  896. { return STRUCTOP_PTR; }
  897. protected:
  898. void do_generate_ax (struct expression *exp,
  899. struct agent_expr *ax,
  900. struct axs_value *value,
  901. struct type *cast_type)
  902. override
  903. {
  904. gen_expr_structop (exp, STRUCTOP_PTR,
  905. std::get<0> (this->m_storage).get (),
  906. std::get<1> (this->m_storage).c_str (),
  907. ax, value);
  908. }
  909. };
  910. class structop_member_base
  911. : public tuple_holding_operation<operation_up, operation_up>
  912. {
  913. public:
  914. using tuple_holding_operation::tuple_holding_operation;
  915. value *evaluate_funcall (struct type *expect_type,
  916. struct expression *exp,
  917. enum noside noside,
  918. const std::vector<operation_up> &args) override;
  919. };
  920. class structop_member_operation
  921. : public structop_member_base
  922. {
  923. public:
  924. using structop_member_base::structop_member_base;
  925. value *evaluate (struct type *expect_type,
  926. struct expression *exp,
  927. enum noside noside) override
  928. {
  929. value *lhs
  930. = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
  931. value *rhs
  932. = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  933. return eval_op_member (expect_type, exp, noside, lhs, rhs);
  934. }
  935. enum exp_opcode opcode () const override
  936. { return STRUCTOP_MEMBER; }
  937. };
  938. class structop_mptr_operation
  939. : public structop_member_base
  940. {
  941. public:
  942. using structop_member_base::structop_member_base;
  943. value *evaluate (struct type *expect_type,
  944. struct expression *exp,
  945. enum noside noside) override
  946. {
  947. value *lhs
  948. = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  949. value *rhs
  950. = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  951. return eval_op_member (expect_type, exp, noside, lhs, rhs);
  952. }
  953. enum exp_opcode opcode () const override
  954. { return STRUCTOP_MPTR; }
  955. };
  956. class concat_operation
  957. : public maybe_constant_operation<operation_up, operation_up>
  958. {
  959. public:
  960. using maybe_constant_operation::maybe_constant_operation;
  961. value *evaluate (struct type *expect_type,
  962. struct expression *exp,
  963. enum noside noside) override
  964. {
  965. value *lhs
  966. = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
  967. value *rhs
  968. = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
  969. return value_concat (lhs, rhs);
  970. }
  971. enum exp_opcode opcode () const override
  972. { return BINOP_CONCAT; }
  973. };
  974. class add_operation
  975. : public maybe_constant_operation<operation_up, operation_up>
  976. {
  977. public:
  978. using maybe_constant_operation::maybe_constant_operation;
  979. value *evaluate (struct type *expect_type,
  980. struct expression *exp,
  981. enum noside noside) override
  982. {
  983. value *lhs
  984. = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
  985. value *rhs
  986. = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
  987. return eval_op_add (expect_type, exp, noside, lhs, rhs);
  988. }
  989. enum exp_opcode opcode () const override
  990. { return BINOP_ADD; }
  991. protected:
  992. void do_generate_ax (struct expression *exp,
  993. struct agent_expr *ax,
  994. struct axs_value *value,
  995. struct type *cast_type)
  996. override
  997. {
  998. gen_expr_binop (exp, BINOP_ADD,
  999. std::get<0> (this->m_storage).get (),
  1000. std::get<1> (this->m_storage).get (),
  1001. ax, value);
  1002. }
  1003. };
  1004. class sub_operation
  1005. : public maybe_constant_operation<operation_up, operation_up>
  1006. {
  1007. public:
  1008. using maybe_constant_operation::maybe_constant_operation;
  1009. value *evaluate (struct type *expect_type,
  1010. struct expression *exp,
  1011. enum noside noside) override
  1012. {
  1013. value *lhs
  1014. = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
  1015. value *rhs
  1016. = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
  1017. return eval_op_sub (expect_type, exp, noside, lhs, rhs);
  1018. }
  1019. enum exp_opcode opcode () const override
  1020. { return BINOP_SUB; }
  1021. protected:
  1022. void do_generate_ax (struct expression *exp,
  1023. struct agent_expr *ax,
  1024. struct axs_value *value,
  1025. struct type *cast_type)
  1026. override
  1027. {
  1028. gen_expr_binop (exp, BINOP_SUB,
  1029. std::get<0> (this->m_storage).get (),
  1030. std::get<1> (this->m_storage).get (),
  1031. ax, value);
  1032. }
  1033. };
  1034. typedef struct value *binary_ftype (struct type *expect_type,
  1035. struct expression *exp,
  1036. enum noside noside, enum exp_opcode op,
  1037. struct value *arg1, struct value *arg2);
  1038. template<enum exp_opcode OP, binary_ftype FUNC>
  1039. class binop_operation
  1040. : public maybe_constant_operation<operation_up, operation_up>
  1041. {
  1042. public:
  1043. using maybe_constant_operation::maybe_constant_operation;
  1044. value *evaluate (struct type *expect_type,
  1045. struct expression *exp,
  1046. enum noside noside) override
  1047. {
  1048. value *lhs
  1049. = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  1050. value *rhs
  1051. = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  1052. return FUNC (expect_type, exp, noside, OP, lhs, rhs);
  1053. }
  1054. enum exp_opcode opcode () const override
  1055. { return OP; }
  1056. };
  1057. template<enum exp_opcode OP, binary_ftype FUNC>
  1058. class usual_ax_binop_operation
  1059. : public binop_operation<OP, FUNC>
  1060. {
  1061. public:
  1062. using binop_operation<OP, FUNC>::binop_operation;
  1063. protected:
  1064. void do_generate_ax (struct expression *exp,
  1065. struct agent_expr *ax,
  1066. struct axs_value *value,
  1067. struct type *cast_type)
  1068. override
  1069. {
  1070. gen_expr_binop (exp, OP,
  1071. std::get<0> (this->m_storage).get (),
  1072. std::get<1> (this->m_storage).get (),
  1073. ax, value);
  1074. }
  1075. };
  1076. using exp_operation = binop_operation<BINOP_EXP, eval_op_binary>;
  1077. using intdiv_operation = binop_operation<BINOP_INTDIV, eval_op_binary>;
  1078. using mod_operation = binop_operation<BINOP_MOD, eval_op_binary>;
  1079. using mul_operation = usual_ax_binop_operation<BINOP_MUL, eval_op_binary>;
  1080. using div_operation = usual_ax_binop_operation<BINOP_DIV, eval_op_binary>;
  1081. using rem_operation = usual_ax_binop_operation<BINOP_REM, eval_op_binary>;
  1082. using lsh_operation = usual_ax_binop_operation<BINOP_LSH, eval_op_binary>;
  1083. using rsh_operation = usual_ax_binop_operation<BINOP_RSH, eval_op_binary>;
  1084. using bitwise_and_operation
  1085. = usual_ax_binop_operation<BINOP_BITWISE_AND, eval_op_binary>;
  1086. using bitwise_ior_operation
  1087. = usual_ax_binop_operation<BINOP_BITWISE_IOR, eval_op_binary>;
  1088. using bitwise_xor_operation
  1089. = usual_ax_binop_operation<BINOP_BITWISE_XOR, eval_op_binary>;
  1090. class subscript_operation
  1091. : public usual_ax_binop_operation<BINOP_SUBSCRIPT, eval_op_subscript>
  1092. {
  1093. public:
  1094. using usual_ax_binop_operation<BINOP_SUBSCRIPT,
  1095. eval_op_subscript>::usual_ax_binop_operation;
  1096. value *evaluate_for_sizeof (struct expression *exp,
  1097. enum noside noside) override;
  1098. };
  1099. /* Implementation of comparison operations. */
  1100. template<enum exp_opcode OP, binary_ftype FUNC>
  1101. class comparison_operation
  1102. : public usual_ax_binop_operation<OP, FUNC>
  1103. {
  1104. public:
  1105. using usual_ax_binop_operation<OP, FUNC>::usual_ax_binop_operation;
  1106. value *evaluate (struct type *expect_type,
  1107. struct expression *exp,
  1108. enum noside noside) override
  1109. {
  1110. value *lhs
  1111. = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside);
  1112. value *rhs
  1113. = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp,
  1114. noside);
  1115. return FUNC (expect_type, exp, noside, OP, lhs, rhs);
  1116. }
  1117. };
  1118. class equal_operation
  1119. : public comparison_operation<BINOP_EQUAL, eval_op_equal>
  1120. {
  1121. public:
  1122. using comparison_operation::comparison_operation;
  1123. operation *get_lhs () const
  1124. {
  1125. return std::get<0> (m_storage).get ();
  1126. }
  1127. operation *get_rhs () const
  1128. {
  1129. return std::get<1> (m_storage).get ();
  1130. }
  1131. };
  1132. using notequal_operation
  1133. = comparison_operation<BINOP_NOTEQUAL, eval_op_notequal>;
  1134. using less_operation = comparison_operation<BINOP_LESS, eval_op_less>;
  1135. using gtr_operation = comparison_operation<BINOP_GTR, eval_op_gtr>;
  1136. using geq_operation = comparison_operation<BINOP_GEQ, eval_op_geq>;
  1137. using leq_operation = comparison_operation<BINOP_LEQ, eval_op_leq>;
  1138. /* Implement the GDB '@' repeat operator. */
  1139. class repeat_operation
  1140. : public binop_operation<BINOP_REPEAT, eval_op_repeat>
  1141. {
  1142. using binop_operation<BINOP_REPEAT, eval_op_repeat>::binop_operation;
  1143. protected:
  1144. void do_generate_ax (struct expression *exp,
  1145. struct agent_expr *ax,
  1146. struct axs_value *value,
  1147. struct type *cast_type)
  1148. override;
  1149. };
  1150. /* C-style comma operator. */
  1151. class comma_operation
  1152. : public maybe_constant_operation<operation_up, operation_up>
  1153. {
  1154. public:
  1155. using maybe_constant_operation::maybe_constant_operation;
  1156. value *evaluate (struct type *expect_type,
  1157. struct expression *exp,
  1158. enum noside noside) override
  1159. {
  1160. /* The left-hand-side is only evaluated for side effects, so don't
  1161. bother in other modes. */
  1162. if (noside == EVAL_NORMAL)
  1163. std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  1164. return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  1165. }
  1166. enum exp_opcode opcode () const override
  1167. { return BINOP_COMMA; }
  1168. protected:
  1169. void do_generate_ax (struct expression *exp,
  1170. struct agent_expr *ax,
  1171. struct axs_value *value,
  1172. struct type *cast_type)
  1173. override;
  1174. };
  1175. typedef struct value *unary_ftype (struct type *expect_type,
  1176. struct expression *exp,
  1177. enum noside noside, enum exp_opcode op,
  1178. struct value *arg1);
  1179. /* Base class for unary operations. */
  1180. template<enum exp_opcode OP, unary_ftype FUNC>
  1181. class unop_operation
  1182. : public maybe_constant_operation<operation_up>
  1183. {
  1184. public:
  1185. using maybe_constant_operation::maybe_constant_operation;
  1186. value *evaluate (struct type *expect_type,
  1187. struct expression *exp,
  1188. enum noside noside) override
  1189. {
  1190. value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  1191. return FUNC (expect_type, exp, noside, OP, val);
  1192. }
  1193. enum exp_opcode opcode () const override
  1194. { return OP; }
  1195. };
  1196. /* Unary operations that can also be turned into agent expressions in
  1197. the "usual" way. */
  1198. template<enum exp_opcode OP, unary_ftype FUNC>
  1199. class usual_ax_unop_operation
  1200. : public unop_operation<OP, FUNC>
  1201. {
  1202. using unop_operation<OP, FUNC>::unop_operation;
  1203. protected:
  1204. void do_generate_ax (struct expression *exp,
  1205. struct agent_expr *ax,
  1206. struct axs_value *value,
  1207. struct type *cast_type)
  1208. override
  1209. {
  1210. gen_expr_unop (exp, OP,
  1211. std::get<0> (this->m_storage).get (),
  1212. ax, value);
  1213. }
  1214. };
  1215. using unary_plus_operation = usual_ax_unop_operation<UNOP_PLUS, eval_op_plus>;
  1216. using unary_neg_operation = usual_ax_unop_operation<UNOP_NEG, eval_op_neg>;
  1217. using unary_complement_operation
  1218. = usual_ax_unop_operation<UNOP_COMPLEMENT, eval_op_complement>;
  1219. using unary_logical_not_operation
  1220. = usual_ax_unop_operation<UNOP_LOGICAL_NOT, eval_op_lognot>;
  1221. /* Handle pre- and post- increment and -decrement. */
  1222. template<enum exp_opcode OP, unary_ftype FUNC>
  1223. class unop_incr_operation
  1224. : public tuple_holding_operation<operation_up>
  1225. {
  1226. public:
  1227. using tuple_holding_operation::tuple_holding_operation;
  1228. value *evaluate (struct type *expect_type,
  1229. struct expression *exp,
  1230. enum noside noside) override
  1231. {
  1232. value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
  1233. return FUNC (expect_type, exp, noside, OP, val);
  1234. }
  1235. enum exp_opcode opcode () const override
  1236. { return OP; }
  1237. };
  1238. using preinc_operation
  1239. = unop_incr_operation<UNOP_PREINCREMENT, eval_op_preinc>;
  1240. using predec_operation
  1241. = unop_incr_operation<UNOP_PREDECREMENT, eval_op_predec>;
  1242. using postinc_operation
  1243. = unop_incr_operation<UNOP_POSTINCREMENT, eval_op_postinc>;
  1244. using postdec_operation
  1245. = unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
  1246. /* Base class for implementations of UNOP_IND. */
  1247. class unop_ind_base_operation
  1248. : public tuple_holding_operation<operation_up>
  1249. {
  1250. public:
  1251. using tuple_holding_operation::tuple_holding_operation;
  1252. value *evaluate (struct type *expect_type,
  1253. struct expression *exp,
  1254. enum noside noside) override
  1255. {
  1256. if (expect_type != nullptr && expect_type->code () == TYPE_CODE_PTR)
  1257. expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
  1258. value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
  1259. return eval_op_ind (expect_type, exp, noside, val);
  1260. }
  1261. value *evaluate_for_address (struct expression *exp,
  1262. enum noside noside) override;
  1263. value *evaluate_for_sizeof (struct expression *exp,
  1264. enum noside noside) override;
  1265. enum exp_opcode opcode () const override
  1266. { return UNOP_IND; }
  1267. };
  1268. /* Ordinary UNOP_IND implementation. */
  1269. class unop_ind_operation
  1270. : public unop_ind_base_operation
  1271. {
  1272. public:
  1273. using unop_ind_base_operation::unop_ind_base_operation;
  1274. protected:
  1275. void do_generate_ax (struct expression *exp,
  1276. struct agent_expr *ax,
  1277. struct axs_value *value,
  1278. struct type *cast_type)
  1279. override
  1280. {
  1281. gen_expr_unop (exp, UNOP_IND,
  1282. std::get<0> (this->m_storage).get (),
  1283. ax, value);
  1284. }
  1285. };
  1286. /* Implement OP_TYPE. */
  1287. class type_operation
  1288. : public tuple_holding_operation<struct type *>
  1289. {
  1290. public:
  1291. using tuple_holding_operation::tuple_holding_operation;
  1292. value *evaluate (struct type *expect_type,
  1293. struct expression *exp,
  1294. enum noside noside) override
  1295. {
  1296. return eval_op_type (expect_type, exp, noside, std::get<0> (m_storage));
  1297. }
  1298. enum exp_opcode opcode () const override
  1299. { return OP_TYPE; }
  1300. bool constant_p () const override
  1301. { return true; }
  1302. };
  1303. /* Implement the "typeof" operation. */
  1304. class typeof_operation
  1305. : public maybe_constant_operation<operation_up>
  1306. {
  1307. public:
  1308. using maybe_constant_operation::maybe_constant_operation;
  1309. value *evaluate (struct type *expect_type,
  1310. struct expression *exp,
  1311. enum noside noside) override
  1312. {
  1313. if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1314. return std::get<0> (m_storage)->evaluate (nullptr, exp,
  1315. EVAL_AVOID_SIDE_EFFECTS);
  1316. else
  1317. error (_("Attempt to use a type as an expression"));
  1318. }
  1319. enum exp_opcode opcode () const override
  1320. { return OP_TYPEOF; }
  1321. };
  1322. /* Implement 'decltype'. */
  1323. class decltype_operation
  1324. : public maybe_constant_operation<operation_up>
  1325. {
  1326. public:
  1327. using maybe_constant_operation::maybe_constant_operation;
  1328. value *evaluate (struct type *expect_type,
  1329. struct expression *exp,
  1330. enum noside noside) override
  1331. {
  1332. if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1333. {
  1334. value *result
  1335. = std::get<0> (m_storage)->evaluate (nullptr, exp,
  1336. EVAL_AVOID_SIDE_EFFECTS);
  1337. enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
  1338. if (sub_op == BINOP_SUBSCRIPT
  1339. || sub_op == STRUCTOP_MEMBER
  1340. || sub_op == STRUCTOP_MPTR
  1341. || sub_op == UNOP_IND
  1342. || sub_op == STRUCTOP_STRUCT
  1343. || sub_op == STRUCTOP_PTR
  1344. || sub_op == OP_SCOPE)
  1345. {
  1346. struct type *type = value_type (result);
  1347. if (!TYPE_IS_REFERENCE (type))
  1348. {
  1349. type = lookup_lvalue_reference_type (type);
  1350. result = allocate_value (type);
  1351. }
  1352. }
  1353. return result;
  1354. }
  1355. else
  1356. error (_("Attempt to use a type as an expression"));
  1357. }
  1358. enum exp_opcode opcode () const override
  1359. { return OP_DECLTYPE; }
  1360. };
  1361. /* Implement 'typeid'. */
  1362. class typeid_operation
  1363. : public tuple_holding_operation<operation_up>
  1364. {
  1365. public:
  1366. using tuple_holding_operation::tuple_holding_operation;
  1367. value *evaluate (struct type *expect_type,
  1368. struct expression *exp,
  1369. enum noside noside) override
  1370. {
  1371. enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
  1372. enum noside sub_noside
  1373. = ((sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
  1374. ? EVAL_AVOID_SIDE_EFFECTS
  1375. : noside);
  1376. value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
  1377. sub_noside);
  1378. if (noside != EVAL_NORMAL)
  1379. return allocate_value (cplus_typeid_type (exp->gdbarch));
  1380. return cplus_typeid (result);
  1381. }
  1382. enum exp_opcode opcode () const override
  1383. { return OP_TYPEID; }
  1384. };
  1385. /* Implement the address-of operation. */
  1386. class unop_addr_operation
  1387. : public maybe_constant_operation<operation_up>
  1388. {
  1389. public:
  1390. using maybe_constant_operation::maybe_constant_operation;
  1391. value *evaluate (struct type *expect_type,
  1392. struct expression *exp,
  1393. enum noside noside) override
  1394. {
  1395. /* C++: check for and handle pointer to members. */
  1396. return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
  1397. }
  1398. enum exp_opcode opcode () const override
  1399. { return UNOP_ADDR; }
  1400. /* Return the subexpression. */
  1401. const operation_up &get_expression () const
  1402. {
  1403. return std::get<0> (m_storage);
  1404. }
  1405. protected:
  1406. void do_generate_ax (struct expression *exp,
  1407. struct agent_expr *ax,
  1408. struct axs_value *value,
  1409. struct type *cast_type)
  1410. override
  1411. {
  1412. gen_expr_unop (exp, UNOP_ADDR,
  1413. std::get<0> (this->m_storage).get (),
  1414. ax, value);
  1415. }
  1416. };
  1417. /* Implement 'sizeof'. */
  1418. class unop_sizeof_operation
  1419. : public maybe_constant_operation<operation_up>
  1420. {
  1421. public:
  1422. using maybe_constant_operation::maybe_constant_operation;
  1423. value *evaluate (struct type *expect_type,
  1424. struct expression *exp,
  1425. enum noside noside) override
  1426. {
  1427. return std::get<0> (m_storage)->evaluate_for_sizeof (exp, noside);
  1428. }
  1429. enum exp_opcode opcode () const override
  1430. { return UNOP_SIZEOF; }
  1431. protected:
  1432. void do_generate_ax (struct expression *exp,
  1433. struct agent_expr *ax,
  1434. struct axs_value *value,
  1435. struct type *cast_type)
  1436. override;
  1437. };
  1438. /* Implement 'alignof'. */
  1439. class unop_alignof_operation
  1440. : public maybe_constant_operation<operation_up>
  1441. {
  1442. public:
  1443. using maybe_constant_operation::maybe_constant_operation;
  1444. value *evaluate (struct type *expect_type,
  1445. struct expression *exp,
  1446. enum noside noside) override
  1447. {
  1448. value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
  1449. EVAL_AVOID_SIDE_EFFECTS);
  1450. return eval_op_alignof (expect_type, exp, noside, val);
  1451. }
  1452. enum exp_opcode opcode () const override
  1453. { return UNOP_ALIGNOF; }
  1454. };
  1455. /* Implement UNOP_MEMVAL. */
  1456. class unop_memval_operation
  1457. : public tuple_holding_operation<operation_up, struct type *>
  1458. {
  1459. public:
  1460. using tuple_holding_operation::tuple_holding_operation;
  1461. value *evaluate (struct type *expect_type,
  1462. struct expression *exp,
  1463. enum noside noside) override
  1464. {
  1465. value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
  1466. return eval_op_memval (expect_type, exp, noside, val,
  1467. std::get<1> (m_storage));
  1468. }
  1469. value *evaluate_for_sizeof (struct expression *exp,
  1470. enum noside noside) override;
  1471. value *evaluate_for_address (struct expression *exp,
  1472. enum noside noside) override;
  1473. enum exp_opcode opcode () const override
  1474. { return UNOP_MEMVAL; }
  1475. /* Return the type referenced by this object. */
  1476. struct type *get_type () const
  1477. {
  1478. return std::get<1> (m_storage);
  1479. }
  1480. protected:
  1481. void do_generate_ax (struct expression *exp,
  1482. struct agent_expr *ax,
  1483. struct axs_value *value,
  1484. struct type *cast_type)
  1485. override;
  1486. };
  1487. /* Implement UNOP_MEMVAL_TYPE. */
  1488. class unop_memval_type_operation
  1489. : public tuple_holding_operation<operation_up, operation_up>
  1490. {
  1491. public:
  1492. using tuple_holding_operation::tuple_holding_operation;
  1493. value *evaluate (struct type *expect_type,
  1494. struct expression *exp,
  1495. enum noside noside) override
  1496. {
  1497. value *typeval
  1498. = std::get<0> (m_storage)->evaluate (expect_type, exp,
  1499. EVAL_AVOID_SIDE_EFFECTS);
  1500. struct type *type = value_type (typeval);
  1501. value *val = std::get<1> (m_storage)->evaluate (expect_type, exp, noside);
  1502. return eval_op_memval (expect_type, exp, noside, val, type);
  1503. }
  1504. value *evaluate_for_sizeof (struct expression *exp,
  1505. enum noside noside) override;
  1506. value *evaluate_for_address (struct expression *exp,
  1507. enum noside noside) override;
  1508. enum exp_opcode opcode () const override
  1509. { return UNOP_MEMVAL_TYPE; }
  1510. protected:
  1511. void do_generate_ax (struct expression *exp,
  1512. struct agent_expr *ax,
  1513. struct axs_value *value,
  1514. struct type *cast_type)
  1515. override;
  1516. };
  1517. /* Implement the 'this' expression. */
  1518. class op_this_operation
  1519. : public tuple_holding_operation<>
  1520. {
  1521. public:
  1522. using tuple_holding_operation::tuple_holding_operation;
  1523. value *evaluate (struct type *expect_type,
  1524. struct expression *exp,
  1525. enum noside noside) override
  1526. {
  1527. return value_of_this (exp->language_defn);
  1528. }
  1529. enum exp_opcode opcode () const override
  1530. { return OP_THIS; }
  1531. protected:
  1532. void do_generate_ax (struct expression *exp,
  1533. struct agent_expr *ax,
  1534. struct axs_value *value,
  1535. struct type *cast_type)
  1536. override;
  1537. };
  1538. /* Implement the "type instance" operation. */
  1539. class type_instance_operation
  1540. : public tuple_holding_operation<type_instance_flags, std::vector<type *>,
  1541. operation_up>
  1542. {
  1543. public:
  1544. using tuple_holding_operation::tuple_holding_operation;
  1545. value *evaluate (struct type *expect_type,
  1546. struct expression *exp,
  1547. enum noside noside) override;
  1548. enum exp_opcode opcode () const override
  1549. { return TYPE_INSTANCE; }
  1550. };
  1551. /* The assignment operator. */
  1552. class assign_operation
  1553. : public tuple_holding_operation<operation_up, operation_up>
  1554. {
  1555. public:
  1556. using tuple_holding_operation::tuple_holding_operation;
  1557. value *evaluate (struct type *expect_type,
  1558. struct expression *exp,
  1559. enum noside noside) override
  1560. {
  1561. value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  1562. /* Special-case assignments where the left-hand-side is a
  1563. convenience variable -- in these, don't bother setting an
  1564. expected type. This avoids a weird case where re-assigning a
  1565. string or array to an internal variable could error with "Too
  1566. many array elements". */
  1567. struct type *xtype = (VALUE_LVAL (lhs) == lval_internalvar
  1568. ? nullptr
  1569. : value_type (lhs));
  1570. value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside);
  1571. if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1572. return lhs;
  1573. if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs))
  1574. return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside);
  1575. else
  1576. return value_assign (lhs, rhs);
  1577. }
  1578. enum exp_opcode opcode () const override
  1579. { return BINOP_ASSIGN; }
  1580. /* Return the left-hand-side of the assignment. */
  1581. operation *get_lhs () const
  1582. {
  1583. return std::get<0> (m_storage).get ();
  1584. }
  1585. protected:
  1586. void do_generate_ax (struct expression *exp,
  1587. struct agent_expr *ax,
  1588. struct axs_value *value,
  1589. struct type *cast_type)
  1590. override;
  1591. };
  1592. /* Assignment with modification, like "+=". */
  1593. class assign_modify_operation
  1594. : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
  1595. {
  1596. public:
  1597. using tuple_holding_operation::tuple_holding_operation;
  1598. value *evaluate (struct type *expect_type,
  1599. struct expression *exp,
  1600. enum noside noside) override
  1601. {
  1602. value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
  1603. value *rhs = std::get<2> (m_storage)->evaluate (expect_type, exp, noside);
  1604. return eval_binop_assign_modify (expect_type, exp, noside,
  1605. std::get<0> (m_storage), lhs, rhs);
  1606. }
  1607. enum exp_opcode opcode () const override
  1608. { return BINOP_ASSIGN_MODIFY; }
  1609. protected:
  1610. void do_generate_ax (struct expression *exp,
  1611. struct agent_expr *ax,
  1612. struct axs_value *value,
  1613. struct type *cast_type)
  1614. override;
  1615. };
  1616. /* Not a cast! Extract a value of a given type from the contents of a
  1617. value. The new value is extracted from the least significant bytes
  1618. of the old value. The new value's type must be no bigger than the
  1619. old values type. */
  1620. class unop_extract_operation
  1621. : public maybe_constant_operation<operation_up, struct type *>
  1622. {
  1623. public:
  1624. using maybe_constant_operation::maybe_constant_operation;
  1625. value *evaluate (struct type *expect_type, struct expression *exp,
  1626. enum noside noside) override;
  1627. enum exp_opcode opcode () const override
  1628. { return UNOP_EXTRACT; }
  1629. /* Return the type referenced by this object. */
  1630. struct type *get_type () const
  1631. {
  1632. return std::get<1> (m_storage);
  1633. }
  1634. protected:
  1635. void do_generate_ax (struct expression *exp,
  1636. struct agent_expr *ax,
  1637. struct axs_value *value,
  1638. struct type *cast_type) override;
  1639. };
  1640. /* A type cast. */
  1641. class unop_cast_operation
  1642. : public maybe_constant_operation<operation_up, struct type *>
  1643. {
  1644. public:
  1645. using maybe_constant_operation::maybe_constant_operation;
  1646. value *evaluate (struct type *expect_type,
  1647. struct expression *exp,
  1648. enum noside noside) override
  1649. {
  1650. return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
  1651. exp, noside);
  1652. }
  1653. enum exp_opcode opcode () const override
  1654. { return UNOP_CAST; }
  1655. /* Return the type referenced by this object. */
  1656. struct type *get_type () const
  1657. {
  1658. return std::get<1> (m_storage);
  1659. }
  1660. protected:
  1661. void do_generate_ax (struct expression *exp,
  1662. struct agent_expr *ax,
  1663. struct axs_value *value,
  1664. struct type *cast_type)
  1665. override;
  1666. };
  1667. /* A cast, but the type comes from an expression, not a "struct
  1668. type". */
  1669. class unop_cast_type_operation
  1670. : public maybe_constant_operation<operation_up, operation_up>
  1671. {
  1672. public:
  1673. using maybe_constant_operation::maybe_constant_operation;
  1674. value *evaluate (struct type *expect_type,
  1675. struct expression *exp,
  1676. enum noside noside) override
  1677. {
  1678. value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
  1679. EVAL_AVOID_SIDE_EFFECTS);
  1680. return std::get<1> (m_storage)->evaluate_for_cast (value_type (val),
  1681. exp, noside);
  1682. }
  1683. enum exp_opcode opcode () const override
  1684. { return UNOP_CAST_TYPE; }
  1685. protected:
  1686. void do_generate_ax (struct expression *exp,
  1687. struct agent_expr *ax,
  1688. struct axs_value *value,
  1689. struct type *cast_type)
  1690. override;
  1691. };
  1692. typedef value *cxx_cast_ftype (struct type *, value *);
  1693. /* This implements dynamic_cast and reinterpret_cast. static_cast and
  1694. const_cast are handled by the ordinary case operations. */
  1695. template<exp_opcode OP, cxx_cast_ftype FUNC>
  1696. class cxx_cast_operation
  1697. : public maybe_constant_operation<operation_up, operation_up>
  1698. {
  1699. public:
  1700. using maybe_constant_operation::maybe_constant_operation;
  1701. value *evaluate (struct type *expect_type,
  1702. struct expression *exp,
  1703. enum noside noside) override
  1704. {
  1705. value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
  1706. EVAL_AVOID_SIDE_EFFECTS);
  1707. struct type *type = value_type (val);
  1708. value *rhs = std::get<1> (m_storage)->evaluate (type, exp, noside);
  1709. return FUNC (type, rhs);
  1710. }
  1711. enum exp_opcode opcode () const override
  1712. { return OP; }
  1713. };
  1714. using dynamic_cast_operation = cxx_cast_operation<UNOP_DYNAMIC_CAST,
  1715. value_dynamic_cast>;
  1716. using reinterpret_cast_operation = cxx_cast_operation<UNOP_REINTERPRET_CAST,
  1717. value_reinterpret_cast>;
  1718. /* Multi-dimensional subscripting. */
  1719. class multi_subscript_operation
  1720. : public tuple_holding_operation<operation_up, std::vector<operation_up>>
  1721. {
  1722. public:
  1723. using tuple_holding_operation::tuple_holding_operation;
  1724. value *evaluate (struct type *expect_type,
  1725. struct expression *exp,
  1726. enum noside noside) override;
  1727. enum exp_opcode opcode () const override
  1728. { return MULTI_SUBSCRIPT; }
  1729. };
  1730. /* The "&&" operator. */
  1731. class logical_and_operation
  1732. : public maybe_constant_operation<operation_up, operation_up>
  1733. {
  1734. public:
  1735. using maybe_constant_operation::maybe_constant_operation;
  1736. value *evaluate (struct type *expect_type,
  1737. struct expression *exp,
  1738. enum noside noside) override;
  1739. enum exp_opcode opcode () const override
  1740. { return BINOP_LOGICAL_AND; }
  1741. protected:
  1742. void do_generate_ax (struct expression *exp,
  1743. struct agent_expr *ax,
  1744. struct axs_value *value,
  1745. struct type *cast_type)
  1746. override;
  1747. };
  1748. /* The "||" operator. */
  1749. class logical_or_operation
  1750. : public maybe_constant_operation<operation_up, operation_up>
  1751. {
  1752. public:
  1753. using maybe_constant_operation::maybe_constant_operation;
  1754. value *evaluate (struct type *expect_type,
  1755. struct expression *exp,
  1756. enum noside noside) override;
  1757. enum exp_opcode opcode () const override
  1758. { return BINOP_LOGICAL_OR; }
  1759. protected:
  1760. void do_generate_ax (struct expression *exp,
  1761. struct agent_expr *ax,
  1762. struct axs_value *value,
  1763. struct type *cast_type)
  1764. override;
  1765. };
  1766. /* This class implements ADL (aka Koenig) function calls for C++. It
  1767. holds the name of the function to call, the block in which the
  1768. lookup should be done, and a vector of arguments. */
  1769. class adl_func_operation
  1770. : public tuple_holding_operation<std::string, const block *,
  1771. std::vector<operation_up>>
  1772. {
  1773. public:
  1774. using tuple_holding_operation::tuple_holding_operation;
  1775. value *evaluate (struct type *expect_type,
  1776. struct expression *exp,
  1777. enum noside noside) override;
  1778. enum exp_opcode opcode () const override
  1779. { return OP_ADL_FUNC; }
  1780. };
  1781. /* The OP_ARRAY operation. */
  1782. class array_operation
  1783. : public tuple_holding_operation<int, int, std::vector<operation_up>>
  1784. {
  1785. public:
  1786. using tuple_holding_operation::tuple_holding_operation;
  1787. value *evaluate (struct type *expect_type,
  1788. struct expression *exp,
  1789. enum noside noside) override;
  1790. enum exp_opcode opcode () const override
  1791. { return OP_ARRAY; }
  1792. private:
  1793. struct value *evaluate_struct_tuple (struct value *struct_val,
  1794. struct expression *exp,
  1795. enum noside noside, int nargs);
  1796. };
  1797. /* A function call. This holds the callee operation and the
  1798. arguments. */
  1799. class funcall_operation
  1800. : public tuple_holding_operation<operation_up, std::vector<operation_up>>
  1801. {
  1802. public:
  1803. using tuple_holding_operation::tuple_holding_operation;
  1804. value *evaluate (struct type *expect_type,
  1805. struct expression *exp,
  1806. enum noside noside) override
  1807. {
  1808. return std::get<0> (m_storage)->evaluate_funcall (expect_type, exp, noside,
  1809. std::get<1> (m_storage));
  1810. }
  1811. enum exp_opcode opcode () const override
  1812. { return OP_FUNCALL; }
  1813. };
  1814. } /* namespace expr */
  1815. #endif /* EXPOP_H */