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

/insight-7.4.50/gdb/p-exp.y

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