PageRenderTime 52ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/gdb-7.4.50.20120714/gdb/p-exp.y

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