PageRenderTime 67ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/netbsd/src/external/gpl3/gdb/dist/gdb/p-exp.y

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