PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/opensource.apple.com/source/gdb/gdb-413/src/gdb/ada-exp.y

#
Happy | 994 lines | 855 code | 139 blank | 0 comment | 0 complexity | d41744e446bea42e0abd22e39303fe5e MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>ada-exp.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">ada-exp.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. /* YACC parser for Ada expressions, for GDB.
  24. Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 1997, 2000, 2003
  25. Free Software Foundation, Inc.
  26. This file is part of GDB.
  27. This program is free software; you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation; either version 2 of the License, or
  30. (at your option) any later version.
  31. This program is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. GNU General Public License for more details.
  35. You should have received a copy of the GNU General Public License
  36. along with this program; if not, write to the Free Software
  37. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  38. /* Parse an Ada expression from text in a string,
  39. and return the result as a struct expression pointer.
  40. That structure contains arithmetic operations in reverse polish,
  41. with constants represented by operations that are followed by special data.
  42. See expression.h for the details of the format.
  43. What is important here is that it can be built up sequentially
  44. during the process of parsing; the lower levels of the tree always
  45. come first in the result.
  46. malloc's and realloc's in this file are transformed to
  47. xmalloc and xrealloc respectively by the same sed command in the
  48. makefile that remaps any other malloc/realloc inserted by the parser
  49. generator. Doing this with #defines and trying to control the interaction
  50. with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for example) just became
  51. too messy, particularly when such includes can be inserted at random
  52. times by the parser generator. */
  53. %{
  54. #include &quot;defs.h&quot;
  55. #include &lt;string.h&gt;
  56. #include &lt;ctype.h&gt;
  57. #include &quot;expression.h&quot;
  58. #include &quot;value.h&quot;
  59. #include &quot;parser-defs.h&quot;
  60. #include &quot;language.h&quot;
  61. #include &quot;ada-lang.h&quot;
  62. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  63. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  64. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols */
  65. #include &quot;frame.h&quot;
  66. #include &quot;block.h&quot;
  67. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  68. as well as gratuitiously global symbol names, so we can have multiple
  69. yacc generated parsers in gdb. These are only the variables
  70. produced by yacc. If other parser generators (bison, byacc, etc) produce
  71. additional global names that conflict at link time, then those parser
  72. generators need to be fixed instead of adding those names to this list. */
  73. /* NOTE: This is clumsy, especially since BISON and FLEX provide --prefix
  74. options. I presume we are maintaining it to accommodate systems
  75. without BISON? (PNH) */
  76. #define yymaxdepth ada_maxdepth
  77. #define yyparse _ada_parse /* ada_parse calls this after initialization */
  78. #define yylex ada_lex
  79. #define yyerror ada_error
  80. #define yylval ada_lval
  81. #define yychar ada_char
  82. #define yydebug ada_debug
  83. #define yypact ada_pact
  84. #define yyr1 ada_r1
  85. #define yyr2 ada_r2
  86. #define yydef ada_def
  87. #define yychk ada_chk
  88. #define yypgo ada_pgo
  89. #define yyact ada_act
  90. #define yyexca ada_exca
  91. #define yyerrflag ada_errflag
  92. #define yynerrs ada_nerrs
  93. #define yyps ada_ps
  94. #define yypv ada_pv
  95. #define yys ada_s
  96. #define yy_yys ada_yys
  97. #define yystate ada_state
  98. #define yytmp ada_tmp
  99. #define yyv ada_v
  100. #define yy_yyv ada_yyv
  101. #define yyval ada_val
  102. #define yylloc ada_lloc
  103. #define yyreds ada_reds /* With YYDEBUG defined */
  104. #define yytoks ada_toks /* With YYDEBUG defined */
  105. #define yyname ada_name /* With YYDEBUG defined */
  106. #define yyrule ada_rule /* With YYDEBUG defined */
  107. #ifndef YYDEBUG
  108. #define YYDEBUG 1 /* Default to yydebug support */
  109. #endif
  110. #define YYFPRINTF parser_fprintf
  111. struct name_info {
  112. struct symbol* sym;
  113. struct minimal_symbol* msym;
  114. struct block* block;
  115. struct stoken stoken;
  116. };
  117. /* If expression is in the context of TYPE'(...), then TYPE, else
  118. * NULL. */
  119. static struct type* type_qualifier;
  120. int yyparse (void);
  121. static int yylex (void);
  122. void yyerror (char *);
  123. static struct stoken string_to_operator (struct stoken);
  124. static void write_attribute_call0 (enum ada_attribute);
  125. static void write_attribute_call1 (enum ada_attribute, LONGEST);
  126. static void write_attribute_calln (enum ada_attribute, int);
  127. static void write_object_renaming (struct block*, struct symbol*);
  128. static void write_var_from_name (struct block*, struct name_info);
  129. static LONGEST
  130. convert_char_literal (struct type*, LONGEST);
  131. %}
  132. %union
  133. {
  134. LONGEST lval;
  135. struct {
  136. LONGEST val;
  137. struct type *type;
  138. } typed_val;
  139. struct {
  140. DOUBLEST dval;
  141. struct type *type;
  142. } typed_val_float;
  143. struct type *tval;
  144. struct stoken sval;
  145. struct name_info ssym;
  146. int voidval;
  147. struct block *bval;
  148. struct internalvar *ivar;
  149. }
  150. %type &lt;voidval&gt; exp exp1 simple_exp start variable
  151. %type &lt;tval&gt; type
  152. %token &lt;typed_val&gt; INT NULL_PTR CHARLIT
  153. %token &lt;typed_val_float&gt; FLOAT
  154. %token &lt;tval&gt; TYPENAME
  155. %token &lt;bval&gt; BLOCKNAME
  156. /* Both NAME and TYPENAME tokens represent symbols in the input,
  157. and both convey their data as strings.
  158. But a TYPENAME is a string that happens to be defined as a typedef
  159. or builtin type name (such as int or char)
  160. and a NAME is any other symbol.
  161. Contexts where this distinction is not important can use the
  162. nonterminal &quot;name&quot;, which matches either NAME or TYPENAME. */
  163. %token &lt;sval&gt; STRING
  164. %token &lt;ssym&gt; NAME DOT_ID OBJECT_RENAMING
  165. %type &lt;bval&gt; block
  166. %type &lt;lval&gt; arglist tick_arglist
  167. %type &lt;tval&gt; save_qualifier
  168. %token DOT_ALL
  169. /* Special type cases, put in to allow the parser to distinguish different
  170. legal basetypes. */
  171. %token &lt;lval&gt; LAST REGNAME
  172. %token &lt;ivar&gt; INTERNAL_VARIABLE
  173. %nonassoc ASSIGN
  174. %left _AND_ OR XOR THEN ELSE
  175. %left '=' NOTEQUAL '&lt;' '&gt;' LEQ GEQ IN DOTDOT
  176. %left '@'
  177. %left '+' '-' '&amp;'
  178. %left UNARY
  179. %left '*' '/' MOD REM
  180. %right STARSTAR ABS NOT
  181. /* The following are right-associative only so that reductions at this
  182. precedence have lower precedence than '.' and '('. The syntax still
  183. forces a.b.c, e.g., to be LEFT-associated. */
  184. %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
  185. %right TICK_MAX TICK_MIN TICK_MODULUS
  186. %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
  187. %right '.' '(' '[' DOT_ID DOT_ALL
  188. %token ARROW NEW
  189. %%
  190. start : exp1
  191. | type { write_exp_elt_opcode (OP_TYPE);
  192. write_exp_elt_type ($1);
  193. write_exp_elt_opcode (OP_TYPE); }
  194. ;
  195. /* Expressions, including the sequencing operator. */
  196. exp1 : exp
  197. | exp1 ';' exp
  198. { write_exp_elt_opcode (BINOP_COMMA); }
  199. ;
  200. /* Expressions, not including the sequencing operator. */
  201. simple_exp : simple_exp DOT_ALL
  202. { write_exp_elt_opcode (UNOP_IND); }
  203. ;
  204. simple_exp : simple_exp DOT_ID
  205. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  206. write_exp_string ($2.stoken);
  207. write_exp_elt_opcode (STRUCTOP_STRUCT);
  208. }
  209. ;
  210. simple_exp : simple_exp '(' arglist ')'
  211. {
  212. write_exp_elt_opcode (OP_FUNCALL);
  213. write_exp_elt_longcst ($3);
  214. write_exp_elt_opcode (OP_FUNCALL);
  215. }
  216. ;
  217. simple_exp : type '(' exp ')'
  218. {
  219. write_exp_elt_opcode (UNOP_CAST);
  220. write_exp_elt_type ($1);
  221. write_exp_elt_opcode (UNOP_CAST);
  222. }
  223. ;
  224. simple_exp : type '\'' save_qualifier { type_qualifier = $1; } '(' exp ')'
  225. {
  226. /* write_exp_elt_opcode (UNOP_QUAL); */
  227. /* FIXME: UNOP_QUAL should be defined in expression.h */
  228. write_exp_elt_type ($1);
  229. /* write_exp_elt_opcode (UNOP_QUAL); */
  230. /* FIXME: UNOP_QUAL should be defined in expression.h */
  231. type_qualifier = $3;
  232. }
  233. ;
  234. save_qualifier : { $$ = type_qualifier; }
  235. ;
  236. simple_exp :
  237. simple_exp '(' exp DOTDOT exp ')'
  238. { write_exp_elt_opcode (TERNOP_SLICE); }
  239. ;
  240. simple_exp : '(' exp1 ')' { }
  241. ;
  242. simple_exp : variable
  243. ;
  244. simple_exp: REGNAME /* GDB extension */
  245. { write_exp_elt_opcode (OP_REGISTER);
  246. write_exp_elt_longcst ((LONGEST) $1);
  247. write_exp_elt_opcode (OP_REGISTER);
  248. }
  249. ;
  250. simple_exp: INTERNAL_VARIABLE /* GDB extension */
  251. { write_exp_elt_opcode (OP_INTERNALVAR);
  252. write_exp_elt_intern ($1);
  253. write_exp_elt_opcode (OP_INTERNALVAR);
  254. }
  255. ;
  256. exp : simple_exp
  257. ;
  258. simple_exp: LAST
  259. { write_exp_elt_opcode (OP_LAST);
  260. write_exp_elt_longcst ((LONGEST) $1);
  261. write_exp_elt_opcode (OP_LAST);
  262. }
  263. ;
  264. exp : exp ASSIGN exp /* Extension for convenience */
  265. { write_exp_elt_opcode (BINOP_ASSIGN); }
  266. ;
  267. exp : '-' exp %prec UNARY
  268. { write_exp_elt_opcode (UNOP_NEG); }
  269. ;
  270. exp : '+' exp %prec UNARY
  271. { write_exp_elt_opcode (UNOP_PLUS); }
  272. ;
  273. exp : NOT exp %prec UNARY
  274. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  275. ;
  276. exp : ABS exp %prec UNARY
  277. { write_exp_elt_opcode (UNOP_ABS); }
  278. ;
  279. arglist : { $$ = 0; }
  280. ;
  281. arglist : exp
  282. { $$ = 1; }
  283. | any_name ARROW exp
  284. { $$ = 1; }
  285. | arglist ',' exp
  286. { $$ = $1 + 1; }
  287. | arglist ',' any_name ARROW exp
  288. { $$ = $1 + 1; }
  289. ;
  290. exp : '{' type '}' exp %prec '.'
  291. /* GDB extension */
  292. { write_exp_elt_opcode (UNOP_MEMVAL);
  293. write_exp_elt_type ($2);
  294. write_exp_elt_opcode (UNOP_MEMVAL);
  295. }
  296. ;
  297. /* Binary operators in order of decreasing precedence. */
  298. exp : exp STARSTAR exp
  299. { write_exp_elt_opcode (BINOP_EXP); }
  300. ;
  301. exp : exp '*' exp
  302. { write_exp_elt_opcode (BINOP_MUL); }
  303. ;
  304. exp : exp '/' exp
  305. { write_exp_elt_opcode (BINOP_DIV); }
  306. ;
  307. exp : exp REM exp /* May need to be fixed to give correct Ada REM */
  308. { write_exp_elt_opcode (BINOP_REM); }
  309. ;
  310. exp : exp MOD exp
  311. { write_exp_elt_opcode (BINOP_MOD); }
  312. ;
  313. exp : exp '@' exp /* GDB extension */
  314. { write_exp_elt_opcode (BINOP_REPEAT); }
  315. ;
  316. exp : exp '+' exp
  317. { write_exp_elt_opcode (BINOP_ADD); }
  318. ;
  319. exp : exp '&amp;' exp
  320. { write_exp_elt_opcode (BINOP_CONCAT); }
  321. ;
  322. exp : exp '-' exp
  323. { write_exp_elt_opcode (BINOP_SUB); }
  324. ;
  325. exp : exp '=' exp
  326. { write_exp_elt_opcode (BINOP_EQUAL); }
  327. ;
  328. exp : exp NOTEQUAL exp
  329. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  330. ;
  331. exp : exp LEQ exp
  332. { write_exp_elt_opcode (BINOP_LEQ); }
  333. ;
  334. exp : exp IN exp DOTDOT exp
  335. { /*write_exp_elt_opcode (TERNOP_MBR); */ }
  336. /* FIXME: TERNOP_MBR should be defined in
  337. expression.h */
  338. | exp IN exp TICK_RANGE tick_arglist
  339. { /*write_exp_elt_opcode (BINOP_MBR); */
  340. /* FIXME: BINOP_MBR should be defined in expression.h */
  341. write_exp_elt_longcst ((LONGEST) $5);
  342. /*write_exp_elt_opcode (BINOP_MBR); */
  343. }
  344. | exp IN TYPENAME %prec TICK_ACCESS
  345. { /*write_exp_elt_opcode (UNOP_MBR); */
  346. /* FIXME: UNOP_QUAL should be defined in expression.h */
  347. write_exp_elt_type ($3);
  348. /* write_exp_elt_opcode (UNOP_MBR); */
  349. /* FIXME: UNOP_MBR should be defined in expression.h */
  350. }
  351. | exp NOT IN exp DOTDOT exp
  352. { /*write_exp_elt_opcode (TERNOP_MBR); */
  353. /* FIXME: TERNOP_MBR should be defined in expression.h */
  354. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  355. }
  356. | exp NOT IN exp TICK_RANGE tick_arglist
  357. { /* write_exp_elt_opcode (BINOP_MBR); */
  358. /* FIXME: BINOP_MBR should be defined in expression.h */
  359. write_exp_elt_longcst ((LONGEST) $6);
  360. /*write_exp_elt_opcode (BINOP_MBR);*/
  361. /* FIXME: BINOP_MBR should be defined in expression.h */
  362. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  363. }
  364. | exp NOT IN TYPENAME %prec TICK_ACCESS
  365. { /*write_exp_elt_opcode (UNOP_MBR);*/
  366. /* FIXME: UNOP_MBR should be defined in expression.h */
  367. write_exp_elt_type ($4);
  368. /* write_exp_elt_opcode (UNOP_MBR);*/
  369. /* FIXME: UNOP_MBR should be defined in expression.h */
  370. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  371. }
  372. ;
  373. exp : exp GEQ exp
  374. { write_exp_elt_opcode (BINOP_GEQ); }
  375. ;
  376. exp : exp '&lt;' exp
  377. { write_exp_elt_opcode (BINOP_LESS); }
  378. ;
  379. exp : exp '&gt;' exp
  380. { write_exp_elt_opcode (BINOP_GTR); }
  381. ;
  382. exp : exp _AND_ exp /* Fix for Ada elementwise AND. */
  383. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  384. ;
  385. exp : exp _AND_ THEN exp %prec _AND_
  386. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  387. ;
  388. exp : exp OR exp /* Fix for Ada elementwise OR */
  389. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  390. ;
  391. exp : exp OR ELSE exp
  392. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  393. ;
  394. exp : exp XOR exp /* Fix for Ada elementwise XOR */
  395. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  396. ;
  397. simple_exp : simple_exp TICK_ACCESS
  398. { write_exp_elt_opcode (UNOP_ADDR); }
  399. | simple_exp TICK_ADDRESS
  400. { write_exp_elt_opcode (UNOP_ADDR);
  401. write_exp_elt_opcode (UNOP_CAST);
  402. write_exp_elt_type (builtin_type_ada_system_address);
  403. write_exp_elt_opcode (UNOP_CAST);
  404. }
  405. | simple_exp TICK_FIRST tick_arglist
  406. { write_attribute_call1 (ATR_FIRST, $3); }
  407. | simple_exp TICK_LAST tick_arglist
  408. { write_attribute_call1 (ATR_LAST, $3); }
  409. | simple_exp TICK_LENGTH tick_arglist
  410. { write_attribute_call1 (ATR_LENGTH, $3); }
  411. | simple_exp TICK_SIZE
  412. { write_attribute_call0 (ATR_SIZE); }
  413. | simple_exp TICK_TAG
  414. { write_attribute_call0 (ATR_TAG); }
  415. | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
  416. { write_attribute_calln (ATR_MIN, 2); }
  417. | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
  418. { write_attribute_calln (ATR_MAX, 2); }
  419. | opt_type_prefix TICK_POS '(' exp ')'
  420. { write_attribute_calln (ATR_POS, 1); }
  421. | type_prefix TICK_FIRST tick_arglist
  422. { write_attribute_call1 (ATR_FIRST, $3); }
  423. | type_prefix TICK_LAST tick_arglist
  424. { write_attribute_call1 (ATR_LAST, $3); }
  425. | type_prefix TICK_LENGTH tick_arglist
  426. { write_attribute_call1 (ATR_LENGTH, $3); }
  427. | type_prefix TICK_VAL '(' exp ')'
  428. { write_attribute_calln (ATR_VAL, 1); }
  429. | type_prefix TICK_MODULUS
  430. { write_attribute_call0 (ATR_MODULUS); }
  431. ;
  432. tick_arglist : %prec '('
  433. { $$ = 1; }
  434. | '(' INT ')'
  435. { $$ = $2.val; }
  436. ;
  437. type_prefix :
  438. TYPENAME
  439. { write_exp_elt_opcode (OP_TYPE);
  440. write_exp_elt_type ($1);
  441. write_exp_elt_opcode (OP_TYPE); }
  442. ;
  443. opt_type_prefix :
  444. type_prefix
  445. | /* EMPTY */
  446. { write_exp_elt_opcode (OP_TYPE);
  447. write_exp_elt_type (builtin_type_void);
  448. write_exp_elt_opcode (OP_TYPE); }
  449. ;
  450. exp : INT
  451. { write_exp_elt_opcode (OP_LONG);
  452. write_exp_elt_type ($1.type);
  453. write_exp_elt_longcst ((LONGEST)($1.val));
  454. write_exp_elt_opcode (OP_LONG);
  455. }
  456. ;
  457. exp : CHARLIT
  458. { write_exp_elt_opcode (OP_LONG);
  459. if (type_qualifier == NULL)
  460. write_exp_elt_type ($1.type);
  461. else
  462. write_exp_elt_type (type_qualifier);
  463. write_exp_elt_longcst
  464. (convert_char_literal (type_qualifier, $1.val));
  465. write_exp_elt_opcode (OP_LONG);
  466. }
  467. ;
  468. exp : FLOAT
  469. { write_exp_elt_opcode (OP_DOUBLE);
  470. write_exp_elt_type ($1.type);
  471. write_exp_elt_dblcst ($1.dval);
  472. write_exp_elt_opcode (OP_DOUBLE);
  473. }
  474. ;
  475. exp : NULL_PTR
  476. { write_exp_elt_opcode (OP_LONG);
  477. write_exp_elt_type (builtin_type_int);
  478. write_exp_elt_longcst ((LONGEST)(0));
  479. write_exp_elt_opcode (OP_LONG);
  480. }
  481. ;
  482. exp : STRING
  483. { /* Ada strings are converted into array constants
  484. a lower bound of 1. Thus, the array upper bound
  485. is the string length. */
  486. char *sp = $1.ptr; int count;
  487. if ($1.length == 0)
  488. { /* One dummy character for the type */
  489. write_exp_elt_opcode (OP_LONG);
  490. write_exp_elt_type (builtin_type_ada_char);
  491. write_exp_elt_longcst ((LONGEST)(0));
  492. write_exp_elt_opcode (OP_LONG);
  493. }
  494. for (count = $1.length; count &gt; 0; count -= 1)
  495. {
  496. write_exp_elt_opcode (OP_LONG);
  497. write_exp_elt_type (builtin_type_ada_char);
  498. write_exp_elt_longcst ((LONGEST)(*sp));
  499. sp += 1;
  500. write_exp_elt_opcode (OP_LONG);
  501. }
  502. write_exp_elt_opcode (OP_ARRAY);
  503. write_exp_elt_longcst ((LONGEST) 1);
  504. write_exp_elt_longcst ((LONGEST) ($1.length));
  505. write_exp_elt_opcode (OP_ARRAY);
  506. }
  507. ;
  508. exp : NEW TYPENAME
  509. { error (&quot;NEW not implemented.&quot;); }
  510. ;
  511. variable: NAME { write_var_from_name (NULL, $1); }
  512. | block NAME /* GDB extension */
  513. { write_var_from_name ($1, $2); }
  514. | OBJECT_RENAMING { write_object_renaming (NULL, $1.sym); }
  515. | block OBJECT_RENAMING
  516. { write_object_renaming ($1, $2.sym); }
  517. ;
  518. any_name : NAME { }
  519. | TYPENAME { }
  520. | OBJECT_RENAMING { }
  521. ;
  522. block : BLOCKNAME /* GDB extension */
  523. { $$ = $1; }
  524. | block BLOCKNAME /* GDB extension */
  525. { $$ = $2; }
  526. ;
  527. type : TYPENAME { $$ = $1; }
  528. | block TYPENAME { $$ = $2; }
  529. | TYPENAME TICK_ACCESS
  530. { $$ = lookup_pointer_type ($1); }
  531. | block TYPENAME TICK_ACCESS
  532. { $$ = lookup_pointer_type ($2); }
  533. ;
  534. /* Some extensions borrowed from C, for the benefit of those who find they
  535. can't get used to Ada notation in GDB. */
  536. exp : '*' exp %prec '.'
  537. { write_exp_elt_opcode (UNOP_IND); }
  538. | '&amp;' exp %prec '.'
  539. { write_exp_elt_opcode (UNOP_ADDR); }
  540. | exp '[' exp ']'
  541. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  542. ;
  543. %%
  544. /* yylex defined in ada-lex.c: Reads one token, getting characters */
  545. /* through lexptr. */
  546. /* Remap normal flex interface names (yylex) as well as gratuitiously */
  547. /* global symbol names, so we can have multiple flex-generated parsers */
  548. /* in gdb. */
  549. /* (See note above on previous definitions for YACC.) */
  550. #define yy_create_buffer ada_yy_create_buffer
  551. #define yy_delete_buffer ada_yy_delete_buffer
  552. #define yy_init_buffer ada_yy_init_buffer
  553. #define yy_load_buffer_state ada_yy_load_buffer_state
  554. #define yy_switch_to_buffer ada_yy_switch_to_buffer
  555. #define yyrestart ada_yyrestart
  556. #define yytext ada_yytext
  557. #define yywrap ada_yywrap
  558. /* The following kludge was found necessary to prevent conflicts between */
  559. /* defs.h and non-standard stdlib.h files. */
  560. #define qsort __qsort__dummy
  561. #include &quot;ada-lex.c&quot;
  562. int
  563. ada_parse ()
  564. {
  565. lexer_init (yyin); /* (Re-)initialize lexer. */
  566. left_block_context = NULL;
  567. type_qualifier = NULL;
  568. return _ada_parse ();
  569. }
  570. void
  571. yyerror (msg)
  572. char *msg;
  573. {
  574. error (&quot;A %s in expression, near `%s'.&quot;, (msg ? msg : &quot;error&quot;), lexptr);
  575. }
  576. /* The operator name corresponding to operator symbol STRING (adds
  577. quotes and maps to lower-case). Destroys the previous contents of
  578. the array pointed to by STRING.ptr. Error if STRING does not match
  579. a valid Ada operator. Assumes that STRING.ptr points to a
  580. null-terminated string and that, if STRING is a valid operator
  581. symbol, the array pointed to by STRING.ptr contains at least
  582. STRING.length+3 characters. */
  583. static struct stoken
  584. string_to_operator (string)
  585. struct stoken string;
  586. {
  587. int i;
  588. for (i = 0; ada_opname_table[i].mangled != NULL; i += 1)
  589. {
  590. if (string.length == strlen (ada_opname_table[i].demangled)-2
  591. &amp;&amp; strncasecmp (string.ptr, ada_opname_table[i].demangled+1,
  592. string.length) == 0)
  593. {
  594. strncpy (string.ptr, ada_opname_table[i].demangled,
  595. string.length+2);
  596. string.length += 2;
  597. return string;
  598. }
  599. }
  600. error (&quot;Invalid operator symbol `%s'&quot;, string.ptr);
  601. }
  602. /* Emit expression to access an instance of SYM, in block BLOCK (if
  603. * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
  604. static void
  605. write_var_from_sym (orig_left_context, block, sym)
  606. struct block* orig_left_context;
  607. struct block* block;
  608. struct symbol* sym;
  609. {
  610. if (orig_left_context == NULL &amp;&amp; symbol_read_needs_frame (sym))
  611. {
  612. if (innermost_block == 0 ||
  613. contained_in (block, innermost_block))
  614. innermost_block = block;
  615. }
  616. write_exp_elt_opcode (OP_VAR_VALUE);
  617. /* We want to use the selected frame, not another more inner frame
  618. which happens to be in the same block */
  619. write_exp_elt_block (NULL);
  620. write_exp_elt_sym (sym);
  621. write_exp_elt_opcode (OP_VAR_VALUE);
  622. }
  623. /* Emit expression to access an instance of NAME. */
  624. static void
  625. write_var_from_name (orig_left_context, name)
  626. struct block* orig_left_context;
  627. struct name_info name;
  628. {
  629. if (name.msym != NULL)
  630. {
  631. write_exp_msymbol (name.msym,
  632. lookup_function_type (builtin_type_int),
  633. builtin_type_int);
  634. }
  635. else if (name.sym == NULL)
  636. {
  637. /* Multiple matches: record name and starting block for later
  638. resolution by ada_resolve. */
  639. /* write_exp_elt_opcode (OP_UNRESOLVED_VALUE); */
  640. /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
  641. write_exp_elt_block (name.block);
  642. /* write_exp_elt_name (name.stoken.ptr); */
  643. /* FIXME: write_exp_elt_name should be defined in defs.h, located in parse.c */
  644. /* write_exp_elt_opcode (OP_UNRESOLVED_VALUE); */
  645. /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
  646. }
  647. else
  648. write_var_from_sym (orig_left_context, name.block, name.sym);
  649. }
  650. /* Write a call on parameterless attribute ATR. */
  651. static void
  652. write_attribute_call0 (atr)
  653. enum ada_attribute atr;
  654. {
  655. /* write_exp_elt_opcode (OP_ATTRIBUTE); */
  656. /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
  657. write_exp_elt_longcst ((LONGEST) 0);
  658. write_exp_elt_longcst ((LONGEST) atr);
  659. /* write_exp_elt_opcode (OP_ATTRIBUTE); */
  660. /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
  661. }
  662. /* Write a call on an attribute ATR with one constant integer
  663. * parameter. */
  664. static void
  665. write_attribute_call1 (atr, arg)
  666. enum ada_attribute atr;
  667. LONGEST arg;
  668. {
  669. write_exp_elt_opcode (OP_LONG);
  670. write_exp_elt_type (builtin_type_int);
  671. write_exp_elt_longcst (arg);
  672. write_exp_elt_opcode (OP_LONG);
  673. /*write_exp_elt_opcode (OP_ATTRIBUTE);*/
  674. /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
  675. write_exp_elt_longcst ((LONGEST) 1);
  676. write_exp_elt_longcst ((LONGEST) atr);
  677. /*write_exp_elt_opcode (OP_ATTRIBUTE);*/
  678. /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
  679. }
  680. /* Write a call on an attribute ATR with N parameters, whose code must have
  681. * been generated previously. */
  682. static void
  683. write_attribute_calln (atr, n)
  684. enum ada_attribute atr;
  685. int n;
  686. {
  687. /*write_exp_elt_opcode (OP_ATTRIBUTE);*/
  688. /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
  689. write_exp_elt_longcst ((LONGEST) n);
  690. write_exp_elt_longcst ((LONGEST) atr);
  691. /* write_exp_elt_opcode (OP_ATTRIBUTE);*/
  692. /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
  693. }
  694. /* Emit expression corresponding to the renamed object designated by
  695. * the type RENAMING, which must be the referent of an object renaming
  696. * type, in the context of ORIG_LEFT_CONTEXT (?). */
  697. static void
  698. write_object_renaming (orig_left_context, renaming)
  699. struct block* orig_left_context;
  700. struct symbol* renaming;
  701. {
  702. const char* qualification = DEPRECATED_SYMBOL_NAME (renaming);
  703. const char* simple_tail;
  704. const char* expr = TYPE_FIELD_NAME (SYMBOL_TYPE (renaming), 0);
  705. const char* suffix;
  706. char* name;
  707. struct symbol* sym;
  708. enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
  709. /* if orig_left_context is null, then use the currently selected
  710. block, otherwise we might fail our symbol lookup below */
  711. if (orig_left_context == NULL)
  712. orig_left_context = get_selected_block (NULL);
  713. for (simple_tail = qualification + strlen (qualification);
  714. simple_tail != qualification; simple_tail -= 1)
  715. {
  716. if (*simple_tail == '.')
  717. {
  718. simple_tail += 1;
  719. break;
  720. }
  721. else if (DEPRECATED_STREQN (simple_tail, &quot;__&quot;, 2))
  722. {
  723. simple_tail += 2;
  724. break;
  725. }
  726. }
  727. suffix = strstr (expr, &quot;___XE&quot;);
  728. if (suffix == NULL)
  729. goto BadEncoding;
  730. name = (char*) malloc (suffix - expr + 1);
  731. /* add_name_string_cleanup (name); */
  732. /* FIXME: add_name_string_cleanup should be defined in
  733. parser-defs.h, implemented in parse.c */
  734. strncpy (name, expr, suffix-expr);
  735. name[suffix-expr] = '\000';
  736. sym = lookup_symbol (name, orig_left_context, VAR_DOMAIN, 0, NULL);
  737. /* if (sym == NULL)
  738. error (&quot;Could not find renamed variable: %s&quot;, ada_demangle (name));
  739. */
  740. /* FIXME: ada_demangle should be defined in defs.h, implemented in ada-lang.c */
  741. write_var_from_sym (orig_left_context, block_found, sym);
  742. suffix += 5;
  743. slice_state = SIMPLE_INDEX;
  744. while (*suffix == 'X')
  745. {
  746. suffix += 1;
  747. switch (*suffix) {
  748. case 'L':
  749. slice_state = LOWER_BOUND;
  750. case 'S':
  751. suffix += 1;
  752. if (isdigit (*suffix))
  753. {
  754. char* next;
  755. long val = strtol (suffix, &amp;next, 10);
  756. if (next == suffix)
  757. goto BadEncoding;
  758. suffix = next;
  759. write_exp_elt_opcode (OP_LONG);
  760. write_exp_elt_type (builtin_type_ada_int);
  761. write_exp_elt_longcst ((LONGEST) val);
  762. write_exp_elt_opcode (OP_LONG);
  763. }
  764. else
  765. {
  766. const char* end;
  767. char* index_name;
  768. int index_len;
  769. struct symbol* index_sym;
  770. end = strchr (suffix, 'X');
  771. if (end == NULL)
  772. end = suffix + strlen (suffix);
  773. index_len = simple_tail - qualification + 2 + (suffix - end) + 1;
  774. index_name = (char*) malloc (index_len);
  775. memset (index_name, '\000', index_len);
  776. /* add_name_string_cleanup (index_name);*/
  777. /* FIXME: add_name_string_cleanup should be defined in
  778. parser-defs.h, implemented in parse.c */
  779. strncpy (index_name, qualification, simple_tail - qualification);
  780. index_name[simple_tail - qualification] = '\000';
  781. strncat (index_name, suffix, suffix-end);
  782. suffix = end;
  783. index_sym =
  784. lookup_symbol (index_name, NULL, VAR_DOMAIN, 0, NULL);
  785. if (index_sym == NULL)
  786. error (&quot;Could not find %s&quot;, index_name);
  787. write_var_from_sym (NULL, block_found, sym);
  788. }
  789. if (slice_state == SIMPLE_INDEX)
  790. {
  791. write_exp_elt_opcode (OP_FUNCALL);
  792. write_exp_elt_longcst ((LONGEST) 1);
  793. write_exp_elt_opcode (OP_FUNCALL);
  794. }
  795. else if (slice_state == LOWER_BOUND)
  796. slice_state = UPPER_BOUND;
  797. else if (slice_state == UPPER_BOUND)
  798. {
  799. write_exp_elt_opcode (TERNOP_SLICE);
  800. slice_state = SIMPLE_INDEX;
  801. }
  802. break;
  803. case 'R':
  804. {
  805. struct stoken field_name;
  806. const char* end;
  807. suffix += 1;
  808. if (slice_state != SIMPLE_INDEX)
  809. goto BadEncoding;
  810. end = strchr (suffix, 'X');
  811. if (end == NULL)
  812. end = suffix + strlen (suffix);
  813. field_name.length = end - suffix;
  814. field_name.ptr = (char*) malloc (end - suffix + 1);
  815. strncpy (field_name.ptr, suffix, end - suffix);
  816. field_name.ptr[end - suffix] = '\000';
  817. suffix = end;
  818. write_exp_elt_opcode (STRUCTOP_STRUCT);
  819. write_exp_string (field_name);
  820. write_exp_elt_opcode (STRUCTOP_STRUCT);
  821. break;
  822. }
  823. default:
  824. goto BadEncoding;
  825. }
  826. }
  827. if (slice_state == SIMPLE_INDEX)
  828. return;
  829. BadEncoding:
  830. error (&quot;Internal error in encoding of renaming declaration: %s&quot;,
  831. DEPRECATED_SYMBOL_NAME (renaming));
  832. }
  833. /* Convert the character literal whose ASCII value would be VAL to the
  834. appropriate value of type TYPE, if there is a translation.
  835. Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
  836. the literal 'A' (VAL == 65), returns 0. */
  837. static LONGEST
  838. convert_char_literal (struct type* type, LONGEST val)
  839. {
  840. char name[7];
  841. int f;
  842. if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
  843. return val;
  844. sprintf (name, &quot;QU%02x&quot;, (int) val);
  845. for (f = 0; f &lt; TYPE_NFIELDS (type); f += 1)
  846. {
  847. if (DEPRECATED_STREQ (name, TYPE_FIELD_NAME (type, f)))
  848. return TYPE_FIELD_BITPOS (type, f);
  849. }
  850. return val;
  851. }
  852. </pre>
  853. <hr />
  854. </body></html>