15796c8dcSSimon Schubert /* YACC parser for Pascal expressions, for GDB.
2*ef5ccd6cSJohn Marino Copyright (C) 2000-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert
45796c8dcSSimon Schubert This file is part of GDB.
55796c8dcSSimon Schubert
65796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
75796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
85796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
95796c8dcSSimon Schubert (at your option) any later version.
105796c8dcSSimon Schubert
115796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
125796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
135796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145796c8dcSSimon Schubert GNU General Public License for more details.
155796c8dcSSimon Schubert
165796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
175796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert /* This file is derived from c-exp.y */
205796c8dcSSimon Schubert
215796c8dcSSimon Schubert /* Parse a Pascal expression from text in a string,
225796c8dcSSimon Schubert and return the result as a struct expression pointer.
235796c8dcSSimon Schubert That structure contains arithmetic operations in reverse polish,
245796c8dcSSimon Schubert with constants represented by operations that are followed by special data.
255796c8dcSSimon Schubert See expression.h for the details of the format.
265796c8dcSSimon Schubert What is important here is that it can be built up sequentially
275796c8dcSSimon Schubert during the process of parsing; the lower levels of the tree always
285796c8dcSSimon Schubert come first in the result.
295796c8dcSSimon Schubert
305796c8dcSSimon Schubert Note that malloc's and realloc's in this file are transformed to
315796c8dcSSimon Schubert xmalloc and xrealloc respectively by the same sed command in the
325796c8dcSSimon Schubert makefile that remaps any other malloc/realloc inserted by the parser
335796c8dcSSimon Schubert generator. Doing this with #defines and trying to control the interaction
345796c8dcSSimon Schubert with include files (<malloc.h> and <stdlib.h> for example) just became
355796c8dcSSimon Schubert too messy, particularly when such includes can be inserted at random
365796c8dcSSimon Schubert times by the parser generator. */
375796c8dcSSimon Schubert
385796c8dcSSimon Schubert /* Known bugs or limitations:
395796c8dcSSimon Schubert - pascal string operations are not supported at all.
405796c8dcSSimon Schubert - there are some problems with boolean types.
415796c8dcSSimon Schubert - Pascal type hexadecimal constants are not supported
425796c8dcSSimon Schubert because they conflict with the internal variables format.
43c50c785cSJohn Marino Probably also lots of other problems, less well defined PM. */
445796c8dcSSimon Schubert %{
455796c8dcSSimon Schubert
465796c8dcSSimon Schubert #include "defs.h"
475796c8dcSSimon Schubert #include "gdb_string.h"
485796c8dcSSimon Schubert #include <ctype.h>
495796c8dcSSimon Schubert #include "expression.h"
505796c8dcSSimon Schubert #include "value.h"
515796c8dcSSimon Schubert #include "parser-defs.h"
525796c8dcSSimon Schubert #include "language.h"
535796c8dcSSimon Schubert #include "p-lang.h"
545796c8dcSSimon Schubert #include "bfd.h" /* Required by objfiles.h. */
555796c8dcSSimon Schubert #include "symfile.h" /* Required by objfiles.h. */
56c50c785cSJohn Marino #include "objfiles.h" /* For have_full_symbols and have_partial_symbols. */
575796c8dcSSimon Schubert #include "block.h"
585796c8dcSSimon Schubert
595796c8dcSSimon Schubert #define parse_type builtin_type (parse_gdbarch)
605796c8dcSSimon Schubert
615796c8dcSSimon Schubert /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
625796c8dcSSimon Schubert as well as gratuitiously global symbol names, so we can have multiple
635796c8dcSSimon Schubert yacc generated parsers in gdb. Note that these are only the variables
645796c8dcSSimon Schubert produced by yacc. If other parser generators (bison, byacc, etc) produce
655796c8dcSSimon Schubert additional global names that conflict at link time, then those parser
665796c8dcSSimon Schubert generators need to be fixed instead of adding those names to this list. */
675796c8dcSSimon Schubert
685796c8dcSSimon Schubert #define yymaxdepth pascal_maxdepth
695796c8dcSSimon Schubert #define yyparse pascal_parse
705796c8dcSSimon Schubert #define yylex pascal_lex
715796c8dcSSimon Schubert #define yyerror pascal_error
725796c8dcSSimon Schubert #define yylval pascal_lval
735796c8dcSSimon Schubert #define yychar pascal_char
745796c8dcSSimon Schubert #define yydebug pascal_debug
755796c8dcSSimon Schubert #define yypact pascal_pact
765796c8dcSSimon Schubert #define yyr1 pascal_r1
775796c8dcSSimon Schubert #define yyr2 pascal_r2
785796c8dcSSimon Schubert #define yydef pascal_def
795796c8dcSSimon Schubert #define yychk pascal_chk
805796c8dcSSimon Schubert #define yypgo pascal_pgo
815796c8dcSSimon Schubert #define yyact pascal_act
825796c8dcSSimon Schubert #define yyexca pascal_exca
835796c8dcSSimon Schubert #define yyerrflag pascal_errflag
845796c8dcSSimon Schubert #define yynerrs pascal_nerrs
855796c8dcSSimon Schubert #define yyps pascal_ps
865796c8dcSSimon Schubert #define yypv pascal_pv
875796c8dcSSimon Schubert #define yys pascal_s
885796c8dcSSimon Schubert #define yy_yys pascal_yys
895796c8dcSSimon Schubert #define yystate pascal_state
905796c8dcSSimon Schubert #define yytmp pascal_tmp
915796c8dcSSimon Schubert #define yyv pascal_v
925796c8dcSSimon Schubert #define yy_yyv pascal_yyv
935796c8dcSSimon Schubert #define yyval pascal_val
945796c8dcSSimon Schubert #define yylloc pascal_lloc
955796c8dcSSimon Schubert #define yyreds pascal_reds /* With YYDEBUG defined */
965796c8dcSSimon Schubert #define yytoks pascal_toks /* With YYDEBUG defined */
975796c8dcSSimon Schubert #define yyname pascal_name /* With YYDEBUG defined */
985796c8dcSSimon Schubert #define yyrule pascal_rule /* With YYDEBUG defined */
995796c8dcSSimon Schubert #define yylhs pascal_yylhs
1005796c8dcSSimon Schubert #define yylen pascal_yylen
1015796c8dcSSimon Schubert #define yydefred pascal_yydefred
1025796c8dcSSimon Schubert #define yydgoto pascal_yydgoto
1035796c8dcSSimon Schubert #define yysindex pascal_yysindex
1045796c8dcSSimon Schubert #define yyrindex pascal_yyrindex
1055796c8dcSSimon Schubert #define yygindex pascal_yygindex
1065796c8dcSSimon Schubert #define yytable pascal_yytable
1075796c8dcSSimon Schubert #define yycheck pascal_yycheck
108*ef5ccd6cSJohn Marino #define yyss pascal_yyss
109*ef5ccd6cSJohn Marino #define yysslim pascal_yysslim
110*ef5ccd6cSJohn Marino #define yyssp pascal_yyssp
111*ef5ccd6cSJohn Marino #define yystacksize pascal_yystacksize
112*ef5ccd6cSJohn Marino #define yyvs pascal_yyvs
113*ef5ccd6cSJohn Marino #define yyvsp pascal_yyvsp
1145796c8dcSSimon Schubert
1155796c8dcSSimon Schubert #ifndef YYDEBUG
1165796c8dcSSimon Schubert #define YYDEBUG 1 /* Default to yydebug support */
1175796c8dcSSimon Schubert #endif
1185796c8dcSSimon Schubert
1195796c8dcSSimon Schubert #define YYFPRINTF parser_fprintf
1205796c8dcSSimon Schubert
1215796c8dcSSimon Schubert int yyparse (void);
1225796c8dcSSimon Schubert
1235796c8dcSSimon Schubert static int yylex (void);
1245796c8dcSSimon Schubert
125c50c785cSJohn Marino void yyerror (char *);
1265796c8dcSSimon Schubert
1275796c8dcSSimon Schubert static char * uptok (char *, int);
1285796c8dcSSimon Schubert %}
1295796c8dcSSimon Schubert
1305796c8dcSSimon Schubert /* Although the yacc "value" of an expression is not used,
1315796c8dcSSimon Schubert since the result is stored in the structure being created,
1325796c8dcSSimon Schubert other node types do have values. */
1335796c8dcSSimon Schubert
1345796c8dcSSimon Schubert %union
1355796c8dcSSimon Schubert {
1365796c8dcSSimon Schubert LONGEST lval;
1375796c8dcSSimon Schubert struct {
1385796c8dcSSimon Schubert LONGEST val;
1395796c8dcSSimon Schubert struct type *type;
1405796c8dcSSimon Schubert } typed_val_int;
1415796c8dcSSimon Schubert struct {
1425796c8dcSSimon Schubert DOUBLEST dval;
1435796c8dcSSimon Schubert struct type *type;
1445796c8dcSSimon Schubert } typed_val_float;
1455796c8dcSSimon Schubert struct symbol *sym;
1465796c8dcSSimon Schubert struct type *tval;
1475796c8dcSSimon Schubert struct stoken sval;
1485796c8dcSSimon Schubert struct ttype tsym;
1495796c8dcSSimon Schubert struct symtoken ssym;
1505796c8dcSSimon Schubert int voidval;
1515796c8dcSSimon Schubert struct block *bval;
1525796c8dcSSimon Schubert enum exp_opcode opcode;
1535796c8dcSSimon Schubert struct internalvar *ivar;
1545796c8dcSSimon Schubert
1555796c8dcSSimon Schubert struct type **tvec;
1565796c8dcSSimon Schubert int *ivec;
1575796c8dcSSimon Schubert }
1585796c8dcSSimon Schubert
1595796c8dcSSimon Schubert %{
1605796c8dcSSimon Schubert /* YYSTYPE gets defined by %union */
161c50c785cSJohn Marino static int parse_number (char *, int, int, YYSTYPE *);
1625796c8dcSSimon Schubert
1635796c8dcSSimon Schubert static struct type *current_type;
164c50c785cSJohn Marino static struct internalvar *intvar;
1655796c8dcSSimon Schubert static int leftdiv_is_integer;
1665796c8dcSSimon Schubert static void push_current_type (void);
1675796c8dcSSimon Schubert static void pop_current_type (void);
1685796c8dcSSimon Schubert static int search_field;
1695796c8dcSSimon Schubert %}
1705796c8dcSSimon Schubert
1715796c8dcSSimon Schubert %type <voidval> exp exp1 type_exp start normal_start variable qualified_name
1725796c8dcSSimon Schubert %type <tval> type typebase
1735796c8dcSSimon Schubert /* %type <bval> block */
1745796c8dcSSimon Schubert
1755796c8dcSSimon Schubert /* Fancy type parsing. */
1765796c8dcSSimon Schubert %type <tval> ptype
1775796c8dcSSimon Schubert
1785796c8dcSSimon Schubert %token <typed_val_int> INT
1795796c8dcSSimon Schubert %token <typed_val_float> FLOAT
1805796c8dcSSimon Schubert
1815796c8dcSSimon Schubert /* Both NAME and TYPENAME tokens represent symbols in the input,
1825796c8dcSSimon Schubert and both convey their data as strings.
1835796c8dcSSimon Schubert But a TYPENAME is a string that happens to be defined as a typedef
1845796c8dcSSimon Schubert or builtin type name (such as int or char)
1855796c8dcSSimon Schubert and a NAME is any other symbol.
1865796c8dcSSimon Schubert Contexts where this distinction is not important can use the
1875796c8dcSSimon Schubert nonterminal "name", which matches either NAME or TYPENAME. */
1885796c8dcSSimon Schubert
1895796c8dcSSimon Schubert %token <sval> STRING
1905796c8dcSSimon Schubert %token <sval> FIELDNAME
191c50c785cSJohn Marino %token <voidval> COMPLETE
1925796c8dcSSimon Schubert %token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
1935796c8dcSSimon Schubert %token <tsym> TYPENAME
1945796c8dcSSimon Schubert %type <sval> name
1955796c8dcSSimon Schubert %type <ssym> name_not_typename
1965796c8dcSSimon Schubert
1975796c8dcSSimon Schubert /* A NAME_OR_INT is a symbol which is not known in the symbol table,
1985796c8dcSSimon Schubert but which would parse as a valid number in the current input radix.
1995796c8dcSSimon Schubert E.g. "c" when input_radix==16. Depending on the parse, it will be
2005796c8dcSSimon Schubert turned into a name or into a number. */
2015796c8dcSSimon Schubert
2025796c8dcSSimon Schubert %token <ssym> NAME_OR_INT
2035796c8dcSSimon Schubert
2045796c8dcSSimon Schubert %token STRUCT CLASS SIZEOF COLONCOLON
2055796c8dcSSimon Schubert %token ERROR
2065796c8dcSSimon Schubert
2075796c8dcSSimon Schubert /* Special type cases, put in to allow the parser to distinguish different
2085796c8dcSSimon Schubert legal basetypes. */
2095796c8dcSSimon Schubert
2105796c8dcSSimon Schubert %token <voidval> VARIABLE
2115796c8dcSSimon Schubert
2125796c8dcSSimon Schubert
2135796c8dcSSimon Schubert /* Object pascal */
2145796c8dcSSimon Schubert %token THIS
2155796c8dcSSimon Schubert %token <lval> TRUEKEYWORD FALSEKEYWORD
2165796c8dcSSimon Schubert
2175796c8dcSSimon Schubert %left ','
2185796c8dcSSimon Schubert %left ABOVE_COMMA
2195796c8dcSSimon Schubert %right ASSIGN
2205796c8dcSSimon Schubert %left NOT
2215796c8dcSSimon Schubert %left OR
2225796c8dcSSimon Schubert %left XOR
2235796c8dcSSimon Schubert %left ANDAND
2245796c8dcSSimon Schubert %left '=' NOTEQUAL
2255796c8dcSSimon Schubert %left '<' '>' LEQ GEQ
2265796c8dcSSimon Schubert %left LSH RSH DIV MOD
2275796c8dcSSimon Schubert %left '@'
2285796c8dcSSimon Schubert %left '+' '-'
2295796c8dcSSimon Schubert %left '*' '/'
2305796c8dcSSimon Schubert %right UNARY INCREMENT DECREMENT
2315796c8dcSSimon Schubert %right ARROW '.' '[' '('
2325796c8dcSSimon Schubert %left '^'
2335796c8dcSSimon Schubert %token <ssym> BLOCKNAME
2345796c8dcSSimon Schubert %type <bval> block
2355796c8dcSSimon Schubert %left COLONCOLON
2365796c8dcSSimon Schubert
2375796c8dcSSimon Schubert
2385796c8dcSSimon Schubert %%
2395796c8dcSSimon Schubert
2405796c8dcSSimon Schubert start : { current_type = NULL;
241c50c785cSJohn Marino intvar = NULL;
2425796c8dcSSimon Schubert search_field = 0;
2435796c8dcSSimon Schubert leftdiv_is_integer = 0;
2445796c8dcSSimon Schubert }
2455796c8dcSSimon Schubert normal_start {}
2465796c8dcSSimon Schubert ;
2475796c8dcSSimon Schubert
2485796c8dcSSimon Schubert normal_start :
2495796c8dcSSimon Schubert exp1
2505796c8dcSSimon Schubert | type_exp
2515796c8dcSSimon Schubert ;
2525796c8dcSSimon Schubert
2535796c8dcSSimon Schubert type_exp: type
2545796c8dcSSimon Schubert { write_exp_elt_opcode(OP_TYPE);
2555796c8dcSSimon Schubert write_exp_elt_type($1);
2565796c8dcSSimon Schubert write_exp_elt_opcode(OP_TYPE);
2575796c8dcSSimon Schubert current_type = $1; } ;
2585796c8dcSSimon Schubert
2595796c8dcSSimon Schubert /* Expressions, including the comma operator. */
2605796c8dcSSimon Schubert exp1 : exp
2615796c8dcSSimon Schubert | exp1 ',' exp
2625796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_COMMA); }
2635796c8dcSSimon Schubert ;
2645796c8dcSSimon Schubert
2655796c8dcSSimon Schubert /* Expressions, not including the comma operator. */
2665796c8dcSSimon Schubert exp : exp '^' %prec UNARY
2675796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_IND);
2685796c8dcSSimon Schubert if (current_type)
2695796c8dcSSimon Schubert current_type = TYPE_TARGET_TYPE (current_type); }
2705796c8dcSSimon Schubert ;
2715796c8dcSSimon Schubert
2725796c8dcSSimon Schubert exp : '@' exp %prec UNARY
2735796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_ADDR);
2745796c8dcSSimon Schubert if (current_type)
2755796c8dcSSimon Schubert current_type = TYPE_POINTER_TYPE (current_type); }
2765796c8dcSSimon Schubert ;
2775796c8dcSSimon Schubert
2785796c8dcSSimon Schubert exp : '-' exp %prec UNARY
2795796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_NEG); }
2805796c8dcSSimon Schubert ;
2815796c8dcSSimon Schubert
2825796c8dcSSimon Schubert exp : NOT exp %prec UNARY
2835796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
2845796c8dcSSimon Schubert ;
2855796c8dcSSimon Schubert
2865796c8dcSSimon Schubert exp : INCREMENT '(' exp ')' %prec UNARY
2875796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_PREINCREMENT); }
2885796c8dcSSimon Schubert ;
2895796c8dcSSimon Schubert
2905796c8dcSSimon Schubert exp : DECREMENT '(' exp ')' %prec UNARY
2915796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_PREDECREMENT); }
2925796c8dcSSimon Schubert ;
2935796c8dcSSimon Schubert
294c50c785cSJohn Marino
295c50c785cSJohn Marino field_exp : exp '.' %prec UNARY
296c50c785cSJohn Marino { search_field = 1; }
297c50c785cSJohn Marino ;
298c50c785cSJohn Marino
299c50c785cSJohn Marino exp : field_exp FIELDNAME
3005796c8dcSSimon Schubert { write_exp_elt_opcode (STRUCTOP_STRUCT);
301c50c785cSJohn Marino write_exp_string ($2);
3025796c8dcSSimon Schubert write_exp_elt_opcode (STRUCTOP_STRUCT);
3035796c8dcSSimon Schubert search_field = 0;
3045796c8dcSSimon Schubert if (current_type)
305c50c785cSJohn Marino {
306c50c785cSJohn Marino while (TYPE_CODE (current_type)
307c50c785cSJohn Marino == TYPE_CODE_PTR)
308c50c785cSJohn Marino current_type =
309c50c785cSJohn Marino TYPE_TARGET_TYPE (current_type);
3105796c8dcSSimon Schubert current_type = lookup_struct_elt_type (
311c50c785cSJohn Marino current_type, $2.ptr, 0);
312c50c785cSJohn Marino }
313c50c785cSJohn Marino }
314c50c785cSJohn Marino ;
315c50c785cSJohn Marino
316c50c785cSJohn Marino
317c50c785cSJohn Marino exp : field_exp name
318c50c785cSJohn Marino { mark_struct_expression ();
319c50c785cSJohn Marino write_exp_elt_opcode (STRUCTOP_STRUCT);
320c50c785cSJohn Marino write_exp_string ($2);
321c50c785cSJohn Marino write_exp_elt_opcode (STRUCTOP_STRUCT);
322c50c785cSJohn Marino search_field = 0;
323c50c785cSJohn Marino if (current_type)
324c50c785cSJohn Marino {
325c50c785cSJohn Marino while (TYPE_CODE (current_type)
326c50c785cSJohn Marino == TYPE_CODE_PTR)
327c50c785cSJohn Marino current_type =
328c50c785cSJohn Marino TYPE_TARGET_TYPE (current_type);
329c50c785cSJohn Marino current_type = lookup_struct_elt_type (
330c50c785cSJohn Marino current_type, $2.ptr, 0);
331c50c785cSJohn Marino }
332c50c785cSJohn Marino }
333c50c785cSJohn Marino ;
334c50c785cSJohn Marino
335c50c785cSJohn Marino exp : field_exp COMPLETE
336c50c785cSJohn Marino { struct stoken s;
337c50c785cSJohn Marino mark_struct_expression ();
338c50c785cSJohn Marino write_exp_elt_opcode (STRUCTOP_STRUCT);
339c50c785cSJohn Marino s.ptr = "";
340c50c785cSJohn Marino s.length = 0;
341c50c785cSJohn Marino write_exp_string (s);
342c50c785cSJohn Marino write_exp_elt_opcode (STRUCTOP_STRUCT); }
343c50c785cSJohn Marino ;
344c50c785cSJohn Marino
3455796c8dcSSimon Schubert exp : exp '['
346c50c785cSJohn Marino /* We need to save the current_type value. */
347*ef5ccd6cSJohn Marino { const char *arrayname;
3485796c8dcSSimon Schubert int arrayfieldindex;
3495796c8dcSSimon Schubert arrayfieldindex = is_pascal_string_type (
3505796c8dcSSimon Schubert current_type, NULL, NULL,
3515796c8dcSSimon Schubert NULL, NULL, &arrayname);
3525796c8dcSSimon Schubert if (arrayfieldindex)
3535796c8dcSSimon Schubert {
3545796c8dcSSimon Schubert struct stoken stringsval;
3555796c8dcSSimon Schubert stringsval.ptr = alloca (strlen (arrayname) + 1);
3565796c8dcSSimon Schubert stringsval.length = strlen (arrayname);
3575796c8dcSSimon Schubert strcpy (stringsval.ptr, arrayname);
3585796c8dcSSimon Schubert current_type = TYPE_FIELD_TYPE (current_type,
3595796c8dcSSimon Schubert arrayfieldindex - 1);
3605796c8dcSSimon Schubert write_exp_elt_opcode (STRUCTOP_STRUCT);
3615796c8dcSSimon Schubert write_exp_string (stringsval);
3625796c8dcSSimon Schubert write_exp_elt_opcode (STRUCTOP_STRUCT);
3635796c8dcSSimon Schubert }
3645796c8dcSSimon Schubert push_current_type (); }
3655796c8dcSSimon Schubert exp1 ']'
3665796c8dcSSimon Schubert { pop_current_type ();
3675796c8dcSSimon Schubert write_exp_elt_opcode (BINOP_SUBSCRIPT);
3685796c8dcSSimon Schubert if (current_type)
3695796c8dcSSimon Schubert current_type = TYPE_TARGET_TYPE (current_type); }
3705796c8dcSSimon Schubert ;
3715796c8dcSSimon Schubert
3725796c8dcSSimon Schubert exp : exp '('
3735796c8dcSSimon Schubert /* This is to save the value of arglist_len
3745796c8dcSSimon Schubert being accumulated by an outer function call. */
3755796c8dcSSimon Schubert { push_current_type ();
3765796c8dcSSimon Schubert start_arglist (); }
3775796c8dcSSimon Schubert arglist ')' %prec ARROW
3785796c8dcSSimon Schubert { write_exp_elt_opcode (OP_FUNCALL);
3795796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) end_arglist ());
3805796c8dcSSimon Schubert write_exp_elt_opcode (OP_FUNCALL);
3815796c8dcSSimon Schubert pop_current_type ();
3825796c8dcSSimon Schubert if (current_type)
3835796c8dcSSimon Schubert current_type = TYPE_TARGET_TYPE (current_type);
3845796c8dcSSimon Schubert }
3855796c8dcSSimon Schubert ;
3865796c8dcSSimon Schubert
3875796c8dcSSimon Schubert arglist :
3885796c8dcSSimon Schubert | exp
3895796c8dcSSimon Schubert { arglist_len = 1; }
3905796c8dcSSimon Schubert | arglist ',' exp %prec ABOVE_COMMA
3915796c8dcSSimon Schubert { arglist_len++; }
3925796c8dcSSimon Schubert ;
3935796c8dcSSimon Schubert
3945796c8dcSSimon Schubert exp : type '(' exp ')' %prec UNARY
3955796c8dcSSimon Schubert { if (current_type)
3965796c8dcSSimon Schubert {
3975796c8dcSSimon Schubert /* Allow automatic dereference of classes. */
3985796c8dcSSimon Schubert if ((TYPE_CODE (current_type) == TYPE_CODE_PTR)
3995796c8dcSSimon Schubert && (TYPE_CODE (TYPE_TARGET_TYPE (current_type)) == TYPE_CODE_CLASS)
4005796c8dcSSimon Schubert && (TYPE_CODE ($1) == TYPE_CODE_CLASS))
4015796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_IND);
4025796c8dcSSimon Schubert }
4035796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_CAST);
4045796c8dcSSimon Schubert write_exp_elt_type ($1);
4055796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_CAST);
4065796c8dcSSimon Schubert current_type = $1; }
4075796c8dcSSimon Schubert ;
4085796c8dcSSimon Schubert
4095796c8dcSSimon Schubert exp : '(' exp1 ')'
4105796c8dcSSimon Schubert { }
4115796c8dcSSimon Schubert ;
4125796c8dcSSimon Schubert
4135796c8dcSSimon Schubert /* Binary operators in order of decreasing precedence. */
4145796c8dcSSimon Schubert
4155796c8dcSSimon Schubert exp : exp '*' exp
4165796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_MUL); }
4175796c8dcSSimon Schubert ;
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert exp : exp '/' {
4205796c8dcSSimon Schubert if (current_type && is_integral_type (current_type))
4215796c8dcSSimon Schubert leftdiv_is_integer = 1;
4225796c8dcSSimon Schubert }
4235796c8dcSSimon Schubert exp
4245796c8dcSSimon Schubert {
4255796c8dcSSimon Schubert if (leftdiv_is_integer && current_type
4265796c8dcSSimon Schubert && is_integral_type (current_type))
4275796c8dcSSimon Schubert {
4285796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_CAST);
4295796c8dcSSimon Schubert write_exp_elt_type (parse_type->builtin_long_double);
4305796c8dcSSimon Schubert current_type = parse_type->builtin_long_double;
4315796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_CAST);
4325796c8dcSSimon Schubert leftdiv_is_integer = 0;
4335796c8dcSSimon Schubert }
4345796c8dcSSimon Schubert
4355796c8dcSSimon Schubert write_exp_elt_opcode (BINOP_DIV);
4365796c8dcSSimon Schubert }
4375796c8dcSSimon Schubert ;
4385796c8dcSSimon Schubert
4395796c8dcSSimon Schubert exp : exp DIV exp
4405796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_INTDIV); }
4415796c8dcSSimon Schubert ;
4425796c8dcSSimon Schubert
4435796c8dcSSimon Schubert exp : exp MOD exp
4445796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_REM); }
4455796c8dcSSimon Schubert ;
4465796c8dcSSimon Schubert
4475796c8dcSSimon Schubert exp : exp '+' exp
4485796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_ADD); }
4495796c8dcSSimon Schubert ;
4505796c8dcSSimon Schubert
4515796c8dcSSimon Schubert exp : exp '-' exp
4525796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_SUB); }
4535796c8dcSSimon Schubert ;
4545796c8dcSSimon Schubert
4555796c8dcSSimon Schubert exp : exp LSH exp
4565796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_LSH); }
4575796c8dcSSimon Schubert ;
4585796c8dcSSimon Schubert
4595796c8dcSSimon Schubert exp : exp RSH exp
4605796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_RSH); }
4615796c8dcSSimon Schubert ;
4625796c8dcSSimon Schubert
4635796c8dcSSimon Schubert exp : exp '=' exp
4645796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_EQUAL);
4655796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
4665796c8dcSSimon Schubert }
4675796c8dcSSimon Schubert ;
4685796c8dcSSimon Schubert
4695796c8dcSSimon Schubert exp : exp NOTEQUAL exp
4705796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_NOTEQUAL);
4715796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
4725796c8dcSSimon Schubert }
4735796c8dcSSimon Schubert ;
4745796c8dcSSimon Schubert
4755796c8dcSSimon Schubert exp : exp LEQ exp
4765796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_LEQ);
4775796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
4785796c8dcSSimon Schubert }
4795796c8dcSSimon Schubert ;
4805796c8dcSSimon Schubert
4815796c8dcSSimon Schubert exp : exp GEQ exp
4825796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_GEQ);
4835796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
4845796c8dcSSimon Schubert }
4855796c8dcSSimon Schubert ;
4865796c8dcSSimon Schubert
4875796c8dcSSimon Schubert exp : exp '<' exp
4885796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_LESS);
4895796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
4905796c8dcSSimon Schubert }
4915796c8dcSSimon Schubert ;
4925796c8dcSSimon Schubert
4935796c8dcSSimon Schubert exp : exp '>' exp
4945796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_GTR);
4955796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
4965796c8dcSSimon Schubert }
4975796c8dcSSimon Schubert ;
4985796c8dcSSimon Schubert
4995796c8dcSSimon Schubert exp : exp ANDAND exp
5005796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_BITWISE_AND); }
5015796c8dcSSimon Schubert ;
5025796c8dcSSimon Schubert
5035796c8dcSSimon Schubert exp : exp XOR exp
5045796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
5055796c8dcSSimon Schubert ;
5065796c8dcSSimon Schubert
5075796c8dcSSimon Schubert exp : exp OR exp
5085796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
5095796c8dcSSimon Schubert ;
5105796c8dcSSimon Schubert
5115796c8dcSSimon Schubert exp : exp ASSIGN exp
5125796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_ASSIGN); }
5135796c8dcSSimon Schubert ;
5145796c8dcSSimon Schubert
5155796c8dcSSimon Schubert exp : TRUEKEYWORD
5165796c8dcSSimon Schubert { write_exp_elt_opcode (OP_BOOL);
5175796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) $1);
5185796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
5195796c8dcSSimon Schubert write_exp_elt_opcode (OP_BOOL); }
5205796c8dcSSimon Schubert ;
5215796c8dcSSimon Schubert
5225796c8dcSSimon Schubert exp : FALSEKEYWORD
5235796c8dcSSimon Schubert { write_exp_elt_opcode (OP_BOOL);
5245796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) $1);
5255796c8dcSSimon Schubert current_type = parse_type->builtin_bool;
5265796c8dcSSimon Schubert write_exp_elt_opcode (OP_BOOL); }
5275796c8dcSSimon Schubert ;
5285796c8dcSSimon Schubert
5295796c8dcSSimon Schubert exp : INT
5305796c8dcSSimon Schubert { write_exp_elt_opcode (OP_LONG);
5315796c8dcSSimon Schubert write_exp_elt_type ($1.type);
5325796c8dcSSimon Schubert current_type = $1.type;
5335796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST)($1.val));
5345796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG); }
5355796c8dcSSimon Schubert ;
5365796c8dcSSimon Schubert
5375796c8dcSSimon Schubert exp : NAME_OR_INT
5385796c8dcSSimon Schubert { YYSTYPE val;
539c50c785cSJohn Marino parse_number ($1.stoken.ptr,
540c50c785cSJohn Marino $1.stoken.length, 0, &val);
5415796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
5425796c8dcSSimon Schubert write_exp_elt_type (val.typed_val_int.type);
5435796c8dcSSimon Schubert current_type = val.typed_val_int.type;
544c50c785cSJohn Marino write_exp_elt_longcst ((LONGEST)
545c50c785cSJohn Marino val.typed_val_int.val);
5465796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
5475796c8dcSSimon Schubert }
5485796c8dcSSimon Schubert ;
5495796c8dcSSimon Schubert
5505796c8dcSSimon Schubert
5515796c8dcSSimon Schubert exp : FLOAT
5525796c8dcSSimon Schubert { write_exp_elt_opcode (OP_DOUBLE);
5535796c8dcSSimon Schubert write_exp_elt_type ($1.type);
5545796c8dcSSimon Schubert current_type = $1.type;
5555796c8dcSSimon Schubert write_exp_elt_dblcst ($1.dval);
5565796c8dcSSimon Schubert write_exp_elt_opcode (OP_DOUBLE); }
5575796c8dcSSimon Schubert ;
5585796c8dcSSimon Schubert
5595796c8dcSSimon Schubert exp : variable
5605796c8dcSSimon Schubert ;
5615796c8dcSSimon Schubert
5625796c8dcSSimon Schubert exp : VARIABLE
563c50c785cSJohn Marino /* Already written by write_dollar_variable.
564c50c785cSJohn Marino Handle current_type. */
565c50c785cSJohn Marino { if (intvar) {
566c50c785cSJohn Marino struct value * val, * mark;
567c50c785cSJohn Marino
568c50c785cSJohn Marino mark = value_mark ();
569c50c785cSJohn Marino val = value_of_internalvar (parse_gdbarch,
570c50c785cSJohn Marino intvar);
571c50c785cSJohn Marino current_type = value_type (val);
572c50c785cSJohn Marino value_release_to_mark (mark);
573c50c785cSJohn Marino }
574c50c785cSJohn Marino }
5755796c8dcSSimon Schubert ;
5765796c8dcSSimon Schubert
5775796c8dcSSimon Schubert exp : SIZEOF '(' type ')' %prec UNARY
5785796c8dcSSimon Schubert { write_exp_elt_opcode (OP_LONG);
5795796c8dcSSimon Schubert write_exp_elt_type (parse_type->builtin_int);
5805796c8dcSSimon Schubert CHECK_TYPEDEF ($3);
5815796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
5825796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG); }
5835796c8dcSSimon Schubert ;
5845796c8dcSSimon Schubert
585cf7f2e2dSJohn Marino exp : SIZEOF '(' exp ')' %prec UNARY
586cf7f2e2dSJohn Marino { write_exp_elt_opcode (UNOP_SIZEOF); }
587cf7f2e2dSJohn Marino
5885796c8dcSSimon Schubert exp : STRING
5895796c8dcSSimon Schubert { /* C strings are converted into array constants with
5905796c8dcSSimon Schubert an explicit null byte added at the end. Thus
5915796c8dcSSimon Schubert the array upper bound is the string length.
5925796c8dcSSimon Schubert There is no such thing in C as a completely empty
5935796c8dcSSimon Schubert string. */
5945796c8dcSSimon Schubert char *sp = $1.ptr; int count = $1.length;
5955796c8dcSSimon Schubert while (count-- > 0)
5965796c8dcSSimon Schubert {
5975796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
5985796c8dcSSimon Schubert write_exp_elt_type (parse_type->builtin_char);
5995796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST)(*sp++));
6005796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
6015796c8dcSSimon Schubert }
6025796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
6035796c8dcSSimon Schubert write_exp_elt_type (parse_type->builtin_char);
6045796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST)'\0');
6055796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
6065796c8dcSSimon Schubert write_exp_elt_opcode (OP_ARRAY);
6075796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) 0);
6085796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) ($1.length));
6095796c8dcSSimon Schubert write_exp_elt_opcode (OP_ARRAY); }
6105796c8dcSSimon Schubert ;
6115796c8dcSSimon Schubert
6125796c8dcSSimon Schubert /* Object pascal */
6135796c8dcSSimon Schubert exp : THIS
6145796c8dcSSimon Schubert {
6155796c8dcSSimon Schubert struct value * this_val;
6165796c8dcSSimon Schubert struct type * this_type;
6175796c8dcSSimon Schubert write_exp_elt_opcode (OP_THIS);
6185796c8dcSSimon Schubert write_exp_elt_opcode (OP_THIS);
619c50c785cSJohn Marino /* We need type of this. */
620a45ae5f8SJohn Marino this_val = value_of_this_silent (parse_language);
6215796c8dcSSimon Schubert if (this_val)
6225796c8dcSSimon Schubert this_type = value_type (this_val);
6235796c8dcSSimon Schubert else
6245796c8dcSSimon Schubert this_type = NULL;
6255796c8dcSSimon Schubert if (this_type)
6265796c8dcSSimon Schubert {
6275796c8dcSSimon Schubert if (TYPE_CODE (this_type) == TYPE_CODE_PTR)
6285796c8dcSSimon Schubert {
6295796c8dcSSimon Schubert this_type = TYPE_TARGET_TYPE (this_type);
6305796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_IND);
6315796c8dcSSimon Schubert }
6325796c8dcSSimon Schubert }
6335796c8dcSSimon Schubert
6345796c8dcSSimon Schubert current_type = this_type;
6355796c8dcSSimon Schubert }
6365796c8dcSSimon Schubert ;
6375796c8dcSSimon Schubert
6385796c8dcSSimon Schubert /* end of object pascal. */
6395796c8dcSSimon Schubert
6405796c8dcSSimon Schubert block : BLOCKNAME
6415796c8dcSSimon Schubert {
6425796c8dcSSimon Schubert if ($1.sym != 0)
6435796c8dcSSimon Schubert $$ = SYMBOL_BLOCK_VALUE ($1.sym);
6445796c8dcSSimon Schubert else
6455796c8dcSSimon Schubert {
6465796c8dcSSimon Schubert struct symtab *tem =
6475796c8dcSSimon Schubert lookup_symtab (copy_name ($1.stoken));
6485796c8dcSSimon Schubert if (tem)
649c50c785cSJohn Marino $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem),
650c50c785cSJohn Marino STATIC_BLOCK);
6515796c8dcSSimon Schubert else
652c50c785cSJohn Marino error (_("No file or function \"%s\"."),
6535796c8dcSSimon Schubert copy_name ($1.stoken));
6545796c8dcSSimon Schubert }
6555796c8dcSSimon Schubert }
6565796c8dcSSimon Schubert ;
6575796c8dcSSimon Schubert
6585796c8dcSSimon Schubert block : block COLONCOLON name
6595796c8dcSSimon Schubert { struct symbol *tem
6605796c8dcSSimon Schubert = lookup_symbol (copy_name ($3), $1,
661*ef5ccd6cSJohn Marino VAR_DOMAIN, NULL);
6625796c8dcSSimon Schubert if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
663c50c785cSJohn Marino error (_("No function \"%s\" in specified context."),
6645796c8dcSSimon Schubert copy_name ($3));
6655796c8dcSSimon Schubert $$ = SYMBOL_BLOCK_VALUE (tem); }
6665796c8dcSSimon Schubert ;
6675796c8dcSSimon Schubert
6685796c8dcSSimon Schubert variable: block COLONCOLON name
6695796c8dcSSimon Schubert { struct symbol *sym;
6705796c8dcSSimon Schubert sym = lookup_symbol (copy_name ($3), $1,
671*ef5ccd6cSJohn Marino VAR_DOMAIN, NULL);
6725796c8dcSSimon Schubert if (sym == 0)
673c50c785cSJohn Marino error (_("No symbol \"%s\" in specified context."),
6745796c8dcSSimon Schubert copy_name ($3));
6755796c8dcSSimon Schubert
6765796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
6775796c8dcSSimon Schubert /* block_found is set by lookup_symbol. */
6785796c8dcSSimon Schubert write_exp_elt_block (block_found);
6795796c8dcSSimon Schubert write_exp_elt_sym (sym);
6805796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE); }
6815796c8dcSSimon Schubert ;
6825796c8dcSSimon Schubert
6835796c8dcSSimon Schubert qualified_name: typebase COLONCOLON name
6845796c8dcSSimon Schubert {
6855796c8dcSSimon Schubert struct type *type = $1;
6865796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_STRUCT
6875796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_UNION)
688c50c785cSJohn Marino error (_("`%s' is not defined as an aggregate type."),
6895796c8dcSSimon Schubert TYPE_NAME (type));
6905796c8dcSSimon Schubert
6915796c8dcSSimon Schubert write_exp_elt_opcode (OP_SCOPE);
6925796c8dcSSimon Schubert write_exp_elt_type (type);
6935796c8dcSSimon Schubert write_exp_string ($3);
6945796c8dcSSimon Schubert write_exp_elt_opcode (OP_SCOPE);
6955796c8dcSSimon Schubert }
6965796c8dcSSimon Schubert ;
6975796c8dcSSimon Schubert
6985796c8dcSSimon Schubert variable: qualified_name
6995796c8dcSSimon Schubert | COLONCOLON name
7005796c8dcSSimon Schubert {
7015796c8dcSSimon Schubert char *name = copy_name ($2);
7025796c8dcSSimon Schubert struct symbol *sym;
7035796c8dcSSimon Schubert struct minimal_symbol *msymbol;
7045796c8dcSSimon Schubert
7055796c8dcSSimon Schubert sym =
7065796c8dcSSimon Schubert lookup_symbol (name, (const struct block *) NULL,
707*ef5ccd6cSJohn Marino VAR_DOMAIN, NULL);
7085796c8dcSSimon Schubert if (sym)
7095796c8dcSSimon Schubert {
7105796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
7115796c8dcSSimon Schubert write_exp_elt_block (NULL);
7125796c8dcSSimon Schubert write_exp_elt_sym (sym);
7135796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
7145796c8dcSSimon Schubert break;
7155796c8dcSSimon Schubert }
7165796c8dcSSimon Schubert
7175796c8dcSSimon Schubert msymbol = lookup_minimal_symbol (name, NULL, NULL);
7185796c8dcSSimon Schubert if (msymbol != NULL)
7195796c8dcSSimon Schubert write_exp_msymbol (msymbol);
720c50c785cSJohn Marino else if (!have_full_symbols ()
721c50c785cSJohn Marino && !have_partial_symbols ())
722c50c785cSJohn Marino error (_("No symbol table is loaded. "
723c50c785cSJohn Marino "Use the \"file\" command."));
7245796c8dcSSimon Schubert else
725c50c785cSJohn Marino error (_("No symbol \"%s\" in current context."),
726c50c785cSJohn Marino name);
7275796c8dcSSimon Schubert }
7285796c8dcSSimon Schubert ;
7295796c8dcSSimon Schubert
7305796c8dcSSimon Schubert variable: name_not_typename
7315796c8dcSSimon Schubert { struct symbol *sym = $1.sym;
7325796c8dcSSimon Schubert
7335796c8dcSSimon Schubert if (sym)
7345796c8dcSSimon Schubert {
7355796c8dcSSimon Schubert if (symbol_read_needs_frame (sym))
7365796c8dcSSimon Schubert {
7375796c8dcSSimon Schubert if (innermost_block == 0
7385796c8dcSSimon Schubert || contained_in (block_found,
7395796c8dcSSimon Schubert innermost_block))
7405796c8dcSSimon Schubert innermost_block = block_found;
7415796c8dcSSimon Schubert }
7425796c8dcSSimon Schubert
7435796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
7445796c8dcSSimon Schubert /* We want to use the selected frame, not
7455796c8dcSSimon Schubert another more inner frame which happens to
7465796c8dcSSimon Schubert be in the same block. */
7475796c8dcSSimon Schubert write_exp_elt_block (NULL);
7485796c8dcSSimon Schubert write_exp_elt_sym (sym);
7495796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
7505796c8dcSSimon Schubert current_type = sym->type; }
7515796c8dcSSimon Schubert else if ($1.is_a_field_of_this)
7525796c8dcSSimon Schubert {
7535796c8dcSSimon Schubert struct value * this_val;
7545796c8dcSSimon Schubert struct type * this_type;
7555796c8dcSSimon Schubert /* Object pascal: it hangs off of `this'. Must
7565796c8dcSSimon Schubert not inadvertently convert from a method call
7575796c8dcSSimon Schubert to data ref. */
7585796c8dcSSimon Schubert if (innermost_block == 0
7595796c8dcSSimon Schubert || contained_in (block_found,
7605796c8dcSSimon Schubert innermost_block))
7615796c8dcSSimon Schubert innermost_block = block_found;
7625796c8dcSSimon Schubert write_exp_elt_opcode (OP_THIS);
7635796c8dcSSimon Schubert write_exp_elt_opcode (OP_THIS);
7645796c8dcSSimon Schubert write_exp_elt_opcode (STRUCTOP_PTR);
7655796c8dcSSimon Schubert write_exp_string ($1.stoken);
7665796c8dcSSimon Schubert write_exp_elt_opcode (STRUCTOP_PTR);
767c50c785cSJohn Marino /* We need type of this. */
768a45ae5f8SJohn Marino this_val = value_of_this_silent (parse_language);
7695796c8dcSSimon Schubert if (this_val)
7705796c8dcSSimon Schubert this_type = value_type (this_val);
7715796c8dcSSimon Schubert else
7725796c8dcSSimon Schubert this_type = NULL;
7735796c8dcSSimon Schubert if (this_type)
7745796c8dcSSimon Schubert current_type = lookup_struct_elt_type (
7755796c8dcSSimon Schubert this_type,
7765796c8dcSSimon Schubert copy_name ($1.stoken), 0);
7775796c8dcSSimon Schubert else
7785796c8dcSSimon Schubert current_type = NULL;
7795796c8dcSSimon Schubert }
7805796c8dcSSimon Schubert else
7815796c8dcSSimon Schubert {
7825796c8dcSSimon Schubert struct minimal_symbol *msymbol;
7835796c8dcSSimon Schubert char *arg = copy_name ($1.stoken);
7845796c8dcSSimon Schubert
7855796c8dcSSimon Schubert msymbol =
7865796c8dcSSimon Schubert lookup_minimal_symbol (arg, NULL, NULL);
7875796c8dcSSimon Schubert if (msymbol != NULL)
7885796c8dcSSimon Schubert write_exp_msymbol (msymbol);
789c50c785cSJohn Marino else if (!have_full_symbols ()
790c50c785cSJohn Marino && !have_partial_symbols ())
791c50c785cSJohn Marino error (_("No symbol table is loaded. "
792c50c785cSJohn Marino "Use the \"file\" command."));
7935796c8dcSSimon Schubert else
794c50c785cSJohn Marino error (_("No symbol \"%s\" in current context."),
7955796c8dcSSimon Schubert copy_name ($1.stoken));
7965796c8dcSSimon Schubert }
7975796c8dcSSimon Schubert }
7985796c8dcSSimon Schubert ;
7995796c8dcSSimon Schubert
8005796c8dcSSimon Schubert
8015796c8dcSSimon Schubert ptype : typebase
8025796c8dcSSimon Schubert ;
8035796c8dcSSimon Schubert
8045796c8dcSSimon Schubert /* We used to try to recognize more pointer to member types here, but
8055796c8dcSSimon Schubert that didn't work (shift/reduce conflicts meant that these rules never
8065796c8dcSSimon Schubert got executed). The problem is that
8075796c8dcSSimon Schubert int (foo::bar::baz::bizzle)
8085796c8dcSSimon Schubert is a function type but
8095796c8dcSSimon Schubert int (foo::bar::baz::bizzle::*)
8105796c8dcSSimon Schubert is a pointer to member type. Stroustrup loses again! */
8115796c8dcSSimon Schubert
8125796c8dcSSimon Schubert type : ptype
8135796c8dcSSimon Schubert ;
8145796c8dcSSimon Schubert
8155796c8dcSSimon Schubert typebase /* Implements (approximately): (type-qualifier)* type-specifier */
8165796c8dcSSimon Schubert : '^' typebase
8175796c8dcSSimon Schubert { $$ = lookup_pointer_type ($2); }
8185796c8dcSSimon Schubert | TYPENAME
8195796c8dcSSimon Schubert { $$ = $1.type; }
8205796c8dcSSimon Schubert | STRUCT name
8215796c8dcSSimon Schubert { $$ = lookup_struct (copy_name ($2),
8225796c8dcSSimon Schubert expression_context_block); }
8235796c8dcSSimon Schubert | CLASS name
8245796c8dcSSimon Schubert { $$ = lookup_struct (copy_name ($2),
8255796c8dcSSimon Schubert expression_context_block); }
8265796c8dcSSimon Schubert /* "const" and "volatile" are curently ignored. A type qualifier
8275796c8dcSSimon Schubert after the type is handled in the ptype rule. I think these could
8285796c8dcSSimon Schubert be too. */
8295796c8dcSSimon Schubert ;
8305796c8dcSSimon Schubert
8315796c8dcSSimon Schubert name : NAME { $$ = $1.stoken; }
8325796c8dcSSimon Schubert | BLOCKNAME { $$ = $1.stoken; }
8335796c8dcSSimon Schubert | TYPENAME { $$ = $1.stoken; }
8345796c8dcSSimon Schubert | NAME_OR_INT { $$ = $1.stoken; }
8355796c8dcSSimon Schubert ;
8365796c8dcSSimon Schubert
8375796c8dcSSimon Schubert name_not_typename : NAME
8385796c8dcSSimon Schubert | BLOCKNAME
8395796c8dcSSimon Schubert /* These would be useful if name_not_typename was useful, but it is just
8405796c8dcSSimon Schubert a fake for "variable", so these cause reduce/reduce conflicts because
8415796c8dcSSimon Schubert the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
8425796c8dcSSimon Schubert =exp) or just an exp. If name_not_typename was ever used in an lvalue
8435796c8dcSSimon Schubert context where only a name could occur, this might be useful.
8445796c8dcSSimon Schubert | NAME_OR_INT
8455796c8dcSSimon Schubert */
8465796c8dcSSimon Schubert ;
8475796c8dcSSimon Schubert
8485796c8dcSSimon Schubert %%
8495796c8dcSSimon Schubert
8505796c8dcSSimon Schubert /* Take care of parsing a number (anything that starts with a digit).
8515796c8dcSSimon Schubert Set yylval and return the token type; update lexptr.
8525796c8dcSSimon Schubert LEN is the number of characters in it. */
8535796c8dcSSimon Schubert
8545796c8dcSSimon Schubert /*** Needs some error checking for the float case ***/
8555796c8dcSSimon Schubert
8565796c8dcSSimon Schubert static int
857c50c785cSJohn Marino parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
8585796c8dcSSimon Schubert {
8595796c8dcSSimon Schubert /* FIXME: Shouldn't these be unsigned? We don't deal with negative values
8605796c8dcSSimon Schubert here, and we do kind of silly things like cast to unsigned. */
8615796c8dcSSimon Schubert LONGEST n = 0;
8625796c8dcSSimon Schubert LONGEST prevn = 0;
8635796c8dcSSimon Schubert ULONGEST un;
8645796c8dcSSimon Schubert
8655796c8dcSSimon Schubert int i = 0;
8665796c8dcSSimon Schubert int c;
8675796c8dcSSimon Schubert int base = input_radix;
8685796c8dcSSimon Schubert int unsigned_p = 0;
8695796c8dcSSimon Schubert
8705796c8dcSSimon Schubert /* Number of "L" suffixes encountered. */
8715796c8dcSSimon Schubert int long_p = 0;
8725796c8dcSSimon Schubert
8735796c8dcSSimon Schubert /* We have found a "L" or "U" suffix. */
8745796c8dcSSimon Schubert int found_suffix = 0;
8755796c8dcSSimon Schubert
8765796c8dcSSimon Schubert ULONGEST high_bit;
8775796c8dcSSimon Schubert struct type *signed_type;
8785796c8dcSSimon Schubert struct type *unsigned_type;
8795796c8dcSSimon Schubert
8805796c8dcSSimon Schubert if (parsed_float)
8815796c8dcSSimon Schubert {
882c50c785cSJohn Marino if (! parse_c_float (parse_gdbarch, p, len,
883c50c785cSJohn Marino &putithere->typed_val_float.dval,
884c50c785cSJohn Marino &putithere->typed_val_float.type))
8855796c8dcSSimon Schubert return ERROR;
8865796c8dcSSimon Schubert return FLOAT;
8875796c8dcSSimon Schubert }
8885796c8dcSSimon Schubert
889c50c785cSJohn Marino /* Handle base-switching prefixes 0x, 0t, 0d, 0. */
8905796c8dcSSimon Schubert if (p[0] == '0')
8915796c8dcSSimon Schubert switch (p[1])
8925796c8dcSSimon Schubert {
8935796c8dcSSimon Schubert case 'x':
8945796c8dcSSimon Schubert case 'X':
8955796c8dcSSimon Schubert if (len >= 3)
8965796c8dcSSimon Schubert {
8975796c8dcSSimon Schubert p += 2;
8985796c8dcSSimon Schubert base = 16;
8995796c8dcSSimon Schubert len -= 2;
9005796c8dcSSimon Schubert }
9015796c8dcSSimon Schubert break;
9025796c8dcSSimon Schubert
9035796c8dcSSimon Schubert case 't':
9045796c8dcSSimon Schubert case 'T':
9055796c8dcSSimon Schubert case 'd':
9065796c8dcSSimon Schubert case 'D':
9075796c8dcSSimon Schubert if (len >= 3)
9085796c8dcSSimon Schubert {
9095796c8dcSSimon Schubert p += 2;
9105796c8dcSSimon Schubert base = 10;
9115796c8dcSSimon Schubert len -= 2;
9125796c8dcSSimon Schubert }
9135796c8dcSSimon Schubert break;
9145796c8dcSSimon Schubert
9155796c8dcSSimon Schubert default:
9165796c8dcSSimon Schubert base = 8;
9175796c8dcSSimon Schubert break;
9185796c8dcSSimon Schubert }
9195796c8dcSSimon Schubert
9205796c8dcSSimon Schubert while (len-- > 0)
9215796c8dcSSimon Schubert {
9225796c8dcSSimon Schubert c = *p++;
9235796c8dcSSimon Schubert if (c >= 'A' && c <= 'Z')
9245796c8dcSSimon Schubert c += 'a' - 'A';
9255796c8dcSSimon Schubert if (c != 'l' && c != 'u')
9265796c8dcSSimon Schubert n *= base;
9275796c8dcSSimon Schubert if (c >= '0' && c <= '9')
9285796c8dcSSimon Schubert {
9295796c8dcSSimon Schubert if (found_suffix)
9305796c8dcSSimon Schubert return ERROR;
9315796c8dcSSimon Schubert n += i = c - '0';
9325796c8dcSSimon Schubert }
9335796c8dcSSimon Schubert else
9345796c8dcSSimon Schubert {
9355796c8dcSSimon Schubert if (base > 10 && c >= 'a' && c <= 'f')
9365796c8dcSSimon Schubert {
9375796c8dcSSimon Schubert if (found_suffix)
9385796c8dcSSimon Schubert return ERROR;
9395796c8dcSSimon Schubert n += i = c - 'a' + 10;
9405796c8dcSSimon Schubert }
9415796c8dcSSimon Schubert else if (c == 'l')
9425796c8dcSSimon Schubert {
9435796c8dcSSimon Schubert ++long_p;
9445796c8dcSSimon Schubert found_suffix = 1;
9455796c8dcSSimon Schubert }
9465796c8dcSSimon Schubert else if (c == 'u')
9475796c8dcSSimon Schubert {
9485796c8dcSSimon Schubert unsigned_p = 1;
9495796c8dcSSimon Schubert found_suffix = 1;
9505796c8dcSSimon Schubert }
9515796c8dcSSimon Schubert else
9525796c8dcSSimon Schubert return ERROR; /* Char not a digit */
9535796c8dcSSimon Schubert }
9545796c8dcSSimon Schubert if (i >= base)
955c50c785cSJohn Marino return ERROR; /* Invalid digit in this base. */
9565796c8dcSSimon Schubert
9575796c8dcSSimon Schubert /* Portably test for overflow (only works for nonzero values, so make
9585796c8dcSSimon Schubert a second check for zero). FIXME: Can't we just make n and prevn
9595796c8dcSSimon Schubert unsigned and avoid this? */
9605796c8dcSSimon Schubert if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
961c50c785cSJohn Marino unsigned_p = 1; /* Try something unsigned. */
9625796c8dcSSimon Schubert
9635796c8dcSSimon Schubert /* Portably test for unsigned overflow.
9645796c8dcSSimon Schubert FIXME: This check is wrong; for example it doesn't find overflow
9655796c8dcSSimon Schubert on 0x123456789 when LONGEST is 32 bits. */
9665796c8dcSSimon Schubert if (c != 'l' && c != 'u' && n != 0)
9675796c8dcSSimon Schubert {
9685796c8dcSSimon Schubert if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
969c50c785cSJohn Marino error (_("Numeric constant too large."));
9705796c8dcSSimon Schubert }
9715796c8dcSSimon Schubert prevn = n;
9725796c8dcSSimon Schubert }
9735796c8dcSSimon Schubert
9745796c8dcSSimon Schubert /* An integer constant is an int, a long, or a long long. An L
9755796c8dcSSimon Schubert suffix forces it to be long; an LL suffix forces it to be long
9765796c8dcSSimon Schubert long. If not forced to a larger size, it gets the first type of
9775796c8dcSSimon Schubert the above that it fits in. To figure out whether it fits, we
9785796c8dcSSimon Schubert shift it right and see whether anything remains. Note that we
9795796c8dcSSimon Schubert can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
9805796c8dcSSimon Schubert operation, because many compilers will warn about such a shift
9815796c8dcSSimon Schubert (which always produces a zero result). Sometimes gdbarch_int_bit
9825796c8dcSSimon Schubert or gdbarch_long_bit will be that big, sometimes not. To deal with
9835796c8dcSSimon Schubert the case where it is we just always shift the value more than
9845796c8dcSSimon Schubert once, with fewer bits each time. */
9855796c8dcSSimon Schubert
9865796c8dcSSimon Schubert un = (ULONGEST)n >> 2;
9875796c8dcSSimon Schubert if (long_p == 0
9885796c8dcSSimon Schubert && (un >> (gdbarch_int_bit (parse_gdbarch) - 2)) == 0)
9895796c8dcSSimon Schubert {
9905796c8dcSSimon Schubert high_bit = ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch) - 1);
9915796c8dcSSimon Schubert
9925796c8dcSSimon Schubert /* A large decimal (not hex or octal) constant (between INT_MAX
9935796c8dcSSimon Schubert and UINT_MAX) is a long or unsigned long, according to ANSI,
9945796c8dcSSimon Schubert never an unsigned int, but this code treats it as unsigned
9955796c8dcSSimon Schubert int. This probably should be fixed. GCC gives a warning on
9965796c8dcSSimon Schubert such constants. */
9975796c8dcSSimon Schubert
9985796c8dcSSimon Schubert unsigned_type = parse_type->builtin_unsigned_int;
9995796c8dcSSimon Schubert signed_type = parse_type->builtin_int;
10005796c8dcSSimon Schubert }
10015796c8dcSSimon Schubert else if (long_p <= 1
10025796c8dcSSimon Schubert && (un >> (gdbarch_long_bit (parse_gdbarch) - 2)) == 0)
10035796c8dcSSimon Schubert {
10045796c8dcSSimon Schubert high_bit = ((ULONGEST)1) << (gdbarch_long_bit (parse_gdbarch) - 1);
10055796c8dcSSimon Schubert unsigned_type = parse_type->builtin_unsigned_long;
10065796c8dcSSimon Schubert signed_type = parse_type->builtin_long;
10075796c8dcSSimon Schubert }
10085796c8dcSSimon Schubert else
10095796c8dcSSimon Schubert {
10105796c8dcSSimon Schubert int shift;
10115796c8dcSSimon Schubert if (sizeof (ULONGEST) * HOST_CHAR_BIT
10125796c8dcSSimon Schubert < gdbarch_long_long_bit (parse_gdbarch))
10135796c8dcSSimon Schubert /* A long long does not fit in a LONGEST. */
10145796c8dcSSimon Schubert shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
10155796c8dcSSimon Schubert else
10165796c8dcSSimon Schubert shift = (gdbarch_long_long_bit (parse_gdbarch) - 1);
10175796c8dcSSimon Schubert high_bit = (ULONGEST) 1 << shift;
10185796c8dcSSimon Schubert unsigned_type = parse_type->builtin_unsigned_long_long;
10195796c8dcSSimon Schubert signed_type = parse_type->builtin_long_long;
10205796c8dcSSimon Schubert }
10215796c8dcSSimon Schubert
10225796c8dcSSimon Schubert putithere->typed_val_int.val = n;
10235796c8dcSSimon Schubert
10245796c8dcSSimon Schubert /* If the high bit of the worked out type is set then this number
10255796c8dcSSimon Schubert has to be unsigned. */
10265796c8dcSSimon Schubert
10275796c8dcSSimon Schubert if (unsigned_p || (n & high_bit))
10285796c8dcSSimon Schubert {
10295796c8dcSSimon Schubert putithere->typed_val_int.type = unsigned_type;
10305796c8dcSSimon Schubert }
10315796c8dcSSimon Schubert else
10325796c8dcSSimon Schubert {
10335796c8dcSSimon Schubert putithere->typed_val_int.type = signed_type;
10345796c8dcSSimon Schubert }
10355796c8dcSSimon Schubert
10365796c8dcSSimon Schubert return INT;
10375796c8dcSSimon Schubert }
10385796c8dcSSimon Schubert
10395796c8dcSSimon Schubert
10405796c8dcSSimon Schubert struct type_push
10415796c8dcSSimon Schubert {
10425796c8dcSSimon Schubert struct type *stored;
10435796c8dcSSimon Schubert struct type_push *next;
10445796c8dcSSimon Schubert };
10455796c8dcSSimon Schubert
10465796c8dcSSimon Schubert static struct type_push *tp_top = NULL;
10475796c8dcSSimon Schubert
10485796c8dcSSimon Schubert static void
push_current_type(void)10495796c8dcSSimon Schubert push_current_type (void)
10505796c8dcSSimon Schubert {
10515796c8dcSSimon Schubert struct type_push *tpnew;
10525796c8dcSSimon Schubert tpnew = (struct type_push *) malloc (sizeof (struct type_push));
10535796c8dcSSimon Schubert tpnew->next = tp_top;
10545796c8dcSSimon Schubert tpnew->stored = current_type;
10555796c8dcSSimon Schubert current_type = NULL;
10565796c8dcSSimon Schubert tp_top = tpnew;
10575796c8dcSSimon Schubert }
10585796c8dcSSimon Schubert
10595796c8dcSSimon Schubert static void
pop_current_type(void)10605796c8dcSSimon Schubert pop_current_type (void)
10615796c8dcSSimon Schubert {
10625796c8dcSSimon Schubert struct type_push *tp = tp_top;
10635796c8dcSSimon Schubert if (tp)
10645796c8dcSSimon Schubert {
10655796c8dcSSimon Schubert current_type = tp->stored;
10665796c8dcSSimon Schubert tp_top = tp->next;
10675796c8dcSSimon Schubert free (tp);
10685796c8dcSSimon Schubert }
10695796c8dcSSimon Schubert }
10705796c8dcSSimon Schubert
10715796c8dcSSimon Schubert struct token
10725796c8dcSSimon Schubert {
10735796c8dcSSimon Schubert char *operator;
10745796c8dcSSimon Schubert int token;
10755796c8dcSSimon Schubert enum exp_opcode opcode;
10765796c8dcSSimon Schubert };
10775796c8dcSSimon Schubert
10785796c8dcSSimon Schubert static const struct token tokentab3[] =
10795796c8dcSSimon Schubert {
10805796c8dcSSimon Schubert {"shr", RSH, BINOP_END},
10815796c8dcSSimon Schubert {"shl", LSH, BINOP_END},
10825796c8dcSSimon Schubert {"and", ANDAND, BINOP_END},
10835796c8dcSSimon Schubert {"div", DIV, BINOP_END},
10845796c8dcSSimon Schubert {"not", NOT, BINOP_END},
10855796c8dcSSimon Schubert {"mod", MOD, BINOP_END},
10865796c8dcSSimon Schubert {"inc", INCREMENT, BINOP_END},
10875796c8dcSSimon Schubert {"dec", DECREMENT, BINOP_END},
10885796c8dcSSimon Schubert {"xor", XOR, BINOP_END}
10895796c8dcSSimon Schubert };
10905796c8dcSSimon Schubert
10915796c8dcSSimon Schubert static const struct token tokentab2[] =
10925796c8dcSSimon Schubert {
10935796c8dcSSimon Schubert {"or", OR, BINOP_END},
10945796c8dcSSimon Schubert {"<>", NOTEQUAL, BINOP_END},
10955796c8dcSSimon Schubert {"<=", LEQ, BINOP_END},
10965796c8dcSSimon Schubert {">=", GEQ, BINOP_END},
10975796c8dcSSimon Schubert {":=", ASSIGN, BINOP_END},
10985796c8dcSSimon Schubert {"::", COLONCOLON, BINOP_END} };
10995796c8dcSSimon Schubert
1100c50c785cSJohn Marino /* Allocate uppercased var: */
1101c50c785cSJohn Marino /* make an uppercased copy of tokstart. */
1102*ef5ccd6cSJohn Marino static char *
uptok(char * tokstart,int namelen)1103*ef5ccd6cSJohn Marino uptok (char *tokstart, int namelen)
11045796c8dcSSimon Schubert {
11055796c8dcSSimon Schubert int i;
11065796c8dcSSimon Schubert char *uptokstart = (char *)malloc(namelen+1);
11075796c8dcSSimon Schubert for (i = 0;i <= namelen;i++)
11085796c8dcSSimon Schubert {
11095796c8dcSSimon Schubert if ((tokstart[i]>='a' && tokstart[i]<='z'))
11105796c8dcSSimon Schubert uptokstart[i] = tokstart[i]-('a'-'A');
11115796c8dcSSimon Schubert else
11125796c8dcSSimon Schubert uptokstart[i] = tokstart[i];
11135796c8dcSSimon Schubert }
11145796c8dcSSimon Schubert uptokstart[namelen]='\0';
11155796c8dcSSimon Schubert return uptokstart;
11165796c8dcSSimon Schubert }
1117c50c785cSJohn Marino
1118c50c785cSJohn Marino /* This is set if the previously-returned token was a structure
1119c50c785cSJohn Marino operator '.'. This is used only when parsing to
1120c50c785cSJohn Marino do field name completion. */
1121c50c785cSJohn Marino static int last_was_structop;
1122c50c785cSJohn Marino
11235796c8dcSSimon Schubert /* Read one token, getting characters through lexptr. */
11245796c8dcSSimon Schubert
11255796c8dcSSimon Schubert static int
yylex(void)1126c50c785cSJohn Marino yylex (void)
11275796c8dcSSimon Schubert {
11285796c8dcSSimon Schubert int c;
11295796c8dcSSimon Schubert int namelen;
11305796c8dcSSimon Schubert unsigned int i;
11315796c8dcSSimon Schubert char *tokstart;
11325796c8dcSSimon Schubert char *uptokstart;
11335796c8dcSSimon Schubert char *tokptr;
11345796c8dcSSimon Schubert int explen, tempbufindex;
11355796c8dcSSimon Schubert static char *tempbuf;
11365796c8dcSSimon Schubert static int tempbufsize;
1137c50c785cSJohn Marino int saw_structop = last_was_structop;
11385796c8dcSSimon Schubert
1139c50c785cSJohn Marino last_was_structop = 0;
11405796c8dcSSimon Schubert retry:
11415796c8dcSSimon Schubert
11425796c8dcSSimon Schubert prev_lexptr = lexptr;
11435796c8dcSSimon Schubert
11445796c8dcSSimon Schubert tokstart = lexptr;
11455796c8dcSSimon Schubert explen = strlen (lexptr);
11465796c8dcSSimon Schubert /* See if it is a special token of length 3. */
11475796c8dcSSimon Schubert if (explen > 2)
11485796c8dcSSimon Schubert for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
11495796c8dcSSimon Schubert if (strncasecmp (tokstart, tokentab3[i].operator, 3) == 0
11505796c8dcSSimon Schubert && (!isalpha (tokentab3[i].operator[0]) || explen == 3
1151c50c785cSJohn Marino || (!isalpha (tokstart[3])
1152c50c785cSJohn Marino && !isdigit (tokstart[3]) && tokstart[3] != '_')))
11535796c8dcSSimon Schubert {
11545796c8dcSSimon Schubert lexptr += 3;
11555796c8dcSSimon Schubert yylval.opcode = tokentab3[i].opcode;
11565796c8dcSSimon Schubert return tokentab3[i].token;
11575796c8dcSSimon Schubert }
11585796c8dcSSimon Schubert
11595796c8dcSSimon Schubert /* See if it is a special token of length 2. */
11605796c8dcSSimon Schubert if (explen > 1)
11615796c8dcSSimon Schubert for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
11625796c8dcSSimon Schubert if (strncasecmp (tokstart, tokentab2[i].operator, 2) == 0
11635796c8dcSSimon Schubert && (!isalpha (tokentab2[i].operator[0]) || explen == 2
1164c50c785cSJohn Marino || (!isalpha (tokstart[2])
1165c50c785cSJohn Marino && !isdigit (tokstart[2]) && tokstart[2] != '_')))
11665796c8dcSSimon Schubert {
11675796c8dcSSimon Schubert lexptr += 2;
11685796c8dcSSimon Schubert yylval.opcode = tokentab2[i].opcode;
11695796c8dcSSimon Schubert return tokentab2[i].token;
11705796c8dcSSimon Schubert }
11715796c8dcSSimon Schubert
11725796c8dcSSimon Schubert switch (c = *tokstart)
11735796c8dcSSimon Schubert {
11745796c8dcSSimon Schubert case 0:
1175c50c785cSJohn Marino if (saw_structop && search_field)
1176c50c785cSJohn Marino return COMPLETE;
1177c50c785cSJohn Marino else
11785796c8dcSSimon Schubert return 0;
11795796c8dcSSimon Schubert
11805796c8dcSSimon Schubert case ' ':
11815796c8dcSSimon Schubert case '\t':
11825796c8dcSSimon Schubert case '\n':
11835796c8dcSSimon Schubert lexptr++;
11845796c8dcSSimon Schubert goto retry;
11855796c8dcSSimon Schubert
11865796c8dcSSimon Schubert case '\'':
11875796c8dcSSimon Schubert /* We either have a character constant ('0' or '\177' for example)
11885796c8dcSSimon Schubert or we have a quoted symbol reference ('foo(int,int)' in object pascal
11895796c8dcSSimon Schubert for example). */
11905796c8dcSSimon Schubert lexptr++;
11915796c8dcSSimon Schubert c = *lexptr++;
11925796c8dcSSimon Schubert if (c == '\\')
1193cf7f2e2dSJohn Marino c = parse_escape (parse_gdbarch, &lexptr);
11945796c8dcSSimon Schubert else if (c == '\'')
1195c50c785cSJohn Marino error (_("Empty character constant."));
11965796c8dcSSimon Schubert
11975796c8dcSSimon Schubert yylval.typed_val_int.val = c;
11985796c8dcSSimon Schubert yylval.typed_val_int.type = parse_type->builtin_char;
11995796c8dcSSimon Schubert
12005796c8dcSSimon Schubert c = *lexptr++;
12015796c8dcSSimon Schubert if (c != '\'')
12025796c8dcSSimon Schubert {
12035796c8dcSSimon Schubert namelen = skip_quoted (tokstart) - tokstart;
12045796c8dcSSimon Schubert if (namelen > 2)
12055796c8dcSSimon Schubert {
12065796c8dcSSimon Schubert lexptr = tokstart + namelen;
12075796c8dcSSimon Schubert if (lexptr[-1] != '\'')
1208c50c785cSJohn Marino error (_("Unmatched single quote."));
12095796c8dcSSimon Schubert namelen -= 2;
12105796c8dcSSimon Schubert tokstart++;
12115796c8dcSSimon Schubert uptokstart = uptok(tokstart,namelen);
12125796c8dcSSimon Schubert goto tryname;
12135796c8dcSSimon Schubert }
1214c50c785cSJohn Marino error (_("Invalid character constant."));
12155796c8dcSSimon Schubert }
12165796c8dcSSimon Schubert return INT;
12175796c8dcSSimon Schubert
12185796c8dcSSimon Schubert case '(':
12195796c8dcSSimon Schubert paren_depth++;
12205796c8dcSSimon Schubert lexptr++;
12215796c8dcSSimon Schubert return c;
12225796c8dcSSimon Schubert
12235796c8dcSSimon Schubert case ')':
12245796c8dcSSimon Schubert if (paren_depth == 0)
12255796c8dcSSimon Schubert return 0;
12265796c8dcSSimon Schubert paren_depth--;
12275796c8dcSSimon Schubert lexptr++;
12285796c8dcSSimon Schubert return c;
12295796c8dcSSimon Schubert
12305796c8dcSSimon Schubert case ',':
12315796c8dcSSimon Schubert if (comma_terminates && paren_depth == 0)
12325796c8dcSSimon Schubert return 0;
12335796c8dcSSimon Schubert lexptr++;
12345796c8dcSSimon Schubert return c;
12355796c8dcSSimon Schubert
12365796c8dcSSimon Schubert case '.':
12375796c8dcSSimon Schubert /* Might be a floating point number. */
12385796c8dcSSimon Schubert if (lexptr[1] < '0' || lexptr[1] > '9')
1239c50c785cSJohn Marino {
1240*ef5ccd6cSJohn Marino if (parse_completion)
1241c50c785cSJohn Marino last_was_structop = 1;
12425796c8dcSSimon Schubert goto symbol; /* Nope, must be a symbol. */
1243c50c785cSJohn Marino }
1244c50c785cSJohn Marino
12455796c8dcSSimon Schubert /* FALL THRU into number case. */
12465796c8dcSSimon Schubert
12475796c8dcSSimon Schubert case '0':
12485796c8dcSSimon Schubert case '1':
12495796c8dcSSimon Schubert case '2':
12505796c8dcSSimon Schubert case '3':
12515796c8dcSSimon Schubert case '4':
12525796c8dcSSimon Schubert case '5':
12535796c8dcSSimon Schubert case '6':
12545796c8dcSSimon Schubert case '7':
12555796c8dcSSimon Schubert case '8':
12565796c8dcSSimon Schubert case '9':
12575796c8dcSSimon Schubert {
12585796c8dcSSimon Schubert /* It's a number. */
12595796c8dcSSimon Schubert int got_dot = 0, got_e = 0, toktype;
12605796c8dcSSimon Schubert char *p = tokstart;
12615796c8dcSSimon Schubert int hex = input_radix > 10;
12625796c8dcSSimon Schubert
12635796c8dcSSimon Schubert if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
12645796c8dcSSimon Schubert {
12655796c8dcSSimon Schubert p += 2;
12665796c8dcSSimon Schubert hex = 1;
12675796c8dcSSimon Schubert }
1268c50c785cSJohn Marino else if (c == '0' && (p[1]=='t' || p[1]=='T'
1269c50c785cSJohn Marino || p[1]=='d' || p[1]=='D'))
12705796c8dcSSimon Schubert {
12715796c8dcSSimon Schubert p += 2;
12725796c8dcSSimon Schubert hex = 0;
12735796c8dcSSimon Schubert }
12745796c8dcSSimon Schubert
12755796c8dcSSimon Schubert for (;; ++p)
12765796c8dcSSimon Schubert {
12775796c8dcSSimon Schubert /* This test includes !hex because 'e' is a valid hex digit
12785796c8dcSSimon Schubert and thus does not indicate a floating point number when
12795796c8dcSSimon Schubert the radix is hex. */
12805796c8dcSSimon Schubert if (!hex && !got_e && (*p == 'e' || *p == 'E'))
12815796c8dcSSimon Schubert got_dot = got_e = 1;
12825796c8dcSSimon Schubert /* This test does not include !hex, because a '.' always indicates
12835796c8dcSSimon Schubert a decimal floating point number regardless of the radix. */
12845796c8dcSSimon Schubert else if (!got_dot && *p == '.')
12855796c8dcSSimon Schubert got_dot = 1;
12865796c8dcSSimon Schubert else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
12875796c8dcSSimon Schubert && (*p == '-' || *p == '+'))
12885796c8dcSSimon Schubert /* This is the sign of the exponent, not the end of the
12895796c8dcSSimon Schubert number. */
12905796c8dcSSimon Schubert continue;
12915796c8dcSSimon Schubert /* We will take any letters or digits. parse_number will
12925796c8dcSSimon Schubert complain if past the radix, or if L or U are not final. */
12935796c8dcSSimon Schubert else if ((*p < '0' || *p > '9')
12945796c8dcSSimon Schubert && ((*p < 'a' || *p > 'z')
12955796c8dcSSimon Schubert && (*p < 'A' || *p > 'Z')))
12965796c8dcSSimon Schubert break;
12975796c8dcSSimon Schubert }
1298c50c785cSJohn Marino toktype = parse_number (tokstart,
1299c50c785cSJohn Marino p - tokstart, got_dot | got_e, &yylval);
13005796c8dcSSimon Schubert if (toktype == ERROR)
13015796c8dcSSimon Schubert {
13025796c8dcSSimon Schubert char *err_copy = (char *) alloca (p - tokstart + 1);
13035796c8dcSSimon Schubert
13045796c8dcSSimon Schubert memcpy (err_copy, tokstart, p - tokstart);
13055796c8dcSSimon Schubert err_copy[p - tokstart] = 0;
1306c50c785cSJohn Marino error (_("Invalid number \"%s\"."), err_copy);
13075796c8dcSSimon Schubert }
13085796c8dcSSimon Schubert lexptr = p;
13095796c8dcSSimon Schubert return toktype;
13105796c8dcSSimon Schubert }
13115796c8dcSSimon Schubert
13125796c8dcSSimon Schubert case '+':
13135796c8dcSSimon Schubert case '-':
13145796c8dcSSimon Schubert case '*':
13155796c8dcSSimon Schubert case '/':
13165796c8dcSSimon Schubert case '|':
13175796c8dcSSimon Schubert case '&':
13185796c8dcSSimon Schubert case '^':
13195796c8dcSSimon Schubert case '~':
13205796c8dcSSimon Schubert case '!':
13215796c8dcSSimon Schubert case '@':
13225796c8dcSSimon Schubert case '<':
13235796c8dcSSimon Schubert case '>':
13245796c8dcSSimon Schubert case '[':
13255796c8dcSSimon Schubert case ']':
13265796c8dcSSimon Schubert case '?':
13275796c8dcSSimon Schubert case ':':
13285796c8dcSSimon Schubert case '=':
13295796c8dcSSimon Schubert case '{':
13305796c8dcSSimon Schubert case '}':
13315796c8dcSSimon Schubert symbol:
13325796c8dcSSimon Schubert lexptr++;
13335796c8dcSSimon Schubert return c;
13345796c8dcSSimon Schubert
13355796c8dcSSimon Schubert case '"':
13365796c8dcSSimon Schubert
13375796c8dcSSimon Schubert /* Build the gdb internal form of the input string in tempbuf,
13385796c8dcSSimon Schubert translating any standard C escape forms seen. Note that the
13395796c8dcSSimon Schubert buffer is null byte terminated *only* for the convenience of
13405796c8dcSSimon Schubert debugging gdb itself and printing the buffer contents when
13415796c8dcSSimon Schubert the buffer contains no embedded nulls. Gdb does not depend
13425796c8dcSSimon Schubert upon the buffer being null byte terminated, it uses the length
13435796c8dcSSimon Schubert string instead. This allows gdb to handle C strings (as well
1344c50c785cSJohn Marino as strings in other languages) with embedded null bytes. */
13455796c8dcSSimon Schubert
13465796c8dcSSimon Schubert tokptr = ++tokstart;
13475796c8dcSSimon Schubert tempbufindex = 0;
13485796c8dcSSimon Schubert
13495796c8dcSSimon Schubert do {
13505796c8dcSSimon Schubert /* Grow the static temp buffer if necessary, including allocating
13515796c8dcSSimon Schubert the first one on demand. */
13525796c8dcSSimon Schubert if (tempbufindex + 1 >= tempbufsize)
13535796c8dcSSimon Schubert {
13545796c8dcSSimon Schubert tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
13555796c8dcSSimon Schubert }
13565796c8dcSSimon Schubert
13575796c8dcSSimon Schubert switch (*tokptr)
13585796c8dcSSimon Schubert {
13595796c8dcSSimon Schubert case '\0':
13605796c8dcSSimon Schubert case '"':
13615796c8dcSSimon Schubert /* Do nothing, loop will terminate. */
13625796c8dcSSimon Schubert break;
13635796c8dcSSimon Schubert case '\\':
13645796c8dcSSimon Schubert tokptr++;
1365cf7f2e2dSJohn Marino c = parse_escape (parse_gdbarch, &tokptr);
13665796c8dcSSimon Schubert if (c == -1)
13675796c8dcSSimon Schubert {
13685796c8dcSSimon Schubert continue;
13695796c8dcSSimon Schubert }
13705796c8dcSSimon Schubert tempbuf[tempbufindex++] = c;
13715796c8dcSSimon Schubert break;
13725796c8dcSSimon Schubert default:
13735796c8dcSSimon Schubert tempbuf[tempbufindex++] = *tokptr++;
13745796c8dcSSimon Schubert break;
13755796c8dcSSimon Schubert }
13765796c8dcSSimon Schubert } while ((*tokptr != '"') && (*tokptr != '\0'));
13775796c8dcSSimon Schubert if (*tokptr++ != '"')
13785796c8dcSSimon Schubert {
1379c50c785cSJohn Marino error (_("Unterminated string in expression."));
13805796c8dcSSimon Schubert }
1381c50c785cSJohn Marino tempbuf[tempbufindex] = '\0'; /* See note above. */
13825796c8dcSSimon Schubert yylval.sval.ptr = tempbuf;
13835796c8dcSSimon Schubert yylval.sval.length = tempbufindex;
13845796c8dcSSimon Schubert lexptr = tokptr;
13855796c8dcSSimon Schubert return (STRING);
13865796c8dcSSimon Schubert }
13875796c8dcSSimon Schubert
13885796c8dcSSimon Schubert if (!(c == '_' || c == '$'
13895796c8dcSSimon Schubert || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
13905796c8dcSSimon Schubert /* We must have come across a bad character (e.g. ';'). */
1391c50c785cSJohn Marino error (_("Invalid character '%c' in expression."), c);
13925796c8dcSSimon Schubert
13935796c8dcSSimon Schubert /* It's a name. See how long it is. */
13945796c8dcSSimon Schubert namelen = 0;
13955796c8dcSSimon Schubert for (c = tokstart[namelen];
13965796c8dcSSimon Schubert (c == '_' || c == '$' || (c >= '0' && c <= '9')
13975796c8dcSSimon Schubert || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
13985796c8dcSSimon Schubert {
13995796c8dcSSimon Schubert /* Template parameter lists are part of the name.
14005796c8dcSSimon Schubert FIXME: This mishandles `print $a<4&&$a>3'. */
14015796c8dcSSimon Schubert if (c == '<')
14025796c8dcSSimon Schubert {
14035796c8dcSSimon Schubert int i = namelen;
14045796c8dcSSimon Schubert int nesting_level = 1;
14055796c8dcSSimon Schubert while (tokstart[++i])
14065796c8dcSSimon Schubert {
14075796c8dcSSimon Schubert if (tokstart[i] == '<')
14085796c8dcSSimon Schubert nesting_level++;
14095796c8dcSSimon Schubert else if (tokstart[i] == '>')
14105796c8dcSSimon Schubert {
14115796c8dcSSimon Schubert if (--nesting_level == 0)
14125796c8dcSSimon Schubert break;
14135796c8dcSSimon Schubert }
14145796c8dcSSimon Schubert }
14155796c8dcSSimon Schubert if (tokstart[i] == '>')
14165796c8dcSSimon Schubert namelen = i;
14175796c8dcSSimon Schubert else
14185796c8dcSSimon Schubert break;
14195796c8dcSSimon Schubert }
14205796c8dcSSimon Schubert
14215796c8dcSSimon Schubert /* do NOT uppercase internals because of registers !!! */
14225796c8dcSSimon Schubert c = tokstart[++namelen];
14235796c8dcSSimon Schubert }
14245796c8dcSSimon Schubert
14255796c8dcSSimon Schubert uptokstart = uptok(tokstart,namelen);
14265796c8dcSSimon Schubert
14275796c8dcSSimon Schubert /* The token "if" terminates the expression and is NOT
14285796c8dcSSimon Schubert removed from the input stream. */
14295796c8dcSSimon Schubert if (namelen == 2 && uptokstart[0] == 'I' && uptokstart[1] == 'F')
14305796c8dcSSimon Schubert {
14315796c8dcSSimon Schubert free (uptokstart);
14325796c8dcSSimon Schubert return 0;
14335796c8dcSSimon Schubert }
14345796c8dcSSimon Schubert
14355796c8dcSSimon Schubert lexptr += namelen;
14365796c8dcSSimon Schubert
14375796c8dcSSimon Schubert tryname:
14385796c8dcSSimon Schubert
14395796c8dcSSimon Schubert /* Catch specific keywords. Should be done with a data structure. */
14405796c8dcSSimon Schubert switch (namelen)
14415796c8dcSSimon Schubert {
14425796c8dcSSimon Schubert case 6:
14435796c8dcSSimon Schubert if (strcmp (uptokstart, "OBJECT") == 0)
14445796c8dcSSimon Schubert {
14455796c8dcSSimon Schubert free (uptokstart);
14465796c8dcSSimon Schubert return CLASS;
14475796c8dcSSimon Schubert }
14485796c8dcSSimon Schubert if (strcmp (uptokstart, "RECORD") == 0)
14495796c8dcSSimon Schubert {
14505796c8dcSSimon Schubert free (uptokstart);
14515796c8dcSSimon Schubert return STRUCT;
14525796c8dcSSimon Schubert }
14535796c8dcSSimon Schubert if (strcmp (uptokstart, "SIZEOF") == 0)
14545796c8dcSSimon Schubert {
14555796c8dcSSimon Schubert free (uptokstart);
14565796c8dcSSimon Schubert return SIZEOF;
14575796c8dcSSimon Schubert }
14585796c8dcSSimon Schubert break;
14595796c8dcSSimon Schubert case 5:
14605796c8dcSSimon Schubert if (strcmp (uptokstart, "CLASS") == 0)
14615796c8dcSSimon Schubert {
14625796c8dcSSimon Schubert free (uptokstart);
14635796c8dcSSimon Schubert return CLASS;
14645796c8dcSSimon Schubert }
14655796c8dcSSimon Schubert if (strcmp (uptokstart, "FALSE") == 0)
14665796c8dcSSimon Schubert {
14675796c8dcSSimon Schubert yylval.lval = 0;
14685796c8dcSSimon Schubert free (uptokstart);
14695796c8dcSSimon Schubert return FALSEKEYWORD;
14705796c8dcSSimon Schubert }
14715796c8dcSSimon Schubert break;
14725796c8dcSSimon Schubert case 4:
14735796c8dcSSimon Schubert if (strcmp (uptokstart, "TRUE") == 0)
14745796c8dcSSimon Schubert {
14755796c8dcSSimon Schubert yylval.lval = 1;
14765796c8dcSSimon Schubert free (uptokstart);
14775796c8dcSSimon Schubert return TRUEKEYWORD;
14785796c8dcSSimon Schubert }
14795796c8dcSSimon Schubert if (strcmp (uptokstart, "SELF") == 0)
14805796c8dcSSimon Schubert {
1481c50c785cSJohn Marino /* Here we search for 'this' like
1482c50c785cSJohn Marino inserted in FPC stabs debug info. */
14835796c8dcSSimon Schubert static const char this_name[] = "this";
14845796c8dcSSimon Schubert
14855796c8dcSSimon Schubert if (lookup_symbol (this_name, expression_context_block,
1486*ef5ccd6cSJohn Marino VAR_DOMAIN, NULL))
14875796c8dcSSimon Schubert {
14885796c8dcSSimon Schubert free (uptokstart);
14895796c8dcSSimon Schubert return THIS;
14905796c8dcSSimon Schubert }
14915796c8dcSSimon Schubert }
14925796c8dcSSimon Schubert break;
14935796c8dcSSimon Schubert default:
14945796c8dcSSimon Schubert break;
14955796c8dcSSimon Schubert }
14965796c8dcSSimon Schubert
14975796c8dcSSimon Schubert yylval.sval.ptr = tokstart;
14985796c8dcSSimon Schubert yylval.sval.length = namelen;
14995796c8dcSSimon Schubert
15005796c8dcSSimon Schubert if (*tokstart == '$')
15015796c8dcSSimon Schubert {
1502c50c785cSJohn Marino char c;
15035796c8dcSSimon Schubert /* $ is the normal prefix for pascal hexadecimal values
15045796c8dcSSimon Schubert but this conflicts with the GDB use for debugger variables
15055796c8dcSSimon Schubert so in expression to enter hexadecimal values
15065796c8dcSSimon Schubert we still need to use C syntax with 0xff */
15075796c8dcSSimon Schubert write_dollar_variable (yylval.sval);
1508c50c785cSJohn Marino c = tokstart[namelen];
1509c50c785cSJohn Marino tokstart[namelen] = 0;
1510c50c785cSJohn Marino intvar = lookup_only_internalvar (++tokstart);
1511c50c785cSJohn Marino --tokstart;
1512c50c785cSJohn Marino tokstart[namelen] = c;
15135796c8dcSSimon Schubert free (uptokstart);
15145796c8dcSSimon Schubert return VARIABLE;
15155796c8dcSSimon Schubert }
15165796c8dcSSimon Schubert
15175796c8dcSSimon Schubert /* Use token-type BLOCKNAME for symbols that happen to be defined as
15185796c8dcSSimon Schubert functions or symtabs. If this is not so, then ...
15195796c8dcSSimon Schubert Use token-type TYPENAME for symbols that happen to be defined
15205796c8dcSSimon Schubert currently as names of types; NAME for other symbols.
15215796c8dcSSimon Schubert The caller is not constrained to care about the distinction. */
15225796c8dcSSimon Schubert {
15235796c8dcSSimon Schubert char *tmp = copy_name (yylval.sval);
15245796c8dcSSimon Schubert struct symbol *sym;
1525*ef5ccd6cSJohn Marino struct field_of_this_result is_a_field_of_this;
15265796c8dcSSimon Schubert int is_a_field = 0;
15275796c8dcSSimon Schubert int hextype;
15285796c8dcSSimon Schubert
15295796c8dcSSimon Schubert
15305796c8dcSSimon Schubert if (search_field && current_type)
15315796c8dcSSimon Schubert is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
1532*ef5ccd6cSJohn Marino if (is_a_field || parse_completion)
15335796c8dcSSimon Schubert sym = NULL;
15345796c8dcSSimon Schubert else
15355796c8dcSSimon Schubert sym = lookup_symbol (tmp, expression_context_block,
15365796c8dcSSimon Schubert VAR_DOMAIN, &is_a_field_of_this);
15375796c8dcSSimon Schubert /* second chance uppercased (as Free Pascal does). */
1538*ef5ccd6cSJohn Marino if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
15395796c8dcSSimon Schubert {
15405796c8dcSSimon Schubert for (i = 0; i <= namelen; i++)
15415796c8dcSSimon Schubert {
15425796c8dcSSimon Schubert if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
15435796c8dcSSimon Schubert tmp[i] -= ('a'-'A');
15445796c8dcSSimon Schubert }
15455796c8dcSSimon Schubert if (search_field && current_type)
15465796c8dcSSimon Schubert is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
1547*ef5ccd6cSJohn Marino if (is_a_field || parse_completion)
15485796c8dcSSimon Schubert sym = NULL;
15495796c8dcSSimon Schubert else
15505796c8dcSSimon Schubert sym = lookup_symbol (tmp, expression_context_block,
15515796c8dcSSimon Schubert VAR_DOMAIN, &is_a_field_of_this);
1552*ef5ccd6cSJohn Marino if (sym || is_a_field_of_this.type != NULL || is_a_field)
15535796c8dcSSimon Schubert for (i = 0; i <= namelen; i++)
15545796c8dcSSimon Schubert {
15555796c8dcSSimon Schubert if ((tokstart[i] >= 'a' && tokstart[i] <= 'z'))
15565796c8dcSSimon Schubert tokstart[i] -= ('a'-'A');
15575796c8dcSSimon Schubert }
15585796c8dcSSimon Schubert }
15595796c8dcSSimon Schubert /* Third chance Capitalized (as GPC does). */
1560*ef5ccd6cSJohn Marino if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
15615796c8dcSSimon Schubert {
15625796c8dcSSimon Schubert for (i = 0; i <= namelen; i++)
15635796c8dcSSimon Schubert {
15645796c8dcSSimon Schubert if (i == 0)
15655796c8dcSSimon Schubert {
15665796c8dcSSimon Schubert if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
15675796c8dcSSimon Schubert tmp[i] -= ('a'-'A');
15685796c8dcSSimon Schubert }
15695796c8dcSSimon Schubert else
15705796c8dcSSimon Schubert if ((tmp[i] >= 'A' && tmp[i] <= 'Z'))
15715796c8dcSSimon Schubert tmp[i] -= ('A'-'a');
15725796c8dcSSimon Schubert }
15735796c8dcSSimon Schubert if (search_field && current_type)
15745796c8dcSSimon Schubert is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
1575*ef5ccd6cSJohn Marino if (is_a_field || parse_completion)
15765796c8dcSSimon Schubert sym = NULL;
15775796c8dcSSimon Schubert else
15785796c8dcSSimon Schubert sym = lookup_symbol (tmp, expression_context_block,
15795796c8dcSSimon Schubert VAR_DOMAIN, &is_a_field_of_this);
1580*ef5ccd6cSJohn Marino if (sym || is_a_field_of_this.type != NULL || is_a_field)
15815796c8dcSSimon Schubert for (i = 0; i <= namelen; i++)
15825796c8dcSSimon Schubert {
15835796c8dcSSimon Schubert if (i == 0)
15845796c8dcSSimon Schubert {
15855796c8dcSSimon Schubert if ((tokstart[i] >= 'a' && tokstart[i] <= 'z'))
15865796c8dcSSimon Schubert tokstart[i] -= ('a'-'A');
15875796c8dcSSimon Schubert }
15885796c8dcSSimon Schubert else
15895796c8dcSSimon Schubert if ((tokstart[i] >= 'A' && tokstart[i] <= 'Z'))
15905796c8dcSSimon Schubert tokstart[i] -= ('A'-'a');
15915796c8dcSSimon Schubert }
15925796c8dcSSimon Schubert }
15935796c8dcSSimon Schubert
15945796c8dcSSimon Schubert if (is_a_field)
15955796c8dcSSimon Schubert {
15965796c8dcSSimon Schubert tempbuf = (char *) realloc (tempbuf, namelen + 1);
15975796c8dcSSimon Schubert strncpy (tempbuf, tokstart, namelen); tempbuf [namelen] = 0;
15985796c8dcSSimon Schubert yylval.sval.ptr = tempbuf;
15995796c8dcSSimon Schubert yylval.sval.length = namelen;
16005796c8dcSSimon Schubert free (uptokstart);
16015796c8dcSSimon Schubert return FIELDNAME;
16025796c8dcSSimon Schubert }
16035796c8dcSSimon Schubert /* Call lookup_symtab, not lookup_partial_symtab, in case there are
16045796c8dcSSimon Schubert no psymtabs (coff, xcoff, or some future change to blow away the
16055796c8dcSSimon Schubert psymtabs once once symbols are read). */
16065796c8dcSSimon Schubert if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
16075796c8dcSSimon Schubert || lookup_symtab (tmp))
16085796c8dcSSimon Schubert {
16095796c8dcSSimon Schubert yylval.ssym.sym = sym;
1610*ef5ccd6cSJohn Marino yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
16115796c8dcSSimon Schubert free (uptokstart);
16125796c8dcSSimon Schubert return BLOCKNAME;
16135796c8dcSSimon Schubert }
16145796c8dcSSimon Schubert if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
16155796c8dcSSimon Schubert {
16165796c8dcSSimon Schubert #if 1
16175796c8dcSSimon Schubert /* Despite the following flaw, we need to keep this code enabled.
16185796c8dcSSimon Schubert Because we can get called from check_stub_method, if we don't
16195796c8dcSSimon Schubert handle nested types then it screws many operations in any
16205796c8dcSSimon Schubert program which uses nested types. */
16215796c8dcSSimon Schubert /* In "A::x", if x is a member function of A and there happens
16225796c8dcSSimon Schubert to be a type (nested or not, since the stabs don't make that
16235796c8dcSSimon Schubert distinction) named x, then this code incorrectly thinks we
16245796c8dcSSimon Schubert are dealing with nested types rather than a member function. */
16255796c8dcSSimon Schubert
16265796c8dcSSimon Schubert char *p;
16275796c8dcSSimon Schubert char *namestart;
16285796c8dcSSimon Schubert struct symbol *best_sym;
16295796c8dcSSimon Schubert
16305796c8dcSSimon Schubert /* Look ahead to detect nested types. This probably should be
16315796c8dcSSimon Schubert done in the grammar, but trying seemed to introduce a lot
16325796c8dcSSimon Schubert of shift/reduce and reduce/reduce conflicts. It's possible
16335796c8dcSSimon Schubert that it could be done, though. Or perhaps a non-grammar, but
16345796c8dcSSimon Schubert less ad hoc, approach would work well. */
16355796c8dcSSimon Schubert
16365796c8dcSSimon Schubert /* Since we do not currently have any way of distinguishing
16375796c8dcSSimon Schubert a nested type from a non-nested one (the stabs don't tell
16385796c8dcSSimon Schubert us whether a type is nested), we just ignore the
16395796c8dcSSimon Schubert containing type. */
16405796c8dcSSimon Schubert
16415796c8dcSSimon Schubert p = lexptr;
16425796c8dcSSimon Schubert best_sym = sym;
16435796c8dcSSimon Schubert while (1)
16445796c8dcSSimon Schubert {
16455796c8dcSSimon Schubert /* Skip whitespace. */
16465796c8dcSSimon Schubert while (*p == ' ' || *p == '\t' || *p == '\n')
16475796c8dcSSimon Schubert ++p;
16485796c8dcSSimon Schubert if (*p == ':' && p[1] == ':')
16495796c8dcSSimon Schubert {
16505796c8dcSSimon Schubert /* Skip the `::'. */
16515796c8dcSSimon Schubert p += 2;
16525796c8dcSSimon Schubert /* Skip whitespace. */
16535796c8dcSSimon Schubert while (*p == ' ' || *p == '\t' || *p == '\n')
16545796c8dcSSimon Schubert ++p;
16555796c8dcSSimon Schubert namestart = p;
16565796c8dcSSimon Schubert while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
16575796c8dcSSimon Schubert || (*p >= 'a' && *p <= 'z')
16585796c8dcSSimon Schubert || (*p >= 'A' && *p <= 'Z'))
16595796c8dcSSimon Schubert ++p;
16605796c8dcSSimon Schubert if (p != namestart)
16615796c8dcSSimon Schubert {
16625796c8dcSSimon Schubert struct symbol *cur_sym;
16635796c8dcSSimon Schubert /* As big as the whole rest of the expression, which is
16645796c8dcSSimon Schubert at least big enough. */
16655796c8dcSSimon Schubert char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
16665796c8dcSSimon Schubert char *tmp1;
16675796c8dcSSimon Schubert
16685796c8dcSSimon Schubert tmp1 = ncopy;
16695796c8dcSSimon Schubert memcpy (tmp1, tmp, strlen (tmp));
16705796c8dcSSimon Schubert tmp1 += strlen (tmp);
16715796c8dcSSimon Schubert memcpy (tmp1, "::", 2);
16725796c8dcSSimon Schubert tmp1 += 2;
16735796c8dcSSimon Schubert memcpy (tmp1, namestart, p - namestart);
16745796c8dcSSimon Schubert tmp1[p - namestart] = '\0';
16755796c8dcSSimon Schubert cur_sym = lookup_symbol (ncopy, expression_context_block,
1676*ef5ccd6cSJohn Marino VAR_DOMAIN, NULL);
16775796c8dcSSimon Schubert if (cur_sym)
16785796c8dcSSimon Schubert {
16795796c8dcSSimon Schubert if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
16805796c8dcSSimon Schubert {
16815796c8dcSSimon Schubert best_sym = cur_sym;
16825796c8dcSSimon Schubert lexptr = p;
16835796c8dcSSimon Schubert }
16845796c8dcSSimon Schubert else
16855796c8dcSSimon Schubert break;
16865796c8dcSSimon Schubert }
16875796c8dcSSimon Schubert else
16885796c8dcSSimon Schubert break;
16895796c8dcSSimon Schubert }
16905796c8dcSSimon Schubert else
16915796c8dcSSimon Schubert break;
16925796c8dcSSimon Schubert }
16935796c8dcSSimon Schubert else
16945796c8dcSSimon Schubert break;
16955796c8dcSSimon Schubert }
16965796c8dcSSimon Schubert
16975796c8dcSSimon Schubert yylval.tsym.type = SYMBOL_TYPE (best_sym);
16985796c8dcSSimon Schubert #else /* not 0 */
16995796c8dcSSimon Schubert yylval.tsym.type = SYMBOL_TYPE (sym);
17005796c8dcSSimon Schubert #endif /* not 0 */
17015796c8dcSSimon Schubert free (uptokstart);
17025796c8dcSSimon Schubert return TYPENAME;
17035796c8dcSSimon Schubert }
17045796c8dcSSimon Schubert yylval.tsym.type
17055796c8dcSSimon Schubert = language_lookup_primitive_type_by_name (parse_language,
17065796c8dcSSimon Schubert parse_gdbarch, tmp);
17075796c8dcSSimon Schubert if (yylval.tsym.type != NULL)
17085796c8dcSSimon Schubert {
17095796c8dcSSimon Schubert free (uptokstart);
17105796c8dcSSimon Schubert return TYPENAME;
17115796c8dcSSimon Schubert }
17125796c8dcSSimon Schubert
17135796c8dcSSimon Schubert /* Input names that aren't symbols but ARE valid hex numbers,
17145796c8dcSSimon Schubert when the input radix permits them, can be names or numbers
17155796c8dcSSimon Schubert depending on the parse. Note we support radixes > 16 here. */
17165796c8dcSSimon Schubert if (!sym
17175796c8dcSSimon Schubert && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
17185796c8dcSSimon Schubert || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
17195796c8dcSSimon Schubert {
17205796c8dcSSimon Schubert YYSTYPE newlval; /* Its value is ignored. */
17215796c8dcSSimon Schubert hextype = parse_number (tokstart, namelen, 0, &newlval);
17225796c8dcSSimon Schubert if (hextype == INT)
17235796c8dcSSimon Schubert {
17245796c8dcSSimon Schubert yylval.ssym.sym = sym;
1725*ef5ccd6cSJohn Marino yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
17265796c8dcSSimon Schubert free (uptokstart);
17275796c8dcSSimon Schubert return NAME_OR_INT;
17285796c8dcSSimon Schubert }
17295796c8dcSSimon Schubert }
17305796c8dcSSimon Schubert
17315796c8dcSSimon Schubert free(uptokstart);
1732c50c785cSJohn Marino /* Any other kind of symbol. */
17335796c8dcSSimon Schubert yylval.ssym.sym = sym;
1734*ef5ccd6cSJohn Marino yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
17355796c8dcSSimon Schubert return NAME;
17365796c8dcSSimon Schubert }
17375796c8dcSSimon Schubert }
17385796c8dcSSimon Schubert
17395796c8dcSSimon Schubert void
yyerror(char * msg)1740*ef5ccd6cSJohn Marino yyerror (char *msg)
17415796c8dcSSimon Schubert {
17425796c8dcSSimon Schubert if (prev_lexptr)
17435796c8dcSSimon Schubert lexptr = prev_lexptr;
17445796c8dcSSimon Schubert
1745c50c785cSJohn Marino error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
17465796c8dcSSimon Schubert }
1747