1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2003, 2004, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* Parse a C expression from text in a string,
24 and return the result as a struct expression pointer.
25 That structure contains arithmetic operations in reverse polish,
26 with constants represented by operations that are followed by special data.
27 See expression.h for the details of the format.
28 What is important here is that it can be built up sequentially
29 during the process of parsing; the lower levels of the tree always
30 come first in the result.
32 Note that malloc's and realloc's in this file are transformed to
33 xmalloc and xrealloc respectively by the same sed command in the
34 makefile that remaps any other malloc/realloc inserted by the parser
35 generator. Doing this with #defines and trying to control the interaction
36 with include files (<malloc.h> and <stdlib.h> for example) just became
37 too messy, particularly when such includes can be inserted at random
38 times by the parser generator. */
43 #include "gdb_string.h"
45 #include "expression.h"
47 #include "parser-defs.h"
50 #include "bfd.h" /* Required by objfiles.h. */
51 #include "symfile.h" /* Required by objfiles.h. */
52 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
55 #include "cp-support.h"
58 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
59 as well as gratuitiously global symbol names, so we can have multiple
60 yacc generated parsers in gdb. Note that these are only the variables
61 produced by yacc. If other parser generators (bison, byacc, etc) produce
62 additional global names that conflict at link time, then those parser
63 generators need to be fixed instead of adding those names to this list. */
65 #define yymaxdepth c_maxdepth
66 #define yyparse c_parse
68 #define yyerror c_error
71 #define yydebug c_debug
80 #define yyerrflag c_errflag
81 #define yynerrs c_nerrs
86 #define yystate c_state
92 #define yyreds c_reds /* With YYDEBUG defined */
93 #define yytoks c_toks /* With YYDEBUG defined */
94 #define yyname c_name /* With YYDEBUG defined */
95 #define yyrule c_rule /* With YYDEBUG defined */
98 #define yydefred c_yydefred
99 #define yydgoto c_yydgoto
100 #define yysindex c_yysindex
101 #define yyrindex c_yyrindex
102 #define yygindex c_yygindex
103 #define yytable c_yytable
104 #define yycheck c_yycheck
107 #define YYDEBUG 1 /* Default to yydebug support */
110 #define YYFPRINTF parser_fprintf
114 static int yylex (void);
116 void yyerror (char *);
120 /* Although the yacc "value" of an expression is not used,
121 since the result is stored in the structure being created,
122 other node types do have values. */
138 } typed_val_decfloat
;
143 struct symtoken ssym
;
146 enum exp_opcode opcode
;
147 struct internalvar
*ivar
;
154 /* YYSTYPE gets defined by %union */
155 static int parse_number
(char *, int, int, YYSTYPE *);
158 %type
<voidval
> exp exp1 type_exp start variable qualified_name lcurly
160 %type
<tval
> type typebase qualified_type
161 %type
<tvec
> nonempty_typelist
162 /* %type <bval> block */
164 /* Fancy type parsing. */
165 %type
<voidval
> func_mod direct_abs_decl abs_decl
167 %type
<lval
> array_mod
169 %token
<typed_val_int
> INT
170 %token
<typed_val_float
> FLOAT
171 %token
<typed_val_decfloat
> DECFLOAT
173 /* Both NAME and TYPENAME tokens represent symbols in the input,
174 and both convey their data as strings.
175 But a TYPENAME is a string that happens to be defined as a typedef
176 or builtin type name (such as int or char)
177 and a NAME is any other symbol.
178 Contexts where this distinction is not important can use the
179 nonterminal "name", which matches either NAME or TYPENAME. */
182 %token
<ssym
> NAME
/* BLOCKNAME defined below to give it higher precedence. */
183 %token
<tsym
> TYPENAME
185 %type
<ssym
> name_not_typename
186 %type
<tsym
> typename
188 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
189 but which would parse as a valid number in the current input radix.
190 E.g. "c" when input_radix==16. Depending on the parse, it will be
191 turned into a name or into a number. */
193 %token
<ssym
> NAME_OR_INT
195 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
199 /* Special type cases, put in to allow the parser to distinguish different
201 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
203 %token
<voidval
> VARIABLE
205 %token
<opcode
> ASSIGN_MODIFY
214 %right
'=' ASSIGN_MODIFY
222 %left
'<' '>' LEQ GEQ
227 %right UNARY INCREMENT DECREMENT
228 %right ARROW
'.' '[' '('
229 %token
<ssym
> BLOCKNAME
230 %token
<bval
> FILENAME
242 { write_exp_elt_opcode
(OP_TYPE
);
243 write_exp_elt_type
($1);
244 write_exp_elt_opcode
(OP_TYPE
);}
247 /* Expressions, including the comma operator. */
250 { write_exp_elt_opcode
(BINOP_COMMA
); }
253 /* Expressions, not including the comma operator. */
254 exp
: '*' exp %prec UNARY
255 { write_exp_elt_opcode
(UNOP_IND
); }
258 exp
: '&' exp %prec UNARY
259 { write_exp_elt_opcode
(UNOP_ADDR
); }
262 exp
: '-' exp %prec UNARY
263 { write_exp_elt_opcode
(UNOP_NEG
); }
266 exp
: '+' exp %prec UNARY
267 { write_exp_elt_opcode
(UNOP_PLUS
); }
270 exp
: '!' exp %prec UNARY
271 { write_exp_elt_opcode
(UNOP_LOGICAL_NOT
); }
274 exp
: '~' exp %prec UNARY
275 { write_exp_elt_opcode
(UNOP_COMPLEMENT
); }
278 exp
: INCREMENT exp %prec UNARY
279 { write_exp_elt_opcode
(UNOP_PREINCREMENT
); }
282 exp
: DECREMENT exp %prec UNARY
283 { write_exp_elt_opcode
(UNOP_PREDECREMENT
); }
286 exp
: exp INCREMENT %prec UNARY
287 { write_exp_elt_opcode
(UNOP_POSTINCREMENT
); }
290 exp
: exp DECREMENT %prec UNARY
291 { write_exp_elt_opcode
(UNOP_POSTDECREMENT
); }
294 exp
: SIZEOF exp %prec UNARY
295 { write_exp_elt_opcode
(UNOP_SIZEOF
); }
299 { write_exp_elt_opcode
(STRUCTOP_PTR
);
300 write_exp_string
($3);
301 write_exp_elt_opcode
(STRUCTOP_PTR
); }
304 exp
: exp ARROW qualified_name
305 { /* exp->type::name becomes exp->*(&type::name) */
306 /* Note: this doesn't work if name is a
307 static member! FIXME */
308 write_exp_elt_opcode
(UNOP_ADDR
);
309 write_exp_elt_opcode
(STRUCTOP_MPTR
); }
312 exp
: exp ARROW
'*' exp
313 { write_exp_elt_opcode
(STRUCTOP_MPTR
); }
317 { write_exp_elt_opcode
(STRUCTOP_STRUCT
);
318 write_exp_string
($3);
319 write_exp_elt_opcode
(STRUCTOP_STRUCT
); }
322 exp
: exp
'.' qualified_name
323 { /* exp.type::name becomes exp.*(&type::name) */
324 /* Note: this doesn't work if name is a
325 static member! FIXME */
326 write_exp_elt_opcode
(UNOP_ADDR
);
327 write_exp_elt_opcode
(STRUCTOP_MEMBER
); }
330 exp
: exp
'.' '*' exp
331 { write_exp_elt_opcode
(STRUCTOP_MEMBER
); }
334 exp
: exp
'[' exp1
']'
335 { write_exp_elt_opcode
(BINOP_SUBSCRIPT
); }
339 /* This is to save the value of arglist_len
340 being accumulated by an outer function call. */
341 { start_arglist
(); }
342 arglist
')' %prec ARROW
343 { write_exp_elt_opcode
(OP_FUNCALL
);
344 write_exp_elt_longcst
((LONGEST
) end_arglist
());
345 write_exp_elt_opcode
(OP_FUNCALL
); }
349 { start_arglist
(); }
359 arglist
: arglist
',' exp %prec ABOVE_COMMA
364 { $$
= end_arglist
() - 1; }
366 exp
: lcurly arglist rcurly %prec ARROW
367 { write_exp_elt_opcode
(OP_ARRAY
);
368 write_exp_elt_longcst
((LONGEST
) 0);
369 write_exp_elt_longcst
((LONGEST
) $3);
370 write_exp_elt_opcode
(OP_ARRAY
); }
373 exp
: lcurly type rcurly exp %prec UNARY
374 { write_exp_elt_opcode
(UNOP_MEMVAL
);
375 write_exp_elt_type
($2);
376 write_exp_elt_opcode
(UNOP_MEMVAL
); }
379 exp
: '(' type
')' exp %prec UNARY
380 { write_exp_elt_opcode
(UNOP_CAST
);
381 write_exp_elt_type
($2);
382 write_exp_elt_opcode
(UNOP_CAST
); }
389 /* Binary operators in order of decreasing precedence. */
392 { write_exp_elt_opcode
(BINOP_REPEAT
); }
396 { write_exp_elt_opcode
(BINOP_MUL
); }
400 { write_exp_elt_opcode
(BINOP_DIV
); }
404 { write_exp_elt_opcode
(BINOP_REM
); }
408 { write_exp_elt_opcode
(BINOP_ADD
); }
412 { write_exp_elt_opcode
(BINOP_SUB
); }
416 { write_exp_elt_opcode
(BINOP_LSH
); }
420 { write_exp_elt_opcode
(BINOP_RSH
); }
424 { write_exp_elt_opcode
(BINOP_EQUAL
); }
427 exp
: exp NOTEQUAL exp
428 { write_exp_elt_opcode
(BINOP_NOTEQUAL
); }
432 { write_exp_elt_opcode
(BINOP_LEQ
); }
436 { write_exp_elt_opcode
(BINOP_GEQ
); }
440 { write_exp_elt_opcode
(BINOP_LESS
); }
444 { write_exp_elt_opcode
(BINOP_GTR
); }
448 { write_exp_elt_opcode
(BINOP_BITWISE_AND
); }
452 { write_exp_elt_opcode
(BINOP_BITWISE_XOR
); }
456 { write_exp_elt_opcode
(BINOP_BITWISE_IOR
); }
460 { write_exp_elt_opcode
(BINOP_LOGICAL_AND
); }
464 { write_exp_elt_opcode
(BINOP_LOGICAL_OR
); }
467 exp
: exp
'?' exp
':' exp %prec
'?'
468 { write_exp_elt_opcode
(TERNOP_COND
); }
472 { write_exp_elt_opcode
(BINOP_ASSIGN
); }
475 exp
: exp ASSIGN_MODIFY exp
476 { write_exp_elt_opcode
(BINOP_ASSIGN_MODIFY
);
477 write_exp_elt_opcode
($2);
478 write_exp_elt_opcode
(BINOP_ASSIGN_MODIFY
); }
482 { write_exp_elt_opcode
(OP_LONG
);
483 write_exp_elt_type
($1.type
);
484 write_exp_elt_longcst
((LONGEST
)($1.val
));
485 write_exp_elt_opcode
(OP_LONG
); }
490 parse_number
($1.stoken.ptr
, $1.stoken.length
, 0, &val
);
491 write_exp_elt_opcode
(OP_LONG
);
492 write_exp_elt_type
(val.typed_val_int.type
);
493 write_exp_elt_longcst
((LONGEST
)val.typed_val_int.val
);
494 write_exp_elt_opcode
(OP_LONG
);
500 { write_exp_elt_opcode
(OP_DOUBLE
);
501 write_exp_elt_type
($1.type
);
502 write_exp_elt_dblcst
($1.dval
);
503 write_exp_elt_opcode
(OP_DOUBLE
); }
507 { write_exp_elt_opcode
(OP_DECFLOAT
);
508 write_exp_elt_type
($1.type
);
509 write_exp_elt_decfloatcst
($1.val
);
510 write_exp_elt_opcode
(OP_DECFLOAT
); }
517 /* Already written by write_dollar_variable. */
520 exp
: SIZEOF
'(' type
')' %prec UNARY
521 { write_exp_elt_opcode
(OP_LONG
);
522 write_exp_elt_type
(builtin_type
(current_gdbarch
)->builtin_int
);
524 write_exp_elt_longcst
((LONGEST
) TYPE_LENGTH
($3));
525 write_exp_elt_opcode
(OP_LONG
); }
529 { /* C strings are converted into array constants with
530 an explicit null byte added at the end. Thus
531 the array upper bound is the string length.
532 There is no such thing in C as a completely empty
534 char *sp
= $1.ptr
; int count
= $1.length
;
537 write_exp_elt_opcode
(OP_LONG
);
538 write_exp_elt_type
(builtin_type
(current_gdbarch
)->builtin_char
);
539 write_exp_elt_longcst
((LONGEST
)(*sp
++));
540 write_exp_elt_opcode
(OP_LONG
);
542 write_exp_elt_opcode
(OP_LONG
);
543 write_exp_elt_type
(builtin_type
(current_gdbarch
)->builtin_char
);
544 write_exp_elt_longcst
((LONGEST
)'\0');
545 write_exp_elt_opcode
(OP_LONG
);
546 write_exp_elt_opcode
(OP_ARRAY
);
547 write_exp_elt_longcst
((LONGEST
) 0);
548 write_exp_elt_longcst
((LONGEST
) ($1.length
));
549 write_exp_elt_opcode
(OP_ARRAY
); }
554 { write_exp_elt_opcode
(OP_LONG
);
555 write_exp_elt_type
(builtin_type
(current_gdbarch
)->builtin_bool
);
556 write_exp_elt_longcst
((LONGEST
) 1);
557 write_exp_elt_opcode
(OP_LONG
); }
561 { write_exp_elt_opcode
(OP_LONG
);
562 write_exp_elt_type
(builtin_type
(current_gdbarch
)->builtin_bool
);
563 write_exp_elt_longcst
((LONGEST
) 0);
564 write_exp_elt_opcode
(OP_LONG
); }
572 $$
= SYMBOL_BLOCK_VALUE
($1.sym
);
574 error ("No file or function \"%s\".",
575 copy_name
($1.stoken
));
583 block
: block COLONCOLON name
585 = lookup_symbol
(copy_name
($3), $1,
586 VAR_DOMAIN
, (int *) NULL
,
587 (struct symtab
**) NULL
);
588 if
(!tem || SYMBOL_CLASS
(tem
) != LOC_BLOCK
)
589 error ("No function \"%s\" in specified context.",
591 $$
= SYMBOL_BLOCK_VALUE
(tem
); }
594 variable: block COLONCOLON name
595 { struct symbol
*sym
;
596 sym
= lookup_symbol
(copy_name
($3), $1,
597 VAR_DOMAIN
, (int *) NULL
,
598 (struct symtab
**) NULL
);
600 error ("No symbol \"%s\" in specified context.",
603 write_exp_elt_opcode
(OP_VAR_VALUE
);
604 /* block_found is set by lookup_symbol. */
605 write_exp_elt_block
(block_found
);
606 write_exp_elt_sym
(sym
);
607 write_exp_elt_opcode
(OP_VAR_VALUE
); }
610 qualified_name: typebase COLONCOLON name
612 struct type
*type
= $1;
613 if
(TYPE_CODE
(type
) != TYPE_CODE_STRUCT
614 && TYPE_CODE
(type
) != TYPE_CODE_UNION
615 && TYPE_CODE
(type
) != TYPE_CODE_NAMESPACE
)
616 error ("`%s' is not defined as an aggregate type.",
619 write_exp_elt_opcode
(OP_SCOPE
);
620 write_exp_elt_type
(type
);
621 write_exp_string
($3);
622 write_exp_elt_opcode
(OP_SCOPE
);
624 | typebase COLONCOLON
'~' name
626 struct type
*type
= $1;
627 struct stoken tmp_token
;
628 if
(TYPE_CODE
(type
) != TYPE_CODE_STRUCT
629 && TYPE_CODE
(type
) != TYPE_CODE_UNION
630 && TYPE_CODE
(type
) != TYPE_CODE_NAMESPACE
)
631 error ("`%s' is not defined as an aggregate type.",
634 tmp_token.ptr
= (char*) alloca
($4.length
+ 2);
635 tmp_token.length
= $4.length
+ 1;
636 tmp_token.ptr
[0] = '~';
637 memcpy
(tmp_token.ptr
+1, $4.ptr
, $4.length
);
638 tmp_token.ptr
[tmp_token.length
] = 0;
640 /* Check for valid destructor name. */
641 destructor_name_p
(tmp_token.ptr
, type
);
642 write_exp_elt_opcode
(OP_SCOPE
);
643 write_exp_elt_type
(type
);
644 write_exp_string
(tmp_token
);
645 write_exp_elt_opcode
(OP_SCOPE
);
649 variable: qualified_name
652 char *name
= copy_name
($2);
654 struct minimal_symbol
*msymbol
;
657 lookup_symbol
(name
, (const struct block
*) NULL
,
658 VAR_DOMAIN
, (int *) NULL
,
659 (struct symtab
**) NULL
);
662 write_exp_elt_opcode
(OP_VAR_VALUE
);
663 write_exp_elt_block
(NULL
);
664 write_exp_elt_sym
(sym
);
665 write_exp_elt_opcode
(OP_VAR_VALUE
);
669 msymbol
= lookup_minimal_symbol
(name
, NULL
, NULL
);
672 write_exp_msymbol
(msymbol
,
673 lookup_function_type
(builtin_type
(current_gdbarch
)->builtin_int
),
674 builtin_type
(current_gdbarch
)->builtin_int
);
677 if
(!have_full_symbols
() && !have_partial_symbols
())
678 error ("No symbol table is loaded. Use the \"file\" command.");
680 error ("No symbol \"%s\" in current context.", name
);
684 variable: name_not_typename
685 { struct symbol
*sym
= $1.sym
;
689 if
(symbol_read_needs_frame
(sym
))
691 if
(innermost_block
== 0 ||
692 contained_in
(block_found
,
694 innermost_block
= block_found
;
697 write_exp_elt_opcode
(OP_VAR_VALUE
);
698 /* We want to use the selected frame, not
699 another more inner frame which happens to
700 be in the same block. */
701 write_exp_elt_block
(NULL
);
702 write_exp_elt_sym
(sym
);
703 write_exp_elt_opcode
(OP_VAR_VALUE
);
705 else if
($1.is_a_field_of_this
)
707 /* C++: it hangs off of `this'. Must
708 not inadvertently convert from a method call
710 if
(innermost_block
== 0 ||
711 contained_in
(block_found
, innermost_block
))
712 innermost_block
= block_found
;
713 write_exp_elt_opcode
(OP_THIS
);
714 write_exp_elt_opcode
(OP_THIS
);
715 write_exp_elt_opcode
(STRUCTOP_PTR
);
716 write_exp_string
($1.stoken
);
717 write_exp_elt_opcode
(STRUCTOP_PTR
);
721 struct minimal_symbol
*msymbol
;
722 char *arg
= copy_name
($1.stoken
);
725 lookup_minimal_symbol
(arg
, NULL
, NULL
);
728 write_exp_msymbol
(msymbol
,
729 lookup_function_type
(builtin_type
(current_gdbarch
)->builtin_int
),
730 builtin_type
(current_gdbarch
)->builtin_int
);
732 else if
(!have_full_symbols
() && !have_partial_symbols
())
733 error ("No symbol table is loaded. Use the \"file\" command.");
735 error ("No symbol \"%s\" in current context.",
736 copy_name
($1.stoken
));
741 space_identifier
: '@' NAME
742 { push_type_address_space
(copy_name
($2.stoken
));
743 push_type
(tp_space_identifier
);
747 const_or_volatile: const_or_volatile_noopt
751 cv_with_space_id
: const_or_volatile space_identifier const_or_volatile
754 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
755 | const_or_volatile_noopt
758 const_or_volatile_or_space_identifier:
759 const_or_volatile_or_space_identifier_noopt
764 { push_type
(tp_pointer
); $$
= 0; }
766 { push_type
(tp_pointer
); $$
= $2; }
768 { push_type
(tp_reference
); $$
= 0; }
770 { push_type
(tp_reference
); $$
= $2; }
774 direct_abs_decl: '(' abs_decl
')'
776 | direct_abs_decl array_mod
779 push_type
(tp_array
);
784 push_type
(tp_array
);
788 | direct_abs_decl func_mod
789 { push_type
(tp_function
); }
791 { push_type
(tp_function
); }
802 |
'(' nonempty_typelist
')'
803 { free
($2); $$
= 0; }
806 /* We used to try to recognize pointer to member types here, but
807 that didn't work (shift/reduce conflicts meant that these rules never
808 got executed). The problem is that
809 int (foo::bar::baz::bizzle)
810 is a function type but
811 int (foo::bar::baz::bizzle::*)
812 is a pointer to member type. Stroustrup loses again! */
817 typebase
/* Implements (approximately): (type-qualifier)* type-specifier */
821 { $$
= builtin_type
(current_gdbarch
)->builtin_int
; }
823 { $$
= builtin_type
(current_gdbarch
)->builtin_long
; }
825 { $$
= builtin_type
(current_gdbarch
)->builtin_short
; }
827 { $$
= builtin_type
(current_gdbarch
)->builtin_long
; }
828 | LONG SIGNED_KEYWORD INT_KEYWORD
829 { $$
= builtin_type
(current_gdbarch
)->builtin_long
; }
830 | LONG SIGNED_KEYWORD
831 { $$
= builtin_type
(current_gdbarch
)->builtin_long
; }
832 | SIGNED_KEYWORD LONG INT_KEYWORD
833 { $$
= builtin_type
(current_gdbarch
)->builtin_long
; }
834 | UNSIGNED LONG INT_KEYWORD
835 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_long
; }
836 | LONG UNSIGNED INT_KEYWORD
837 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_long
; }
839 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_long
; }
841 { $$
= builtin_type
(current_gdbarch
)->builtin_long_long
; }
842 | LONG LONG INT_KEYWORD
843 { $$
= builtin_type
(current_gdbarch
)->builtin_long_long
; }
844 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
845 { $$
= builtin_type
(current_gdbarch
)->builtin_long_long
; }
846 | LONG LONG SIGNED_KEYWORD
847 { $$
= builtin_type
(current_gdbarch
)->builtin_long_long
; }
848 | SIGNED_KEYWORD LONG LONG
849 { $$
= builtin_type
(current_gdbarch
)->builtin_long_long
; }
850 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
851 { $$
= builtin_type
(current_gdbarch
)->builtin_long_long
; }
853 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_long_long
; }
854 | UNSIGNED LONG LONG INT_KEYWORD
855 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_long_long
; }
857 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_long_long
; }
858 | LONG LONG UNSIGNED INT_KEYWORD
859 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_long_long
; }
861 { $$
= builtin_type
(current_gdbarch
)->builtin_short
; }
862 | SHORT SIGNED_KEYWORD INT_KEYWORD
863 { $$
= builtin_type
(current_gdbarch
)->builtin_short
; }
864 | SHORT SIGNED_KEYWORD
865 { $$
= builtin_type
(current_gdbarch
)->builtin_short
; }
866 | UNSIGNED SHORT INT_KEYWORD
867 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_short
; }
869 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_short
; }
870 | SHORT UNSIGNED INT_KEYWORD
871 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_short
; }
873 { $$
= builtin_type
(current_gdbarch
)->builtin_double
; }
874 | LONG DOUBLE_KEYWORD
875 { $$
= builtin_type
(current_gdbarch
)->builtin_long_double
; }
877 { $$
= lookup_struct
(copy_name
($2),
878 expression_context_block
); }
880 { $$
= lookup_struct
(copy_name
($2),
881 expression_context_block
); }
883 { $$
= lookup_union
(copy_name
($2),
884 expression_context_block
); }
886 { $$
= lookup_enum
(copy_name
($2),
887 expression_context_block
); }
889 { $$
= lookup_unsigned_typename
(TYPE_NAME
($2.type
)); }
891 { $$
= builtin_type
(current_gdbarch
)->builtin_unsigned_int
; }
892 | SIGNED_KEYWORD typename
893 { $$
= lookup_signed_typename
(TYPE_NAME
($2.type
)); }
895 { $$
= builtin_type
(current_gdbarch
)->builtin_int
; }
896 /* It appears that this rule for templates is never
897 reduced; template recognition happens by lookahead
898 in the token processing code in yylex. */
899 | TEMPLATE name
'<' type
'>'
900 { $$
= lookup_template_type
(copy_name
($2), $4,
901 expression_context_block
);
903 | const_or_volatile_or_space_identifier_noopt typebase
904 { $$
= follow_types
($2); }
905 | typebase const_or_volatile_or_space_identifier_noopt
906 { $$
= follow_types
($1); }
910 /* FIXME: carlton/2003-09-25: This next bit leads to lots of
911 reduce-reduce conflicts, because the parser doesn't know whether or
912 not to use qualified_name or qualified_type: the rules are
913 identical. If the parser is parsing 'A::B::x', then, when it sees
914 the second '::', it knows that the expression to the left of it has
915 to be a type, so it uses qualified_type. But if it is parsing just
916 'A::B', then it doesn't have any way of knowing which rule to use,
917 so there's a reduce-reduce conflict; it picks qualified_name, since
918 that occurs earlier in this file than qualified_type.
920 There's no good way to fix this with the grammar as it stands; as
921 far as I can tell, some of the problems arise from ambiguities that
922 GDB introduces ('start' can be either an expression or a type), but
923 some of it is inherent to the nature of C++ (you want to treat the
924 input "(FOO)" fairly differently depending on whether FOO is an
925 expression or a type, and if FOO is a complex expression, this can
926 be hard to determine at the right time). Fortunately, it works
927 pretty well in most cases. For example, if you do 'ptype A::B',
928 where A::B is a nested type, then the parser will mistakenly
929 misidentify it as an expression; but evaluate_subexp will get
930 called with 'noside' set to EVAL_AVOID_SIDE_EFFECTS, and everything
931 will work out anyways. But there are situations where the parser
932 will get confused: the most common one that I've run into is when
937 where the parser doesn't realize that A::B has to be a type until
938 it hits the first right paren, at which point it's too late. (The
939 workaround is to type "print *(('A::B' *) x)" instead.) (And
940 another solution is to fix our symbol-handling code so that the
941 user never wants to type something like that in the first place,
942 because we get all the types right without the user's help!)
944 Perhaps we could fix this by making the lexer smarter. Some of
945 this functionality used to be in the lexer, but in a way that
946 worked even less well than the current solution: that attempt
947 involved having the parser sometimes handle '::' and having the
948 lexer sometimes handle it, and without a clear division of
949 responsibility, it quickly degenerated into a big mess. Probably
950 the eventual correct solution will give more of a role to the lexer
951 (ideally via code that is shared between the lexer and
952 decode_line_1), but I'm not holding my breath waiting for somebody
953 to get around to cleaning this up... */
955 qualified_type: typebase COLONCOLON name
957 struct type
*type
= $1;
958 struct type
*new_type
;
959 char *ncopy
= alloca
($3.length
+ 1);
961 memcpy
(ncopy
, $3.ptr
, $3.length
);
962 ncopy
[$3.length
] = '\0';
964 if
(TYPE_CODE
(type
) != TYPE_CODE_STRUCT
965 && TYPE_CODE
(type
) != TYPE_CODE_UNION
966 && TYPE_CODE
(type
) != TYPE_CODE_NAMESPACE
)
967 error ("`%s' is not defined as an aggregate type.",
970 new_type
= cp_lookup_nested_type
(type
, ncopy
,
971 expression_context_block
);
972 if
(new_type
== NULL
)
973 error ("No type \"%s\" within class or namespace \"%s\".",
974 ncopy
, TYPE_NAME
(type
));
983 $$.stoken.ptr
= "int";
984 $$.stoken.length
= 3;
985 $$.type
= builtin_type
(current_gdbarch
)->builtin_int
;
989 $$.stoken.ptr
= "long";
990 $$.stoken.length
= 4;
991 $$.type
= builtin_type
(current_gdbarch
)->builtin_long
;
995 $$.stoken.ptr
= "short";
996 $$.stoken.length
= 5;
997 $$.type
= builtin_type
(current_gdbarch
)->builtin_short
;
1003 { $$
= (struct type
**) malloc
(sizeof
(struct type
*) * 2);
1004 $
<ivec
>$
[0] = 1; /* Number of types in vector */
1007 | nonempty_typelist
',' type
1008 { int len
= sizeof
(struct type
*) * (++($
<ivec
>1[0]) + 1);
1009 $$
= (struct type
**) realloc
((char *) $1, len
);
1010 $$
[$
<ivec
>$
[0]] = $3;
1015 | ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
1016 { $$
= follow_types
($1); }
1019 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1020 | VOLATILE_KEYWORD CONST_KEYWORD
1023 const_or_volatile_noopt: const_and_volatile
1024 { push_type
(tp_const
);
1025 push_type
(tp_volatile
);
1028 { push_type
(tp_const
); }
1030 { push_type
(tp_volatile
); }
1033 name
: NAME
{ $$
= $1.stoken
; }
1034 | BLOCKNAME
{ $$
= $1.stoken
; }
1035 | TYPENAME
{ $$
= $1.stoken
; }
1036 | NAME_OR_INT
{ $$
= $1.stoken
; }
1039 name_not_typename
: NAME
1041 /* These would be useful if name_not_typename was useful, but it is just
1042 a fake for "variable", so these cause reduce/reduce conflicts because
1043 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1044 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1045 context where only a name could occur, this might be useful.
1052 /* Take care of parsing a number (anything that starts with a digit).
1053 Set yylval and return the token type; update lexptr.
1054 LEN is the number of characters in it. */
1056 /*** Needs some error checking for the float case ***/
1059 parse_number
(p
, len
, parsed_float
, putithere
)
1065 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1066 here, and we do kind of silly things like cast to unsigned. */
1073 int base
= input_radix
;
1076 /* Number of "L" suffixes encountered. */
1079 /* We have found a "L" or "U" suffix. */
1080 int found_suffix
= 0;
1083 struct type
*signed_type
;
1084 struct type
*unsigned_type
;
1088 /* It's a float since it contains a point or an exponent. */
1089 char *s
= malloc
(len
);
1090 int num
= 0; /* number of tokens scanned by scanf */
1091 char saved_char
= p
[len
];
1093 p
[len
] = 0; /* null-terminate the token */
1095 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1096 point. Return DECFLOAT. */
1098 if
(p
[len
- 2] == 'd' && p
[len
- 1] == 'f')
1101 putithere
->typed_val_decfloat.type
1102 = builtin_type
(current_gdbarch
)->builtin_decfloat
;
1103 decimal_from_string
(putithere
->typed_val_decfloat.val
, 4, p
);
1104 p
[len
] = saved_char
;
1108 if
(p
[len
- 2] == 'd' && p
[len
- 1] == 'd')
1111 putithere
->typed_val_decfloat.type
1112 = builtin_type
(current_gdbarch
)->builtin_decdouble
;
1113 decimal_from_string
(putithere
->typed_val_decfloat.val
, 8, p
);
1114 p
[len
] = saved_char
;
1118 if
(p
[len
- 2] == 'd' && p
[len
- 1] == 'l')
1121 putithere
->typed_val_decfloat.type
1122 = builtin_type
(current_gdbarch
)->builtin_declong
;
1123 decimal_from_string
(putithere
->typed_val_decfloat.val
, 16, p
);
1124 p
[len
] = saved_char
;
1128 num
= sscanf
(p
, "%" DOUBLEST_SCAN_FORMAT
"%s",
1129 &putithere
->typed_val_float.dval
, s
);
1130 p
[len
] = saved_char
; /* restore the input stream */
1133 putithere
->typed_val_float.type
=
1134 builtin_type
(current_gdbarch
)->builtin_double
;
1138 /* See if it has any float suffix: 'f' for float, 'l' for long
1140 if
(!strcasecmp
(s
, "f"))
1141 putithere
->typed_val_float.type
=
1142 builtin_type
(current_gdbarch
)->builtin_float
;
1143 else if
(!strcasecmp
(s
, "l"))
1144 putithere
->typed_val_float.type
=
1145 builtin_type
(current_gdbarch
)->builtin_long_double
;
1157 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1191 if
(c
>= 'A' && c
<= 'Z')
1193 if
(c
!= 'l' && c
!= 'u')
1195 if
(c
>= '0' && c
<= '9')
1203 if
(base
> 10 && c
>= 'a' && c
<= 'f')
1207 n
+= i
= c
- 'a' + 10;
1220 return ERROR
; /* Char not a digit */
1223 return ERROR
; /* Invalid digit in this base */
1225 /* Portably test for overflow (only works for nonzero values, so make
1226 a second check for zero). FIXME: Can't we just make n and prevn
1227 unsigned and avoid this? */
1228 if
(c
!= 'l' && c
!= 'u' && (prevn
>= n
) && n
!= 0)
1229 unsigned_p
= 1; /* Try something unsigned */
1231 /* Portably test for unsigned overflow.
1232 FIXME: This check is wrong; for example it doesn't find overflow
1233 on 0x123456789 when LONGEST is 32 bits. */
1234 if
(c
!= 'l' && c
!= 'u' && n
!= 0)
1236 if
((unsigned_p
&& (ULONGEST
) prevn
>= (ULONGEST
) n
))
1237 error ("Numeric constant too large.");
1242 /* An integer constant is an int, a long, or a long long. An L
1243 suffix forces it to be long; an LL suffix forces it to be long
1244 long. If not forced to a larger size, it gets the first type of
1245 the above that it fits in. To figure out whether it fits, we
1246 shift it right and see whether anything remains. Note that we
1247 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1248 operation, because many compilers will warn about such a shift
1249 (which always produces a zero result). Sometimes gdbarch_int_bit
1250 or gdbarch_long_bit will be that big, sometimes not. To deal with
1251 the case where it is we just always shift the value more than
1252 once, with fewer bits each time. */
1254 un
= (ULONGEST
)n
>> 2;
1256 && (un
>> (gdbarch_int_bit
(current_gdbarch
) - 2)) == 0)
1258 high_bit
= ((ULONGEST
)1) << (gdbarch_int_bit
(current_gdbarch
) - 1);
1260 /* A large decimal (not hex or octal) constant (between INT_MAX
1261 and UINT_MAX) is a long or unsigned long, according to ANSI,
1262 never an unsigned int, but this code treats it as unsigned
1263 int. This probably should be fixed. GCC gives a warning on
1266 unsigned_type
= builtin_type
(current_gdbarch
)->builtin_unsigned_int
;
1267 signed_type
= builtin_type
(current_gdbarch
)->builtin_int
;
1269 else if
(long_p
<= 1
1270 && (un
>> (gdbarch_long_bit
(current_gdbarch
) - 2)) == 0)
1272 high_bit
= ((ULONGEST
)1) << (gdbarch_long_bit
(current_gdbarch
) - 1);
1273 unsigned_type
= builtin_type
(current_gdbarch
)->builtin_unsigned_long
;
1274 signed_type
= builtin_type
(current_gdbarch
)->builtin_long
;
1279 if
(sizeof
(ULONGEST
) * HOST_CHAR_BIT
1280 < gdbarch_long_long_bit
(current_gdbarch
))
1281 /* A long long does not fit in a LONGEST. */
1282 shift
= (sizeof
(ULONGEST
) * HOST_CHAR_BIT
- 1);
1284 shift
= (gdbarch_long_long_bit
(current_gdbarch
) - 1);
1285 high_bit
= (ULONGEST
) 1 << shift
;
1286 unsigned_type
= builtin_type
(current_gdbarch
)->builtin_unsigned_long_long
;
1287 signed_type
= builtin_type
(current_gdbarch
)->builtin_long_long
;
1290 putithere
->typed_val_int.val
= n
;
1292 /* If the high bit of the worked out type is set then this number
1293 has to be unsigned. */
1295 if
(unsigned_p ||
(n
& high_bit
))
1297 putithere
->typed_val_int.type
= unsigned_type
;
1301 putithere
->typed_val_int.type
= signed_type
;
1311 enum exp_opcode opcode
;
1314 static const struct token tokentab3
[] =
1316 {">>=", ASSIGN_MODIFY
, BINOP_RSH
},
1317 {"<<=", ASSIGN_MODIFY
, BINOP_LSH
}
1320 static const struct token tokentab2
[] =
1322 {"+=", ASSIGN_MODIFY
, BINOP_ADD
},
1323 {"-=", ASSIGN_MODIFY
, BINOP_SUB
},
1324 {"*=", ASSIGN_MODIFY
, BINOP_MUL
},
1325 {"/=", ASSIGN_MODIFY
, BINOP_DIV
},
1326 {"%=", ASSIGN_MODIFY
, BINOP_REM
},
1327 {"|=", ASSIGN_MODIFY
, BINOP_BITWISE_IOR
},
1328 {"&=", ASSIGN_MODIFY
, BINOP_BITWISE_AND
},
1329 {"^=", ASSIGN_MODIFY
, BINOP_BITWISE_XOR
},
1330 {"++", INCREMENT
, BINOP_END
},
1331 {"--", DECREMENT
, BINOP_END
},
1332 {"->", ARROW
, BINOP_END
},
1333 {"&&", ANDAND
, BINOP_END
},
1334 {"||", OROR
, BINOP_END
},
1335 {"::", COLONCOLON
, BINOP_END
},
1336 {"<<", LSH
, BINOP_END
},
1337 {">>", RSH
, BINOP_END
},
1338 {"==", EQUAL
, BINOP_END
},
1339 {"!=", NOTEQUAL
, BINOP_END
},
1340 {"<=", LEQ
, BINOP_END
},
1341 {">=", GEQ
, BINOP_END
}
1344 /* Read one token, getting characters through lexptr. */
1355 static char *tempbuf
;
1356 static int tempbufsize
;
1357 char * token_string
= NULL
;
1358 int class_prefix
= 0;
1362 /* Check if this is a macro invocation that we need to expand. */
1363 if
(! scanning_macro_expansion
())
1365 char *expanded
= macro_expand_next
(&lexptr
,
1366 expression_macro_lookup_func
,
1367 expression_macro_lookup_baton
);
1370 scan_macro_expansion
(expanded
);
1373 prev_lexptr
= lexptr
;
1376 /* See if it is a special token of length 3. */
1377 for
(i
= 0; i
< sizeof tokentab3
/ sizeof tokentab3
[0]; i
++)
1378 if
(strncmp
(tokstart
, tokentab3
[i
].operator
, 3) == 0)
1381 yylval.opcode
= tokentab3
[i
].opcode
;
1382 return tokentab3
[i
].token
;
1385 /* See if it is a special token of length 2. */
1386 for
(i
= 0; i
< sizeof tokentab2
/ sizeof tokentab2
[0]; i
++)
1387 if
(strncmp
(tokstart
, tokentab2
[i
].operator
, 2) == 0)
1390 yylval.opcode
= tokentab2
[i
].opcode
;
1391 return tokentab2
[i
].token
;
1394 switch
(c
= *tokstart
)
1397 /* If we were just scanning the result of a macro expansion,
1398 then we need to resume scanning the original text.
1399 Otherwise, we were already scanning the original text, and
1400 we're really done. */
1401 if
(scanning_macro_expansion
())
1403 finished_macro_expansion
();
1416 /* We either have a character constant ('0' or '\177' for example)
1417 or we have a quoted symbol reference ('foo(int,int)' in C++
1422 c
= parse_escape
(&lexptr
);
1424 error ("Empty character constant.");
1425 else if
(! host_char_to_target
(c
, &c
))
1427 int toklen
= lexptr
- tokstart
+ 1;
1428 char *tok
= alloca
(toklen
+ 1);
1429 memcpy
(tok
, tokstart
, toklen
);
1431 error ("There is no character corresponding to %s in the target "
1432 "character set `%s'.", tok
, target_charset
());
1435 yylval.typed_val_int.val
= c
;
1436 yylval.typed_val_int.type
= builtin_type
(current_gdbarch
)->builtin_char
;
1441 namelen
= skip_quoted
(tokstart
) - tokstart
;
1444 lexptr
= tokstart
+ namelen
;
1445 if
(lexptr
[-1] != '\'')
1446 error ("Unmatched single quote.");
1451 error ("Invalid character constant.");
1461 if
(paren_depth
== 0)
1468 if
(comma_terminates
1470 && ! scanning_macro_expansion
())
1476 /* Might be a floating point number. */
1477 if
(lexptr
[1] < '0' || lexptr
[1] > '9')
1478 goto symbol
; /* Nope, must be a symbol. */
1479 /* FALL THRU into number case. */
1492 /* It's a number. */
1493 int got_dot
= 0, got_e
= 0, toktype
;
1495 int hex
= input_radix
> 10;
1497 if
(c
== '0' && (p
[1] == 'x' || p
[1] == 'X'))
1502 else if
(c
== '0' && (p
[1]=='t' || p
[1]=='T' || p
[1]=='d' || p
[1]=='D'))
1510 /* This test includes !hex because 'e' is a valid hex digit
1511 and thus does not indicate a floating point number when
1512 the radix is hex. */
1513 if
(!hex
&& !got_e
&& (*p
== 'e' ||
*p
== 'E'))
1514 got_dot
= got_e
= 1;
1515 /* This test does not include !hex, because a '.' always indicates
1516 a decimal floating point number regardless of the radix. */
1517 else if
(!got_dot
&& *p
== '.')
1519 else if
(got_e
&& (p
[-1] == 'e' || p
[-1] == 'E')
1520 && (*p
== '-' ||
*p
== '+'))
1521 /* This is the sign of the exponent, not the end of the
1524 /* We will take any letters or digits. parse_number will
1525 complain if past the radix, or if L or U are not final. */
1526 else if
((*p
< '0' ||
*p
> '9')
1527 && ((*p
< 'a' ||
*p
> 'z')
1528 && (*p
< 'A' ||
*p
> 'Z')))
1531 toktype
= parse_number
(tokstart
, p
- tokstart
, got_dot|got_e
, &yylval);
1532 if
(toktype
== ERROR
)
1534 char *err_copy
= (char *) alloca
(p
- tokstart
+ 1);
1536 memcpy
(err_copy
, tokstart
, p
- tokstart
);
1537 err_copy
[p
- tokstart
] = 0;
1538 error ("Invalid number \"%s\".", err_copy
);
1570 /* Build the gdb internal form of the input string in tempbuf,
1571 translating any standard C escape forms seen. Note that the
1572 buffer is null byte terminated *only* for the convenience of
1573 debugging gdb itself and printing the buffer contents when
1574 the buffer contains no embedded nulls. Gdb does not depend
1575 upon the buffer being null byte terminated, it uses the length
1576 string instead. This allows gdb to handle C strings (as well
1577 as strings in other languages) with embedded null bytes */
1579 tokptr
= ++tokstart
;
1583 char *char_start_pos
= tokptr
;
1585 /* Grow the static temp buffer if necessary, including allocating
1586 the first one on demand. */
1587 if
(tempbufindex
+ 1 >= tempbufsize
)
1589 tempbuf
= (char *) realloc
(tempbuf
, tempbufsize
+= 64);
1595 /* Do nothing, loop will terminate. */
1599 c
= parse_escape
(&tokptr
);
1604 tempbuf
[tempbufindex
++] = c
;
1608 if
(! host_char_to_target
(c
, &c
))
1610 int len
= tokptr
- char_start_pos
;
1611 char *copy
= alloca
(len
+ 1);
1612 memcpy
(copy
, char_start_pos
, len
);
1615 error ("There is no character corresponding to `%s' "
1616 "in the target character set `%s'.",
1617 copy
, target_charset
());
1619 tempbuf
[tempbufindex
++] = c
;
1622 } while
((*tokptr
!= '"') && (*tokptr
!= '\0'));
1623 if
(*tokptr
++ != '"')
1625 error ("Unterminated string in expression.");
1627 tempbuf
[tempbufindex
] = '\0'; /* See note above */
1628 yylval.sval.ptr
= tempbuf
;
1629 yylval.sval.length
= tempbufindex
;
1634 if
(!(c
== '_' || c
== '$'
1635 ||
(c
>= 'a' && c
<= 'z') ||
(c
>= 'A' && c
<= 'Z')))
1636 /* We must have come across a bad character (e.g. ';'). */
1637 error ("Invalid character '%c' in expression.", c
);
1639 /* It's a name. See how long it is. */
1641 for
(c
= tokstart
[namelen
];
1642 (c
== '_' || c
== '$' ||
(c
>= '0' && c
<= '9')
1643 ||
(c
>= 'a' && c
<= 'z') ||
(c
>= 'A' && c
<= 'Z') || c
== '<');)
1645 /* Template parameter lists are part of the name.
1646 FIXME: This mishandles `print $a<4&&$a>3'. */
1650 /* Scan ahead to get rest of the template specification. Note
1651 that we look ahead only when the '<' adjoins non-whitespace
1652 characters; for comparison expressions, e.g. "a < b > c",
1653 there must be spaces before the '<', etc. */
1655 char * p
= find_template_name_end
(tokstart
+ namelen
);
1657 namelen
= p
- tokstart
;
1660 c
= tokstart
[++namelen
];
1663 /* The token "if" terminates the expression and is NOT removed from
1664 the input stream. It doesn't count if it appears in the
1665 expansion of a macro. */
1667 && tokstart
[0] == 'i'
1668 && tokstart
[1] == 'f'
1669 && ! scanning_macro_expansion
())
1678 /* Catch specific keywords. Should be done with a data structure. */
1682 if
(strncmp
(tokstart
, "unsigned", 8) == 0)
1684 if
(current_language
->la_language
== language_cplus
1685 && strncmp
(tokstart
, "template", 8) == 0)
1687 if
(strncmp
(tokstart
, "volatile", 8) == 0)
1688 return VOLATILE_KEYWORD
;
1691 if
(strncmp
(tokstart
, "struct", 6) == 0)
1693 if
(strncmp
(tokstart
, "signed", 6) == 0)
1694 return SIGNED_KEYWORD
;
1695 if
(strncmp
(tokstart
, "sizeof", 6) == 0)
1697 if
(strncmp
(tokstart
, "double", 6) == 0)
1698 return DOUBLE_KEYWORD
;
1701 if
(current_language
->la_language
== language_cplus
)
1703 if
(strncmp
(tokstart
, "false", 5) == 0)
1704 return FALSEKEYWORD
;
1705 if
(strncmp
(tokstart
, "class", 5) == 0)
1708 if
(strncmp
(tokstart
, "union", 5) == 0)
1710 if
(strncmp
(tokstart
, "short", 5) == 0)
1712 if
(strncmp
(tokstart
, "const", 5) == 0)
1713 return CONST_KEYWORD
;
1716 if
(strncmp
(tokstart
, "enum", 4) == 0)
1718 if
(strncmp
(tokstart
, "long", 4) == 0)
1720 if
(current_language
->la_language
== language_cplus
)
1722 if
(strncmp
(tokstart
, "true", 4) == 0)
1727 if
(strncmp
(tokstart
, "int", 3) == 0)
1734 yylval.sval.ptr
= tokstart
;
1735 yylval.sval.length
= namelen
;
1737 if
(*tokstart
== '$')
1739 write_dollar_variable
(yylval.sval
);
1743 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1744 functions or symtabs. If this is not so, then ...
1745 Use token-type TYPENAME for symbols that happen to be defined
1746 currently as names of types; NAME for other symbols.
1747 The caller is not constrained to care about the distinction. */
1749 char *tmp
= copy_name
(yylval.sval
);
1751 int is_a_field_of_this
= 0;
1754 sym
= lookup_symbol
(tmp
, expression_context_block
,
1756 current_language
->la_language
== language_cplus
1757 ?
&is_a_field_of_this
: (int *) NULL
,
1758 (struct symtab
**) NULL
);
1759 /* Call lookup_symtab, not lookup_partial_symtab, in case there are
1760 no psymtabs (coff, xcoff, or some future change to blow away the
1761 psymtabs once once symbols are read). */
1762 if
(sym
&& SYMBOL_CLASS
(sym
) == LOC_BLOCK
)
1764 yylval.ssym.sym
= sym
;
1765 yylval.ssym.is_a_field_of_this
= is_a_field_of_this
;
1769 { /* See if it's a file name. */
1770 struct symtab
*symtab
;
1772 symtab
= lookup_symtab
(tmp
);
1776 yylval.bval
= BLOCKVECTOR_BLOCK
(BLOCKVECTOR
(symtab
), STATIC_BLOCK
);
1781 if
(sym
&& SYMBOL_CLASS
(sym
) == LOC_TYPEDEF
)
1783 /* NOTE: carlton/2003-09-25: There used to be code here to
1784 handle nested types. It didn't work very well. See the
1785 comment before qualified_type for more info. */
1786 yylval.tsym.type
= SYMBOL_TYPE
(sym
);
1790 = language_lookup_primitive_type_by_name
(current_language
,
1791 current_gdbarch
, tmp
);
1792 if
(yylval.tsym.type
!= NULL
)
1795 /* Input names that aren't symbols but ARE valid hex numbers,
1796 when the input radix permits them, can be names or numbers
1797 depending on the parse. Note we support radixes > 16 here. */
1799 ((tokstart
[0] >= 'a' && tokstart
[0] < 'a' + input_radix
- 10) ||
1800 (tokstart
[0] >= 'A' && tokstart
[0] < 'A' + input_radix
- 10)))
1802 YYSTYPE newlval
; /* Its value is ignored. */
1803 hextype
= parse_number
(tokstart
, namelen
, 0, &newlval
);
1806 yylval.ssym.sym
= sym
;
1807 yylval.ssym.is_a_field_of_this
= is_a_field_of_this
;
1812 /* Any other kind of symbol */
1813 yylval.ssym.sym
= sym
;
1814 yylval.ssym.is_a_field_of_this
= is_a_field_of_this
;
1824 lexptr
= prev_lexptr
;
1826 error ("A %s in expression, near `%s'.", (msg ? msg
: "error"), lexptr
);