/* YACC parser for Java expressions, for GDB.
- Copyright (C) 1997.
+ Copyright 1997, 1998, 1999, 2000
Free Software Foundation, Inc.
This file is part of GDB.
#define YYDEBUG 0 /* Default to no yydebug support */
#endif
-int
-yyparse PARAMS ((void));
+int yyparse (void);
-static int
-yylex PARAMS ((void));
+static int yylex (void);
-void
-yyerror PARAMS ((char *));
+void yyerror (char *);
-static struct type * java_type_from_name PARAMS ((struct stoken));
-static void push_expression_name PARAMS ((struct stoken));
-static void push_fieldnames PARAMS ((struct stoken));
+static struct type *java_type_from_name (struct stoken);
+static void push_expression_name (struct stoken);
+static void push_fieldnames (struct stoken);
-static struct expression *copy_exp PARAMS ((struct expression *, int));
-static void insert_exp PARAMS ((int, struct expression *));
+static struct expression *copy_exp (struct expression *, int);
+static void insert_exp (int, struct expression *);
%}
%{
/* YYSTYPE gets defined by %union */
-static int
-parse_number PARAMS ((char *, int, int, YYSTYPE *));
+static int parse_number (char *, int, int, YYSTYPE *);
%}
%type <lval> rcurly Dims Dims_opt
%type <tval> ClassOrInterfaceType ClassType /* ReferenceType Type ArrayType */
-%type <tval> IntegralType FloatingPointType NumericType PrimitiveType
+%type <tval> IntegralType FloatingPointType NumericType PrimitiveType ArrayType PrimitiveOrArrayType
%token <typed_val_int> INTEGER_LITERAL
%token <typed_val_float> FLOATING_POINT_LITERAL
%%
start : exp1
-/* | type_exp FIXME */
+ | type_exp
+ ;
+
+type_exp: PrimitiveOrArrayType
+ {
+ write_exp_elt_opcode(OP_TYPE);
+ write_exp_elt_type($1);
+ write_exp_elt_opcode(OP_TYPE);
+ }
+ ;
+
+PrimitiveOrArrayType:
+ PrimitiveType
+ | ArrayType
;
StringLiteral:
ClassOrInterfaceType
;
-/* UNUSED:
ArrayType:
PrimitiveType Dims
{ $$ = java_array_type ($1, $2); }
| Name Dims
{ $$ = java_array_type (java_type_from_name ($1), $2); }
;
-*/
Name:
IDENTIFIER
num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval, &c);
else
{
-#ifdef PRINTF_HAS_LONG_DOUBLE
+#ifdef SCANF_HAS_LONG_DOUBLE
num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval, &c);
#else
/* Scan it into a double, then assign it to the long double.
return ERROR;
return FLOATING_POINT_LITERAL;
-}
+ }
/* Handle base-switching prefixes 0x, 0t, 0d, 0 */
if (p[0] == '0')
}
c = p[len-1];
+ /* A paranoid calculation of (1<<64)-1. */
limit = (ULONGEST)0xffffffff;
+ limit = ((limit << 16) << 16) | limit;
if (c == 'l' || c == 'L')
{
type = java_long_type;
len--;
- /* A paranoid calculation of (1<<64)-1. */
- limit = ((limit << 16) << 16) | limit;
}
else
{
n += c;
}
- putithere->typed_val_int.val = n;
- putithere->typed_val_int.type = type;
- return INTEGER_LITERAL;
+ /* If the type is bigger than a 32-bit signed integer can be, implicitly
+ promote to long. Java does not do this, so mark it as builtin_type_uint64
+ rather than java_long_type. 0x80000000 will become -0x80000000 instead
+ of 0x80000000L, because we don't know the sign at this point.
+ */
+ if (type == java_int_type && n > (ULONGEST)0x80000000)
+ type = builtin_type_uint64;
+
+ putithere->typed_val_int.val = n;
+ putithere->typed_val_int.type = type;
+
+ return INTEGER_LITERAL;
}
struct token
retry:
+ prev_lexptr = lexptr;
+
tokstart = lexptr;
/* See if it is a special token of length 3. */
for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
error ("Empty character constant.");
yylval.typed_val_int.val = c;
- yylval.typed_val_int.type = builtin_type_char;
+ yylval.typed_val_int.type = java_char_type;
c = *lexptr++;
if (c != '\'')
/* It's a name. See how long it is. */
namelen = 0;
for (c = tokstart[namelen];
- (c == '_' || c == '$' || (c >= '0' && c <= '9')
- || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
+ (c == '_'
+ || c == '$'
+ || (c >= '0' && c <= '9')
+ || (c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || c == '<');
+ )
{
- if (c == '<')
- {
- int i = namelen;
- while (tokstart[++i] && tokstart[i] != '>');
- if (tokstart[i] == '>')
- namelen = i;
- }
+ if (c == '<')
+ {
+ int i = namelen;
+ while (tokstart[++i] && tokstart[i] != '>');
+ if (tokstart[i] == '>')
+ namelen = i;
+ }
c = tokstart[++namelen];
}
yyerror (msg)
char *msg;
{
+ if (prev_lexptr)
+ lexptr = prev_lexptr;
+
error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
}