PageRenderTime 75ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/gdb-7/gdb/objc-exp.y

http://github.com/davshao/dflygsocdrm
Happy | 1787 lines | 1583 code | 204 blank | 0 comment | 0 complexity | 20a6a5b9340f5465de5b38222b61db2e MD5 | raw file
Possible License(s): AGPL-1.0, CC-BY-SA-3.0, LGPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception, 0BSD, BSD-3-Clause, GPL-2.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. write_exp_elt_opcode (OP_VAR_VALUE);
  544. /* block_found is set by lookup_symbol. */
  545. write_exp_elt_block (block_found);
  546. write_exp_elt_sym (sym);
  547. write_exp_elt_opcode (OP_VAR_VALUE); }
  548. ;
  549. qualified_name: typebase COLONCOLON name
  550. {
  551. struct type *type = $1;
  552. if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  553. && TYPE_CODE (type) != TYPE_CODE_UNION)
  554. error (_("`%s' is not defined as an aggregate type."),
  555. TYPE_NAME (type));
  556. write_exp_elt_opcode (OP_SCOPE);
  557. write_exp_elt_type (type);
  558. write_exp_string ($3);
  559. write_exp_elt_opcode (OP_SCOPE);
  560. }
  561. | typebase COLONCOLON '~' name
  562. {
  563. struct type *type = $1;
  564. struct stoken tmp_token;
  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. if (strcmp (type_name_no_tag (type), $4.ptr) != 0)
  570. error (_("invalid destructor `%s::~%s'"),
  571. type_name_no_tag (type), $4.ptr);
  572. tmp_token.ptr = (char*) alloca ($4.length + 2);
  573. tmp_token.length = $4.length + 1;
  574. tmp_token.ptr[0] = '~';
  575. memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
  576. tmp_token.ptr[tmp_token.length] = 0;
  577. write_exp_elt_opcode (OP_SCOPE);
  578. write_exp_elt_type (type);
  579. write_exp_string (tmp_token);
  580. write_exp_elt_opcode (OP_SCOPE);
  581. }
  582. ;
  583. variable: qualified_name
  584. | COLONCOLON name
  585. {
  586. char *name = copy_name ($2);
  587. struct symbol *sym;
  588. struct minimal_symbol *msymbol;
  589. sym =
  590. lookup_symbol (name, (const struct block *) NULL,
  591. VAR_DOMAIN, (int *) NULL);
  592. if (sym)
  593. {
  594. write_exp_elt_opcode (OP_VAR_VALUE);
  595. write_exp_elt_block (NULL);
  596. write_exp_elt_sym (sym);
  597. write_exp_elt_opcode (OP_VAR_VALUE);
  598. break;
  599. }
  600. msymbol = lookup_minimal_symbol (name, NULL, NULL);
  601. if (msymbol != NULL)
  602. write_exp_msymbol (msymbol);
  603. else if (!have_full_symbols ()
  604. && !have_partial_symbols ())
  605. error (_("No symbol table is loaded. "
  606. "Use the \"file\" command."));
  607. else
  608. error (_("No symbol \"%s\" in current context."),
  609. name);
  610. }
  611. ;
  612. variable: name_not_typename
  613. { struct symbol *sym = $1.sym;
  614. if (sym)
  615. {
  616. if (symbol_read_needs_frame (sym))
  617. {
  618. if (innermost_block == 0 ||
  619. contained_in (block_found,
  620. innermost_block))
  621. innermost_block = block_found;
  622. }
  623. write_exp_elt_opcode (OP_VAR_VALUE);
  624. /* We want to use the selected frame, not
  625. another more inner frame which happens to
  626. be in the same block. */
  627. write_exp_elt_block (NULL);
  628. write_exp_elt_sym (sym);
  629. write_exp_elt_opcode (OP_VAR_VALUE);
  630. }
  631. else if ($1.is_a_field_of_this)
  632. {
  633. /* C++/ObjC: it hangs off of `this'/'self'.
  634. Must not inadvertently convert from a
  635. method call to data ref. */
  636. if (innermost_block == 0 ||
  637. contained_in (block_found, innermost_block))
  638. innermost_block = block_found;
  639. write_exp_elt_opcode (OP_THIS);
  640. write_exp_elt_opcode (OP_THIS);
  641. write_exp_elt_opcode (STRUCTOP_PTR);
  642. write_exp_string ($1.stoken);
  643. write_exp_elt_opcode (STRUCTOP_PTR);
  644. }
  645. else
  646. {
  647. struct minimal_symbol *msymbol;
  648. char *arg = copy_name ($1.stoken);
  649. msymbol =
  650. lookup_minimal_symbol (arg, NULL, NULL);
  651. if (msymbol != NULL)
  652. write_exp_msymbol (msymbol);
  653. else if (!have_full_symbols () &&
  654. !have_partial_symbols ())
  655. error (_("No symbol table is loaded. "
  656. "Use the \"file\" command."));
  657. else
  658. error (_("No symbol \"%s\" in current context."),
  659. copy_name ($1.stoken));
  660. }
  661. }
  662. ;
  663. ptype : typebase
  664. /* "const" and "volatile" are curently ignored. A type
  665. qualifier before the type is currently handled in the
  666. typebase rule. The reason for recognizing these here
  667. (shift/reduce conflicts) might be obsolete now that some
  668. pointer to member rules have been deleted. */
  669. | typebase CONST_KEYWORD
  670. | typebase VOLATILE_KEYWORD
  671. | typebase abs_decl
  672. { $$ = follow_types ($1); }
  673. | typebase CONST_KEYWORD abs_decl
  674. { $$ = follow_types ($1); }
  675. | typebase VOLATILE_KEYWORD abs_decl
  676. { $$ = follow_types ($1); }
  677. ;
  678. abs_decl: '*'
  679. { push_type (tp_pointer); $$ = 0; }
  680. | '*' abs_decl
  681. { push_type (tp_pointer); $$ = $2; }
  682. | '&'
  683. { push_type (tp_reference); $$ = 0; }
  684. | '&' abs_decl
  685. { push_type (tp_reference); $$ = $2; }
  686. | direct_abs_decl
  687. ;
  688. direct_abs_decl: '(' abs_decl ')'
  689. { $$ = $2; }
  690. | direct_abs_decl array_mod
  691. {
  692. push_type_int ($2);
  693. push_type (tp_array);
  694. }
  695. | array_mod
  696. {
  697. push_type_int ($1);
  698. push_type (tp_array);
  699. $$ = 0;
  700. }
  701. | direct_abs_decl func_mod
  702. { push_type (tp_function); }
  703. | func_mod
  704. { push_type (tp_function); }
  705. ;
  706. array_mod: '[' ']'
  707. { $$ = -1; }
  708. | '[' INT ']'
  709. { $$ = $2.val; }
  710. ;
  711. func_mod: '(' ')'
  712. { $$ = 0; }
  713. | '(' nonempty_typelist ')'
  714. { free ($2); $$ = 0; }
  715. ;
  716. /* We used to try to recognize more pointer to member types here, but
  717. that didn't work (shift/reduce conflicts meant that these rules
  718. never got executed). The problem is that
  719. int (foo::bar::baz::bizzle)
  720. is a function type but
  721. int (foo::bar::baz::bizzle::*)
  722. is a pointer to member type. Stroustrup loses again! */
  723. type : ptype
  724. ;
  725. typebase /* Implements (approximately): (type-qualifier)* type-specifier. */
  726. : TYPENAME
  727. { $$ = $1.type; }
  728. | CLASSNAME
  729. {
  730. if ($1.type == NULL)
  731. error (_("No symbol \"%s\" in current context."),
  732. copy_name($1.stoken));
  733. else
  734. $$ = $1.type;
  735. }
  736. | INT_KEYWORD
  737. { $$ = parse_type->builtin_int; }
  738. | LONG
  739. { $$ = parse_type->builtin_long; }
  740. | SHORT
  741. { $$ = parse_type->builtin_short; }
  742. | LONG INT_KEYWORD
  743. { $$ = parse_type->builtin_long; }
  744. | UNSIGNED LONG INT_KEYWORD
  745. { $$ = parse_type->builtin_unsigned_long; }
  746. | LONG LONG
  747. { $$ = parse_type->builtin_long_long; }
  748. | LONG LONG INT_KEYWORD
  749. { $$ = parse_type->builtin_long_long; }
  750. | UNSIGNED LONG LONG
  751. { $$ = parse_type->builtin_unsigned_long_long; }
  752. | UNSIGNED LONG LONG INT_KEYWORD
  753. { $$ = parse_type->builtin_unsigned_long_long; }
  754. | SHORT INT_KEYWORD
  755. { $$ = parse_type->builtin_short; }
  756. | UNSIGNED SHORT INT_KEYWORD
  757. { $$ = parse_type->builtin_unsigned_short; }
  758. | DOUBLE_KEYWORD
  759. { $$ = parse_type->builtin_double; }
  760. | LONG DOUBLE_KEYWORD
  761. { $$ = parse_type->builtin_long_double; }
  762. | STRUCT name
  763. { $$ = lookup_struct (copy_name ($2),
  764. expression_context_block); }
  765. | CLASS name
  766. { $$ = lookup_struct (copy_name ($2),
  767. expression_context_block); }
  768. | UNION name
  769. { $$ = lookup_union (copy_name ($2),
  770. expression_context_block); }
  771. | ENUM name
  772. { $$ = lookup_enum (copy_name ($2),
  773. expression_context_block); }
  774. | UNSIGNED typename
  775. { $$ = lookup_unsigned_typename (parse_language,
  776. parse_gdbarch,
  777. TYPE_NAME($2.type)); }
  778. | UNSIGNED
  779. { $$ = parse_type->builtin_unsigned_int; }
  780. | SIGNED_KEYWORD typename
  781. { $$ = lookup_signed_typename (parse_language,
  782. parse_gdbarch,
  783. TYPE_NAME($2.type)); }
  784. | SIGNED_KEYWORD
  785. { $$ = parse_type->builtin_int; }
  786. | TEMPLATE name '<' type '>'
  787. { $$ = lookup_template_type(copy_name($2), $4,
  788. expression_context_block);
  789. }
  790. /* "const" and "volatile" are curently ignored. A type
  791. qualifier after the type is handled in the ptype rule. I
  792. think these could be too. */
  793. | CONST_KEYWORD typebase { $$ = $2; }
  794. | VOLATILE_KEYWORD typebase { $$ = $2; }
  795. ;
  796. typename: TYPENAME
  797. | INT_KEYWORD
  798. {
  799. $$.stoken.ptr = "int";
  800. $$.stoken.length = 3;
  801. $$.type = parse_type->builtin_int;
  802. }
  803. | LONG
  804. {
  805. $$.stoken.ptr = "long";
  806. $$.stoken.length = 4;
  807. $$.type = parse_type->builtin_long;
  808. }
  809. | SHORT
  810. {
  811. $$.stoken.ptr = "short";
  812. $$.stoken.length = 5;
  813. $$.type = parse_type->builtin_short;
  814. }
  815. ;
  816. nonempty_typelist
  817. : type
  818. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  819. $<ivec>$[0] = 1; /* Number of types in vector. */
  820. $$[1] = $1;
  821. }
  822. | nonempty_typelist ',' type
  823. { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
  824. $$ = (struct type **) realloc ((char *) $1, len);
  825. $$[$<ivec>$[0]] = $3;
  826. }
  827. ;
  828. name : NAME { $$ = $1.stoken; }
  829. | BLOCKNAME { $$ = $1.stoken; }
  830. | TYPENAME { $$ = $1.stoken; }
  831. | CLASSNAME { $$ = $1.stoken; }
  832. | NAME_OR_INT { $$ = $1.stoken; }
  833. ;
  834. name_not_typename : NAME
  835. | BLOCKNAME
  836. /* These would be useful if name_not_typename was useful, but it is
  837. just a fake for "variable", so these cause reduce/reduce conflicts
  838. because the parser can't tell whether NAME_OR_INT is a
  839. name_not_typename (=variable, =exp) or just an exp. If
  840. name_not_typename was ever used in an lvalue context where only a
  841. name could occur, this might be useful. */
  842. /* | NAME_OR_INT */
  843. ;
  844. %%
  845. /* Take care of parsing a number (anything that starts with a digit).
  846. Set yylval and return the token type; update lexptr. LEN is the
  847. number of characters in it. */
  848. /*** Needs some error checking for the float case. ***/
  849. static int
  850. parse_number (p, len, parsed_float, putithere)
  851. char *p;
  852. int len;
  853. int parsed_float;
  854. YYSTYPE *putithere;
  855. {
  856. /* FIXME: Shouldn't these be unsigned? We don't deal with negative
  857. values here, and we do kind of silly things like cast to
  858. unsigned. */
  859. LONGEST n = 0;
  860. LONGEST prevn = 0;
  861. unsigned LONGEST un;
  862. int i = 0;
  863. int c;
  864. int base = input_radix;
  865. int unsigned_p = 0;
  866. /* Number of "L" suffixes encountered. */
  867. int long_p = 0;
  868. /* We have found a "L" or "U" suffix. */
  869. int found_suffix = 0;
  870. unsigned LONGEST high_bit;
  871. struct type *signed_type;
  872. struct type *unsigned_type;
  873. if (parsed_float)
  874. {
  875. if (! parse_c_float (parse_gdbarch, p, len,
  876. &putithere->typed_val_float.dval,
  877. &putithere->typed_val_float.type))
  878. return ERROR;
  879. return FLOAT;
  880. }
  881. /* Handle base-switching prefixes 0x, 0t, 0d, and 0. */
  882. if (p[0] == '0')
  883. switch (p[1])
  884. {
  885. case 'x':
  886. case 'X':
  887. if (len >= 3)
  888. {
  889. p += 2;
  890. base = 16;
  891. len -= 2;
  892. }
  893. break;
  894. case 't':
  895. case 'T':
  896. case 'd':
  897. case 'D':
  898. if (len >= 3)
  899. {
  900. p += 2;
  901. base = 10;
  902. len -= 2;
  903. }
  904. break;
  905. default:
  906. base = 8;
  907. break;
  908. }
  909. while (len-- > 0)
  910. {
  911. c = *p++;
  912. if (c >= 'A' && c <= 'Z')
  913. c += 'a' - 'A';
  914. if (c != 'l' && c != 'u')
  915. n *= base;
  916. if (c >= '0' && c <= '9')
  917. {
  918. if (found_suffix)
  919. return ERROR;
  920. n += i = c - '0';
  921. }
  922. else
  923. {
  924. if (base > 10 && c >= 'a' && c <= 'f')
  925. {
  926. if (found_suffix)
  927. return ERROR;
  928. n += i = c - 'a' + 10;
  929. }
  930. else if (c == 'l')
  931. {
  932. ++long_p;
  933. found_suffix = 1;
  934. }
  935. else if (c == 'u')
  936. {
  937. unsigned_p = 1;
  938. found_suffix = 1;
  939. }
  940. else
  941. return ERROR; /* Char not a digit. */
  942. }
  943. if (i >= base)
  944. return ERROR; /* Invalid digit in this base. */
  945. /* Portably test for overflow (only works for nonzero values, so
  946. make a second check for zero). FIXME: Can't we just make n
  947. and prevn unsigned and avoid this? */
  948. if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
  949. unsigned_p = 1; /* Try something unsigned. */
  950. /* Portably test for unsigned overflow.
  951. FIXME: This check is wrong; for example it doesn't find
  952. overflow on 0x123456789 when LONGEST is 32 bits. */
  953. if (c != 'l' && c != 'u' && n != 0)
  954. {
  955. if ((unsigned_p && (unsigned LONGEST) prevn >= (unsigned LONGEST) n))
  956. error (_("Numeric constant too large."));
  957. }
  958. prevn = n;
  959. }
  960. /* An integer constant is an int, a long, or a long long. An L
  961. suffix forces it to be long; an LL suffix forces it to be long
  962. long. If not forced to a larger size, it gets the first type of
  963. the above that it fits in. To figure out whether it fits, we
  964. shift it right and see whether anything remains. Note that we
  965. can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
  966. operation, because many compilers will warn about such a shift
  967. (which always produces a zero result). Sometimes gdbarch_int_bit
  968. or gdbarch_long_int will be that big, sometimes not. To deal with
  969. the case where it is we just always shift the value more than
  970. once, with fewer bits each time. */
  971. un = (unsigned LONGEST)n >> 2;
  972. if (long_p == 0
  973. && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
  974. {
  975. high_bit
  976. = ((unsigned LONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
  977. /* A large decimal (not hex or octal) constant (between INT_MAX
  978. and UINT_MAX) is a long or unsigned long, according to ANSI,
  979. never an unsigned int, but this code treats it as unsigned
  980. int. This probably should be fixed. GCC gives a warning on
  981. such constants. */
  982. unsigned_type = parse_type->builtin_unsigned_int;
  983. signed_type = parse_type->builtin_int;
  984. }
  985. else if (long_p <= 1
  986. && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
  987. {
  988. high_bit
  989. = ((unsigned LONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
  990. unsigned_type = parse_type->builtin_unsigned_long;
  991. signed_type = parse_type->builtin_long;
  992. }
  993. else
  994. {
  995. high_bit = (((unsigned LONGEST)1)
  996. << (gdbarch_long_long_bit (parse_gdbarch) - 32 - 1)
  997. << 16
  998. << 16);
  999. if (high_bit == 0)
  1000. /* A long long does not fit in a LONGEST. */
  1001. high_bit =
  1002. (unsigned LONGEST)1 << (sizeof (LONGEST) * HOST_CHAR_BIT - 1);
  1003. unsigned_type = parse_type->builtin_unsigned_long_long;
  1004. signed_type = parse_type->builtin_long_long;
  1005. }
  1006. putithere->typed_val_int.val = n;
  1007. /* If the high bit of the worked out type is set then this number
  1008. has to be unsigned. */
  1009. if (unsigned_p || (n & high_bit))
  1010. {
  1011. putithere->typed_val_int.type = unsigned_type;
  1012. }
  1013. else
  1014. {
  1015. putithere->typed_val_int.type = signed_type;
  1016. }
  1017. return INT;
  1018. }
  1019. struct token
  1020. {
  1021. char *operator;
  1022. int token;
  1023. enum exp_opcode opcode;
  1024. };
  1025. static const struct token tokentab3[] =
  1026. {
  1027. {">>=", ASSIGN_MODIFY, BINOP_RSH},
  1028. {"<<=", ASSIGN_MODIFY, BINOP_LSH}
  1029. };
  1030. static const struct token tokentab2[] =
  1031. {
  1032. {"+=", ASSIGN_MODIFY, BINOP_ADD},
  1033. {"-=", ASSIGN_MODIFY, BINOP_SUB},
  1034. {"*=", ASSIGN_MODIFY, BINOP_MUL},
  1035. {"/=", ASSIGN_MODIFY, BINOP_DIV},
  1036. {"%=", ASSIGN_MODIFY, BINOP_REM},
  1037. {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR},
  1038. {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND},
  1039. {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR},
  1040. {"++", INCREMENT, BINOP_END},
  1041. {"--", DECREMENT, BINOP_END},
  1042. {"->", ARROW, BINOP_END},
  1043. {"&&", ANDAND, BINOP_END},
  1044. {"||", OROR, BINOP_END},
  1045. {"::", COLONCOLON, BINOP_END},
  1046. {"<<", LSH, BINOP_END},
  1047. {">>", RSH, BINOP_END},
  1048. {"==", EQUAL, BINOP_END},
  1049. {"!=", NOTEQUAL, BINOP_END},
  1050. {"<=", LEQ, BINOP_END},
  1051. {">=", GEQ, BINOP_END}
  1052. };
  1053. /* Read one token, getting characters through lexptr. */
  1054. static int
  1055. yylex (void)
  1056. {
  1057. int c, tokchr;
  1058. int namelen;
  1059. unsigned int i;
  1060. char *tokstart;
  1061. char *tokptr;
  1062. int tempbufindex;
  1063. static char *tempbuf;
  1064. static int tempbufsize;
  1065. retry:
  1066. tokstart = lexptr;
  1067. /* See if it is a special token of length 3. */
  1068. for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
  1069. if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
  1070. {
  1071. lexptr += 3;
  1072. yylval.opcode = tokentab3[i].opcode;
  1073. return tokentab3[i].token;
  1074. }
  1075. /* See if it is a special token of length 2. */
  1076. for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
  1077. if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
  1078. {
  1079. lexptr += 2;
  1080. yylval.opcode = tokentab2[i].opcode;
  1081. return tokentab2[i].token;
  1082. }
  1083. c = 0;
  1084. switch (tokchr = *tokstart)
  1085. {
  1086. case 0:
  1087. return 0;
  1088. case ' ':
  1089. case '\t':
  1090. case '\n':
  1091. lexptr++;
  1092. goto retry;
  1093. case '\'':
  1094. /* We either have a character constant ('0' or '\177' for
  1095. example) or we have a quoted symbol reference ('foo(int,int)'
  1096. in C++ for example). */
  1097. lexptr++;
  1098. c = *lexptr++;
  1099. if (c == '\\')
  1100. c = parse_escape (parse_gdbarch, &lexptr);
  1101. else if (c == '\'')
  1102. error (_("Empty character constant."));
  1103. yylval.typed_val_int.val = c;
  1104. yylval.typed_val_int.type = parse_type->builtin_char;
  1105. c = *lexptr++;
  1106. if (c != '\'')
  1107. {
  1108. namelen = skip_quoted (tokstart) - tokstart;
  1109. if (namelen > 2)
  1110. {
  1111. lexptr = tokstart + namelen;
  1112. if (lexptr[-1] != '\'')
  1113. error (_("Unmatched single quote."));
  1114. namelen -= 2;
  1115. tokstart++;
  1116. goto tryname;
  1117. }
  1118. error (_("Invalid character constant."));
  1119. }
  1120. return INT;
  1121. case '(':
  1122. paren_depth++;
  1123. lexptr++;
  1124. return '(';
  1125. case ')':
  1126. if (paren_depth == 0)
  1127. return 0;
  1128. paren_depth--;
  1129. lexptr++;
  1130. return ')';
  1131. case ',':
  1132. if (comma_terminates && paren_depth == 0)
  1133. return 0;
  1134. lexptr++;
  1135. return ',';
  1136. case '.':
  1137. /* Might be a floating point number. */
  1138. if (lexptr[1] < '0' || lexptr[1] > '9')
  1139. goto symbol; /* Nope, must be a symbol. */
  1140. /* FALL THRU into number case. */
  1141. case '0':
  1142. case '1':
  1143. case '2':
  1144. case '3':
  1145. case '4':
  1146. case '5':
  1147. case '6':
  1148. case '7':
  1149. case '8':
  1150. case '9':
  1151. {
  1152. /* It's a number. */
  1153. int got_dot = 0, got_e = 0, toktype = FLOAT;
  1154. /* Initialize toktype to anything other than ERROR. */
  1155. char *p = tokstart;
  1156. int hex = input_radix > 10;
  1157. int local_radix = input_radix;
  1158. if (tokchr == '0' && (p[1] == 'x' || p[1] == 'X'))
  1159. {
  1160. p += 2;
  1161. hex = 1;
  1162. local_radix = 16;
  1163. }
  1164. else if (tokchr == '0' && (p[1]=='t' || p[1]=='T'
  1165. || p[1]=='d' || p[1]=='D'))
  1166. {
  1167. p += 2;
  1168. hex = 0;
  1169. local_radix = 10;
  1170. }
  1171. for (;; ++p)
  1172. {
  1173. /* This test includes !hex because 'e' is a valid hex digit
  1174. and thus does not indicate a floating point number when
  1175. the radix is hex. */
  1176. if (!hex && (*p == 'e' || *p == 'E'))
  1177. if (got_e)
  1178. toktype = ERROR; /* Only one 'e' in a float. */
  1179. else
  1180. got_e = 1;
  1181. /* This test does not include !hex, because a '.' always
  1182. indicates a decimal floating point number regardless of
  1183. the radix. */
  1184. else if (*p == '.')
  1185. if (got_dot)
  1186. toktype = ERROR; /* Only one '.' in a float. */
  1187. else
  1188. got_dot = 1;
  1189. else if (got_e && (p[-1] == 'e' || p[-1] == 'E') &&
  1190. (*p == '-' || *p == '+'))
  1191. /* This is the sign of the exponent, not the end of the
  1192. number. */
  1193. continue;
  1194. /* Always take decimal digits; parse_number handles radix
  1195. error. */
  1196. else if (*p >= '0' && *p <= '9')
  1197. continue;
  1198. /* We will take letters only if hex is true, and only up
  1199. to what the input radix would permit. FSF was content
  1200. to rely on parse_number to validate; but it leaks. */
  1201. else if (*p >= 'a' && *p <= 'z')
  1202. {
  1203. if (!hex || *p >= ('a' + local_radix - 10))
  1204. toktype = ERROR;
  1205. }
  1206. else if (*p >= 'A' && *p <= 'Z')
  1207. {
  1208. if (!hex || *p >= ('A' + local_radix - 10))
  1209. toktype = ERROR;
  1210. }
  1211. else break;
  1212. }
  1213. if (toktype != ERROR)
  1214. toktype = parse_number (tokstart, p - tokstart,
  1215. got_dot | got_e, &yylval);
  1216. if (toktype == ERROR)
  1217. {
  1218. char *err_copy = (char *) alloca (p - tokstart + 1);
  1219. memcpy (err_copy, tokstart, p - tokstart);
  1220. err_copy[p - tokstart] = 0;
  1221. error (_("Invalid number \"%s\"."), err_copy);
  1222. }
  1223. lexptr = p;
  1224. return toktype;
  1225. }
  1226. case '+':
  1227. case '-':
  1228. case '*':
  1229. case '/':
  1230. case '%':
  1231. case '|':
  1232. case '&':
  1233. case '^':
  1234. case '~':
  1235. case '!':
  1236. #if 0
  1237. case '@': /* Moved out below. */
  1238. #endif
  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 (msg)
  1575. char *msg;
  1576. {
  1577. if (*lexptr == '\0')
  1578. error(_("A %s near end of expression."), (msg ? msg : "error"));
  1579. else
  1580. error (_("A %s in expression, near `%s'."), (msg ? msg : "error"),
  1581. lexptr);
  1582. }