PageRenderTime 124ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/src/netbsd/src/gnu/dist/gdb6/gdb/ada-exp.y

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
Happy | 1420 lines | 1220 code | 200 blank | 0 comment | 0 complexity | e2f2fe15fffd55aece6bf1e78ad2e349 MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /* YACC parser for Ada expressions, for GDB.
  2. Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 1997, 2000, 2003,
  3. 2004 Free Software Foundation, Inc.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. /* Parse an Ada expression from text in a string,
  18. and return the result as a struct expression pointer.
  19. That structure contains arithmetic operations in reverse polish,
  20. with constants represented by operations that are followed by special data.
  21. See expression.h for the details of the format.
  22. What is important here is that it can be built up sequentially
  23. during the process of parsing; the lower levels of the tree always
  24. come first in the result.
  25. malloc's and realloc's in this file are transformed to
  26. xmalloc and xrealloc respectively by the same sed command in the
  27. makefile that remaps any other malloc/realloc inserted by the parser
  28. generator. Doing this with #defines and trying to control the interaction
  29. with include files (<malloc.h> and <stdlib.h> for example) just became
  30. too messy, particularly when such includes can be inserted at random
  31. times by the parser generator. */
  32. %{
  33. #include "defs.h"
  34. #include "gdb_string.h"
  35. #include <ctype.h>
  36. #include "expression.h"
  37. #include "value.h"
  38. #include "parser-defs.h"
  39. #include "language.h"
  40. #include "ada-lang.h"
  41. #include "bfd.h" /* Required by objfiles.h. */
  42. #include "symfile.h" /* Required by objfiles.h. */
  43. #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
  44. #include "frame.h"
  45. #include "block.h"
  46. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  47. as well as gratuitiously global symbol names, so we can have multiple
  48. yacc generated parsers in gdb. These are only the variables
  49. produced by yacc. If other parser generators (bison, byacc, etc) produce
  50. additional global names that conflict at link time, then those parser
  51. generators need to be fixed instead of adding those names to this list. */
  52. /* NOTE: This is clumsy, especially since BISON and FLEX provide --prefix
  53. options. I presume we are maintaining it to accommodate systems
  54. without BISON? (PNH) */
  55. #define yymaxdepth ada_maxdepth
  56. #define yyparse _ada_parse /* ada_parse calls this after initialization */
  57. #define yylex ada_lex
  58. #define yyerror ada_error
  59. #define yylval ada_lval
  60. #define yychar ada_char
  61. #define yydebug ada_debug
  62. #define yypact ada_pact
  63. #define yyr1 ada_r1
  64. #define yyr2 ada_r2
  65. #define yydef ada_def
  66. #define yychk ada_chk
  67. #define yypgo ada_pgo
  68. #define yyact ada_act
  69. #define yyexca ada_exca
  70. #define yyerrflag ada_errflag
  71. #define yynerrs ada_nerrs
  72. #define yyps ada_ps
  73. #define yypv ada_pv
  74. #define yys ada_s
  75. #define yy_yys ada_yys
  76. #define yystate ada_state
  77. #define yytmp ada_tmp
  78. #define yyv ada_v
  79. #define yy_yyv ada_yyv
  80. #define yyval ada_val
  81. #define yylloc ada_lloc
  82. #define yyreds ada_reds /* With YYDEBUG defined */
  83. #define yytoks ada_toks /* With YYDEBUG defined */
  84. #define yyname ada_name /* With YYDEBUG defined */
  85. #define yyrule ada_rule /* With YYDEBUG defined */
  86. #ifndef YYDEBUG
  87. #define YYDEBUG 1 /* Default to yydebug support */
  88. #endif
  89. #define YYFPRINTF parser_fprintf
  90. struct name_info {
  91. struct symbol *sym;
  92. struct minimal_symbol *msym;
  93. struct block *block;
  94. struct stoken stoken;
  95. };
  96. static struct stoken empty_stoken = { "", 0 };
  97. /* If expression is in the context of TYPE'(...), then TYPE, else
  98. * NULL. */
  99. static struct type *type_qualifier;
  100. int yyparse (void);
  101. static int yylex (void);
  102. void yyerror (char *);
  103. static struct stoken string_to_operator (struct stoken);
  104. static void write_int (LONGEST, struct type *);
  105. static void write_object_renaming (struct block *, struct symbol *, int);
  106. static struct type* write_var_or_type (struct block *, struct stoken);
  107. static void write_name_assoc (struct stoken);
  108. static void write_exp_op_with_string (enum exp_opcode, struct stoken);
  109. static struct block *block_lookup (struct block *, char *);
  110. static LONGEST convert_char_literal (struct type *, LONGEST);
  111. static void write_ambiguous_var (struct block *, char *, int);
  112. static struct type *type_int (void);
  113. static struct type *type_long (void);
  114. static struct type *type_long_long (void);
  115. static struct type *type_float (void);
  116. static struct type *type_double (void);
  117. static struct type *type_long_double (void);
  118. static struct type *type_char (void);
  119. static struct type *type_system_address (void);
  120. %}
  121. %union
  122. {
  123. LONGEST lval;
  124. struct {
  125. LONGEST val;
  126. struct type *type;
  127. } typed_val;
  128. struct {
  129. DOUBLEST dval;
  130. struct type *type;
  131. } typed_val_float;
  132. struct type *tval;
  133. struct stoken sval;
  134. struct block *bval;
  135. struct internalvar *ivar;
  136. }
  137. %type <lval> positional_list component_groups component_associations
  138. %type <lval> aggregate_component_list
  139. %type <tval> var_or_type
  140. %token <typed_val> INT NULL_PTR CHARLIT
  141. %token <typed_val_float> FLOAT
  142. %token COLONCOLON
  143. %token <sval> STRING NAME DOT_ID
  144. %type <bval> block
  145. %type <lval> arglist tick_arglist
  146. %type <tval> save_qualifier
  147. %token DOT_ALL
  148. /* Special type cases, put in to allow the parser to distinguish different
  149. legal basetypes. */
  150. %token <sval> SPECIAL_VARIABLE
  151. %nonassoc ASSIGN
  152. %left _AND_ OR XOR THEN ELSE
  153. %left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
  154. %left '@'
  155. %left '+' '-' '&'
  156. %left UNARY
  157. %left '*' '/' MOD REM
  158. %right STARSTAR ABS NOT
  159. /* Artificial token to give NAME => ... and NAME | priority over reducing
  160. NAME to <primary> and to give <primary>' priority over reducing <primary>
  161. to <simple_exp>. */
  162. %nonassoc VAR
  163. %nonassoc ARROW '|'
  164. %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
  165. %right TICK_MAX TICK_MIN TICK_MODULUS
  166. %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
  167. /* The following are right-associative only so that reductions at this
  168. precedence have lower precedence than '.' and '('. The syntax still
  169. forces a.b.c, e.g., to be LEFT-associated. */
  170. %right '.' '(' '[' DOT_ID DOT_ALL
  171. %token NEW OTHERS
  172. %%
  173. start : exp1
  174. ;
  175. /* Expressions, including the sequencing operator. */
  176. exp1 : exp
  177. | exp1 ';' exp
  178. { write_exp_elt_opcode (BINOP_COMMA); }
  179. | primary ASSIGN exp /* Extension for convenience */
  180. { write_exp_elt_opcode (BINOP_ASSIGN); }
  181. ;
  182. /* Expressions, not including the sequencing operator. */
  183. primary : primary DOT_ALL
  184. { write_exp_elt_opcode (UNOP_IND); }
  185. ;
  186. primary : primary DOT_ID
  187. { write_exp_op_with_string (STRUCTOP_STRUCT, $2); }
  188. ;
  189. primary : primary '(' arglist ')'
  190. {
  191. write_exp_elt_opcode (OP_FUNCALL);
  192. write_exp_elt_longcst ($3);
  193. write_exp_elt_opcode (OP_FUNCALL);
  194. }
  195. | var_or_type '(' arglist ')'
  196. {
  197. if ($1 != NULL)
  198. {
  199. if ($3 != 1)
  200. error (_("Invalid conversion"));
  201. write_exp_elt_opcode (UNOP_CAST);
  202. write_exp_elt_type ($1);
  203. write_exp_elt_opcode (UNOP_CAST);
  204. }
  205. else
  206. {
  207. write_exp_elt_opcode (OP_FUNCALL);
  208. write_exp_elt_longcst ($3);
  209. write_exp_elt_opcode (OP_FUNCALL);
  210. }
  211. }
  212. ;
  213. primary : var_or_type '\'' save_qualifier { type_qualifier = $1; }
  214. '(' exp ')'
  215. {
  216. if ($1 == NULL)
  217. error (_("Type required for qualification"));
  218. write_exp_elt_opcode (UNOP_QUAL);
  219. write_exp_elt_type ($1);
  220. write_exp_elt_opcode (UNOP_QUAL);
  221. type_qualifier = $3;
  222. }
  223. ;
  224. save_qualifier : { $$ = type_qualifier; }
  225. ;
  226. primary :
  227. primary '(' simple_exp DOTDOT simple_exp ')'
  228. { write_exp_elt_opcode (TERNOP_SLICE); }
  229. | var_or_type '(' simple_exp DOTDOT simple_exp ')'
  230. { if ($1 == NULL)
  231. write_exp_elt_opcode (TERNOP_SLICE);
  232. else
  233. error (_("Cannot slice a type"));
  234. }
  235. ;
  236. primary : '(' exp1 ')' { }
  237. ;
  238. /* The following rule causes a conflict with the type conversion
  239. var_or_type (exp)
  240. To get around it, we give '(' higher priority and add bridge rules for
  241. var_or_type (exp, exp, ...)
  242. var_or_type (exp .. exp)
  243. We also have the action for var_or_type(exp) generate a function call
  244. when the first symbol does not denote a type. */
  245. primary : var_or_type %prec VAR
  246. { if ($1 != NULL)
  247. {
  248. write_exp_elt_opcode (OP_TYPE);
  249. write_exp_elt_type ($1);
  250. write_exp_elt_opcode (OP_TYPE);
  251. }
  252. }
  253. ;
  254. primary : SPECIAL_VARIABLE /* Various GDB extensions */
  255. { write_dollar_variable ($1); }
  256. ;
  257. primary : aggregate
  258. ;
  259. simple_exp : primary
  260. ;
  261. simple_exp : '-' simple_exp %prec UNARY
  262. { write_exp_elt_opcode (UNOP_NEG); }
  263. ;
  264. simple_exp : '+' simple_exp %prec UNARY
  265. { write_exp_elt_opcode (UNOP_PLUS); }
  266. ;
  267. simple_exp : NOT simple_exp %prec UNARY
  268. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  269. ;
  270. simple_exp : ABS simple_exp %prec UNARY
  271. { write_exp_elt_opcode (UNOP_ABS); }
  272. ;
  273. arglist : { $$ = 0; }
  274. ;
  275. arglist : exp
  276. { $$ = 1; }
  277. | NAME ARROW exp
  278. { $$ = 1; }
  279. | arglist ',' exp
  280. { $$ = $1 + 1; }
  281. | arglist ',' NAME ARROW exp
  282. { $$ = $1 + 1; }
  283. ;
  284. simple_exp : '{' var_or_type '}' simple_exp %prec '.'
  285. /* GDB extension */
  286. {
  287. if ($2 == NULL)
  288. error (_("Type required within braces in coercion"));
  289. write_exp_elt_opcode (UNOP_MEMVAL);
  290. write_exp_elt_type ($2);
  291. write_exp_elt_opcode (UNOP_MEMVAL);
  292. }
  293. ;
  294. /* Binary operators in order of decreasing precedence. */
  295. simple_exp : simple_exp STARSTAR simple_exp
  296. { write_exp_elt_opcode (BINOP_EXP); }
  297. ;
  298. simple_exp : simple_exp '*' simple_exp
  299. { write_exp_elt_opcode (BINOP_MUL); }
  300. ;
  301. simple_exp : simple_exp '/' simple_exp
  302. { write_exp_elt_opcode (BINOP_DIV); }
  303. ;
  304. simple_exp : simple_exp REM simple_exp /* May need to be fixed to give correct Ada REM */
  305. { write_exp_elt_opcode (BINOP_REM); }
  306. ;
  307. simple_exp : simple_exp MOD simple_exp
  308. { write_exp_elt_opcode (BINOP_MOD); }
  309. ;
  310. simple_exp : simple_exp '@' simple_exp /* GDB extension */
  311. { write_exp_elt_opcode (BINOP_REPEAT); }
  312. ;
  313. simple_exp : simple_exp '+' simple_exp
  314. { write_exp_elt_opcode (BINOP_ADD); }
  315. ;
  316. simple_exp : simple_exp '&' simple_exp
  317. { write_exp_elt_opcode (BINOP_CONCAT); }
  318. ;
  319. simple_exp : simple_exp '-' simple_exp
  320. { write_exp_elt_opcode (BINOP_SUB); }
  321. ;
  322. relation : simple_exp
  323. ;
  324. relation : simple_exp '=' simple_exp
  325. { write_exp_elt_opcode (BINOP_EQUAL); }
  326. ;
  327. relation : simple_exp NOTEQUAL simple_exp
  328. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  329. ;
  330. relation : simple_exp LEQ simple_exp
  331. { write_exp_elt_opcode (BINOP_LEQ); }
  332. ;
  333. relation : simple_exp IN simple_exp DOTDOT simple_exp
  334. { write_exp_elt_opcode (TERNOP_IN_RANGE); }
  335. | simple_exp IN primary TICK_RANGE tick_arglist
  336. { write_exp_elt_opcode (BINOP_IN_BOUNDS);
  337. write_exp_elt_longcst ((LONGEST) $5);
  338. write_exp_elt_opcode (BINOP_IN_BOUNDS);
  339. }
  340. | simple_exp IN var_or_type %prec TICK_ACCESS
  341. {
  342. if ($3 == NULL)
  343. error (_("Right operand of 'in' must be type"));
  344. write_exp_elt_opcode (UNOP_IN_RANGE);
  345. write_exp_elt_type ($3);
  346. write_exp_elt_opcode (UNOP_IN_RANGE);
  347. }
  348. | simple_exp NOT IN simple_exp DOTDOT simple_exp
  349. { write_exp_elt_opcode (TERNOP_IN_RANGE);
  350. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  351. }
  352. | simple_exp NOT IN primary TICK_RANGE tick_arglist
  353. { write_exp_elt_opcode (BINOP_IN_BOUNDS);
  354. write_exp_elt_longcst ((LONGEST) $6);
  355. write_exp_elt_opcode (BINOP_IN_BOUNDS);
  356. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  357. }
  358. | simple_exp NOT IN var_or_type %prec TICK_ACCESS
  359. {
  360. if ($4 == NULL)
  361. error (_("Right operand of 'in' must be type"));
  362. write_exp_elt_opcode (UNOP_IN_RANGE);
  363. write_exp_elt_type ($4);
  364. write_exp_elt_opcode (UNOP_IN_RANGE);
  365. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  366. }
  367. ;
  368. relation : simple_exp GEQ simple_exp
  369. { write_exp_elt_opcode (BINOP_GEQ); }
  370. ;
  371. relation : simple_exp '<' simple_exp
  372. { write_exp_elt_opcode (BINOP_LESS); }
  373. ;
  374. relation : simple_exp '>' simple_exp
  375. { write_exp_elt_opcode (BINOP_GTR); }
  376. ;
  377. exp : relation
  378. | and_exp
  379. | and_then_exp
  380. | or_exp
  381. | or_else_exp
  382. | xor_exp
  383. ;
  384. and_exp :
  385. relation _AND_ relation
  386. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  387. | and_exp _AND_ relation
  388. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  389. ;
  390. and_then_exp :
  391. relation _AND_ THEN relation
  392. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  393. | and_then_exp _AND_ THEN relation
  394. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  395. ;
  396. or_exp :
  397. relation OR relation
  398. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  399. | or_exp OR relation
  400. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  401. ;
  402. or_else_exp :
  403. relation OR ELSE relation
  404. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  405. | or_else_exp OR ELSE relation
  406. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  407. ;
  408. xor_exp : relation XOR relation
  409. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  410. | xor_exp XOR relation
  411. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  412. ;
  413. /* Primaries can denote types (OP_TYPE). In cases such as
  414. primary TICK_ADDRESS, where a type would be invalid, it will be
  415. caught when evaluate_subexp in ada-lang.c tries to evaluate the
  416. primary, expecting a value. Precedence rules resolve the ambiguity
  417. in NAME TICK_ACCESS in favor of shifting to form a var_or_type. A
  418. construct such as aType'access'access will again cause an error when
  419. aType'access evaluates to a type that evaluate_subexp attempts to
  420. evaluate. */
  421. primary : primary TICK_ACCESS
  422. { write_exp_elt_opcode (UNOP_ADDR); }
  423. | primary TICK_ADDRESS
  424. { write_exp_elt_opcode (UNOP_ADDR);
  425. write_exp_elt_opcode (UNOP_CAST);
  426. write_exp_elt_type (type_system_address ());
  427. write_exp_elt_opcode (UNOP_CAST);
  428. }
  429. | primary TICK_FIRST tick_arglist
  430. { write_int ($3, type_int ());
  431. write_exp_elt_opcode (OP_ATR_FIRST); }
  432. | primary TICK_LAST tick_arglist
  433. { write_int ($3, type_int ());
  434. write_exp_elt_opcode (OP_ATR_LAST); }
  435. | primary TICK_LENGTH tick_arglist
  436. { write_int ($3, type_int ());
  437. write_exp_elt_opcode (OP_ATR_LENGTH); }
  438. | primary TICK_SIZE
  439. { write_exp_elt_opcode (OP_ATR_SIZE); }
  440. | primary TICK_TAG
  441. { write_exp_elt_opcode (OP_ATR_TAG); }
  442. | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
  443. { write_exp_elt_opcode (OP_ATR_MIN); }
  444. | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
  445. { write_exp_elt_opcode (OP_ATR_MAX); }
  446. | opt_type_prefix TICK_POS '(' exp ')'
  447. { write_exp_elt_opcode (OP_ATR_POS); }
  448. | type_prefix TICK_VAL '(' exp ')'
  449. { write_exp_elt_opcode (OP_ATR_VAL); }
  450. | type_prefix TICK_MODULUS
  451. { write_exp_elt_opcode (OP_ATR_MODULUS); }
  452. ;
  453. tick_arglist : %prec '('
  454. { $$ = 1; }
  455. | '(' INT ')'
  456. { $$ = $2.val; }
  457. ;
  458. type_prefix :
  459. var_or_type
  460. {
  461. if ($1 == NULL)
  462. error (_("Prefix must be type"));
  463. write_exp_elt_opcode (OP_TYPE);
  464. write_exp_elt_type ($1);
  465. write_exp_elt_opcode (OP_TYPE); }
  466. ;
  467. opt_type_prefix :
  468. type_prefix
  469. | /* EMPTY */
  470. { write_exp_elt_opcode (OP_TYPE);
  471. write_exp_elt_type (builtin_type_void);
  472. write_exp_elt_opcode (OP_TYPE); }
  473. ;
  474. primary : INT
  475. { write_int ((LONGEST) $1.val, $1.type); }
  476. ;
  477. primary : CHARLIT
  478. { write_int (convert_char_literal (type_qualifier, $1.val),
  479. (type_qualifier == NULL)
  480. ? $1.type : type_qualifier);
  481. }
  482. ;
  483. primary : FLOAT
  484. { write_exp_elt_opcode (OP_DOUBLE);
  485. write_exp_elt_type ($1.type);
  486. write_exp_elt_dblcst ($1.dval);
  487. write_exp_elt_opcode (OP_DOUBLE);
  488. }
  489. ;
  490. primary : NULL_PTR
  491. { write_int (0, type_int ()); }
  492. ;
  493. primary : STRING
  494. {
  495. write_exp_op_with_string (OP_STRING, $1);
  496. }
  497. ;
  498. primary : NEW NAME
  499. { error (_("NEW not implemented.")); }
  500. ;
  501. var_or_type: NAME %prec VAR
  502. { $$ = write_var_or_type (NULL, $1); }
  503. | block NAME %prec VAR
  504. { $$ = write_var_or_type ($1, $2); }
  505. | NAME TICK_ACCESS
  506. {
  507. $$ = write_var_or_type (NULL, $1);
  508. if ($$ == NULL)
  509. write_exp_elt_opcode (UNOP_ADDR);
  510. else
  511. $$ = lookup_pointer_type ($$);
  512. }
  513. | block NAME TICK_ACCESS
  514. {
  515. $$ = write_var_or_type ($1, $2);
  516. if ($$ == NULL)
  517. write_exp_elt_opcode (UNOP_ADDR);
  518. else
  519. $$ = lookup_pointer_type ($$);
  520. }
  521. ;
  522. /* GDB extension */
  523. block : NAME COLONCOLON
  524. { $$ = block_lookup (NULL, $1.ptr); }
  525. | block NAME COLONCOLON
  526. { $$ = block_lookup ($1, $2.ptr); }
  527. ;
  528. aggregate :
  529. '(' aggregate_component_list ')'
  530. {
  531. write_exp_elt_opcode (OP_AGGREGATE);
  532. write_exp_elt_longcst ($2);
  533. write_exp_elt_opcode (OP_AGGREGATE);
  534. }
  535. ;
  536. aggregate_component_list :
  537. component_groups { $$ = $1; }
  538. | positional_list exp
  539. { write_exp_elt_opcode (OP_POSITIONAL);
  540. write_exp_elt_longcst ($1);
  541. write_exp_elt_opcode (OP_POSITIONAL);
  542. $$ = $1 + 1;
  543. }
  544. | positional_list component_groups
  545. { $$ = $1 + $2; }
  546. ;
  547. positional_list :
  548. exp ','
  549. { write_exp_elt_opcode (OP_POSITIONAL);
  550. write_exp_elt_longcst (0);
  551. write_exp_elt_opcode (OP_POSITIONAL);
  552. $$ = 1;
  553. }
  554. | positional_list exp ','
  555. { write_exp_elt_opcode (OP_POSITIONAL);
  556. write_exp_elt_longcst ($1);
  557. write_exp_elt_opcode (OP_POSITIONAL);
  558. $$ = $1 + 1;
  559. }
  560. ;
  561. component_groups:
  562. others { $$ = 1; }
  563. | component_group { $$ = 1; }
  564. | component_group ',' component_groups
  565. { $$ = $3 + 1; }
  566. ;
  567. others : OTHERS ARROW exp
  568. { write_exp_elt_opcode (OP_OTHERS); }
  569. ;
  570. component_group :
  571. component_associations
  572. {
  573. write_exp_elt_opcode (OP_CHOICES);
  574. write_exp_elt_longcst ($1);
  575. write_exp_elt_opcode (OP_CHOICES);
  576. }
  577. ;
  578. /* We use this somewhat obscure definition in order to handle NAME => and
  579. NAME | differently from exp => and exp |. ARROW and '|' have a precedence
  580. above that of the reduction of NAME to var_or_type. By delaying
  581. decisions until after the => or '|', we convert the ambiguity to a
  582. resolved shift/reduce conflict. */
  583. component_associations :
  584. NAME ARROW
  585. { write_name_assoc ($1); }
  586. exp { $$ = 1; }
  587. | simple_exp ARROW exp
  588. { $$ = 1; }
  589. | simple_exp DOTDOT simple_exp ARROW
  590. { write_exp_elt_opcode (OP_DISCRETE_RANGE);
  591. write_exp_op_with_string (OP_NAME, empty_stoken);
  592. }
  593. exp { $$ = 1; }
  594. | NAME '|'
  595. { write_name_assoc ($1); }
  596. component_associations { $$ = $4 + 1; }
  597. | simple_exp '|'
  598. component_associations { $$ = $3 + 1; }
  599. | simple_exp DOTDOT simple_exp '|'
  600. { write_exp_elt_opcode (OP_DISCRETE_RANGE); }
  601. component_associations { $$ = $6 + 1; }
  602. ;
  603. /* Some extensions borrowed from C, for the benefit of those who find they
  604. can't get used to Ada notation in GDB. */
  605. primary : '*' primary %prec '.'
  606. { write_exp_elt_opcode (UNOP_IND); }
  607. | '&' primary %prec '.'
  608. { write_exp_elt_opcode (UNOP_ADDR); }
  609. | primary '[' exp ']'
  610. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  611. ;
  612. %%
  613. /* yylex defined in ada-lex.c: Reads one token, getting characters */
  614. /* through lexptr. */
  615. /* Remap normal flex interface names (yylex) as well as gratuitiously */
  616. /* global symbol names, so we can have multiple flex-generated parsers */
  617. /* in gdb. */
  618. /* (See note above on previous definitions for YACC.) */
  619. #define yy_create_buffer ada_yy_create_buffer
  620. #define yy_delete_buffer ada_yy_delete_buffer
  621. #define yy_init_buffer ada_yy_init_buffer
  622. #define yy_load_buffer_state ada_yy_load_buffer_state
  623. #define yy_switch_to_buffer ada_yy_switch_to_buffer
  624. #define yyrestart ada_yyrestart
  625. #define yytext ada_yytext
  626. #define yywrap ada_yywrap
  627. static struct obstack temp_parse_space;
  628. /* The following kludge was found necessary to prevent conflicts between */
  629. /* defs.h and non-standard stdlib.h files. */
  630. #define qsort __qsort__dummy
  631. #include "ada-lex.c"
  632. int
  633. ada_parse (void)
  634. {
  635. lexer_init (yyin); /* (Re-)initialize lexer. */
  636. type_qualifier = NULL;
  637. obstack_free (&temp_parse_space, NULL);
  638. obstack_init (&temp_parse_space);
  639. return _ada_parse ();
  640. }
  641. void
  642. yyerror (char *msg)
  643. {
  644. error (_("Error in expression, near `%s'."), lexptr);
  645. }
  646. /* The operator name corresponding to operator symbol STRING (adds
  647. quotes and maps to lower-case). Destroys the previous contents of
  648. the array pointed to by STRING.ptr. Error if STRING does not match
  649. a valid Ada operator. Assumes that STRING.ptr points to a
  650. null-terminated string and that, if STRING is a valid operator
  651. symbol, the array pointed to by STRING.ptr contains at least
  652. STRING.length+3 characters. */
  653. static struct stoken
  654. string_to_operator (struct stoken string)
  655. {
  656. int i;
  657. for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
  658. {
  659. if (string.length == strlen (ada_opname_table[i].decoded)-2
  660. && strncasecmp (string.ptr, ada_opname_table[i].decoded+1,
  661. string.length) == 0)
  662. {
  663. strncpy (string.ptr, ada_opname_table[i].decoded,
  664. string.length+2);
  665. string.length += 2;
  666. return string;
  667. }
  668. }
  669. error (_("Invalid operator symbol `%s'"), string.ptr);
  670. }
  671. /* Emit expression to access an instance of SYM, in block BLOCK (if
  672. * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
  673. static void
  674. write_var_from_sym (struct block *orig_left_context,
  675. struct block *block,
  676. struct symbol *sym)
  677. {
  678. if (orig_left_context == NULL && symbol_read_needs_frame (sym))
  679. {
  680. if (innermost_block == 0
  681. || contained_in (block, innermost_block))
  682. innermost_block = block;
  683. }
  684. write_exp_elt_opcode (OP_VAR_VALUE);
  685. write_exp_elt_block (block);
  686. write_exp_elt_sym (sym);
  687. write_exp_elt_opcode (OP_VAR_VALUE);
  688. }
  689. /* Write integer constant ARG of type TYPE. */
  690. static void
  691. write_int (LONGEST arg, struct type *type)
  692. {
  693. write_exp_elt_opcode (OP_LONG);
  694. write_exp_elt_type (type);
  695. write_exp_elt_longcst (arg);
  696. write_exp_elt_opcode (OP_LONG);
  697. }
  698. /* Write an OPCODE, string, OPCODE sequence to the current expression. */
  699. static void
  700. write_exp_op_with_string (enum exp_opcode opcode, struct stoken token)
  701. {
  702. write_exp_elt_opcode (opcode);
  703. write_exp_string (token);
  704. write_exp_elt_opcode (opcode);
  705. }
  706. /* Emit expression corresponding to the renamed object designated by
  707. * the type RENAMING, which must be the referent of an object renaming
  708. * type, in the context of ORIG_LEFT_CONTEXT. MAX_DEPTH is the maximum
  709. * number of cascaded renamings to allow. */
  710. static void
  711. write_object_renaming (struct block *orig_left_context,
  712. struct symbol *renaming, int max_depth)
  713. {
  714. const char *qualification = SYMBOL_LINKAGE_NAME (renaming);
  715. const char *simple_tail;
  716. const char *expr = TYPE_FIELD_NAME (SYMBOL_TYPE (renaming), 0);
  717. const char *suffix;
  718. char *name;
  719. struct symbol *sym;
  720. enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
  721. if (max_depth <= 0)
  722. error (_("Could not find renamed symbol"));
  723. /* if orig_left_context is null, then use the currently selected
  724. block; otherwise we might fail our symbol lookup below. */
  725. if (orig_left_context == NULL)
  726. orig_left_context = get_selected_block (NULL);
  727. for (simple_tail = qualification + strlen (qualification);
  728. simple_tail != qualification; simple_tail -= 1)
  729. {
  730. if (*simple_tail == '.')
  731. {
  732. simple_tail += 1;
  733. break;
  734. }
  735. else if (strncmp (simple_tail, "__", 2) == 0)
  736. {
  737. simple_tail += 2;
  738. break;
  739. }
  740. }
  741. suffix = strstr (expr, "___XE");
  742. if (suffix == NULL)
  743. goto BadEncoding;
  744. name = (char *) obstack_alloc (&temp_parse_space, suffix - expr + 1);
  745. strncpy (name, expr, suffix-expr);
  746. name[suffix-expr] = '\000';
  747. sym = lookup_symbol (name, orig_left_context, VAR_DOMAIN, 0, NULL);
  748. if (sym == NULL)
  749. error (_("Could not find renamed variable: %s"), ada_decode (name));
  750. if (ada_is_object_renaming (sym))
  751. write_object_renaming (orig_left_context, sym, max_depth-1);
  752. else
  753. write_var_from_sym (orig_left_context, block_found, sym);
  754. suffix += 5;
  755. slice_state = SIMPLE_INDEX;
  756. while (*suffix == 'X')
  757. {
  758. suffix += 1;
  759. switch (*suffix) {
  760. case 'A':
  761. suffix += 1;
  762. write_exp_elt_opcode (UNOP_IND);
  763. break;
  764. case 'L':
  765. slice_state = LOWER_BOUND;
  766. case 'S':
  767. suffix += 1;
  768. if (isdigit (*suffix))
  769. {
  770. char *next;
  771. long val = strtol (suffix, &next, 10);
  772. if (next == suffix)
  773. goto BadEncoding;
  774. suffix = next;
  775. write_exp_elt_opcode (OP_LONG);
  776. write_exp_elt_type (type_int ());
  777. write_exp_elt_longcst ((LONGEST) val);
  778. write_exp_elt_opcode (OP_LONG);
  779. }
  780. else
  781. {
  782. const char *end;
  783. char *index_name;
  784. int index_len;
  785. struct symbol *index_sym;
  786. end = strchr (suffix, 'X');
  787. if (end == NULL)
  788. end = suffix + strlen (suffix);
  789. index_len = simple_tail - qualification + 2 + (suffix - end) + 1;
  790. index_name
  791. = (char *) obstack_alloc (&temp_parse_space, index_len);
  792. memset (index_name, '\000', index_len);
  793. strncpy (index_name, qualification, simple_tail - qualification);
  794. index_name[simple_tail - qualification] = '\000';
  795. strncat (index_name, suffix, suffix-end);
  796. suffix = end;
  797. index_sym =
  798. lookup_symbol (index_name, NULL, VAR_DOMAIN, 0, NULL);
  799. if (index_sym == NULL)
  800. error (_("Could not find %s"), index_name);
  801. write_var_from_sym (NULL, block_found, sym);
  802. }
  803. if (slice_state == SIMPLE_INDEX)
  804. {
  805. write_exp_elt_opcode (OP_FUNCALL);
  806. write_exp_elt_longcst ((LONGEST) 1);
  807. write_exp_elt_opcode (OP_FUNCALL);
  808. }
  809. else if (slice_state == LOWER_BOUND)
  810. slice_state = UPPER_BOUND;
  811. else if (slice_state == UPPER_BOUND)
  812. {
  813. write_exp_elt_opcode (TERNOP_SLICE);
  814. slice_state = SIMPLE_INDEX;
  815. }
  816. break;
  817. case 'R':
  818. {
  819. struct stoken field_name;
  820. const char *end;
  821. suffix += 1;
  822. if (slice_state != SIMPLE_INDEX)
  823. goto BadEncoding;
  824. end = strchr (suffix, 'X');
  825. if (end == NULL)
  826. end = suffix + strlen (suffix);
  827. field_name.length = end - suffix;
  828. field_name.ptr = xmalloc (end - suffix + 1);
  829. strncpy (field_name.ptr, suffix, end - suffix);
  830. field_name.ptr[end - suffix] = '\000';
  831. suffix = end;
  832. write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
  833. break;
  834. }
  835. default:
  836. goto BadEncoding;
  837. }
  838. }
  839. if (slice_state == SIMPLE_INDEX)
  840. return;
  841. BadEncoding:
  842. error (_("Internal error in encoding of renaming declaration: %s"),
  843. SYMBOL_LINKAGE_NAME (renaming));
  844. }
  845. static struct block*
  846. block_lookup (struct block *context, char *raw_name)
  847. {
  848. char *name;
  849. struct ada_symbol_info *syms;
  850. int nsyms;
  851. struct symtab *symtab;
  852. if (raw_name[0] == '\'')
  853. {
  854. raw_name += 1;
  855. name = raw_name;
  856. }
  857. else
  858. name = ada_encode (raw_name);
  859. nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
  860. if (context == NULL &&
  861. (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
  862. symtab = lookup_symtab (name);
  863. else
  864. symtab = NULL;
  865. if (symtab != NULL)
  866. return BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
  867. else if (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK)
  868. {
  869. if (context == NULL)
  870. error (_("No file or function \"%s\"."), raw_name);
  871. else
  872. error (_("No function \"%s\" in specified context."), raw_name);
  873. }
  874. else
  875. {
  876. if (nsyms > 1)
  877. warning (_("Function name \"%s\" ambiguous here"), raw_name);
  878. return SYMBOL_BLOCK_VALUE (syms[0].sym);
  879. }
  880. }
  881. static struct symbol*
  882. select_possible_type_sym (struct ada_symbol_info *syms, int nsyms)
  883. {
  884. int i;
  885. int preferred_index;
  886. struct type *preferred_type;
  887. preferred_index = -1; preferred_type = NULL;
  888. for (i = 0; i < nsyms; i += 1)
  889. switch (SYMBOL_CLASS (syms[i].sym))
  890. {
  891. case LOC_TYPEDEF:
  892. if (ada_prefer_type (SYMBOL_TYPE (syms[i].sym), preferred_type))
  893. {
  894. preferred_index = i;
  895. preferred_type = SYMBOL_TYPE (syms[i].sym);
  896. }
  897. break;
  898. case LOC_REGISTER:
  899. case LOC_ARG:
  900. case LOC_REF_ARG:
  901. case LOC_REGPARM:
  902. case LOC_REGPARM_ADDR:
  903. case LOC_LOCAL:
  904. case LOC_LOCAL_ARG:
  905. case LOC_BASEREG:
  906. case LOC_BASEREG_ARG:
  907. case LOC_COMPUTED:
  908. case LOC_COMPUTED_ARG:
  909. return NULL;
  910. default:
  911. break;
  912. }
  913. if (preferred_type == NULL)
  914. return NULL;
  915. return syms[preferred_index].sym;
  916. }
  917. static struct type*
  918. find_primitive_type (char *name)
  919. {
  920. struct type *type;
  921. type = language_lookup_primitive_type_by_name (current_language,
  922. current_gdbarch,
  923. name);
  924. if (type == NULL && strcmp ("system__address", name) == 0)
  925. type = type_system_address ();
  926. if (type != NULL)
  927. {
  928. /* Check to see if we have a regular definition of this
  929. type that just didn't happen to have been read yet. */
  930. int ntypes;
  931. struct symbol *sym;
  932. char *expanded_name =
  933. (char *) alloca (strlen (name) + sizeof ("standard__"));
  934. strcpy (expanded_name, "standard__");
  935. strcat (expanded_name, name);
  936. sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN, NULL, NULL);
  937. if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  938. type = SYMBOL_TYPE (sym);
  939. }
  940. return type;
  941. }
  942. static int
  943. chop_selector (char *name, int end)
  944. {
  945. int i;
  946. for (i = end - 1; i > 0; i -= 1)
  947. if (name[i] == '.' || (name[i] == '_' && name[i+1] == '_'))
  948. return i;
  949. return -1;
  950. }
  951. /* Given that SELS is a string of the form (<sep><identifier>)*, where
  952. <sep> is '__' or '.', write the indicated sequence of
  953. STRUCTOP_STRUCT expression operators. */
  954. static void
  955. write_selectors (char *sels)
  956. {
  957. while (*sels != '\0')
  958. {
  959. struct stoken field_name;
  960. char *p;
  961. while (*sels == '_' || *sels == '.')
  962. sels += 1;
  963. p = sels;
  964. while (*sels != '\0' && *sels != '.'
  965. && (sels[0] != '_' || sels[1] != '_'))
  966. sels += 1;
  967. field_name.length = sels - p;
  968. field_name.ptr = p;
  969. write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
  970. }
  971. }
  972. /* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
  973. NAME[0..LEN-1], in block context BLOCK, to be resolved later. Writes
  974. a temporary symbol that is valid until the next call to ada_parse.
  975. */
  976. static void
  977. write_ambiguous_var (struct block *block, char *name, int len)
  978. {
  979. struct symbol *sym =
  980. obstack_alloc (&temp_parse_space, sizeof (struct symbol));
  981. memset (sym, 0, sizeof (struct symbol));
  982. SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
  983. SYMBOL_LINKAGE_NAME (sym) = obsavestring (name, len, &temp_parse_space);
  984. SYMBOL_LANGUAGE (sym) = language_ada;
  985. write_exp_elt_opcode (OP_VAR_VALUE);
  986. write_exp_elt_block (block);
  987. write_exp_elt_sym (sym);
  988. write_exp_elt_opcode (OP_VAR_VALUE);
  989. }
  990. /* Look up NAME0 (an unencoded identifier or dotted name) in BLOCK (or
  991. expression_block_context if NULL). If it denotes a type, return
  992. that type. Otherwise, write expression code to evaluate it as an
  993. object and return NULL. In this second case, NAME0 will, in general,
  994. have the form <name>(.<selector_name>)*, where <name> is an object
  995. or renaming encoded in the debugging data. Calls error if no
  996. prefix <name> matches a name in the debugging data (i.e., matches
  997. either a complete name or, as a wild-card match, the final
  998. identifier). */
  999. static struct type*
  1000. write_var_or_type (struct block *block, struct stoken name0)
  1001. {
  1002. int depth;
  1003. char *encoded_name;
  1004. int name_len;
  1005. if (block == NULL)
  1006. block = expression_context_block;
  1007. encoded_name = ada_encode (name0.ptr);
  1008. name_len = strlen (encoded_name);
  1009. encoded_name = obsavestring (encoded_name, name_len, &temp_parse_space);
  1010. for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1)
  1011. {
  1012. int tail_index;
  1013. tail_index = name_len;
  1014. while (tail_index > 0)
  1015. {
  1016. int nsyms;
  1017. struct ada_symbol_info *syms;
  1018. struct symbol *type_sym;
  1019. int terminator = encoded_name[tail_index];
  1020. encoded_name[tail_index] = '\0';
  1021. nsyms = ada_lookup_symbol_list (encoded_name, block,
  1022. VAR_DOMAIN, &syms);
  1023. encoded_name[tail_index] = terminator;
  1024. /* A single symbol may rename a package or object. */
  1025. if (nsyms == 1 && !ada_is_object_renaming (syms[0].sym))
  1026. {
  1027. struct symbol *renaming_sym =
  1028. ada_find_renaming_symbol (SYMBOL_LINKAGE_NAME (syms[0].sym),
  1029. syms[0].block);
  1030. if (renaming_sym != NULL)
  1031. syms[0].sym = renaming_sym;
  1032. }
  1033. type_sym = select_possible_type_sym (syms, nsyms);
  1034. if (type_sym != NULL)
  1035. {
  1036. struct type *type = SYMBOL_TYPE (type_sym);
  1037. if (TYPE_CODE (type) == TYPE_CODE_VOID)
  1038. error (_("`%s' matches only void type name(s)"), name0.ptr);
  1039. else if (ada_is_object_renaming (type_sym))
  1040. {
  1041. write_object_renaming (block, type_sym,
  1042. MAX_RENAMING_CHAIN_LENGTH);
  1043. write_selectors (encoded_name + tail_index);
  1044. return NULL;
  1045. }
  1046. else if (ada_renaming_type (SYMBOL_TYPE (type_sym)) != NULL)
  1047. {
  1048. int result;
  1049. char *renaming = ada_simple_renamed_entity (type_sym);
  1050. int renaming_len = strlen (renaming);
  1051. char *new_name
  1052. = obstack_alloc (&temp_parse_space,
  1053. renaming_len + name_len - tail_index
  1054. + 1);
  1055. strcpy (new_name, renaming);
  1056. xfree (renaming);
  1057. strcpy (new_name + renaming_len, encoded_name + tail_index);
  1058. encoded_name = new_name;
  1059. name_len = renaming_len + name_len - tail_index;
  1060. goto TryAfterRenaming;
  1061. }
  1062. else if (tail_index == name_len)
  1063. return type;
  1064. else
  1065. error (_("Invalid attempt to select from type: \"%s\"."), name0.ptr);
  1066. }
  1067. else if (tail_index == name_len && nsyms == 0)
  1068. {
  1069. struct type *type = find_primitive_type (encoded_name);
  1070. if (type != NULL)
  1071. return type;
  1072. }
  1073. if (nsyms == 1)
  1074. {
  1075. write_var_from_sym (block, syms[0].block, syms[0].sym);
  1076. write_selectors (encoded_name + tail_index);
  1077. return NULL;
  1078. }
  1079. else if (nsyms == 0)
  1080. {
  1081. int i;
  1082. struct minimal_symbol *msym
  1083. = ada_lookup_simple_minsym (encoded_name);
  1084. if (msym != NULL)
  1085. {
  1086. write_exp_msymbol (msym, lookup_function_type (type_int ()),
  1087. type_int ());
  1088. /* Maybe cause error here rather than later? FIXME? */
  1089. write_selectors (encoded_name + tail_index);
  1090. return NULL;
  1091. }
  1092. if (tail_index == name_len
  1093. && strncmp (encoded_name, "standard__",
  1094. sizeof ("standard__") - 1) == 0)
  1095. error (_("No definition of \"%s\" found."), name0.ptr);
  1096. tail_index = chop_selector (encoded_name, tail_index);
  1097. }
  1098. else
  1099. {
  1100. write_ambiguous_var (block, encoded_name, tail_index);
  1101. write_selectors (encoded_name + tail_index);
  1102. return NULL;
  1103. }
  1104. }
  1105. if (!have_full_symbols () && !have_partial_symbols () && block == NULL)
  1106. error (_("No symbol table is loaded. Use the \"file\" command."));
  1107. if (block == expression_context_block)
  1108. error (_("No definition of \"%s\" in current context."), name0.ptr);
  1109. else
  1110. error (_("No definition of \"%s\" in specified context."), name0.ptr);
  1111. TryAfterRenaming: ;
  1112. }
  1113. error (_("Could not find renamed symbol \"%s\""), name0.ptr);
  1114. }
  1115. /* Write a left side of a component association (e.g., NAME in NAME =>
  1116. exp). If NAME has the form of a selected component, write it as an
  1117. ordinary expression. If it is a simple variable that unambiguously
  1118. corresponds to exactly one symbol that does not denote a type or an
  1119. object renaming, also write it normally as an OP_VAR_VALUE.
  1120. Otherwise, write it as an OP_NAME.
  1121. Unfortunately, we don't know at this point whether NAME is supposed
  1122. to denote a record component name or the value of an array index.
  1123. Therefore, it is not appropriate to disambiguate an ambiguous name
  1124. as we normally would, nor to replace a renaming with its referent.
  1125. As a result, in the (one hopes) rare case that one writes an
  1126. aggregate such as (R => 42) where R renames an object or is an
  1127. ambiguous name, one must write instead ((R) => 42). */
  1128. static void
  1129. write_name_assoc (struct stoken name)
  1130. {
  1131. if (strchr (name.ptr, '.') == NULL)
  1132. {
  1133. struct ada_symbol_info *syms;
  1134. int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
  1135. VAR_DOMAIN, &syms);
  1136. if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
  1137. write_exp_op_with_string (OP_NAME, name);
  1138. else
  1139. write_var_from_sym (NULL, syms[0].block, syms[0].sym);
  1140. }
  1141. else
  1142. if (write_var_or_type (NULL, name) != NULL)
  1143. error (_("Invalid use of type."));
  1144. }
  1145. /* Convert the character literal whose ASCII value would be VAL to the
  1146. appropriate value of type TYPE, if there is a translation.
  1147. Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
  1148. the literal 'A' (VAL == 65), returns 0. */
  1149. static LONGEST
  1150. convert_char_literal (struct type *type, LONGEST val)
  1151. {
  1152. char name[7];
  1153. int f;
  1154. if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
  1155. return val;
  1156. sprintf (name, "QU%02x", (int) val);
  1157. for (f = 0; f < TYPE_NFIELDS (type); f += 1)
  1158. {
  1159. if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
  1160. return TYPE_FIELD_BITPOS (type, f);
  1161. }
  1162. return val;
  1163. }
  1164. static struct type *
  1165. type_int (void)
  1166. {
  1167. return builtin_type (current_gdbarch)->builtin_int;
  1168. }
  1169. static struct type *
  1170. type_long (void)
  1171. {
  1172. return builtin_type (current_gdbarch)->builtin_long;
  1173. }
  1174. static struct type *
  1175. type_long_long (void)
  1176. {
  1177. return builtin_type (current_gdbarch)->builtin_long_long;
  1178. }
  1179. static struct type *
  1180. type_float (void)
  1181. {
  1182. return builtin_type (current_gdbarch)->builtin_float;
  1183. }
  1184. static struct type *
  1185. type_double (void)
  1186. {
  1187. return builtin_type (current_gdbarch)->builtin_double;
  1188. }
  1189. static struct type *
  1190. type_long_double (void)
  1191. {
  1192. return builtin_type (current_gdbarch)->builtin_long_double;
  1193. }
  1194. static struct type *
  1195. type_char (void)
  1196. {
  1197. return language_string_char_type (current_language, current_gdbarch);
  1198. }
  1199. static struct type *
  1200. type_system_address (void)
  1201. {
  1202. struct type *type
  1203. = language_lookup_primitive_type_by_name (current_language,
  1204. current_gdbarch,
  1205. "system__address");
  1206. return type != NULL ? type : lookup_pointer_type (builtin_type_void);
  1207. }
  1208. void
  1209. _initialize_ada_exp (void)
  1210. {
  1211. obstack_init (&temp_parse_space);
  1212. }
  1213. /* FIXME: hilfingr/2004-10-05: Hack to remove warning. The function
  1214. string_to_operator is supposed to be used for cases where one
  1215. calls an operator function with prefix notation, as in
  1216. "+" (a, b), but at some point, this code seems to have gone
  1217. missing. */
  1218. struct stoken (*dummy_string_to_ada_operator) (struct stoken)
  1219. = string_to_operator;