PageRenderTime 80ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

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