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

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

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