PageRenderTime 67ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/insight-7.4.50/gdb/ada-exp.y

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