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

/gdb-7.4.50.20120714/gdb/objc-exp.y

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