OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [c-exp.y] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
/* YACC parser for C expressions, for GDB.
2
   Copyright 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3
   1998, 1999, 2000
4
   Free Software Foundation, Inc.
5
 
6
This file is part of GDB.
7
 
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
 
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
21
 
22
/* Parse a C expression from text in a string,
23
   and return the result as a  struct expression  pointer.
24
   That structure contains arithmetic operations in reverse polish,
25
   with constants represented by operations that are followed by special data.
26
   See expression.h for the details of the format.
27
   What is important here is that it can be built up sequentially
28
   during the process of parsing; the lower levels of the tree always
29
   come first in the result.
30
 
31
   Note that malloc's and realloc's in this file are transformed to
32
   xmalloc and xrealloc respectively by the same sed command in the
33
   makefile that remaps any other malloc/realloc inserted by the parser
34
   generator.  Doing this with #defines and trying to control the interaction
35
   with include files ( and  for example) just became
36
   too messy, particularly when such includes can be inserted at random
37
   times by the parser generator.  */
38
 
39
%{
40
 
41
#include "defs.h"
42
#include "gdb_string.h"
43
#include 
44
#include "expression.h"
45
#include "value.h"
46
#include "parser-defs.h"
47
#include "language.h"
48
#include "c-lang.h"
49
#include "bfd.h" /* Required by objfiles.h.  */
50
#include "symfile.h" /* Required by objfiles.h.  */
51
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
52
 
53
/* Flag indicating we're dealing with HP-compiled objects */
54
extern int hp_som_som_object_present;
55
 
56
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
57
   as well as gratuitiously global symbol names, so we can have multiple
58
   yacc generated parsers in gdb.  Note that these are only the variables
59
   produced by yacc.  If other parser generators (bison, byacc, etc) produce
60
   additional global names that conflict at link time, then those parser
61
   generators need to be fixed instead of adding those names to this list. */
62
 
63
#define yymaxdepth c_maxdepth
64
#define yyparse c_parse
65
#define yylex   c_lex
66
#define yyerror c_error
67
#define yylval  c_lval
68
#define yychar  c_char
69
#define yydebug c_debug
70
#define yypact  c_pact
71
#define yyr1    c_r1
72
#define yyr2    c_r2
73
#define yydef   c_def
74
#define yychk   c_chk
75
#define yypgo   c_pgo
76
#define yyact   c_act
77
#define yyexca  c_exca
78
#define yyerrflag c_errflag
79
#define yynerrs c_nerrs
80
#define yyps    c_ps
81
#define yypv    c_pv
82
#define yys     c_s
83
#define yy_yys  c_yys
84
#define yystate c_state
85
#define yytmp   c_tmp
86
#define yyv     c_v
87
#define yy_yyv  c_yyv
88
#define yyval   c_val
89
#define yylloc  c_lloc
90
#define yyreds  c_reds          /* With YYDEBUG defined */
91
#define yytoks  c_toks          /* With YYDEBUG defined */
92
#define yyname  c_name          /* With YYDEBUG defined */
93
#define yyrule  c_rule          /* With YYDEBUG defined */
94
#define yylhs   c_yylhs
95
#define yylen   c_yylen
96
#define yydefred c_yydefred
97
#define yydgoto c_yydgoto
98
#define yysindex c_yysindex
99
#define yyrindex c_yyrindex
100
#define yygindex c_yygindex
101
#define yytable  c_yytable
102
#define yycheck  c_yycheck
103
 
104
#ifndef YYDEBUG
105
#define YYDEBUG 1               /* Default to yydebug support */
106
#endif
107
 
108
#define YYFPRINTF parser_fprintf
109
 
110
int yyparse (void);
111
 
112
static int yylex (void);
113
 
114
void yyerror (char *);
115
 
116
%}
117
 
118
/* Although the yacc "value" of an expression is not used,
119
   since the result is stored in the structure being created,
120
   other node types do have values.  */
121
 
122
%union
123
  {
124
    LONGEST lval;
125
    struct {
126
      LONGEST val;
127
      struct type *type;
128
    } typed_val_int;
129
    struct {
130
      DOUBLEST dval;
131
      struct type *type;
132
    } typed_val_float;
133
    struct symbol *sym;
134
    struct type *tval;
135
    struct stoken sval;
136
    struct ttype tsym;
137
    struct symtoken ssym;
138
    int voidval;
139
    struct block *bval;
140
    enum exp_opcode opcode;
141
    struct internalvar *ivar;
142
 
143
    struct type **tvec;
144
    int *ivec;
145
  }
146
 
147
%{
148
/* YYSTYPE gets defined by %union */
149
static int parse_number (char *, int, int, YYSTYPE *);
150
%}
151
 
152
%type  exp exp1 type_exp start variable qualified_name lcurly
153
%type  rcurly
154
%type  type typebase
155
%type  nonempty_typelist
156
/* %type  block */
157
 
158
/* Fancy type parsing.  */
159
%type  func_mod direct_abs_decl abs_decl
160
%type  ptype
161
%type  array_mod
162
 
163
%token  INT
164
%token  FLOAT
165
 
166
/* Both NAME and TYPENAME tokens represent symbols in the input,
167
   and both convey their data as strings.
168
   But a TYPENAME is a string that happens to be defined as a typedef
169
   or builtin type name (such as int or char)
170
   and a NAME is any other symbol.
171
   Contexts where this distinction is not important can use the
172
   nonterminal "name", which matches either NAME or TYPENAME.  */
173
 
174
%token  STRING
175
%token  NAME /* BLOCKNAME defined below to give it higher precedence. */
176
%token  TYPENAME
177
%type  name
178
%type  name_not_typename
179
%type  typename
180
 
181
/* A NAME_OR_INT is a symbol which is not known in the symbol table,
182
   but which would parse as a valid number in the current input radix.
183
   E.g. "c" when input_radix==16.  Depending on the parse, it will be
184
   turned into a name or into a number.  */
185
 
186
%token  NAME_OR_INT
187
 
188
%token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
189
%token TEMPLATE
190
%token ERROR
191
 
192
/* Special type cases, put in to allow the parser to distinguish different
193
   legal basetypes.  */
194
%token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
195
 
196
%token  VARIABLE
197
 
198
%token  ASSIGN_MODIFY
199
 
200
/* C++ */
201
%token THIS
202
%token TRUEKEYWORD
203
%token FALSEKEYWORD
204
 
205
 
206
%left ','
207
%left ABOVE_COMMA
208
%right '=' ASSIGN_MODIFY
209
%right '?'
210
%left OROR
211
%left ANDAND
212
%left '|'
213
%left '^'
214
%left '&'
215
%left EQUAL NOTEQUAL
216
%left '<' '>' LEQ GEQ
217
%left LSH RSH
218
%left '@'
219
%left '+' '-'
220
%left '*' '/' '%'
221
%right UNARY INCREMENT DECREMENT
222
%right ARROW '.' '[' '('
223
%token  BLOCKNAME
224
%token  FILENAME
225
%type  block
226
%left COLONCOLON
227
 
228
 
229
%%
230
 
231
start   :       exp1
232
        |       type_exp
233
        ;
234
 
235
type_exp:       type
236
                        { write_exp_elt_opcode(OP_TYPE);
237
                          write_exp_elt_type($1);
238
                          write_exp_elt_opcode(OP_TYPE);}
239
        ;
240
 
241
/* Expressions, including the comma operator.  */
242
exp1    :       exp
243
        |       exp1 ',' exp
244
                        { write_exp_elt_opcode (BINOP_COMMA); }
245
        ;
246
 
247
/* Expressions, not including the comma operator.  */
248
exp     :       '*' exp    %prec UNARY
249
                        { write_exp_elt_opcode (UNOP_IND); }
250
        ;
251
 
252
exp     :       '&' exp    %prec UNARY
253
                        { write_exp_elt_opcode (UNOP_ADDR); }
254
        ;
255
 
256
exp     :       '-' exp    %prec UNARY
257
                        { write_exp_elt_opcode (UNOP_NEG); }
258
        ;
259
 
260
exp     :       '!' exp    %prec UNARY
261
                        { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
262
        ;
263
 
264
exp     :       '~' exp    %prec UNARY
265
                        { write_exp_elt_opcode (UNOP_COMPLEMENT); }
266
        ;
267
 
268
exp     :       INCREMENT exp    %prec UNARY
269
                        { write_exp_elt_opcode (UNOP_PREINCREMENT); }
270
        ;
271
 
272
exp     :       DECREMENT exp    %prec UNARY
273
                        { write_exp_elt_opcode (UNOP_PREDECREMENT); }
274
        ;
275
 
276
exp     :       exp INCREMENT    %prec UNARY
277
                        { write_exp_elt_opcode (UNOP_POSTINCREMENT); }
278
        ;
279
 
280
exp     :       exp DECREMENT    %prec UNARY
281
                        { write_exp_elt_opcode (UNOP_POSTDECREMENT); }
282
        ;
283
 
284
exp     :       SIZEOF exp       %prec UNARY
285
                        { write_exp_elt_opcode (UNOP_SIZEOF); }
286
        ;
287
 
288
exp     :       exp ARROW name
289
                        { write_exp_elt_opcode (STRUCTOP_PTR);
290
                          write_exp_string ($3);
291
                          write_exp_elt_opcode (STRUCTOP_PTR); }
292
        ;
293
 
294
exp     :       exp ARROW qualified_name
295
                        { /* exp->type::name becomes exp->*(&type::name) */
296
                          /* Note: this doesn't work if name is a
297
                             static member!  FIXME */
298
                          write_exp_elt_opcode (UNOP_ADDR);
299
                          write_exp_elt_opcode (STRUCTOP_MPTR); }
300
        ;
301
 
302
exp     :       exp ARROW '*' exp
303
                        { write_exp_elt_opcode (STRUCTOP_MPTR); }
304
        ;
305
 
306
exp     :       exp '.' name
307
                        { write_exp_elt_opcode (STRUCTOP_STRUCT);
308
                          write_exp_string ($3);
309
                          write_exp_elt_opcode (STRUCTOP_STRUCT); }
310
        ;
311
 
312
exp     :       exp '.' qualified_name
313
                        { /* exp.type::name becomes exp.*(&type::name) */
314
                          /* Note: this doesn't work if name is a
315
                             static member!  FIXME */
316
                          write_exp_elt_opcode (UNOP_ADDR);
317
                          write_exp_elt_opcode (STRUCTOP_MEMBER); }
318
        ;
319
 
320
exp     :       exp '.' '*' exp
321
                        { write_exp_elt_opcode (STRUCTOP_MEMBER); }
322
        ;
323
 
324
exp     :       exp '[' exp1 ']'
325
                        { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
326
        ;
327
 
328
exp     :       exp '('
329
                        /* This is to save the value of arglist_len
330
                           being accumulated by an outer function call.  */
331
                        { start_arglist (); }
332
                arglist ')'     %prec ARROW
333
                        { write_exp_elt_opcode (OP_FUNCALL);
334
                          write_exp_elt_longcst ((LONGEST) end_arglist ());
335
                          write_exp_elt_opcode (OP_FUNCALL); }
336
        ;
337
 
338
lcurly  :       '{'
339
                        { start_arglist (); }
340
        ;
341
 
342
arglist :
343
        ;
344
 
345
arglist :       exp
346
                        { arglist_len = 1; }
347
        ;
348
 
349
arglist :       arglist ',' exp   %prec ABOVE_COMMA
350
                        { arglist_len++; }
351
        ;
352
 
353
rcurly  :       '}'
354
                        { $$ = end_arglist () - 1; }
355
        ;
356
exp     :       lcurly arglist rcurly   %prec ARROW
357
                        { write_exp_elt_opcode (OP_ARRAY);
358
                          write_exp_elt_longcst ((LONGEST) 0);
359
                          write_exp_elt_longcst ((LONGEST) $3);
360
                          write_exp_elt_opcode (OP_ARRAY); }
361
        ;
362
 
363
exp     :       lcurly type rcurly exp  %prec UNARY
364
                        { write_exp_elt_opcode (UNOP_MEMVAL);
365
                          write_exp_elt_type ($2);
366
                          write_exp_elt_opcode (UNOP_MEMVAL); }
367
        ;
368
 
369
exp     :       '(' type ')' exp  %prec UNARY
370
                        { write_exp_elt_opcode (UNOP_CAST);
371
                          write_exp_elt_type ($2);
372
                          write_exp_elt_opcode (UNOP_CAST); }
373
        ;
374
 
375
exp     :       '(' exp1 ')'
376
                        { }
377
        ;
378
 
379
/* Binary operators in order of decreasing precedence.  */
380
 
381
exp     :       exp '@' exp
382
                        { write_exp_elt_opcode (BINOP_REPEAT); }
383
        ;
384
 
385
exp     :       exp '*' exp
386
                        { write_exp_elt_opcode (BINOP_MUL); }
387
        ;
388
 
389
exp     :       exp '/' exp
390
                        { write_exp_elt_opcode (BINOP_DIV); }
391
        ;
392
 
393
exp     :       exp '%' exp
394
                        { write_exp_elt_opcode (BINOP_REM); }
395
        ;
396
 
397
exp     :       exp '+' exp
398
                        { write_exp_elt_opcode (BINOP_ADD); }
399
        ;
400
 
401
exp     :       exp '-' exp
402
                        { write_exp_elt_opcode (BINOP_SUB); }
403
        ;
404
 
405
exp     :       exp LSH exp
406
                        { write_exp_elt_opcode (BINOP_LSH); }
407
        ;
408
 
409
exp     :       exp RSH exp
410
                        { write_exp_elt_opcode (BINOP_RSH); }
411
        ;
412
 
413
exp     :       exp EQUAL exp
414
                        { write_exp_elt_opcode (BINOP_EQUAL); }
415
        ;
416
 
417
exp     :       exp NOTEQUAL exp
418
                        { write_exp_elt_opcode (BINOP_NOTEQUAL); }
419
        ;
420
 
421
exp     :       exp LEQ exp
422
                        { write_exp_elt_opcode (BINOP_LEQ); }
423
        ;
424
 
425
exp     :       exp GEQ exp
426
                        { write_exp_elt_opcode (BINOP_GEQ); }
427
        ;
428
 
429
exp     :       exp '<' exp
430
                        { write_exp_elt_opcode (BINOP_LESS); }
431
        ;
432
 
433
exp     :       exp '>' exp
434
                        { write_exp_elt_opcode (BINOP_GTR); }
435
        ;
436
 
437
exp     :       exp '&' exp
438
                        { write_exp_elt_opcode (BINOP_BITWISE_AND); }
439
        ;
440
 
441
exp     :       exp '^' exp
442
                        { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
443
        ;
444
 
445
exp     :       exp '|' exp
446
                        { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
447
        ;
448
 
449
exp     :       exp ANDAND exp
450
                        { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
451
        ;
452
 
453
exp     :       exp OROR exp
454
                        { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
455
        ;
456
 
457
exp     :       exp '?' exp ':' exp     %prec '?'
458
                        { write_exp_elt_opcode (TERNOP_COND); }
459
        ;
460
 
461
exp     :       exp '=' exp
462
                        { write_exp_elt_opcode (BINOP_ASSIGN); }
463
        ;
464
 
465
exp     :       exp ASSIGN_MODIFY exp
466
                        { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
467
                          write_exp_elt_opcode ($2);
468
                          write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
469
        ;
470
 
471
exp     :       INT
472
                        { write_exp_elt_opcode (OP_LONG);
473
                          write_exp_elt_type ($1.type);
474
                          write_exp_elt_longcst ((LONGEST)($1.val));
475
                          write_exp_elt_opcode (OP_LONG); }
476
        ;
477
 
478
exp     :       NAME_OR_INT
479
                        { YYSTYPE val;
480
                          parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
481
                          write_exp_elt_opcode (OP_LONG);
482
                          write_exp_elt_type (val.typed_val_int.type);
483
                          write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
484
                          write_exp_elt_opcode (OP_LONG);
485
                        }
486
        ;
487
 
488
 
489
exp     :       FLOAT
490
                        { write_exp_elt_opcode (OP_DOUBLE);
491
                          write_exp_elt_type ($1.type);
492
                          write_exp_elt_dblcst ($1.dval);
493
                          write_exp_elt_opcode (OP_DOUBLE); }
494
        ;
495
 
496
exp     :       variable
497
        ;
498
 
499
exp     :       VARIABLE
500
                        /* Already written by write_dollar_variable. */
501
        ;
502
 
503
exp     :       SIZEOF '(' type ')'     %prec UNARY
504
                        { write_exp_elt_opcode (OP_LONG);
505
                          write_exp_elt_type (builtin_type_int);
506
                          CHECK_TYPEDEF ($3);
507
                          write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
508
                          write_exp_elt_opcode (OP_LONG); }
509
        ;
510
 
511
exp     :       STRING
512
                        { /* C strings are converted into array constants with
513
                             an explicit null byte added at the end.  Thus
514
                             the array upper bound is the string length.
515
                             There is no such thing in C as a completely empty
516
                             string. */
517
                          char *sp = $1.ptr; int count = $1.length;
518
                          while (count-- > 0)
519
                            {
520
                              write_exp_elt_opcode (OP_LONG);
521
                              write_exp_elt_type (builtin_type_char);
522
                              write_exp_elt_longcst ((LONGEST)(*sp++));
523
                              write_exp_elt_opcode (OP_LONG);
524
                            }
525
                          write_exp_elt_opcode (OP_LONG);
526
                          write_exp_elt_type (builtin_type_char);
527
                          write_exp_elt_longcst ((LONGEST)'\0');
528
                          write_exp_elt_opcode (OP_LONG);
529
                          write_exp_elt_opcode (OP_ARRAY);
530
                          write_exp_elt_longcst ((LONGEST) 0);
531
                          write_exp_elt_longcst ((LONGEST) ($1.length));
532
                          write_exp_elt_opcode (OP_ARRAY); }
533
        ;
534
 
535
/* C++.  */
536
exp     :       THIS
537
                        { write_exp_elt_opcode (OP_THIS);
538
                          write_exp_elt_opcode (OP_THIS); }
539
        ;
540
 
541
exp     :       TRUEKEYWORD
542
                        { write_exp_elt_opcode (OP_LONG);
543
                          write_exp_elt_type (builtin_type_bool);
544
                          write_exp_elt_longcst ((LONGEST) 1);
545
                          write_exp_elt_opcode (OP_LONG); }
546
        ;
547
 
548
exp     :       FALSEKEYWORD
549
                        { write_exp_elt_opcode (OP_LONG);
550
                          write_exp_elt_type (builtin_type_bool);
551
                          write_exp_elt_longcst ((LONGEST) 0);
552
                          write_exp_elt_opcode (OP_LONG); }
553
        ;
554
 
555
/* end of C++.  */
556
 
557
block   :       BLOCKNAME
558
                        {
559
                          if ($1.sym)
560
                            $$ = SYMBOL_BLOCK_VALUE ($1.sym);
561
                          else
562
                            error ("No file or function \"%s\".",
563
                                   copy_name ($1.stoken));
564
                        }
565
        |       FILENAME
566
                        {
567
                          $$ = $1;
568
                        }
569
        ;
570
 
571
block   :       block COLONCOLON name
572
                        { struct symbol *tem
573
                            = lookup_symbol (copy_name ($3), $1,
574
                                             VAR_NAMESPACE, (int *) NULL,
575
                                             (struct symtab **) NULL);
576
                          if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
577
                            error ("No function \"%s\" in specified context.",
578
                                   copy_name ($3));
579
                          $$ = SYMBOL_BLOCK_VALUE (tem); }
580
        ;
581
 
582
variable:       block COLONCOLON name
583
                        { struct symbol *sym;
584
                          sym = lookup_symbol (copy_name ($3), $1,
585
                                               VAR_NAMESPACE, (int *) NULL,
586
                                               (struct symtab **) NULL);
587
                          if (sym == 0)
588
                            error ("No symbol \"%s\" in specified context.",
589
                                   copy_name ($3));
590
 
591
                          write_exp_elt_opcode (OP_VAR_VALUE);
592
                          /* block_found is set by lookup_symbol.  */
593
                          write_exp_elt_block (block_found);
594
                          write_exp_elt_sym (sym);
595
                          write_exp_elt_opcode (OP_VAR_VALUE); }
596
        ;
597
 
598
qualified_name: typebase COLONCOLON name
599
                        {
600
                          struct type *type = $1;
601
                          if (TYPE_CODE (type) != TYPE_CODE_STRUCT
602
                              && TYPE_CODE (type) != TYPE_CODE_UNION)
603
                            error ("`%s' is not defined as an aggregate type.",
604
                                   TYPE_NAME (type));
605
 
606
                          write_exp_elt_opcode (OP_SCOPE);
607
                          write_exp_elt_type (type);
608
                          write_exp_string ($3);
609
                          write_exp_elt_opcode (OP_SCOPE);
610
                        }
611
        |       typebase COLONCOLON '~' name
612
                        {
613
                          struct type *type = $1;
614
                          struct stoken tmp_token;
615
                          if (TYPE_CODE (type) != TYPE_CODE_STRUCT
616
                              && TYPE_CODE (type) != TYPE_CODE_UNION)
617
                            error ("`%s' is not defined as an aggregate type.",
618
                                   TYPE_NAME (type));
619
 
620
                          tmp_token.ptr = (char*) alloca ($4.length + 2);
621
                          tmp_token.length = $4.length + 1;
622
                          tmp_token.ptr[0] = '~';
623
                          memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
624
                          tmp_token.ptr[tmp_token.length] = 0;
625
 
626
                          /* Check for valid destructor name.  */
627
                          destructor_name_p (tmp_token.ptr, type);
628
                          write_exp_elt_opcode (OP_SCOPE);
629
                          write_exp_elt_type (type);
630
                          write_exp_string (tmp_token);
631
                          write_exp_elt_opcode (OP_SCOPE);
632
                        }
633
        ;
634
 
635
variable:       qualified_name
636
        |       COLONCOLON name
637
                        {
638
                          char *name = copy_name ($2);
639
                          struct symbol *sym;
640
                          struct minimal_symbol *msymbol;
641
 
642
                          sym =
643
                            lookup_symbol (name, (const struct block *) NULL,
644
                                           VAR_NAMESPACE, (int *) NULL,
645
                                           (struct symtab **) NULL);
646
                          if (sym)
647
                            {
648
                              write_exp_elt_opcode (OP_VAR_VALUE);
649
                              write_exp_elt_block (NULL);
650
                              write_exp_elt_sym (sym);
651
                              write_exp_elt_opcode (OP_VAR_VALUE);
652
                              break;
653
                            }
654
 
655
                          msymbol = lookup_minimal_symbol (name, NULL, NULL);
656
                          if (msymbol != NULL)
657
                            {
658
                              write_exp_msymbol (msymbol,
659
                                                 lookup_function_type (builtin_type_int),
660
                                                 builtin_type_int);
661
                            }
662
                          else
663
                            if (!have_full_symbols () && !have_partial_symbols ())
664
                              error ("No symbol table is loaded.  Use the \"file\" command.");
665
                            else
666
                              error ("No symbol \"%s\" in current context.", name);
667
                        }
668
        ;
669
 
670
variable:       name_not_typename
671
                        { struct symbol *sym = $1.sym;
672
 
673
                          if (sym)
674
                            {
675
                              if (symbol_read_needs_frame (sym))
676
                                {
677
                                  if (innermost_block == 0 ||
678
                                      contained_in (block_found,
679
                                                    innermost_block))
680
                                    innermost_block = block_found;
681
                                }
682
 
683
                              write_exp_elt_opcode (OP_VAR_VALUE);
684
                              /* We want to use the selected frame, not
685
                                 another more inner frame which happens to
686
                                 be in the same block.  */
687
                              write_exp_elt_block (NULL);
688
                              write_exp_elt_sym (sym);
689
                              write_exp_elt_opcode (OP_VAR_VALUE);
690
                            }
691
                          else if ($1.is_a_field_of_this)
692
                            {
693
                              /* C++: it hangs off of `this'.  Must
694
                                 not inadvertently convert from a method call
695
                                 to data ref.  */
696
                              if (innermost_block == 0 ||
697
                                  contained_in (block_found, innermost_block))
698
                                innermost_block = block_found;
699
                              write_exp_elt_opcode (OP_THIS);
700
                              write_exp_elt_opcode (OP_THIS);
701
                              write_exp_elt_opcode (STRUCTOP_PTR);
702
                              write_exp_string ($1.stoken);
703
                              write_exp_elt_opcode (STRUCTOP_PTR);
704
                            }
705
                          else
706
                            {
707
                              struct minimal_symbol *msymbol;
708
                              register char *arg = copy_name ($1.stoken);
709
 
710
                              msymbol =
711
                                lookup_minimal_symbol (arg, NULL, NULL);
712
                              if (msymbol != NULL)
713
                                {
714
                                  write_exp_msymbol (msymbol,
715
                                                     lookup_function_type (builtin_type_int),
716
                                                     builtin_type_int);
717
                                }
718
                              else if (!have_full_symbols () && !have_partial_symbols ())
719
                                error ("No symbol table is loaded.  Use the \"file\" command.");
720
                              else
721
                                error ("No symbol \"%s\" in current context.",
722
                                       copy_name ($1.stoken));
723
                            }
724
                        }
725
        ;
726
 
727
space_identifier : '@' NAME
728
                { push_type_address_space (copy_name ($2.stoken));
729
                  push_type (tp_space_identifier);
730
                }
731
        ;
732
 
733
const_or_volatile: const_or_volatile_noopt
734
        |
735
        ;
736
 
737
cv_with_space_id : const_or_volatile space_identifier const_or_volatile
738
        ;
739
 
740
const_or_volatile_or_space_identifier_noopt: cv_with_space_id
741
        | const_or_volatile_noopt
742
        ;
743
 
744
const_or_volatile_or_space_identifier:
745
                const_or_volatile_or_space_identifier_noopt
746
        |
747
        ;
748
 
749
abs_decl:       '*'
750
                        { push_type (tp_pointer); $$ = 0; }
751
        |       '*' abs_decl
752
                        { push_type (tp_pointer); $$ = $2; }
753
        |       '&'
754
                        { push_type (tp_reference); $$ = 0; }
755
        |       '&' abs_decl
756
                        { push_type (tp_reference); $$ = $2; }
757
        |       direct_abs_decl
758
        ;
759
 
760
direct_abs_decl: '(' abs_decl ')'
761
                        { $$ = $2; }
762
        |       direct_abs_decl array_mod
763
                        {
764
                          push_type_int ($2);
765
                          push_type (tp_array);
766
                        }
767
        |       array_mod
768
                        {
769
                          push_type_int ($1);
770
                          push_type (tp_array);
771
                          $$ = 0;
772
                        }
773
 
774
        |       direct_abs_decl func_mod
775
                        { push_type (tp_function); }
776
        |       func_mod
777
                        { push_type (tp_function); }
778
        ;
779
 
780
array_mod:      '[' ']'
781
                        { $$ = -1; }
782
        |       '[' INT ']'
783
                        { $$ = $2.val; }
784
        ;
785
 
786
func_mod:       '(' ')'
787
                        { $$ = 0; }
788
        |       '(' nonempty_typelist ')'
789
                        { free ((PTR)$2); $$ = 0; }
790
        ;
791
 
792
/* We used to try to recognize more pointer to member types here, but
793
   that didn't work (shift/reduce conflicts meant that these rules never
794
   got executed).  The problem is that
795
     int (foo::bar::baz::bizzle)
796
   is a function type but
797
     int (foo::bar::baz::bizzle::*)
798
   is a pointer to member type.  Stroustrup loses again!  */
799
 
800
type    :       ptype
801
        |       typebase COLONCOLON '*'
802
                        { $$ = lookup_member_type (builtin_type_int, $1); }
803
        ;
804
 
805
typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
806
        :       TYPENAME
807
                        { $$ = $1.type; }
808
        |       INT_KEYWORD
809
                        { $$ = builtin_type_int; }
810
        |       LONG
811
                        { $$ = builtin_type_long; }
812
        |       SHORT
813
                        { $$ = builtin_type_short; }
814
        |       LONG INT_KEYWORD
815
                        { $$ = builtin_type_long; }
816
        |       LONG SIGNED_KEYWORD INT_KEYWORD
817
                        { $$ = builtin_type_long; }
818
        |       LONG SIGNED_KEYWORD
819
                        { $$ = builtin_type_long; }
820
        |       SIGNED_KEYWORD LONG INT_KEYWORD
821
                        { $$ = builtin_type_long; }
822
        |       UNSIGNED LONG INT_KEYWORD
823
                        { $$ = builtin_type_unsigned_long; }
824
        |       LONG UNSIGNED INT_KEYWORD
825
                        { $$ = builtin_type_unsigned_long; }
826
        |       LONG UNSIGNED
827
                        { $$ = builtin_type_unsigned_long; }
828
        |       LONG LONG
829
                        { $$ = builtin_type_long_long; }
830
        |       LONG LONG INT_KEYWORD
831
                        { $$ = builtin_type_long_long; }
832
        |       LONG LONG SIGNED_KEYWORD INT_KEYWORD
833
                        { $$ = builtin_type_long_long; }
834
        |       LONG LONG SIGNED_KEYWORD
835
                        { $$ = builtin_type_long_long; }
836
        |       SIGNED_KEYWORD LONG LONG
837
                        { $$ = builtin_type_long_long; }
838
        |       UNSIGNED LONG LONG
839
                        { $$ = builtin_type_unsigned_long_long; }
840
        |       UNSIGNED LONG LONG INT_KEYWORD
841
                        { $$ = builtin_type_unsigned_long_long; }
842
        |       LONG LONG UNSIGNED
843
                        { $$ = builtin_type_unsigned_long_long; }
844
        |       LONG LONG UNSIGNED INT_KEYWORD
845
                        { $$ = builtin_type_unsigned_long_long; }
846
        |       SIGNED_KEYWORD LONG LONG
847
                        { $$ = lookup_signed_typename ("long long"); }
848
        |       SIGNED_KEYWORD LONG LONG INT_KEYWORD
849
                        { $$ = lookup_signed_typename ("long long"); }
850
        |       SHORT INT_KEYWORD
851
                        { $$ = builtin_type_short; }
852
        |       SHORT SIGNED_KEYWORD INT_KEYWORD
853
                        { $$ = builtin_type_short; }
854
        |       SHORT SIGNED_KEYWORD
855
                        { $$ = builtin_type_short; }
856
        |       UNSIGNED SHORT INT_KEYWORD
857
                        { $$ = builtin_type_unsigned_short; }
858
        |       SHORT UNSIGNED
859
                        { $$ = builtin_type_unsigned_short; }
860
        |       SHORT UNSIGNED INT_KEYWORD
861
                        { $$ = builtin_type_unsigned_short; }
862
        |       DOUBLE_KEYWORD
863
                        { $$ = builtin_type_double; }
864
        |       LONG DOUBLE_KEYWORD
865
                        { $$ = builtin_type_long_double; }
866
        |       STRUCT name
867
                        { $$ = lookup_struct (copy_name ($2),
868
                                              expression_context_block); }
869
        |       CLASS name
870
                        { $$ = lookup_struct (copy_name ($2),
871
                                              expression_context_block); }
872
        |       UNION name
873
                        { $$ = lookup_union (copy_name ($2),
874
                                             expression_context_block); }
875
        |       ENUM name
876
                        { $$ = lookup_enum (copy_name ($2),
877
                                            expression_context_block); }
878
        |       UNSIGNED typename
879
                        { $$ = lookup_unsigned_typename (TYPE_NAME($2.type)); }
880
        |       UNSIGNED
881
                        { $$ = builtin_type_unsigned_int; }
882
        |       SIGNED_KEYWORD typename
883
                        { $$ = lookup_signed_typename (TYPE_NAME($2.type)); }
884
        |       SIGNED_KEYWORD
885
                        { $$ = builtin_type_int; }
886
                /* It appears that this rule for templates is never
887
                   reduced; template recognition happens by lookahead
888
                   in the token processing code in yylex. */
889
        |       TEMPLATE name '<' type '>'
890
                        { $$ = lookup_template_type(copy_name($2), $4,
891
                                                    expression_context_block);
892
                        }
893
        | const_or_volatile_or_space_identifier_noopt typebase
894
                        { $$ = follow_types ($2); }
895
        | typebase const_or_volatile_or_space_identifier_noopt
896
                        { $$ = follow_types ($1); }
897
        ;
898
 
899
typename:       TYPENAME
900
        |       INT_KEYWORD
901
                {
902
                  $$.stoken.ptr = "int";
903
                  $$.stoken.length = 3;
904
                  $$.type = builtin_type_int;
905
                }
906
        |       LONG
907
                {
908
                  $$.stoken.ptr = "long";
909
                  $$.stoken.length = 4;
910
                  $$.type = builtin_type_long;
911
                }
912
        |       SHORT
913
                {
914
                  $$.stoken.ptr = "short";
915
                  $$.stoken.length = 5;
916
                  $$.type = builtin_type_short;
917
                }
918
        ;
919
 
920
nonempty_typelist
921
        :       type
922
                { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
923
                  $$[0] = 1;    /* Number of types in vector */
924
                  $$[1] = $1;
925
                }
926
        |       nonempty_typelist ',' type
927
                { int len = sizeof (struct type *) * (++($1[0]) + 1);
928
                  $$ = (struct type **) realloc ((char *) $1, len);
929
                  $$[$$[0]] = $3;
930
                }
931
        ;
932
 
933
ptype   :       typebase
934
        |       ptype const_or_volatile_or_space_identifier abs_decl const_or_volatile_or_space_identifier
935
                { $$ = follow_types ($1); }
936
        ;
937
 
938
const_and_volatile:     CONST_KEYWORD VOLATILE_KEYWORD
939
        |               VOLATILE_KEYWORD CONST_KEYWORD
940
        ;
941
 
942
const_or_volatile_noopt:        const_and_volatile
943
                        { push_type (tp_const);
944
                          push_type (tp_volatile);
945
                        }
946
        |               CONST_KEYWORD
947
                        { push_type (tp_const); }
948
        |               VOLATILE_KEYWORD
949
                        { push_type (tp_volatile); }
950
        ;
951
 
952
name    :       NAME { $$ = $1.stoken; }
953
        |       BLOCKNAME { $$ = $1.stoken; }
954
        |       TYPENAME { $$ = $1.stoken; }
955
        |       NAME_OR_INT  { $$ = $1.stoken; }
956
        ;
957
 
958
name_not_typename :     NAME
959
        |       BLOCKNAME
960
/* These would be useful if name_not_typename was useful, but it is just
961
   a fake for "variable", so these cause reduce/reduce conflicts because
962
   the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
963
   =exp) or just an exp.  If name_not_typename was ever used in an lvalue
964
   context where only a name could occur, this might be useful.
965
        |       NAME_OR_INT
966
 */
967
        ;
968
 
969
%%
970
 
971
/* Take care of parsing a number (anything that starts with a digit).
972
   Set yylval and return the token type; update lexptr.
973
   LEN is the number of characters in it.  */
974
 
975
/*** Needs some error checking for the float case ***/
976
 
977
static int
978
parse_number (p, len, parsed_float, putithere)
979
     register char *p;
980
     register int len;
981
     int parsed_float;
982
     YYSTYPE *putithere;
983
{
984
  /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
985
     here, and we do kind of silly things like cast to unsigned.  */
986
  register LONGEST n = 0;
987
  register LONGEST prevn = 0;
988
  ULONGEST un;
989
 
990
  register int i = 0;
991
  register int c;
992
  register int base = input_radix;
993
  int unsigned_p = 0;
994
 
995
  /* Number of "L" suffixes encountered.  */
996
  int long_p = 0;
997
 
998
  /* We have found a "L" or "U" suffix.  */
999
  int found_suffix = 0;
1000
 
1001
  ULONGEST high_bit;
1002
  struct type *signed_type;
1003
  struct type *unsigned_type;
1004
 
1005
  if (parsed_float)
1006
    {
1007
      /* It's a float since it contains a point or an exponent.  */
1008
      char c;
1009
      int num = 0;      /* number of tokens scanned by scanf */
1010
      char saved_char = p[len];
1011
 
1012
      p[len] = 0;       /* null-terminate the token */
1013
      if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
1014
        num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval,&c);
1015
      else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
1016
        num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval,&c);
1017
      else
1018
        {
1019
#ifdef SCANF_HAS_LONG_DOUBLE
1020
          num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval,&c);
1021
#else
1022
          /* Scan it into a double, then assign it to the long double.
1023
             This at least wins with values representable in the range
1024
             of doubles. */
1025
          double temp;
1026
          num = sscanf (p, "%lg%c", &temp,&c);
1027
          putithere->typed_val_float.dval = temp;
1028
#endif
1029
        }
1030
      p[len] = saved_char;      /* restore the input stream */
1031
      if (num != 1)             /* check scanf found ONLY a float ... */
1032
        return ERROR;
1033
      /* See if it has `f' or `l' suffix (float or long double).  */
1034
 
1035
      c = tolower (p[len - 1]);
1036
 
1037
      if (c == 'f')
1038
        putithere->typed_val_float.type = builtin_type_float;
1039
      else if (c == 'l')
1040
        putithere->typed_val_float.type = builtin_type_long_double;
1041
      else if (isdigit (c) || c == '.')
1042
        putithere->typed_val_float.type = builtin_type_double;
1043
      else
1044
        return ERROR;
1045
 
1046
      return FLOAT;
1047
    }
1048
 
1049
  /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
1050
  if (p[0] == '0')
1051
    switch (p[1])
1052
      {
1053
      case 'x':
1054
      case 'X':
1055
        if (len >= 3)
1056
          {
1057
            p += 2;
1058
            base = 16;
1059
            len -= 2;
1060
          }
1061
        break;
1062
 
1063
      case 't':
1064
      case 'T':
1065
      case 'd':
1066
      case 'D':
1067
        if (len >= 3)
1068
          {
1069
            p += 2;
1070
            base = 10;
1071
            len -= 2;
1072
          }
1073
        break;
1074
 
1075
      default:
1076
        base = 8;
1077
        break;
1078
      }
1079
 
1080
  while (len-- > 0)
1081
    {
1082
      c = *p++;
1083
      if (c >= 'A' && c <= 'Z')
1084
        c += 'a' - 'A';
1085
      if (c != 'l' && c != 'u')
1086
        n *= base;
1087
      if (c >= '0' && c <= '9')
1088
        {
1089
          if (found_suffix)
1090
            return ERROR;
1091
          n += i = c - '0';
1092
        }
1093
      else
1094
        {
1095
          if (base > 10 && c >= 'a' && c <= 'f')
1096
            {
1097
              if (found_suffix)
1098
                return ERROR;
1099
              n += i = c - 'a' + 10;
1100
            }
1101
          else if (c == 'l')
1102
            {
1103
              ++long_p;
1104
              found_suffix = 1;
1105
            }
1106
          else if (c == 'u')
1107
            {
1108
              unsigned_p = 1;
1109
              found_suffix = 1;
1110
            }
1111
          else
1112
            return ERROR;       /* Char not a digit */
1113
        }
1114
      if (i >= base)
1115
        return ERROR;           /* Invalid digit in this base */
1116
 
1117
      /* Portably test for overflow (only works for nonzero values, so make
1118
         a second check for zero).  FIXME: Can't we just make n and prevn
1119
         unsigned and avoid this?  */
1120
      if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
1121
        unsigned_p = 1;         /* Try something unsigned */
1122
 
1123
      /* Portably test for unsigned overflow.
1124
         FIXME: This check is wrong; for example it doesn't find overflow
1125
         on 0x123456789 when LONGEST is 32 bits.  */
1126
      if (c != 'l' && c != 'u' && n != 0)
1127
        {
1128
          if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
1129
            error ("Numeric constant too large.");
1130
        }
1131
      prevn = n;
1132
    }
1133
 
1134
  /* An integer constant is an int, a long, or a long long.  An L
1135
     suffix forces it to be long; an LL suffix forces it to be long
1136
     long.  If not forced to a larger size, it gets the first type of
1137
     the above that it fits in.  To figure out whether it fits, we
1138
     shift it right and see whether anything remains.  Note that we
1139
     can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
1140
     operation, because many compilers will warn about such a shift
1141
     (which always produces a zero result).  Sometimes TARGET_INT_BIT
1142
     or TARGET_LONG_BIT will be that big, sometimes not.  To deal with
1143
     the case where it is we just always shift the value more than
1144
     once, with fewer bits each time.  */
1145
 
1146
  un = (ULONGEST)n >> 2;
1147
  if (long_p == 0
1148
      && (un >> (TARGET_INT_BIT - 2)) == 0)
1149
    {
1150
      high_bit = ((ULONGEST)1) << (TARGET_INT_BIT-1);
1151
 
1152
      /* A large decimal (not hex or octal) constant (between INT_MAX
1153
         and UINT_MAX) is a long or unsigned long, according to ANSI,
1154
         never an unsigned int, but this code treats it as unsigned
1155
         int.  This probably should be fixed.  GCC gives a warning on
1156
         such constants.  */
1157
 
1158
      unsigned_type = builtin_type_unsigned_int;
1159
      signed_type = builtin_type_int;
1160
    }
1161
  else if (long_p <= 1
1162
           && (un >> (TARGET_LONG_BIT - 2)) == 0)
1163
    {
1164
      high_bit = ((ULONGEST)1) << (TARGET_LONG_BIT-1);
1165
      unsigned_type = builtin_type_unsigned_long;
1166
      signed_type = builtin_type_long;
1167
    }
1168
  else
1169
    {
1170
      int shift;
1171
      if (sizeof (ULONGEST) * HOST_CHAR_BIT < TARGET_LONG_LONG_BIT)
1172
        /* A long long does not fit in a LONGEST.  */
1173
        shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
1174
      else
1175
        shift = (TARGET_LONG_LONG_BIT - 1);
1176
      high_bit = (ULONGEST) 1 << shift;
1177
      unsigned_type = builtin_type_unsigned_long_long;
1178
      signed_type = builtin_type_long_long;
1179
    }
1180
 
1181
   putithere->typed_val_int.val = n;
1182
 
1183
   /* If the high bit of the worked out type is set then this number
1184
      has to be unsigned. */
1185
 
1186
   if (unsigned_p || (n & high_bit))
1187
     {
1188
       putithere->typed_val_int.type = unsigned_type;
1189
     }
1190
   else
1191
     {
1192
       putithere->typed_val_int.type = signed_type;
1193
     }
1194
 
1195
   return INT;
1196
}
1197
 
1198
struct token
1199
{
1200
  char *operator;
1201
  int token;
1202
  enum exp_opcode opcode;
1203
};
1204
 
1205
static const struct token tokentab3[] =
1206
  {
1207
    {">>=", ASSIGN_MODIFY, BINOP_RSH},
1208
    {"<<=", ASSIGN_MODIFY, BINOP_LSH}
1209
  };
1210
 
1211
static const struct token tokentab2[] =
1212
  {
1213
    {"+=", ASSIGN_MODIFY, BINOP_ADD},
1214
    {"-=", ASSIGN_MODIFY, BINOP_SUB},
1215
    {"*=", ASSIGN_MODIFY, BINOP_MUL},
1216
    {"/=", ASSIGN_MODIFY, BINOP_DIV},
1217
    {"%=", ASSIGN_MODIFY, BINOP_REM},
1218
    {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR},
1219
    {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND},
1220
    {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR},
1221
    {"++", INCREMENT, BINOP_END},
1222
    {"--", DECREMENT, BINOP_END},
1223
    {"->", ARROW, BINOP_END},
1224
    {"&&", ANDAND, BINOP_END},
1225
    {"||", OROR, BINOP_END},
1226
    {"::", COLONCOLON, BINOP_END},
1227
    {"<<", LSH, BINOP_END},
1228
    {">>", RSH, BINOP_END},
1229
    {"==", EQUAL, BINOP_END},
1230
    {"!=", NOTEQUAL, BINOP_END},
1231
    {"<=", LEQ, BINOP_END},
1232
    {">=", GEQ, BINOP_END}
1233
  };
1234
 
1235
/* Read one token, getting characters through lexptr.  */
1236
 
1237
static int
1238
yylex ()
1239
{
1240
  int c;
1241
  int namelen;
1242
  unsigned int i;
1243
  char *tokstart;
1244
  char *tokptr;
1245
  int tempbufindex;
1246
  static char *tempbuf;
1247
  static int tempbufsize;
1248
  struct symbol * sym_class = NULL;
1249
  char * token_string = NULL;
1250
  int class_prefix = 0;
1251
  int unquoted_expr;
1252
 
1253
 retry:
1254
 
1255
  /* Check if this is a macro invocation that we need to expand.  */
1256
  if (! scanning_macro_expansion ())
1257
    {
1258
      char *expanded = macro_expand_next (&lexptr,
1259
                                          expression_macro_lookup_func,
1260
                                          expression_macro_lookup_baton);
1261
 
1262
      if (expanded)
1263
        scan_macro_expansion (expanded);
1264
    }
1265
 
1266
  prev_lexptr = lexptr;
1267
  unquoted_expr = 1;
1268
 
1269
  tokstart = lexptr;
1270
  /* See if it is a special token of length 3.  */
1271
  for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
1272
    if (STREQN (tokstart, tokentab3[i].operator, 3))
1273
      {
1274
        lexptr += 3;
1275
        yylval.opcode = tokentab3[i].opcode;
1276
        return tokentab3[i].token;
1277
      }
1278
 
1279
  /* See if it is a special token of length 2.  */
1280
  for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
1281
    if (STREQN (tokstart, tokentab2[i].operator, 2))
1282
      {
1283
        lexptr += 2;
1284
        yylval.opcode = tokentab2[i].opcode;
1285
        return tokentab2[i].token;
1286
      }
1287
 
1288
  switch (c = *tokstart)
1289
    {
1290
    case 0:
1291
      /* If we were just scanning the result of a macro expansion,
1292
         then we need to resume scanning the original text.
1293
         Otherwise, we were already scanning the original text, and
1294
         we're really done.  */
1295
      if (scanning_macro_expansion ())
1296
        {
1297
          finished_macro_expansion ();
1298
          goto retry;
1299
        }
1300
      else
1301
        return 0;
1302
 
1303
    case ' ':
1304
    case '\t':
1305
    case '\n':
1306
      lexptr++;
1307
      goto retry;
1308
 
1309
    case '\'':
1310
      /* We either have a character constant ('0' or '\177' for example)
1311
         or we have a quoted symbol reference ('foo(int,int)' in C++
1312
         for example). */
1313
      lexptr++;
1314
      c = *lexptr++;
1315
      if (c == '\\')
1316
        c = parse_escape (&lexptr);
1317
      else if (c == '\'')
1318
        error ("Empty character constant.");
1319
 
1320
      yylval.typed_val_int.val = c;
1321
      yylval.typed_val_int.type = builtin_type_char;
1322
 
1323
      c = *lexptr++;
1324
      if (c != '\'')
1325
        {
1326
          namelen = skip_quoted (tokstart) - tokstart;
1327
          if (namelen > 2)
1328
            {
1329
              lexptr = tokstart + namelen;
1330
              unquoted_expr = 0;
1331
              if (lexptr[-1] != '\'')
1332
                error ("Unmatched single quote.");
1333
              namelen -= 2;
1334
              tokstart++;
1335
              goto tryname;
1336
            }
1337
          error ("Invalid character constant.");
1338
        }
1339
      return INT;
1340
 
1341
    case '(':
1342
      paren_depth++;
1343
      lexptr++;
1344
      return c;
1345
 
1346
    case ')':
1347
      if (paren_depth == 0)
1348
        return 0;
1349
      paren_depth--;
1350
      lexptr++;
1351
      return c;
1352
 
1353
    case ',':
1354
      if (comma_terminates
1355
          && paren_depth == 0
1356
          && ! scanning_macro_expansion ())
1357
        return 0;
1358
      lexptr++;
1359
      return c;
1360
 
1361
    case '.':
1362
      /* Might be a floating point number.  */
1363
      if (lexptr[1] < '0' || lexptr[1] > '9')
1364
        goto symbol;            /* Nope, must be a symbol. */
1365
      /* FALL THRU into number case.  */
1366
 
1367
    case '0':
1368
    case '1':
1369
    case '2':
1370
    case '3':
1371
    case '4':
1372
    case '5':
1373
    case '6':
1374
    case '7':
1375
    case '8':
1376
    case '9':
1377
      {
1378
        /* It's a number.  */
1379
        int got_dot = 0, got_e = 0, toktype;
1380
        register char *p = tokstart;
1381
        int hex = input_radix > 10;
1382
 
1383
        if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
1384
          {
1385
            p += 2;
1386
            hex = 1;
1387
          }
1388
        else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
1389
          {
1390
            p += 2;
1391
            hex = 0;
1392
          }
1393
 
1394
        for (;; ++p)
1395
          {
1396
            /* This test includes !hex because 'e' is a valid hex digit
1397
               and thus does not indicate a floating point number when
1398
               the radix is hex.  */
1399
            if (!hex && !got_e && (*p == 'e' || *p == 'E'))
1400
              got_dot = got_e = 1;
1401
            /* This test does not include !hex, because a '.' always indicates
1402
               a decimal floating point number regardless of the radix.  */
1403
            else if (!got_dot && *p == '.')
1404
              got_dot = 1;
1405
            else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
1406
                     && (*p == '-' || *p == '+'))
1407
              /* This is the sign of the exponent, not the end of the
1408
                 number.  */
1409
              continue;
1410
            /* We will take any letters or digits.  parse_number will
1411
               complain if past the radix, or if L or U are not final.  */
1412
            else if ((*p < '0' || *p > '9')
1413
                     && ((*p < 'a' || *p > 'z')
1414
                                  && (*p < 'A' || *p > 'Z')))
1415
              break;
1416
          }
1417
        toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
1418
        if (toktype == ERROR)
1419
          {
1420
            char *err_copy = (char *) alloca (p - tokstart + 1);
1421
 
1422
            memcpy (err_copy, tokstart, p - tokstart);
1423
            err_copy[p - tokstart] = 0;
1424
            error ("Invalid number \"%s\".", err_copy);
1425
          }
1426
        lexptr = p;
1427
        return toktype;
1428
      }
1429
 
1430
    case '+':
1431
    case '-':
1432
    case '*':
1433
    case '/':
1434
    case '%':
1435
    case '|':
1436
    case '&':
1437
    case '^':
1438
    case '~':
1439
    case '!':
1440
    case '@':
1441
    case '<':
1442
    case '>':
1443
    case '[':
1444
    case ']':
1445
    case '?':
1446
    case ':':
1447
    case '=':
1448
    case '{':
1449
    case '}':
1450
    symbol:
1451
      lexptr++;
1452
      return c;
1453
 
1454
    case '"':
1455
 
1456
      /* Build the gdb internal form of the input string in tempbuf,
1457
         translating any standard C escape forms seen.  Note that the
1458
         buffer is null byte terminated *only* for the convenience of
1459
         debugging gdb itself and printing the buffer contents when
1460
         the buffer contains no embedded nulls.  Gdb does not depend
1461
         upon the buffer being null byte terminated, it uses the length
1462
         string instead.  This allows gdb to handle C strings (as well
1463
         as strings in other languages) with embedded null bytes */
1464
 
1465
      tokptr = ++tokstart;
1466
      tempbufindex = 0;
1467
 
1468
      do {
1469
        /* Grow the static temp buffer if necessary, including allocating
1470
           the first one on demand. */
1471
        if (tempbufindex + 1 >= tempbufsize)
1472
          {
1473
            tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
1474
          }
1475
        switch (*tokptr)
1476
          {
1477
          case '\0':
1478
          case '"':
1479
            /* Do nothing, loop will terminate. */
1480
            break;
1481
          case '\\':
1482
            tokptr++;
1483
            c = parse_escape (&tokptr);
1484
            if (c == -1)
1485
              {
1486
                continue;
1487
              }
1488
            tempbuf[tempbufindex++] = c;
1489
            break;
1490
          default:
1491
            tempbuf[tempbufindex++] = *tokptr++;
1492
            break;
1493
          }
1494
      } while ((*tokptr != '"') && (*tokptr != '\0'));
1495
      if (*tokptr++ != '"')
1496
        {
1497
          error ("Unterminated string in expression.");
1498
        }
1499
      tempbuf[tempbufindex] = '\0';     /* See note above */
1500
      yylval.sval.ptr = tempbuf;
1501
      yylval.sval.length = tempbufindex;
1502
      lexptr = tokptr;
1503
      return (STRING);
1504
    }
1505
 
1506
  if (!(c == '_' || c == '$'
1507
        || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1508
    /* We must have come across a bad character (e.g. ';').  */
1509
    error ("Invalid character '%c' in expression.", c);
1510
 
1511
  /* It's a name.  See how long it is.  */
1512
  namelen = 0;
1513
  for (c = tokstart[namelen];
1514
       (c == '_' || c == '$' || (c >= '0' && c <= '9')
1515
        || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
1516
    {
1517
      /* Template parameter lists are part of the name.
1518
         FIXME: This mishandles `print $a<4&&$a>3'.  */
1519
 
1520
      if (c == '<')
1521
        {
1522
               /* Scan ahead to get rest of the template specification.  Note
1523
                  that we look ahead only when the '<' adjoins non-whitespace
1524
                  characters; for comparison expressions, e.g. "a < b > c",
1525
                  there must be spaces before the '<', etc. */
1526
 
1527
               char * p = find_template_name_end (tokstart + namelen);
1528
               if (p)
1529
                 namelen = p - tokstart;
1530
               break;
1531
        }
1532
      c = tokstart[++namelen];
1533
    }
1534
 
1535
  /* The token "if" terminates the expression and is NOT removed from
1536
     the input stream.  It doesn't count if it appears in the
1537
     expansion of a macro.  */
1538
  if (namelen == 2
1539
      && tokstart[0] == 'i'
1540
      && tokstart[1] == 'f'
1541
      && ! scanning_macro_expansion ())
1542
    {
1543
      return 0;
1544
    }
1545
 
1546
  lexptr += namelen;
1547
 
1548
  tryname:
1549
 
1550
  /* Catch specific keywords.  Should be done with a data structure.  */
1551
  switch (namelen)
1552
    {
1553
    case 8:
1554
      if (STREQN (tokstart, "unsigned", 8))
1555
        return UNSIGNED;
1556
      if (current_language->la_language == language_cplus
1557
          && STREQN (tokstart, "template", 8))
1558
        return TEMPLATE;
1559
      if (STREQN (tokstart, "volatile", 8))
1560
        return VOLATILE_KEYWORD;
1561
      break;
1562
    case 6:
1563
      if (STREQN (tokstart, "struct", 6))
1564
        return STRUCT;
1565
      if (STREQN (tokstart, "signed", 6))
1566
        return SIGNED_KEYWORD;
1567
      if (STREQN (tokstart, "sizeof", 6))
1568
        return SIZEOF;
1569
      if (STREQN (tokstart, "double", 6))
1570
        return DOUBLE_KEYWORD;
1571
      break;
1572
    case 5:
1573
      if (current_language->la_language == language_cplus)
1574
        {
1575
          if (STREQN (tokstart, "false", 5))
1576
            return FALSEKEYWORD;
1577
          if (STREQN (tokstart, "class", 5))
1578
            return CLASS;
1579
        }
1580
      if (STREQN (tokstart, "union", 5))
1581
        return UNION;
1582
      if (STREQN (tokstart, "short", 5))
1583
        return SHORT;
1584
      if (STREQN (tokstart, "const", 5))
1585
        return CONST_KEYWORD;
1586
      break;
1587
    case 4:
1588
      if (STREQN (tokstart, "enum", 4))
1589
        return ENUM;
1590
      if (STREQN (tokstart, "long", 4))
1591
        return LONG;
1592
      if (current_language->la_language == language_cplus)
1593
          {
1594
            if (STREQN (tokstart, "true", 4))
1595
              return TRUEKEYWORD;
1596
 
1597
            if (STREQN (tokstart, "this", 4))
1598
              {
1599
                static const char this_name[] =
1600
                { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
1601
 
1602
                if (lookup_symbol (this_name, expression_context_block,
1603
                                   VAR_NAMESPACE, (int *) NULL,
1604
                                   (struct symtab **) NULL))
1605
                  return THIS;
1606
              }
1607
          }
1608
      break;
1609
    case 3:
1610
      if (STREQN (tokstart, "int", 3))
1611
        return INT_KEYWORD;
1612
      break;
1613
    default:
1614
      break;
1615
    }
1616
 
1617
  yylval.sval.ptr = tokstart;
1618
  yylval.sval.length = namelen;
1619
 
1620
  if (*tokstart == '$')
1621
    {
1622
      write_dollar_variable (yylval.sval);
1623
      return VARIABLE;
1624
    }
1625
 
1626
  /* Look ahead and see if we can consume more of the input
1627
     string to get a reasonable class/namespace spec or a
1628
     fully-qualified name.  This is a kludge to get around the
1629
     HP aCC compiler's generation of symbol names with embedded
1630
     colons for namespace and nested classes. */
1631
  if (unquoted_expr)
1632
    {
1633
      /* Only do it if not inside single quotes */
1634
      sym_class = parse_nested_classes_for_hpacc (yylval.sval.ptr, yylval.sval.length,
1635
                                                  &token_string, &class_prefix, &lexptr);
1636
      if (sym_class)
1637
        {
1638
          /* Replace the current token with the bigger one we found */
1639
          yylval.sval.ptr = token_string;
1640
          yylval.sval.length = strlen (token_string);
1641
        }
1642
    }
1643
 
1644
  /* Use token-type BLOCKNAME for symbols that happen to be defined as
1645
     functions or symtabs.  If this is not so, then ...
1646
     Use token-type TYPENAME for symbols that happen to be defined
1647
     currently as names of types; NAME for other symbols.
1648
     The caller is not constrained to care about the distinction.  */
1649
  {
1650
    char *tmp = copy_name (yylval.sval);
1651
    struct symbol *sym;
1652
    int is_a_field_of_this = 0;
1653
    int hextype;
1654
 
1655
    sym = lookup_symbol (tmp, expression_context_block,
1656
                         VAR_NAMESPACE,
1657
                         current_language->la_language == language_cplus
1658
                         ? &is_a_field_of_this : (int *) NULL,
1659
                         (struct symtab **) NULL);
1660
    /* Call lookup_symtab, not lookup_partial_symtab, in case there are
1661
       no psymtabs (coff, xcoff, or some future change to blow away the
1662
       psymtabs once once symbols are read).  */
1663
    if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1664
      {
1665
        yylval.ssym.sym = sym;
1666
        yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1667
        return BLOCKNAME;
1668
      }
1669
    else if (!sym)
1670
      {                         /* See if it's a file name. */
1671
        struct symtab *symtab;
1672
 
1673
        symtab = lookup_symtab (tmp);
1674
 
1675
        if (symtab)
1676
          {
1677
            yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
1678
            return FILENAME;
1679
          }
1680
      }
1681
 
1682
    if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1683
        {
1684
#if 1
1685
          /* Despite the following flaw, we need to keep this code enabled.
1686
             Because we can get called from check_stub_method, if we don't
1687
             handle nested types then it screws many operations in any
1688
             program which uses nested types.  */
1689
          /* In "A::x", if x is a member function of A and there happens
1690
             to be a type (nested or not, since the stabs don't make that
1691
             distinction) named x, then this code incorrectly thinks we
1692
             are dealing with nested types rather than a member function.  */
1693
 
1694
          char *p;
1695
          char *namestart;
1696
          struct symbol *best_sym;
1697
 
1698
          /* Look ahead to detect nested types.  This probably should be
1699
             done in the grammar, but trying seemed to introduce a lot
1700
             of shift/reduce and reduce/reduce conflicts.  It's possible
1701
             that it could be done, though.  Or perhaps a non-grammar, but
1702
             less ad hoc, approach would work well.  */
1703
 
1704
          /* Since we do not currently have any way of distinguishing
1705
             a nested type from a non-nested one (the stabs don't tell
1706
             us whether a type is nested), we just ignore the
1707
             containing type.  */
1708
 
1709
          p = lexptr;
1710
          best_sym = sym;
1711
          while (1)
1712
            {
1713
              /* Skip whitespace.  */
1714
              while (*p == ' ' || *p == '\t' || *p == '\n')
1715
                ++p;
1716
              if (*p == ':' && p[1] == ':')
1717
                {
1718
                  /* Skip the `::'.  */
1719
                  p += 2;
1720
                  /* Skip whitespace.  */
1721
                  while (*p == ' ' || *p == '\t' || *p == '\n')
1722
                    ++p;
1723
                  namestart = p;
1724
                  while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
1725
                         || (*p >= 'a' && *p <= 'z')
1726
                         || (*p >= 'A' && *p <= 'Z'))
1727
                    ++p;
1728
                  if (p != namestart)
1729
                    {
1730
                      struct symbol *cur_sym;
1731
                      /* As big as the whole rest of the expression, which is
1732
                         at least big enough.  */
1733
                      char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
1734
                      char *tmp1;
1735
 
1736
                      tmp1 = ncopy;
1737
                      memcpy (tmp1, tmp, strlen (tmp));
1738
                      tmp1 += strlen (tmp);
1739
                      memcpy (tmp1, "::", 2);
1740
                      tmp1 += 2;
1741
                      memcpy (tmp1, namestart, p - namestart);
1742
                      tmp1[p - namestart] = '\0';
1743
                      cur_sym = lookup_symbol (ncopy, expression_context_block,
1744
                                               VAR_NAMESPACE, (int *) NULL,
1745
                                               (struct symtab **) NULL);
1746
                      if (cur_sym)
1747
                        {
1748
                          if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
1749
                            {
1750
                              best_sym = cur_sym;
1751
                              lexptr = p;
1752
                            }
1753
                          else
1754
                            break;
1755
                        }
1756
                      else
1757
                        break;
1758
                    }
1759
                  else
1760
                    break;
1761
                }
1762
              else
1763
                break;
1764
            }
1765
 
1766
          yylval.tsym.type = SYMBOL_TYPE (best_sym);
1767
#else /* not 0 */
1768
          yylval.tsym.type = SYMBOL_TYPE (sym);
1769
#endif /* not 0 */
1770
          return TYPENAME;
1771
        }
1772
    if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
1773
      return TYPENAME;
1774
 
1775
    /* Input names that aren't symbols but ARE valid hex numbers,
1776
       when the input radix permits them, can be names or numbers
1777
       depending on the parse.  Note we support radixes > 16 here.  */
1778
    if (!sym &&
1779
        ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1780
         (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1781
      {
1782
        YYSTYPE newlval;        /* Its value is ignored.  */
1783
        hextype = parse_number (tokstart, namelen, 0, &newlval);
1784
        if (hextype == INT)
1785
          {
1786
            yylval.ssym.sym = sym;
1787
            yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1788
            return NAME_OR_INT;
1789
          }
1790
      }
1791
 
1792
    /* Any other kind of symbol */
1793
    yylval.ssym.sym = sym;
1794
    yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1795
    return NAME;
1796
  }
1797
}
1798
 
1799
void
1800
yyerror (msg)
1801
     char *msg;
1802
{
1803
  if (prev_lexptr)
1804
    lexptr = prev_lexptr;
1805
 
1806
  error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
1807
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.