1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986, 1989-2000, 2003-2004, 2006-2012 Free Software
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Parse a C expression from text in a string,
21 and return the result as a struct expression pointer.
22 That structure contains arithmetic operations in reverse polish,
23 with constants represented by operations that are followed by special data.
24 See expression.h for the details of the format.
25 What is important here is that it can be built up sequentially
26 during the process of parsing; the lower levels of the tree always
27 come first in the result.
29 Note that malloc's and realloc's in this file are transformed to
30 xmalloc and xrealloc respectively by the same sed command in the
31 makefile that remaps any other malloc/realloc inserted by the parser
32 generator. Doing this with #defines and trying to control the interaction
33 with include files (<malloc.h> and <stdlib.h> for example) just became
34 too messy, particularly when such includes can be inserted at random
35 times by the parser generator. */
40 #include "gdb_string.h"
42 #include "expression.h"
44 #include "parser-defs.h"
47 #include "bfd.h" /* Required by objfiles.h. */
48 #include "symfile.h" /* Required by objfiles.h. */
49 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
52 #include "cp-support.h"
54 #include "gdb_assert.h"
55 #include "macroscope.h"
56 #include "objc-lang.h"
57 #include "typeprint.h"
59 #define parse_type builtin_type (parse_gdbarch)
61 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
62 as well as gratuitiously global symbol names, so we can have multiple
63 yacc generated parsers in gdb. Note that these are only the variables
64 produced by yacc. If other parser generators (bison, byacc, etc) produce
65 additional global names that conflict at link time, then those parser
66 generators need to be fixed instead of adding those names to this list. */
68 #define yymaxdepth c_maxdepth
69 #define yyparse c_parse_internal
71 #define yyerror c_error
74 #define yydebug c_debug
83 #define yyerrflag c_errflag
84 #define yynerrs c_nerrs
89 #define yystate c_state
95 #define yyreds c_reds /* With YYDEBUG defined */
96 #define yytoks c_toks /* With YYDEBUG defined */
97 #define yyname c_name /* With YYDEBUG defined */
98 #define yyrule c_rule /* With YYDEBUG defined */
100 #define yylen c_yylen
101 #define yydefred c_yydefred
102 #define yydgoto c_yydgoto
103 #define yysindex c_yysindex
104 #define yyrindex c_yyrindex
105 #define yygindex c_yygindex
106 #define yytable c_yytable
107 #define yycheck c_yycheck
109 #define yysslim c_yysslim
110 #define yyssp c_yyssp
111 #define yystacksize c_yystacksize
113 #define yyvsp c_yyvsp
116 #define YYDEBUG 1 /* Default to yydebug support */
119 #define YYFPRINTF parser_fprintf
123 static int yylex (void);
125 void yyerror (char *);
129 /* Although the yacc "value" of an expression is not used,
130 since the result is stored in the structure being created,
131 other node types do have values. */
147 } typed_val_decfloat;
151 struct typed_stoken tsval;
153 struct symtoken ssym;
156 enum exp_opcode opcode;
157 struct internalvar *ivar;
159 struct stoken_vector svec;
160 VEC (type_ptr) *tvec;
163 struct type_stack *type_stack;
165 struct objc_class_str class;
169 /* YYSTYPE gets defined by %union */
170 static int parse_number (char *, int, int, YYSTYPE *);
171 static struct stoken operator_stoken (const char *);
172 static void check_parameter_typelist (VEC (type_ptr) *);
175 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
177 %type <tval> type typebase
178 %type <tvec> nonempty_typelist func_mod parameter_typelist
179 /* %type <bval> block */
181 /* Fancy type parsing. */
183 %type <lval> array_mod
184 %type <tval> conversion_type_id
186 %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
188 %token <typed_val_int> INT
189 %token <typed_val_float> FLOAT
190 %token <typed_val_decfloat> DECFLOAT
192 /* Both NAME and TYPENAME tokens represent symbols in the input,
193 and both convey their data as strings.
194 But a TYPENAME is a string that happens to be defined as a typedef
195 or builtin type name (such as int or char)
196 and a NAME is any other symbol.
197 Contexts where this distinction is not important can use the
198 nonterminal "name", which matches either NAME or TYPENAME. */
200 %token <tsval> STRING
201 %token <sval> NSSTRING /* ObjC Foundation "NSString" literal */
202 %token SELECTOR /* ObjC "@selector" pseudo-operator */
204 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
205 %token <ssym> UNKNOWN_CPP_NAME
206 %token <voidval> COMPLETE
207 %token <tsym> TYPENAME
208 %token <class> CLASSNAME /* ObjC Class name */
210 %type <svec> string_exp
211 %type <ssym> name_not_typename
212 %type <tsym> typename
214 /* This is like a '[' token, but is only generated when parsing
215 Objective C. This lets us reuse the same parser without
216 erroneously parsing ObjC-specific expressions in C. */
219 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
220 but which would parse as a valid number in the current input radix.
221 E.g. "c" when input_radix==16. Depending on the parse, it will be
222 turned into a name or into a number. */
224 %token <ssym> NAME_OR_INT
227 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
231 %type <sval> operator
232 %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
237 /* Special type cases, put in to allow the parser to distinguish different
239 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
241 %token <sval> VARIABLE
243 %token <opcode> ASSIGN_MODIFY
252 %right '=' ASSIGN_MODIFY
260 %left '<' '>' LEQ GEQ
265 %right UNARY INCREMENT DECREMENT
266 %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
267 %token <ssym> BLOCKNAME
268 %token <bval> FILENAME
282 { write_exp_elt_opcode(OP_TYPE);
283 write_exp_elt_type($1);
284 write_exp_elt_opcode(OP_TYPE);}
287 write_exp_elt_opcode (OP_TYPEOF);
289 | TYPEOF '(' type ')'
291 write_exp_elt_opcode (OP_TYPE);
292 write_exp_elt_type ($3);
293 write_exp_elt_opcode (OP_TYPE);
295 | DECLTYPE '(' exp ')'
297 write_exp_elt_opcode (OP_DECLTYPE);
301 /* Expressions, including the comma operator. */
304 { write_exp_elt_opcode (BINOP_COMMA); }
307 /* Expressions, not including the comma operator. */
308 exp : '*' exp %prec UNARY
309 { write_exp_elt_opcode (UNOP_IND); }
312 exp : '&' exp %prec UNARY
313 { write_exp_elt_opcode (UNOP_ADDR); }
316 exp : '-' exp %prec UNARY
317 { write_exp_elt_opcode (UNOP_NEG); }
320 exp : '+' exp %prec UNARY
321 { write_exp_elt_opcode (UNOP_PLUS); }
324 exp : '!' exp %prec UNARY
325 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
328 exp : '~' exp %prec UNARY
329 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
332 exp : INCREMENT exp %prec UNARY
333 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
336 exp : DECREMENT exp %prec UNARY
337 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
340 exp : exp INCREMENT %prec UNARY
341 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
344 exp : exp DECREMENT %prec UNARY
345 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
348 exp : SIZEOF exp %prec UNARY
349 { write_exp_elt_opcode (UNOP_SIZEOF); }
353 { write_exp_elt_opcode (STRUCTOP_PTR);
354 write_exp_string ($3);
355 write_exp_elt_opcode (STRUCTOP_PTR); }
358 exp : exp ARROW name COMPLETE
359 { mark_struct_expression ();
360 write_exp_elt_opcode (STRUCTOP_PTR);
361 write_exp_string ($3);
362 write_exp_elt_opcode (STRUCTOP_PTR); }
365 exp : exp ARROW COMPLETE
367 mark_struct_expression ();
368 write_exp_elt_opcode (STRUCTOP_PTR);
371 write_exp_string (s);
372 write_exp_elt_opcode (STRUCTOP_PTR); }
375 exp : exp ARROW qualified_name
376 { /* exp->type::name becomes exp->*(&type::name) */
377 /* Note: this doesn't work if name is a
378 static member! FIXME */
379 write_exp_elt_opcode (UNOP_ADDR);
380 write_exp_elt_opcode (STRUCTOP_MPTR); }
383 exp : exp ARROW_STAR exp
384 { write_exp_elt_opcode (STRUCTOP_MPTR); }
388 { write_exp_elt_opcode (STRUCTOP_STRUCT);
389 write_exp_string ($3);
390 write_exp_elt_opcode (STRUCTOP_STRUCT); }
393 exp : exp '.' name COMPLETE
394 { mark_struct_expression ();
395 write_exp_elt_opcode (STRUCTOP_STRUCT);
396 write_exp_string ($3);
397 write_exp_elt_opcode (STRUCTOP_STRUCT); }
400 exp : exp '.' COMPLETE
402 mark_struct_expression ();
403 write_exp_elt_opcode (STRUCTOP_STRUCT);
406 write_exp_string (s);
407 write_exp_elt_opcode (STRUCTOP_STRUCT); }
410 exp : exp '.' qualified_name
411 { /* exp.type::name becomes exp.*(&type::name) */
412 /* Note: this doesn't work if name is a
413 static member! FIXME */
414 write_exp_elt_opcode (UNOP_ADDR);
415 write_exp_elt_opcode (STRUCTOP_MEMBER); }
418 exp : exp DOT_STAR exp
419 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
422 exp : exp '[' exp1 ']'
423 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
426 exp : exp OBJC_LBRAC exp1 ']'
427 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
431 * The rules below parse ObjC message calls of the form:
432 * '[' target selector {':' argument}* ']'
435 exp : OBJC_LBRAC TYPENAME
439 class = lookup_objc_class (parse_gdbarch,
440 copy_name ($2.stoken));
442 error (_("%s is not an ObjC Class"),
443 copy_name ($2.stoken));
444 write_exp_elt_opcode (OP_LONG);
445 write_exp_elt_type (parse_type->builtin_int);
446 write_exp_elt_longcst ((LONGEST) class);
447 write_exp_elt_opcode (OP_LONG);
451 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
453 write_exp_elt_opcode (OP_OBJC_MSGCALL);
457 exp : OBJC_LBRAC CLASSNAME
459 write_exp_elt_opcode (OP_LONG);
460 write_exp_elt_type (parse_type->builtin_int);
461 write_exp_elt_longcst ((LONGEST) $2.class);
462 write_exp_elt_opcode (OP_LONG);
466 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
468 write_exp_elt_opcode (OP_OBJC_MSGCALL);
475 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
477 write_exp_elt_opcode (OP_OBJC_MSGCALL);
482 { add_msglist(&$1, 0); }
490 msgarg : name ':' exp
491 { add_msglist(&$1, 1); }
492 | ':' exp /* Unnamed arg. */
493 { add_msglist(0, 1); }
494 | ',' exp /* Variable number of args. */
495 { add_msglist(0, 0); }
499 /* This is to save the value of arglist_len
500 being accumulated by an outer function call. */
501 { start_arglist (); }
502 arglist ')' %prec ARROW
503 { write_exp_elt_opcode (OP_FUNCALL);
504 write_exp_elt_longcst ((LONGEST) end_arglist ());
505 write_exp_elt_opcode (OP_FUNCALL); }
508 exp : UNKNOWN_CPP_NAME '('
510 /* This could potentially be a an argument defined
511 lookup function (Koenig). */
512 write_exp_elt_opcode (OP_ADL_FUNC);
513 write_exp_elt_block (expression_context_block);
514 write_exp_elt_sym (NULL); /* Placeholder. */
515 write_exp_string ($1.stoken);
516 write_exp_elt_opcode (OP_ADL_FUNC);
518 /* This is to save the value of arglist_len
519 being accumulated by an outer function call. */
523 arglist ')' %prec ARROW
525 write_exp_elt_opcode (OP_FUNCALL);
526 write_exp_elt_longcst ((LONGEST) end_arglist ());
527 write_exp_elt_opcode (OP_FUNCALL);
532 { start_arglist (); }
542 arglist : arglist ',' exp %prec ABOVE_COMMA
546 exp : exp '(' parameter_typelist ')' const_or_volatile
548 VEC (type_ptr) *type_list = $3;
549 struct type *type_elt;
550 LONGEST len = VEC_length (type_ptr, type_list);
552 write_exp_elt_opcode (TYPE_INSTANCE);
553 write_exp_elt_longcst (len);
555 VEC_iterate (type_ptr, type_list, i, type_elt);
557 write_exp_elt_type (type_elt);
558 write_exp_elt_longcst(len);
559 write_exp_elt_opcode (TYPE_INSTANCE);
560 VEC_free (type_ptr, type_list);
565 { $$ = end_arglist () - 1; }
567 exp : lcurly arglist rcurly %prec ARROW
568 { write_exp_elt_opcode (OP_ARRAY);
569 write_exp_elt_longcst ((LONGEST) 0);
570 write_exp_elt_longcst ((LONGEST) $3);
571 write_exp_elt_opcode (OP_ARRAY); }
574 exp : lcurly type_exp rcurly exp %prec UNARY
575 { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); }
578 exp : '(' type_exp ')' exp %prec UNARY
579 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
586 /* Binary operators in order of decreasing precedence. */
589 { write_exp_elt_opcode (BINOP_REPEAT); }
593 { write_exp_elt_opcode (BINOP_MUL); }
597 { write_exp_elt_opcode (BINOP_DIV); }
601 { write_exp_elt_opcode (BINOP_REM); }
605 { write_exp_elt_opcode (BINOP_ADD); }
609 { write_exp_elt_opcode (BINOP_SUB); }
613 { write_exp_elt_opcode (BINOP_LSH); }
617 { write_exp_elt_opcode (BINOP_RSH); }
621 { write_exp_elt_opcode (BINOP_EQUAL); }
624 exp : exp NOTEQUAL exp
625 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
629 { write_exp_elt_opcode (BINOP_LEQ); }
633 { write_exp_elt_opcode (BINOP_GEQ); }
637 { write_exp_elt_opcode (BINOP_LESS); }
641 { write_exp_elt_opcode (BINOP_GTR); }
645 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
649 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
653 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
657 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
661 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
664 exp : exp '?' exp ':' exp %prec '?'
665 { write_exp_elt_opcode (TERNOP_COND); }
669 { write_exp_elt_opcode (BINOP_ASSIGN); }
672 exp : exp ASSIGN_MODIFY exp
673 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
674 write_exp_elt_opcode ($2);
675 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
679 { write_exp_elt_opcode (OP_LONG);
680 write_exp_elt_type ($1.type);
681 write_exp_elt_longcst ((LONGEST)($1.val));
682 write_exp_elt_opcode (OP_LONG); }
687 struct stoken_vector vec;
690 write_exp_string_vector ($1.type, &vec);
696 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
697 write_exp_elt_opcode (OP_LONG);
698 write_exp_elt_type (val.typed_val_int.type);
699 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
700 write_exp_elt_opcode (OP_LONG);
706 { write_exp_elt_opcode (OP_DOUBLE);
707 write_exp_elt_type ($1.type);
708 write_exp_elt_dblcst ($1.dval);
709 write_exp_elt_opcode (OP_DOUBLE); }
713 { write_exp_elt_opcode (OP_DECFLOAT);
714 write_exp_elt_type ($1.type);
715 write_exp_elt_decfloatcst ($1.val);
716 write_exp_elt_opcode (OP_DECFLOAT); }
724 write_dollar_variable ($1);
728 exp : SELECTOR '(' name ')'
730 write_exp_elt_opcode (OP_OBJC_SELECTOR);
731 write_exp_string ($3);
732 write_exp_elt_opcode (OP_OBJC_SELECTOR); }
735 exp : SIZEOF '(' type ')' %prec UNARY
736 { write_exp_elt_opcode (OP_LONG);
737 write_exp_elt_type (lookup_signed_typename
738 (parse_language, parse_gdbarch,
741 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
742 write_exp_elt_opcode (OP_LONG); }
745 exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
746 { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
749 exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
750 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
753 exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
754 { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
757 exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
758 { /* We could do more error checking here, but
759 it doesn't seem worthwhile. */
760 write_exp_elt_opcode (UNOP_CAST_TYPE); }
766 /* We copy the string here, and not in the
767 lexer, to guarantee that we do not leak a
768 string. Note that we follow the
769 NUL-termination convention of the
771 struct typed_stoken *vec = XNEW (struct typed_stoken);
776 vec->length = $1.length;
777 vec->ptr = malloc ($1.length + 1);
778 memcpy (vec->ptr, $1.ptr, $1.length + 1);
783 /* Note that we NUL-terminate here, but just
787 $$.tokens = realloc ($$.tokens,
788 $$.len * sizeof (struct typed_stoken));
790 p = malloc ($2.length + 1);
791 memcpy (p, $2.ptr, $2.length + 1);
793 $$.tokens[$$.len - 1].type = $2.type;
794 $$.tokens[$$.len - 1].length = $2.length;
795 $$.tokens[$$.len - 1].ptr = p;
802 enum c_string_type type = C_STRING;
804 for (i = 0; i < $1.len; ++i)
806 switch ($1.tokens[i].type)
814 && type != $1.tokens[i].type)
815 error (_("Undefined string concatenation."));
816 type = $1.tokens[i].type;
820 internal_error (__FILE__, __LINE__,
821 "unrecognized type in string concatenation");
825 write_exp_string_vector (type, &$1);
826 for (i = 0; i < $1.len; ++i)
827 free ($1.tokens[i].ptr);
832 exp : NSSTRING /* ObjC NextStep NSString constant
833 * of the form '@' '"' string '"'.
835 { write_exp_elt_opcode (OP_OBJC_NSSTRING);
836 write_exp_string ($1);
837 write_exp_elt_opcode (OP_OBJC_NSSTRING); }
842 { write_exp_elt_opcode (OP_LONG);
843 write_exp_elt_type (parse_type->builtin_bool);
844 write_exp_elt_longcst ((LONGEST) 1);
845 write_exp_elt_opcode (OP_LONG); }
849 { write_exp_elt_opcode (OP_LONG);
850 write_exp_elt_type (parse_type->builtin_bool);
851 write_exp_elt_longcst ((LONGEST) 0);
852 write_exp_elt_opcode (OP_LONG); }
860 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
862 error (_("No file or function \"%s\"."),
863 copy_name ($1.stoken));
871 block : block COLONCOLON name
873 = lookup_symbol (copy_name ($3), $1,
874 VAR_DOMAIN, (int *) NULL);
875 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
876 error (_("No function \"%s\" in specified context."),
878 $$ = SYMBOL_BLOCK_VALUE (tem); }
881 variable: name_not_typename ENTRY
882 { struct symbol *sym = $1.sym;
884 if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
885 || !symbol_read_needs_frame (sym))
886 error (_("@entry can be used only for function "
887 "parameters, not for \"%s\""),
888 copy_name ($1.stoken));
890 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
891 write_exp_elt_sym (sym);
892 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
896 variable: block COLONCOLON name
897 { struct symbol *sym;
898 sym = lookup_symbol (copy_name ($3), $1,
899 VAR_DOMAIN, (int *) NULL);
901 error (_("No symbol \"%s\" in specified context."),
903 if (symbol_read_needs_frame (sym))
905 if (innermost_block == 0
906 || contained_in (block_found,
908 innermost_block = block_found;
911 write_exp_elt_opcode (OP_VAR_VALUE);
912 /* block_found is set by lookup_symbol. */
913 write_exp_elt_block (block_found);
914 write_exp_elt_sym (sym);
915 write_exp_elt_opcode (OP_VAR_VALUE); }
918 qualified_name: TYPENAME COLONCOLON name
920 struct type *type = $1.type;
921 CHECK_TYPEDEF (type);
922 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
923 && TYPE_CODE (type) != TYPE_CODE_UNION
924 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
925 error (_("`%s' is not defined as an aggregate type."),
928 write_exp_elt_opcode (OP_SCOPE);
929 write_exp_elt_type (type);
930 write_exp_string ($3);
931 write_exp_elt_opcode (OP_SCOPE);
933 | TYPENAME COLONCOLON '~' name
935 struct type *type = $1.type;
936 struct stoken tmp_token;
937 CHECK_TYPEDEF (type);
938 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
939 && TYPE_CODE (type) != TYPE_CODE_UNION
940 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
941 error (_("`%s' is not defined as an aggregate type."),
944 tmp_token.ptr = (char*) alloca ($4.length + 2);
945 tmp_token.length = $4.length + 1;
946 tmp_token.ptr[0] = '~';
947 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
948 tmp_token.ptr[tmp_token.length] = 0;
950 /* Check for valid destructor name. */
951 destructor_name_p (tmp_token.ptr, $1.type);
952 write_exp_elt_opcode (OP_SCOPE);
953 write_exp_elt_type (type);
954 write_exp_string (tmp_token);
955 write_exp_elt_opcode (OP_SCOPE);
957 | TYPENAME COLONCOLON name COLONCOLON name
959 char *copy = copy_name ($3);
960 error (_("No type \"%s\" within class "
961 "or namespace \"%s\"."),
962 copy, TYPE_NAME ($1.type));
966 variable: qualified_name
967 | COLONCOLON name_not_typename
969 char *name = copy_name ($2.stoken);
971 struct minimal_symbol *msymbol;
974 lookup_symbol (name, (const struct block *) NULL,
975 VAR_DOMAIN, (int *) NULL);
978 write_exp_elt_opcode (OP_VAR_VALUE);
979 write_exp_elt_block (NULL);
980 write_exp_elt_sym (sym);
981 write_exp_elt_opcode (OP_VAR_VALUE);
985 msymbol = lookup_minimal_symbol (name, NULL, NULL);
987 write_exp_msymbol (msymbol);
988 else if (!have_full_symbols () && !have_partial_symbols ())
989 error (_("No symbol table is loaded. Use the \"file\" command."));
991 error (_("No symbol \"%s\" in current context."), name);
995 variable: name_not_typename
996 { struct symbol *sym = $1.sym;
1000 if (symbol_read_needs_frame (sym))
1002 if (innermost_block == 0
1003 || contained_in (block_found,
1005 innermost_block = block_found;
1008 write_exp_elt_opcode (OP_VAR_VALUE);
1009 /* We want to use the selected frame, not
1010 another more inner frame which happens to
1011 be in the same block. */
1012 write_exp_elt_block (NULL);
1013 write_exp_elt_sym (sym);
1014 write_exp_elt_opcode (OP_VAR_VALUE);
1016 else if ($1.is_a_field_of_this)
1018 /* C++: it hangs off of `this'. Must
1019 not inadvertently convert from a method call
1021 if (innermost_block == 0
1022 || contained_in (block_found,
1024 innermost_block = block_found;
1025 write_exp_elt_opcode (OP_THIS);
1026 write_exp_elt_opcode (OP_THIS);
1027 write_exp_elt_opcode (STRUCTOP_PTR);
1028 write_exp_string ($1.stoken);
1029 write_exp_elt_opcode (STRUCTOP_PTR);
1033 struct minimal_symbol *msymbol;
1034 char *arg = copy_name ($1.stoken);
1037 lookup_minimal_symbol (arg, NULL, NULL);
1038 if (msymbol != NULL)
1039 write_exp_msymbol (msymbol);
1040 else if (!have_full_symbols () && !have_partial_symbols ())
1041 error (_("No symbol table is loaded. Use the \"file\" command."));
1043 error (_("No symbol \"%s\" in current context."),
1044 copy_name ($1.stoken));
1049 space_identifier : '@' NAME
1050 { insert_type_address_space (copy_name ($2.stoken)); }
1053 const_or_volatile: const_or_volatile_noopt
1057 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
1060 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
1061 | const_or_volatile_noopt
1064 const_or_volatile_or_space_identifier:
1065 const_or_volatile_or_space_identifier_noopt
1071 { insert_type (tp_pointer); }
1072 const_or_volatile_or_space_identifier
1074 { insert_type (tp_pointer); }
1075 const_or_volatile_or_space_identifier
1077 { insert_type (tp_reference); }
1079 { insert_type (tp_reference); }
1082 ptr_operator_ts: ptr_operator
1084 $$ = get_type_stack ();
1085 /* This cleanup is eventually run by
1087 make_cleanup (type_stack_cleanup, $$);
1091 abs_decl: ptr_operator_ts direct_abs_decl
1092 { $$ = append_type_stack ($2, $1); }
1097 direct_abs_decl: '(' abs_decl ')'
1099 | direct_abs_decl array_mod
1101 push_type_stack ($1);
1103 push_type (tp_array);
1104 $$ = get_type_stack ();
1109 push_type (tp_array);
1110 $$ = get_type_stack ();
1113 | direct_abs_decl func_mod
1115 push_type_stack ($1);
1117 $$ = get_type_stack ();
1122 $$ = get_type_stack ();
1132 | OBJC_LBRAC INT ']'
1138 | '(' parameter_typelist ')'
1142 /* We used to try to recognize pointer to member types here, but
1143 that didn't work (shift/reduce conflicts meant that these rules never
1144 got executed). The problem is that
1145 int (foo::bar::baz::bizzle)
1146 is a function type but
1147 int (foo::bar::baz::bizzle::*)
1148 is a pointer to member type. Stroustrup loses again! */
1153 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
1157 { $$ = lookup_signed_typename (parse_language,
1161 { $$ = lookup_signed_typename (parse_language,
1165 { $$ = lookup_signed_typename (parse_language,
1169 { $$ = lookup_signed_typename (parse_language,
1172 | LONG SIGNED_KEYWORD INT_KEYWORD
1173 { $$ = lookup_signed_typename (parse_language,
1176 | LONG SIGNED_KEYWORD
1177 { $$ = lookup_signed_typename (parse_language,
1180 | SIGNED_KEYWORD LONG INT_KEYWORD
1181 { $$ = lookup_signed_typename (parse_language,
1184 | UNSIGNED LONG INT_KEYWORD
1185 { $$ = lookup_unsigned_typename (parse_language,
1188 | LONG UNSIGNED INT_KEYWORD
1189 { $$ = lookup_unsigned_typename (parse_language,
1193 { $$ = lookup_unsigned_typename (parse_language,
1197 { $$ = lookup_signed_typename (parse_language,
1200 | LONG LONG INT_KEYWORD
1201 { $$ = lookup_signed_typename (parse_language,
1204 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
1205 { $$ = lookup_signed_typename (parse_language,
1208 | LONG LONG SIGNED_KEYWORD
1209 { $$ = lookup_signed_typename (parse_language,
1212 | SIGNED_KEYWORD LONG LONG
1213 { $$ = lookup_signed_typename (parse_language,
1216 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
1217 { $$ = lookup_signed_typename (parse_language,
1220 | UNSIGNED LONG LONG
1221 { $$ = lookup_unsigned_typename (parse_language,
1224 | UNSIGNED LONG LONG INT_KEYWORD
1225 { $$ = lookup_unsigned_typename (parse_language,
1228 | LONG LONG UNSIGNED
1229 { $$ = lookup_unsigned_typename (parse_language,
1232 | LONG LONG UNSIGNED INT_KEYWORD
1233 { $$ = lookup_unsigned_typename (parse_language,
1237 { $$ = lookup_signed_typename (parse_language,
1240 | SHORT SIGNED_KEYWORD INT_KEYWORD
1241 { $$ = lookup_signed_typename (parse_language,
1244 | SHORT SIGNED_KEYWORD
1245 { $$ = lookup_signed_typename (parse_language,
1248 | UNSIGNED SHORT INT_KEYWORD
1249 { $$ = lookup_unsigned_typename (parse_language,
1253 { $$ = lookup_unsigned_typename (parse_language,
1256 | SHORT UNSIGNED INT_KEYWORD
1257 { $$ = lookup_unsigned_typename (parse_language,
1261 { $$ = lookup_typename (parse_language, parse_gdbarch,
1262 "double", (struct block *) NULL,
1264 | LONG DOUBLE_KEYWORD
1265 { $$ = lookup_typename (parse_language, parse_gdbarch,
1267 (struct block *) NULL, 0); }
1269 { $$ = lookup_struct (copy_name ($2),
1270 expression_context_block); }
1273 mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
1276 | STRUCT name COMPLETE
1278 mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
1283 { $$ = lookup_struct (copy_name ($2),
1284 expression_context_block); }
1287 mark_completion_tag (TYPE_CODE_CLASS, "", 0);
1290 | CLASS name COMPLETE
1292 mark_completion_tag (TYPE_CODE_CLASS, $2.ptr,
1297 { $$ = lookup_union (copy_name ($2),
1298 expression_context_block); }
1301 mark_completion_tag (TYPE_CODE_UNION, "", 0);
1304 | UNION name COMPLETE
1306 mark_completion_tag (TYPE_CODE_UNION, $2.ptr,
1311 { $$ = lookup_enum (copy_name ($2),
1312 expression_context_block); }
1315 mark_completion_tag (TYPE_CODE_ENUM, "", 0);
1318 | ENUM name COMPLETE
1320 mark_completion_tag (TYPE_CODE_ENUM, $2.ptr,
1325 { $$ = lookup_unsigned_typename (parse_language,
1327 TYPE_NAME($2.type)); }
1329 { $$ = lookup_unsigned_typename (parse_language,
1332 | SIGNED_KEYWORD typename
1333 { $$ = lookup_signed_typename (parse_language,
1335 TYPE_NAME($2.type)); }
1337 { $$ = lookup_signed_typename (parse_language,
1340 /* It appears that this rule for templates is never
1341 reduced; template recognition happens by lookahead
1342 in the token processing code in yylex. */
1343 | TEMPLATE name '<' type '>'
1344 { $$ = lookup_template_type(copy_name($2), $4,
1345 expression_context_block);
1347 | const_or_volatile_or_space_identifier_noopt typebase
1348 { $$ = follow_types ($2); }
1349 | typebase const_or_volatile_or_space_identifier_noopt
1350 { $$ = follow_types ($1); }
1356 $$.stoken.ptr = "int";
1357 $$.stoken.length = 3;
1358 $$.type = lookup_signed_typename (parse_language,
1364 $$.stoken.ptr = "long";
1365 $$.stoken.length = 4;
1366 $$.type = lookup_signed_typename (parse_language,
1372 $$.stoken.ptr = "short";
1373 $$.stoken.length = 5;
1374 $$.type = lookup_signed_typename (parse_language,
1382 { check_parameter_typelist ($1); }
1383 | nonempty_typelist ',' DOTDOTDOT
1385 VEC_safe_push (type_ptr, $1, NULL);
1386 check_parameter_typelist ($1);
1394 VEC (type_ptr) *typelist = NULL;
1395 VEC_safe_push (type_ptr, typelist, $1);
1398 | nonempty_typelist ',' type
1400 VEC_safe_push (type_ptr, $1, $3);
1408 push_type_stack ($2);
1409 $$ = follow_types ($1);
1413 conversion_type_id: typebase conversion_declarator
1414 { $$ = follow_types ($1); }
1417 conversion_declarator: /* Nothing. */
1418 | ptr_operator conversion_declarator
1421 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1422 | VOLATILE_KEYWORD CONST_KEYWORD
1425 const_or_volatile_noopt: const_and_volatile
1426 { insert_type (tp_const);
1427 insert_type (tp_volatile);
1430 { insert_type (tp_const); }
1432 { insert_type (tp_volatile); }
1435 operator: OPERATOR NEW
1436 { $$ = operator_stoken (" new"); }
1438 { $$ = operator_stoken (" delete"); }
1439 | OPERATOR NEW '[' ']'
1440 { $$ = operator_stoken (" new[]"); }
1441 | OPERATOR DELETE '[' ']'
1442 { $$ = operator_stoken (" delete[]"); }
1443 | OPERATOR NEW OBJC_LBRAC ']'
1444 { $$ = operator_stoken (" new[]"); }
1445 | OPERATOR DELETE OBJC_LBRAC ']'
1446 { $$ = operator_stoken (" delete[]"); }
1448 { $$ = operator_stoken ("+"); }
1450 { $$ = operator_stoken ("-"); }
1452 { $$ = operator_stoken ("*"); }
1454 { $$ = operator_stoken ("/"); }
1456 { $$ = operator_stoken ("%"); }
1458 { $$ = operator_stoken ("^"); }
1460 { $$ = operator_stoken ("&"); }
1462 { $$ = operator_stoken ("|"); }
1464 { $$ = operator_stoken ("~"); }
1466 { $$ = operator_stoken ("!"); }
1468 { $$ = operator_stoken ("="); }
1470 { $$ = operator_stoken ("<"); }
1472 { $$ = operator_stoken (">"); }
1473 | OPERATOR ASSIGN_MODIFY
1474 { const char *op = "unknown";
1498 case BINOP_BITWISE_IOR:
1501 case BINOP_BITWISE_AND:
1504 case BINOP_BITWISE_XOR:
1511 $$ = operator_stoken (op);
1514 { $$ = operator_stoken ("<<"); }
1516 { $$ = operator_stoken (">>"); }
1518 { $$ = operator_stoken ("=="); }
1520 { $$ = operator_stoken ("!="); }
1522 { $$ = operator_stoken ("<="); }
1524 { $$ = operator_stoken (">="); }
1526 { $$ = operator_stoken ("&&"); }
1528 { $$ = operator_stoken ("||"); }
1529 | OPERATOR INCREMENT
1530 { $$ = operator_stoken ("++"); }
1531 | OPERATOR DECREMENT
1532 { $$ = operator_stoken ("--"); }
1534 { $$ = operator_stoken (","); }
1535 | OPERATOR ARROW_STAR
1536 { $$ = operator_stoken ("->*"); }
1538 { $$ = operator_stoken ("->"); }
1540 { $$ = operator_stoken ("()"); }
1542 { $$ = operator_stoken ("[]"); }
1543 | OPERATOR OBJC_LBRAC ']'
1544 { $$ = operator_stoken ("[]"); }
1545 | OPERATOR conversion_type_id
1548 struct ui_file *buf = mem_fileopen ();
1550 c_print_type ($2, NULL, buf, -1, 0,
1551 &type_print_raw_options);
1552 name = ui_file_xstrdup (buf, &length);
1553 ui_file_delete (buf);
1554 $$ = operator_stoken (name);
1561 name : NAME { $$ = $1.stoken; }
1562 | BLOCKNAME { $$ = $1.stoken; }
1563 | TYPENAME { $$ = $1.stoken; }
1564 | NAME_OR_INT { $$ = $1.stoken; }
1565 | UNKNOWN_CPP_NAME { $$ = $1.stoken; }
1566 | operator { $$ = $1; }
1569 name_not_typename : NAME
1571 /* These would be useful if name_not_typename was useful, but it is just
1572 a fake for "variable", so these cause reduce/reduce conflicts because
1573 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1574 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1575 context where only a name could occur, this might be useful.
1581 $$.sym = lookup_symbol ($1.ptr,
1582 expression_context_block,
1584 &$$.is_a_field_of_this);
1591 /* Returns a stoken of the operator name given by OP (which does not
1592 include the string "operator"). */
1593 static struct stoken
1594 operator_stoken (const char *op)
1596 static const char *operator_string = "operator";
1597 struct stoken st = { NULL, 0 };
1598 st.length = strlen (operator_string) + strlen (op);
1599 st.ptr = malloc (st.length + 1);
1600 strcpy (st.ptr, operator_string);
1601 strcat (st.ptr, op);
1603 /* The toplevel (c_parse) will free the memory allocated here. */
1604 make_cleanup (free, st.ptr);
1608 /* Validate a parameter typelist. */
1611 check_parameter_typelist (VEC (type_ptr) *params)
1616 for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
1618 if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1622 if (VEC_length (type_ptr, params) == 1)
1627 VEC_free (type_ptr, params);
1628 error (_("parameter types following 'void'"));
1632 VEC_free (type_ptr, params);
1633 error (_("'void' invalid as parameter type"));
1639 /* Take care of parsing a number (anything that starts with a digit).
1640 Set yylval and return the token type; update lexptr.
1641 LEN is the number of characters in it. */
1643 /*** Needs some error checking for the float case ***/
1646 parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
1648 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1649 here, and we do kind of silly things like cast to unsigned. */
1656 int base = input_radix;
1659 /* Number of "L" suffixes encountered. */
1662 /* We have found a "L" or "U" suffix. */
1663 int found_suffix = 0;
1666 struct type *signed_type;
1667 struct type *unsigned_type;
1671 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1672 point. Return DECFLOAT. */
1674 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1677 putithere->typed_val_decfloat.type
1678 = parse_type->builtin_decfloat;
1679 decimal_from_string (putithere->typed_val_decfloat.val, 4,
1680 gdbarch_byte_order (parse_gdbarch), p);
1685 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1688 putithere->typed_val_decfloat.type
1689 = parse_type->builtin_decdouble;
1690 decimal_from_string (putithere->typed_val_decfloat.val, 8,
1691 gdbarch_byte_order (parse_gdbarch), p);
1696 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1699 putithere->typed_val_decfloat.type
1700 = parse_type->builtin_declong;
1701 decimal_from_string (putithere->typed_val_decfloat.val, 16,
1702 gdbarch_byte_order (parse_gdbarch), p);
1707 if (! parse_c_float (parse_gdbarch, p, len,
1708 &putithere->typed_val_float.dval,
1709 &putithere->typed_val_float.type))
1714 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1758 if (c >= 'A' && c <= 'Z')
1760 if (c != 'l' && c != 'u')
1762 if (c >= '0' && c <= '9')
1770 if (base > 10 && c >= 'a' && c <= 'f')
1774 n += i = c - 'a' + 10;
1787 return ERROR; /* Char not a digit */
1790 return ERROR; /* Invalid digit in this base */
1792 /* Portably test for overflow (only works for nonzero values, so make
1793 a second check for zero). FIXME: Can't we just make n and prevn
1794 unsigned and avoid this? */
1795 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1796 unsigned_p = 1; /* Try something unsigned */
1798 /* Portably test for unsigned overflow.
1799 FIXME: This check is wrong; for example it doesn't find overflow
1800 on 0x123456789 when LONGEST is 32 bits. */
1801 if (c != 'l' && c != 'u' && n != 0)
1803 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1804 error (_("Numeric constant too large."));
1809 /* An integer constant is an int, a long, or a long long. An L
1810 suffix forces it to be long; an LL suffix forces it to be long
1811 long. If not forced to a larger size, it gets the first type of
1812 the above that it fits in. To figure out whether it fits, we
1813 shift it right and see whether anything remains. Note that we
1814 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1815 operation, because many compilers will warn about such a shift
1816 (which always produces a zero result). Sometimes gdbarch_int_bit
1817 or gdbarch_long_bit will be that big, sometimes not. To deal with
1818 the case where it is we just always shift the value more than
1819 once, with fewer bits each time. */
1821 un = (ULONGEST)n >> 2;
1823 && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1825 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1827 /* A large decimal (not hex or octal) constant (between INT_MAX
1828 and UINT_MAX) is a long or unsigned long, according to ANSI,
1829 never an unsigned int, but this code treats it as unsigned
1830 int. This probably should be fixed. GCC gives a warning on
1833 unsigned_type = parse_type->builtin_unsigned_int;
1834 signed_type = parse_type->builtin_int;
1836 else if (long_p <= 1
1837 && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1839 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1840 unsigned_type = parse_type->builtin_unsigned_long;
1841 signed_type = parse_type->builtin_long;
1846 if (sizeof (ULONGEST) * HOST_CHAR_BIT
1847 < gdbarch_long_long_bit (parse_gdbarch))
1848 /* A long long does not fit in a LONGEST. */
1849 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1851 shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1852 high_bit = (ULONGEST) 1 << shift;
1853 unsigned_type = parse_type->builtin_unsigned_long_long;
1854 signed_type = parse_type->builtin_long_long;
1857 putithere->typed_val_int.val = n;
1859 /* If the high bit of the worked out type is set then this number
1860 has to be unsigned. */
1862 if (unsigned_p || (n & high_bit))
1864 putithere->typed_val_int.type = unsigned_type;
1868 putithere->typed_val_int.type = signed_type;
1874 /* Temporary obstack used for holding strings. */
1875 static struct obstack tempbuf;
1876 static int tempbuf_init;
1878 /* Parse a C escape sequence. The initial backslash of the sequence
1879 is at (*PTR)[-1]. *PTR will be updated to point to just after the
1880 last character of the sequence. If OUTPUT is not NULL, the
1881 translated form of the escape sequence will be written there. If
1882 OUTPUT is NULL, no output is written and the call will only affect
1883 *PTR. If an escape sequence is expressed in target bytes, then the
1884 entire sequence will simply be copied to OUTPUT. Return 1 if any
1885 character was emitted, 0 otherwise. */
1888 c_parse_escape (char **ptr, struct obstack *output)
1890 char *tokptr = *ptr;
1893 /* Some escape sequences undergo character set conversion. Those we
1897 /* Hex escapes do not undergo character set conversion, so keep
1898 the escape sequence for later. */
1901 obstack_grow_str (output, "\\x");
1903 if (!isxdigit (*tokptr))
1904 error (_("\\x escape without a following hex digit"));
1905 while (isxdigit (*tokptr))
1908 obstack_1grow (output, *tokptr);
1913 /* Octal escapes do not undergo character set conversion, so
1914 keep the escape sequence for later. */
1926 obstack_grow_str (output, "\\");
1928 i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
1932 obstack_1grow (output, *tokptr);
1938 /* We handle UCNs later. We could handle them here, but that
1939 would mean a spurious error in the case where the UCN could
1940 be converted to the target charset but not the host
1946 int i, len = c == 'U' ? 8 : 4;
1949 obstack_1grow (output, '\\');
1950 obstack_1grow (output, *tokptr);
1953 if (!isxdigit (*tokptr))
1954 error (_("\\%c escape without a following hex digit"), c);
1955 for (i = 0; i < len && isxdigit (*tokptr); ++i)
1958 obstack_1grow (output, *tokptr);
1964 /* We must pass backslash through so that it does not
1965 cause quoting during the second expansion. */
1968 obstack_grow_str (output, "\\\\");
1972 /* Escapes which undergo conversion. */
1975 obstack_1grow (output, '\a');
1980 obstack_1grow (output, '\b');
1985 obstack_1grow (output, '\f');
1990 obstack_1grow (output, '\n');
1995 obstack_1grow (output, '\r');
2000 obstack_1grow (output, '\t');
2005 obstack_1grow (output, '\v');
2009 /* GCC extension. */
2012 obstack_1grow (output, HOST_ESCAPE_CHAR);
2016 /* Backslash-newline expands to nothing at all. */
2022 /* A few escapes just expand to the character itself. */
2026 /* GCC extensions. */
2031 /* Unrecognized escapes turn into the character itself. */
2034 obstack_1grow (output, *tokptr);
2042 /* Parse a string or character literal from TOKPTR. The string or
2043 character may be wide or unicode. *OUTPTR is set to just after the
2044 end of the literal in the input string. The resulting token is
2045 stored in VALUE. This returns a token value, either STRING or
2046 CHAR, depending on what was parsed. *HOST_CHARS is set to the
2047 number of host characters in the literal. */
2049 parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
2053 enum c_string_type type;
2056 /* Build the gdb internal form of the input string in tempbuf. Note
2057 that the buffer is null byte terminated *only* for the
2058 convenience of debugging gdb itself and printing the buffer
2059 contents when the buffer contains no embedded nulls. Gdb does
2060 not depend upon the buffer being null byte terminated, it uses
2061 the length string instead. This allows gdb to handle C strings
2062 (as well as strings in other languages) with embedded null
2068 obstack_free (&tempbuf, NULL);
2069 obstack_init (&tempbuf);
2071 /* Record the string type. */
2074 type = C_WIDE_STRING;
2077 else if (*tokptr == 'u')
2082 else if (*tokptr == 'U')
2087 else if (*tokptr == '@')
2089 /* An Objective C string. */
2097 /* Skip the quote. */
2111 *host_chars += c_parse_escape (&tokptr, &tempbuf);
2113 else if (c == quote)
2117 obstack_1grow (&tempbuf, c);
2119 /* FIXME: this does the wrong thing with multi-byte host
2120 characters. We could use mbrlen here, but that would
2121 make "set host-charset" a bit less useful. */
2126 if (*tokptr != quote)
2129 error (_("Unterminated string in expression."));
2131 error (_("Unmatched single quote."));
2136 value->ptr = obstack_base (&tempbuf);
2137 value->length = obstack_object_size (&tempbuf);
2141 return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
2144 /* This is used to associate some attributes with a token. */
2148 /* If this bit is set, the token is C++-only. */
2152 /* If this bit is set, the token is conditional: if there is a
2153 symbol of the same name, then the token is a symbol; otherwise,
2154 the token is a keyword. */
2163 enum exp_opcode opcode;
2164 enum token_flags flags;
2167 static const struct token tokentab3[] =
2169 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
2170 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
2171 {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
2172 {"...", DOTDOTDOT, BINOP_END, 0}
2175 static const struct token tokentab2[] =
2177 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
2178 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
2179 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
2180 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
2181 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
2182 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
2183 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
2184 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
2185 {"++", INCREMENT, BINOP_END, 0},
2186 {"--", DECREMENT, BINOP_END, 0},
2187 {"->", ARROW, BINOP_END, 0},
2188 {"&&", ANDAND, BINOP_END, 0},
2189 {"||", OROR, BINOP_END, 0},
2190 /* "::" is *not* only C++: gdb overrides its meaning in several
2191 different ways, e.g., 'filename'::func, function::variable. */
2192 {"::", COLONCOLON, BINOP_END, 0},
2193 {"<<", LSH, BINOP_END, 0},
2194 {">>", RSH, BINOP_END, 0},
2195 {"==", EQUAL, BINOP_END, 0},
2196 {"!=", NOTEQUAL, BINOP_END, 0},
2197 {"<=", LEQ, BINOP_END, 0},
2198 {">=", GEQ, BINOP_END, 0},
2199 {".*", DOT_STAR, BINOP_END, FLAG_CXX}
2202 /* Identifier-like tokens. */
2203 static const struct token ident_tokens[] =
2205 {"unsigned", UNSIGNED, OP_NULL, 0},
2206 {"template", TEMPLATE, OP_NULL, FLAG_CXX},
2207 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
2208 {"struct", STRUCT, OP_NULL, 0},
2209 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
2210 {"sizeof", SIZEOF, OP_NULL, 0},
2211 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
2212 {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2213 {"class", CLASS, OP_NULL, FLAG_CXX},
2214 {"union", UNION, OP_NULL, 0},
2215 {"short", SHORT, OP_NULL, 0},
2216 {"const", CONST_KEYWORD, OP_NULL, 0},
2217 {"enum", ENUM, OP_NULL, 0},
2218 {"long", LONG, OP_NULL, 0},
2219 {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
2220 {"int", INT_KEYWORD, OP_NULL, 0},
2221 {"new", NEW, OP_NULL, FLAG_CXX},
2222 {"delete", DELETE, OP_NULL, FLAG_CXX},
2223 {"operator", OPERATOR, OP_NULL, FLAG_CXX},
2225 {"and", ANDAND, BINOP_END, FLAG_CXX},
2226 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2227 {"bitand", '&', OP_NULL, FLAG_CXX},
2228 {"bitor", '|', OP_NULL, FLAG_CXX},
2229 {"compl", '~', OP_NULL, FLAG_CXX},
2230 {"not", '!', OP_NULL, FLAG_CXX},
2231 {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2232 {"or", OROR, BINOP_END, FLAG_CXX},
2233 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2234 {"xor", '^', OP_NULL, FLAG_CXX},
2235 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2237 {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2238 {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2239 {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
2240 {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },
2242 {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
2243 {"__typeof", TYPEOF, OP_TYPEOF, 0 },
2244 {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
2245 {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
2246 {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }
2249 /* When we find that lexptr (the global var defined in parse.c) is
2250 pointing at a macro invocation, we expand the invocation, and call
2251 scan_macro_expansion to save the old lexptr here and point lexptr
2252 into the expanded text. When we reach the end of that, we call
2253 end_macro_expansion to pop back to the value we saved here. The
2254 macro expansion code promises to return only fully-expanded text,
2255 so we don't need to "push" more than one level.
2257 This is disgusting, of course. It would be cleaner to do all macro
2258 expansion beforehand, and then hand that to lexptr. But we don't
2259 really know where the expression ends. Remember, in a command like
2261 (gdb) break *ADDRESS if CONDITION
2263 we evaluate ADDRESS in the scope of the current frame, but we
2264 evaluate CONDITION in the scope of the breakpoint's location. So
2265 it's simply wrong to try to macro-expand the whole thing at once. */
2266 static char *macro_original_text;
2268 /* We save all intermediate macro expansions on this obstack for the
2269 duration of a single parse. The expansion text may sometimes have
2270 to live past the end of the expansion, due to yacc lookahead.
2271 Rather than try to be clever about saving the data for a single
2272 token, we simply keep it all and delete it after parsing has
2274 static struct obstack expansion_obstack;
2277 scan_macro_expansion (char *expansion)
2281 /* We'd better not be trying to push the stack twice. */
2282 gdb_assert (! macro_original_text);
2284 /* Copy to the obstack, and then free the intermediate
2286 copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
2289 /* Save the old lexptr value, so we can return to it when we're done
2290 parsing the expanded text. */
2291 macro_original_text = lexptr;
2297 scanning_macro_expansion (void)
2299 return macro_original_text != 0;
2304 finished_macro_expansion (void)
2306 /* There'd better be something to pop back to. */
2307 gdb_assert (macro_original_text);
2309 /* Pop back to the original text. */
2310 lexptr = macro_original_text;
2311 macro_original_text = 0;
2316 scan_macro_cleanup (void *dummy)
2318 if (macro_original_text)
2319 finished_macro_expansion ();
2321 obstack_free (&expansion_obstack, NULL);
2324 /* Return true iff the token represents a C++ cast operator. */
2327 is_cast_operator (const char *token, int len)
2329 return (! strncmp (token, "dynamic_cast", len)
2330 || ! strncmp (token, "static_cast", len)
2331 || ! strncmp (token, "reinterpret_cast", len)
2332 || ! strncmp (token, "const_cast", len));
2335 /* The scope used for macro expansion. */
2336 static struct macro_scope *expression_macro_scope;
2338 /* This is set if a NAME token appeared at the very end of the input
2339 string, with no whitespace separating the name from the EOF. This
2340 is used only when parsing to do field name completion. */
2341 static int saw_name_at_eof;
2343 /* This is set if the previously-returned token was a structure
2344 operator -- either '.' or ARROW. This is used only when parsing to
2345 do field name completion. */
2346 static int last_was_structop;
2348 /* Read one token, getting characters through lexptr. */
2351 lex_one_token (void)
2357 int saw_structop = last_was_structop;
2360 last_was_structop = 0;
2364 /* Check if this is a macro invocation that we need to expand. */
2365 if (! scanning_macro_expansion ())
2367 char *expanded = macro_expand_next (&lexptr,
2368 standard_macro_lookup,
2369 expression_macro_scope);
2372 scan_macro_expansion (expanded);
2375 prev_lexptr = lexptr;
2378 /* See if it is a special token of length 3. */
2379 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
2380 if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
2382 if ((tokentab3[i].flags & FLAG_CXX) != 0
2383 && parse_language->la_language != language_cplus)
2387 yylval.opcode = tokentab3[i].opcode;
2388 return tokentab3[i].token;
2391 /* See if it is a special token of length 2. */
2392 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
2393 if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
2395 if ((tokentab2[i].flags & FLAG_CXX) != 0
2396 && parse_language->la_language != language_cplus)
2400 yylval.opcode = tokentab2[i].opcode;
2401 if (parse_completion && tokentab2[i].token == ARROW)
2402 last_was_structop = 1;
2403 return tokentab2[i].token;
2406 switch (c = *tokstart)
2409 /* If we were just scanning the result of a macro expansion,
2410 then we need to resume scanning the original text.
2411 If we're parsing for field name completion, and the previous
2412 token allows such completion, return a COMPLETE token.
2413 Otherwise, we were already scanning the original text, and
2414 we're really done. */
2415 if (scanning_macro_expansion ())
2417 finished_macro_expansion ();
2420 else if (saw_name_at_eof)
2422 saw_name_at_eof = 0;
2425 else if (saw_structop)
2440 if (parse_language->la_language == language_objc && c == '[')
2446 if (paren_depth == 0)
2453 if (comma_terminates
2455 && ! scanning_macro_expansion ())
2461 /* Might be a floating point number. */
2462 if (lexptr[1] < '0' || lexptr[1] > '9')
2464 if (parse_completion)
2465 last_was_structop = 1;
2466 goto symbol; /* Nope, must be a symbol. */
2468 /* FALL THRU into number case. */
2481 /* It's a number. */
2482 int got_dot = 0, got_e = 0, toktype;
2484 int hex = input_radix > 10;
2486 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2491 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2499 /* This test includes !hex because 'e' is a valid hex digit
2500 and thus does not indicate a floating point number when
2501 the radix is hex. */
2502 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2503 got_dot = got_e = 1;
2504 /* This test does not include !hex, because a '.' always indicates
2505 a decimal floating point number regardless of the radix. */
2506 else if (!got_dot && *p == '.')
2508 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2509 && (*p == '-' || *p == '+'))
2510 /* This is the sign of the exponent, not the end of the
2513 /* We will take any letters or digits. parse_number will
2514 complain if past the radix, or if L or U are not final. */
2515 else if ((*p < '0' || *p > '9')
2516 && ((*p < 'a' || *p > 'z')
2517 && (*p < 'A' || *p > 'Z')))
2520 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
2521 if (toktype == ERROR)
2523 char *err_copy = (char *) alloca (p - tokstart + 1);
2525 memcpy (err_copy, tokstart, p - tokstart);
2526 err_copy[p - tokstart] = 0;
2527 error (_("Invalid number \"%s\"."), err_copy);
2535 char *p = &tokstart[1];
2536 size_t len = strlen ("entry");
2538 if (parse_language->la_language == language_objc)
2540 size_t len = strlen ("selector");
2542 if (strncmp (p, "selector", len) == 0
2543 && (p[len] == '\0' || isspace (p[len])))
2552 while (isspace (*p))
2554 if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2586 if (tokstart[1] != '"' && tokstart[1] != '\'')
2595 int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
2600 error (_("Empty character constant."));
2601 else if (host_len > 2 && c == '\'')
2604 namelen = lexptr - tokstart - 1;
2607 else if (host_len > 1)
2608 error (_("Invalid character constant."));
2614 if (!(c == '_' || c == '$'
2615 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2616 /* We must have come across a bad character (e.g. ';'). */
2617 error (_("Invalid character '%c' in expression."), c);
2619 /* It's a name. See how long it is. */
2621 for (c = tokstart[namelen];
2622 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2623 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2625 /* Template parameter lists are part of the name.
2626 FIXME: This mishandles `print $a<4&&$a>3'. */
2630 if (! is_cast_operator (tokstart, namelen))
2632 /* Scan ahead to get rest of the template specification. Note
2633 that we look ahead only when the '<' adjoins non-whitespace
2634 characters; for comparison expressions, e.g. "a < b > c",
2635 there must be spaces before the '<', etc. */
2637 char * p = find_template_name_end (tokstart + namelen);
2639 namelen = p - tokstart;
2643 c = tokstart[++namelen];
2646 /* The token "if" terminates the expression and is NOT removed from
2647 the input stream. It doesn't count if it appears in the
2648 expansion of a macro. */
2650 && tokstart[0] == 'i'
2651 && tokstart[1] == 'f'
2652 && ! scanning_macro_expansion ())
2657 /* For the same reason (breakpoint conditions), "thread N"
2658 terminates the expression. "thread" could be an identifier, but
2659 an identifier is never followed by a number without intervening
2660 punctuation. "task" is similar. Handle abbreviations of these,
2661 similarly to breakpoint.c:find_condition_and_thread. */
2663 && (strncmp (tokstart, "thread", namelen) == 0
2664 || strncmp (tokstart, "task", namelen) == 0)
2665 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2666 && ! scanning_macro_expansion ())
2668 char *p = tokstart + namelen + 1;
2669 while (*p == ' ' || *p == '\t')
2671 if (*p >= '0' && *p <= '9')
2679 yylval.sval.ptr = tokstart;
2680 yylval.sval.length = namelen;
2682 /* Catch specific keywords. */
2683 copy = copy_name (yylval.sval);
2684 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
2685 if (strcmp (copy, ident_tokens[i].operator) == 0)
2687 if ((ident_tokens[i].flags & FLAG_CXX) != 0
2688 && parse_language->la_language != language_cplus)
2691 if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2693 int is_a_field_of_this = 0;
2695 if (lookup_symbol (copy, expression_context_block,
2697 (parse_language->la_language == language_cplus
2698 ? &is_a_field_of_this
2702 /* The keyword is shadowed. */
2707 /* It is ok to always set this, even though we don't always
2708 strictly need to. */
2709 yylval.opcode = ident_tokens[i].opcode;
2710 return ident_tokens[i].token;
2713 if (*tokstart == '$')
2716 if (parse_completion && *lexptr == '\0')
2717 saw_name_at_eof = 1;
2721 /* An object of this type is pushed on a FIFO by the "outer" lexer. */
2728 DEF_VEC_O (token_and_value);
2730 /* A FIFO of tokens that have been read but not yet returned to the
2732 static VEC (token_and_value) *token_fifo;
2734 /* Non-zero if the lexer should return tokens from the FIFO. */
2737 /* Temporary storage for c_lex; this holds symbol names as they are
2739 static struct obstack name_obstack;
2741 /* Classify a NAME token. The contents of the token are in `yylval'.
2742 Updates yylval and returns the new token type. BLOCK is the block
2743 in which lookups start; this can be NULL to mean the global
2746 classify_name (const struct block *block)
2750 int is_a_field_of_this = 0;
2752 copy = copy_name (yylval.sval);
2754 sym = lookup_symbol (copy, block, VAR_DOMAIN,
2755 parse_language->la_name_of_this
2756 ? &is_a_field_of_this : (int *) NULL);
2758 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2760 yylval.ssym.sym = sym;
2761 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2766 /* See if it's a file name. */
2767 struct symtab *symtab;
2769 symtab = lookup_symtab (copy);
2772 yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
2777 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2779 yylval.tsym.type = SYMBOL_TYPE (sym);
2784 = language_lookup_primitive_type_by_name (parse_language,
2785 parse_gdbarch, copy);
2786 if (yylval.tsym.type != NULL)
2789 /* See if it's an ObjC classname. */
2790 if (parse_language->la_language == language_objc && !sym)
2792 CORE_ADDR Class = lookup_objc_class (parse_gdbarch, copy);
2795 yylval.class.class = Class;
2796 sym = lookup_struct_typedef (copy, expression_context_block, 1);
2798 yylval.class.type = SYMBOL_TYPE (sym);
2803 /* Input names that aren't symbols but ARE valid hex numbers, when
2804 the input radix permits them, can be names or numbers depending
2805 on the parse. Note we support radixes > 16 here. */
2807 && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
2808 || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
2810 YYSTYPE newlval; /* Its value is ignored. */
2811 int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
2814 yylval.ssym.sym = sym;
2815 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2820 /* Any other kind of symbol */
2821 yylval.ssym.sym = sym;
2822 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2825 && parse_language->la_language == language_cplus
2826 && !is_a_field_of_this
2827 && !lookup_minimal_symbol (copy, NULL, NULL))
2828 return UNKNOWN_CPP_NAME;
2833 /* Like classify_name, but used by the inner loop of the lexer, when a
2834 name might have already been seen. FIRST_NAME is true if the token
2835 in `yylval' is the first component of a name, false otherwise. */
2838 classify_inner_name (const struct block *block, int first_name)
2840 struct type *type, *new_type;
2844 return classify_name (block);
2846 type = check_typedef (yylval.tsym.type);
2847 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2848 && TYPE_CODE (type) != TYPE_CODE_UNION
2849 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2852 copy = copy_name (yylval.tsym.stoken);
2853 yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
2854 if (yylval.ssym.sym == NULL)
2857 switch (SYMBOL_CLASS (yylval.ssym.sym))
2864 yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
2868 yylval.ssym.is_a_field_of_this = 0;
2871 internal_error (__FILE__, __LINE__, _("not reached"));
2874 /* The outer level of a two-level lexer. This calls the inner lexer
2875 to return tokens. It then either returns these tokens, or
2876 aggregates them into a larger token. This lets us work around a
2877 problem in our parsing approach, where the parser could not
2878 distinguish between qualified names and qualified types at the
2881 This approach is still not ideal, because it mishandles template
2882 types. See the comment in lex_one_token for an example. However,
2883 this is still an improvement over the earlier approach, and will
2884 suffice until we move to better parsing technology. */
2888 token_and_value current;
2889 int first_was_coloncolon, last_was_coloncolon, first_iter;
2891 if (popping && !VEC_empty (token_and_value, token_fifo))
2893 token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
2894 VEC_ordered_remove (token_and_value, token_fifo, 0);
2900 current.token = lex_one_token ();
2901 if (current.token == NAME)
2902 current.token = classify_name (expression_context_block);
2903 if (parse_language->la_language != language_cplus
2904 || (current.token != TYPENAME && current.token != COLONCOLON))
2905 return current.token;
2907 first_was_coloncolon = current.token == COLONCOLON;
2908 last_was_coloncolon = first_was_coloncolon;
2909 obstack_free (&name_obstack, obstack_base (&name_obstack));
2910 if (!last_was_coloncolon)
2911 obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2912 current.value = yylval;
2916 token_and_value next;
2918 next.token = lex_one_token ();
2919 next.value = yylval;
2921 if (next.token == NAME && last_was_coloncolon)
2925 classification = classify_inner_name (first_was_coloncolon
2927 : expression_context_block,
2929 /* We keep going until we either run out of names, or until
2930 we have a qualified name which is not a type. */
2931 if (classification != TYPENAME && classification != NAME)
2933 /* Push the final component and leave the loop. */
2934 VEC_safe_push (token_and_value, token_fifo, &next);
2938 /* Update the partial name we are constructing. */
2941 /* We don't want to put a leading "::" into the name. */
2942 obstack_grow_str (&name_obstack, "::");
2944 obstack_grow (&name_obstack, next.value.sval.ptr,
2945 next.value.sval.length);
2947 yylval.sval.ptr = obstack_base (&name_obstack);
2948 yylval.sval.length = obstack_object_size (&name_obstack);
2949 current.value = yylval;
2950 current.token = classification;
2952 last_was_coloncolon = 0;
2954 else if (next.token == COLONCOLON && !last_was_coloncolon)
2955 last_was_coloncolon = 1;
2958 /* We've reached the end of the name. */
2959 VEC_safe_push (token_and_value, token_fifo, &next);
2968 /* If we ended with a "::", insert it too. */
2969 if (last_was_coloncolon)
2972 memset (&cc, 0, sizeof (token_and_value));
2973 if (first_was_coloncolon && first_iter)
2978 cc.token = COLONCOLON;
2979 VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
2982 yylval = current.value;
2983 yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
2985 yylval.sval.length);
2986 return current.token;
2993 struct cleanup *back_to = make_cleanup (free_current_contents,
2994 &expression_macro_scope);
2996 /* Set up the scope for macro expansion. */
2997 expression_macro_scope = NULL;
2999 if (expression_context_block)
3000 expression_macro_scope
3001 = sal_macro_scope (find_pc_line (expression_context_pc, 0));
3003 expression_macro_scope = default_macro_scope ();
3004 if (! expression_macro_scope)
3005 expression_macro_scope = user_macro_scope ();
3007 /* Initialize macro expansion code. */
3008 obstack_init (&expansion_obstack);
3009 gdb_assert (! macro_original_text);
3010 make_cleanup (scan_macro_cleanup, 0);
3012 make_cleanup_restore_integer (&yydebug);
3013 yydebug = parser_debug;
3015 /* Initialize some state used by the lexer. */
3016 last_was_structop = 0;
3017 saw_name_at_eof = 0;
3019 VEC_free (token_and_value, token_fifo);
3021 obstack_init (&name_obstack);
3022 make_cleanup_obstack_free (&name_obstack);
3024 result = yyparse ();
3025 do_cleanups (back_to);
3034 lexptr = prev_lexptr;
3036 error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);