PageRenderTime 85ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

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