PageRenderTime 71ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Happy | 989 lines | 837 code | 152 blank | 0 comment | 0 complexity | 79d63ac0372419188cd70f80d604dced MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
  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. 2004 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 &quot;gdb_string.h&quot;
  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_int (LONGEST, struct type *);
  125. static void write_object_renaming (struct block *, struct symbol *, int);
  126. static void write_var_from_name (struct block *, struct name_info);
  127. static LONGEST convert_char_literal (struct type *, LONGEST);
  128. static struct type *type_int (void);
  129. static struct type *type_long (void);
  130. static struct type *type_long_long (void);
  131. static struct type *type_float (void);
  132. static struct type *type_double (void);
  133. static struct type *type_long_double (void);
  134. static struct type *type_char (void);
  135. static struct type *type_system_address (void);
  136. %}
  137. %union
  138. {
  139. LONGEST lval;
  140. struct {
  141. LONGEST val;
  142. struct type *type;
  143. } typed_val;
  144. struct {
  145. DOUBLEST dval;
  146. struct type *type;
  147. } typed_val_float;
  148. struct type *tval;
  149. struct stoken sval;
  150. struct name_info ssym;
  151. int voidval;
  152. struct block *bval;
  153. struct internalvar *ivar;
  154. }
  155. %type &lt;voidval&gt; exp exp1 simple_exp start variable
  156. %type &lt;tval&gt; type
  157. %token &lt;typed_val&gt; INT NULL_PTR CHARLIT
  158. %token &lt;typed_val_float&gt; FLOAT
  159. %token &lt;tval&gt; TYPENAME
  160. %token &lt;bval&gt; BLOCKNAME
  161. /* Both NAME and TYPENAME tokens represent symbols in the input,
  162. and both convey their data as strings.
  163. But a TYPENAME is a string that happens to be defined as a typedef
  164. or builtin type name (such as int or char)
  165. and a NAME is any other symbol.
  166. Contexts where this distinction is not important can use the
  167. nonterminal &quot;name&quot;, which matches either NAME or TYPENAME. */
  168. %token &lt;sval&gt; STRING
  169. %token &lt;ssym&gt; NAME DOT_ID OBJECT_RENAMING
  170. %type &lt;bval&gt; block
  171. %type &lt;lval&gt; arglist tick_arglist
  172. %type &lt;tval&gt; save_qualifier
  173. %token DOT_ALL
  174. /* Special type cases, put in to allow the parser to distinguish different
  175. legal basetypes. */
  176. %token &lt;sval&gt; SPECIAL_VARIABLE
  177. %nonassoc ASSIGN
  178. %left _AND_ OR XOR THEN ELSE
  179. %left '=' NOTEQUAL '&lt;' '&gt;' LEQ GEQ IN DOTDOT
  180. %left '@'
  181. %left '+' '-' '&amp;'
  182. %left UNARY
  183. %left '*' '/' MOD REM
  184. %right STARSTAR ABS NOT
  185. /* The following are right-associative only so that reductions at this
  186. precedence have lower precedence than '.' and '('. The syntax still
  187. forces a.b.c, e.g., to be LEFT-associated. */
  188. %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
  189. %right TICK_MAX TICK_MIN TICK_MODULUS
  190. %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
  191. %right '.' '(' '[' DOT_ID DOT_ALL
  192. %token ARROW NEW
  193. %%
  194. start : exp1
  195. | type { write_exp_elt_opcode (OP_TYPE);
  196. write_exp_elt_type ($1);
  197. write_exp_elt_opcode (OP_TYPE); }
  198. ;
  199. /* Expressions, including the sequencing operator. */
  200. exp1 : exp
  201. | exp1 ';' exp
  202. { write_exp_elt_opcode (BINOP_COMMA); }
  203. ;
  204. /* Expressions, not including the sequencing operator. */
  205. simple_exp : simple_exp DOT_ALL
  206. { write_exp_elt_opcode (UNOP_IND); }
  207. ;
  208. simple_exp : simple_exp DOT_ID
  209. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  210. write_exp_string ($2.stoken);
  211. write_exp_elt_opcode (STRUCTOP_STRUCT);
  212. }
  213. ;
  214. simple_exp : simple_exp '(' arglist ')'
  215. {
  216. write_exp_elt_opcode (OP_FUNCALL);
  217. write_exp_elt_longcst ($3);
  218. write_exp_elt_opcode (OP_FUNCALL);
  219. }
  220. ;
  221. simple_exp : type '(' exp ')'
  222. {
  223. write_exp_elt_opcode (UNOP_CAST);
  224. write_exp_elt_type ($1);
  225. write_exp_elt_opcode (UNOP_CAST);
  226. }
  227. ;
  228. simple_exp : type '\'' save_qualifier { type_qualifier = $1; } '(' exp ')'
  229. {
  230. write_exp_elt_opcode (UNOP_QUAL);
  231. write_exp_elt_type ($1);
  232. write_exp_elt_opcode (UNOP_QUAL);
  233. type_qualifier = $3;
  234. }
  235. ;
  236. save_qualifier : { $$ = type_qualifier; }
  237. ;
  238. simple_exp :
  239. simple_exp '(' exp DOTDOT exp ')'
  240. { write_exp_elt_opcode (TERNOP_SLICE); }
  241. ;
  242. simple_exp : '(' exp1 ')' { }
  243. ;
  244. simple_exp : variable
  245. ;
  246. simple_exp: SPECIAL_VARIABLE /* Various GDB extensions */
  247. { write_dollar_variable ($1); }
  248. ;
  249. exp : simple_exp
  250. ;
  251. exp : exp ASSIGN exp /* Extension for convenience */
  252. { write_exp_elt_opcode (BINOP_ASSIGN); }
  253. ;
  254. exp : '-' exp %prec UNARY
  255. { write_exp_elt_opcode (UNOP_NEG); }
  256. ;
  257. exp : '+' exp %prec UNARY
  258. { write_exp_elt_opcode (UNOP_PLUS); }
  259. ;
  260. exp : NOT exp %prec UNARY
  261. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  262. ;
  263. exp : ABS exp %prec UNARY
  264. { write_exp_elt_opcode (UNOP_ABS); }
  265. ;
  266. arglist : { $$ = 0; }
  267. ;
  268. arglist : exp
  269. { $$ = 1; }
  270. | any_name ARROW exp
  271. { $$ = 1; }
  272. | arglist ',' exp
  273. { $$ = $1 + 1; }
  274. | arglist ',' any_name ARROW exp
  275. { $$ = $1 + 1; }
  276. ;
  277. exp : '{' type '}' exp %prec '.'
  278. /* GDB extension */
  279. { write_exp_elt_opcode (UNOP_MEMVAL);
  280. write_exp_elt_type ($2);
  281. write_exp_elt_opcode (UNOP_MEMVAL);
  282. }
  283. ;
  284. /* Binary operators in order of decreasing precedence. */
  285. exp : exp STARSTAR exp
  286. { write_exp_elt_opcode (BINOP_EXP); }
  287. ;
  288. exp : exp '*' exp
  289. { write_exp_elt_opcode (BINOP_MUL); }
  290. ;
  291. exp : exp '/' exp
  292. { write_exp_elt_opcode (BINOP_DIV); }
  293. ;
  294. exp : exp REM exp /* May need to be fixed to give correct Ada REM */
  295. { write_exp_elt_opcode (BINOP_REM); }
  296. ;
  297. exp : exp MOD exp
  298. { write_exp_elt_opcode (BINOP_MOD); }
  299. ;
  300. exp : exp '@' exp /* GDB extension */
  301. { write_exp_elt_opcode (BINOP_REPEAT); }
  302. ;
  303. exp : exp '+' exp
  304. { write_exp_elt_opcode (BINOP_ADD); }
  305. ;
  306. exp : exp '&amp;' exp
  307. { write_exp_elt_opcode (BINOP_CONCAT); }
  308. ;
  309. exp : exp '-' exp
  310. { write_exp_elt_opcode (BINOP_SUB); }
  311. ;
  312. exp : exp '=' exp
  313. { write_exp_elt_opcode (BINOP_EQUAL); }
  314. ;
  315. exp : exp NOTEQUAL exp
  316. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  317. ;
  318. exp : exp LEQ exp
  319. { write_exp_elt_opcode (BINOP_LEQ); }
  320. ;
  321. exp : exp IN exp DOTDOT exp
  322. { write_exp_elt_opcode (TERNOP_IN_RANGE); }
  323. | exp IN exp TICK_RANGE tick_arglist
  324. { write_exp_elt_opcode (BINOP_IN_BOUNDS);
  325. write_exp_elt_longcst ((LONGEST) $5);
  326. write_exp_elt_opcode (BINOP_IN_BOUNDS);
  327. }
  328. | exp IN TYPENAME %prec TICK_ACCESS
  329. { write_exp_elt_opcode (UNOP_IN_RANGE);
  330. write_exp_elt_type ($3);
  331. write_exp_elt_opcode (UNOP_IN_RANGE);
  332. }
  333. | exp NOT IN exp DOTDOT exp
  334. { write_exp_elt_opcode (TERNOP_IN_RANGE);
  335. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  336. }
  337. | exp NOT IN exp TICK_RANGE tick_arglist
  338. { write_exp_elt_opcode (BINOP_IN_BOUNDS);
  339. write_exp_elt_longcst ((LONGEST) $6);
  340. write_exp_elt_opcode (BINOP_IN_BOUNDS);
  341. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  342. }
  343. | exp NOT IN TYPENAME %prec TICK_ACCESS
  344. { write_exp_elt_opcode (UNOP_IN_RANGE);
  345. write_exp_elt_type ($4);
  346. write_exp_elt_opcode (UNOP_IN_RANGE);
  347. write_exp_elt_opcode (UNOP_LOGICAL_NOT);
  348. }
  349. ;
  350. exp : exp GEQ exp
  351. { write_exp_elt_opcode (BINOP_GEQ); }
  352. ;
  353. exp : exp '&lt;' exp
  354. { write_exp_elt_opcode (BINOP_LESS); }
  355. ;
  356. exp : exp '&gt;' exp
  357. { write_exp_elt_opcode (BINOP_GTR); }
  358. ;
  359. exp : exp _AND_ exp /* Fix for Ada elementwise AND. */
  360. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  361. ;
  362. exp : exp _AND_ THEN exp %prec _AND_
  363. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  364. ;
  365. exp : exp OR exp /* Fix for Ada elementwise OR */
  366. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  367. ;
  368. exp : exp OR ELSE exp
  369. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  370. ;
  371. exp : exp XOR exp /* Fix for Ada elementwise XOR */
  372. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  373. ;
  374. simple_exp : simple_exp TICK_ACCESS
  375. { write_exp_elt_opcode (UNOP_ADDR); }
  376. | simple_exp TICK_ADDRESS
  377. { write_exp_elt_opcode (UNOP_ADDR);
  378. write_exp_elt_opcode (UNOP_CAST);
  379. write_exp_elt_type (type_system_address ());
  380. write_exp_elt_opcode (UNOP_CAST);
  381. }
  382. | simple_exp TICK_FIRST tick_arglist
  383. { write_int ($3, type_int ());
  384. write_exp_elt_opcode (OP_ATR_FIRST); }
  385. | simple_exp TICK_LAST tick_arglist
  386. { write_int ($3, type_int ());
  387. write_exp_elt_opcode (OP_ATR_LAST); }
  388. | simple_exp TICK_LENGTH tick_arglist
  389. { write_int ($3, type_int ());
  390. write_exp_elt_opcode (OP_ATR_LENGTH); }
  391. | simple_exp TICK_SIZE
  392. { write_exp_elt_opcode (OP_ATR_SIZE); }
  393. | simple_exp TICK_TAG
  394. { write_exp_elt_opcode (OP_ATR_TAG); }
  395. | opt_type_prefix TICK_MIN '(' exp ',' exp ')'
  396. { write_exp_elt_opcode (OP_ATR_MIN); }
  397. | opt_type_prefix TICK_MAX '(' exp ',' exp ')'
  398. { write_exp_elt_opcode (OP_ATR_MAX); }
  399. | opt_type_prefix TICK_POS '(' exp ')'
  400. { write_exp_elt_opcode (OP_ATR_POS); }
  401. | type_prefix TICK_FIRST tick_arglist
  402. { write_int ($3, type_int ());
  403. write_exp_elt_opcode (OP_ATR_FIRST); }
  404. | type_prefix TICK_LAST tick_arglist
  405. { write_int ($3, type_int ());
  406. write_exp_elt_opcode (OP_ATR_LAST); }
  407. | type_prefix TICK_LENGTH tick_arglist
  408. { write_int ($3, type_int ());
  409. write_exp_elt_opcode (OP_ATR_LENGTH); }
  410. | type_prefix TICK_VAL '(' exp ')'
  411. { write_exp_elt_opcode (OP_ATR_VAL); }
  412. | type_prefix TICK_MODULUS
  413. { write_exp_elt_opcode (OP_ATR_MODULUS); }
  414. ;
  415. tick_arglist : %prec '('
  416. { $$ = 1; }
  417. | '(' INT ')'
  418. { $$ = $2.val; }
  419. ;
  420. type_prefix :
  421. TYPENAME
  422. { write_exp_elt_opcode (OP_TYPE);
  423. write_exp_elt_type ($1);
  424. write_exp_elt_opcode (OP_TYPE); }
  425. ;
  426. opt_type_prefix :
  427. type_prefix
  428. | /* EMPTY */
  429. { write_exp_elt_opcode (OP_TYPE);
  430. write_exp_elt_type (builtin_type_void);
  431. write_exp_elt_opcode (OP_TYPE); }
  432. ;
  433. exp : INT
  434. { write_int ((LONGEST) $1.val, $1.type); }
  435. ;
  436. exp : CHARLIT
  437. { write_int (convert_char_literal (type_qualifier, $1.val),
  438. (type_qualifier == NULL)
  439. ? $1.type : type_qualifier);
  440. }
  441. ;
  442. exp : FLOAT
  443. { write_exp_elt_opcode (OP_DOUBLE);
  444. write_exp_elt_type ($1.type);
  445. write_exp_elt_dblcst ($1.dval);
  446. write_exp_elt_opcode (OP_DOUBLE);
  447. }
  448. ;
  449. exp : NULL_PTR
  450. { write_int (0, type_int ()); }
  451. ;
  452. exp : STRING
  453. {
  454. write_exp_elt_opcode (OP_STRING);
  455. write_exp_string ($1);
  456. write_exp_elt_opcode (OP_STRING);
  457. }
  458. ;
  459. exp : NEW TYPENAME
  460. { error (&quot;NEW not implemented.&quot;); }
  461. ;
  462. variable: NAME { write_var_from_name (NULL, $1); }
  463. | block NAME /* GDB extension */
  464. { write_var_from_name ($1, $2); }
  465. | OBJECT_RENAMING
  466. { write_object_renaming (NULL, $1.sym,
  467. MAX_RENAMING_CHAIN_LENGTH); }
  468. | block OBJECT_RENAMING
  469. { write_object_renaming ($1, $2.sym,
  470. MAX_RENAMING_CHAIN_LENGTH); }
  471. ;
  472. any_name : NAME { }
  473. | TYPENAME { }
  474. | OBJECT_RENAMING { }
  475. ;
  476. block : BLOCKNAME /* GDB extension */
  477. { $$ = $1; }
  478. | block BLOCKNAME /* GDB extension */
  479. { $$ = $2; }
  480. ;
  481. type : TYPENAME { $$ = $1; }
  482. | block TYPENAME { $$ = $2; }
  483. | TYPENAME TICK_ACCESS
  484. { $$ = lookup_pointer_type ($1); }
  485. | block TYPENAME TICK_ACCESS
  486. { $$ = lookup_pointer_type ($2); }
  487. ;
  488. /* Some extensions borrowed from C, for the benefit of those who find they
  489. can't get used to Ada notation in GDB. */
  490. exp : '*' exp %prec '.'
  491. { write_exp_elt_opcode (UNOP_IND); }
  492. | '&amp;' exp %prec '.'
  493. { write_exp_elt_opcode (UNOP_ADDR); }
  494. | exp '[' exp ']'
  495. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  496. ;
  497. %%
  498. /* yylex defined in ada-lex.c: Reads one token, getting characters */
  499. /* through lexptr. */
  500. /* Remap normal flex interface names (yylex) as well as gratuitiously */
  501. /* global symbol names, so we can have multiple flex-generated parsers */
  502. /* in gdb. */
  503. /* (See note above on previous definitions for YACC.) */
  504. #define yy_create_buffer ada_yy_create_buffer
  505. #define yy_delete_buffer ada_yy_delete_buffer
  506. #define yy_init_buffer ada_yy_init_buffer
  507. #define yy_load_buffer_state ada_yy_load_buffer_state
  508. #define yy_switch_to_buffer ada_yy_switch_to_buffer
  509. #define yyrestart ada_yyrestart
  510. #define yytext ada_yytext
  511. #define yywrap ada_yywrap
  512. static struct obstack temp_parse_space;
  513. /* The following kludge was found necessary to prevent conflicts between */
  514. /* defs.h and non-standard stdlib.h files. */
  515. #define qsort __qsort__dummy
  516. #include &quot;ada-lex.c&quot;
  517. int
  518. ada_parse (void)
  519. {
  520. lexer_init (yyin); /* (Re-)initialize lexer. */
  521. left_block_context = NULL;
  522. type_qualifier = NULL;
  523. obstack_free (&amp;temp_parse_space, NULL);
  524. obstack_init (&amp;temp_parse_space);
  525. return _ada_parse ();
  526. }
  527. void
  528. yyerror (char *msg)
  529. {
  530. error (&quot;A %s in expression, near `%s'.&quot;, (msg ? msg : &quot;error&quot;), lexptr);
  531. }
  532. /* The operator name corresponding to operator symbol STRING (adds
  533. quotes and maps to lower-case). Destroys the previous contents of
  534. the array pointed to by STRING.ptr. Error if STRING does not match
  535. a valid Ada operator. Assumes that STRING.ptr points to a
  536. null-terminated string and that, if STRING is a valid operator
  537. symbol, the array pointed to by STRING.ptr contains at least
  538. STRING.length+3 characters. */
  539. static struct stoken
  540. string_to_operator (struct stoken string)
  541. {
  542. int i;
  543. for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
  544. {
  545. if (string.length == strlen (ada_opname_table[i].decoded)-2
  546. &amp;&amp; strncasecmp (string.ptr, ada_opname_table[i].decoded+1,
  547. string.length) == 0)
  548. {
  549. strncpy (string.ptr, ada_opname_table[i].decoded,
  550. string.length+2);
  551. string.length += 2;
  552. return string;
  553. }
  554. }
  555. error (&quot;Invalid operator symbol `%s'&quot;, string.ptr);
  556. }
  557. /* Emit expression to access an instance of SYM, in block BLOCK (if
  558. * non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
  559. static void
  560. write_var_from_sym (struct block *orig_left_context,
  561. struct block *block,
  562. struct symbol *sym)
  563. {
  564. if (orig_left_context == NULL &amp;&amp; symbol_read_needs_frame (sym))
  565. {
  566. if (innermost_block == 0
  567. || contained_in (block, innermost_block))
  568. innermost_block = block;
  569. }
  570. write_exp_elt_opcode (OP_VAR_VALUE);
  571. write_exp_elt_block (block);
  572. write_exp_elt_sym (sym);
  573. write_exp_elt_opcode (OP_VAR_VALUE);
  574. }
  575. /* Emit expression to access an instance of NAME in :: context
  576. * ORIG_LEFT_CONTEXT. If no unique symbol for NAME has been found,
  577. * output a dummy symbol (good to the next call of ada_parse) for NAME
  578. * in the UNDEF_DOMAIN, for later resolution by ada_resolve. */
  579. static void
  580. write_var_from_name (struct block *orig_left_context,
  581. struct name_info name)
  582. {
  583. if (name.msym != NULL)
  584. {
  585. write_exp_msymbol (name.msym,
  586. lookup_function_type (type_int ()),
  587. type_int ());
  588. }
  589. else if (name.sym == NULL)
  590. {
  591. /* Multiple matches: record name and starting block for later
  592. resolution by ada_resolve. */
  593. char *encoded_name = ada_encode (name.stoken.ptr);
  594. struct symbol *sym =
  595. obstack_alloc (&amp;temp_parse_space, sizeof (struct symbol));
  596. memset (sym, 0, sizeof (struct symbol));
  597. SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
  598. SYMBOL_LINKAGE_NAME (sym)
  599. = obsavestring (encoded_name, strlen (encoded_name), &amp;temp_parse_space);
  600. SYMBOL_LANGUAGE (sym) = language_ada;
  601. write_exp_elt_opcode (OP_VAR_VALUE);
  602. write_exp_elt_block (name.block);
  603. write_exp_elt_sym (sym);
  604. write_exp_elt_opcode (OP_VAR_VALUE);
  605. }
  606. else
  607. write_var_from_sym (orig_left_context, name.block, name.sym);
  608. }
  609. /* Write integer constant ARG of type TYPE. */
  610. static void
  611. write_int (LONGEST arg, struct type *type)
  612. {
  613. write_exp_elt_opcode (OP_LONG);
  614. write_exp_elt_type (type);
  615. write_exp_elt_longcst (arg);
  616. write_exp_elt_opcode (OP_LONG);
  617. }
  618. /* Emit expression corresponding to the renamed object designated by
  619. * the type RENAMING, which must be the referent of an object renaming
  620. * type, in the context of ORIG_LEFT_CONTEXT. MAX_DEPTH is the maximum
  621. * number of cascaded renamings to allow. */
  622. static void
  623. write_object_renaming (struct block *orig_left_context,
  624. struct symbol *renaming, int max_depth)
  625. {
  626. const char *qualification = SYMBOL_LINKAGE_NAME (renaming);
  627. const char *simple_tail;
  628. const char *expr = TYPE_FIELD_NAME (SYMBOL_TYPE (renaming), 0);
  629. const char *suffix;
  630. char *name;
  631. struct symbol *sym;
  632. enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
  633. if (max_depth &lt;= 0)
  634. error (&quot;Could not find renamed symbol&quot;);
  635. /* if orig_left_context is null, then use the currently selected
  636. block; otherwise we might fail our symbol lookup below. */
  637. if (orig_left_context == NULL)
  638. orig_left_context = get_selected_block (NULL);
  639. for (simple_tail = qualification + strlen (qualification);
  640. simple_tail != qualification; simple_tail -= 1)
  641. {
  642. if (*simple_tail == '.')
  643. {
  644. simple_tail += 1;
  645. break;
  646. }
  647. else if (strncmp (simple_tail, &quot;__&quot;, 2) == 0)
  648. {
  649. simple_tail += 2;
  650. break;
  651. }
  652. }
  653. suffix = strstr (expr, &quot;___XE&quot;);
  654. if (suffix == NULL)
  655. goto BadEncoding;
  656. name = (char *) obstack_alloc (&amp;temp_parse_space, suffix - expr + 1);
  657. strncpy (name, expr, suffix-expr);
  658. name[suffix-expr] = '\000';
  659. sym = lookup_symbol (name, orig_left_context, VAR_DOMAIN, 0, NULL);
  660. if (sym == NULL)
  661. error (&quot;Could not find renamed variable: %s&quot;, ada_decode (name));
  662. if (ada_is_object_renaming (sym))
  663. write_object_renaming (orig_left_context, sym, max_depth-1);
  664. else
  665. write_var_from_sym (orig_left_context, block_found, sym);
  666. suffix += 5;
  667. slice_state = SIMPLE_INDEX;
  668. while (*suffix == 'X')
  669. {
  670. suffix += 1;
  671. switch (*suffix) {
  672. case 'A':
  673. suffix += 1;
  674. write_exp_elt_opcode (UNOP_IND);
  675. break;
  676. case 'L':
  677. slice_state = LOWER_BOUND;
  678. case 'S':
  679. suffix += 1;
  680. if (isdigit (*suffix))
  681. {
  682. char *next;
  683. long val = strtol (suffix, &amp;next, 10);
  684. if (next == suffix)
  685. goto BadEncoding;
  686. suffix = next;
  687. write_exp_elt_opcode (OP_LONG);
  688. write_exp_elt_type (type_int ());
  689. write_exp_elt_longcst ((LONGEST) val);
  690. write_exp_elt_opcode (OP_LONG);
  691. }
  692. else
  693. {
  694. const char *end;
  695. char *index_name;
  696. int index_len;
  697. struct symbol *index_sym;
  698. end = strchr (suffix, 'X');
  699. if (end == NULL)
  700. end = suffix + strlen (suffix);
  701. index_len = simple_tail - qualification + 2 + (suffix - end) + 1;
  702. index_name
  703. = (char *) obstack_alloc (&amp;temp_parse_space, index_len);
  704. memset (index_name, '\000', index_len);
  705. strncpy (index_name, qualification, simple_tail - qualification);
  706. index_name[simple_tail - qualification] = '\000';
  707. strncat (index_name, suffix, suffix-end);
  708. suffix = end;
  709. index_sym =
  710. lookup_symbol (index_name, NULL, VAR_DOMAIN, 0, NULL);
  711. if (index_sym == NULL)
  712. error (&quot;Could not find %s&quot;, index_name);
  713. write_var_from_sym (NULL, block_found, sym);
  714. }
  715. if (slice_state == SIMPLE_INDEX)
  716. {
  717. write_exp_elt_opcode (OP_FUNCALL);
  718. write_exp_elt_longcst ((LONGEST) 1);
  719. write_exp_elt_opcode (OP_FUNCALL);
  720. }
  721. else if (slice_state == LOWER_BOUND)
  722. slice_state = UPPER_BOUND;
  723. else if (slice_state == UPPER_BOUND)
  724. {
  725. write_exp_elt_opcode (TERNOP_SLICE);
  726. slice_state = SIMPLE_INDEX;
  727. }
  728. break;
  729. case 'R':
  730. {
  731. struct stoken field_name;
  732. const char *end;
  733. suffix += 1;
  734. if (slice_state != SIMPLE_INDEX)
  735. goto BadEncoding;
  736. end = strchr (suffix, 'X');
  737. if (end == NULL)
  738. end = suffix + strlen (suffix);
  739. field_name.length = end - suffix;
  740. field_name.ptr = xmalloc (end - suffix + 1);
  741. strncpy (field_name.ptr, suffix, end - suffix);
  742. field_name.ptr[end - suffix] = '\000';
  743. suffix = end;
  744. write_exp_elt_opcode (STRUCTOP_STRUCT);
  745. write_exp_string (field_name);
  746. write_exp_elt_opcode (STRUCTOP_STRUCT);
  747. break;
  748. }
  749. default:
  750. goto BadEncoding;
  751. }
  752. }
  753. if (slice_state == SIMPLE_INDEX)
  754. return;
  755. BadEncoding:
  756. error (&quot;Internal error in encoding of renaming declaration: %s&quot;,
  757. SYMBOL_LINKAGE_NAME (renaming));
  758. }
  759. /* Convert the character literal whose ASCII value would be VAL to the
  760. appropriate value of type TYPE, if there is a translation.
  761. Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
  762. the literal 'A' (VAL == 65), returns 0. */
  763. static LONGEST
  764. convert_char_literal (struct type *type, LONGEST val)
  765. {
  766. char name[7];
  767. int f;
  768. if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
  769. return val;
  770. sprintf (name, &quot;QU%02x&quot;, (int) val);
  771. for (f = 0; f &lt; TYPE_NFIELDS (type); f += 1)
  772. {
  773. if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
  774. return TYPE_FIELD_BITPOS (type, f);
  775. }
  776. return val;
  777. }
  778. static struct type *
  779. type_int (void)
  780. {
  781. return builtin_type (current_gdbarch)-&gt;builtin_int;
  782. }
  783. static struct type *
  784. type_long (void)
  785. {
  786. return builtin_type (current_gdbarch)-&gt;builtin_long;
  787. }
  788. static struct type *
  789. type_long_long (void)
  790. {
  791. return builtin_type (current_gdbarch)-&gt;builtin_long_long;
  792. }
  793. static struct type *
  794. type_float (void)
  795. {
  796. return builtin_type (current_gdbarch)-&gt;builtin_float;
  797. }
  798. static struct type *
  799. type_double (void)
  800. {
  801. return builtin_type (current_gdbarch)-&gt;builtin_double;
  802. }
  803. static struct type *
  804. type_long_double (void)
  805. {
  806. return builtin_type (current_gdbarch)-&gt;builtin_long_double;
  807. }
  808. static struct type *
  809. type_char (void)
  810. {
  811. return language_string_char_type (current_language, current_gdbarch);
  812. }
  813. static struct type *
  814. type_system_address (void)
  815. {
  816. struct type *type
  817. = language_lookup_primitive_type_by_name (current_language,
  818. current_gdbarch,
  819. &quot;system__address&quot;);
  820. return type != NULL ? type : lookup_pointer_type (builtin_type_void);
  821. }
  822. void
  823. _initialize_ada_exp (void)
  824. {
  825. obstack_init (&amp;temp_parse_space);
  826. }
  827. /* FIXME: hilfingr/2004-10-05: Hack to remove warning. The function
  828. string_to_operator is supposed to be used for cases where one
  829. calls an operator function with prefix notation, as in
  830. &quot;+&quot; (a, b), but at some point, this code seems to have gone
  831. missing. */
  832. struct stoken (*dummy_string_to_ada_operator) (struct stoken)
  833. = string_to_operator;
  834. </pre>
  835. <hr />
  836. </body></html>