binutils-gdb/gdb/ada-exp.y
Eli Zaretskii 197e01b6dc * breakpoint.c:
* arm-tdep.c:
	* ia64-tdep.c:
	* i386-tdep.c:
	* hpread.c:
	* hppa-tdep.c:
	* hppa-hpux-tdep.c:
	* gnu-nat.c:
	* gdbtypes.c:
	* gdbarch.h:
	* gdbarch.c:
	* eval.c:
	* dwarf2read.c:
	* dbxread.c:
	* copying:
	* symfile.c:
	* stabsread.c:
	* sh64-tdep.c:
	* sh-tdep.c:
	* s390-tdep.c:
	* rs6000-tdep.c:
	* remote.c:
	* remote-mips.c:
	* mips-tdep.c:
	* mdebugread.c:
	* linux-nat.c:
	* infrun.c:
	* xcoffread.c:
	* win32-nat.c:
	* valops.c:
	* utils.c:
	* tracepoint.c:
	* target.c:
	* symtab.c:
	* c-exp.y:
	* ada-valprint.c:
	* ada-typeprint.c:
	* ada-lex.l:
	* ada-lang.h:
	* ada-lang.c:
	* ada-exp.y:
	* alphafbsd-tdep.c:
	* alphabsd-tdep.h:
	* alphabsd-tdep.c:
	* alphabsd-nat.c:
	* alpha-tdep.h:
	* alpha-tdep.c:
	* alpha-osf1-tdep.c:
	* alpha-nat.c:
	* alpha-mdebug-tdep.c:
	* alpha-linux-tdep.c:
	* alpha-linux-nat.c:
	* aix-thread.c:
	* abug-rom.c:
	* arch-utils.c:
	* annotate.h:
	* annotate.c:
	* amd64obsd-tdep.c:
	* amd64obsd-nat.c:
	* amd64nbsd-tdep.c:
	* amd64nbsd-nat.c:
	* amd64fbsd-tdep.c:
	* amd64fbsd-nat.c:
	* amd64bsd-nat.c:
	* amd64-tdep.h:
	* amd64-tdep.c:
	* amd64-sol2-tdep.c:
	* amd64-nat.h:
	* amd64-nat.c:
	* amd64-linux-tdep.c:
	* amd64-linux-nat.c:
	* alphanbsd-tdep.c:
	* block.h:
	* block.c:
	* bfd-target.h:
	* bfd-target.c:
	* bcache.h:
	* bcache.c:
	* ax.h:
	* ax-general.c:
	* ax-gdb.h:
	* ax-gdb.c:
	* avr-tdep.c:
	* auxv.h:
	* auxv.c:
	* armnbsd-tdep.c:
	* armnbsd-nat.c:
	* arm-tdep.h:
	* arm-linux-nat.c:
	* arch-utils.h:
	* charset.c:
	* call-cmds.h:
	* c-valprint.c:
	* c-typeprint.c:
	* c-lang.h:
	* c-lang.c:
	* buildsym.h:
	* buildsym.c:
	* bsd-uthread.h:
	* bsd-uthread.c:
	* bsd-kvm.h:
	* bsd-kvm.c:
	* breakpoint.h:
	* core-regset.c:
	* core-aout.c:
	* completer.h:
	* completer.c:
	* complaints.h:
	* complaints.c:
	* command.h:
	* coffread.c:
	* coff-solib.h:
	* coff-solib.c:
	* coff-pe-read.h:
	* coff-pe-read.c:
	* cli-out.h:
	* cli-out.c:
	* charset.h:
	* dink32-rom.c:
	* dictionary.h:
	* dictionary.c:
	* demangle.c:
	* defs.h:
	* dcache.h:
	* dcache.c:
	* d10v-tdep.c:
	* cpu32bug-rom.c:
	* cp-valprint.c:
	* cp-support.h:
	* cp-support.c:
	* cp-namespace.c:
	* cp-abi.h:
	* cp-abi.c:
	* corelow.c:
	* corefile.c:
	* environ.c:
	* elfread.c:
	* dwarfread.c:
	* dwarf2loc.c:
	* dwarf2expr.h:
	* dwarf2expr.c:
	* dwarf2-frame.h:
	* dwarf2-frame.c:
	* dve3900-rom.c:
	* dummy-frame.h:
	* dummy-frame.c:
	* dsrec.c:
	* doublest.h:
	* doublest.c:
	* disasm.h:
	* disasm.c:
	* fork-child.c:
	* findvar.c:
	* fbsd-nat.h:
	* fbsd-nat.c:
	* f-valprint.c:
	* f-typeprint.c:
	* f-lang.h:
	* f-lang.c:
	* expression.h:
	* expprint.c:
	* exec.h:
	* exec.c:
	* exceptions.h:
	* exceptions.c:
	* event-top.h:
	* event-top.c:
	* event-loop.h:
	* event-loop.c:
	* gdb.c:
	* gdb-stabs.h:
	* gdb-events.h:
	* gdb-events.c:
	* gcore.c:
	* frv-tdep.h:
	* frv-tdep.c:
	* frv-linux-tdep.c:
	* frame.h:
	* frame.c:
	* frame-unwind.h:
	* frame-unwind.c:
	* frame-base.h:
	* frame-base.c:
	* gdb_vfork.h:
	* gdb_thread_db.h:
	* gdb_string.h:
	* gdb_stat.h:
	* gdb_regex.h:
	* gdb_ptrace.h:
	* gdb_proc_service.h:
	* gdb_obstack.h:
	* gdb_locale.h:
	* gdb_dirent.h:
	* gdb_curses.h:
	* gdb_assert.h:
	* gdbarch.sh:
	* gdb.h:
	* hpux-thread.c:
	* hppabsd-nat.c:
	* hppa-tdep.h:
	* hpacc-abi.c:
	* h8300-tdep.c:
	* gregset.h:
	* go32-nat.c:
	* gnu-v3-abi.c:
	* gnu-v2-abi.h:
	* gnu-v2-abi.c:
	* gnu-nat.h:
	* glibc-tdep.c:
	* gdbtypes.h:
	* gdbcore.h:
	* gdbcmd.h:
	* i386nbsd-tdep.c:
	* i386nbsd-nat.c:
	* i386gnu-tdep.c:
	* i386gnu-nat.c:
	* i386fbsd-tdep.c:
	* i386fbsd-nat.c:
	* i386bsd-tdep.c:
	* i386bsd-nat.h:
	* i386bsd-nat.c:
	* i386-tdep.h:
	* i386-sol2-nat.c:
	* i386-nto-tdep.c:
	* i386-nat.c:
	* i386-linux-tdep.h:
	* i386-linux-tdep.c:
	* i386-linux-nat.c:
	* i386-cygwin-tdep.c:
	* inf-ttrace.c:
	* inf-ptrace.h:
	* inf-ptrace.c:
	* inf-loop.h:
	* inf-loop.c:
	* inf-child.h:
	* inf-child.c:
	* ia64-tdep.h:
	* ia64-linux-nat.c:
	* i387-tdep.h:
	* i387-tdep.c:
	* i386v4-nat.c:
	* i386v-nat.c:
	* i386obsd-tdep.c:
	* i386obsd-nat.c:
	* kod.c:
	* jv-valprint.c:
	* jv-typeprint.c:
	* jv-lang.h:
	* jv-lang.c:
	* irix5-nat.c:
	* iq2000-tdep.c:
	* interps.h:
	* interps.c:
	* inftarg.c:
	* inflow.h:
	* inflow.c:
	* inferior.h:
	* infcmd.c:
	* infcall.h:
	* infcall.c:
	* inf-ttrace.h:
	* m32r-tdep.h:
	* m32r-tdep.c:
	* m32r-rom.c:
	* m32r-linux-tdep.c:
	* m32r-linux-nat.c:
	* m2-valprint.c:
	* m2-typeprint.c:
	* m2-lang.h:
	* m2-lang.c:
	* lynx-nat.c:
	* linux-thread-db.c:
	* linux-nat.h:
	* linespec.c:
	* libunwind-frame.h:
	* libunwind-frame.c:
	* language.h:
	* language.c:
	* macroexp.c:
	* macrocmd.c:
	* m88kbsd-nat.c:
	* m88k-tdep.h:
	* m88k-tdep.c:
	* m68klinux-tdep.c:
	* m68klinux-nat.c:
	* m68kbsd-tdep.c:
	* m68kbsd-nat.c:
	* m68k-tdep.h:
	* m68k-tdep.c:
	* mips-linux-nat.c:
	* mips-irix-tdep.c:
	* minsyms.c:
	* memattr.h:
	* memattr.c:
	* mem-break.c:
	* mdebugread.h:
	* main.h:
	* main.c:
	* macrotab.h:
	* macrotab.c:
	* macroscope.h:
	* macroscope.c:
	* macroexp.h:
	* nbsd-tdep.c:
	* mt-tdep.c:
	* monitor.h:
	* monitor.c:
	* mn10300-tdep.h:
	* mn10300-tdep.c:
	* mn10300-linux-tdep.c:
	* mipsv4-nat.c:
	* mipsread.c:
	* mipsnbsd-tdep.h:
	* mipsnbsd-tdep.c:
	* mipsnbsd-nat.c:
	* mips64obsd-tdep.c:
	* mips64obsd-nat.c:
	* mips-tdep.h:
	* mips-mdebug-tdep.c:
	* mips-linux-tdep.c:
	* osabi.h:
	* osabi.c:
	* ocd.h:
	* ocd.c:
	* observer.c:
	* objfiles.h:
	* objfiles.c:
	* objc-lang.h:
	* objc-lang.c:
	* objc-exp.y:
	* nto-tdep.h:
	* nto-tdep.c:
	* nto-procfs.c:
	* nlmread.c:
	* nbsd-tdep.h:
	* ppcobsd-tdep.c:
	* ppcobsd-nat.c:
	* ppcnbsd-tdep.h:
	* ppcnbsd-tdep.c:
	* ppcnbsd-nat.c:
	* ppcbug-rom.c:
	* ppc-tdep.h:
	* ppc-sysv-tdep.c:
	* ppc-linux-tdep.c:
	* ppc-linux-nat.c:
	* ppc-bdm.c:
	* parser-defs.h:
	* parse.c:
	* p-valprint.c:
	* p-typeprint.c:
	* p-lang.h:
	* p-lang.c:
	* remote-fileio.h:
	* remote-fileio.c:
	* remote-est.c:
	* remote-e7000.c:
	* regset.h:
	* regset.c:
	* reggroups.h:
	* reggroups.c:
	* regcache.h:
	* regcache.c:
	* proc-why.c:
	* proc-service.c:
	* proc-events.c:
	* printcmd.c:
	* ppcobsd-tdep.h:
	* sentinel-frame.h:
	* sentinel-frame.c:
	* scm-valprint.c:
	* scm-tags.h:
	* scm-lang.h:
	* scm-lang.c:
	* scm-exp.c:
	* s390-tdep.h:
	* rom68k-rom.c:
	* remote.h:
	* remote-utils.c:
	* remote-st.c:
	* remote-sim.c:
	* remote-sds.c:
	* remote-rdp.c:
	* remote-rdi.c:
	* remote-hms.c:
	* sim-regno.h:
	* shnbsd-tdep.h:
	* shnbsd-tdep.c:
	* shnbsd-nat.c:
	* sh-tdep.h:
	* serial.h:
	* serial.c:
	* ser-unix.h:
	* ser-unix.c:
	* ser-tcp.c:
	* ser-pipe.c:
	* ser-go32.c:
	* ser-e7kpc.c:
	* ser-base.h:
	* ser-base.c:
	* solib.c:
	* solib-svr4.h:
	* solib-svr4.c:
	* solib-sunos.c:
	* solib-som.h:
	* solib-som.c:
	* solib-pa64.h:
	* solib-pa64.c:
	* solib-osf.c:
	* solib-null.c:
	* solib-legacy.c:
	* solib-irix.c:
	* solib-frv.c:
	* solib-aix5.c:
	* sol-thread.c:
	* sparc64-linux-tdep.c:
	* sparc64-linux-nat.c:
	* sparc-tdep.h:
	* sparc-tdep.c:
	* sparc-sol2-tdep.c:
	* sparc-sol2-nat.c:
	* sparc-nat.h:
	* sparc-nat.c:
	* sparc-linux-tdep.c:
	* sparc-linux-nat.c:
	* source.h:
	* source.c:
	* somread.c:
	* solist.h:
	* solib.h:
	* std-regs.c:
	* stack.h:
	* stack.c:
	* stabsread.h:
	* sparcobsd-tdep.c:
	* sparcnbsd-tdep.c:
	* sparcnbsd-nat.c:
	* sparc64obsd-tdep.c:
	* sparc64nbsd-tdep.c:
	* sparc64nbsd-nat.c:
	* sparc64fbsd-tdep.c:
	* sparc64fbsd-nat.c:
	* sparc64-tdep.h:
	* sparc64-tdep.c:
	* sparc64-sol2-tdep.c:
	* sparc64-nat.c:
	* ui-file.c:
	* typeprint.h:
	* typeprint.c:
	* tramp-frame.h:
	* tramp-frame.c:
	* trad-frame.h:
	* trad-frame.c:
	* tracepoint.h:
	* top.c:
	* tobs.inc:
	* thread.c:
	* terminal.h:
	* target.h:
	* symfile.h:
	* stop-gdb.c:
	* vaxbsd-nat.c:
	* vax-tdep.h:
	* vax-tdep.c:
	* vax-nat.c:
	* varobj.h:
	* varobj.c:
	* value.h:
	* value.c:
	* valprint.h:
	* valprint.c:
	* v850-tdep.c:
	* uw-thread.c:
	* user-regs.c:
	* ui-out.h:
	* ui-out.c:
	* ui-file.h:
	* xcoffsolib.h:
	* xcoffsolib.c:
	* wrapper.c:
	* wince.c:
	* wince-stub.h:
	* wince-stub.c:
	* vaxobsd-tdep.c:
	* vaxnbsd-tdep.c:
	* gdb_gcore.sh:
	* copying.c:
	* configure.ac:
	* aclocal.m4:
	* acinclude.m4:
	* reply_mig_hack.awk:
	* observer.sh:
	* gdb_mbuild.sh:
	* arm-linux-tdep.c:
	* blockframe.c:
	* dbug-rom.c:
	* environ.h:
	* dwarf2loc.h:
	* gdb-events.sh:
	* glibc-tdep.h:
	* gdb_wait.h:
	* gdbthread.h:
	* i386-sol2-tdep.c:
	* hppabsd-tdep.c:
	* hppa-linux-nat.c:
	* hppa-hpux-nat.c:
	* ia64-linux-tdep.c:
	* infptrace.c:
	* linespec.h:
	* maint.c:
	* mips-mdebug-tdep.h:
	* remote-m32r-sdi.c:
	* s390-nat.c:
	* rs6000-nat.c:
	* remote-utils.h:
	* sh3-rom.c:
	* sh-linux-tdep.c:
	* top.h:
	* symtab.h:
	* symmisc.c:
	* symfile-mem.c:
	* srec.h:
	* user-regs.h:
	* version.h:
	* valarith.c:
	* xstormy16-tdep.c:
	* wrapper.h:
	* Makefile.in:
	* f-exp.y:
	* cris-tdep.c:
	* cp-name-parser.y:
	* procfs.c:
	* proc-utils.h:
	* proc-flags.c:
	* proc-api.c:
	* p-exp.y:
	* m68hc11-tdep.c:
	* m2-exp.y:
	* kod.h:
	* kod-cisco.c:
	* jv-exp.y:
	* hppa-linux-tdep.c: Add (c) after Copyright.  Update the FSF
	address.
2005-12-17 22:34:03 +00:00

966 lines
25 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* YACC parser for Ada expressions, for GDB.
Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 1997, 2000, 2003,
2004 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* Parse an Ada expression from text in a string,
and return the result as a struct expression pointer.
That structure contains arithmetic operations in reverse polish,
with constants represented by operations that are followed by special data.
See expression.h for the details of the format.
What is important here is that it can be built up sequentially
during the process of parsing; the lower levels of the tree always
come first in the result.
malloc's and realloc's in this file are transformed to
xmalloc and xrealloc respectively by the same sed command in the
makefile that remaps any other malloc/realloc inserted by the parser
generator. Doing this with #defines and trying to control the interaction
with include files (<malloc.h> and <stdlib.h> for example) just became
too messy, particularly when such includes can be inserted at random
times by the parser generator. */
%{
#include "defs.h"
#include "gdb_string.h"
#include <ctype.h>
#include "expression.h"
#include "value.h"
#include "parser-defs.h"
#include "language.h"
#include "ada-lang.h"
#include "bfd.h" /* Required by objfiles.h. */
#include "symfile.h" /* Required by objfiles.h. */
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
#include "frame.h"
#include "block.h"
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
as well as gratuitiously global symbol names, so we can have multiple
yacc generated parsers in gdb. These are only the variables
produced by yacc. If other parser generators (bison, byacc, etc) produce
additional global names that conflict at link time, then those parser
generators need to be fixed instead of adding those names to this list. */
/* NOTE: This is clumsy, especially since BISON and FLEX provide --prefix
options. I presume we are maintaining it to accommodate systems
without BISON? (PNH) */
#define yymaxdepth ada_maxdepth
#define yyparse _ada_parse /* ada_parse calls this after initialization */
#define yylex ada_lex
#define yyerror ada_error
#define yylval ada_lval
#define yychar ada_char
#define yydebug ada_debug
#define yypact ada_pact
#define yyr1 ada_r1
#define yyr2 ada_r2
#define yydef ada_def
#define yychk ada_chk
#define yypgo ada_pgo
#define yyact ada_act
#define yyexca ada_exca
#define yyerrflag ada_errflag
#define yynerrs ada_nerrs
#define yyps ada_ps
#define yypv ada_pv
#define yys ada_s
#define yy_yys ada_yys
#define yystate ada_state
#define yytmp ada_tmp
#define yyv ada_v
#define yy_yyv ada_yyv
#define yyval ada_val
#define yylloc ada_lloc
#define yyreds ada_reds /* With YYDEBUG defined */
#define yytoks ada_toks /* With YYDEBUG defined */
#define yyname ada_name /* With YYDEBUG defined */
#define yyrule ada_rule /* With YYDEBUG defined */
#ifndef YYDEBUG
#define YYDEBUG 1 /* Default to yydebug support */
#endif
#define YYFPRINTF parser_fprintf
struct name_info {
struct symbol *sym;
struct minimal_symbol *msym;
struct block *block;
struct stoken stoken;
};
/* If expression is in the context of TYPE'(...), then TYPE, else
* NULL. */
static struct type *type_qualifier;
int yyparse (void);
static int yylex (void);
void yyerror (char *);
static struct stoken string_to_operator (struct stoken);
static void write_int (LONGEST, struct type *);
static void write_object_renaming (struct block *, struct symbol *, int);
static void write_var_from_name (struct block *, struct name_info);
static LONGEST convert_char_literal (struct type *, LONGEST);
static struct type *type_int (void);
static struct type *type_long (void);
static struct type *type_long_long (void);
static struct type *type_float (void);
static struct type *type_double (void);
static struct type *type_long_double (void);
static struct type *type_char (void);
static struct type *type_system_address (void);
%}
%union
{
LONGEST lval;
struct {
LONGEST val;
struct type *type;
} typed_val;
struct {
DOUBLEST dval;
struct type *type;
} typed_val_float;
struct type *tval;
struct stoken sval;
struct name_info ssym;
int voidval;
struct block *bval;
struct internalvar *ivar;
}
%type <voidval> exp exp1 simple_exp start variable
%type <tval> type
%token <typed_val> INT NULL_PTR CHARLIT
%token <typed_val_float> FLOAT
%token <tval> TYPENAME
%token <bval> BLOCKNAME
/* Both NAME and TYPENAME tokens represent symbols in the input,
and both convey their data as strings.
But a TYPENAME is a string that happens to be defined as a typedef
or builtin type name (such as int or char)
and a NAME is any other symbol.
Contexts where this distinction is not important can use the
nonterminal "name", which matches either NAME or TYPENAME. */
%token <sval> STRING
%token <ssym> NAME DOT_ID OBJECT_RENAMING
%type <bval> block
%type <lval> arglist tick_arglist
%type <tval> save_qualifier
%token DOT_ALL
/* Special type cases, put in to allow the parser to distinguish different
legal basetypes. */
%token <sval> SPECIAL_VARIABLE
%nonassoc ASSIGN
%left _AND_ OR XOR THEN ELSE
%left '=' NOTEQUAL '<' '>' LEQ GEQ IN DOTDOT
%left '@'
%left '+' '-' '&'
%left UNARY
%left '*' '/' MOD REM
%right STARSTAR ABS NOT
/* The following are right-associative only so that reductions at this
precedence have lower precedence than '.' and '('. The syntax still
forces a.b.c, e.g., to be LEFT-associated. */
%right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH
%right TICK_MAX TICK_MIN TICK_MODULUS
%right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL
%right '.' '(' '[' DOT_ID DOT_ALL
%token ARROW NEW
%%
start : exp1
| type { write_exp_elt_opcode (OP_TYPE);
write_exp_elt_type ($1);
write_exp_elt_opcode (OP_TYPE); }
;
/* Expressions, including the sequencing operator. */
exp1 : exp
| exp1 ';' exp
{ write_exp_elt_opcode (BINOP_COMMA); }
;
/* Expressions, not including the sequencing operator. */
simple_exp : simple_exp DOT_ALL
{ write_exp_elt_opcode (UNOP_IND); }
;
simple_exp : simple_exp DOT_ID
{ write_exp_elt_opcode (STRUCTOP_STRUCT);
write_exp_string ($2.stoken);
write_exp_elt_opcode (STRUCTOP_STRUCT);
}
;
simple_exp : simple_exp '(' arglist ')'
{
write_exp_elt_opcode (OP_FUNCALL);
write_exp_elt_longcst ($3);
write_exp_elt_opcode (OP_FUNCALL);
}
;
simple_exp : type '(' exp ')'
{
write_exp_elt_opcode (UNOP_CAST);
write_exp_elt_type ($1);
write_exp_elt_opcode (UNOP_CAST);
}
;
simple_exp : type '\'' save_qualifier { type_qualifier = $1; } '(' exp ')'
{
write_exp_elt_opcode (UNOP_QUAL);
write_exp_elt_type ($1);
write_exp_elt_opcode (UNOP_QUAL);
type_qualifier = $3;
}
;
save_qualifier : { $$ = type_qualifier; }
;
simple_exp :
simple_exp '(' exp DOTDOT exp ')'
{ write_exp_elt_opcode (TERNOP_SLICE); }
;
simple_exp : '(' exp1 ')' { }
;
simple_exp : variable
;
simple_exp: SPECIAL_VARIABLE /* Various GDB extensions */
{ write_dollar_variable ($1); }
;
exp : simple_exp
;
exp : exp ASSIGN exp /* Extension for convenience */
{ write_exp_elt_opcode (BINOP_ASSIGN); }
;
exp : '-' exp %prec UNARY
{ write_exp_elt_opcode (UNOP_NEG); }
;
exp : '+' exp %prec UNARY
{ write_exp_elt_opcode (UNOP_PLUS); }
;
exp : NOT exp %prec UNARY
{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
;
exp : ABS exp %prec UNARY
{ write_exp_elt_opcode (UNOP_ABS); }
;
arglist : { $$ = 0; }
;
arglist : exp
{ $$ = 1; }
| any_name ARROW exp
{ $$ = 1; }
| arglist ',' exp
{ $$ = $1 + 1; }
| arglist ',' any_name ARROW exp
{ $$ = $1 + 1; }
;
exp : '{' type '}' exp %prec '.'
/* GDB extension */
{ write_exp_elt_opcode (UNOP_MEMVAL);
write_exp_elt_type ($2);
write_exp_elt_opcode (UNOP_MEMVAL);
}
;
/* Binary operators in order of decreasing precedence. */
exp : exp STARSTAR exp
{ write_exp_elt_opcode (BINOP_EXP); }
;
exp : exp '*' exp
{ write_exp_elt_opcode (BINOP_MUL); }
;
exp : exp '/' exp
{ write_exp_elt_opcode (BINOP_DIV); }
;
exp : exp REM exp /* May need to be fixed to give correct Ada REM */
{ write_exp_elt_opcode (BINOP_REM); }
;
exp : exp MOD exp
{ write_exp_elt_opcode (BINOP_MOD); }
;
exp : exp '@' exp /* GDB extension */
{ write_exp_elt_opcode (BINOP_REPEAT); }
;
exp : exp '+' exp
{ write_exp_elt_opcode (BINOP_ADD); }
;
exp : exp '&' exp
{ write_exp_elt_opcode (BINOP_CONCAT); }
;
exp : exp '-' exp
{ write_exp_elt_opcode (BINOP_SUB); }
;
exp : exp '=' exp
{ write_exp_elt_opcode (BINOP_EQUAL); }
;
exp : exp NOTEQUAL exp
{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
;
exp : exp LEQ exp
{ write_exp_elt_opcode (BINOP_LEQ); }
;
exp : exp IN exp DOTDOT exp
{ write_exp_elt_opcode (TERNOP_IN_RANGE); }
| exp IN exp TICK_RANGE tick_arglist
{ write_exp_elt_opcode (BINOP_IN_BOUNDS);
write_exp_elt_longcst ((LONGEST) $5);
write_exp_elt_opcode (BINOP_IN_BOUNDS);
}
| exp IN TYPENAME %prec TICK_ACCESS
{ write_exp_elt_opcode (UNOP_IN_RANGE);
write_exp_elt_type ($3);
write_exp_elt_opcode (UNOP_IN_RANGE);
}
| exp NOT IN exp DOTDOT exp
{ write_exp_elt_opcode (TERNOP_IN_RANGE);
write_exp_elt_opcode (UNOP_LOGICAL_NOT);
}
| exp NOT IN exp TICK_RANGE tick_arglist
{ write_exp_elt_opcode (BINOP_IN_BOUNDS);
write_exp_elt_longcst ((LONGEST) $6);
write_exp_elt_opcode (BINOP_IN_BOUNDS);
write_exp_elt_opcode (UNOP_LOGICAL_NOT);
}
| exp NOT IN TYPENAME %prec TICK_ACCESS
{ write_exp_elt_opcode (UNOP_IN_RANGE);
write_exp_elt_type ($4);
write_exp_elt_opcode (UNOP_IN_RANGE);
write_exp_elt_opcode (UNOP_LOGICAL_NOT);
}
;
exp : exp GEQ exp
{ write_exp_elt_opcode (BINOP_GEQ); }
;
exp : exp '<' exp
{ write_exp_elt_opcode (BINOP_LESS); }
;
exp : exp '>' exp
{ write_exp_elt_opcode (BINOP_GTR); }
;
exp : exp _AND_ exp /* Fix for Ada elementwise AND. */
{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
;
exp : exp _AND_ THEN exp %prec _AND_
{ write_exp_elt_opcode (BINOP_LOGICAL_AND); }
;
exp : exp OR exp /* Fix for Ada elementwise OR */
{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
;
exp : exp OR ELSE exp
{ write_exp_elt_opcode (BINOP_LOGICAL_OR); }
;
exp : exp XOR exp /* Fix for Ada elementwise XOR */
{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
;
simple_exp : simple_exp TICK_ACCESS
{ write_exp_elt_opcode (UNOP_ADDR); }
| simple_exp TICK_ADDRESS
{ write_exp_elt_opcode (UNOP_ADDR);
write_exp_elt_opcode (UNOP_CAST);
write_exp_elt_type (type_system_address ());
write_exp_elt_opcode (UNOP_CAST);
}
| simple_exp TICK_FIRST tick_arglist
{ write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_FIRST); }
| simple_exp TICK_LAST tick_arglist
{ write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LAST); }
| simple_exp TICK_LENGTH tick_arglist
{ write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LENGTH); }
| simple_exp TICK_SIZE
{ write_exp_elt_opcode (OP_ATR_SIZE); }
| simple_exp TICK_TAG
{ write_exp_elt_opcode (OP_ATR_TAG); }
| opt_type_prefix TICK_MIN '(' exp ',' exp ')'
{ write_exp_elt_opcode (OP_ATR_MIN); }
| opt_type_prefix TICK_MAX '(' exp ',' exp ')'
{ write_exp_elt_opcode (OP_ATR_MAX); }
| opt_type_prefix TICK_POS '(' exp ')'
{ write_exp_elt_opcode (OP_ATR_POS); }
| type_prefix TICK_FIRST tick_arglist
{ write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_FIRST); }
| type_prefix TICK_LAST tick_arglist
{ write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LAST); }
| type_prefix TICK_LENGTH tick_arglist
{ write_int ($3, type_int ());
write_exp_elt_opcode (OP_ATR_LENGTH); }
| type_prefix TICK_VAL '(' exp ')'
{ write_exp_elt_opcode (OP_ATR_VAL); }
| type_prefix TICK_MODULUS
{ write_exp_elt_opcode (OP_ATR_MODULUS); }
;
tick_arglist : %prec '('
{ $$ = 1; }
| '(' INT ')'
{ $$ = $2.val; }
;
type_prefix :
TYPENAME
{ write_exp_elt_opcode (OP_TYPE);
write_exp_elt_type ($1);
write_exp_elt_opcode (OP_TYPE); }
;
opt_type_prefix :
type_prefix
| /* EMPTY */
{ write_exp_elt_opcode (OP_TYPE);
write_exp_elt_type (builtin_type_void);
write_exp_elt_opcode (OP_TYPE); }
;
exp : INT
{ write_int ((LONGEST) $1.val, $1.type); }
;
exp : CHARLIT
{ write_int (convert_char_literal (type_qualifier, $1.val),
(type_qualifier == NULL)
? $1.type : type_qualifier);
}
;
exp : FLOAT
{ write_exp_elt_opcode (OP_DOUBLE);
write_exp_elt_type ($1.type);
write_exp_elt_dblcst ($1.dval);
write_exp_elt_opcode (OP_DOUBLE);
}
;
exp : NULL_PTR
{ write_int (0, type_int ()); }
;
exp : STRING
{
write_exp_elt_opcode (OP_STRING);
write_exp_string ($1);
write_exp_elt_opcode (OP_STRING);
}
;
exp : NEW TYPENAME
{ error ("NEW not implemented."); }
;
variable: NAME { write_var_from_name (NULL, $1); }
| block NAME /* GDB extension */
{ write_var_from_name ($1, $2); }
| OBJECT_RENAMING
{ write_object_renaming (NULL, $1.sym,
MAX_RENAMING_CHAIN_LENGTH); }
| block OBJECT_RENAMING
{ write_object_renaming ($1, $2.sym,
MAX_RENAMING_CHAIN_LENGTH); }
;
any_name : NAME { }
| TYPENAME { }
| OBJECT_RENAMING { }
;
block : BLOCKNAME /* GDB extension */
{ $$ = $1; }
| block BLOCKNAME /* GDB extension */
{ $$ = $2; }
;
type : TYPENAME { $$ = $1; }
| block TYPENAME { $$ = $2; }
| TYPENAME TICK_ACCESS
{ $$ = lookup_pointer_type ($1); }
| block TYPENAME TICK_ACCESS
{ $$ = lookup_pointer_type ($2); }
;
/* Some extensions borrowed from C, for the benefit of those who find they
can't get used to Ada notation in GDB. */
exp : '*' exp %prec '.'
{ write_exp_elt_opcode (UNOP_IND); }
| '&' exp %prec '.'
{ write_exp_elt_opcode (UNOP_ADDR); }
| exp '[' exp ']'
{ write_exp_elt_opcode (BINOP_SUBSCRIPT); }
;
%%
/* yylex defined in ada-lex.c: Reads one token, getting characters */
/* through lexptr. */
/* Remap normal flex interface names (yylex) as well as gratuitiously */
/* global symbol names, so we can have multiple flex-generated parsers */
/* in gdb. */
/* (See note above on previous definitions for YACC.) */
#define yy_create_buffer ada_yy_create_buffer
#define yy_delete_buffer ada_yy_delete_buffer
#define yy_init_buffer ada_yy_init_buffer
#define yy_load_buffer_state ada_yy_load_buffer_state
#define yy_switch_to_buffer ada_yy_switch_to_buffer
#define yyrestart ada_yyrestart
#define yytext ada_yytext
#define yywrap ada_yywrap
static struct obstack temp_parse_space;
/* The following kludge was found necessary to prevent conflicts between */
/* defs.h and non-standard stdlib.h files. */
#define qsort __qsort__dummy
#include "ada-lex.c"
int
ada_parse (void)
{
lexer_init (yyin); /* (Re-)initialize lexer. */
left_block_context = NULL;
type_qualifier = NULL;
obstack_free (&temp_parse_space, NULL);
obstack_init (&temp_parse_space);
return _ada_parse ();
}
void
yyerror (char *msg)
{
error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
}
/* The operator name corresponding to operator symbol STRING (adds
quotes and maps to lower-case). Destroys the previous contents of
the array pointed to by STRING.ptr. Error if STRING does not match
a valid Ada operator. Assumes that STRING.ptr points to a
null-terminated string and that, if STRING is a valid operator
symbol, the array pointed to by STRING.ptr contains at least
STRING.length+3 characters. */
static struct stoken
string_to_operator (struct stoken string)
{
int i;
for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
{
if (string.length == strlen (ada_opname_table[i].decoded)-2
&& strncasecmp (string.ptr, ada_opname_table[i].decoded+1,
string.length) == 0)
{
strncpy (string.ptr, ada_opname_table[i].decoded,
string.length+2);
string.length += 2;
return string;
}
}
error ("Invalid operator symbol `%s'", string.ptr);
}
/* Emit expression to access an instance of SYM, in block BLOCK (if
* non-NULL), and with :: qualification ORIG_LEFT_CONTEXT. */
static void
write_var_from_sym (struct block *orig_left_context,
struct block *block,
struct symbol *sym)
{
if (orig_left_context == NULL && symbol_read_needs_frame (sym))
{
if (innermost_block == 0
|| contained_in (block, innermost_block))
innermost_block = block;
}
write_exp_elt_opcode (OP_VAR_VALUE);
write_exp_elt_block (block);
write_exp_elt_sym (sym);
write_exp_elt_opcode (OP_VAR_VALUE);
}
/* Emit expression to access an instance of NAME in :: context
* ORIG_LEFT_CONTEXT. If no unique symbol for NAME has been found,
* output a dummy symbol (good to the next call of ada_parse) for NAME
* in the UNDEF_DOMAIN, for later resolution by ada_resolve. */
static void
write_var_from_name (struct block *orig_left_context,
struct name_info name)
{
if (name.msym != NULL)
{
write_exp_msymbol (name.msym,
lookup_function_type (type_int ()),
type_int ());
}
else if (name.sym == NULL)
{
/* Multiple matches: record name and starting block for later
resolution by ada_resolve. */
char *encoded_name = ada_encode (name.stoken.ptr);
struct symbol *sym =
obstack_alloc (&temp_parse_space, sizeof (struct symbol));
memset (sym, 0, sizeof (struct symbol));
SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
SYMBOL_LINKAGE_NAME (sym)
= obsavestring (encoded_name, strlen (encoded_name), &temp_parse_space);
SYMBOL_LANGUAGE (sym) = language_ada;
write_exp_elt_opcode (OP_VAR_VALUE);
write_exp_elt_block (name.block);
write_exp_elt_sym (sym);
write_exp_elt_opcode (OP_VAR_VALUE);
}
else
write_var_from_sym (orig_left_context, name.block, name.sym);
}
/* Write integer constant ARG of type TYPE. */
static void
write_int (LONGEST arg, struct type *type)
{
write_exp_elt_opcode (OP_LONG);
write_exp_elt_type (type);
write_exp_elt_longcst (arg);
write_exp_elt_opcode (OP_LONG);
}
/* Emit expression corresponding to the renamed object designated by
* the type RENAMING, which must be the referent of an object renaming
* type, in the context of ORIG_LEFT_CONTEXT. MAX_DEPTH is the maximum
* number of cascaded renamings to allow. */
static void
write_object_renaming (struct block *orig_left_context,
struct symbol *renaming, int max_depth)
{
const char *qualification = SYMBOL_LINKAGE_NAME (renaming);
const char *simple_tail;
const char *expr = TYPE_FIELD_NAME (SYMBOL_TYPE (renaming), 0);
const char *suffix;
char *name;
struct symbol *sym;
enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
if (max_depth <= 0)
error ("Could not find renamed symbol");
/* if orig_left_context is null, then use the currently selected
block; otherwise we might fail our symbol lookup below. */
if (orig_left_context == NULL)
orig_left_context = get_selected_block (NULL);
for (simple_tail = qualification + strlen (qualification);
simple_tail != qualification; simple_tail -= 1)
{
if (*simple_tail == '.')
{
simple_tail += 1;
break;
}
else if (strncmp (simple_tail, "__", 2) == 0)
{
simple_tail += 2;
break;
}
}
suffix = strstr (expr, "___XE");
if (suffix == NULL)
goto BadEncoding;
name = (char *) obstack_alloc (&temp_parse_space, suffix - expr + 1);
strncpy (name, expr, suffix-expr);
name[suffix-expr] = '\000';
sym = lookup_symbol (name, orig_left_context, VAR_DOMAIN, 0, NULL);
if (sym == NULL)
error ("Could not find renamed variable: %s", ada_decode (name));
if (ada_is_object_renaming (sym))
write_object_renaming (orig_left_context, sym, max_depth-1);
else
write_var_from_sym (orig_left_context, block_found, sym);
suffix += 5;
slice_state = SIMPLE_INDEX;
while (*suffix == 'X')
{
suffix += 1;
switch (*suffix) {
case 'A':
suffix += 1;
write_exp_elt_opcode (UNOP_IND);
break;
case 'L':
slice_state = LOWER_BOUND;
case 'S':
suffix += 1;
if (isdigit (*suffix))
{
char *next;
long val = strtol (suffix, &next, 10);
if (next == suffix)
goto BadEncoding;
suffix = next;
write_exp_elt_opcode (OP_LONG);
write_exp_elt_type (type_int ());
write_exp_elt_longcst ((LONGEST) val);
write_exp_elt_opcode (OP_LONG);
}
else
{
const char *end;
char *index_name;
int index_len;
struct symbol *index_sym;
end = strchr (suffix, 'X');
if (end == NULL)
end = suffix + strlen (suffix);
index_len = simple_tail - qualification + 2 + (suffix - end) + 1;
index_name
= (char *) obstack_alloc (&temp_parse_space, index_len);
memset (index_name, '\000', index_len);
strncpy (index_name, qualification, simple_tail - qualification);
index_name[simple_tail - qualification] = '\000';
strncat (index_name, suffix, suffix-end);
suffix = end;
index_sym =
lookup_symbol (index_name, NULL, VAR_DOMAIN, 0, NULL);
if (index_sym == NULL)
error ("Could not find %s", index_name);
write_var_from_sym (NULL, block_found, sym);
}
if (slice_state == SIMPLE_INDEX)
{
write_exp_elt_opcode (OP_FUNCALL);
write_exp_elt_longcst ((LONGEST) 1);
write_exp_elt_opcode (OP_FUNCALL);
}
else if (slice_state == LOWER_BOUND)
slice_state = UPPER_BOUND;
else if (slice_state == UPPER_BOUND)
{
write_exp_elt_opcode (TERNOP_SLICE);
slice_state = SIMPLE_INDEX;
}
break;
case 'R':
{
struct stoken field_name;
const char *end;
suffix += 1;
if (slice_state != SIMPLE_INDEX)
goto BadEncoding;
end = strchr (suffix, 'X');
if (end == NULL)
end = suffix + strlen (suffix);
field_name.length = end - suffix;
field_name.ptr = xmalloc (end - suffix + 1);
strncpy (field_name.ptr, suffix, end - suffix);
field_name.ptr[end - suffix] = '\000';
suffix = end;
write_exp_elt_opcode (STRUCTOP_STRUCT);
write_exp_string (field_name);
write_exp_elt_opcode (STRUCTOP_STRUCT);
break;
}
default:
goto BadEncoding;
}
}
if (slice_state == SIMPLE_INDEX)
return;
BadEncoding:
error ("Internal error in encoding of renaming declaration: %s",
SYMBOL_LINKAGE_NAME (renaming));
}
/* Convert the character literal whose ASCII value would be VAL to the
appropriate value of type TYPE, if there is a translation.
Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
the literal 'A' (VAL == 65), returns 0. */
static LONGEST
convert_char_literal (struct type *type, LONGEST val)
{
char name[7];
int f;
if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
return val;
sprintf (name, "QU%02x", (int) val);
for (f = 0; f < TYPE_NFIELDS (type); f += 1)
{
if (strcmp (name, TYPE_FIELD_NAME (type, f)) == 0)
return TYPE_FIELD_BITPOS (type, f);
}
return val;
}
static struct type *
type_int (void)
{
return builtin_type (current_gdbarch)->builtin_int;
}
static struct type *
type_long (void)
{
return builtin_type (current_gdbarch)->builtin_long;
}
static struct type *
type_long_long (void)
{
return builtin_type (current_gdbarch)->builtin_long_long;
}
static struct type *
type_float (void)
{
return builtin_type (current_gdbarch)->builtin_float;
}
static struct type *
type_double (void)
{
return builtin_type (current_gdbarch)->builtin_double;
}
static struct type *
type_long_double (void)
{
return builtin_type (current_gdbarch)->builtin_long_double;
}
static struct type *
type_char (void)
{
return language_string_char_type (current_language, current_gdbarch);
}
static struct type *
type_system_address (void)
{
struct type *type
= language_lookup_primitive_type_by_name (current_language,
current_gdbarch,
"system__address");
return type != NULL ? type : lookup_pointer_type (builtin_type_void);
}
void
_initialize_ada_exp (void)
{
obstack_init (&temp_parse_space);
}
/* FIXME: hilfingr/2004-10-05: Hack to remove warning. The function
string_to_operator is supposed to be used for cases where one
calls an operator function with prefix notation, as in
"+" (a, b), but at some point, this code seems to have gone
missing. */
struct stoken (*dummy_string_to_ada_operator) (struct stoken)
= string_to_operator;