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

/src/netbsd/src/gnu/dist/gdb6/gdb/jv-exp.y

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