PageRenderTime 71ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Happy | 1502 lines | 1324 code | 178 blank | 0 comment | 0 complexity | 88f3f45bcb58cd0eb744946f5ef47bd9 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>jv-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">jv-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 Java expressions, for GDB.
  24. Copyright 1997, 1998, 1999, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  38. /* Parse a Java 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. Well, almost always; see ArrayAccess.
  46. Note that 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;jv-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;block.h&quot;
  66. #include &quot;completer.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. Note that 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. #define yymaxdepth java_maxdepth
  74. #define yyparse java_parse
  75. #define yylex java_lex
  76. #define yyerror java_error
  77. #define yylval java_lval
  78. #define yychar java_char
  79. #define yydebug java_debug
  80. #define yypact java_pact
  81. #define yyr1 java_r1
  82. #define yyr2 java_r2
  83. #define yydef java_def
  84. #define yychk java_chk
  85. #define yypgo java_pgo
  86. #define yyact java_act
  87. #define yyexca java_exca
  88. #define yyerrflag java_errflag
  89. #define yynerrs java_nerrs
  90. #define yyps java_ps
  91. #define yypv java_pv
  92. #define yys java_s
  93. #define yy_yys java_yys
  94. #define yystate java_state
  95. #define yytmp java_tmp
  96. #define yyv java_v
  97. #define yy_yyv java_yyv
  98. #define yyval java_val
  99. #define yylloc java_lloc
  100. #define yyreds java_reds /* With YYDEBUG defined */
  101. #define yytoks java_toks /* With YYDEBUG defined */
  102. #define yyname java_name /* With YYDEBUG defined */
  103. #define yyrule java_rule /* With YYDEBUG defined */
  104. #define yylhs java_yylhs
  105. #define yylen java_yylen
  106. #define yydefred java_yydefred
  107. #define yydgoto java_yydgoto
  108. #define yysindex java_yysindex
  109. #define yyrindex java_yyrindex
  110. #define yygindex java_yygindex
  111. #define yytable java_yytable
  112. #define yycheck java_yycheck
  113. #ifndef YYDEBUG
  114. #define YYDEBUG 1 /* Default to yydebug support */
  115. #endif
  116. #define YYFPRINTF parser_fprintf
  117. int yyparse (void);
  118. static int yylex (void);
  119. void yyerror (char *);
  120. static struct type *java_type_from_name (struct stoken);
  121. static void push_expression_name (struct stoken);
  122. static void push_fieldnames (struct stoken);
  123. static struct expression *copy_exp (struct expression *, int);
  124. static void insert_exp (int, struct expression *);
  125. %}
  126. /* Although the yacc &quot;value&quot; of an expression is not used,
  127. since the result is stored in the structure being created,
  128. other node types do have values. */
  129. %union
  130. {
  131. LONGEST lval;
  132. struct {
  133. LONGEST val;
  134. struct type *type;
  135. } typed_val_int;
  136. struct {
  137. DOUBLEST dval;
  138. struct type *type;
  139. } typed_val_float;
  140. struct symbol *sym;
  141. struct type *tval;
  142. struct stoken sval;
  143. struct ttype tsym;
  144. struct symtoken ssym;
  145. struct block *bval;
  146. enum exp_opcode opcode;
  147. struct internalvar *ivar;
  148. int *ivec;
  149. }
  150. %{
  151. /* YYSTYPE gets defined by %union */
  152. static int parse_number (char *, int, int, YYSTYPE *);
  153. %}
  154. %type &lt;lval&gt; rcurly Dims Dims_opt
  155. %type &lt;tval&gt; ClassOrInterfaceType ClassType /* ReferenceType Type ArrayType */
  156. %type &lt;tval&gt; IntegralType FloatingPointType NumericType PrimitiveType ArrayType PrimitiveOrArrayType
  157. %token &lt;typed_val_int&gt; INTEGER_LITERAL
  158. %token &lt;typed_val_float&gt; FLOATING_POINT_LITERAL
  159. %token &lt;sval&gt; IDENTIFIER
  160. %token &lt;sval&gt; STRING_LITERAL
  161. %token &lt;lval&gt; BOOLEAN_LITERAL
  162. %token &lt;tsym&gt; TYPENAME
  163. %type &lt;sval&gt; Name SimpleName QualifiedName ForcedName
  164. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  165. but which would parse as a valid number in the current input radix.
  166. E.g. &quot;c&quot; when input_radix==16. Depending on the parse, it will be
  167. turned into a name or into a number. */
  168. %token &lt;sval&gt; NAME_OR_INT
  169. %token ERROR
  170. /* Special type cases, put in to allow the parser to distinguish different
  171. legal basetypes. */
  172. %token LONG SHORT BYTE INT CHAR BOOLEAN DOUBLE FLOAT
  173. %token VARIABLE
  174. %token &lt;opcode&gt; ASSIGN_MODIFY
  175. %token SUPER NEW
  176. %left ','
  177. %right '=' ASSIGN_MODIFY
  178. %right '?'
  179. %left OROR
  180. %left ANDAND
  181. %left '|'
  182. %left '^'
  183. %left '&amp;'
  184. %left EQUAL NOTEQUAL
  185. %left '&lt;' '&gt;' LEQ GEQ
  186. %left LSH RSH
  187. %left '+' '-'
  188. %left '*' '/' '%'
  189. %right INCREMENT DECREMENT
  190. %right '.' '[' '('
  191. %%
  192. start : exp1
  193. | type_exp
  194. ;
  195. type_exp: PrimitiveOrArrayType
  196. {
  197. write_exp_elt_opcode(OP_TYPE);
  198. write_exp_elt_type($1);
  199. write_exp_elt_opcode(OP_TYPE);
  200. }
  201. ;
  202. PrimitiveOrArrayType:
  203. PrimitiveType
  204. | ArrayType
  205. ;
  206. StringLiteral:
  207. STRING_LITERAL
  208. {
  209. write_exp_elt_opcode (OP_STRING);
  210. write_exp_string ($1);
  211. write_exp_elt_opcode (OP_STRING);
  212. }
  213. ;
  214. Literal:
  215. INTEGER_LITERAL
  216. { write_exp_elt_opcode (OP_LONG);
  217. write_exp_elt_type ($1.type);
  218. write_exp_elt_longcst ((LONGEST)($1.val));
  219. write_exp_elt_opcode (OP_LONG); }
  220. | NAME_OR_INT
  221. { YYSTYPE val;
  222. parse_number ($1.ptr, $1.length, 0, &amp;val);
  223. write_exp_elt_opcode (OP_LONG);
  224. write_exp_elt_type (val.typed_val_int.type);
  225. write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
  226. write_exp_elt_opcode (OP_LONG);
  227. }
  228. | FLOATING_POINT_LITERAL
  229. { write_exp_elt_opcode (OP_DOUBLE);
  230. write_exp_elt_type ($1.type);
  231. write_exp_elt_dblcst ($1.dval);
  232. write_exp_elt_opcode (OP_DOUBLE); }
  233. | BOOLEAN_LITERAL
  234. { write_exp_elt_opcode (OP_LONG);
  235. write_exp_elt_type (java_boolean_type);
  236. write_exp_elt_longcst ((LONGEST)$1);
  237. write_exp_elt_opcode (OP_LONG); }
  238. | StringLiteral
  239. ;
  240. /* UNUSED:
  241. Type:
  242. PrimitiveType
  243. | ReferenceType
  244. ;
  245. */
  246. PrimitiveType:
  247. NumericType
  248. | BOOLEAN
  249. { $$ = java_boolean_type; }
  250. ;
  251. NumericType:
  252. IntegralType
  253. | FloatingPointType
  254. ;
  255. IntegralType:
  256. BYTE
  257. { $$ = java_byte_type; }
  258. | SHORT
  259. { $$ = java_short_type; }
  260. | INT
  261. { $$ = java_int_type; }
  262. | LONG
  263. { $$ = java_long_type; }
  264. | CHAR
  265. { $$ = java_char_type; }
  266. ;
  267. FloatingPointType:
  268. FLOAT
  269. { $$ = java_float_type; }
  270. | DOUBLE
  271. { $$ = java_double_type; }
  272. ;
  273. /* UNUSED:
  274. ReferenceType:
  275. ClassOrInterfaceType
  276. | ArrayType
  277. ;
  278. */
  279. ClassOrInterfaceType:
  280. Name
  281. { $$ = java_type_from_name ($1); }
  282. ;
  283. ClassType:
  284. ClassOrInterfaceType
  285. ;
  286. ArrayType:
  287. PrimitiveType Dims
  288. { $$ = java_array_type ($1, $2); }
  289. | Name Dims
  290. { $$ = java_array_type (java_type_from_name ($1), $2); }
  291. ;
  292. Name:
  293. IDENTIFIER
  294. | QualifiedName
  295. ;
  296. ForcedName:
  297. SimpleName
  298. | QualifiedName
  299. ;
  300. SimpleName:
  301. IDENTIFIER
  302. | NAME_OR_INT
  303. ;
  304. QualifiedName:
  305. Name '.' SimpleName
  306. { $$.length = $1.length + $3.length + 1;
  307. if ($1.ptr + $1.length + 1 == $3.ptr
  308. &amp;&amp; $1.ptr[$1.length] == '.')
  309. $$.ptr = $1.ptr; /* Optimization. */
  310. else
  311. {
  312. $$.ptr = (char *) malloc ($$.length + 1);
  313. make_cleanup (free, $$.ptr);
  314. sprintf ($$.ptr, &quot;%.*s.%.*s&quot;,
  315. $1.length, $1.ptr, $3.length, $3.ptr);
  316. } }
  317. ;
  318. /*
  319. type_exp: type
  320. { write_exp_elt_opcode(OP_TYPE);
  321. write_exp_elt_type($1);
  322. write_exp_elt_opcode(OP_TYPE);}
  323. ;
  324. */
  325. /* Expressions, including the comma operator. */
  326. exp1 : Expression
  327. | exp1 ',' Expression
  328. { write_exp_elt_opcode (BINOP_COMMA); }
  329. ;
  330. Primary:
  331. PrimaryNoNewArray
  332. | ArrayCreationExpression
  333. ;
  334. PrimaryNoNewArray:
  335. Literal
  336. | '(' Expression ')'
  337. | ClassInstanceCreationExpression
  338. | FieldAccess
  339. | MethodInvocation
  340. | ArrayAccess
  341. | lcurly ArgumentList rcurly
  342. { write_exp_elt_opcode (OP_ARRAY);
  343. write_exp_elt_longcst ((LONGEST) 0);
  344. write_exp_elt_longcst ((LONGEST) $3);
  345. write_exp_elt_opcode (OP_ARRAY); }
  346. ;
  347. lcurly:
  348. '{'
  349. { start_arglist (); }
  350. ;
  351. rcurly:
  352. '}'
  353. { $$ = end_arglist () - 1; }
  354. ;
  355. ClassInstanceCreationExpression:
  356. NEW ClassType '(' ArgumentList_opt ')'
  357. { internal_error (__FILE__, __LINE__,
  358. _(&quot;FIXME - ClassInstanceCreationExpression&quot;)); }
  359. ;
  360. ArgumentList:
  361. Expression
  362. { arglist_len = 1; }
  363. | ArgumentList ',' Expression
  364. { arglist_len++; }
  365. ;
  366. ArgumentList_opt:
  367. /* EMPTY */
  368. { arglist_len = 0; }
  369. | ArgumentList
  370. ;
  371. ArrayCreationExpression:
  372. NEW PrimitiveType DimExprs Dims_opt
  373. { internal_error (__FILE__, __LINE__,
  374. _(&quot;FIXME - ArrayCreationExpression&quot;)); }
  375. | NEW ClassOrInterfaceType DimExprs Dims_opt
  376. { internal_error (__FILE__, __LINE__,
  377. _(&quot;FIXME - ArrayCreationExpression&quot;)); }
  378. ;
  379. DimExprs:
  380. DimExpr
  381. | DimExprs DimExpr
  382. ;
  383. DimExpr:
  384. '[' Expression ']'
  385. ;
  386. Dims:
  387. '[' ']'
  388. { $$ = 1; }
  389. | Dims '[' ']'
  390. { $$ = $1 + 1; }
  391. ;
  392. Dims_opt:
  393. Dims
  394. | /* EMPTY */
  395. { $$ = 0; }
  396. ;
  397. FieldAccess:
  398. Primary '.' SimpleName
  399. { push_fieldnames ($3); }
  400. | VARIABLE '.' SimpleName
  401. { push_fieldnames ($3); }
  402. /*| SUPER '.' SimpleName { FIXME } */
  403. ;
  404. FuncStart:
  405. Name '('
  406. { push_expression_name ($1); }
  407. ;
  408. MethodInvocation:
  409. FuncStart
  410. { start_arglist(); }
  411. ArgumentList_opt ')'
  412. { write_exp_elt_opcode (OP_FUNCALL);
  413. write_exp_elt_longcst ((LONGEST) end_arglist ());
  414. write_exp_elt_opcode (OP_FUNCALL); }
  415. | Primary '.' SimpleName '(' ArgumentList_opt ')'
  416. { error (_(&quot;Form of method invocation not implemented&quot;)); }
  417. | SUPER '.' SimpleName '(' ArgumentList_opt ')'
  418. { error (_(&quot;Form of method invocation not implemented&quot;)); }
  419. ;
  420. ArrayAccess:
  421. Name '[' Expression ']'
  422. {
  423. /* Emit code for the Name now, then exchange it in the
  424. expout array with the Expression's code. We could
  425. introduce a OP_SWAP code or a reversed version of
  426. BINOP_SUBSCRIPT, but that makes the rest of GDB pay
  427. for our parsing kludges. */
  428. struct expression *name_expr;
  429. push_expression_name ($1);
  430. name_expr = copy_exp (expout, expout_ptr);
  431. expout_ptr -= name_expr-&gt;nelts;
  432. insert_exp (expout_ptr-length_of_subexp (expout, expout_ptr),
  433. name_expr);
  434. free (name_expr);
  435. write_exp_elt_opcode (BINOP_SUBSCRIPT);
  436. }
  437. | VARIABLE '[' Expression ']'
  438. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  439. | PrimaryNoNewArray '[' Expression ']'
  440. { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
  441. ;
  442. PostfixExpression:
  443. Primary
  444. | Name
  445. { push_expression_name ($1); }
  446. | VARIABLE
  447. /* Already written by write_dollar_variable. */
  448. | PostIncrementExpression
  449. | PostDecrementExpression
  450. ;
  451. PostIncrementExpression:
  452. PostfixExpression INCREMENT
  453. { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
  454. ;
  455. PostDecrementExpression:
  456. PostfixExpression DECREMENT
  457. { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
  458. ;
  459. UnaryExpression:
  460. PreIncrementExpression
  461. | PreDecrementExpression
  462. | '+' UnaryExpression
  463. | '-' UnaryExpression
  464. { write_exp_elt_opcode (UNOP_NEG); }
  465. | '*' UnaryExpression
  466. { write_exp_elt_opcode (UNOP_IND); } /*FIXME not in Java */
  467. | UnaryExpressionNotPlusMinus
  468. ;
  469. PreIncrementExpression:
  470. INCREMENT UnaryExpression
  471. { write_exp_elt_opcode (UNOP_PREINCREMENT); }
  472. ;
  473. PreDecrementExpression:
  474. DECREMENT UnaryExpression
  475. { write_exp_elt_opcode (UNOP_PREDECREMENT); }
  476. ;
  477. UnaryExpressionNotPlusMinus:
  478. PostfixExpression
  479. | '~' UnaryExpression
  480. { write_exp_elt_opcode (UNOP_COMPLEMENT); }
  481. | '!' UnaryExpression
  482. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  483. | CastExpression
  484. ;
  485. CastExpression:
  486. '(' PrimitiveType Dims_opt ')' UnaryExpression
  487. { write_exp_elt_opcode (UNOP_CAST);
  488. write_exp_elt_type (java_array_type ($2, $3));
  489. write_exp_elt_opcode (UNOP_CAST); }
  490. | '(' Expression ')' UnaryExpressionNotPlusMinus
  491. {
  492. int last_exp_size = length_of_subexp(expout, expout_ptr);
  493. struct type *type;
  494. int i;
  495. int base = expout_ptr - last_exp_size - 3;
  496. if (base &lt; 0 || expout-&gt;elts[base+2].opcode != OP_TYPE)
  497. error (_(&quot;Invalid cast expression&quot;));
  498. type = expout-&gt;elts[base+1].type;
  499. /* Remove the 'Expression' and slide the
  500. UnaryExpressionNotPlusMinus down to replace it. */
  501. for (i = 0; i &lt; last_exp_size; i++)
  502. expout-&gt;elts[base + i] = expout-&gt;elts[base + i + 3];
  503. expout_ptr -= 3;
  504. if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
  505. type = lookup_pointer_type (type);
  506. write_exp_elt_opcode (UNOP_CAST);
  507. write_exp_elt_type (type);
  508. write_exp_elt_opcode (UNOP_CAST);
  509. }
  510. | '(' Name Dims ')' UnaryExpressionNotPlusMinus
  511. { write_exp_elt_opcode (UNOP_CAST);
  512. write_exp_elt_type (java_array_type (java_type_from_name ($2), $3));
  513. write_exp_elt_opcode (UNOP_CAST); }
  514. ;
  515. MultiplicativeExpression:
  516. UnaryExpression
  517. | MultiplicativeExpression '*' UnaryExpression
  518. { write_exp_elt_opcode (BINOP_MUL); }
  519. | MultiplicativeExpression '/' UnaryExpression
  520. { write_exp_elt_opcode (BINOP_DIV); }
  521. | MultiplicativeExpression '%' UnaryExpression
  522. { write_exp_elt_opcode (BINOP_REM); }
  523. ;
  524. AdditiveExpression:
  525. MultiplicativeExpression
  526. | AdditiveExpression '+' MultiplicativeExpression
  527. { write_exp_elt_opcode (BINOP_ADD); }
  528. | AdditiveExpression '-' MultiplicativeExpression
  529. { write_exp_elt_opcode (BINOP_SUB); }
  530. ;
  531. ShiftExpression:
  532. AdditiveExpression
  533. | ShiftExpression LSH AdditiveExpression
  534. { write_exp_elt_opcode (BINOP_LSH); }
  535. | ShiftExpression RSH AdditiveExpression
  536. { write_exp_elt_opcode (BINOP_RSH); }
  537. /* | ShiftExpression &gt;&gt;&gt; AdditiveExpression { FIXME } */
  538. ;
  539. RelationalExpression:
  540. ShiftExpression
  541. | RelationalExpression '&lt;' ShiftExpression
  542. { write_exp_elt_opcode (BINOP_LESS); }
  543. | RelationalExpression '&gt;' ShiftExpression
  544. { write_exp_elt_opcode (BINOP_GTR); }
  545. | RelationalExpression LEQ ShiftExpression
  546. { write_exp_elt_opcode (BINOP_LEQ); }
  547. | RelationalExpression GEQ ShiftExpression
  548. { write_exp_elt_opcode (BINOP_GEQ); }
  549. /* | RelationalExpresion INSTANCEOF ReferenceType { FIXME } */
  550. ;
  551. EqualityExpression:
  552. RelationalExpression
  553. | EqualityExpression EQUAL RelationalExpression
  554. { write_exp_elt_opcode (BINOP_EQUAL); }
  555. | EqualityExpression NOTEQUAL RelationalExpression
  556. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  557. ;
  558. AndExpression:
  559. EqualityExpression
  560. | AndExpression '&amp;' EqualityExpression
  561. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  562. ;
  563. ExclusiveOrExpression:
  564. AndExpression
  565. | ExclusiveOrExpression '^' AndExpression
  566. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  567. ;
  568. InclusiveOrExpression:
  569. ExclusiveOrExpression
  570. | InclusiveOrExpression '|' ExclusiveOrExpression
  571. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  572. ;
  573. ConditionalAndExpression:
  574. InclusiveOrExpression
  575. | ConditionalAndExpression ANDAND InclusiveOrExpression
  576. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  577. ;
  578. ConditionalOrExpression:
  579. ConditionalAndExpression
  580. | ConditionalOrExpression OROR ConditionalAndExpression
  581. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  582. ;
  583. ConditionalExpression:
  584. ConditionalOrExpression
  585. | ConditionalOrExpression '?' Expression ':' ConditionalExpression
  586. { write_exp_elt_opcode (TERNOP_COND); }
  587. ;
  588. AssignmentExpression:
  589. ConditionalExpression
  590. | Assignment
  591. ;
  592. Assignment:
  593. LeftHandSide '=' ConditionalExpression
  594. { write_exp_elt_opcode (BINOP_ASSIGN); }
  595. | LeftHandSide ASSIGN_MODIFY ConditionalExpression
  596. { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
  597. write_exp_elt_opcode ($2);
  598. write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
  599. ;
  600. LeftHandSide:
  601. ForcedName
  602. { push_expression_name ($1); }
  603. | VARIABLE
  604. /* Already written by write_dollar_variable. */
  605. | FieldAccess
  606. | ArrayAccess
  607. ;
  608. Expression:
  609. AssignmentExpression
  610. ;
  611. %%
  612. /* Take care of parsing a number (anything that starts with a digit).
  613. Set yylval and return the token type; update lexptr.
  614. LEN is the number of characters in it. */
  615. /*** Needs some error checking for the float case ***/
  616. static int
  617. parse_number (p, len, parsed_float, putithere)
  618. char *p;
  619. int len;
  620. int parsed_float;
  621. YYSTYPE *putithere;
  622. {
  623. ULONGEST n = 0;
  624. ULONGEST limit, limit_div_base;
  625. int c;
  626. int base = input_radix;
  627. struct type *type;
  628. if (parsed_float)
  629. {
  630. /* It's a float since it contains a point or an exponent. */
  631. char c;
  632. int num = 0; /* number of tokens scanned by scanf */
  633. char saved_char = p[len];
  634. p[len] = 0; /* null-terminate the token */
  635. if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (float))
  636. num = sscanf (p, &quot;%g%c&quot;, (float *) &amp;putithere-&gt;typed_val_float.dval, &amp;c);
  637. else if (sizeof (putithere-&gt;typed_val_float.dval) &lt;= sizeof (double))
  638. num = sscanf (p, &quot;%lg%c&quot;, (double *) &amp;putithere-&gt;typed_val_float.dval, &amp;c);
  639. else
  640. {
  641. #ifdef SCANF_HAS_LONG_DOUBLE
  642. num = sscanf (p, &quot;%Lg%c&quot;, &amp;putithere-&gt;typed_val_float.dval, &amp;c);
  643. #else
  644. /* Scan it into a double, then assign it to the long double.
  645. This at least wins with values representable in the range
  646. of doubles. */
  647. double temp;
  648. num = sscanf (p, &quot;%lg%c&quot;, &amp;temp, &amp;c);
  649. putithere-&gt;typed_val_float.dval = temp;
  650. #endif
  651. }
  652. p[len] = saved_char; /* restore the input stream */
  653. if (num != 1) /* check scanf found ONLY a float ... */
  654. return ERROR;
  655. /* See if it has `f' or `d' suffix (float or double). */
  656. c = tolower (p[len - 1]);
  657. if (c == 'f' || c == 'F')
  658. putithere-&gt;typed_val_float.type = builtin_type_float;
  659. else if (isdigit (c) || c == '.' || c == 'd' || c == 'D')
  660. putithere-&gt;typed_val_float.type = builtin_type_double;
  661. else
  662. return ERROR;
  663. return FLOATING_POINT_LITERAL;
  664. }
  665. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  666. if (p[0] == '0')
  667. switch (p[1])
  668. {
  669. case 'x':
  670. case 'X':
  671. if (len &gt;= 3)
  672. {
  673. p += 2;
  674. base = 16;
  675. len -= 2;
  676. }
  677. break;
  678. case 't':
  679. case 'T':
  680. case 'd':
  681. case 'D':
  682. if (len &gt;= 3)
  683. {
  684. p += 2;
  685. base = 10;
  686. len -= 2;
  687. }
  688. break;
  689. default:
  690. base = 8;
  691. break;
  692. }
  693. c = p[len-1];
  694. /* A paranoid calculation of (1&lt;&lt;64)-1. */
  695. limit = (ULONGEST)0xffffffff;
  696. limit = ((limit &lt;&lt; 16) &lt;&lt; 16) | limit;
  697. if (c == 'l' || c == 'L')
  698. {
  699. type = java_long_type;
  700. len--;
  701. }
  702. else
  703. {
  704. type = java_int_type;
  705. }
  706. limit_div_base = limit / (ULONGEST) base;
  707. while (--len &gt;= 0)
  708. {
  709. c = *p++;
  710. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  711. c -= '0';
  712. else if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  713. c -= 'A' - 10;
  714. else if (c &gt;= 'a' &amp;&amp; c &lt;= 'z')
  715. c -= 'a' - 10;
  716. else
  717. return ERROR; /* Char not a digit */
  718. if (c &gt;= base)
  719. return ERROR;
  720. if (n &gt; limit_div_base
  721. || (n *= base) &gt; limit - c)
  722. error (_(&quot;Numeric constant too large&quot;));
  723. n += c;
  724. }
  725. /* If the type is bigger than a 32-bit signed integer can be, implicitly
  726. promote to long. Java does not do this, so mark it as builtin_type_uint64
  727. rather than java_long_type. 0x80000000 will become -0x80000000 instead
  728. of 0x80000000L, because we don't know the sign at this point.
  729. */
  730. if (type == java_int_type &amp;&amp; n &gt; (ULONGEST)0x80000000)
  731. type = builtin_type_uint64;
  732. putithere-&gt;typed_val_int.val = n;
  733. putithere-&gt;typed_val_int.type = type;
  734. return INTEGER_LITERAL;
  735. }
  736. struct token
  737. {
  738. char *operator;
  739. int token;
  740. enum exp_opcode opcode;
  741. };
  742. static const struct token tokentab3[] =
  743. {
  744. {&quot;&gt;&gt;=&quot;, ASSIGN_MODIFY, BINOP_RSH},
  745. {&quot;&lt;&lt;=&quot;, ASSIGN_MODIFY, BINOP_LSH}
  746. };
  747. static const struct token tokentab2[] =
  748. {
  749. {&quot;+=&quot;, ASSIGN_MODIFY, BINOP_ADD},
  750. {&quot;-=&quot;, ASSIGN_MODIFY, BINOP_SUB},
  751. {&quot;*=&quot;, ASSIGN_MODIFY, BINOP_MUL},
  752. {&quot;/=&quot;, ASSIGN_MODIFY, BINOP_DIV},
  753. {&quot;%=&quot;, ASSIGN_MODIFY, BINOP_REM},
  754. {&quot;|=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_IOR},
  755. {&quot;&amp;=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_AND},
  756. {&quot;^=&quot;, ASSIGN_MODIFY, BINOP_BITWISE_XOR},
  757. {&quot;++&quot;, INCREMENT, BINOP_END},
  758. {&quot;--&quot;, DECREMENT, BINOP_END},
  759. {&quot;&amp;&amp;&quot;, ANDAND, BINOP_END},
  760. {&quot;||&quot;, OROR, BINOP_END},
  761. {&quot;&lt;&lt;&quot;, LSH, BINOP_END},
  762. {&quot;&gt;&gt;&quot;, RSH, BINOP_END},
  763. {&quot;==&quot;, EQUAL, BINOP_END},
  764. {&quot;!=&quot;, NOTEQUAL, BINOP_END},
  765. {&quot;&lt;=&quot;, LEQ, BINOP_END},
  766. {&quot;&gt;=&quot;, GEQ, BINOP_END}
  767. };
  768. /* Read one token, getting characters through lexptr. */
  769. static int
  770. yylex ()
  771. {
  772. int c;
  773. int namelen;
  774. unsigned int i;
  775. char *tokstart;
  776. char *tokptr;
  777. int tempbufindex;
  778. static char *tempbuf;
  779. static int tempbufsize;
  780. retry:
  781. prev_lexptr = lexptr;
  782. tokstart = lexptr;
  783. /* See if it is a special token of length 3. */
  784. for (i = 0; i &lt; sizeof tokentab3 / sizeof tokentab3[0]; i++)
  785. if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
  786. {
  787. lexptr += 3;
  788. yylval.opcode = tokentab3[i].opcode;
  789. return tokentab3[i].token;
  790. }
  791. /* See if it is a special token of length 2. */
  792. for (i = 0; i &lt; sizeof tokentab2 / sizeof tokentab2[0]; i++)
  793. if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
  794. {
  795. lexptr += 2;
  796. yylval.opcode = tokentab2[i].opcode;
  797. return tokentab2[i].token;
  798. }
  799. switch (c = *tokstart)
  800. {
  801. case 0:
  802. return 0;
  803. case ' ':
  804. case '\t':
  805. case '\n':
  806. lexptr++;
  807. goto retry;
  808. case '\'':
  809. /* We either have a character constant ('0' or '\177' for example)
  810. or we have a quoted symbol reference ('foo(int,int)' in C++
  811. for example). */
  812. lexptr++;
  813. c = *lexptr++;
  814. if (c == '\\')
  815. c = parse_escape (&amp;lexptr);
  816. else if (c == '\'')
  817. error (_(&quot;Empty character constant&quot;));
  818. yylval.typed_val_int.val = c;
  819. yylval.typed_val_int.type = java_char_type;
  820. c = *lexptr++;
  821. if (c != '\'')
  822. {
  823. namelen = skip_quoted (tokstart) - tokstart;
  824. if (namelen &gt; 2)
  825. {
  826. lexptr = tokstart + namelen;
  827. if (lexptr[-1] != '\'')
  828. error (_(&quot;Unmatched single quote&quot;));
  829. namelen -= 2;
  830. tokstart++;
  831. goto tryname;
  832. }
  833. error (_(&quot;Invalid character constant&quot;));
  834. }
  835. return INTEGER_LITERAL;
  836. case '(':
  837. paren_depth++;
  838. lexptr++;
  839. return c;
  840. case ')':
  841. if (paren_depth == 0)
  842. return 0;
  843. paren_depth--;
  844. lexptr++;
  845. return c;
  846. case ',':
  847. if (comma_terminates &amp;&amp; paren_depth == 0)
  848. return 0;
  849. lexptr++;
  850. return c;
  851. case '.':
  852. /* Might be a floating point number. */
  853. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  854. goto symbol; /* Nope, must be a symbol. */
  855. /* FALL THRU into number case. */
  856. case '0':
  857. case '1':
  858. case '2':
  859. case '3':
  860. case '4':
  861. case '5':
  862. case '6':
  863. case '7':
  864. case '8':
  865. case '9':
  866. {
  867. /* It's a number. */
  868. int got_dot = 0, got_e = 0, toktype;
  869. char *p = tokstart;
  870. int hex = input_radix &gt; 10;
  871. if (c == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  872. {
  873. p += 2;
  874. hex = 1;
  875. }
  876. else if (c == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  877. {
  878. p += 2;
  879. hex = 0;
  880. }
  881. for (;; ++p)
  882. {
  883. /* This test includes !hex because 'e' is a valid hex digit
  884. and thus does not indicate a floating point number when
  885. the radix is hex. */
  886. if (!hex &amp;&amp; !got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  887. got_dot = got_e = 1;
  888. /* This test does not include !hex, because a '.' always indicates
  889. a decimal floating point number regardless of the radix. */
  890. else if (!got_dot &amp;&amp; *p == '.')
  891. got_dot = 1;
  892. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E')
  893. &amp;&amp; (*p == '-' || *p == '+'))
  894. /* This is the sign of the exponent, not the end of the
  895. number. */
  896. continue;
  897. /* We will take any letters or digits. parse_number will
  898. complain if past the radix, or if L or U are not final. */
  899. else if ((*p &lt; '0' || *p &gt; '9')
  900. &amp;&amp; ((*p &lt; 'a' || *p &gt; 'z')
  901. &amp;&amp; (*p &lt; 'A' || *p &gt; 'Z')))
  902. break;
  903. }
  904. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &amp;yylval);
  905. if (toktype == ERROR)
  906. {
  907. char *err_copy = (char *) alloca (p - tokstart + 1);
  908. memcpy (err_copy, tokstart, p - tokstart);
  909. err_copy[p - tokstart] = 0;
  910. error (_(&quot;Invalid number \&quot;%s\&quot;&quot;), err_copy);
  911. }
  912. lexptr = p;
  913. return toktype;
  914. }
  915. case '+':
  916. case '-':
  917. case '*':
  918. case '/':
  919. case '%':
  920. case '|':
  921. case '&amp;':
  922. case '^':
  923. case '~':
  924. case '!':
  925. case '&lt;':
  926. case '&gt;':
  927. case '[':
  928. case ']':
  929. case '?':
  930. case ':':
  931. case '=':
  932. case '{':
  933. case '}':
  934. symbol:
  935. lexptr++;
  936. return c;
  937. case '&quot;':
  938. /* Build the gdb internal form of the input string in tempbuf,
  939. translating any standard C escape forms seen. Note that the
  940. buffer is null byte terminated *only* for the convenience of
  941. debugging gdb itself and printing the buffer contents when
  942. the buffer contains no embedded nulls. Gdb does not depend
  943. upon the buffer being null byte terminated, it uses the length
  944. string instead. This allows gdb to handle C strings (as well
  945. as strings in other languages) with embedded null bytes */
  946. tokptr = ++tokstart;
  947. tempbufindex = 0;
  948. do {
  949. /* Grow the static temp buffer if necessary, including allocating
  950. the first one on demand. */
  951. if (tempbufindex + 1 &gt;= tempbufsize)
  952. {
  953. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  954. }
  955. switch (*tokptr)
  956. {
  957. case '\0':
  958. case '&quot;':
  959. /* Do nothing, loop will terminate. */
  960. break;
  961. case '\\':
  962. tokptr++;
  963. c = parse_escape (&amp;tokptr);
  964. if (c == -1)
  965. {
  966. continue;
  967. }
  968. tempbuf[tempbufindex++] = c;
  969. break;
  970. default:
  971. tempbuf[tempbufindex++] = *tokptr++;
  972. break;
  973. }
  974. } while ((*tokptr != '&quot;') &amp;&amp; (*tokptr != '\0'));
  975. if (*tokptr++ != '&quot;')
  976. {
  977. error (_(&quot;Unterminated string in expression&quot;));
  978. }
  979. tempbuf[tempbufindex] = '\0'; /* See note above */
  980. yylval.sval.ptr = tempbuf;
  981. yylval.sval.length = tempbufindex;
  982. lexptr = tokptr;
  983. return (STRING_LITERAL);
  984. }
  985. if (!(c == '_' || c == '$'
  986. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')))
  987. /* We must have come across a bad character (e.g. ';'). */
  988. error (_(&quot;Invalid character '%c' in expression&quot;), c);
  989. /* It's a name. See how long it is. */
  990. namelen = 0;
  991. for (c = tokstart[namelen];
  992. (c == '_'
  993. || c == '$'
  994. || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  995. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z')
  996. || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')
  997. || c == '&lt;');
  998. )
  999. {
  1000. if (c == '&lt;')
  1001. {
  1002. int i = namelen;
  1003. while (tokstart[++i] &amp;&amp; tokstart[i] != '&gt;');
  1004. if (tokstart[i] == '&gt;')
  1005. namelen = i;
  1006. }
  1007. c = tokstart[++namelen];
  1008. }
  1009. /* The token &quot;if&quot; terminates the expression and is NOT
  1010. removed from the input stream. */
  1011. if (namelen == 2 &amp;&amp; tokstart[0] == 'i' &amp;&amp; tokstart[1] == 'f')
  1012. {
  1013. return 0;
  1014. }
  1015. lexptr += namelen;
  1016. tryname:
  1017. /* Catch specific keywords. Should be done with a data structure. */
  1018. switch (namelen)
  1019. {
  1020. case 7:
  1021. if (DEPRECATED_STREQN (tokstart, &quot;boolean&quot;, 7))
  1022. return BOOLEAN;
  1023. break;
  1024. case 6:
  1025. if (DEPRECATED_STREQN (tokstart, &quot;double&quot;, 6))
  1026. return DOUBLE;
  1027. break;
  1028. case 5:
  1029. if (DEPRECATED_STREQN (tokstart, &quot;short&quot;, 5))
  1030. return SHORT;
  1031. if (DEPRECATED_STREQN (tokstart, &quot;false&quot;, 5))
  1032. {
  1033. yylval.lval = 0;
  1034. return BOOLEAN_LITERAL;
  1035. }
  1036. if (DEPRECATED_STREQN (tokstart, &quot;super&quot;, 5))
  1037. return SUPER;
  1038. if (DEPRECATED_STREQN (tokstart, &quot;float&quot;, 5))
  1039. return FLOAT;
  1040. break;
  1041. case 4:
  1042. if (DEPRECATED_STREQN (tokstart, &quot;long&quot;, 4))
  1043. return LONG;
  1044. if (DEPRECATED_STREQN (tokstart, &quot;byte&quot;, 4))
  1045. return BYTE;
  1046. if (DEPRECATED_STREQN (tokstart, &quot;char&quot;, 4))
  1047. return CHAR;
  1048. if (DEPRECATED_STREQN (tokstart, &quot;true&quot;, 4))
  1049. {
  1050. yylval.lval = 1;
  1051. return BOOLEAN_LITERAL;
  1052. }
  1053. break;
  1054. case 3:
  1055. if (strncmp (tokstart, &quot;int&quot;, 3) == 0)
  1056. return INT;
  1057. if (strncmp (tokstart, &quot;new&quot;, 3) == 0)
  1058. return NEW;
  1059. break;
  1060. default:
  1061. break;
  1062. }
  1063. yylval.sval.ptr = tokstart;
  1064. yylval.sval.length = namelen;
  1065. if (*tokstart == '$')
  1066. {
  1067. write_dollar_variable (yylval.sval);
  1068. return VARIABLE;
  1069. }
  1070. /* Input names that aren't symbols but ARE valid hex numbers,
  1071. when the input radix permits them, can be names or numbers
  1072. depending on the parse. Note we support radixes &gt; 16 here. */
  1073. if (((tokstart[0] &gt;= 'a' &amp;&amp; tokstart[0] &lt; 'a' + input_radix - 10) ||
  1074. (tokstart[0] &gt;= 'A' &amp;&amp; tokstart[0] &lt; 'A' + input_radix - 10)))
  1075. {
  1076. YYSTYPE newlval; /* Its value is ignored. */
  1077. int hextype = parse_number (tokstart, namelen, 0, &amp;newlval);
  1078. if (hextype == INTEGER_LITERAL)
  1079. return NAME_OR_INT;
  1080. }
  1081. return IDENTIFIER;
  1082. }
  1083. void
  1084. yyerror (msg)
  1085. char *msg;
  1086. {
  1087. if (prev_lexptr)
  1088. lexptr = prev_lexptr;
  1089. if (msg)
  1090. error (_(&quot;%s: near `%s'&quot;), msg, lexptr);
  1091. else
  1092. error (_(&quot;error in expression, near `%s'&quot;), lexptr);
  1093. }
  1094. static struct type *
  1095. java_type_from_name (name)
  1096. struct stoken name;
  1097. {
  1098. char *tmp = copy_name (name);
  1099. struct type *typ = java_lookup_class (tmp);
  1100. if (typ == NULL || TYPE_CODE (typ) != TYPE_CODE_STRUCT)
  1101. error (_(&quot;No class named `%s'&quot;), tmp);
  1102. return typ;
  1103. }
  1104. /* If NAME is a valid variable name in this scope, push it and return 1.
  1105. Otherwise, return 0. */
  1106. static int
  1107. push_variable (struct stoken name)
  1108. {
  1109. char *tmp = copy_name (name);
  1110. int is_a_field_of_this = 0;
  1111. struct symbol *sym;
  1112. sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN,
  1113. &amp;is_a_field_of_this, (struct symtab **) NULL);
  1114. if (sym &amp;&amp; SYMBOL_CLASS (sym) != LOC_TYPEDEF)
  1115. {
  1116. if (symbol_read_needs_frame (sym))
  1117. {
  1118. if (innermost_block == 0 ||
  1119. contained_in (block_found, innermost_block))
  1120. innermost_block = block_found;
  1121. }
  1122. write_exp_elt_opcode (OP_VAR_VALUE);
  1123. /* We want to use the selected frame, not another more inner frame
  1124. which happens to be in the same block. */
  1125. write_exp_elt_block (NULL);
  1126. write_exp_elt_sym (sym);
  1127. write_exp_elt_opcode (OP_VAR_VALUE);
  1128. return 1;
  1129. }
  1130. if (is_a_field_of_this)
  1131. {
  1132. /* it hangs off of `this'. Must not inadvertently convert from a
  1133. method call to data ref. */
  1134. if (innermost_block == 0 ||
  1135. contained_in (block_found, innermost_block))
  1136. innermost_block = block_found;
  1137. write_exp_elt_opcode (OP_THIS);
  1138. write_exp_elt_opcode (OP_THIS);
  1139. write_exp_elt_opcode (STRUCTOP_PTR);
  1140. write_exp_string (name);
  1141. write_exp_elt_opcode (STRUCTOP_PTR);
  1142. return 1;
  1143. }
  1144. return 0;
  1145. }
  1146. /* Assuming a reference expression has been pushed, emit the
  1147. STRUCTOP_STRUCT ops to access the field named NAME. If NAME is a
  1148. qualified name (has '.'), generate a field access for each part. */
  1149. static void
  1150. push_fieldnames (name)
  1151. struct stoken name;
  1152. {
  1153. int i;
  1154. struct stoken token;
  1155. token.ptr = name.ptr;
  1156. for (i = 0; ; i++)
  1157. {
  1158. if (i == name.length || name.ptr[i] == '.')
  1159. {
  1160. /* token.ptr is start of current field name. */
  1161. token.length = &amp;name.ptr[i] - token.ptr;
  1162. write_exp_elt_opcode (STRUCTOP_STRUCT);
  1163. write_exp_string (token);
  1164. write_exp_elt_opcode (STRUCTOP_STRUCT);
  1165. token.ptr += token.length + 1;
  1166. }
  1167. if (i &gt;= name.length)
  1168. break;
  1169. }
  1170. }
  1171. /* Helper routine for push_expression_name.
  1172. Handle a qualified name, where DOT_INDEX is the index of the first '.' */
  1173. static void
  1174. push_qualified_expression_name (struct stoken name, int dot_index)
  1175. {
  1176. struct stoken token;
  1177. char *tmp;
  1178. struct type *typ;
  1179. token.ptr = name.ptr;
  1180. token.length = dot_index;
  1181. if (push_variable (token))
  1182. {
  1183. token.ptr = name.ptr + dot_index + 1;
  1184. token.length = name.length - dot_index - 1;
  1185. push_fieldnames (token);
  1186. return;
  1187. }
  1188. token.ptr = name.ptr;
  1189. for (;;)
  1190. {
  1191. token.length = dot_index;
  1192. tmp = copy_name (token);
  1193. typ = java_lookup_class (tmp);
  1194. if (typ != NULL)
  1195. {
  1196. if (dot_index == name.length)
  1197. {
  1198. write_exp_elt_opcode(OP_TYPE);
  1199. write_exp_elt_type(typ);
  1200. write_exp_elt_opcode(OP_TYPE);
  1201. return;
  1202. }
  1203. dot_index++; /* Skip '.' */
  1204. name.ptr += dot_index;
  1205. name.length -= dot_index;
  1206. dot_index = 0;
  1207. while (dot_index &lt; name.length &amp;&amp; name.ptr[dot_index] != '.')
  1208. dot_index++;
  1209. token.ptr = name.ptr;
  1210. token.length = dot_index;
  1211. write_exp_elt_opcode (OP_SCOPE);
  1212. write_exp_elt_type (typ);
  1213. write_exp_string (token);
  1214. write_exp_elt_opcode (OP_SCOPE);
  1215. if (dot_index &lt; name.length)
  1216. {
  1217. dot_index++;
  1218. name.ptr += dot_index;
  1219. name.length -= dot_index;
  1220. push_fieldnames (name);
  1221. }
  1222. return;
  1223. }
  1224. else if (dot_index &gt;= name.length)
  1225. break;
  1226. dot_index++; /* Skip '.' */
  1227. while (dot_index &lt; name.length &amp;&amp; name.ptr[dot_index] != '.')
  1228. dot_index++;
  1229. }
  1230. error (_(&quot;unknown type `%.*s'&quot;), name.length, name.ptr);
  1231. }
  1232. /* Handle Name in an expression (or LHS).
  1233. Handle VAR, TYPE, TYPE.FIELD1....FIELDN and VAR.FIELD1....FIELDN. */
  1234. static void
  1235. push_expression_name (name)
  1236. struct stoken name;
  1237. {
  1238. char *tmp;
  1239. struct type *typ;
  1240. int i;
  1241. for (i = 0; i &lt; name.length; i++)
  1242. {
  1243. if (name.ptr[i] == '.')
  1244. {
  1245. /* It's a Qualified Expression Name. */
  1246. push_qualified_expression_name (name, i);
  1247. return;
  1248. }
  1249. }
  1250. /* It's a Simple Expression Name. */
  1251. if (push_variable (name))
  1252. return;
  1253. tmp = copy_name (name);
  1254. typ = java_lookup_class (tmp);
  1255. if (typ != NULL)
  1256. {
  1257. write_exp_elt_opcode(OP_TYPE);
  1258. write_exp_elt_type(typ);
  1259. write_exp_elt_opcode(OP_TYPE);
  1260. }
  1261. else
  1262. {
  1263. struct minimal_symbol *msymbol;
  1264. msymbol = lookup_minimal_symbol (tmp, NULL, NULL);
  1265. if (msymbol != NULL)
  1266. {
  1267. write_exp_msymbol (msymbol,
  1268. lookup_function_type (builtin_type_int),
  1269. builtin_type_int);
  1270. }
  1271. else if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  1272. error (_(&quot;No symbol table is loaded. Use the \&quot;file\&quot; command&quot;));
  1273. else
  1274. error (_(&quot;No symbol \&quot;%s\&quot; in current context&quot;), tmp);
  1275. }
  1276. }
  1277. /* The following two routines, copy_exp and insert_exp, aren't specific to
  1278. Java, so they could go in parse.c, but their only purpose is to support
  1279. the parsing kludges we use in this file, so maybe it's best to isolate
  1280. them here. */
  1281. /* Copy the expression whose last element is at index ENDPOS - 1 in EXPR
  1282. into a freshly malloc'ed struct expression. Its language_defn is set
  1283. to null. */
  1284. static struct expression *
  1285. copy_exp (expr, endpos)
  1286. struct expression *expr;
  1287. int endpos;
  1288. {
  1289. int len = length_of_subexp (expr, endpos);
  1290. struct expression *new
  1291. = (struct expression *) malloc (sizeof (*new) + EXP_ELEM_TO_BYTES (len));
  1292. new-&gt;nelts = len;
  1293. memcpy (new-&gt;elts, expr-&gt;elts + endpos - len, EXP_ELEM_TO_BYTES (len));
  1294. new-&gt;language_defn = 0;
  1295. return new;
  1296. }
  1297. /* Insert the expression NEW into the current expression (expout) at POS. */
  1298. static void
  1299. insert_exp (pos, new)
  1300. int pos;
  1301. struct expression *new;
  1302. {
  1303. int newlen = new-&gt;nelts;
  1304. /* Grow expout if necessary. In this function's only use at present,
  1305. this should never be necessary. */
  1306. if (expout_ptr + newlen &gt; expout_size)
  1307. {
  1308. expout_size = max (expout_size * 2, expout_ptr + newlen + 10);
  1309. expout = (struct expression *)
  1310. realloc ((char *) expout, (sizeof (struct expression)
  1311. + EXP_ELEM_TO_BYTES (expout_size)));
  1312. }
  1313. {
  1314. int i;
  1315. for (i = expout_ptr - 1; i &gt;= pos; i--)
  1316. expout-&gt;elts[i + newlen] = expout-&gt;elts[i];
  1317. }
  1318. memcpy (expout-&gt;elts + pos, new-&gt;elts, EXP_ELEM_TO_BYTES (newlen));
  1319. expout_ptr += newlen;
  1320. }
  1321. </pre>
  1322. <hr />
  1323. </body></html>