PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/avr-gdb-7.1/gdb-7.1/gdb/objc-exp.y

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