PageRenderTime 68ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

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

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