binutils-gdb/gdb/ada-lex.l
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

930 lines
23 KiB
Plaintext

/* FLEX lexer for Ada expressions, for GDB.
Copyright (C) 1994, 1997, 1998, 2000, 2001, 2002, 2003
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. */
/*----------------------------------------------------------------------*/
/* The converted version of this file is to be included in ada-exp.y, */
/* the Ada parser for gdb. The function yylex obtains characters from */
/* the global pointer lexptr. It returns a syntactic category for */
/* each successive token and places a semantic value into yylval */
/* (ada-lval), defined by the parser. */
DIG [0-9]
NUM10 ({DIG}({DIG}|_)*)
HEXDIG [0-9a-f]
NUM16 ({HEXDIG}({HEXDIG}|_)*)
OCTDIG [0-7]
LETTER [a-z_]
ID ({LETTER}({LETTER}|{DIG})*|"<"{LETTER}({LETTER}|{DIG})*">")
WHITE [ \t\n]
TICK ("'"{WHITE}*)
GRAPHIC [a-z0-9 #&'()*+,-./:;<>=_|!$%?@\[\]\\^`{}~]
OPER ([-+*/=<>&]|"<="|">="|"**"|"/="|"and"|"or"|"xor"|"not"|"mod"|"rem"|"abs")
EXP (e[+-]{NUM10})
POSEXP (e"+"?{NUM10})
%{
#define NUMERAL_WIDTH 256
#define LONGEST_SIGN ((ULONGEST) 1 << (sizeof(LONGEST) * HOST_CHAR_BIT - 1))
/* Temporary staging for numeric literals. */
static char numbuf[NUMERAL_WIDTH];
static void canonicalizeNumeral (char *s1, const char *);
static int processInt (const char *, const char *, const char *);
static int processReal (const char *);
static int processId (const char *, int);
static int processAttribute (const char *);
static int find_dot_all (const char *);
#undef YY_DECL
#define YY_DECL static int yylex ( void )
#undef YY_INPUT
#define YY_INPUT(BUF, RESULT, MAX_SIZE) \
if ( *lexptr == '\000' ) \
(RESULT) = YY_NULL; \
else \
{ \
*(BUF) = *lexptr; \
(RESULT) = 1; \
lexptr += 1; \
}
static char *tempbuf = NULL;
static int tempbufsize = 0;
static int tempbuf_len;
static struct block *left_block_context;
static void resize_tempbuf (unsigned int);
static void block_lookup (char *, char *);
static int name_lookup (char *, char *, int *, int);
static int find_dot_all (const char *);
%}
%option case-insensitive interactive nodefault
%s IN_STRING BEFORE_QUAL_QUOTE
%%
{WHITE} { }
"--".* { yyterminate(); }
{NUM10}{POSEXP} {
canonicalizeNumeral (numbuf, yytext);
return processInt (NULL, numbuf, strrchr(numbuf, 'e')+1);
}
{NUM10} {
canonicalizeNumeral (numbuf, yytext);
return processInt (NULL, numbuf, NULL);
}
{NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} {
canonicalizeNumeral (numbuf, yytext);
return processInt (numbuf,
strchr (numbuf, '#') + 1,
strrchr(numbuf, '#') + 1);
}
{NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" {
canonicalizeNumeral (numbuf, yytext);
return processInt (numbuf, strchr (numbuf, '#') + 1, NULL);
}
"0x"{HEXDIG}+ {
canonicalizeNumeral (numbuf, yytext+2);
return processInt ("16#", numbuf, NULL);
}
{NUM10}"."{NUM10}{EXP} {
canonicalizeNumeral (numbuf, yytext);
return processReal (numbuf);
}
{NUM10}"."{NUM10} {
canonicalizeNumeral (numbuf, yytext);
return processReal (numbuf);
}
{NUM10}"#"{NUM16}"."{NUM16}"#"{EXP} {
error ("Based real literals not implemented yet.");
}
{NUM10}"#"{NUM16}"."{NUM16}"#" {
error ("Based real literals not implemented yet.");
}
<INITIAL>"'"({GRAPHIC}|\")"'" {
yylval.typed_val.type = type_char ();
yylval.typed_val.val = yytext[1];
return CHARLIT;
}
<INITIAL>"'[\""{HEXDIG}{2}"\"]'" {
int v;
yylval.typed_val.type = type_char ();
sscanf (yytext+3, "%2x", &v);
yylval.typed_val.val = v;
return CHARLIT;
}
<INITIAL>\" {
tempbuf_len = 0;
BEGIN IN_STRING;
}
<IN_STRING>{GRAPHIC}*\" {
resize_tempbuf (yyleng+tempbuf_len);
strncpy (tempbuf+tempbuf_len, yytext, yyleng-1);
tempbuf_len += yyleng-1;
yylval.sval.ptr = tempbuf;
yylval.sval.length = tempbuf_len;
BEGIN INITIAL;
return STRING;
}
<IN_STRING>{GRAPHIC}*"[\""{HEXDIG}{2}"\"]" {
int n;
resize_tempbuf (yyleng-5+tempbuf_len+1);
strncpy (tempbuf+tempbuf_len, yytext, yyleng-6);
sscanf(yytext+yyleng-4, "%2x", &n);
tempbuf[yyleng-6+tempbuf_len] = (char) n;
tempbuf_len += yyleng-5;
}
<IN_STRING>{GRAPHIC}*"[\"\"\"]" {
int n;
resize_tempbuf (yyleng-4+tempbuf_len+1);
strncpy (tempbuf+tempbuf_len, yytext, yyleng-6);
tempbuf[yyleng-5+tempbuf_len] = '"';
tempbuf_len += yyleng-4;
}
if {
while (*lexptr != 'i' && *lexptr != 'I')
lexptr -= 1;
yyrestart(NULL);
return 0;
}
/* ADA KEYWORDS */
abs { return ABS; }
and { return _AND_; }
else { return ELSE; }
in { return IN; }
mod { return MOD; }
new { return NEW; }
not { return NOT; }
null { return NULL_PTR; }
or { return OR; }
rem { return REM; }
then { return THEN; }
xor { return XOR; }
/* ATTRIBUTES */
{TICK}[a-zA-Z][a-zA-Z]+ { return processAttribute (yytext+1); }
/* PUNCTUATION */
"=>" { return ARROW; }
".." { return DOTDOT; }
"**" { return STARSTAR; }
":=" { return ASSIGN; }
"/=" { return NOTEQUAL; }
"<=" { return LEQ; }
">=" { return GEQ; }
<BEFORE_QUAL_QUOTE>"'" { BEGIN INITIAL; return '\''; }
[-&*+./:<>=|;\[\]] { return yytext[0]; }
"," { if (paren_depth == 0 && comma_terminates)
{
lexptr -= 1;
yyrestart(NULL);
return 0;
}
else
return ',';
}
"(" { paren_depth += 1; return '('; }
")" { if (paren_depth == 0)
{
lexptr -= 1;
yyrestart(NULL);
return 0;
}
else
{
paren_depth -= 1;
return ')';
}
}
"."{WHITE}*all { return DOT_ALL; }
"."{WHITE}*{ID} {
processId (yytext+1, yyleng-1);
return DOT_ID;
}
{ID}({WHITE}*"."{WHITE}*({ID}|\"{OPER}\"))*(" "*"'")? {
int all_posn = find_dot_all (yytext);
int token_type, segments, k;
int quote_follows;
if (all_posn == -1 && yytext[yyleng-1] == '\'')
{
quote_follows = 1;
do {
yyless (yyleng-1);
} while (yytext[yyleng-1] == ' ');
}
else
quote_follows = 0;
if (all_posn >= 0)
yyless (all_posn);
processId(yytext, yyleng);
segments = name_lookup (ada_encode (yylval.ssym.stoken.ptr),
yylval.ssym.stoken.ptr,
&token_type,
MAX_RENAMING_CHAIN_LENGTH);
left_block_context = NULL;
for (k = yyleng; segments > 0 && k > 0; k -= 1)
{
if (yytext[k-1] == '.')
segments -= 1;
quote_follows = 0;
}
if (k <= 0)
error ("confused by name %s", yytext);
yyless (k);
if (quote_follows)
BEGIN BEFORE_QUAL_QUOTE;
return token_type;
}
/* GDB EXPRESSION CONSTRUCTS */
"'"[^']+"'"{WHITE}*:: {
processId(yytext, yyleng-2);
block_lookup (yylval.ssym.stoken.ptr, yylval.ssym.stoken.ptr);
return BLOCKNAME;
}
{ID}({WHITE}*"."{WHITE}*({ID}|\"{OPER}\"))*{WHITE}*:: {
processId(yytext, yyleng-2);
block_lookup (ada_encode (yylval.ssym.stoken.ptr),
yylval.ssym.stoken.ptr);
return BLOCKNAME;
}
[{}@] { return yytext[0]; }
/* REGISTERS AND GDB CONVENIENCE VARIABLES */
"$"({LETTER}|{DIG}|"$")* {
yylval.sval.ptr = yytext;
yylval.sval.length = yyleng;
return SPECIAL_VARIABLE;
}
/* CATCH-ALL ERROR CASE */
. { error ("Invalid character '%s' in expression.", yytext); }
%%
#include <ctype.h>
#include "gdb_string.h"
/* Initialize the lexer for processing new expression */
void
lexer_init (FILE *inp)
{
BEGIN INITIAL;
yyrestart (inp);
}
/* Make sure that tempbuf points at an array at least N characters long. */
static void
resize_tempbuf (unsigned int n)
{
if (tempbufsize < n)
{
tempbufsize = (n+63) & ~63;
tempbuf = xrealloc (tempbuf, tempbufsize);
}
}
/* Copy S2 to S1, removing all underscores, and downcasing all letters. */
static void
canonicalizeNumeral (char *s1, const char *s2)
{
for (; *s2 != '\000'; s2 += 1)
{
if (*s2 != '_')
{
*s1 = tolower(*s2);
s1 += 1;
}
}
s1[0] = '\000';
}
#define HIGH_BYTE_POSN ((sizeof (ULONGEST) - 1) * HOST_CHAR_BIT)
/* True (non-zero) iff DIGIT is a valid digit in radix BASE,
where 2 <= BASE <= 16. */
static int
is_digit_in_base (unsigned char digit, int base)
{
if (!isxdigit (digit))
return 0;
if (base <= 10)
return (isdigit (digit) && digit < base + '0');
else
return (isdigit (digit) || tolower (digit) < base - 10 + 'a');
}
static int
digit_to_int (unsigned char c)
{
if (isdigit (c))
return c - '0';
else
return tolower (c) - 'a' + 10;
}
/* As for strtoul, but for ULONGEST results. */
ULONGEST
strtoulst (const char *num, const char **trailer, int base)
{
unsigned int high_part;
ULONGEST result;
int i;
unsigned char lim;
if (base < 2 || base > 16)
{
errno = EINVAL;
return 0;
}
lim = base - 1 + '0';
result = high_part = 0;
for (i = 0; is_digit_in_base (num[i], base); i += 1)
{
result = result*base + digit_to_int (num[i]);
high_part = high_part*base + (unsigned int) (result >> HIGH_BYTE_POSN);
result &= ((ULONGEST) 1 << HIGH_BYTE_POSN) - 1;
if (high_part > 0xff)
{
errno = ERANGE;
result = high_part = 0;
break;
}
}
if (trailer != NULL)
*trailer = &num[i];
return result + ((ULONGEST) high_part << HIGH_BYTE_POSN);
}
/* Interprets the prefix of NUM that consists of digits of the given BASE
as an integer of that BASE, with the string EXP as an exponent.
Puts value in yylval, and returns INT, if the string is valid. Causes
an error if the number is improperly formated. BASE, if NULL, defaults
to "10", and EXP to "1". The EXP does not contain a leading 'e' or 'E'. */
static int
processInt (const char *base0, const char *num0, const char *exp0)
{
ULONGEST result;
long exp;
int base;
char *trailer;
if (base0 == NULL)
base = 10;
else
{
base = strtol (base0, (char **) NULL, 10);
if (base < 2 || base > 16)
error ("Invalid base: %d.", base);
}
if (exp0 == NULL)
exp = 0;
else
exp = strtol(exp0, (char **) NULL, 10);
errno = 0;
result = strtoulst (num0, (const char **) &trailer, base);
if (errno == ERANGE)
error ("Integer literal out of range");
if (isxdigit(*trailer))
error ("Invalid digit `%c' in based literal", *trailer);
while (exp > 0)
{
if (result > (ULONG_MAX / base))
error ("Integer literal out of range");
result *= base;
exp -= 1;
}
if ((result >> (TARGET_INT_BIT-1)) == 0)
yylval.typed_val.type = type_int ();
else if ((result >> (TARGET_LONG_BIT-1)) == 0)
yylval.typed_val.type = type_long ();
else if (((result >> (TARGET_LONG_BIT-1)) >> 1) == 0)
{
/* We have a number representable as an unsigned integer quantity.
For consistency with the C treatment, we will treat it as an
anonymous modular (unsigned) quantity. Alas, the types are such
that we need to store .val as a signed quantity. Sorry
for the mess, but C doesn't officially guarantee that a simple
assignment does the trick (no, it doesn't; read the reference manual).
*/
yylval.typed_val.type = builtin_type_unsigned_long;
if (result & LONGEST_SIGN)
yylval.typed_val.val =
(LONGEST) (result & ~LONGEST_SIGN)
- (LONGEST_SIGN>>1) - (LONGEST_SIGN>>1);
else
yylval.typed_val.val = (LONGEST) result;
return INT;
}
else
yylval.typed_val.type = type_long_long ();
yylval.typed_val.val = (LONGEST) result;
return INT;
}
#if defined (PRINTF_HAS_LONG_DOUBLE)
# undef PRINTF_HAS_LONG_DOUBLE
# define PRINTF_HAS_LONG_DOUBLE 1
#else
# define PRINTF_HAS_LONG_DOUBLE 0
#endif
static int
processReal (const char *num0)
{
#if defined (PRINTF_HAS_LONG_DOUBLE)
if (sizeof (DOUBLEST) > sizeof (double))
sscanf (num0, "%Lg", &yylval.typed_val_float.dval);
else
#endif
{
double temp;
sscanf (num0, "%lg", &temp);
yylval.typed_val_float.dval = temp;
}
yylval.typed_val_float.type = type_float ();
if (sizeof(DOUBLEST) >= TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
yylval.typed_val_float.type = type_double ();
if (sizeof(DOUBLEST) >= TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
yylval.typed_val_float.type = type_long_double ();
return FLOAT;
}
static int
processId (const char *name0, int len)
{
char *name = obstack_alloc (&temp_parse_space, len + 11);
int i0, i;
while (len > 0 && isspace (name0[len-1]))
len -= 1;
i = i0 = 0;
while (i0 < len)
{
if (isalnum (name0[i0]))
{
name[i] = tolower (name0[i0]);
i += 1; i0 += 1;
}
else switch (name0[i0])
{
default:
name[i] = name0[i0];
i += 1; i0 += 1;
break;
case ' ': case '\t':
i0 += 1;
break;
case '\'':
i0 += 1;
while (i0 < len && name0[i0] != '\'')
{
name[i] = name0[i0];
i += 1; i0 += 1;
}
i0 += 1;
break;
case '<':
i0 += 1;
while (i0 < len && name0[i0] != '>')
{
name[i] = name0[i0];
i += 1; i0 += 1;
}
i0 += 1;
break;
}
}
name[i] = '\000';
yylval.ssym.sym = NULL;
yylval.ssym.stoken.ptr = name;
yylval.ssym.stoken.length = i;
return NAME;
}
static void
block_lookup (char *name, char *err_name)
{
struct ada_symbol_info *syms;
int nsyms;
struct symtab *symtab;
nsyms = ada_lookup_symbol_list (name, left_block_context,
VAR_DOMAIN, &syms);
if (left_block_context == NULL &&
(nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
symtab = lookup_symtab (name);
else
symtab = NULL;
if (symtab != NULL)
left_block_context = yylval.bval =
BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
else if (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK)
{
if (left_block_context == NULL)
error ("No file or function \"%s\".", err_name);
else
error ("No function \"%s\" in specified context.", err_name);
}
else
{
left_block_context = yylval.bval = SYMBOL_BLOCK_VALUE (syms[0].sym);
if (nsyms > 1)
warning ("Function name \"%s\" ambiguous here", err_name);
}
}
/* Look up NAME0 (assumed to be encoded) as a name in VAR_DOMAIN,
setting *TOKEN_TYPE to NAME or TYPENAME, depending on what is
found. Try first the entire name, then the name without the last
segment (i.e., after the last .id), etc., and return the number of
segments that had to be removed to get a match. Try only the full
name if it starts with "standard__". Calls error if no
matches are found, using ERR_NAME in any error message. When
exactly one symbol match is found, it is placed in yylval. When
the symbol is a renaming, follow at most DEPTH steps to find the
ultimate definition; cause error if depth exceeded. */
static int
name_lookup (char *name0, char *err_name, int *token_type, int depth)
{
struct ada_symbol_info *syms;
struct type *type;
int len0 = strlen (name0);
char *name = obsavestring (name0, len0, &temp_parse_space);
int nsyms;
int segments;
if (depth <= 0)
error ("Could not find renamed symbol \"%s\"", err_name);
yylval.ssym.stoken.ptr = name;
yylval.ssym.stoken.length = strlen (name);
for (segments = 0; ; segments += 1)
{
struct type *preferred_type;
int i, preferred_index;
if (left_block_context == NULL)
nsyms = ada_lookup_symbol_list (name, expression_context_block,
VAR_DOMAIN, &syms);
else
nsyms = ada_lookup_symbol_list (name, left_block_context,
VAR_DOMAIN, &syms);
/* Check for a type renaming. */
if (nsyms == 1 && !ada_is_object_renaming (syms[0].sym))
{
struct symbol *renaming_sym =
ada_find_renaming_symbol (SYMBOL_LINKAGE_NAME (syms[0].sym),
syms[0].block);
if (renaming_sym != NULL)
syms[0].sym = renaming_sym;
}
/* Check for a type definition. */
/* Look for a symbol that doesn't denote void. This is (I think) a */
/* temporary kludge to get around problems in GNAT output. */
preferred_index = -1; preferred_type = NULL;
for (i = 0; i < nsyms; i += 1)
switch (SYMBOL_CLASS (syms[i].sym))
{
case LOC_TYPEDEF:
if (ada_prefer_type (SYMBOL_TYPE (syms[i].sym), preferred_type))
{
preferred_index = i;
preferred_type = SYMBOL_TYPE (syms[i].sym);
}
break;
case LOC_REGISTER:
case LOC_ARG:
case LOC_REF_ARG:
case LOC_REGPARM:
case LOC_REGPARM_ADDR:
case LOC_LOCAL:
case LOC_LOCAL_ARG:
case LOC_BASEREG:
case LOC_BASEREG_ARG:
case LOC_COMPUTED:
case LOC_COMPUTED_ARG:
goto NotType;
default:
break;
}
if (preferred_type != NULL)
{
if (TYPE_CODE (preferred_type) == TYPE_CODE_VOID)
error ("`%s' matches only void type name(s)",
ada_decode (name));
else if (ada_is_object_renaming (syms[preferred_index].sym))
{
yylval.ssym.sym = syms[preferred_index].sym;
*token_type = OBJECT_RENAMING;
return segments;
}
else if (ada_renaming_type (SYMBOL_TYPE (syms[preferred_index].sym))
!= NULL)
{
int result;
char *renaming
= ada_simple_renamed_entity (syms[preferred_index].sym);
char *new_name
= (char *) obstack_alloc (&temp_parse_space,
strlen (renaming) + len0
- yylval.ssym.stoken.length + 1);
strcpy (new_name, renaming);
xfree (renaming);
strcat (new_name, name0 + yylval.ssym.stoken.length);
result = name_lookup (new_name, err_name, token_type, depth - 1);
if (result > segments)
error ("Confused by renamed symbol.");
return result;
}
else if (segments == 0)
{
yylval.tval = preferred_type;
*token_type = TYPENAME;
return 0;
}
}
if (segments == 0)
{
type = language_lookup_primitive_type_by_name (current_language,
current_gdbarch,
name);
if (type == NULL && strcmp ("system__address", name) == 0)
type = type_system_address ();
if (type != NULL)
{
/* First check to see if we have a regular definition of this
type that just didn't happen to have been read yet. */
int ntypes;
struct symbol *sym;
char *expanded_name =
(char *) alloca (strlen (name) + sizeof ("standard__"));
strcpy (expanded_name, "standard__");
strcat (expanded_name, name);
sym = ada_lookup_symbol (expanded_name, NULL,
VAR_DOMAIN, NULL, NULL);
if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
type = SYMBOL_TYPE (sym);
yylval.tval = type;
*token_type = TYPENAME;
return 0;
}
}
NotType:
if (nsyms == 1)
{
*token_type = NAME;
yylval.ssym.sym = syms[0].sym;
yylval.ssym.msym = NULL;
yylval.ssym.block = syms[0].block;
return segments;
}
else if (nsyms == 0) {
int i;
yylval.ssym.msym = ada_lookup_simple_minsym (name);
if (yylval.ssym.msym != NULL)
{
yylval.ssym.sym = NULL;
yylval.ssym.block = NULL;
*token_type = NAME;
return segments;
}
if (segments == 0
&& strncmp (name, "standard__", sizeof ("standard__") - 1) == 0)
error ("No definition of \"%s\" found.", err_name);
for (i = yylval.ssym.stoken.length - 1; i > 0; i -= 1)
{
if (name[i] == '.')
{
name[i] = '\0';
yylval.ssym.stoken.length = i;
break;
}
else if (name[i] == '_' && name[i-1] == '_')
{
i -= 1;
name[i] = '\0';
yylval.ssym.stoken.length = i;
break;
}
}
if (i <= 0)
{
if (!have_full_symbols () && !have_partial_symbols ()
&& left_block_context == NULL)
error ("No symbol table is loaded. Use the \"file\" command.");
if (left_block_context == NULL)
error ("No definition of \"%s\" in current context.",
err_name);
else
error ("No definition of \"%s\" in specified context.",
err_name);
}
}
else
{
*token_type = NAME;
yylval.ssym.sym = NULL;
yylval.ssym.msym = NULL;
if (left_block_context == NULL)
yylval.ssym.block = expression_context_block;
else
yylval.ssym.block = left_block_context;
return segments;
}
}
}
/* Returns the position within STR of the '.' in a
'.{WHITE}*all' component of a dotted name, or -1 if there is none. */
static int
find_dot_all (const char *str)
{
int i;
for (i = 0; str[i] != '\000'; i += 1)
{
if (str[i] == '.')
{
int i0 = i;
do
i += 1;
while (isspace (str[i]));
if (strcmp (str+i, "all") == 0
&& ! isalnum (str[i+3]) && str[i+3] != '_')
return i0;
}
}
return -1;
}
/* Returns non-zero iff string SUBSEQ matches a subsequence of STR, ignoring
case. */
static int
subseqMatch (const char *subseq, const char *str)
{
if (subseq[0] == '\0')
return 1;
else if (str[0] == '\0')
return 0;
else if (tolower (subseq[0]) == tolower (str[0]))
return subseqMatch (subseq+1, str+1) || subseqMatch (subseq, str+1);
else
return subseqMatch (subseq, str+1);
}
static struct { const char *name; int code; }
attributes[] = {
{ "address", TICK_ADDRESS },
{ "unchecked_access", TICK_ACCESS },
{ "unrestricted_access", TICK_ACCESS },
{ "access", TICK_ACCESS },
{ "first", TICK_FIRST },
{ "last", TICK_LAST },
{ "length", TICK_LENGTH },
{ "max", TICK_MAX },
{ "min", TICK_MIN },
{ "modulus", TICK_MODULUS },
{ "pos", TICK_POS },
{ "range", TICK_RANGE },
{ "size", TICK_SIZE },
{ "tag", TICK_TAG },
{ "val", TICK_VAL },
{ NULL, -1 }
};
/* Return the syntactic code corresponding to the attribute name or
abbreviation STR. */
static int
processAttribute (const char *str)
{
int i, k;
for (i = 0; attributes[i].code != -1; i += 1)
if (strcasecmp (str, attributes[i].name) == 0)
return attributes[i].code;
for (i = 0, k = -1; attributes[i].code != -1; i += 1)
if (subseqMatch (str, attributes[i].name))
{
if (k == -1)
k = i;
else
error ("ambiguous attribute name: `%s'", str);
}
if (k == -1)
error ("unrecognized attribute: `%s'", str);
return attributes[k].code;
}
int
yywrap(void)
{
return 1;
}
/* Dummy definition to suppress warnings about unused static definitions. */
typedef void (*dummy_function) ();
dummy_function ada_flex_use[] =
{
(dummy_function) yyunput
};