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"
60 #define parse_type builtin_type (parse_gdbarch)
62 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
63 as well as gratuitiously global symbol names, so we can have multiple
64 yacc generated parsers in gdb. Note that these are only the variables
65 produced by yacc. If other parser generators (bison, byacc, etc) produce
66 additional global names that conflict at link time, then those parser
67 generators need to be fixed instead of adding those names to this list. */
69 #define yymaxdepth c_maxdepth
70 #define yyparse c_parse_internal
72 #define yyerror c_error
75 #define yydebug c_debug
84 #define yyerrflag c_errflag
85 #define yynerrs c_nerrs
90 #define yystate c_state
96 #define yyreds c_reds /* With YYDEBUG defined */
97 #define yytoks c_toks /* With YYDEBUG defined */
98 #define yyname c_name /* With YYDEBUG defined */
99 #define yyrule c_rule /* With YYDEBUG defined */
100 #define yylhs c_yylhs
101 #define yylen c_yylen
102 #define yydefred c_yydefred
103 #define yydgoto c_yydgoto
104 #define yysindex c_yysindex
105 #define yyrindex c_yyrindex
106 #define yygindex c_yygindex
107 #define yytable c_yytable
108 #define yycheck c_yycheck
110 #define yysslim c_yysslim
111 #define yyssp c_yyssp
112 #define yystacksize c_yystacksize
114 #define yyvsp c_yyvsp
117 #define YYDEBUG 1 /* Default to yydebug support */
120 #define YYFPRINTF parser_fprintf
124 static int yylex (void);
126 void yyerror (char *);
130 /* Although the yacc "value" of an expression is not used,
131 since the result is stored in the structure being created,
132 other node types do have values. */
148 } typed_val_decfloat;
152 struct typed_stoken tsval;
154 struct symtoken ssym;
157 enum exp_opcode opcode;
158 struct internalvar *ivar;
160 struct stoken_vector svec;
161 VEC (type_ptr) *tvec;
164 struct type_stack *type_stack;
166 struct objc_class_str class;
170 /* YYSTYPE gets defined by %union */
171 static int parse_number (char *, int, int, YYSTYPE *);
172 static struct stoken operator_stoken (const char *);
173 static void check_parameter_typelist (VEC (type_ptr) *);
176 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
178 %type <tval> type typebase
179 %type <tvec> nonempty_typelist func_mod parameter_typelist
180 /* %type <bval> block */
182 /* Fancy type parsing. */
184 %type <lval> array_mod
185 %type <tval> conversion_type_id
187 %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
189 %token <typed_val_int> INT
190 %token <typed_val_float> FLOAT
191 %token <typed_val_decfloat> DECFLOAT
193 /* Both NAME and TYPENAME tokens represent symbols in the input,
194 and both convey their data as strings.
195 But a TYPENAME is a string that happens to be defined as a typedef
196 or builtin type name (such as int or char)
197 and a NAME is any other symbol.
198 Contexts where this distinction is not important can use the
199 nonterminal "name", which matches either NAME or TYPENAME. */
201 %token <tsval> STRING
202 %token <sval> NSSTRING /* ObjC Foundation "NSString" literal */
203 %token SELECTOR /* ObjC "@selector" pseudo-operator */
205 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
206 %token <ssym> UNKNOWN_CPP_NAME
207 %token <voidval> COMPLETE
208 %token <tsym> TYPENAME
209 %token <class> CLASSNAME /* ObjC Class name */
211 %type <svec> string_exp
212 %type <ssym> name_not_typename
213 %type <tsym> typename
215 /* This is like a '[' token, but is only generated when parsing
216 Objective C. This lets us reuse the same parser without
217 erroneously parsing ObjC-specific expressions in C. */
220 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
221 but which would parse as a valid number in the current input radix.
222 E.g. "c" when input_radix==16. Depending on the parse, it will be
223 turned into a name or into a number. */
225 %token <ssym> NAME_OR_INT
228 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
232 %type <sval> operator
233 %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
238 /* Special type cases, put in to allow the parser to distinguish different
240 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
242 %token <sval> VARIABLE
244 %token <opcode> ASSIGN_MODIFY
253 %right '=' ASSIGN_MODIFY
261 %left '<' '>' LEQ GEQ
266 %right UNARY INCREMENT DECREMENT
267 %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
268 %token <ssym> BLOCKNAME
269 %token <bval> FILENAME
283 { write_exp_elt_opcode(OP_TYPE);
284 write_exp_elt_type($1);
285 write_exp_elt_opcode(OP_TYPE);}
288 write_exp_elt_opcode (OP_TYPEOF);
290 | TYPEOF '(' type ')'
292 write_exp_elt_opcode (OP_TYPE);
293 write_exp_elt_type ($3);
294 write_exp_elt_opcode (OP_TYPE);
296 | DECLTYPE '(' exp ')'
298 write_exp_elt_opcode (OP_DECLTYPE);
302 /* Expressions, including the comma operator. */
305 { write_exp_elt_opcode (BINOP_COMMA); }
308 /* Expressions, not including the comma operator. */
309 exp : '*' exp %prec UNARY
310 { write_exp_elt_opcode (UNOP_IND); }
313 exp : '&' exp %prec UNARY
314 { write_exp_elt_opcode (UNOP_ADDR); }
317 exp : '-' exp %prec UNARY
318 { write_exp_elt_opcode (UNOP_NEG); }
321 exp : '+' exp %prec UNARY
322 { write_exp_elt_opcode (UNOP_PLUS); }
325 exp : '!' exp %prec UNARY
326 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
329 exp : '~' exp %prec UNARY
330 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
333 exp : INCREMENT exp %prec UNARY
334 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
337 exp : DECREMENT exp %prec UNARY
338 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
341 exp : exp INCREMENT %prec UNARY
342 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
345 exp : exp DECREMENT %prec UNARY
346 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
349 exp : SIZEOF exp %prec UNARY
350 { write_exp_elt_opcode (UNOP_SIZEOF); }
354 { write_exp_elt_opcode (STRUCTOP_PTR);
355 write_exp_string ($3);
356 write_exp_elt_opcode (STRUCTOP_PTR); }
359 exp : exp ARROW name COMPLETE
360 { mark_struct_expression ();
361 write_exp_elt_opcode (STRUCTOP_PTR);
362 write_exp_string ($3);
363 write_exp_elt_opcode (STRUCTOP_PTR); }
366 exp : exp ARROW COMPLETE
368 mark_struct_expression ();
369 write_exp_elt_opcode (STRUCTOP_PTR);
372 write_exp_string (s);
373 write_exp_elt_opcode (STRUCTOP_PTR); }
376 exp : exp ARROW qualified_name
377 { /* exp->type::name becomes exp->*(&type::name) */
378 /* Note: this doesn't work if name is a
379 static member! FIXME */
380 write_exp_elt_opcode (UNOP_ADDR);
381 write_exp_elt_opcode (STRUCTOP_MPTR); }
384 exp : exp ARROW_STAR exp
385 { write_exp_elt_opcode (STRUCTOP_MPTR); }
389 { write_exp_elt_opcode (STRUCTOP_STRUCT);
390 write_exp_string ($3);
391 write_exp_elt_opcode (STRUCTOP_STRUCT); }
394 exp : exp '.' name COMPLETE
395 { mark_struct_expression ();
396 write_exp_elt_opcode (STRUCTOP_STRUCT);
397 write_exp_string ($3);
398 write_exp_elt_opcode (STRUCTOP_STRUCT); }
401 exp : exp '.' COMPLETE
403 mark_struct_expression ();
404 write_exp_elt_opcode (STRUCTOP_STRUCT);
407 write_exp_string (s);
408 write_exp_elt_opcode (STRUCTOP_STRUCT); }
411 exp : exp '.' qualified_name
412 { /* exp.type::name becomes exp.*(&type::name) */
413 /* Note: this doesn't work if name is a
414 static member! FIXME */
415 write_exp_elt_opcode (UNOP_ADDR);
416 write_exp_elt_opcode (STRUCTOP_MEMBER); }
419 exp : exp DOT_STAR exp
420 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
423 exp : exp '[' exp1 ']'
424 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
427 exp : exp OBJC_LBRAC exp1 ']'
428 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
432 * The rules below parse ObjC message calls of the form:
433 * '[' target selector {':' argument}* ']'
436 exp : OBJC_LBRAC TYPENAME
440 class = lookup_objc_class (parse_gdbarch,
441 copy_name ($2.stoken));
443 error (_("%s is not an ObjC Class"),
444 copy_name ($2.stoken));
445 write_exp_elt_opcode (OP_LONG);
446 write_exp_elt_type (parse_type->builtin_int);
447 write_exp_elt_longcst ((LONGEST) class);
448 write_exp_elt_opcode (OP_LONG);
452 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
454 write_exp_elt_opcode (OP_OBJC_MSGCALL);
458 exp : OBJC_LBRAC CLASSNAME
460 write_exp_elt_opcode (OP_LONG);
461 write_exp_elt_type (parse_type->builtin_int);
462 write_exp_elt_longcst ((LONGEST) $2.class);
463 write_exp_elt_opcode (OP_LONG);
467 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
469 write_exp_elt_opcode (OP_OBJC_MSGCALL);
476 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
478 write_exp_elt_opcode (OP_OBJC_MSGCALL);
483 { add_msglist(&$1, 0); }
491 msgarg : name ':' exp
492 { add_msglist(&$1, 1); }
493 | ':' exp /* Unnamed arg. */
494 { add_msglist(0, 1); }
495 | ',' exp /* Variable number of args. */
496 { add_msglist(0, 0); }
500 /* This is to save the value of arglist_len
501 being accumulated by an outer function call. */
502 { start_arglist (); }
503 arglist ')' %prec ARROW
504 { write_exp_elt_opcode (OP_FUNCALL);
505 write_exp_elt_longcst ((LONGEST) end_arglist ());
506 write_exp_elt_opcode (OP_FUNCALL); }
509 exp : UNKNOWN_CPP_NAME '('
511 /* This could potentially be a an argument defined
512 lookup function (Koenig). */
513 write_exp_elt_opcode (OP_ADL_FUNC);
514 write_exp_elt_block (expression_context_block);
515 write_exp_elt_sym (NULL); /* Placeholder. */
516 write_exp_string ($1.stoken);
517 write_exp_elt_opcode (OP_ADL_FUNC);
519 /* This is to save the value of arglist_len
520 being accumulated by an outer function call. */
524 arglist ')' %prec ARROW
526 write_exp_elt_opcode (OP_FUNCALL);
527 write_exp_elt_longcst ((LONGEST) end_arglist ());
528 write_exp_elt_opcode (OP_FUNCALL);
533 { start_arglist (); }
543 arglist : arglist ',' exp %prec ABOVE_COMMA
547 exp : exp '(' parameter_typelist ')' const_or_volatile
549 VEC (type_ptr) *type_list = $3;
550 struct type *type_elt;
551 LONGEST len = VEC_length (type_ptr, type_list);
553 write_exp_elt_opcode (TYPE_INSTANCE);
554 write_exp_elt_longcst (len);
556 VEC_iterate (type_ptr, type_list, i, type_elt);
558 write_exp_elt_type (type_elt);
559 write_exp_elt_longcst(len);
560 write_exp_elt_opcode (TYPE_INSTANCE);
561 VEC_free (type_ptr, type_list);
566 { $$ = end_arglist () - 1; }
568 exp : lcurly arglist rcurly %prec ARROW
569 { write_exp_elt_opcode (OP_ARRAY);
570 write_exp_elt_longcst ((LONGEST) 0);
571 write_exp_elt_longcst ((LONGEST) $3);
572 write_exp_elt_opcode (OP_ARRAY); }
575 exp : lcurly type_exp rcurly exp %prec UNARY
576 { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); }
579 exp : '(' type_exp ')' exp %prec UNARY
580 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
587 /* Binary operators in order of decreasing precedence. */
590 { write_exp_elt_opcode (BINOP_REPEAT); }
594 { write_exp_elt_opcode (BINOP_MUL); }
598 { write_exp_elt_opcode (BINOP_DIV); }
602 { write_exp_elt_opcode (BINOP_REM); }
606 { write_exp_elt_opcode (BINOP_ADD); }
610 { write_exp_elt_opcode (BINOP_SUB); }
614 { write_exp_elt_opcode (BINOP_LSH); }
618 { write_exp_elt_opcode (BINOP_RSH); }
622 { write_exp_elt_opcode (BINOP_EQUAL); }
625 exp : exp NOTEQUAL exp
626 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
630 { write_exp_elt_opcode (BINOP_LEQ); }
634 { write_exp_elt_opcode (BINOP_GEQ); }
638 { write_exp_elt_opcode (BINOP_LESS); }
642 { write_exp_elt_opcode (BINOP_GTR); }
646 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
650 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
654 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
658 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
662 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
665 exp : exp '?' exp ':' exp %prec '?'
666 { write_exp_elt_opcode (TERNOP_COND); }
670 { write_exp_elt_opcode (BINOP_ASSIGN); }
673 exp : exp ASSIGN_MODIFY exp
674 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
675 write_exp_elt_opcode ($2);
676 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
680 { write_exp_elt_opcode (OP_LONG);
681 write_exp_elt_type ($1.type);
682 write_exp_elt_longcst ((LONGEST)($1.val));
683 write_exp_elt_opcode (OP_LONG); }
688 struct stoken_vector vec;
691 write_exp_string_vector ($1.type, &vec);
697 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
698 write_exp_elt_opcode (OP_LONG);
699 write_exp_elt_type (val.typed_val_int.type);
700 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
701 write_exp_elt_opcode (OP_LONG);
707 { write_exp_elt_opcode (OP_DOUBLE);
708 write_exp_elt_type ($1.type);
709 write_exp_elt_dblcst ($1.dval);
710 write_exp_elt_opcode (OP_DOUBLE); }
714 { write_exp_elt_opcode (OP_DECFLOAT);
715 write_exp_elt_type ($1.type);
716 write_exp_elt_decfloatcst ($1.val);
717 write_exp_elt_opcode (OP_DECFLOAT); }
725 write_dollar_variable ($1);
729 exp : SELECTOR '(' name ')'
731 write_exp_elt_opcode (OP_OBJC_SELECTOR);
732 write_exp_string ($3);
733 write_exp_elt_opcode (OP_OBJC_SELECTOR); }
736 exp : SIZEOF '(' type ')' %prec UNARY
737 { write_exp_elt_opcode (OP_LONG);
738 write_exp_elt_type (lookup_signed_typename
739 (parse_language, parse_gdbarch,
742 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
743 write_exp_elt_opcode (OP_LONG); }
746 exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
747 { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
750 exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
751 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
754 exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
755 { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
758 exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
759 { /* We could do more error checking here, but
760 it doesn't seem worthwhile. */
761 write_exp_elt_opcode (UNOP_CAST_TYPE); }
767 /* We copy the string here, and not in the
768 lexer, to guarantee that we do not leak a
769 string. Note that we follow the
770 NUL-termination convention of the
772 struct typed_stoken *vec = XNEW (struct typed_stoken);
777 vec->length = $1.length;
778 vec->ptr = malloc ($1.length + 1);
779 memcpy (vec->ptr, $1.ptr, $1.length + 1);
784 /* Note that we NUL-terminate here, but just
788 $$.tokens = realloc ($$.tokens,
789 $$.len * sizeof (struct typed_stoken));
791 p = malloc ($2.length + 1);
792 memcpy (p, $2.ptr, $2.length + 1);
794 $$.tokens[$$.len - 1].type = $2.type;
795 $$.tokens[$$.len - 1].length = $2.length;
796 $$.tokens[$$.len - 1].ptr = p;
803 enum c_string_type type = C_STRING;
805 for (i = 0; i < $1.len; ++i)
807 switch ($1.tokens[i].type)
815 && type != $1.tokens[i].type)
816 error (_("Undefined string concatenation."));
817 type = $1.tokens[i].type;
821 internal_error (__FILE__, __LINE__,
822 "unrecognized type in string concatenation");
826 write_exp_string_vector (type, &$1);
827 for (i = 0; i < $1.len; ++i)
828 free ($1.tokens[i].ptr);
833 exp : NSSTRING /* ObjC NextStep NSString constant
834 * of the form '@' '"' string '"'.
836 { write_exp_elt_opcode (OP_OBJC_NSSTRING);
837 write_exp_string ($1);
838 write_exp_elt_opcode (OP_OBJC_NSSTRING); }
843 { write_exp_elt_opcode (OP_LONG);
844 write_exp_elt_type (parse_type->builtin_bool);
845 write_exp_elt_longcst ((LONGEST) 1);
846 write_exp_elt_opcode (OP_LONG); }
850 { write_exp_elt_opcode (OP_LONG);
851 write_exp_elt_type (parse_type->builtin_bool);
852 write_exp_elt_longcst ((LONGEST) 0);
853 write_exp_elt_opcode (OP_LONG); }
861 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
863 error (_("No file or function \"%s\"."),
864 copy_name ($1.stoken));
872 block : block COLONCOLON name
874 = lookup_symbol (copy_name ($3), $1,
876 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
877 error (_("No function \"%s\" in specified context."),
879 $$ = SYMBOL_BLOCK_VALUE (tem); }
882 variable: name_not_typename ENTRY
883 { struct symbol *sym = $1.sym;
885 if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
886 || !symbol_read_needs_frame (sym))
887 error (_("@entry can be used only for function "
888 "parameters, not for \"%s\""),
889 copy_name ($1.stoken));
891 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
892 write_exp_elt_sym (sym);
893 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
897 variable: block COLONCOLON name
898 { struct symbol *sym;
899 sym = lookup_symbol (copy_name ($3), $1,
902 error (_("No symbol \"%s\" in specified context."),
904 if (symbol_read_needs_frame (sym))
906 if (innermost_block == 0
907 || contained_in (block_found,
909 innermost_block = block_found;
912 write_exp_elt_opcode (OP_VAR_VALUE);
913 /* block_found is set by lookup_symbol. */
914 write_exp_elt_block (block_found);
915 write_exp_elt_sym (sym);
916 write_exp_elt_opcode (OP_VAR_VALUE); }
919 qualified_name: TYPENAME COLONCOLON name
921 struct type *type = $1.type;
922 CHECK_TYPEDEF (type);
923 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
924 && TYPE_CODE (type) != TYPE_CODE_UNION
925 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
926 error (_("`%s' is not defined as an aggregate type."),
929 write_exp_elt_opcode (OP_SCOPE);
930 write_exp_elt_type (type);
931 write_exp_string ($3);
932 write_exp_elt_opcode (OP_SCOPE);
934 | TYPENAME COLONCOLON '~' name
936 struct type *type = $1.type;
937 struct stoken tmp_token;
938 CHECK_TYPEDEF (type);
939 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
940 && TYPE_CODE (type) != TYPE_CODE_UNION
941 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
942 error (_("`%s' is not defined as an aggregate type."),
945 tmp_token.ptr = (char*) alloca ($4.length + 2);
946 tmp_token.length = $4.length + 1;
947 tmp_token.ptr[0] = '~';
948 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
949 tmp_token.ptr[tmp_token.length] = 0;
951 /* Check for valid destructor name. */
952 destructor_name_p (tmp_token.ptr, $1.type);
953 write_exp_elt_opcode (OP_SCOPE);
954 write_exp_elt_type (type);
955 write_exp_string (tmp_token);
956 write_exp_elt_opcode (OP_SCOPE);
958 | TYPENAME COLONCOLON name COLONCOLON name
960 char *copy = copy_name ($3);
961 error (_("No type \"%s\" within class "
962 "or namespace \"%s\"."),
963 copy, TYPE_NAME ($1.type));
967 variable: qualified_name
968 | COLONCOLON name_not_typename
970 char *name = copy_name ($2.stoken);
972 struct minimal_symbol *msymbol;
975 lookup_symbol (name, (const struct block *) NULL,
979 write_exp_elt_opcode (OP_VAR_VALUE);
980 write_exp_elt_block (NULL);
981 write_exp_elt_sym (sym);
982 write_exp_elt_opcode (OP_VAR_VALUE);
986 msymbol = lookup_minimal_symbol (name, NULL, NULL);
988 write_exp_msymbol (msymbol);
989 else if (!have_full_symbols () && !have_partial_symbols ())
990 error (_("No symbol table is loaded. Use the \"file\" command."));
992 error (_("No symbol \"%s\" in current context."), name);
996 variable: name_not_typename
997 { struct symbol *sym = $1.sym;
1001 if (symbol_read_needs_frame (sym))
1003 if (innermost_block == 0
1004 || contained_in (block_found,
1006 innermost_block = block_found;
1009 write_exp_elt_opcode (OP_VAR_VALUE);
1010 /* We want to use the selected frame, not
1011 another more inner frame which happens to
1012 be in the same block. */
1013 write_exp_elt_block (NULL);
1014 write_exp_elt_sym (sym);
1015 write_exp_elt_opcode (OP_VAR_VALUE);
1017 else if ($1.is_a_field_of_this)
1019 /* C++: it hangs off of `this'. Must
1020 not inadvertently convert from a method call
1022 if (innermost_block == 0
1023 || contained_in (block_found,
1025 innermost_block = block_found;
1026 write_exp_elt_opcode (OP_THIS);
1027 write_exp_elt_opcode (OP_THIS);
1028 write_exp_elt_opcode (STRUCTOP_PTR);
1029 write_exp_string ($1.stoken);
1030 write_exp_elt_opcode (STRUCTOP_PTR);
1034 struct minimal_symbol *msymbol;
1035 char *arg = copy_name ($1.stoken);
1038 lookup_minimal_symbol (arg, NULL, NULL);
1039 if (msymbol != NULL)
1040 write_exp_msymbol (msymbol);
1041 else if (!have_full_symbols () && !have_partial_symbols ())
1042 error (_("No symbol table is loaded. Use the \"file\" command."));
1044 error (_("No symbol \"%s\" in current context."),
1045 copy_name ($1.stoken));
1050 space_identifier : '@' NAME
1051 { insert_type_address_space (copy_name ($2.stoken)); }
1054 const_or_volatile: const_or_volatile_noopt
1058 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
1061 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
1062 | const_or_volatile_noopt
1065 const_or_volatile_or_space_identifier:
1066 const_or_volatile_or_space_identifier_noopt
1072 { insert_type (tp_pointer); }
1073 const_or_volatile_or_space_identifier
1075 { insert_type (tp_pointer); }
1076 const_or_volatile_or_space_identifier
1078 { insert_type (tp_reference); }
1080 { insert_type (tp_reference); }
1083 ptr_operator_ts: ptr_operator
1085 $$ = get_type_stack ();
1086 /* This cleanup is eventually run by
1088 make_cleanup (type_stack_cleanup, $$);
1092 abs_decl: ptr_operator_ts direct_abs_decl
1093 { $$ = append_type_stack ($2, $1); }
1098 direct_abs_decl: '(' abs_decl ')'
1100 | direct_abs_decl array_mod
1102 push_type_stack ($1);
1104 push_type (tp_array);
1105 $$ = get_type_stack ();
1110 push_type (tp_array);
1111 $$ = get_type_stack ();
1114 | direct_abs_decl func_mod
1116 push_type_stack ($1);
1118 $$ = get_type_stack ();
1123 $$ = get_type_stack ();
1133 | OBJC_LBRAC INT ']'
1139 | '(' parameter_typelist ')'
1143 /* We used to try to recognize pointer to member types here, but
1144 that didn't work (shift/reduce conflicts meant that these rules never
1145 got executed). The problem is that
1146 int (foo::bar::baz::bizzle)
1147 is a function type but
1148 int (foo::bar::baz::bizzle::*)
1149 is a pointer to member type. Stroustrup loses again! */
1154 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
1158 { $$ = lookup_signed_typename (parse_language,
1162 { $$ = lookup_signed_typename (parse_language,
1166 { $$ = lookup_signed_typename (parse_language,
1170 { $$ = lookup_signed_typename (parse_language,
1173 | LONG SIGNED_KEYWORD INT_KEYWORD
1174 { $$ = lookup_signed_typename (parse_language,
1177 | LONG SIGNED_KEYWORD
1178 { $$ = lookup_signed_typename (parse_language,
1181 | SIGNED_KEYWORD LONG INT_KEYWORD
1182 { $$ = lookup_signed_typename (parse_language,
1185 | UNSIGNED LONG INT_KEYWORD
1186 { $$ = lookup_unsigned_typename (parse_language,
1189 | LONG UNSIGNED INT_KEYWORD
1190 { $$ = lookup_unsigned_typename (parse_language,
1194 { $$ = lookup_unsigned_typename (parse_language,
1198 { $$ = lookup_signed_typename (parse_language,
1201 | LONG LONG INT_KEYWORD
1202 { $$ = lookup_signed_typename (parse_language,
1205 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
1206 { $$ = lookup_signed_typename (parse_language,
1209 | LONG LONG SIGNED_KEYWORD
1210 { $$ = lookup_signed_typename (parse_language,
1213 | SIGNED_KEYWORD LONG LONG
1214 { $$ = lookup_signed_typename (parse_language,
1217 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
1218 { $$ = lookup_signed_typename (parse_language,
1221 | UNSIGNED LONG LONG
1222 { $$ = lookup_unsigned_typename (parse_language,
1225 | UNSIGNED LONG LONG INT_KEYWORD
1226 { $$ = lookup_unsigned_typename (parse_language,
1229 | LONG LONG UNSIGNED
1230 { $$ = lookup_unsigned_typename (parse_language,
1233 | LONG LONG UNSIGNED INT_KEYWORD
1234 { $$ = lookup_unsigned_typename (parse_language,
1238 { $$ = lookup_signed_typename (parse_language,
1241 | SHORT SIGNED_KEYWORD INT_KEYWORD
1242 { $$ = lookup_signed_typename (parse_language,
1245 | SHORT SIGNED_KEYWORD
1246 { $$ = lookup_signed_typename (parse_language,
1249 | UNSIGNED SHORT INT_KEYWORD
1250 { $$ = lookup_unsigned_typename (parse_language,
1254 { $$ = lookup_unsigned_typename (parse_language,
1257 | SHORT UNSIGNED INT_KEYWORD
1258 { $$ = lookup_unsigned_typename (parse_language,
1262 { $$ = lookup_typename (parse_language, parse_gdbarch,
1263 "double", (struct block *) NULL,
1265 | LONG DOUBLE_KEYWORD
1266 { $$ = lookup_typename (parse_language, parse_gdbarch,
1268 (struct block *) NULL, 0); }
1270 { $$ = lookup_struct (copy_name ($2),
1271 expression_context_block); }
1274 mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
1277 | STRUCT name COMPLETE
1279 mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
1284 { $$ = lookup_struct (copy_name ($2),
1285 expression_context_block); }
1288 mark_completion_tag (TYPE_CODE_CLASS, "", 0);
1291 | CLASS name COMPLETE
1293 mark_completion_tag (TYPE_CODE_CLASS, $2.ptr,
1298 { $$ = lookup_union (copy_name ($2),
1299 expression_context_block); }
1302 mark_completion_tag (TYPE_CODE_UNION, "", 0);
1305 | UNION name COMPLETE
1307 mark_completion_tag (TYPE_CODE_UNION, $2.ptr,
1312 { $$ = lookup_enum (copy_name ($2),
1313 expression_context_block); }
1316 mark_completion_tag (TYPE_CODE_ENUM, "", 0);
1319 | ENUM name COMPLETE
1321 mark_completion_tag (TYPE_CODE_ENUM, $2.ptr,
1326 { $$ = lookup_unsigned_typename (parse_language,
1328 TYPE_NAME($2.type)); }
1330 { $$ = lookup_unsigned_typename (parse_language,
1333 | SIGNED_KEYWORD typename
1334 { $$ = lookup_signed_typename (parse_language,
1336 TYPE_NAME($2.type)); }
1338 { $$ = lookup_signed_typename (parse_language,
1341 /* It appears that this rule for templates is never
1342 reduced; template recognition happens by lookahead
1343 in the token processing code in yylex. */
1344 | TEMPLATE name '<' type '>'
1345 { $$ = lookup_template_type(copy_name($2), $4,
1346 expression_context_block);
1348 | const_or_volatile_or_space_identifier_noopt typebase
1349 { $$ = follow_types ($2); }
1350 | typebase const_or_volatile_or_space_identifier_noopt
1351 { $$ = follow_types ($1); }
1357 $$.stoken.ptr = "int";
1358 $$.stoken.length = 3;
1359 $$.type = lookup_signed_typename (parse_language,
1365 $$.stoken.ptr = "long";
1366 $$.stoken.length = 4;
1367 $$.type = lookup_signed_typename (parse_language,
1373 $$.stoken.ptr = "short";
1374 $$.stoken.length = 5;
1375 $$.type = lookup_signed_typename (parse_language,
1383 { check_parameter_typelist ($1); }
1384 | nonempty_typelist ',' DOTDOTDOT
1386 VEC_safe_push (type_ptr, $1, NULL);
1387 check_parameter_typelist ($1);
1395 VEC (type_ptr) *typelist = NULL;
1396 VEC_safe_push (type_ptr, typelist, $1);
1399 | nonempty_typelist ',' type
1401 VEC_safe_push (type_ptr, $1, $3);
1409 push_type_stack ($2);
1410 $$ = follow_types ($1);
1414 conversion_type_id: typebase conversion_declarator
1415 { $$ = follow_types ($1); }
1418 conversion_declarator: /* Nothing. */
1419 | ptr_operator conversion_declarator
1422 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1423 | VOLATILE_KEYWORD CONST_KEYWORD
1426 const_or_volatile_noopt: const_and_volatile
1427 { insert_type (tp_const);
1428 insert_type (tp_volatile);
1431 { insert_type (tp_const); }
1433 { insert_type (tp_volatile); }
1436 operator: OPERATOR NEW
1437 { $$ = operator_stoken (" new"); }
1439 { $$ = operator_stoken (" delete"); }
1440 | OPERATOR NEW '[' ']'
1441 { $$ = operator_stoken (" new[]"); }
1442 | OPERATOR DELETE '[' ']'
1443 { $$ = operator_stoken (" delete[]"); }
1444 | OPERATOR NEW OBJC_LBRAC ']'
1445 { $$ = operator_stoken (" new[]"); }
1446 | OPERATOR DELETE OBJC_LBRAC ']'
1447 { $$ = operator_stoken (" delete[]"); }
1449 { $$ = operator_stoken ("+"); }
1451 { $$ = operator_stoken ("-"); }
1453 { $$ = operator_stoken ("*"); }
1455 { $$ = operator_stoken ("/"); }
1457 { $$ = operator_stoken ("%"); }
1459 { $$ = operator_stoken ("^"); }
1461 { $$ = operator_stoken ("&"); }
1463 { $$ = operator_stoken ("|"); }
1465 { $$ = operator_stoken ("~"); }
1467 { $$ = operator_stoken ("!"); }
1469 { $$ = operator_stoken ("="); }
1471 { $$ = operator_stoken ("<"); }
1473 { $$ = operator_stoken (">"); }
1474 | OPERATOR ASSIGN_MODIFY
1475 { const char *op = "unknown";
1499 case BINOP_BITWISE_IOR:
1502 case BINOP_BITWISE_AND:
1505 case BINOP_BITWISE_XOR:
1512 $$ = operator_stoken (op);
1515 { $$ = operator_stoken ("<<"); }
1517 { $$ = operator_stoken (">>"); }
1519 { $$ = operator_stoken ("=="); }
1521 { $$ = operator_stoken ("!="); }
1523 { $$ = operator_stoken ("<="); }
1525 { $$ = operator_stoken (">="); }
1527 { $$ = operator_stoken ("&&"); }
1529 { $$ = operator_stoken ("||"); }
1530 | OPERATOR INCREMENT
1531 { $$ = operator_stoken ("++"); }
1532 | OPERATOR DECREMENT
1533 { $$ = operator_stoken ("--"); }
1535 { $$ = operator_stoken (","); }
1536 | OPERATOR ARROW_STAR
1537 { $$ = operator_stoken ("->*"); }
1539 { $$ = operator_stoken ("->"); }
1541 { $$ = operator_stoken ("()"); }
1543 { $$ = operator_stoken ("[]"); }
1544 | OPERATOR OBJC_LBRAC ']'
1545 { $$ = operator_stoken ("[]"); }
1546 | OPERATOR conversion_type_id
1549 struct ui_file *buf = mem_fileopen ();
1551 c_print_type ($2, NULL, buf, -1, 0,
1552 &type_print_raw_options);
1553 name = ui_file_xstrdup (buf, &length);
1554 ui_file_delete (buf);
1555 $$ = operator_stoken (name);
1562 name : NAME { $$ = $1.stoken; }
1563 | BLOCKNAME { $$ = $1.stoken; }
1564 | TYPENAME { $$ = $1.stoken; }
1565 | NAME_OR_INT { $$ = $1.stoken; }
1566 | UNKNOWN_CPP_NAME { $$ = $1.stoken; }
1567 | operator { $$ = $1; }
1570 name_not_typename : NAME
1572 /* These would be useful if name_not_typename was useful, but it is just
1573 a fake for "variable", so these cause reduce/reduce conflicts because
1574 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1575 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1576 context where only a name could occur, this might be useful.
1581 struct field_of_this_result is_a_field_of_this;
1584 $$.sym = lookup_symbol ($1.ptr,
1585 expression_context_block,
1587 &is_a_field_of_this);
1588 $$.is_a_field_of_this
1589 = is_a_field_of_this.type != NULL;
1596 /* Returns a stoken of the operator name given by OP (which does not
1597 include the string "operator"). */
1598 static struct stoken
1599 operator_stoken (const char *op)
1601 static const char *operator_string = "operator";
1602 struct stoken st = { NULL, 0 };
1603 st.length = strlen (operator_string) + strlen (op);
1604 st.ptr = malloc (st.length + 1);
1605 strcpy (st.ptr, operator_string);
1606 strcat (st.ptr, op);
1608 /* The toplevel (c_parse) will free the memory allocated here. */
1609 make_cleanup (free, st.ptr);
1613 /* Validate a parameter typelist. */
1616 check_parameter_typelist (VEC (type_ptr) *params)
1621 for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
1623 if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1627 if (VEC_length (type_ptr, params) == 1)
1632 VEC_free (type_ptr, params);
1633 error (_("parameter types following 'void'"));
1637 VEC_free (type_ptr, params);
1638 error (_("'void' invalid as parameter type"));
1644 /* Take care of parsing a number (anything that starts with a digit).
1645 Set yylval and return the token type; update lexptr.
1646 LEN is the number of characters in it. */
1648 /*** Needs some error checking for the float case ***/
1651 parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
1653 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1654 here, and we do kind of silly things like cast to unsigned. */
1661 int base = input_radix;
1664 /* Number of "L" suffixes encountered. */
1667 /* We have found a "L" or "U" suffix. */
1668 int found_suffix = 0;
1671 struct type *signed_type;
1672 struct type *unsigned_type;
1676 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1677 point. Return DECFLOAT. */
1679 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1682 putithere->typed_val_decfloat.type
1683 = parse_type->builtin_decfloat;
1684 decimal_from_string (putithere->typed_val_decfloat.val, 4,
1685 gdbarch_byte_order (parse_gdbarch), p);
1690 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1693 putithere->typed_val_decfloat.type
1694 = parse_type->builtin_decdouble;
1695 decimal_from_string (putithere->typed_val_decfloat.val, 8,
1696 gdbarch_byte_order (parse_gdbarch), p);
1701 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1704 putithere->typed_val_decfloat.type
1705 = parse_type->builtin_declong;
1706 decimal_from_string (putithere->typed_val_decfloat.val, 16,
1707 gdbarch_byte_order (parse_gdbarch), p);
1712 if (! parse_c_float (parse_gdbarch, p, len,
1713 &putithere->typed_val_float.dval,
1714 &putithere->typed_val_float.type))
1719 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1763 if (c >= 'A' && c <= 'Z')
1765 if (c != 'l' && c != 'u')
1767 if (c >= '0' && c <= '9')
1775 if (base > 10 && c >= 'a' && c <= 'f')
1779 n += i = c - 'a' + 10;
1792 return ERROR; /* Char not a digit */
1795 return ERROR; /* Invalid digit in this base */
1797 /* Portably test for overflow (only works for nonzero values, so make
1798 a second check for zero). FIXME: Can't we just make n and prevn
1799 unsigned and avoid this? */
1800 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1801 unsigned_p = 1; /* Try something unsigned */
1803 /* Portably test for unsigned overflow.
1804 FIXME: This check is wrong; for example it doesn't find overflow
1805 on 0x123456789 when LONGEST is 32 bits. */
1806 if (c != 'l' && c != 'u' && n != 0)
1808 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1809 error (_("Numeric constant too large."));
1814 /* An integer constant is an int, a long, or a long long. An L
1815 suffix forces it to be long; an LL suffix forces it to be long
1816 long. If not forced to a larger size, it gets the first type of
1817 the above that it fits in. To figure out whether it fits, we
1818 shift it right and see whether anything remains. Note that we
1819 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1820 operation, because many compilers will warn about such a shift
1821 (which always produces a zero result). Sometimes gdbarch_int_bit
1822 or gdbarch_long_bit will be that big, sometimes not. To deal with
1823 the case where it is we just always shift the value more than
1824 once, with fewer bits each time. */
1826 un = (ULONGEST)n >> 2;
1828 && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1830 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1832 /* A large decimal (not hex or octal) constant (between INT_MAX
1833 and UINT_MAX) is a long or unsigned long, according to ANSI,
1834 never an unsigned int, but this code treats it as unsigned
1835 int. This probably should be fixed. GCC gives a warning on
1838 unsigned_type = parse_type->builtin_unsigned_int;
1839 signed_type = parse_type->builtin_int;
1841 else if (long_p <= 1
1842 && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1844 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1845 unsigned_type = parse_type->builtin_unsigned_long;
1846 signed_type = parse_type->builtin_long;
1851 if (sizeof (ULONGEST) * HOST_CHAR_BIT
1852 < gdbarch_long_long_bit (parse_gdbarch))
1853 /* A long long does not fit in a LONGEST. */
1854 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1856 shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1857 high_bit = (ULONGEST) 1 << shift;
1858 unsigned_type = parse_type->builtin_unsigned_long_long;
1859 signed_type = parse_type->builtin_long_long;
1862 putithere->typed_val_int.val = n;
1864 /* If the high bit of the worked out type is set then this number
1865 has to be unsigned. */
1867 if (unsigned_p || (n & high_bit))
1869 putithere->typed_val_int.type = unsigned_type;
1873 putithere->typed_val_int.type = signed_type;
1879 /* Temporary obstack used for holding strings. */
1880 static struct obstack tempbuf;
1881 static int tempbuf_init;
1883 /* Parse a C escape sequence. The initial backslash of the sequence
1884 is at (*PTR)[-1]. *PTR will be updated to point to just after the
1885 last character of the sequence. If OUTPUT is not NULL, the
1886 translated form of the escape sequence will be written there. If
1887 OUTPUT is NULL, no output is written and the call will only affect
1888 *PTR. If an escape sequence is expressed in target bytes, then the
1889 entire sequence will simply be copied to OUTPUT. Return 1 if any
1890 character was emitted, 0 otherwise. */
1893 c_parse_escape (char **ptr, struct obstack *output)
1895 char *tokptr = *ptr;
1898 /* Some escape sequences undergo character set conversion. Those we
1902 /* Hex escapes do not undergo character set conversion, so keep
1903 the escape sequence for later. */
1906 obstack_grow_str (output, "\\x");
1908 if (!isxdigit (*tokptr))
1909 error (_("\\x escape without a following hex digit"));
1910 while (isxdigit (*tokptr))
1913 obstack_1grow (output, *tokptr);
1918 /* Octal escapes do not undergo character set conversion, so
1919 keep the escape sequence for later. */
1931 obstack_grow_str (output, "\\");
1933 i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
1937 obstack_1grow (output, *tokptr);
1943 /* We handle UCNs later. We could handle them here, but that
1944 would mean a spurious error in the case where the UCN could
1945 be converted to the target charset but not the host
1951 int i, len = c == 'U' ? 8 : 4;
1954 obstack_1grow (output, '\\');
1955 obstack_1grow (output, *tokptr);
1958 if (!isxdigit (*tokptr))
1959 error (_("\\%c escape without a following hex digit"), c);
1960 for (i = 0; i < len && isxdigit (*tokptr); ++i)
1963 obstack_1grow (output, *tokptr);
1969 /* We must pass backslash through so that it does not
1970 cause quoting during the second expansion. */
1973 obstack_grow_str (output, "\\\\");
1977 /* Escapes which undergo conversion. */
1980 obstack_1grow (output, '\a');
1985 obstack_1grow (output, '\b');
1990 obstack_1grow (output, '\f');
1995 obstack_1grow (output, '\n');
2000 obstack_1grow (output, '\r');
2005 obstack_1grow (output, '\t');
2010 obstack_1grow (output, '\v');
2014 /* GCC extension. */
2017 obstack_1grow (output, HOST_ESCAPE_CHAR);
2021 /* Backslash-newline expands to nothing at all. */
2027 /* A few escapes just expand to the character itself. */
2031 /* GCC extensions. */
2036 /* Unrecognized escapes turn into the character itself. */
2039 obstack_1grow (output, *tokptr);
2047 /* Parse a string or character literal from TOKPTR. The string or
2048 character may be wide or unicode. *OUTPTR is set to just after the
2049 end of the literal in the input string. The resulting token is
2050 stored in VALUE. This returns a token value, either STRING or
2051 CHAR, depending on what was parsed. *HOST_CHARS is set to the
2052 number of host characters in the literal. */
2054 parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
2058 enum c_string_type type;
2061 /* Build the gdb internal form of the input string in tempbuf. Note
2062 that the buffer is null byte terminated *only* for the
2063 convenience of debugging gdb itself and printing the buffer
2064 contents when the buffer contains no embedded nulls. Gdb does
2065 not depend upon the buffer being null byte terminated, it uses
2066 the length string instead. This allows gdb to handle C strings
2067 (as well as strings in other languages) with embedded null
2073 obstack_free (&tempbuf, NULL);
2074 obstack_init (&tempbuf);
2076 /* Record the string type. */
2079 type = C_WIDE_STRING;
2082 else if (*tokptr == 'u')
2087 else if (*tokptr == 'U')
2092 else if (*tokptr == '@')
2094 /* An Objective C string. */
2102 /* Skip the quote. */
2116 *host_chars += c_parse_escape (&tokptr, &tempbuf);
2118 else if (c == quote)
2122 obstack_1grow (&tempbuf, c);
2124 /* FIXME: this does the wrong thing with multi-byte host
2125 characters. We could use mbrlen here, but that would
2126 make "set host-charset" a bit less useful. */
2131 if (*tokptr != quote)
2134 error (_("Unterminated string in expression."));
2136 error (_("Unmatched single quote."));
2141 value->ptr = obstack_base (&tempbuf);
2142 value->length = obstack_object_size (&tempbuf);
2146 return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
2149 /* This is used to associate some attributes with a token. */
2153 /* If this bit is set, the token is C++-only. */
2157 /* If this bit is set, the token is conditional: if there is a
2158 symbol of the same name, then the token is a symbol; otherwise,
2159 the token is a keyword. */
2168 enum exp_opcode opcode;
2169 enum token_flags flags;
2172 static const struct token tokentab3[] =
2174 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
2175 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
2176 {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
2177 {"...", DOTDOTDOT, BINOP_END, 0}
2180 static const struct token tokentab2[] =
2182 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
2183 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
2184 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
2185 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
2186 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
2187 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
2188 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
2189 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
2190 {"++", INCREMENT, BINOP_END, 0},
2191 {"--", DECREMENT, BINOP_END, 0},
2192 {"->", ARROW, BINOP_END, 0},
2193 {"&&", ANDAND, BINOP_END, 0},
2194 {"||", OROR, BINOP_END, 0},
2195 /* "::" is *not* only C++: gdb overrides its meaning in several
2196 different ways, e.g., 'filename'::func, function::variable. */
2197 {"::", COLONCOLON, BINOP_END, 0},
2198 {"<<", LSH, BINOP_END, 0},
2199 {">>", RSH, BINOP_END, 0},
2200 {"==", EQUAL, BINOP_END, 0},
2201 {"!=", NOTEQUAL, BINOP_END, 0},
2202 {"<=", LEQ, BINOP_END, 0},
2203 {">=", GEQ, BINOP_END, 0},
2204 {".*", DOT_STAR, BINOP_END, FLAG_CXX}
2207 /* Identifier-like tokens. */
2208 static const struct token ident_tokens[] =
2210 {"unsigned", UNSIGNED, OP_NULL, 0},
2211 {"template", TEMPLATE, OP_NULL, FLAG_CXX},
2212 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
2213 {"struct", STRUCT, OP_NULL, 0},
2214 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
2215 {"sizeof", SIZEOF, OP_NULL, 0},
2216 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
2217 {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2218 {"class", CLASS, OP_NULL, FLAG_CXX},
2219 {"union", UNION, OP_NULL, 0},
2220 {"short", SHORT, OP_NULL, 0},
2221 {"const", CONST_KEYWORD, OP_NULL, 0},
2222 {"enum", ENUM, OP_NULL, 0},
2223 {"long", LONG, OP_NULL, 0},
2224 {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
2225 {"int", INT_KEYWORD, OP_NULL, 0},
2226 {"new", NEW, OP_NULL, FLAG_CXX},
2227 {"delete", DELETE, OP_NULL, FLAG_CXX},
2228 {"operator", OPERATOR, OP_NULL, FLAG_CXX},
2230 {"and", ANDAND, BINOP_END, FLAG_CXX},
2231 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2232 {"bitand", '&', OP_NULL, FLAG_CXX},
2233 {"bitor", '|', OP_NULL, FLAG_CXX},
2234 {"compl", '~', OP_NULL, FLAG_CXX},
2235 {"not", '!', OP_NULL, FLAG_CXX},
2236 {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2237 {"or", OROR, BINOP_END, FLAG_CXX},
2238 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2239 {"xor", '^', OP_NULL, FLAG_CXX},
2240 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2242 {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2243 {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2244 {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
2245 {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },
2247 {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
2248 {"__typeof", TYPEOF, OP_TYPEOF, 0 },
2249 {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
2250 {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
2251 {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }
2254 /* When we find that lexptr (the global var defined in parse.c) is
2255 pointing at a macro invocation, we expand the invocation, and call
2256 scan_macro_expansion to save the old lexptr here and point lexptr
2257 into the expanded text. When we reach the end of that, we call
2258 end_macro_expansion to pop back to the value we saved here. The
2259 macro expansion code promises to return only fully-expanded text,
2260 so we don't need to "push" more than one level.
2262 This is disgusting, of course. It would be cleaner to do all macro
2263 expansion beforehand, and then hand that to lexptr. But we don't
2264 really know where the expression ends. Remember, in a command like
2266 (gdb) break *ADDRESS if CONDITION
2268 we evaluate ADDRESS in the scope of the current frame, but we
2269 evaluate CONDITION in the scope of the breakpoint's location. So
2270 it's simply wrong to try to macro-expand the whole thing at once. */
2271 static char *macro_original_text;
2273 /* We save all intermediate macro expansions on this obstack for the
2274 duration of a single parse. The expansion text may sometimes have
2275 to live past the end of the expansion, due to yacc lookahead.
2276 Rather than try to be clever about saving the data for a single
2277 token, we simply keep it all and delete it after parsing has
2279 static struct obstack expansion_obstack;
2282 scan_macro_expansion (char *expansion)
2286 /* We'd better not be trying to push the stack twice. */
2287 gdb_assert (! macro_original_text);
2289 /* Copy to the obstack, and then free the intermediate
2291 copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
2294 /* Save the old lexptr value, so we can return to it when we're done
2295 parsing the expanded text. */
2296 macro_original_text = lexptr;
2302 scanning_macro_expansion (void)
2304 return macro_original_text != 0;
2309 finished_macro_expansion (void)
2311 /* There'd better be something to pop back to. */
2312 gdb_assert (macro_original_text);
2314 /* Pop back to the original text. */
2315 lexptr = macro_original_text;
2316 macro_original_text = 0;
2321 scan_macro_cleanup (void *dummy)
2323 if (macro_original_text)
2324 finished_macro_expansion ();
2326 obstack_free (&expansion_obstack, NULL);
2329 /* Return true iff the token represents a C++ cast operator. */
2332 is_cast_operator (const char *token, int len)
2334 return (! strncmp (token, "dynamic_cast", len)
2335 || ! strncmp (token, "static_cast", len)
2336 || ! strncmp (token, "reinterpret_cast", len)
2337 || ! strncmp (token, "const_cast", len));
2340 /* The scope used for macro expansion. */
2341 static struct macro_scope *expression_macro_scope;
2343 /* This is set if a NAME token appeared at the very end of the input
2344 string, with no whitespace separating the name from the EOF. This
2345 is used only when parsing to do field name completion. */
2346 static int saw_name_at_eof;
2348 /* This is set if the previously-returned token was a structure
2349 operator -- either '.' or ARROW. This is used only when parsing to
2350 do field name completion. */
2351 static int last_was_structop;
2353 /* Read one token, getting characters through lexptr. */
2356 lex_one_token (void)
2362 int saw_structop = last_was_structop;
2365 last_was_structop = 0;
2369 /* Check if this is a macro invocation that we need to expand. */
2370 if (! scanning_macro_expansion ())
2372 char *expanded = macro_expand_next (&lexptr,
2373 standard_macro_lookup,
2374 expression_macro_scope);
2377 scan_macro_expansion (expanded);
2380 prev_lexptr = lexptr;
2383 /* See if it is a special token of length 3. */
2384 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
2385 if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
2387 if ((tokentab3[i].flags & FLAG_CXX) != 0
2388 && parse_language->la_language != language_cplus)
2392 yylval.opcode = tokentab3[i].opcode;
2393 return tokentab3[i].token;
2396 /* See if it is a special token of length 2. */
2397 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
2398 if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
2400 if ((tokentab2[i].flags & FLAG_CXX) != 0
2401 && parse_language->la_language != language_cplus)
2405 yylval.opcode = tokentab2[i].opcode;
2406 if (parse_completion && tokentab2[i].token == ARROW)
2407 last_was_structop = 1;
2408 return tokentab2[i].token;
2411 switch (c = *tokstart)
2414 /* If we were just scanning the result of a macro expansion,
2415 then we need to resume scanning the original text.
2416 If we're parsing for field name completion, and the previous
2417 token allows such completion, return a COMPLETE token.
2418 Otherwise, we were already scanning the original text, and
2419 we're really done. */
2420 if (scanning_macro_expansion ())
2422 finished_macro_expansion ();
2425 else if (saw_name_at_eof)
2427 saw_name_at_eof = 0;
2430 else if (saw_structop)
2445 if (parse_language->la_language == language_objc && c == '[')
2451 if (paren_depth == 0)
2458 if (comma_terminates
2460 && ! scanning_macro_expansion ())
2466 /* Might be a floating point number. */
2467 if (lexptr[1] < '0' || lexptr[1] > '9')
2469 if (parse_completion)
2470 last_was_structop = 1;
2471 goto symbol; /* Nope, must be a symbol. */
2473 /* FALL THRU into number case. */
2486 /* It's a number. */
2487 int got_dot = 0, got_e = 0, toktype;
2489 int hex = input_radix > 10;
2491 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2496 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2504 /* This test includes !hex because 'e' is a valid hex digit
2505 and thus does not indicate a floating point number when
2506 the radix is hex. */
2507 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2508 got_dot = got_e = 1;
2509 /* This test does not include !hex, because a '.' always indicates
2510 a decimal floating point number regardless of the radix. */
2511 else if (!got_dot && *p == '.')
2513 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2514 && (*p == '-' || *p == '+'))
2515 /* This is the sign of the exponent, not the end of the
2518 /* We will take any letters or digits. parse_number will
2519 complain if past the radix, or if L or U are not final. */
2520 else if ((*p < '0' || *p > '9')
2521 && ((*p < 'a' || *p > 'z')
2522 && (*p < 'A' || *p > 'Z')))
2525 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
2526 if (toktype == ERROR)
2528 char *err_copy = (char *) alloca (p - tokstart + 1);
2530 memcpy (err_copy, tokstart, p - tokstart);
2531 err_copy[p - tokstart] = 0;
2532 error (_("Invalid number \"%s\"."), err_copy);
2540 char *p = &tokstart[1];
2541 size_t len = strlen ("entry");
2543 if (parse_language->la_language == language_objc)
2545 size_t len = strlen ("selector");
2547 if (strncmp (p, "selector", len) == 0
2548 && (p[len] == '\0' || isspace (p[len])))
2557 while (isspace (*p))
2559 if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2591 if (tokstart[1] != '"' && tokstart[1] != '\'')
2600 int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
2605 error (_("Empty character constant."));
2606 else if (host_len > 2 && c == '\'')
2609 namelen = lexptr - tokstart - 1;
2612 else if (host_len > 1)
2613 error (_("Invalid character constant."));
2619 if (!(c == '_' || c == '$'
2620 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2621 /* We must have come across a bad character (e.g. ';'). */
2622 error (_("Invalid character '%c' in expression."), c);
2624 /* It's a name. See how long it is. */
2626 for (c = tokstart[namelen];
2627 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2628 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2630 /* Template parameter lists are part of the name.
2631 FIXME: This mishandles `print $a<4&&$a>3'. */
2635 if (! is_cast_operator (tokstart, namelen))
2637 /* Scan ahead to get rest of the template specification. Note
2638 that we look ahead only when the '<' adjoins non-whitespace
2639 characters; for comparison expressions, e.g. "a < b > c",
2640 there must be spaces before the '<', etc. */
2642 char * p = find_template_name_end (tokstart + namelen);
2644 namelen = p - tokstart;
2648 c = tokstart[++namelen];
2651 /* The token "if" terminates the expression and is NOT removed from
2652 the input stream. It doesn't count if it appears in the
2653 expansion of a macro. */
2655 && tokstart[0] == 'i'
2656 && tokstart[1] == 'f'
2657 && ! scanning_macro_expansion ())
2662 /* For the same reason (breakpoint conditions), "thread N"
2663 terminates the expression. "thread" could be an identifier, but
2664 an identifier is never followed by a number without intervening
2665 punctuation. "task" is similar. Handle abbreviations of these,
2666 similarly to breakpoint.c:find_condition_and_thread. */
2668 && (strncmp (tokstart, "thread", namelen) == 0
2669 || strncmp (tokstart, "task", namelen) == 0)
2670 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2671 && ! scanning_macro_expansion ())
2673 char *p = tokstart + namelen + 1;
2674 while (*p == ' ' || *p == '\t')
2676 if (*p >= '0' && *p <= '9')
2684 yylval.sval.ptr = tokstart;
2685 yylval.sval.length = namelen;
2687 /* Catch specific keywords. */
2688 copy = copy_name (yylval.sval);
2689 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
2690 if (strcmp (copy, ident_tokens[i].operator) == 0)
2692 if ((ident_tokens[i].flags & FLAG_CXX) != 0
2693 && parse_language->la_language != language_cplus)
2696 if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2698 struct field_of_this_result is_a_field_of_this;
2700 if (lookup_symbol (copy, expression_context_block,
2702 (parse_language->la_language == language_cplus
2703 ? &is_a_field_of_this
2707 /* The keyword is shadowed. */
2712 /* It is ok to always set this, even though we don't always
2713 strictly need to. */
2714 yylval.opcode = ident_tokens[i].opcode;
2715 return ident_tokens[i].token;
2718 if (*tokstart == '$')
2721 if (parse_completion && *lexptr == '\0')
2722 saw_name_at_eof = 1;
2726 /* An object of this type is pushed on a FIFO by the "outer" lexer. */
2733 DEF_VEC_O (token_and_value);
2735 /* A FIFO of tokens that have been read but not yet returned to the
2737 static VEC (token_and_value) *token_fifo;
2739 /* Non-zero if the lexer should return tokens from the FIFO. */
2742 /* Temporary storage for c_lex; this holds symbol names as they are
2744 static struct obstack name_obstack;
2746 /* Classify a NAME token. The contents of the token are in `yylval'.
2747 Updates yylval and returns the new token type. BLOCK is the block
2748 in which lookups start; this can be NULL to mean the global
2751 classify_name (const struct block *block)
2755 struct field_of_this_result is_a_field_of_this;
2757 copy = copy_name (yylval.sval);
2759 /* Initialize this in case we *don't* use it in this call; that way
2760 we can refer to it unconditionally below. */
2761 memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
2763 sym = lookup_symbol (copy, block, VAR_DOMAIN,
2764 parse_language->la_name_of_this
2765 ? &is_a_field_of_this : NULL);
2767 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2769 yylval.ssym.sym = sym;
2770 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
2775 /* See if it's a file name. */
2776 struct symtab *symtab;
2778 symtab = lookup_symtab (copy);
2781 yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
2785 /* If we found a field of 'this', we might have erroneously
2786 found a constructor where we wanted a type name. Handle this
2787 case by noticing that we found a constructor and then look up
2788 the type tag instead. */
2789 if (is_a_field_of_this.type != NULL
2790 && is_a_field_of_this.fn_field != NULL
2791 && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields,
2794 struct field_of_this_result inner_is_a_field_of_this;
2796 sym = lookup_symbol (copy, block, STRUCT_DOMAIN,
2797 &inner_is_a_field_of_this);
2800 yylval.tsym.type = SYMBOL_TYPE (sym);
2806 if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2808 yylval.tsym.type = SYMBOL_TYPE (sym);
2813 = language_lookup_primitive_type_by_name (parse_language,
2814 parse_gdbarch, copy);
2815 if (yylval.tsym.type != NULL)
2818 /* See if it's an ObjC classname. */
2819 if (parse_language->la_language == language_objc && !sym)
2821 CORE_ADDR Class = lookup_objc_class (parse_gdbarch, copy);
2824 yylval.class.class = Class;
2825 sym = lookup_struct_typedef (copy, expression_context_block, 1);
2827 yylval.class.type = SYMBOL_TYPE (sym);
2832 /* Input names that aren't symbols but ARE valid hex numbers, when
2833 the input radix permits them, can be names or numbers depending
2834 on the parse. Note we support radixes > 16 here. */
2836 && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10)
2837 || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10)))
2839 YYSTYPE newlval; /* Its value is ignored. */
2840 int hextype = parse_number (copy, yylval.sval.length, 0, &newlval);
2843 yylval.ssym.sym = sym;
2844 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
2849 /* Any other kind of symbol */
2850 yylval.ssym.sym = sym;
2851 yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
2854 && parse_language->la_language == language_cplus
2855 && is_a_field_of_this.type == NULL
2856 && !lookup_minimal_symbol (copy, NULL, NULL))
2857 return UNKNOWN_CPP_NAME;
2862 /* Like classify_name, but used by the inner loop of the lexer, when a
2863 name might have already been seen. FIRST_NAME is true if the token
2864 in `yylval' is the first component of a name, false otherwise. */
2867 classify_inner_name (const struct block *block, int first_name)
2869 struct type *type, *new_type;
2873 return classify_name (block);
2875 type = check_typedef (yylval.tsym.type);
2876 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2877 && TYPE_CODE (type) != TYPE_CODE_UNION
2878 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2881 copy = copy_name (yylval.tsym.stoken);
2882 yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
2883 if (yylval.ssym.sym == NULL)
2886 switch (SYMBOL_CLASS (yylval.ssym.sym))
2893 yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
2897 yylval.ssym.is_a_field_of_this = 0;
2900 internal_error (__FILE__, __LINE__, _("not reached"));
2903 /* The outer level of a two-level lexer. This calls the inner lexer
2904 to return tokens. It then either returns these tokens, or
2905 aggregates them into a larger token. This lets us work around a
2906 problem in our parsing approach, where the parser could not
2907 distinguish between qualified names and qualified types at the
2910 This approach is still not ideal, because it mishandles template
2911 types. See the comment in lex_one_token for an example. However,
2912 this is still an improvement over the earlier approach, and will
2913 suffice until we move to better parsing technology. */
2917 token_and_value current;
2918 int first_was_coloncolon, last_was_coloncolon, first_iter;
2920 if (popping && !VEC_empty (token_and_value, token_fifo))
2922 token_and_value tv = *VEC_index (token_and_value, token_fifo, 0);
2923 VEC_ordered_remove (token_and_value, token_fifo, 0);
2929 current.token = lex_one_token ();
2930 if (current.token == NAME)
2931 current.token = classify_name (expression_context_block);
2932 if (parse_language->la_language != language_cplus
2933 || (current.token != TYPENAME && current.token != COLONCOLON))
2934 return current.token;
2936 first_was_coloncolon = current.token == COLONCOLON;
2937 last_was_coloncolon = first_was_coloncolon;
2938 obstack_free (&name_obstack, obstack_base (&name_obstack));
2939 if (!last_was_coloncolon)
2940 obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2941 current.value = yylval;
2945 token_and_value next;
2947 next.token = lex_one_token ();
2948 next.value = yylval;
2950 if (next.token == NAME && last_was_coloncolon)
2954 classification = classify_inner_name (first_was_coloncolon
2956 : expression_context_block,
2958 /* We keep going until we either run out of names, or until
2959 we have a qualified name which is not a type. */
2960 if (classification != TYPENAME && classification != NAME)
2962 /* Push the final component and leave the loop. */
2963 VEC_safe_push (token_and_value, token_fifo, &next);
2967 /* Update the partial name we are constructing. */
2970 /* We don't want to put a leading "::" into the name. */
2971 obstack_grow_str (&name_obstack, "::");
2973 obstack_grow (&name_obstack, next.value.sval.ptr,
2974 next.value.sval.length);
2976 yylval.sval.ptr = obstack_base (&name_obstack);
2977 yylval.sval.length = obstack_object_size (&name_obstack);
2978 current.value = yylval;
2979 current.token = classification;
2981 last_was_coloncolon = 0;
2983 else if (next.token == COLONCOLON && !last_was_coloncolon)
2984 last_was_coloncolon = 1;
2987 /* We've reached the end of the name. */
2988 VEC_safe_push (token_and_value, token_fifo, &next);
2997 /* If we ended with a "::", insert it too. */
2998 if (last_was_coloncolon)
3001 memset (&cc, 0, sizeof (token_and_value));
3002 if (first_was_coloncolon && first_iter)
3007 cc.token = COLONCOLON;
3008 VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
3011 yylval = current.value;
3012 yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
3014 yylval.sval.length);
3015 return current.token;
3022 struct cleanup *back_to = make_cleanup (free_current_contents,
3023 &expression_macro_scope);
3025 /* Set up the scope for macro expansion. */
3026 expression_macro_scope = NULL;
3028 if (expression_context_block)
3029 expression_macro_scope
3030 = sal_macro_scope (find_pc_line (expression_context_pc, 0));
3032 expression_macro_scope = default_macro_scope ();
3033 if (! expression_macro_scope)
3034 expression_macro_scope = user_macro_scope ();
3036 /* Initialize macro expansion code. */
3037 obstack_init (&expansion_obstack);
3038 gdb_assert (! macro_original_text);
3039 make_cleanup (scan_macro_cleanup, 0);
3041 make_cleanup_restore_integer (&yydebug);
3042 yydebug = parser_debug;
3044 /* Initialize some state used by the lexer. */
3045 last_was_structop = 0;
3046 saw_name_at_eof = 0;
3048 VEC_free (token_and_value, token_fifo);
3050 obstack_init (&name_obstack);
3051 make_cleanup_obstack_free (&name_obstack);
3053 result = yyparse ();
3054 do_cleanups (back_to);
3063 lexptr = prev_lexptr;
3065 error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);