PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/gdb/gdb/p-exp.y

https://review.tizen.org/git/
Happy | 1684 lines | 1492 code | 192 blank | 0 comment | 0 complexity | cdf970209ea130cd7fa377f25fa4b25d MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
  1. /* YACC parser for Pascal expressions, for GDB.
  2. Copyright (C) 2000, 2006, 2007, 2008, 2009, 2010
  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 3 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, see <http://www.gnu.org/licenses/>. */
  15. /* This file is derived from c-exp.y */
  16. /* Parse a Pascal expression from text in a string,
  17. and return the result as a struct expression pointer.
  18. That structure contains arithmetic operations in reverse polish,
  19. with constants represented by operations that are followed by special data.
  20. See expression.h for the details of the format.
  21. What is important here is that it can be built up sequentially
  22. during the process of parsing; the lower levels of the tree always
  23. come first in the result.
  24. Note that malloc's and realloc's in this file are transformed to
  25. xmalloc and xrealloc respectively by the same sed command in the
  26. makefile that remaps any other malloc/realloc inserted by the parser
  27. generator. Doing this with #defines and trying to control the interaction
  28. with include files (<malloc.h> and <stdlib.h> for example) just became
  29. too messy, particularly when such includes can be inserted at random
  30. times by the parser generator. */
  31. /* Known bugs or limitations:
  32. - pascal string operations are not supported at all.
  33. - there are some problems with boolean types.
  34. - Pascal type hexadecimal constants are not supported
  35. because they conflict with the internal variables format.
  36. Probably also lots of other problems, less well defined PM */
  37. %{
  38. #include "defs.h"
  39. #include "gdb_string.h"
  40. #include <ctype.h>
  41. #include "expression.h"
  42. #include "value.h"
  43. #include "parser-defs.h"
  44. #include "language.h"
  45. #include "p-lang.h"
  46. #include "bfd.h" /* Required by objfiles.h. */
  47. #include "symfile.h" /* Required by objfiles.h. */
  48. #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
  49. #include "block.h"
  50. #define parse_type builtin_type (parse_gdbarch)
  51. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  52. as well as gratuitiously global symbol names, so we can have multiple
  53. yacc generated parsers in gdb. Note that these are only the variables
  54. produced by yacc. If other parser generators (bison, byacc, etc) produce
  55. additional global names that conflict at link time, then those parser
  56. generators need to be fixed instead of adding those names to this list. */
  57. #define yymaxdepth pascal_maxdepth
  58. #define yyparse pascal_parse
  59. #define yylex pascal_lex
  60. #define yyerror pascal_error
  61. #define yylval pascal_lval
  62. #define yychar pascal_char
  63. #define yydebug pascal_debug
  64. #define yypact pascal_pact
  65. #define yyr1 pascal_r1
  66. #define yyr2 pascal_r2
  67. #define yydef pascal_def
  68. #define yychk pascal_chk
  69. #define yypgo pascal_pgo
  70. #define yyact pascal_act
  71. #define yyexca pascal_exca
  72. #define yyerrflag pascal_errflag
  73. #define yynerrs pascal_nerrs
  74. #define yyps pascal_ps
  75. #define yypv pascal_pv
  76. #define yys pascal_s
  77. #define yy_yys pascal_yys
  78. #define yystate pascal_state
  79. #define yytmp pascal_tmp
  80. #define yyv pascal_v
  81. #define yy_yyv pascal_yyv
  82. #define yyval pascal_val
  83. #define yylloc pascal_lloc
  84. #define yyreds pascal_reds /* With YYDEBUG defined */
  85. #define yytoks pascal_toks /* With YYDEBUG defined */
  86. #define yyname pascal_name /* With YYDEBUG defined */
  87. #define yyrule pascal_rule /* With YYDEBUG defined */
  88. #define yylhs pascal_yylhs
  89. #define yylen pascal_yylen
  90. #define yydefred pascal_yydefred
  91. #define yydgoto pascal_yydgoto
  92. #define yysindex pascal_yysindex
  93. #define yyrindex pascal_yyrindex
  94. #define yygindex pascal_yygindex
  95. #define yytable pascal_yytable
  96. #define yycheck pascal_yycheck
  97. #ifndef YYDEBUG
  98. #define YYDEBUG 1 /* Default to yydebug support */
  99. #endif
  100. #define YYFPRINTF parser_fprintf
  101. int yyparse (void);
  102. static int yylex (void);
  103. void
  104. yyerror (char *);
  105. static char * uptok (char *, int);
  106. %}
  107. /* Although the yacc "value" of an expression is not used,
  108. since the result is stored in the structure being created,
  109. other node types do have values. */
  110. %union
  111. {
  112. LONGEST lval;
  113. struct {
  114. LONGEST val;
  115. struct type *type;
  116. } typed_val_int;
  117. struct {
  118. DOUBLEST dval;
  119. struct type *type;
  120. } typed_val_float;
  121. struct symbol *sym;
  122. struct type *tval;
  123. struct stoken sval;
  124. struct ttype tsym;
  125. struct symtoken ssym;
  126. int voidval;
  127. struct block *bval;
  128. enum exp_opcode opcode;
  129. struct internalvar *ivar;
  130. struct type **tvec;
  131. int *ivec;
  132. }
  133. %{
  134. /* YYSTYPE gets defined by %union */
  135. static int
  136. parse_number (char *, int, int, YYSTYPE *);
  137. static struct type *current_type;
  138. static int leftdiv_is_integer;
  139. static void push_current_type (void);
  140. static void pop_current_type (void);
  141. static int search_field;
  142. %}
  143. %type <voidval> exp exp1 type_exp start normal_start variable qualified_name
  144. %type <tval> type typebase
  145. /* %type <bval> block */
  146. /* Fancy type parsing. */
  147. %type <tval> ptype
  148. %token <typed_val_int> INT
  149. %token <typed_val_float> FLOAT
  150. /* Both NAME and TYPENAME tokens represent symbols in the input,
  151. and both convey their data as strings.
  152. But a TYPENAME is a string that happens to be defined as a typedef
  153. or builtin type name (such as int or char)
  154. and a NAME is any other symbol.
  155. Contexts where this distinction is not important can use the
  156. nonterminal "name", which matches either NAME or TYPENAME. */
  157. %token <sval> STRING
  158. %token <sval> FIELDNAME
  159. %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
  160. %token <tsym> TYPENAME
  161. %type <sval> name
  162. %type <ssym> name_not_typename
  163. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  164. but which would parse as a valid number in the current input radix.
  165. E.g. "c" when input_radix==16. Depending on the parse, it will be
  166. turned into a name or into a number. */
  167. %token <ssym> NAME_OR_INT
  168. %token STRUCT CLASS SIZEOF COLONCOLON
  169. %token ERROR
  170. /* Special type cases, put in to allow the parser to distinguish different
  171. legal basetypes. */
  172. %token <voidval> VARIABLE
  173. /* Object pascal */
  174. %token THIS
  175. %token <lval> TRUEKEYWORD FALSEKEYWORD
  176. %left ','
  177. %left ABOVE_COMMA
  178. %right ASSIGN
  179. %left NOT
  180. %left OR
  181. %left XOR
  182. %left ANDAND
  183. %left '=' NOTEQUAL
  184. %left '<' '>' LEQ GEQ
  185. %left LSH RSH DIV MOD
  186. %left '@'
  187. %left '+' '-'
  188. %left '*' '/'
  189. %right UNARY INCREMENT DECREMENT
  190. %right ARROW '.' '[' '('
  191. %left '^'
  192. %token <ssym> BLOCKNAME
  193. %type <bval> block
  194. %left COLONCOLON
  195. %%
  196. start : { current_type = NULL;
  197. search_field = 0;
  198. leftdiv_is_integer = 0;
  199. }
  200. normal_start {}
  201. ;
  202. normal_start :
  203. exp1
  204. | type_exp
  205. ;
  206. type_exp: type
  207. { write_exp_elt_opcode(OP_TYPE);
  208. write_exp_elt_type($1);
  209. write_exp_elt_opcode(OP_TYPE);
  210. current_type = $1; } ;
  211. /* Expressions, including the comma operator. */
  212. exp1 : exp
  213. | exp1 ',' exp
  214. { write_exp_elt_opcode (BINOP_COMMA); }
  215. ;
  216. /* Expressions, not including the comma operator. */
  217. exp : exp '^' %prec UNARY
  218. { write_exp_elt_opcode (UNOP_IND);
  219. if (current_type)
  220. current_type = TYPE_TARGET_TYPE (current_type); }
  221. ;
  222. exp : '@' exp %prec UNARY
  223. { write_exp_elt_opcode (UNOP_ADDR);
  224. if (current_type)
  225. current_type = TYPE_POINTER_TYPE (current_type); }
  226. ;
  227. exp : '-' exp %prec UNARY
  228. { write_exp_elt_opcode (UNOP_NEG); }
  229. ;
  230. exp : NOT exp %prec UNARY
  231. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  232. ;
  233. exp : INCREMENT '(' exp ')' %prec UNARY
  234. { write_exp_elt_opcode (UNOP_PREINCREMENT); }
  235. ;
  236. exp : DECREMENT '(' exp ')' %prec UNARY
  237. { write_exp_elt_opcode (UNOP_PREDECREMENT); }
  238. ;
  239. exp : exp '.' { search_field = 1; }
  240. FIELDNAME
  241. /* name */
  242. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  243. write_exp_string ($4);
  244. write_exp_elt_opcode (STRUCTOP_STRUCT);
  245. search_field = 0;
  246. if (current_type)
  247. { while (TYPE_CODE (current_type) == TYPE_CODE_PTR)
  248. current_type = TYPE_TARGET_TYPE (current_type);
  249. current_type = lookup_struct_elt_type (
  250. current_type, $4.ptr, 0); };
  251. } ;
  252. exp : exp '['
  253. /* We need to save the current_type value */
  254. { char *arrayname;
  255. int arrayfieldindex;
  256. arrayfieldindex = is_pascal_string_type (
  257. current_type, NULL, NULL,
  258. NULL, NULL, &arrayname);
  259. if (arrayfieldindex)
  260. {
  261. struct stoken stringsval;
  262. stringsval.ptr = alloca (strlen (arrayname) + 1);
  263. stringsval.length = strlen (arrayname);
  264. strcpy (stringsval.ptr, arrayname);
  265. current_type = TYPE_FIELD_TYPE (current_type,
  266. arrayfieldindex - 1);
  267. write_exp_elt_opcode (STRUCTOP_STRUCT);
  268. write_exp_string (stringsval);
  269. write_exp_elt_opcode (STRUCTOP_STRUCT);
  270. }
  271. push_current_type (); }
  272. exp1 ']'
  273. { pop_current_type ();
  274. write_exp_elt_opcode (BINOP_SUBSCRIPT);
  275. if (current_type)
  276. current_type = TYPE_TARGET_TYPE (current_type); }
  277. ;
  278. exp : exp '('
  279. /* This is to save the value of arglist_len
  280. being accumulated by an outer function call. */
  281. { push_current_type ();
  282. start_arglist (); }
  283. arglist ')' %prec ARROW
  284. { write_exp_elt_opcode (OP_FUNCALL);
  285. write_exp_elt_longcst ((LONGEST) end_arglist ());
  286. write_exp_elt_opcode (OP_FUNCALL);
  287. pop_current_type ();
  288. if (current_type)
  289. current_type = TYPE_TARGET_TYPE (current_type);
  290. }
  291. ;
  292. arglist :
  293. | exp
  294. { arglist_len = 1; }
  295. | arglist ',' exp %prec ABOVE_COMMA
  296. { arglist_len++; }
  297. ;
  298. exp : type '(' exp ')' %prec UNARY
  299. { if (current_type)
  300. {
  301. /* Allow automatic dereference of classes. */
  302. if ((TYPE_CODE (current_type) == TYPE_CODE_PTR)
  303. && (TYPE_CODE (TYPE_TARGET_TYPE (current_type)) == TYPE_CODE_CLASS)
  304. && (TYPE_CODE ($1) == TYPE_CODE_CLASS))
  305. write_exp_elt_opcode (UNOP_IND);
  306. }
  307. write_exp_elt_opcode (UNOP_CAST);
  308. write_exp_elt_type ($1);
  309. write_exp_elt_opcode (UNOP_CAST);
  310. current_type = $1; }
  311. ;
  312. exp : '(' exp1 ')'
  313. { }
  314. ;
  315. /* Binary operators in order of decreasing precedence. */
  316. exp : exp '*' exp
  317. { write_exp_elt_opcode (BINOP_MUL); }
  318. ;
  319. exp : exp '/' {
  320. if (current_type && is_integral_type (current_type))
  321. leftdiv_is_integer = 1;
  322. }
  323. exp
  324. {
  325. if (leftdiv_is_integer && current_type
  326. && is_integral_type (current_type))
  327. {
  328. write_exp_elt_opcode (UNOP_CAST);
  329. write_exp_elt_type (parse_type->builtin_long_double);
  330. current_type = parse_type->builtin_long_double;
  331. write_exp_elt_opcode (UNOP_CAST);
  332. leftdiv_is_integer = 0;
  333. }
  334. write_exp_elt_opcode (BINOP_DIV);
  335. }
  336. ;
  337. exp : exp DIV exp
  338. { write_exp_elt_opcode (BINOP_INTDIV); }
  339. ;
  340. exp : exp MOD exp
  341. { write_exp_elt_opcode (BINOP_REM); }
  342. ;
  343. exp : exp '+' exp
  344. { write_exp_elt_opcode (BINOP_ADD); }
  345. ;
  346. exp : exp '-' exp
  347. { write_exp_elt_opcode (BINOP_SUB); }
  348. ;
  349. exp : exp LSH exp
  350. { write_exp_elt_opcode (BINOP_LSH); }
  351. ;
  352. exp : exp RSH exp
  353. { write_exp_elt_opcode (BINOP_RSH); }
  354. ;
  355. exp : exp '=' exp
  356. { write_exp_elt_opcode (BINOP_EQUAL);
  357. current_type = parse_type->builtin_bool;
  358. }
  359. ;
  360. exp : exp NOTEQUAL exp
  361. { write_exp_elt_opcode (BINOP_NOTEQUAL);
  362. current_type = parse_type->builtin_bool;
  363. }
  364. ;
  365. exp : exp LEQ exp
  366. { write_exp_elt_opcode (BINOP_LEQ);
  367. current_type = parse_type->builtin_bool;
  368. }
  369. ;
  370. exp : exp GEQ exp
  371. { write_exp_elt_opcode (BINOP_GEQ);
  372. current_type = parse_type->builtin_bool;
  373. }
  374. ;
  375. exp : exp '<' exp
  376. { write_exp_elt_opcode (BINOP_LESS);
  377. current_type = parse_type->builtin_bool;
  378. }
  379. ;
  380. exp : exp '>' exp
  381. { write_exp_elt_opcode (BINOP_GTR);
  382. current_type = parse_type->builtin_bool;
  383. }
  384. ;
  385. exp : exp ANDAND exp
  386. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  387. ;
  388. exp : exp XOR exp
  389. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  390. ;
  391. exp : exp OR exp
  392. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  393. ;
  394. exp : exp ASSIGN exp
  395. { write_exp_elt_opcode (BINOP_ASSIGN); }
  396. ;
  397. exp : TRUEKEYWORD
  398. { write_exp_elt_opcode (OP_BOOL);
  399. write_exp_elt_longcst ((LONGEST) $1);
  400. current_type = parse_type->builtin_bool;
  401. write_exp_elt_opcode (OP_BOOL); }
  402. ;
  403. exp : FALSEKEYWORD
  404. { write_exp_elt_opcode (OP_BOOL);
  405. write_exp_elt_longcst ((LONGEST) $1);
  406. current_type = parse_type->builtin_bool;
  407. write_exp_elt_opcode (OP_BOOL); }
  408. ;
  409. exp : INT
  410. { write_exp_elt_opcode (OP_LONG);
  411. write_exp_elt_type ($1.type);
  412. current_type = $1.type;
  413. write_exp_elt_longcst ((LONGEST)($1.val));
  414. write_exp_elt_opcode (OP_LONG); }
  415. ;
  416. exp : NAME_OR_INT
  417. { YYSTYPE val;
  418. parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
  419. write_exp_elt_opcode (OP_LONG);
  420. write_exp_elt_type (val.typed_val_int.type);
  421. current_type = val.typed_val_int.type;
  422. write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
  423. write_exp_elt_opcode (OP_LONG);
  424. }
  425. ;
  426. exp : FLOAT
  427. { write_exp_elt_opcode (OP_DOUBLE);
  428. write_exp_elt_type ($1.type);
  429. current_type = $1.type;
  430. write_exp_elt_dblcst ($1.dval);
  431. write_exp_elt_opcode (OP_DOUBLE); }
  432. ;
  433. exp : variable
  434. ;
  435. exp : VARIABLE
  436. /* Already written by write_dollar_variable. */
  437. ;
  438. exp : SIZEOF '(' type ')' %prec UNARY
  439. { write_exp_elt_opcode (OP_LONG);
  440. write_exp_elt_type (parse_type->builtin_int);
  441. CHECK_TYPEDEF ($3);
  442. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  443. write_exp_elt_opcode (OP_LONG); }
  444. ;
  445. exp : SIZEOF '(' exp ')' %prec UNARY
  446. { write_exp_elt_opcode (UNOP_SIZEOF); }
  447. exp : STRING
  448. { /* C strings are converted into array constants with
  449. an explicit null byte added at the end. Thus
  450. the array upper bound is the string length.
  451. There is no such thing in C as a completely empty
  452. string. */
  453. char *sp = $1.ptr; int count = $1.length;
  454. while (count-- > 0)
  455. {
  456. write_exp_elt_opcode (OP_LONG);
  457. write_exp_elt_type (parse_type->builtin_char);
  458. write_exp_elt_longcst ((LONGEST)(*sp++));
  459. write_exp_elt_opcode (OP_LONG);
  460. }
  461. write_exp_elt_opcode (OP_LONG);
  462. write_exp_elt_type (parse_type->builtin_char);
  463. write_exp_elt_longcst ((LONGEST)'\0');
  464. write_exp_elt_opcode (OP_LONG);
  465. write_exp_elt_opcode (OP_ARRAY);
  466. write_exp_elt_longcst ((LONGEST) 0);
  467. write_exp_elt_longcst ((LONGEST) ($1.length));
  468. write_exp_elt_opcode (OP_ARRAY); }
  469. ;
  470. /* Object pascal */
  471. exp : THIS
  472. {
  473. struct value * this_val;
  474. struct type * this_type;
  475. write_exp_elt_opcode (OP_THIS);
  476. write_exp_elt_opcode (OP_THIS);
  477. /* we need type of this */
  478. this_val = value_of_this (0);
  479. if (this_val)
  480. this_type = value_type (this_val);
  481. else
  482. this_type = NULL;
  483. if (this_type)
  484. {
  485. if (TYPE_CODE (this_type) == TYPE_CODE_PTR)
  486. {
  487. this_type = TYPE_TARGET_TYPE (this_type);
  488. write_exp_elt_opcode (UNOP_IND);
  489. }
  490. }
  491. current_type = this_type;
  492. }
  493. ;
  494. /* end of object pascal. */
  495. block : BLOCKNAME
  496. {
  497. if ($1.sym != 0)
  498. $$ = SYMBOL_BLOCK_VALUE ($1.sym);
  499. else
  500. {
  501. struct symtab *tem =
  502. lookup_symtab (copy_name ($1.stoken));
  503. if (tem)
  504. $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), STATIC_BLOCK);
  505. else
  506. error ("No file or function \"%s\".",
  507. copy_name ($1.stoken));
  508. }
  509. }
  510. ;
  511. block : block COLONCOLON name
  512. { struct symbol *tem
  513. = lookup_symbol (copy_name ($3), $1,
  514. VAR_DOMAIN, (int *) NULL);
  515. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  516. error ("No function \"%s\" in specified context.",
  517. copy_name ($3));
  518. $$ = SYMBOL_BLOCK_VALUE (tem); }
  519. ;
  520. variable: block COLONCOLON name
  521. { struct symbol *sym;
  522. sym = lookup_symbol (copy_name ($3), $1,
  523. VAR_DOMAIN, (int *) NULL);
  524. if (sym == 0)
  525. error ("No symbol \"%s\" in specified context.",
  526. copy_name ($3));
  527. write_exp_elt_opcode (OP_VAR_VALUE);
  528. /* block_found is set by lookup_symbol. */
  529. write_exp_elt_block (block_found);
  530. write_exp_elt_sym (sym);
  531. write_exp_elt_opcode (OP_VAR_VALUE); }
  532. ;
  533. qualified_name: typebase COLONCOLON name
  534. {
  535. struct type *type = $1;
  536. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  537. && TYPE_CODE (type) != TYPE_CODE_UNION)
  538. error ("`%s' is not defined as an aggregate type.",
  539. TYPE_NAME (type));
  540. write_exp_elt_opcode (OP_SCOPE);
  541. write_exp_elt_type (type);
  542. write_exp_string ($3);
  543. write_exp_elt_opcode (OP_SCOPE);
  544. }
  545. ;
  546. variable: qualified_name
  547. | COLONCOLON name
  548. {
  549. char *name = copy_name ($2);
  550. struct symbol *sym;
  551. struct minimal_symbol *msymbol;
  552. sym =
  553. lookup_symbol (name, (const struct block *) NULL,
  554. VAR_DOMAIN, (int *) NULL);
  555. if (sym)
  556. {
  557. write_exp_elt_opcode (OP_VAR_VALUE);
  558. write_exp_elt_block (NULL);
  559. write_exp_elt_sym (sym);
  560. write_exp_elt_opcode (OP_VAR_VALUE);
  561. break;
  562. }
  563. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  564. if (msymbol != NULL)
  565. write_exp_msymbol (msymbol);
  566. else if (!have_full_symbols () && !have_partial_symbols ())
  567. error ("No symbol table is loaded. Use the \"file\" command.");
  568. else
  569. error ("No symbol \"%s\" in current context.", name);
  570. }
  571. ;
  572. variable: name_not_typename
  573. { struct symbol *sym = $1.sym;
  574. if (sym)
  575. {
  576. if (symbol_read_needs_frame (sym))
  577. {
  578. if (innermost_block == 0
  579. || contained_in (block_found,
  580. innermost_block))
  581. innermost_block = block_found;
  582. }
  583. write_exp_elt_opcode (OP_VAR_VALUE);
  584. /* We want to use the selected frame, not
  585. another more inner frame which happens to
  586. be in the same block. */
  587. write_exp_elt_block (NULL);
  588. write_exp_elt_sym (sym);
  589. write_exp_elt_opcode (OP_VAR_VALUE);
  590. current_type = sym->type; }
  591. else if ($1.is_a_field_of_this)
  592. {
  593. struct value * this_val;
  594. struct type * this_type;
  595. /* Object pascal: it hangs off of `this'. Must
  596. not inadvertently convert from a method call
  597. to data ref. */
  598. if (innermost_block == 0
  599. || contained_in (block_found,
  600. innermost_block))
  601. innermost_block = block_found;
  602. write_exp_elt_opcode (OP_THIS);
  603. write_exp_elt_opcode (OP_THIS);
  604. write_exp_elt_opcode (STRUCTOP_PTR);
  605. write_exp_string ($1.stoken);
  606. write_exp_elt_opcode (STRUCTOP_PTR);
  607. /* we need type of this */
  608. this_val = value_of_this (0);
  609. if (this_val)
  610. this_type = value_type (this_val);
  611. else
  612. this_type = NULL;
  613. if (this_type)
  614. current_type = lookup_struct_elt_type (
  615. this_type,
  616. copy_name ($1.stoken), 0);
  617. else
  618. current_type = NULL;
  619. }
  620. else
  621. {
  622. struct minimal_symbol *msymbol;
  623. char *arg = copy_name ($1.stoken);
  624. msymbol =
  625. lookup_minimal_symbol (arg, NULL, NULL);
  626. if (msymbol != NULL)
  627. write_exp_msymbol (msymbol);
  628. else if (!have_full_symbols () && !have_partial_symbols ())
  629. error ("No symbol table is loaded. Use the \"file\" command.");
  630. else
  631. error ("No symbol \"%s\" in current context.",
  632. copy_name ($1.stoken));
  633. }
  634. }
  635. ;
  636. ptype : typebase
  637. ;
  638. /* We used to try to recognize more pointer to member types here, but
  639. that didn't work (shift/reduce conflicts meant that these rules never
  640. got executed). The problem is that
  641. int (foo::bar::baz::bizzle)
  642. is a function type but
  643. int (foo::bar::baz::bizzle::*)
  644. is a pointer to member type. Stroustrup loses again! */
  645. type : ptype
  646. ;
  647. typebase /* Implements (approximately): (type-qualifier)* type-specifier */
  648. : '^' typebase
  649. { $$ = lookup_pointer_type ($2); }
  650. | TYPENAME
  651. { $$ = $1.type; }
  652. | STRUCT name
  653. { $$ = lookup_struct (copy_name ($2),
  654. expression_context_block); }
  655. | CLASS name
  656. { $$ = lookup_struct (copy_name ($2),
  657. expression_context_block); }
  658. /* "const" and "volatile" are curently ignored. A type qualifier
  659. after the type is handled in the ptype rule. I think these could
  660. be too. */
  661. ;
  662. name : NAME { $$ = $1.stoken; }
  663. | BLOCKNAME { $$ = $1.stoken; }
  664. | TYPENAME { $$ = $1.stoken; }
  665. | NAME_OR_INT { $$ = $1.stoken; }
  666. ;
  667. name_not_typename : NAME
  668. | BLOCKNAME
  669. /* These would be useful if name_not_typename was useful, but it is just
  670. a fake for "variable", so these cause reduce/reduce conflicts because
  671. the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  672. =exp) or just an exp. If name_not_typename was ever used in an lvalue
  673. context where only a name could occur, this might be useful.
  674. | NAME_OR_INT
  675. */
  676. ;
  677. %%
  678. /* Take care of parsing a number (anything that starts with a digit).
  679. Set yylval and return the token type; update lexptr.
  680. LEN is the number of characters in it. */
  681. /*** Needs some error checking for the float case ***/
  682. static int
  683. parse_number (p, len, parsed_float, putithere)
  684. char *p;
  685. int len;
  686. int parsed_float;
  687. YYSTYPE *putithere;
  688. {
  689. /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
  690. here, and we do kind of silly things like cast to unsigned. */
  691. LONGEST n = 0;
  692. LONGEST prevn = 0;
  693. ULONGEST un;
  694. int i = 0;
  695. int c;
  696. int base = input_radix;
  697. int unsigned_p = 0;
  698. /* Number of "L" suffixes encountered. */
  699. int long_p = 0;
  700. /* We have found a "L" or "U" suffix. */
  701. int found_suffix = 0;
  702. ULONGEST high_bit;
  703. struct type *signed_type;
  704. struct type *unsigned_type;
  705. if (parsed_float)
  706. {
  707. /* It's a float since it contains a point or an exponent. */
  708. char c;
  709. int num = 0; /* number of tokens scanned by scanf */
  710. char saved_char = p[len];
  711. p[len] = 0; /* null-terminate the token */
  712. num = sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%c",
  713. &putithere->typed_val_float.dval, &c);
  714. p[len] = saved_char; /* restore the input stream */
  715. if (num != 1) /* check scanf found ONLY a float ... */
  716. return ERROR;
  717. /* See if it has `f' or `l' suffix (float or long double). */
  718. c = tolower (p[len - 1]);
  719. if (c == 'f')
  720. putithere->typed_val_float.type = parse_type->builtin_float;
  721. else if (c == 'l')
  722. putithere->typed_val_float.type = parse_type->builtin_long_double;
  723. else if (isdigit (c) || c == '.')
  724. putithere->typed_val_float.type = parse_type->builtin_double;
  725. else
  726. return ERROR;
  727. return FLOAT;
  728. }
  729. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  730. if (p[0] == '0')
  731. switch (p[1])
  732. {
  733. case 'x':
  734. case 'X':
  735. if (len >= 3)
  736. {
  737. p += 2;
  738. base = 16;
  739. len -= 2;
  740. }
  741. break;
  742. case 't':
  743. case 'T':
  744. case 'd':
  745. case 'D':
  746. if (len >= 3)
  747. {
  748. p += 2;
  749. base = 10;
  750. len -= 2;
  751. }
  752. break;
  753. default:
  754. base = 8;
  755. break;
  756. }
  757. while (len-- > 0)
  758. {
  759. c = *p++;
  760. if (c >= 'A' && c <= 'Z')
  761. c += 'a' - 'A';
  762. if (c != 'l' && c != 'u')
  763. n *= base;
  764. if (c >= '0' && c <= '9')
  765. {
  766. if (found_suffix)
  767. return ERROR;
  768. n += i = c - '0';
  769. }
  770. else
  771. {
  772. if (base > 10 && c >= 'a' && c <= 'f')
  773. {
  774. if (found_suffix)
  775. return ERROR;
  776. n += i = c - 'a' + 10;
  777. }
  778. else if (c == 'l')
  779. {
  780. ++long_p;
  781. found_suffix = 1;
  782. }
  783. else if (c == 'u')
  784. {
  785. unsigned_p = 1;
  786. found_suffix = 1;
  787. }
  788. else
  789. return ERROR; /* Char not a digit */
  790. }
  791. if (i >= base)
  792. return ERROR; /* Invalid digit in this base */
  793. /* Portably test for overflow (only works for nonzero values, so make
  794. a second check for zero). FIXME: Can't we just make n and prevn
  795. unsigned and avoid this? */
  796. if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
  797. unsigned_p = 1; /* Try something unsigned */
  798. /* Portably test for unsigned overflow.
  799. FIXME: This check is wrong; for example it doesn't find overflow
  800. on 0x123456789 when LONGEST is 32 bits. */
  801. if (c != 'l' && c != 'u' && n != 0)
  802. {
  803. if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
  804. error ("Numeric constant too large.");
  805. }
  806. prevn = n;
  807. }
  808. /* An integer constant is an int, a long, or a long long. An L
  809. suffix forces it to be long; an LL suffix forces it to be long
  810. long. If not forced to a larger size, it gets the first type of
  811. the above that it fits in. To figure out whether it fits, we
  812. shift it right and see whether anything remains. Note that we
  813. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  814. operation, because many compilers will warn about such a shift
  815. (which always produces a zero result). Sometimes gdbarch_int_bit
  816. or gdbarch_long_bit will be that big, sometimes not. To deal with
  817. the case where it is we just always shift the value more than
  818. once, with fewer bits each time. */
  819. un = (ULONGEST)n >> 2;
  820. if (long_p == 0
  821. && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
  822. {
  823. high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
  824. /* A large decimal (not hex or octal) constant (between INT_MAX
  825. and UINT_MAX) is a long or unsigned long, according to ANSI,
  826. never an unsigned int, but this code treats it as unsigned
  827. int. This probably should be fixed. GCC gives a warning on
  828. such constants. */
  829. unsigned_type = parse_type->builtin_unsigned_int;
  830. signed_type = parse_type->builtin_int;
  831. }
  832. else if (long_p <= 1
  833. && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
  834. {
  835. high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
  836. unsigned_type = parse_type->builtin_unsigned_long;
  837. signed_type = parse_type->builtin_long;
  838. }
  839. else
  840. {
  841. int shift;
  842. if (sizeof (ULONGEST) * HOST_CHAR_BIT
  843. < gdbarch_long_long_bit (parse_gdbarch))
  844. /* A long long does not fit in a LONGEST. */
  845. shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
  846. else
  847. shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
  848. high_bit = (ULONGEST) 1 << shift;
  849. unsigned_type = parse_type->builtin_unsigned_long_long;
  850. signed_type = parse_type->builtin_long_long;
  851. }
  852. putithere->typed_val_int.val = n;
  853. /* If the high bit of the worked out type is set then this number
  854. has to be unsigned. */
  855. if (unsigned_p || (n & high_bit))
  856. {
  857. putithere->typed_val_int.type = unsigned_type;
  858. }
  859. else
  860. {
  861. putithere->typed_val_int.type = signed_type;
  862. }
  863. return INT;
  864. }
  865. struct type_push
  866. {
  867. struct type *stored;
  868. struct type_push *next;
  869. };
  870. static struct type_push *tp_top = NULL;
  871. static void
  872. push_current_type (void)
  873. {
  874. struct type_push *tpnew;
  875. tpnew = (struct type_push *) malloc (sizeof (struct type_push));
  876. tpnew->next = tp_top;
  877. tpnew->stored = current_type;
  878. current_type = NULL;
  879. tp_top = tpnew;
  880. }
  881. static void
  882. pop_current_type (void)
  883. {
  884. struct type_push *tp = tp_top;
  885. if (tp)
  886. {
  887. current_type = tp->stored;
  888. tp_top = tp->next;
  889. free (tp);
  890. }
  891. }
  892. struct token
  893. {
  894. char *operator;
  895. int token;
  896. enum exp_opcode opcode;
  897. };
  898. static const struct token tokentab3[] =
  899. {
  900. {"shr", RSH, BINOP_END},
  901. {"shl", LSH, BINOP_END},
  902. {"and", ANDAND, BINOP_END},
  903. {"div", DIV, BINOP_END},
  904. {"not", NOT, BINOP_END},
  905. {"mod", MOD, BINOP_END},
  906. {"inc", INCREMENT, BINOP_END},
  907. {"dec", DECREMENT, BINOP_END},
  908. {"xor", XOR, BINOP_END}
  909. };
  910. static const struct token tokentab2[] =
  911. {
  912. {"or", OR, BINOP_END},
  913. {"<>", NOTEQUAL, BINOP_END},
  914. {"<=", LEQ, BINOP_END},
  915. {">=", GEQ, BINOP_END},
  916. {":=", ASSIGN, BINOP_END},
  917. {"::", COLONCOLON, BINOP_END} };
  918. /* Allocate uppercased var */
  919. /* make an uppercased copy of tokstart */
  920. static char * uptok (tokstart, namelen)
  921. char *tokstart;
  922. int namelen;
  923. {
  924. int i;
  925. char *uptokstart = (char *)malloc(namelen+1);
  926. for (i = 0;i <= namelen;i++)
  927. {
  928. if ((tokstart[i]>='a' && tokstart[i]<='z'))
  929. uptokstart[i] = tokstart[i]-('a'-'A');
  930. else
  931. uptokstart[i] = tokstart[i];
  932. }
  933. uptokstart[namelen]='\0';
  934. return uptokstart;
  935. }
  936. /* Read one token, getting characters through lexptr. */
  937. static int
  938. yylex ()
  939. {
  940. int c;
  941. int namelen;
  942. unsigned int i;
  943. char *tokstart;
  944. char *uptokstart;
  945. char *tokptr;
  946. int explen, tempbufindex;
  947. static char *tempbuf;
  948. static int tempbufsize;
  949. retry:
  950. prev_lexptr = lexptr;
  951. tokstart = lexptr;
  952. explen = strlen (lexptr);
  953. /* See if it is a special token of length 3. */
  954. if (explen > 2)
  955. for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
  956. if (strncasecmp (tokstart, tokentab3[i].operator, 3) == 0
  957. && (!isalpha (tokentab3[i].operator[0]) || explen == 3
  958. || (!isalpha (tokstart[3]) && !isdigit (tokstart[3]) && tokstart[3] != '_')))
  959. {
  960. lexptr += 3;
  961. yylval.opcode = tokentab3[i].opcode;
  962. return tokentab3[i].token;
  963. }
  964. /* See if it is a special token of length 2. */
  965. if (explen > 1)
  966. for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
  967. if (strncasecmp (tokstart, tokentab2[i].operator, 2) == 0
  968. && (!isalpha (tokentab2[i].operator[0]) || explen == 2
  969. || (!isalpha (tokstart[2]) && !isdigit (tokstart[2]) && tokstart[2] != '_')))
  970. {
  971. lexptr += 2;
  972. yylval.opcode = tokentab2[i].opcode;
  973. return tokentab2[i].token;
  974. }
  975. switch (c = *tokstart)
  976. {
  977. case 0:
  978. return 0;
  979. case ' ':
  980. case '\t':
  981. case '\n':
  982. lexptr++;
  983. goto retry;
  984. case '\'':
  985. /* We either have a character constant ('0' or '\177' for example)
  986. or we have a quoted symbol reference ('foo(int,int)' in object pascal
  987. for example). */
  988. lexptr++;
  989. c = *lexptr++;
  990. if (c == '\\')
  991. c = parse_escape (parse_gdbarch, &lexptr);
  992. else if (c == '\'')
  993. error ("Empty character constant.");
  994. yylval.typed_val_int.val = c;
  995. yylval.typed_val_int.type = parse_type->builtin_char;
  996. c = *lexptr++;
  997. if (c != '\'')
  998. {
  999. namelen = skip_quoted (tokstart) - tokstart;
  1000. if (namelen > 2)
  1001. {
  1002. lexptr = tokstart + namelen;
  1003. if (lexptr[-1] != '\'')
  1004. error ("Unmatched single quote.");
  1005. namelen -= 2;
  1006. tokstart++;
  1007. uptokstart = uptok(tokstart,namelen);
  1008. goto tryname;
  1009. }
  1010. error ("Invalid character constant.");
  1011. }
  1012. return INT;
  1013. case '(':
  1014. paren_depth++;
  1015. lexptr++;
  1016. return c;
  1017. case ')':
  1018. if (paren_depth == 0)
  1019. return 0;
  1020. paren_depth--;
  1021. lexptr++;
  1022. return c;
  1023. case ',':
  1024. if (comma_terminates && paren_depth == 0)
  1025. return 0;
  1026. lexptr++;
  1027. return c;
  1028. case '.':
  1029. /* Might be a floating point number. */
  1030. if (lexptr[1] < '0' || lexptr[1] > '9')
  1031. goto symbol; /* Nope, must be a symbol. */
  1032. /* FALL THRU into number case. */
  1033. case '0':
  1034. case '1':
  1035. case '2':
  1036. case '3':
  1037. case '4':
  1038. case '5':
  1039. case '6':
  1040. case '7':
  1041. case '8':
  1042. case '9':
  1043. {
  1044. /* It's a number. */
  1045. int got_dot = 0, got_e = 0, toktype;
  1046. char *p = tokstart;
  1047. int hex = input_radix > 10;
  1048. if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
  1049. {
  1050. p += 2;
  1051. hex = 1;
  1052. }
  1053. else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  1054. {
  1055. p += 2;
  1056. hex = 0;
  1057. }
  1058. for (;; ++p)
  1059. {
  1060. /* This test includes !hex because 'e' is a valid hex digit
  1061. and thus does not indicate a floating point number when
  1062. the radix is hex. */
  1063. if (!hex && !got_e && (*p == 'e' || *p == 'E'))
  1064. got_dot = got_e = 1;
  1065. /* This test does not include !hex, because a '.' always indicates
  1066. a decimal floating point number regardless of the radix. */
  1067. else if (!got_dot && *p == '.')
  1068. got_dot = 1;
  1069. else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
  1070. && (*p == '-' || *p == '+'))
  1071. /* This is the sign of the exponent, not the end of the
  1072. number. */
  1073. continue;
  1074. /* We will take any letters or digits. parse_number will
  1075. complain if past the radix, or if L or U are not final. */
  1076. else if ((*p < '0' || *p > '9')
  1077. && ((*p < 'a' || *p > 'z')
  1078. && (*p < 'A' || *p > 'Z')))
  1079. break;
  1080. }
  1081. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
  1082. if (toktype == ERROR)
  1083. {
  1084. char *err_copy = (char *) alloca (p - tokstart + 1);
  1085. memcpy (err_copy, tokstart, p - tokstart);
  1086. err_copy[p - tokstart] = 0;
  1087. error ("Invalid number \"%s\".", err_copy);
  1088. }
  1089. lexptr = p;
  1090. return toktype;
  1091. }
  1092. case '+':
  1093. case '-':
  1094. case '*':
  1095. case '/':
  1096. case '|':
  1097. case '&':
  1098. case '^':
  1099. case '~':
  1100. case '!':
  1101. case '@':
  1102. case '<':
  1103. case '>':
  1104. case '[':
  1105. case ']':
  1106. case '?':
  1107. case ':':
  1108. case '=':
  1109. case '{':
  1110. case '}':
  1111. symbol:
  1112. lexptr++;
  1113. return c;
  1114. case '"':
  1115. /* Build the gdb internal form of the input string in tempbuf,
  1116. translating any standard C escape forms seen. Note that the
  1117. buffer is null byte terminated *only* for the convenience of
  1118. debugging gdb itself and printing the buffer contents when
  1119. the buffer contains no embedded nulls. Gdb does not depend
  1120. upon the buffer being null byte terminated, it uses the length
  1121. string instead. This allows gdb to handle C strings (as well
  1122. as strings in other languages) with embedded null bytes */
  1123. tokptr = ++tokstart;
  1124. tempbufindex = 0;
  1125. do {
  1126. /* Grow the static temp buffer if necessary, including allocating
  1127. the first one on demand. */
  1128. if (tempbufindex + 1 >= tempbufsize)
  1129. {
  1130. tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
  1131. }
  1132. switch (*tokptr)
  1133. {
  1134. case '\0':
  1135. case '"':
  1136. /* Do nothing, loop will terminate. */
  1137. break;
  1138. case '\\':
  1139. tokptr++;
  1140. c = parse_escape (parse_gdbarch, &tokptr);
  1141. if (c == -1)
  1142. {
  1143. continue;
  1144. }
  1145. tempbuf[tempbufindex++] = c;
  1146. break;
  1147. default:
  1148. tempbuf[tempbufindex++] = *tokptr++;
  1149. break;
  1150. }
  1151. } while ((*tokptr != '"') && (*tokptr != '\0'));
  1152. if (*tokptr++ != '"')
  1153. {
  1154. error ("Unterminated string in expression.");
  1155. }
  1156. tempbuf[tempbufindex] = '\0'; /* See note above */
  1157. yylval.sval.ptr = tempbuf;
  1158. yylval.sval.length = tempbufindex;
  1159. lexptr = tokptr;
  1160. return (STRING);
  1161. }
  1162. if (!(c == '_' || c == '$'
  1163. || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
  1164. /* We must have come across a bad character (e.g. ';'). */
  1165. error ("Invalid character '%c' in expression.", c);
  1166. /* It's a name. See how long it is. */
  1167. namelen = 0;
  1168. for (c = tokstart[namelen];
  1169. (c == '_' || c == '$' || (c >= '0' && c <= '9')
  1170. || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
  1171. {
  1172. /* Template parameter lists are part of the name.
  1173. FIXME: This mishandles `print $a<4&&$a>3'. */
  1174. if (c == '<')
  1175. {
  1176. int i = namelen;
  1177. int nesting_level = 1;
  1178. while (tokstart[++i])
  1179. {
  1180. if (tokstart[i] == '<')
  1181. nesting_level++;
  1182. else if (tokstart[i] == '>')
  1183. {
  1184. if (--nesting_level == 0)
  1185. break;
  1186. }
  1187. }
  1188. if (tokstart[i] == '>')
  1189. namelen = i;
  1190. else
  1191. break;
  1192. }
  1193. /* do NOT uppercase internals because of registers !!! */
  1194. c = tokstart[++namelen];
  1195. }
  1196. uptokstart = uptok(tokstart,namelen);
  1197. /* The token "if" terminates the expression and is NOT
  1198. removed from the input stream. */
  1199. if (namelen == 2 && uptokstart[0] == 'I' && uptokstart[1] == 'F')
  1200. {
  1201. free (uptokstart);
  1202. return 0;
  1203. }
  1204. lexptr += namelen;
  1205. tryname:
  1206. /* Catch specific keywords. Should be done with a data structure. */
  1207. switch (namelen)
  1208. {
  1209. case 6:
  1210. if (strcmp (uptokstart, "OBJECT") == 0)
  1211. {
  1212. free (uptokstart);
  1213. return CLASS;
  1214. }
  1215. if (strcmp (uptokstart, "RECORD") == 0)
  1216. {
  1217. free (uptokstart);
  1218. return STRUCT;
  1219. }
  1220. if (strcmp (uptokstart, "SIZEOF") == 0)
  1221. {
  1222. free (uptokstart);
  1223. return SIZEOF;
  1224. }
  1225. break;
  1226. case 5:
  1227. if (strcmp (uptokstart, "CLASS") == 0)
  1228. {
  1229. free (uptokstart);
  1230. return CLASS;
  1231. }
  1232. if (strcmp (uptokstart, "FALSE") == 0)
  1233. {
  1234. yylval.lval = 0;
  1235. free (uptokstart);
  1236. return FALSEKEYWORD;
  1237. }
  1238. break;
  1239. case 4:
  1240. if (strcmp (uptokstart, "TRUE") == 0)
  1241. {
  1242. yylval.lval = 1;
  1243. free (uptokstart);
  1244. return TRUEKEYWORD;
  1245. }
  1246. if (strcmp (uptokstart, "SELF") == 0)
  1247. {
  1248. /* here we search for 'this' like
  1249. inserted in FPC stabs debug info */
  1250. static const char this_name[] = "this";
  1251. if (lookup_symbol (this_name, expression_context_block,
  1252. VAR_DOMAIN, (int *) NULL))
  1253. {
  1254. free (uptokstart);
  1255. return THIS;
  1256. }
  1257. }
  1258. break;
  1259. default:
  1260. break;
  1261. }
  1262. yylval.sval.ptr = tokstart;
  1263. yylval.sval.length = namelen;
  1264. if (*tokstart == '$')
  1265. {
  1266. /* $ is the normal prefix for pascal hexadecimal values
  1267. but this conflicts with the GDB use for debugger variables
  1268. so in expression to enter hexadecimal values
  1269. we still need to use C syntax with 0xff */
  1270. write_dollar_variable (yylval.sval);
  1271. free (uptokstart);
  1272. return VARIABLE;
  1273. }
  1274. /* Use token-type BLOCKNAME for symbols that happen to be defined as
  1275. functions or symtabs. If this is not so, then ...
  1276. Use token-type TYPENAME for symbols that happen to be defined
  1277. currently as names of types; NAME for other symbols.
  1278. The caller is not constrained to care about the distinction. */
  1279. {
  1280. char *tmp = copy_name (yylval.sval);
  1281. struct symbol *sym;
  1282. int is_a_field_of_this = 0;
  1283. int is_a_field = 0;
  1284. int hextype;
  1285. if (search_field && current_type)
  1286. is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
  1287. if (is_a_field)
  1288. sym = NULL;
  1289. else
  1290. sym = lookup_symbol (tmp, expression_context_block,
  1291. VAR_DOMAIN, &is_a_field_of_this);
  1292. /* second chance uppercased (as Free Pascal does). */
  1293. if (!sym && !is_a_field_of_this && !is_a_field)
  1294. {
  1295. for (i = 0; i <= namelen; i++)
  1296. {
  1297. if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
  1298. tmp[i] -= ('a'-'A');
  1299. }
  1300. if (search_field && current_type)
  1301. is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
  1302. if (is_a_field)
  1303. sym = NULL;
  1304. else
  1305. sym = lookup_symbol (tmp, expression_context_block,
  1306. VAR_DOMAIN, &is_a_field_of_this);
  1307. if (sym || is_a_field_of_this || is_a_field)
  1308. for (i = 0; i <= namelen; i++)
  1309. {
  1310. if ((tokstart[i] >= 'a' && tokstart[i] <= 'z'))
  1311. tokstart[i] -= ('a'-'A');
  1312. }
  1313. }
  1314. /* Third chance Capitalized (as GPC does). */
  1315. if (!sym && !is_a_field_of_this && !is_a_field)
  1316. {
  1317. for (i = 0; i <= namelen; i++)
  1318. {
  1319. if (i == 0)
  1320. {
  1321. if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
  1322. tmp[i] -= ('a'-'A');
  1323. }
  1324. else
  1325. if ((tmp[i] >= 'A' && tmp[i] <= 'Z'))
  1326. tmp[i] -= ('A'-'a');
  1327. }
  1328. if (search_field && current_type)
  1329. is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
  1330. if (is_a_field)
  1331. sym = NULL;
  1332. else
  1333. sym = lookup_symbol (tmp, expression_context_block,
  1334. VAR_DOMAIN, &is_a_field_of_this);
  1335. if (sym || is_a_field_of_this || is_a_field)
  1336. for (i = 0; i <= namelen; i++)
  1337. {
  1338. if (i == 0)
  1339. {
  1340. if ((tokstart[i] >= 'a' && tokstart[i] <= 'z'))
  1341. tokstart[i] -= ('a'-'A');
  1342. }
  1343. else
  1344. if ((tokstart[i] >= 'A' && tokstart[i] <= 'Z'))
  1345. tokstart[i] -= ('A'-'a');
  1346. }
  1347. }
  1348. if (is_a_field)
  1349. {
  1350. tempbuf = (char *) realloc (tempbuf, namelen + 1);
  1351. strncpy (tempbuf, tokstart, namelen); tempbuf [namelen] = 0;
  1352. yylval.sval.ptr = tempbuf;
  1353. yylval.sval.length = namelen;
  1354. free (uptokstart);
  1355. return FIELDNAME;
  1356. }
  1357. /* Call lookup_symtab, not lookup_partial_symtab, in case there are
  1358. no psymtabs (coff, xcoff, or some future change to blow away the
  1359. psymtabs once once symbols are read). */
  1360. if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
  1361. || lookup_symtab (tmp))
  1362. {
  1363. yylval.ssym.sym = sym;
  1364. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1365. free (uptokstart);
  1366. return BLOCKNAME;
  1367. }
  1368. if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  1369. {
  1370. #if 1
  1371. /* Despite the following flaw, we need to keep this code enabled.
  1372. Because we can get called from check_stub_method, if we don't
  1373. handle nested types then it screws many operations in any
  1374. program which uses nested types. */
  1375. /* In "A::x", if x is a member function of A and there happens
  1376. to be a type (nested or not, since the stabs don't make that
  1377. distinction) named x, then this code incorrectly thinks we
  1378. are dealing with nested types rather than a member function. */
  1379. char *p;
  1380. char *namestart;
  1381. struct symbol *best_sym;
  1382. /* Look ahead to detect nested types. This probably should be
  1383. done in the grammar, but trying seemed to introduce a lot
  1384. of shift/reduce and reduce/reduce conflicts. It's possible
  1385. that it could be done, though. Or perhaps a non-grammar, but
  1386. less ad hoc, approach would work well. */
  1387. /* Since we do not currently have any way of distinguishing
  1388. a nested type from a non-nested one (the stabs don't tell
  1389. us whether a type is nested), we just ignore the
  1390. containing type. */
  1391. p = lexptr;
  1392. best_sym = sym;
  1393. while (1)
  1394. {
  1395. /* Skip whitespace. */
  1396. while (*p == ' ' || *p == '\t' || *p == '\n')
  1397. ++p;
  1398. if (*p == ':' && p[1] == ':')
  1399. {
  1400. /* Skip the `::'. */
  1401. p += 2;
  1402. /* Skip whitespace. */
  1403. while (*p == ' ' || *p == '\t' || *p == '\n')
  1404. ++p;
  1405. namestart = p;
  1406. while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
  1407. || (*p >= 'a' && *p <= 'z')
  1408. || (*p >= 'A' && *p <= 'Z'))
  1409. ++p;
  1410. if (p != namestart)
  1411. {
  1412. struct symbol *cur_sym;
  1413. /* As big as the whole rest of the expression, which is
  1414. at least big enough. */
  1415. char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
  1416. char *tmp1;
  1417. tmp1 = ncopy;
  1418. memcpy (tmp1, tmp, strlen (tmp));
  1419. tmp1 += strlen (tmp);
  1420. memcpy (tmp1, "::", 2);
  1421. tmp1 += 2;
  1422. memcpy (tmp1, namestart, p - namestart);
  1423. tmp1[p - namestart] = '\0';
  1424. cur_sym = lookup_symbol (ncopy, expression_context_block,
  1425. VAR_DOMAIN, (int *) NULL);
  1426. if (cur_sym)
  1427. {
  1428. if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
  1429. {
  1430. best_sym = cur_sym;
  1431. lexptr = p;
  1432. }
  1433. else
  1434. break;
  1435. }
  1436. else
  1437. break;
  1438. }
  1439. else
  1440. break;
  1441. }
  1442. else
  1443. break;
  1444. }
  1445. yylval.tsym.type = SYMBOL_TYPE (best_sym);
  1446. #else /* not 0 */
  1447. yylval.tsym.type = SYMBOL_TYPE (sym);
  1448. #endif /* not 0 */
  1449. free (uptokstart);
  1450. return TYPENAME;
  1451. }
  1452. yylval.tsym.type
  1453. = language_lookup_primitive_type_by_name (parse_language,
  1454. parse_gdbarch, tmp);
  1455. if (yylval.tsym.type != NULL)
  1456. {
  1457. free (uptokstart);
  1458. return TYPENAME;
  1459. }
  1460. /* Input names that aren't symbols but ARE valid hex numbers,
  1461. when the input radix permits them, can be names or numbers
  1462. depending on the parse. Note we support radixes > 16 here. */
  1463. if (!sym
  1464. && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
  1465. || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
  1466. {
  1467. YYSTYPE newlval; /* Its value is ignored. */
  1468. hextype = parse_number (tokstart, namelen, 0, &newlval);
  1469. if (hextype == INT)
  1470. {
  1471. yylval.ssym.sym = sym;
  1472. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1473. free (uptokstart);
  1474. return NAME_OR_INT;
  1475. }
  1476. }
  1477. free(uptokstart);
  1478. /* Any other kind of symbol */
  1479. yylval.ssym.sym = sym;
  1480. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1481. return NAME;
  1482. }
  1483. }
  1484. void
  1485. yyerror (msg)
  1486. char *msg;
  1487. {
  1488. if (prev_lexptr)
  1489. lexptr = prev_lexptr;
  1490. error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
  1491. }