1 /* YACC parser for C expressions, for GDB.
2 Copyright (C) 1986-2013 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* Parse a C expression from text in a string,
20 and return the result as a struct expression pointer.
21 That structure contains arithmetic operations in reverse polish,
22 with constants represented by operations that are followed by special data.
23 See expression.h for the details of the format.
24 What is important here is that it can be built up sequentially
25 during the process of parsing; the lower levels of the tree always
26 come first in the result.
28 Note that malloc's and realloc's in this file are transformed to
29 xmalloc and xrealloc respectively by the same sed command in the
30 makefile that remaps any other malloc/realloc inserted by the parser
31 generator. Doing this with #defines and trying to control the interaction
32 with include files (<malloc.h> and <stdlib.h> for example) just became
33 too messy, particularly when such includes can be inserted at random
34 times by the parser generator. */
39 #include "gdb_string.h"
41 #include "expression.h"
43 #include "parser-defs.h"
46 #include "bfd.h" /* Required by objfiles.h. */
47 #include "symfile.h" /* Required by objfiles.h. */
48 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
51 #include "cp-support.h"
53 #include "gdb_assert.h"
54 #include "macroscope.h"
55 #include "objc-lang.h"
56 #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;
150 struct typed_stoken tsval;
152 struct symtoken ssym;
155 enum exp_opcode opcode;
157 struct stoken_vector svec;
158 VEC (type_ptr) *tvec;
160 struct type_stack *type_stack;
162 struct objc_class_str class;
166 /* YYSTYPE gets defined by %union */
167 static int parse_number (char *, int, int, YYSTYPE *);
168 static struct stoken operator_stoken (const char *);
169 static void check_parameter_typelist (VEC (type_ptr) *);
172 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
174 %type <tval> type typebase
175 %type <tvec> nonempty_typelist func_mod parameter_typelist
176 /* %type <bval> block */
178 /* Fancy type parsing. */
180 %type <lval> array_mod
181 %type <tval> conversion_type_id
183 %type <type_stack> ptr_operator_ts abs_decl direct_abs_decl
185 %token <typed_val_int> INT
186 %token <typed_val_float> FLOAT
187 %token <typed_val_decfloat> DECFLOAT
189 /* Both NAME and TYPENAME tokens represent symbols in the input,
190 and both convey their data as strings.
191 But a TYPENAME is a string that happens to be defined as a typedef
192 or builtin type name (such as int or char)
193 and a NAME is any other symbol.
194 Contexts where this distinction is not important can use the
195 nonterminal "name", which matches either NAME or TYPENAME. */
197 %token <tsval> STRING
198 %token <sval> NSSTRING /* ObjC Foundation "NSString" literal */
199 %token SELECTOR /* ObjC "@selector" pseudo-operator */
201 %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
202 %token <ssym> UNKNOWN_CPP_NAME
203 %token <voidval> COMPLETE
204 %token <tsym> TYPENAME
205 %token <class> CLASSNAME /* ObjC Class name */
207 %type <svec> string_exp
208 %type <ssym> name_not_typename
209 %type <tsym> typename
211 /* This is like a '[' token, but is only generated when parsing
212 Objective C. This lets us reuse the same parser without
213 erroneously parsing ObjC-specific expressions in C. */
216 /* A NAME_OR_INT is a symbol which is not known in the symbol table,
217 but which would parse as a valid number in the current input radix.
218 E.g. "c" when input_radix==16. Depending on the parse, it will be
219 turned into a name or into a number. */
221 %token <ssym> NAME_OR_INT
224 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
228 %type <sval> operator
229 %token REINTERPRET_CAST DYNAMIC_CAST STATIC_CAST CONST_CAST
234 /* Special type cases, put in to allow the parser to distinguish different
236 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
238 %token <sval> VARIABLE
240 %token <opcode> ASSIGN_MODIFY
249 %right '=' ASSIGN_MODIFY
257 %left '<' '>' LEQ GEQ
262 %right UNARY INCREMENT DECREMENT
263 %right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
264 %token <ssym> BLOCKNAME
265 %token <bval> FILENAME
279 { write_exp_elt_opcode(OP_TYPE);
280 write_exp_elt_type($1);
281 write_exp_elt_opcode(OP_TYPE);}
284 write_exp_elt_opcode (OP_TYPEOF);
286 | TYPEOF '(' type ')'
288 write_exp_elt_opcode (OP_TYPE);
289 write_exp_elt_type ($3);
290 write_exp_elt_opcode (OP_TYPE);
292 | DECLTYPE '(' exp ')'
294 write_exp_elt_opcode (OP_DECLTYPE);
298 /* Expressions, including the comma operator. */
301 { write_exp_elt_opcode (BINOP_COMMA); }
304 /* Expressions, not including the comma operator. */
305 exp : '*' exp %prec UNARY
306 { write_exp_elt_opcode (UNOP_IND); }
309 exp : '&' exp %prec UNARY
310 { write_exp_elt_opcode (UNOP_ADDR); }
313 exp : '-' exp %prec UNARY
314 { write_exp_elt_opcode (UNOP_NEG); }
317 exp : '+' exp %prec UNARY
318 { write_exp_elt_opcode (UNOP_PLUS); }
321 exp : '!' exp %prec UNARY
322 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
325 exp : '~' exp %prec UNARY
326 { write_exp_elt_opcode (UNOP_COMPLEMENT); }
329 exp : INCREMENT exp %prec UNARY
330 { write_exp_elt_opcode (UNOP_PREINCREMENT); }
333 exp : DECREMENT exp %prec UNARY
334 { write_exp_elt_opcode (UNOP_PREDECREMENT); }
337 exp : exp INCREMENT %prec UNARY
338 { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
341 exp : exp DECREMENT %prec UNARY
342 { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
345 exp : SIZEOF exp %prec UNARY
346 { write_exp_elt_opcode (UNOP_SIZEOF); }
350 { write_exp_elt_opcode (STRUCTOP_PTR);
351 write_exp_string ($3);
352 write_exp_elt_opcode (STRUCTOP_PTR); }
355 exp : exp ARROW name COMPLETE
356 { mark_struct_expression ();
357 write_exp_elt_opcode (STRUCTOP_PTR);
358 write_exp_string ($3);
359 write_exp_elt_opcode (STRUCTOP_PTR); }
362 exp : exp ARROW COMPLETE
364 mark_struct_expression ();
365 write_exp_elt_opcode (STRUCTOP_PTR);
368 write_exp_string (s);
369 write_exp_elt_opcode (STRUCTOP_PTR); }
372 exp : exp ARROW qualified_name
373 { /* exp->type::name becomes exp->*(&type::name) */
374 /* Note: this doesn't work if name is a
375 static member! FIXME */
376 write_exp_elt_opcode (UNOP_ADDR);
377 write_exp_elt_opcode (STRUCTOP_MPTR); }
380 exp : exp ARROW_STAR exp
381 { write_exp_elt_opcode (STRUCTOP_MPTR); }
385 { write_exp_elt_opcode (STRUCTOP_STRUCT);
386 write_exp_string ($3);
387 write_exp_elt_opcode (STRUCTOP_STRUCT); }
390 exp : exp '.' name COMPLETE
391 { mark_struct_expression ();
392 write_exp_elt_opcode (STRUCTOP_STRUCT);
393 write_exp_string ($3);
394 write_exp_elt_opcode (STRUCTOP_STRUCT); }
397 exp : exp '.' COMPLETE
399 mark_struct_expression ();
400 write_exp_elt_opcode (STRUCTOP_STRUCT);
403 write_exp_string (s);
404 write_exp_elt_opcode (STRUCTOP_STRUCT); }
407 exp : exp '.' qualified_name
408 { /* exp.type::name becomes exp.*(&type::name) */
409 /* Note: this doesn't work if name is a
410 static member! FIXME */
411 write_exp_elt_opcode (UNOP_ADDR);
412 write_exp_elt_opcode (STRUCTOP_MEMBER); }
415 exp : exp DOT_STAR exp
416 { write_exp_elt_opcode (STRUCTOP_MEMBER); }
419 exp : exp '[' exp1 ']'
420 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
423 exp : exp OBJC_LBRAC exp1 ']'
424 { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
428 * The rules below parse ObjC message calls of the form:
429 * '[' target selector {':' argument}* ']'
432 exp : OBJC_LBRAC TYPENAME
436 class = lookup_objc_class (parse_gdbarch,
437 copy_name ($2.stoken));
439 error (_("%s is not an ObjC Class"),
440 copy_name ($2.stoken));
441 write_exp_elt_opcode (OP_LONG);
442 write_exp_elt_type (parse_type->builtin_int);
443 write_exp_elt_longcst ((LONGEST) class);
444 write_exp_elt_opcode (OP_LONG);
448 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
450 write_exp_elt_opcode (OP_OBJC_MSGCALL);
454 exp : OBJC_LBRAC CLASSNAME
456 write_exp_elt_opcode (OP_LONG);
457 write_exp_elt_type (parse_type->builtin_int);
458 write_exp_elt_longcst ((LONGEST) $2.class);
459 write_exp_elt_opcode (OP_LONG);
463 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
465 write_exp_elt_opcode (OP_OBJC_MSGCALL);
472 { write_exp_elt_opcode (OP_OBJC_MSGCALL);
474 write_exp_elt_opcode (OP_OBJC_MSGCALL);
479 { add_msglist(&$1, 0); }
487 msgarg : name ':' exp
488 { add_msglist(&$1, 1); }
489 | ':' exp /* Unnamed arg. */
490 { add_msglist(0, 1); }
491 | ',' exp /* Variable number of args. */
492 { add_msglist(0, 0); }
496 /* This is to save the value of arglist_len
497 being accumulated by an outer function call. */
498 { start_arglist (); }
499 arglist ')' %prec ARROW
500 { write_exp_elt_opcode (OP_FUNCALL);
501 write_exp_elt_longcst ((LONGEST) end_arglist ());
502 write_exp_elt_opcode (OP_FUNCALL); }
505 exp : UNKNOWN_CPP_NAME '('
507 /* This could potentially be a an argument defined
508 lookup function (Koenig). */
509 write_exp_elt_opcode (OP_ADL_FUNC);
510 write_exp_elt_block (expression_context_block);
511 write_exp_elt_sym (NULL); /* Placeholder. */
512 write_exp_string ($1.stoken);
513 write_exp_elt_opcode (OP_ADL_FUNC);
515 /* This is to save the value of arglist_len
516 being accumulated by an outer function call. */
520 arglist ')' %prec ARROW
522 write_exp_elt_opcode (OP_FUNCALL);
523 write_exp_elt_longcst ((LONGEST) end_arglist ());
524 write_exp_elt_opcode (OP_FUNCALL);
529 { start_arglist (); }
539 arglist : arglist ',' exp %prec ABOVE_COMMA
543 exp : exp '(' parameter_typelist ')' const_or_volatile
545 VEC (type_ptr) *type_list = $3;
546 struct type *type_elt;
547 LONGEST len = VEC_length (type_ptr, type_list);
549 write_exp_elt_opcode (TYPE_INSTANCE);
550 write_exp_elt_longcst (len);
552 VEC_iterate (type_ptr, type_list, i, type_elt);
554 write_exp_elt_type (type_elt);
555 write_exp_elt_longcst(len);
556 write_exp_elt_opcode (TYPE_INSTANCE);
557 VEC_free (type_ptr, type_list);
562 { $$ = end_arglist () - 1; }
564 exp : lcurly arglist rcurly %prec ARROW
565 { write_exp_elt_opcode (OP_ARRAY);
566 write_exp_elt_longcst ((LONGEST) 0);
567 write_exp_elt_longcst ((LONGEST) $3);
568 write_exp_elt_opcode (OP_ARRAY); }
571 exp : lcurly type_exp rcurly exp %prec UNARY
572 { write_exp_elt_opcode (UNOP_MEMVAL_TYPE); }
575 exp : '(' type_exp ')' exp %prec UNARY
576 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
583 /* Binary operators in order of decreasing precedence. */
586 { write_exp_elt_opcode (BINOP_REPEAT); }
590 { write_exp_elt_opcode (BINOP_MUL); }
594 { write_exp_elt_opcode (BINOP_DIV); }
598 { write_exp_elt_opcode (BINOP_REM); }
602 { write_exp_elt_opcode (BINOP_ADD); }
606 { write_exp_elt_opcode (BINOP_SUB); }
610 { write_exp_elt_opcode (BINOP_LSH); }
614 { write_exp_elt_opcode (BINOP_RSH); }
618 { write_exp_elt_opcode (BINOP_EQUAL); }
621 exp : exp NOTEQUAL exp
622 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
626 { write_exp_elt_opcode (BINOP_LEQ); }
630 { write_exp_elt_opcode (BINOP_GEQ); }
634 { write_exp_elt_opcode (BINOP_LESS); }
638 { write_exp_elt_opcode (BINOP_GTR); }
642 { write_exp_elt_opcode (BINOP_BITWISE_AND); }
646 { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
650 { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
654 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
658 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
661 exp : exp '?' exp ':' exp %prec '?'
662 { write_exp_elt_opcode (TERNOP_COND); }
666 { write_exp_elt_opcode (BINOP_ASSIGN); }
669 exp : exp ASSIGN_MODIFY exp
670 { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
671 write_exp_elt_opcode ($2);
672 write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
676 { write_exp_elt_opcode (OP_LONG);
677 write_exp_elt_type ($1.type);
678 write_exp_elt_longcst ((LONGEST)($1.val));
679 write_exp_elt_opcode (OP_LONG); }
684 struct stoken_vector vec;
687 write_exp_string_vector ($1.type, &vec);
693 parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
694 write_exp_elt_opcode (OP_LONG);
695 write_exp_elt_type (val.typed_val_int.type);
696 write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
697 write_exp_elt_opcode (OP_LONG);
703 { write_exp_elt_opcode (OP_DOUBLE);
704 write_exp_elt_type ($1.type);
705 write_exp_elt_dblcst ($1.dval);
706 write_exp_elt_opcode (OP_DOUBLE); }
710 { write_exp_elt_opcode (OP_DECFLOAT);
711 write_exp_elt_type ($1.type);
712 write_exp_elt_decfloatcst ($1.val);
713 write_exp_elt_opcode (OP_DECFLOAT); }
721 write_dollar_variable ($1);
725 exp : SELECTOR '(' name ')'
727 write_exp_elt_opcode (OP_OBJC_SELECTOR);
728 write_exp_string ($3);
729 write_exp_elt_opcode (OP_OBJC_SELECTOR); }
732 exp : SIZEOF '(' type ')' %prec UNARY
733 { write_exp_elt_opcode (OP_LONG);
734 write_exp_elt_type (lookup_signed_typename
735 (parse_language, parse_gdbarch,
738 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
739 write_exp_elt_opcode (OP_LONG); }
742 exp : REINTERPRET_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
743 { write_exp_elt_opcode (UNOP_REINTERPRET_CAST); }
746 exp : STATIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
747 { write_exp_elt_opcode (UNOP_CAST_TYPE); }
750 exp : DYNAMIC_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
751 { write_exp_elt_opcode (UNOP_DYNAMIC_CAST); }
754 exp : CONST_CAST '<' type_exp '>' '(' exp ')' %prec UNARY
755 { /* We could do more error checking here, but
756 it doesn't seem worthwhile. */
757 write_exp_elt_opcode (UNOP_CAST_TYPE); }
763 /* We copy the string here, and not in the
764 lexer, to guarantee that we do not leak a
765 string. Note that we follow the
766 NUL-termination convention of the
768 struct typed_stoken *vec = XNEW (struct typed_stoken);
773 vec->length = $1.length;
774 vec->ptr = malloc ($1.length + 1);
775 memcpy (vec->ptr, $1.ptr, $1.length + 1);
780 /* Note that we NUL-terminate here, but just
784 $$.tokens = realloc ($$.tokens,
785 $$.len * sizeof (struct typed_stoken));
787 p = malloc ($2.length + 1);
788 memcpy (p, $2.ptr, $2.length + 1);
790 $$.tokens[$$.len - 1].type = $2.type;
791 $$.tokens[$$.len - 1].length = $2.length;
792 $$.tokens[$$.len - 1].ptr = p;
799 enum c_string_type type = C_STRING;
801 for (i = 0; i < $1.len; ++i)
803 switch ($1.tokens[i].type)
811 && type != $1.tokens[i].type)
812 error (_("Undefined string concatenation."));
813 type = $1.tokens[i].type;
817 internal_error (__FILE__, __LINE__,
818 "unrecognized type in string concatenation");
822 write_exp_string_vector (type, &$1);
823 for (i = 0; i < $1.len; ++i)
824 free ($1.tokens[i].ptr);
829 exp : NSSTRING /* ObjC NextStep NSString constant
830 * of the form '@' '"' string '"'.
832 { write_exp_elt_opcode (OP_OBJC_NSSTRING);
833 write_exp_string ($1);
834 write_exp_elt_opcode (OP_OBJC_NSSTRING); }
839 { write_exp_elt_opcode (OP_LONG);
840 write_exp_elt_type (parse_type->builtin_bool);
841 write_exp_elt_longcst ((LONGEST) 1);
842 write_exp_elt_opcode (OP_LONG); }
846 { write_exp_elt_opcode (OP_LONG);
847 write_exp_elt_type (parse_type->builtin_bool);
848 write_exp_elt_longcst ((LONGEST) 0);
849 write_exp_elt_opcode (OP_LONG); }
857 $$ = SYMBOL_BLOCK_VALUE ($1.sym);
859 error (_("No file or function \"%s\"."),
860 copy_name ($1.stoken));
868 block : block COLONCOLON name
870 = lookup_symbol (copy_name ($3), $1,
872 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
873 error (_("No function \"%s\" in specified context."),
875 $$ = SYMBOL_BLOCK_VALUE (tem); }
878 variable: name_not_typename ENTRY
879 { struct symbol *sym = $1.sym;
881 if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym)
882 || !symbol_read_needs_frame (sym))
883 error (_("@entry can be used only for function "
884 "parameters, not for \"%s\""),
885 copy_name ($1.stoken));
887 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
888 write_exp_elt_sym (sym);
889 write_exp_elt_opcode (OP_VAR_ENTRY_VALUE);
893 variable: block COLONCOLON name
894 { struct symbol *sym;
895 sym = lookup_symbol (copy_name ($3), $1,
898 error (_("No symbol \"%s\" in specified context."),
900 if (symbol_read_needs_frame (sym))
902 if (innermost_block == 0
903 || contained_in (block_found,
905 innermost_block = block_found;
908 write_exp_elt_opcode (OP_VAR_VALUE);
909 /* block_found is set by lookup_symbol. */
910 write_exp_elt_block (block_found);
911 write_exp_elt_sym (sym);
912 write_exp_elt_opcode (OP_VAR_VALUE); }
915 qualified_name: TYPENAME COLONCOLON name
917 struct type *type = $1.type;
918 CHECK_TYPEDEF (type);
919 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
920 && TYPE_CODE (type) != TYPE_CODE_UNION
921 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
922 error (_("`%s' is not defined as an aggregate type."),
923 TYPE_SAFE_NAME (type));
925 write_exp_elt_opcode (OP_SCOPE);
926 write_exp_elt_type (type);
927 write_exp_string ($3);
928 write_exp_elt_opcode (OP_SCOPE);
930 | TYPENAME COLONCOLON '~' name
932 struct type *type = $1.type;
933 struct stoken tmp_token;
934 CHECK_TYPEDEF (type);
935 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
936 && TYPE_CODE (type) != TYPE_CODE_UNION
937 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
938 error (_("`%s' is not defined as an aggregate type."),
939 TYPE_SAFE_NAME (type));
941 tmp_token.ptr = (char*) alloca ($4.length + 2);
942 tmp_token.length = $4.length + 1;
943 tmp_token.ptr[0] = '~';
944 memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
945 tmp_token.ptr[tmp_token.length] = 0;
947 /* Check for valid destructor name. */
948 destructor_name_p (tmp_token.ptr, $1.type);
949 write_exp_elt_opcode (OP_SCOPE);
950 write_exp_elt_type (type);
951 write_exp_string (tmp_token);
952 write_exp_elt_opcode (OP_SCOPE);
954 | TYPENAME COLONCOLON name COLONCOLON name
956 char *copy = copy_name ($3);
957 error (_("No type \"%s\" within class "
958 "or namespace \"%s\"."),
959 copy, TYPE_SAFE_NAME ($1.type));
963 variable: qualified_name
964 | COLONCOLON name_not_typename
966 char *name = copy_name ($2.stoken);
968 struct minimal_symbol *msymbol;
971 lookup_symbol (name, (const struct block *) NULL,
975 write_exp_elt_opcode (OP_VAR_VALUE);
976 write_exp_elt_block (NULL);
977 write_exp_elt_sym (sym);
978 write_exp_elt_opcode (OP_VAR_VALUE);
982 msymbol = lookup_minimal_symbol (name, NULL, NULL);
984 write_exp_msymbol (msymbol);
985 else if (!have_full_symbols () && !have_partial_symbols ())
986 error (_("No symbol table is loaded. Use the \"file\" command."));
988 error (_("No symbol \"%s\" in current context."), name);
992 variable: name_not_typename
993 { struct symbol *sym = $1.sym;
997 if (symbol_read_needs_frame (sym))
999 if (innermost_block == 0
1000 || contained_in (block_found,
1002 innermost_block = block_found;
1005 write_exp_elt_opcode (OP_VAR_VALUE);
1006 /* We want to use the selected frame, not
1007 another more inner frame which happens to
1008 be in the same block. */
1009 write_exp_elt_block (NULL);
1010 write_exp_elt_sym (sym);
1011 write_exp_elt_opcode (OP_VAR_VALUE);
1013 else if ($1.is_a_field_of_this)
1015 /* C++: it hangs off of `this'. Must
1016 not inadvertently convert from a method call
1018 if (innermost_block == 0
1019 || contained_in (block_found,
1021 innermost_block = block_found;
1022 write_exp_elt_opcode (OP_THIS);
1023 write_exp_elt_opcode (OP_THIS);
1024 write_exp_elt_opcode (STRUCTOP_PTR);
1025 write_exp_string ($1.stoken);
1026 write_exp_elt_opcode (STRUCTOP_PTR);
1030 struct minimal_symbol *msymbol;
1031 char *arg = copy_name ($1.stoken);
1034 lookup_minimal_symbol (arg, NULL, NULL);
1035 if (msymbol != NULL)
1036 write_exp_msymbol (msymbol);
1037 else if (!have_full_symbols () && !have_partial_symbols ())
1038 error (_("No symbol table is loaded. Use the \"file\" command."));
1040 error (_("No symbol \"%s\" in current context."),
1041 copy_name ($1.stoken));
1046 space_identifier : '@' NAME
1047 { insert_type_address_space (copy_name ($2.stoken)); }
1050 const_or_volatile: const_or_volatile_noopt
1054 cv_with_space_id : const_or_volatile space_identifier const_or_volatile
1057 const_or_volatile_or_space_identifier_noopt: cv_with_space_id
1058 | const_or_volatile_noopt
1061 const_or_volatile_or_space_identifier:
1062 const_or_volatile_or_space_identifier_noopt
1068 { insert_type (tp_pointer); }
1069 const_or_volatile_or_space_identifier
1071 { insert_type (tp_pointer); }
1072 const_or_volatile_or_space_identifier
1074 { insert_type (tp_reference); }
1076 { insert_type (tp_reference); }
1079 ptr_operator_ts: ptr_operator
1081 $$ = get_type_stack ();
1082 /* This cleanup is eventually run by
1084 make_cleanup (type_stack_cleanup, $$);
1088 abs_decl: ptr_operator_ts direct_abs_decl
1089 { $$ = append_type_stack ($2, $1); }
1094 direct_abs_decl: '(' abs_decl ')'
1096 | direct_abs_decl array_mod
1098 push_type_stack ($1);
1100 push_type (tp_array);
1101 $$ = get_type_stack ();
1106 push_type (tp_array);
1107 $$ = get_type_stack ();
1110 | direct_abs_decl func_mod
1112 push_type_stack ($1);
1114 $$ = get_type_stack ();
1119 $$ = get_type_stack ();
1129 | OBJC_LBRAC INT ']'
1135 | '(' parameter_typelist ')'
1139 /* We used to try to recognize pointer to member types here, but
1140 that didn't work (shift/reduce conflicts meant that these rules never
1141 got executed). The problem is that
1142 int (foo::bar::baz::bizzle)
1143 is a function type but
1144 int (foo::bar::baz::bizzle::*)
1145 is a pointer to member type. Stroustrup loses again! */
1150 typebase /* Implements (approximately): (type-qualifier)* type-specifier */
1154 { $$ = lookup_signed_typename (parse_language,
1158 { $$ = lookup_signed_typename (parse_language,
1162 { $$ = lookup_signed_typename (parse_language,
1166 { $$ = lookup_signed_typename (parse_language,
1169 | LONG SIGNED_KEYWORD INT_KEYWORD
1170 { $$ = lookup_signed_typename (parse_language,
1173 | LONG SIGNED_KEYWORD
1174 { $$ = lookup_signed_typename (parse_language,
1177 | SIGNED_KEYWORD LONG INT_KEYWORD
1178 { $$ = lookup_signed_typename (parse_language,
1181 | UNSIGNED LONG INT_KEYWORD
1182 { $$ = lookup_unsigned_typename (parse_language,
1185 | LONG UNSIGNED INT_KEYWORD
1186 { $$ = lookup_unsigned_typename (parse_language,
1190 { $$ = lookup_unsigned_typename (parse_language,
1194 { $$ = lookup_signed_typename (parse_language,
1197 | LONG LONG INT_KEYWORD
1198 { $$ = lookup_signed_typename (parse_language,
1201 | LONG LONG SIGNED_KEYWORD INT_KEYWORD
1202 { $$ = lookup_signed_typename (parse_language,
1205 | LONG LONG SIGNED_KEYWORD
1206 { $$ = lookup_signed_typename (parse_language,
1209 | SIGNED_KEYWORD LONG LONG
1210 { $$ = lookup_signed_typename (parse_language,
1213 | SIGNED_KEYWORD LONG LONG INT_KEYWORD
1214 { $$ = lookup_signed_typename (parse_language,
1217 | UNSIGNED LONG LONG
1218 { $$ = lookup_unsigned_typename (parse_language,
1221 | UNSIGNED LONG LONG INT_KEYWORD
1222 { $$ = lookup_unsigned_typename (parse_language,
1225 | LONG LONG UNSIGNED
1226 { $$ = lookup_unsigned_typename (parse_language,
1229 | LONG LONG UNSIGNED INT_KEYWORD
1230 { $$ = lookup_unsigned_typename (parse_language,
1234 { $$ = lookup_signed_typename (parse_language,
1237 | SHORT SIGNED_KEYWORD INT_KEYWORD
1238 { $$ = lookup_signed_typename (parse_language,
1241 | SHORT SIGNED_KEYWORD
1242 { $$ = lookup_signed_typename (parse_language,
1245 | UNSIGNED SHORT INT_KEYWORD
1246 { $$ = lookup_unsigned_typename (parse_language,
1250 { $$ = lookup_unsigned_typename (parse_language,
1253 | SHORT UNSIGNED INT_KEYWORD
1254 { $$ = lookup_unsigned_typename (parse_language,
1258 { $$ = lookup_typename (parse_language, parse_gdbarch,
1259 "double", (struct block *) NULL,
1261 | LONG DOUBLE_KEYWORD
1262 { $$ = lookup_typename (parse_language, parse_gdbarch,
1264 (struct block *) NULL, 0); }
1266 { $$ = lookup_struct (copy_name ($2),
1267 expression_context_block); }
1270 mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
1273 | STRUCT name COMPLETE
1275 mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
1280 { $$ = lookup_struct (copy_name ($2),
1281 expression_context_block); }
1284 mark_completion_tag (TYPE_CODE_CLASS, "", 0);
1287 | CLASS name COMPLETE
1289 mark_completion_tag (TYPE_CODE_CLASS, $2.ptr,
1294 { $$ = lookup_union (copy_name ($2),
1295 expression_context_block); }
1298 mark_completion_tag (TYPE_CODE_UNION, "", 0);
1301 | UNION name COMPLETE
1303 mark_completion_tag (TYPE_CODE_UNION, $2.ptr,
1308 { $$ = lookup_enum (copy_name ($2),
1309 expression_context_block); }
1312 mark_completion_tag (TYPE_CODE_ENUM, "", 0);
1315 | ENUM name COMPLETE
1317 mark_completion_tag (TYPE_CODE_ENUM, $2.ptr,
1322 { $$ = lookup_unsigned_typename (parse_language,
1324 TYPE_NAME($2.type)); }
1326 { $$ = lookup_unsigned_typename (parse_language,
1329 | SIGNED_KEYWORD typename
1330 { $$ = lookup_signed_typename (parse_language,
1332 TYPE_NAME($2.type)); }
1334 { $$ = lookup_signed_typename (parse_language,
1337 /* It appears that this rule for templates is never
1338 reduced; template recognition happens by lookahead
1339 in the token processing code in yylex. */
1340 | TEMPLATE name '<' type '>'
1341 { $$ = lookup_template_type(copy_name($2), $4,
1342 expression_context_block);
1344 | const_or_volatile_or_space_identifier_noopt typebase
1345 { $$ = follow_types ($2); }
1346 | typebase const_or_volatile_or_space_identifier_noopt
1347 { $$ = follow_types ($1); }
1353 $$.stoken.ptr = "int";
1354 $$.stoken.length = 3;
1355 $$.type = lookup_signed_typename (parse_language,
1361 $$.stoken.ptr = "long";
1362 $$.stoken.length = 4;
1363 $$.type = lookup_signed_typename (parse_language,
1369 $$.stoken.ptr = "short";
1370 $$.stoken.length = 5;
1371 $$.type = lookup_signed_typename (parse_language,
1379 { check_parameter_typelist ($1); }
1380 | nonempty_typelist ',' DOTDOTDOT
1382 VEC_safe_push (type_ptr, $1, NULL);
1383 check_parameter_typelist ($1);
1391 VEC (type_ptr) *typelist = NULL;
1392 VEC_safe_push (type_ptr, typelist, $1);
1395 | nonempty_typelist ',' type
1397 VEC_safe_push (type_ptr, $1, $3);
1405 push_type_stack ($2);
1406 $$ = follow_types ($1);
1410 conversion_type_id: typebase conversion_declarator
1411 { $$ = follow_types ($1); }
1414 conversion_declarator: /* Nothing. */
1415 | ptr_operator conversion_declarator
1418 const_and_volatile: CONST_KEYWORD VOLATILE_KEYWORD
1419 | VOLATILE_KEYWORD CONST_KEYWORD
1422 const_or_volatile_noopt: const_and_volatile
1423 { insert_type (tp_const);
1424 insert_type (tp_volatile);
1427 { insert_type (tp_const); }
1429 { insert_type (tp_volatile); }
1432 operator: OPERATOR NEW
1433 { $$ = operator_stoken (" new"); }
1435 { $$ = operator_stoken (" delete"); }
1436 | OPERATOR NEW '[' ']'
1437 { $$ = operator_stoken (" new[]"); }
1438 | OPERATOR DELETE '[' ']'
1439 { $$ = operator_stoken (" delete[]"); }
1440 | OPERATOR NEW OBJC_LBRAC ']'
1441 { $$ = operator_stoken (" new[]"); }
1442 | OPERATOR DELETE OBJC_LBRAC ']'
1443 { $$ = operator_stoken (" delete[]"); }
1445 { $$ = operator_stoken ("+"); }
1447 { $$ = operator_stoken ("-"); }
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 (">"); }
1470 | OPERATOR ASSIGN_MODIFY
1471 { const char *op = "unknown";
1495 case BINOP_BITWISE_IOR:
1498 case BINOP_BITWISE_AND:
1501 case BINOP_BITWISE_XOR:
1508 $$ = operator_stoken (op);
1511 { $$ = operator_stoken ("<<"); }
1513 { $$ = operator_stoken (">>"); }
1515 { $$ = operator_stoken ("=="); }
1517 { $$ = operator_stoken ("!="); }
1519 { $$ = operator_stoken ("<="); }
1521 { $$ = operator_stoken (">="); }
1523 { $$ = operator_stoken ("&&"); }
1525 { $$ = operator_stoken ("||"); }
1526 | OPERATOR INCREMENT
1527 { $$ = operator_stoken ("++"); }
1528 | OPERATOR DECREMENT
1529 { $$ = operator_stoken ("--"); }
1531 { $$ = operator_stoken (","); }
1532 | OPERATOR ARROW_STAR
1533 { $$ = operator_stoken ("->*"); }
1535 { $$ = operator_stoken ("->"); }
1537 { $$ = operator_stoken ("()"); }
1539 { $$ = operator_stoken ("[]"); }
1540 | OPERATOR OBJC_LBRAC ']'
1541 { $$ = operator_stoken ("[]"); }
1542 | OPERATOR conversion_type_id
1545 struct ui_file *buf = mem_fileopen ();
1547 c_print_type ($2, NULL, buf, -1, 0,
1548 &type_print_raw_options);
1549 name = ui_file_xstrdup (buf, &length);
1550 ui_file_delete (buf);
1551 $$ = operator_stoken (name);
1558 name : NAME { $$ = $1.stoken; }
1559 | BLOCKNAME { $$ = $1.stoken; }
1560 | TYPENAME { $$ = $1.stoken; }
1561 | NAME_OR_INT { $$ = $1.stoken; }
1562 | UNKNOWN_CPP_NAME { $$ = $1.stoken; }
1563 | operator { $$ = $1; }
1566 name_not_typename : NAME
1568 /* These would be useful if name_not_typename was useful, but it is just
1569 a fake for "variable", so these cause reduce/reduce conflicts because
1570 the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
1571 =exp) or just an exp. If name_not_typename was ever used in an lvalue
1572 context where only a name could occur, this might be useful.
1577 struct field_of_this_result is_a_field_of_this;
1580 $$.sym = lookup_symbol ($1.ptr,
1581 expression_context_block,
1583 &is_a_field_of_this);
1584 $$.is_a_field_of_this
1585 = is_a_field_of_this.type != NULL;
1592 /* Returns a stoken of the operator name given by OP (which does not
1593 include the string "operator"). */
1594 static struct stoken
1595 operator_stoken (const char *op)
1597 static const char *operator_string = "operator";
1598 struct stoken st = { NULL, 0 };
1599 st.length = strlen (operator_string) + strlen (op);
1600 st.ptr = malloc (st.length + 1);
1601 strcpy (st.ptr, operator_string);
1602 strcat (st.ptr, op);
1604 /* The toplevel (c_parse) will free the memory allocated here. */
1605 make_cleanup (free, st.ptr);
1609 /* Validate a parameter typelist. */
1612 check_parameter_typelist (VEC (type_ptr) *params)
1617 for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix)
1619 if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
1623 if (VEC_length (type_ptr, params) == 1)
1628 VEC_free (type_ptr, params);
1629 error (_("parameter types following 'void'"));
1633 VEC_free (type_ptr, params);
1634 error (_("'void' invalid as parameter type"));
1640 /* Take care of parsing a number (anything that starts with a digit).
1641 Set yylval and return the token type; update lexptr.
1642 LEN is the number of characters in it. */
1644 /*** Needs some error checking for the float case ***/
1647 parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
1649 /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
1650 here, and we do kind of silly things like cast to unsigned. */
1657 int base = input_radix;
1660 /* Number of "L" suffixes encountered. */
1663 /* We have found a "L" or "U" suffix. */
1664 int found_suffix = 0;
1667 struct type *signed_type;
1668 struct type *unsigned_type;
1672 /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
1673 point. Return DECFLOAT. */
1675 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
1678 putithere->typed_val_decfloat.type
1679 = parse_type->builtin_decfloat;
1680 decimal_from_string (putithere->typed_val_decfloat.val, 4,
1681 gdbarch_byte_order (parse_gdbarch), p);
1686 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
1689 putithere->typed_val_decfloat.type
1690 = parse_type->builtin_decdouble;
1691 decimal_from_string (putithere->typed_val_decfloat.val, 8,
1692 gdbarch_byte_order (parse_gdbarch), p);
1697 if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
1700 putithere->typed_val_decfloat.type
1701 = parse_type->builtin_declong;
1702 decimal_from_string (putithere->typed_val_decfloat.val, 16,
1703 gdbarch_byte_order (parse_gdbarch), p);
1708 if (! parse_c_float (parse_gdbarch, p, len,
1709 &putithere->typed_val_float.dval,
1710 &putithere->typed_val_float.type))
1715 /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1759 if (c >= 'A' && c <= 'Z')
1761 if (c != 'l' && c != 'u')
1763 if (c >= '0' && c <= '9')
1771 if (base > 10 && c >= 'a' && c <= 'f')
1775 n += i = c - 'a' + 10;
1788 return ERROR; /* Char not a digit */
1791 return ERROR; /* Invalid digit in this base */
1793 /* Portably test for overflow (only works for nonzero values, so make
1794 a second check for zero). FIXME: Can't we just make n and prevn
1795 unsigned and avoid this? */
1796 if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1797 unsigned_p = 1; /* Try something unsigned */
1799 /* Portably test for unsigned overflow.
1800 FIXME: This check is wrong; for example it doesn't find overflow
1801 on 0x123456789 when LONGEST is 32 bits. */
1802 if (c != 'l' && c != 'u' && n != 0)
1804 if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1805 error (_("Numeric constant too large."));
1810 /* An integer constant is an int, a long, or a long long. An L
1811 suffix forces it to be long; an LL suffix forces it to be long
1812 long. If not forced to a larger size, it gets the first type of
1813 the above that it fits in. To figure out whether it fits, we
1814 shift it right and see whether anything remains. Note that we
1815 can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1816 operation, because many compilers will warn about such a shift
1817 (which always produces a zero result). Sometimes gdbarch_int_bit
1818 or gdbarch_long_bit will be that big, sometimes not. To deal with
1819 the case where it is we just always shift the value more than
1820 once, with fewer bits each time. */
1822 un = (ULONGEST)n >> 2;
1824 && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
1826 high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
1828 /* A large decimal (not hex or octal) constant (between INT_MAX
1829 and UINT_MAX) is a long or unsigned long, according to ANSI,
1830 never an unsigned int, but this code treats it as unsigned
1831 int. This probably should be fixed. GCC gives a warning on
1834 unsigned_type = parse_type->builtin_unsigned_int;
1835 signed_type = parse_type->builtin_int;
1837 else if (long_p <= 1
1838 && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
1840 high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
1841 unsigned_type = parse_type->builtin_unsigned_long;
1842 signed_type = parse_type->builtin_long;
1847 if (sizeof (ULONGEST) * HOST_CHAR_BIT
1848 < gdbarch_long_long_bit (parse_gdbarch))
1849 /* A long long does not fit in a LONGEST. */
1850 shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1852 shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
1853 high_bit = (ULONGEST) 1 << shift;
1854 unsigned_type = parse_type->builtin_unsigned_long_long;
1855 signed_type = parse_type->builtin_long_long;
1858 putithere->typed_val_int.val = n;
1860 /* If the high bit of the worked out type is set then this number
1861 has to be unsigned. */
1863 if (unsigned_p || (n & high_bit))
1865 putithere->typed_val_int.type = unsigned_type;
1869 putithere->typed_val_int.type = signed_type;
1875 /* Temporary obstack used for holding strings. */
1876 static struct obstack tempbuf;
1877 static int tempbuf_init;
1879 /* Parse a C escape sequence. The initial backslash of the sequence
1880 is at (*PTR)[-1]. *PTR will be updated to point to just after the
1881 last character of the sequence. If OUTPUT is not NULL, the
1882 translated form of the escape sequence will be written there. If
1883 OUTPUT is NULL, no output is written and the call will only affect
1884 *PTR. If an escape sequence is expressed in target bytes, then the
1885 entire sequence will simply be copied to OUTPUT. Return 1 if any
1886 character was emitted, 0 otherwise. */
1889 c_parse_escape (char **ptr, struct obstack *output)
1891 char *tokptr = *ptr;
1894 /* Some escape sequences undergo character set conversion. Those we
1898 /* Hex escapes do not undergo character set conversion, so keep
1899 the escape sequence for later. */
1902 obstack_grow_str (output, "\\x");
1904 if (!isxdigit (*tokptr))
1905 error (_("\\x escape without a following hex digit"));
1906 while (isxdigit (*tokptr))
1909 obstack_1grow (output, *tokptr);
1914 /* Octal escapes do not undergo character set conversion, so
1915 keep the escape sequence for later. */
1927 obstack_grow_str (output, "\\");
1929 i < 3 && isdigit (*tokptr) && *tokptr != '8' && *tokptr != '9';
1933 obstack_1grow (output, *tokptr);
1939 /* We handle UCNs later. We could handle them here, but that
1940 would mean a spurious error in the case where the UCN could
1941 be converted to the target charset but not the host
1947 int i, len = c == 'U' ? 8 : 4;
1950 obstack_1grow (output, '\\');
1951 obstack_1grow (output, *tokptr);
1954 if (!isxdigit (*tokptr))
1955 error (_("\\%c escape without a following hex digit"), c);
1956 for (i = 0; i < len && isxdigit (*tokptr); ++i)
1959 obstack_1grow (output, *tokptr);
1965 /* We must pass backslash through so that it does not
1966 cause quoting during the second expansion. */
1969 obstack_grow_str (output, "\\\\");
1973 /* Escapes which undergo conversion. */
1976 obstack_1grow (output, '\a');
1981 obstack_1grow (output, '\b');
1986 obstack_1grow (output, '\f');
1991 obstack_1grow (output, '\n');
1996 obstack_1grow (output, '\r');
2001 obstack_1grow (output, '\t');
2006 obstack_1grow (output, '\v');
2010 /* GCC extension. */
2013 obstack_1grow (output, HOST_ESCAPE_CHAR);
2017 /* Backslash-newline expands to nothing at all. */
2023 /* A few escapes just expand to the character itself. */
2027 /* GCC extensions. */
2032 /* Unrecognized escapes turn into the character itself. */
2035 obstack_1grow (output, *tokptr);
2043 /* Parse a string or character literal from TOKPTR. The string or
2044 character may be wide or unicode. *OUTPTR is set to just after the
2045 end of the literal in the input string. The resulting token is
2046 stored in VALUE. This returns a token value, either STRING or
2047 CHAR, depending on what was parsed. *HOST_CHARS is set to the
2048 number of host characters in the literal. */
2050 parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
2054 enum c_string_type type;
2057 /* Build the gdb internal form of the input string in tempbuf. Note
2058 that the buffer is null byte terminated *only* for the
2059 convenience of debugging gdb itself and printing the buffer
2060 contents when the buffer contains no embedded nulls. Gdb does
2061 not depend upon the buffer being null byte terminated, it uses
2062 the length string instead. This allows gdb to handle C strings
2063 (as well as strings in other languages) with embedded null
2069 obstack_free (&tempbuf, NULL);
2070 obstack_init (&tempbuf);
2072 /* Record the string type. */
2075 type = C_WIDE_STRING;
2078 else if (*tokptr == 'u')
2083 else if (*tokptr == 'U')
2088 else if (*tokptr == '@')
2090 /* An Objective C string. */
2098 /* Skip the quote. */
2112 *host_chars += c_parse_escape (&tokptr, &tempbuf);
2114 else if (c == quote)
2118 obstack_1grow (&tempbuf, c);
2120 /* FIXME: this does the wrong thing with multi-byte host
2121 characters. We could use mbrlen here, but that would
2122 make "set host-charset" a bit less useful. */
2127 if (*tokptr != quote)
2130 error (_("Unterminated string in expression."));
2132 error (_("Unmatched single quote."));
2137 value->ptr = obstack_base (&tempbuf);
2138 value->length = obstack_object_size (&tempbuf);
2142 return quote == '"' ? (is_objc ? NSSTRING : STRING) : CHAR;
2145 /* This is used to associate some attributes with a token. */
2149 /* If this bit is set, the token is C++-only. */
2153 /* If this bit is set, the token is conditional: if there is a
2154 symbol of the same name, then the token is a symbol; otherwise,
2155 the token is a keyword. */
2164 enum exp_opcode opcode;
2165 enum token_flags flags;
2168 static const struct token tokentab3[] =
2170 {">>=", ASSIGN_MODIFY, BINOP_RSH, 0},
2171 {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0},
2172 {"->*", ARROW_STAR, BINOP_END, FLAG_CXX},
2173 {"...", DOTDOTDOT, BINOP_END, 0}
2176 static const struct token tokentab2[] =
2178 {"+=", ASSIGN_MODIFY, BINOP_ADD, 0},
2179 {"-=", ASSIGN_MODIFY, BINOP_SUB, 0},
2180 {"*=", ASSIGN_MODIFY, BINOP_MUL, 0},
2181 {"/=", ASSIGN_MODIFY, BINOP_DIV, 0},
2182 {"%=", ASSIGN_MODIFY, BINOP_REM, 0},
2183 {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0},
2184 {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0},
2185 {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0},
2186 {"++", INCREMENT, BINOP_END, 0},
2187 {"--", DECREMENT, BINOP_END, 0},
2188 {"->", ARROW, BINOP_END, 0},
2189 {"&&", ANDAND, BINOP_END, 0},
2190 {"||", OROR, BINOP_END, 0},
2191 /* "::" is *not* only C++: gdb overrides its meaning in several
2192 different ways, e.g., 'filename'::func, function::variable. */
2193 {"::", COLONCOLON, BINOP_END, 0},
2194 {"<<", LSH, BINOP_END, 0},
2195 {">>", RSH, BINOP_END, 0},
2196 {"==", EQUAL, BINOP_END, 0},
2197 {"!=", NOTEQUAL, BINOP_END, 0},
2198 {"<=", LEQ, BINOP_END, 0},
2199 {">=", GEQ, BINOP_END, 0},
2200 {".*", DOT_STAR, BINOP_END, FLAG_CXX}
2203 /* Identifier-like tokens. */
2204 static const struct token ident_tokens[] =
2206 {"unsigned", UNSIGNED, OP_NULL, 0},
2207 {"template", TEMPLATE, OP_NULL, FLAG_CXX},
2208 {"volatile", VOLATILE_KEYWORD, OP_NULL, 0},
2209 {"struct", STRUCT, OP_NULL, 0},
2210 {"signed", SIGNED_KEYWORD, OP_NULL, 0},
2211 {"sizeof", SIZEOF, OP_NULL, 0},
2212 {"double", DOUBLE_KEYWORD, OP_NULL, 0},
2213 {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
2214 {"class", CLASS, OP_NULL, FLAG_CXX},
2215 {"union", UNION, OP_NULL, 0},
2216 {"short", SHORT, OP_NULL, 0},
2217 {"const", CONST_KEYWORD, OP_NULL, 0},
2218 {"enum", ENUM, OP_NULL, 0},
2219 {"long", LONG, OP_NULL, 0},
2220 {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
2221 {"int", INT_KEYWORD, OP_NULL, 0},
2222 {"new", NEW, OP_NULL, FLAG_CXX},
2223 {"delete", DELETE, OP_NULL, FLAG_CXX},
2224 {"operator", OPERATOR, OP_NULL, FLAG_CXX},
2226 {"and", ANDAND, BINOP_END, FLAG_CXX},
2227 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
2228 {"bitand", '&', OP_NULL, FLAG_CXX},
2229 {"bitor", '|', OP_NULL, FLAG_CXX},
2230 {"compl", '~', OP_NULL, FLAG_CXX},
2231 {"not", '!', OP_NULL, FLAG_CXX},
2232 {"not_eq", NOTEQUAL, BINOP_END, FLAG_CXX},
2233 {"or", OROR, BINOP_END, FLAG_CXX},
2234 {"or_eq", ASSIGN_MODIFY, BINOP_BITWISE_IOR, FLAG_CXX},
2235 {"xor", '^', OP_NULL, FLAG_CXX},
2236 {"xor_eq", ASSIGN_MODIFY, BINOP_BITWISE_XOR, FLAG_CXX},
2238 {"const_cast", CONST_CAST, OP_NULL, FLAG_CXX },
2239 {"dynamic_cast", DYNAMIC_CAST, OP_NULL, FLAG_CXX },
2240 {"static_cast", STATIC_CAST, OP_NULL, FLAG_CXX },
2241 {"reinterpret_cast", REINTERPRET_CAST, OP_NULL, FLAG_CXX },
2243 {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
2244 {"__typeof", TYPEOF, OP_TYPEOF, 0 },
2245 {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
2246 {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
2247 {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW }
2250 /* When we find that lexptr (the global var defined in parse.c) is
2251 pointing at a macro invocation, we expand the invocation, and call
2252 scan_macro_expansion to save the old lexptr here and point lexptr
2253 into the expanded text. When we reach the end of that, we call
2254 end_macro_expansion to pop back to the value we saved here. The
2255 macro expansion code promises to return only fully-expanded text,
2256 so we don't need to "push" more than one level.
2258 This is disgusting, of course. It would be cleaner to do all macro
2259 expansion beforehand, and then hand that to lexptr. But we don't
2260 really know where the expression ends. Remember, in a command like
2262 (gdb) break *ADDRESS if CONDITION
2264 we evaluate ADDRESS in the scope of the current frame, but we
2265 evaluate CONDITION in the scope of the breakpoint's location. So
2266 it's simply wrong to try to macro-expand the whole thing at once. */
2267 static char *macro_original_text;
2269 /* We save all intermediate macro expansions on this obstack for the
2270 duration of a single parse. The expansion text may sometimes have
2271 to live past the end of the expansion, due to yacc lookahead.
2272 Rather than try to be clever about saving the data for a single
2273 token, we simply keep it all and delete it after parsing has
2275 static struct obstack expansion_obstack;
2278 scan_macro_expansion (char *expansion)
2282 /* We'd better not be trying to push the stack twice. */
2283 gdb_assert (! macro_original_text);
2285 /* Copy to the obstack, and then free the intermediate
2287 copy = obstack_copy0 (&expansion_obstack, expansion, strlen (expansion));
2290 /* Save the old lexptr value, so we can return to it when we're done
2291 parsing the expanded text. */
2292 macro_original_text = lexptr;
2298 scanning_macro_expansion (void)
2300 return macro_original_text != 0;
2305 finished_macro_expansion (void)
2307 /* There'd better be something to pop back to. */
2308 gdb_assert (macro_original_text);
2310 /* Pop back to the original text. */
2311 lexptr = macro_original_text;
2312 macro_original_text = 0;
2317 scan_macro_cleanup (void *dummy)
2319 if (macro_original_text)
2320 finished_macro_expansion ();
2322 obstack_free (&expansion_obstack, NULL);
2325 /* Return true iff the token represents a C++ cast operator. */
2328 is_cast_operator (const char *token, int len)
2330 return (! strncmp (token, "dynamic_cast", len)
2331 || ! strncmp (token, "static_cast", len)
2332 || ! strncmp (token, "reinterpret_cast", len)
2333 || ! strncmp (token, "const_cast", len));
2336 /* The scope used for macro expansion. */
2337 static struct macro_scope *expression_macro_scope;
2339 /* This is set if a NAME token appeared at the very end of the input
2340 string, with no whitespace separating the name from the EOF. This
2341 is used only when parsing to do field name completion. */
2342 static int saw_name_at_eof;
2344 /* This is set if the previously-returned token was a structure
2345 operator -- either '.' or ARROW. This is used only when parsing to
2346 do field name completion. */
2347 static int last_was_structop;
2349 /* Read one token, getting characters through lexptr. */
2352 lex_one_token (void)
2358 int saw_structop = last_was_structop;
2361 last_was_structop = 0;
2365 /* Check if this is a macro invocation that we need to expand. */
2366 if (! scanning_macro_expansion ())
2368 char *expanded = macro_expand_next (&lexptr,
2369 standard_macro_lookup,
2370 expression_macro_scope);
2373 scan_macro_expansion (expanded);
2376 prev_lexptr = lexptr;
2379 /* See if it is a special token of length 3. */
2380 for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
2381 if (strncmp (tokstart, tokentab3[i].operator, 3) == 0)
2383 if ((tokentab3[i].flags & FLAG_CXX) != 0
2384 && parse_language->la_language != language_cplus)
2388 yylval.opcode = tokentab3[i].opcode;
2389 return tokentab3[i].token;
2392 /* See if it is a special token of length 2. */
2393 for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
2394 if (strncmp (tokstart, tokentab2[i].operator, 2) == 0)
2396 if ((tokentab2[i].flags & FLAG_CXX) != 0
2397 && parse_language->la_language != language_cplus)
2401 yylval.opcode = tokentab2[i].opcode;
2402 if (parse_completion && tokentab2[i].token == ARROW)
2403 last_was_structop = 1;
2404 return tokentab2[i].token;
2407 switch (c = *tokstart)
2410 /* If we were just scanning the result of a macro expansion,
2411 then we need to resume scanning the original text.
2412 If we're parsing for field name completion, and the previous
2413 token allows such completion, return a COMPLETE token.
2414 Otherwise, we were already scanning the original text, and
2415 we're really done. */
2416 if (scanning_macro_expansion ())
2418 finished_macro_expansion ();
2421 else if (saw_name_at_eof)
2423 saw_name_at_eof = 0;
2426 else if (saw_structop)
2441 if (parse_language->la_language == language_objc && c == '[')
2447 if (paren_depth == 0)
2454 if (comma_terminates
2456 && ! scanning_macro_expansion ())
2462 /* Might be a floating point number. */
2463 if (lexptr[1] < '0' || lexptr[1] > '9')
2465 if (parse_completion)
2466 last_was_structop = 1;
2467 goto symbol; /* Nope, must be a symbol. */
2469 /* FALL THRU into number case. */
2482 /* It's a number. */
2483 int got_dot = 0, got_e = 0, toktype;
2485 int hex = input_radix > 10;
2487 if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
2492 else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
2500 /* This test includes !hex because 'e' is a valid hex digit
2501 and thus does not indicate a floating point number when
2502 the radix is hex. */
2503 if (!hex && !got_e && (*p == 'e' || *p == 'E'))
2504 got_dot = got_e = 1;
2505 /* This test does not include !hex, because a '.' always indicates
2506 a decimal floating point number regardless of the radix. */
2507 else if (!got_dot && *p == '.')
2509 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
2510 && (*p == '-' || *p == '+'))
2511 /* This is the sign of the exponent, not the end of the
2514 /* We will take any letters or digits. parse_number will
2515 complain if past the radix, or if L or U are not final. */
2516 else if ((*p < '0' || *p > '9')
2517 && ((*p < 'a' || *p > 'z')
2518 && (*p < 'A' || *p > 'Z')))
2521 toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
2522 if (toktype == ERROR)
2524 char *err_copy = (char *) alloca (p - tokstart + 1);
2526 memcpy (err_copy, tokstart, p - tokstart);
2527 err_copy[p - tokstart] = 0;
2528 error (_("Invalid number \"%s\"."), err_copy);
2536 char *p = &tokstart[1];
2537 size_t len = strlen ("entry");
2539 if (parse_language->la_language == language_objc)
2541 size_t len = strlen ("selector");
2543 if (strncmp (p, "selector", len) == 0
2544 && (p[len] == '\0' || isspace (p[len])))
2553 while (isspace (*p))
2555 if (strncmp (p, "entry", len) == 0 && !isalnum (p[len])
2587 if (tokstart[1] != '"' && tokstart[1] != '\'')
2596 int result = parse_string_or_char (tokstart, &lexptr, &yylval.tsval,
2601 error (_("Empty character constant."));
2602 else if (host_len > 2 && c == '\'')
2605 namelen = lexptr - tokstart - 1;
2608 else if (host_len > 1)
2609 error (_("Invalid character constant."));
2615 if (!(c == '_' || c == '$'
2616 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
2617 /* We must have come across a bad character (e.g. ';'). */
2618 error (_("Invalid character '%c' in expression."), c);
2620 /* It's a name. See how long it is. */
2622 for (c = tokstart[namelen];
2623 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2624 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2626 /* Template parameter lists are part of the name.
2627 FIXME: This mishandles `print $a<4&&$a>3'. */
2631 if (! is_cast_operator (tokstart, namelen))
2633 /* Scan ahead to get rest of the template specification. Note
2634 that we look ahead only when the '<' adjoins non-whitespace
2635 characters; for comparison expressions, e.g. "a < b > c",
2636 there must be spaces before the '<', etc. */
2638 char * p = find_template_name_end (tokstart + namelen);
2640 namelen = p - tokstart;
2644 c = tokstart[++namelen];
2647 /* The token "if" terminates the expression and is NOT removed from
2648 the input stream. It doesn't count if it appears in the
2649 expansion of a macro. */
2651 && tokstart[0] == 'i'
2652 && tokstart[1] == 'f'
2653 && ! scanning_macro_expansion ())
2658 /* For the same reason (breakpoint conditions), "thread N"
2659 terminates the expression. "thread" could be an identifier, but
2660 an identifier is never followed by a number without intervening
2661 punctuation. "task" is similar. Handle abbreviations of these,
2662 similarly to breakpoint.c:find_condition_and_thread. */
2664 && (strncmp (tokstart, "thread", namelen) == 0
2665 || strncmp (tokstart, "task", namelen) == 0)
2666 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
2667 && ! scanning_macro_expansion ())
2669 char *p = tokstart + namelen + 1;
2670 while (*p == ' ' || *p == '\t')
2672 if (*p >= '0' && *p <= '9')
2680 yylval.sval.ptr = tokstart;
2681 yylval.sval.length = namelen;
2683 /* Catch specific keywords. */
2684 copy = copy_name (yylval.sval);
2685 for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++)
2686 if (strcmp (copy, ident_tokens[i].operator) == 0)
2688 if ((ident_tokens[i].flags & FLAG_CXX) != 0
2689 && parse_language->la_language != language_cplus)
2692 if ((ident_tokens[i].flags & FLAG_SHADOW) != 0)
2694 struct field_of_this_result is_a_field_of_this;
2696 if (lookup_symbol (copy, expression_context_block,
2698 (parse_language->la_language == language_cplus
2699 ? &is_a_field_of_this
2703 /* The keyword is shadowed. */
2708 /* It is ok to always set this, even though we don't always
2709 strictly need to. */
2710 yylval.opcode = ident_tokens[i].opcode;
2711 return ident_tokens[i].token;
2714 if (*tokstart == '$')
2717 if (parse_completion && *lexptr == '\0')
2718 saw_name_at_eof = 1;
2720 yylval.ssym.stoken = yylval.sval;
2721 yylval.ssym.sym = NULL;
2722 yylval.ssym.is_a_field_of_this = 0;
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. CONTEXT is the context type, or
2864 NULL if this is the first component of a name. */
2867 classify_inner_name (const struct block *block, struct type *context)
2872 if (context == NULL)
2873 return classify_name (block);
2875 type = check_typedef (context);
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.ssym.stoken);
2882 yylval.ssym.sym = cp_lookup_nested_symbol (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);;
2899 internal_error (__FILE__, __LINE__, _("not reached"));
2902 /* The outer level of a two-level lexer. This calls the inner lexer
2903 to return tokens. It then either returns these tokens, or
2904 aggregates them into a larger token. This lets us work around a
2905 problem in our parsing approach, where the parser could not
2906 distinguish between qualified names and qualified types at the
2909 This approach is still not ideal, because it mishandles template
2910 types. See the comment in lex_one_token for an example. However,
2911 this is still an improvement over the earlier approach, and will
2912 suffice until we move to better parsing technology. */
2916 token_and_value current;
2917 int first_was_coloncolon, last_was_coloncolon, first_iter;
2918 struct type *context_type = NULL;
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)
2941 obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
2942 context_type = yylval.tsym.type;
2944 current.value = yylval;
2948 token_and_value next;
2950 next.token = lex_one_token ();
2951 next.value = yylval;
2953 if (next.token == NAME && last_was_coloncolon)
2957 classification = classify_inner_name (first_was_coloncolon
2959 : expression_context_block,
2961 /* We keep going until we either run out of names, or until
2962 we have a qualified name which is not a type. */
2963 if (classification != TYPENAME && classification != NAME)
2965 /* Push the final component and leave the loop. */
2966 VEC_safe_push (token_and_value, token_fifo, &next);
2970 /* Update the partial name we are constructing. */
2971 if (context_type != NULL)
2973 /* We don't want to put a leading "::" into the name. */
2974 obstack_grow_str (&name_obstack, "::");
2976 obstack_grow (&name_obstack, next.value.sval.ptr,
2977 next.value.sval.length);
2979 yylval.sval.ptr = obstack_base (&name_obstack);
2980 yylval.sval.length = obstack_object_size (&name_obstack);
2981 current.value = yylval;
2982 current.token = classification;
2984 last_was_coloncolon = 0;
2986 if (classification == NAME)
2989 context_type = yylval.tsym.type;
2991 else if (next.token == COLONCOLON && !last_was_coloncolon)
2992 last_was_coloncolon = 1;
2995 /* We've reached the end of the name. */
2996 VEC_safe_push (token_and_value, token_fifo, &next);
3005 /* If we ended with a "::", insert it too. */
3006 if (last_was_coloncolon)
3009 memset (&cc, 0, sizeof (token_and_value));
3010 if (first_was_coloncolon && first_iter)
3015 cc.token = COLONCOLON;
3016 VEC_safe_insert (token_and_value, token_fifo, 0, &cc);
3019 yylval = current.value;
3020 yylval.sval.ptr = obstack_copy0 (&expansion_obstack,
3022 yylval.sval.length);
3023 return current.token;
3030 struct cleanup *back_to = make_cleanup (free_current_contents,
3031 &expression_macro_scope);
3033 /* Set up the scope for macro expansion. */
3034 expression_macro_scope = NULL;
3036 if (expression_context_block)
3037 expression_macro_scope
3038 = sal_macro_scope (find_pc_line (expression_context_pc, 0));
3040 expression_macro_scope = default_macro_scope ();
3041 if (! expression_macro_scope)
3042 expression_macro_scope = user_macro_scope ();
3044 /* Initialize macro expansion code. */
3045 obstack_init (&expansion_obstack);
3046 gdb_assert (! macro_original_text);
3047 make_cleanup (scan_macro_cleanup, 0);
3049 make_cleanup_restore_integer (&yydebug);
3050 yydebug = parser_debug;
3052 /* Initialize some state used by the lexer. */
3053 last_was_structop = 0;
3054 saw_name_at_eof = 0;
3056 VEC_free (token_and_value, token_fifo);
3058 obstack_init (&name_obstack);
3059 make_cleanup_obstack_free (&name_obstack);
3061 result = yyparse ();
3062 do_cleanups (back_to);
3071 lexptr = prev_lexptr;
3073 error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);