From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32037 invoked by alias); 15 Jan 2012 19:05:17 -0000 Received: (qmail 31716 invoked by uid 22791); 15 Jan 2012 19:05:11 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_CP,TW_YY,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 15 Jan 2012 19:04:55 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0FJ4s6g028277 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 15 Jan 2012 14:04:54 -0500 Received: from psique ([10.3.112.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q0FJ4oFm018460 for ; Sun, 15 Jan 2012 14:04:52 -0500 From: Sergio Durigan Junior To: gdb-patches@sourceware.org Subject: [RFC 5/8] Java language References: X-URL: http://www.redhat.com Date: Sun, 15 Jan 2012 19:06:00 -0000 In-Reply-To: (Sergio Durigan Junior's message of "Sun, 15 Jan 2012 16:48:52 -0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-01/txt/msg00531.txt.bz2 Hi, This is the patch for the Java language. Thanks, Sergio. diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y index a8eb430..50d3383 100644 --- a/gdb/jv-exp.y +++ b/gdb/jv-exp.y @@ -48,8 +48,8 @@ #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ #include "block.h" -#define parse_type builtin_type (parse_gdbarch) -#define parse_java_type builtin_java_type (parse_gdbarch) +#define parse_type(ps) builtin_type (parse_gdbarch (ps)) +#define parse_java_type(ps) builtin_java_type (parse_gdbarch (ps)) /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), as well as gratuitiously global symbol names, so we can have multiple @@ -105,21 +105,24 @@ #define YYFPRINTF parser_fprintf -int yyparse (void); +int yyparse (struct parser_state *); -static int yylex (void); +static int yylex (struct parser_state *); -void yyerror (char *); +void yyerror (struct parser_state *, char *); static struct type *java_type_from_name (struct stoken); -static void push_expression_name (struct stoken); -static void push_fieldnames (struct stoken); +static void push_expression_name (struct parser_state *, struct stoken); +static void push_fieldnames (struct parser_state *, struct stoken); static struct expression *copy_exp (struct expression *, int); -static void insert_exp (int, struct expression *); +static void insert_exp (struct parser_state *, int, struct expression *); %} +%parse-param {struct parser_state *ps} +%lex-param {struct parser_state *ps} + /* Although the yacc "value" of an expression is not used, since the result is stored in the structure being created, other node types do have values. */ @@ -148,7 +151,7 @@ static void insert_exp (int, struct expression *); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (char *, int, int, YYSTYPE *); +static int parse_number (struct parser_state *, char *, int, int, YYSTYPE *); %} %type rcurly Dims Dims_opt @@ -208,9 +211,9 @@ start : exp1 type_exp: PrimitiveOrArrayType { - write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type($1); - write_exp_elt_opcode(OP_TYPE); + write_exp_elt_opcode (ps, OP_TYPE); + write_exp_elt_type (ps, $1); + write_exp_elt_opcode (ps, OP_TYPE); } ; @@ -222,36 +225,37 @@ PrimitiveOrArrayType: StringLiteral: STRING_LITERAL { - write_exp_elt_opcode (OP_STRING); - write_exp_string ($1); - write_exp_elt_opcode (OP_STRING); + write_exp_elt_opcode (ps, OP_STRING); + write_exp_string (ps, $1); + write_exp_elt_opcode (ps, OP_STRING); } ; Literal: INTEGER_LITERAL - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type ($1.type); - write_exp_elt_longcst ((LONGEST)($1.val)); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (ps, OP_LONG); + write_exp_elt_type (ps, $1.type); + write_exp_elt_longcst (ps, (LONGEST)($1.val)); + write_exp_elt_opcode (ps, OP_LONG); } | NAME_OR_INT { YYSTYPE val; - parse_number ($1.ptr, $1.length, 0, &val); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (val.typed_val_int.type); - write_exp_elt_longcst ((LONGEST)val.typed_val_int.val); - write_exp_elt_opcode (OP_LONG); + parse_number (ps, $1.ptr, $1.length, 0, &val); + write_exp_elt_opcode (ps, OP_LONG); + write_exp_elt_type (ps, val.typed_val_int.type); + write_exp_elt_longcst (ps, (LONGEST)val.typed_val_int.val); + write_exp_elt_opcode (ps, OP_LONG); } | FLOATING_POINT_LITERAL - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type ($1.type); - write_exp_elt_dblcst ($1.dval); - write_exp_elt_opcode (OP_DOUBLE); } + { write_exp_elt_opcode (ps, OP_DOUBLE); + write_exp_elt_type (ps, $1.type); + write_exp_elt_dblcst (ps, $1.dval); + write_exp_elt_opcode (ps, OP_DOUBLE); } | BOOLEAN_LITERAL - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (parse_java_type->builtin_boolean); - write_exp_elt_longcst ((LONGEST)$1); - write_exp_elt_opcode (OP_LONG); } + { write_exp_elt_opcode (ps, OP_LONG); + write_exp_elt_type (ps, + parse_java_type (ps)->builtin_boolean); + write_exp_elt_longcst (ps, (LONGEST)$1); + write_exp_elt_opcode (ps, OP_LONG); } | StringLiteral ; @@ -265,7 +269,7 @@ Type: PrimitiveType: NumericType | BOOLEAN - { $$ = parse_java_type->builtin_boolean; } + { $$ = parse_java_type (ps)->builtin_boolean; } ; NumericType: @@ -275,22 +279,22 @@ NumericType: IntegralType: BYTE - { $$ = parse_java_type->builtin_byte; } + { $$ = parse_java_type (ps)->builtin_byte; } | SHORT - { $$ = parse_java_type->builtin_short; } + { $$ = parse_java_type (ps)->builtin_short; } | INT - { $$ = parse_java_type->builtin_int; } + { $$ = parse_java_type (ps)->builtin_int; } | LONG - { $$ = parse_java_type->builtin_long; } + { $$ = parse_java_type (ps)->builtin_long; } | CHAR - { $$ = parse_java_type->builtin_char; } + { $$ = parse_java_type (ps)->builtin_char; } ; FloatingPointType: FLOAT - { $$ = parse_java_type->builtin_float; } + { $$ = parse_java_type (ps)->builtin_float; } | DOUBLE - { $$ = parse_java_type->builtin_double; } + { $$ = parse_java_type (ps)->builtin_double; } ; /* UNUSED: @@ -357,7 +361,7 @@ type_exp: type /* Expressions, including the comma operator. */ exp1 : Expression | exp1 ',' Expression - { write_exp_elt_opcode (BINOP_COMMA); } + { write_exp_elt_opcode (ps, BINOP_COMMA); } ; Primary: @@ -373,10 +377,10 @@ PrimaryNoNewArray: | MethodInvocation | ArrayAccess | lcurly ArgumentList rcurly - { write_exp_elt_opcode (OP_ARRAY); - write_exp_elt_longcst ((LONGEST) 0); - write_exp_elt_longcst ((LONGEST) $3); - write_exp_elt_opcode (OP_ARRAY); } + { write_exp_elt_opcode (ps, OP_ARRAY); + write_exp_elt_longcst (ps, (LONGEST) 0); + write_exp_elt_longcst (ps, (LONGEST) $3); + write_exp_elt_opcode (ps, OP_ARRAY); } ; lcurly: @@ -441,24 +445,24 @@ Dims_opt: FieldAccess: Primary '.' SimpleName - { push_fieldnames ($3); } + { push_fieldnames (ps, $3); } | VARIABLE '.' SimpleName - { push_fieldnames ($3); } + { push_fieldnames (ps, $3); } /*| SUPER '.' SimpleName { FIXME } */ ; FuncStart: Name '(' - { push_expression_name ($1); } + { push_expression_name (ps, $1); } ; MethodInvocation: FuncStart { start_arglist(); } ArgumentList_opt ')' - { write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } + { write_exp_elt_opcode (ps, OP_FUNCALL); + write_exp_elt_longcst (ps, (LONGEST) end_arglist ()); + write_exp_elt_opcode (ps, OP_FUNCALL); } | Primary '.' SimpleName '(' ArgumentList_opt ')' { error (_("Form of method invocation not implemented")); } | SUPER '.' SimpleName '(' ArgumentList_opt ')' @@ -475,24 +479,26 @@ ArrayAccess: for our parsing kludges. */ struct expression *name_expr; - push_expression_name ($1); - name_expr = copy_exp (expout, expout_ptr); - expout_ptr -= name_expr->nelts; - insert_exp (expout_ptr-length_of_subexp (expout, expout_ptr), + push_expression_name (ps, $1); + name_expr = copy_exp (ps->expout, ps->expout_ptr); + ps->expout_ptr -= name_expr->nelts; + insert_exp (ps, + ps->expout_ptr - length_of_subexp (ps->expout, + ps->expout_ptr), name_expr); free (name_expr); - write_exp_elt_opcode (BINOP_SUBSCRIPT); + write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); } | VARIABLE '[' Expression ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); } | PrimaryNoNewArray '[' Expression ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } + { write_exp_elt_opcode (ps, BINOP_SUBSCRIPT); } ; PostfixExpression: Primary | Name - { push_expression_name ($1); } + { push_expression_name (ps, $1); } | VARIABLE /* Already written by write_dollar_variable. */ | PostIncrementExpression @@ -501,12 +507,12 @@ PostfixExpression: PostIncrementExpression: PostfixExpression INCREMENT - { write_exp_elt_opcode (UNOP_POSTINCREMENT); } + { write_exp_elt_opcode (ps, UNOP_POSTINCREMENT); } ; PostDecrementExpression: PostfixExpression DECREMENT - { write_exp_elt_opcode (UNOP_POSTDECREMENT); } + { write_exp_elt_opcode (ps, UNOP_POSTDECREMENT); } ; UnaryExpression: @@ -514,144 +520,149 @@ UnaryExpression: | PreDecrementExpression | '+' UnaryExpression | '-' UnaryExpression - { write_exp_elt_opcode (UNOP_NEG); } + { write_exp_elt_opcode (ps, UNOP_NEG); } | '*' UnaryExpression - { write_exp_elt_opcode (UNOP_IND); } /*FIXME not in Java */ + { write_exp_elt_opcode (ps, UNOP_IND); } /*FIXME not in Java */ | UnaryExpressionNotPlusMinus ; PreIncrementExpression: INCREMENT UnaryExpression - { write_exp_elt_opcode (UNOP_PREINCREMENT); } + { write_exp_elt_opcode (ps, UNOP_PREINCREMENT); } ; PreDecrementExpression: DECREMENT UnaryExpression - { write_exp_elt_opcode (UNOP_PREDECREMENT); } + { write_exp_elt_opcode (ps, UNOP_PREDECREMENT); } ; UnaryExpressionNotPlusMinus: PostfixExpression | '~' UnaryExpression - { write_exp_elt_opcode (UNOP_COMPLEMENT); } + { write_exp_elt_opcode (ps, UNOP_COMPLEMENT); } | '!' UnaryExpression - { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } + { write_exp_elt_opcode (ps, UNOP_LOGICAL_NOT); } | CastExpression ; CastExpression: '(' PrimitiveType Dims_opt ')' UnaryExpression - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (java_array_type ($2, $3)); - write_exp_elt_opcode (UNOP_CAST); } + { write_exp_elt_opcode (ps, UNOP_CAST); + write_exp_elt_type (ps, java_array_type ($2, $3)); + write_exp_elt_opcode (ps, UNOP_CAST); } | '(' Expression ')' UnaryExpressionNotPlusMinus { - int last_exp_size = length_of_subexp(expout, expout_ptr); + int last_exp_size = length_of_subexp (ps->expout, + ps->expout_ptr); struct type *type; int i; - int base = expout_ptr - last_exp_size - 3; - if (base < 0 || expout->elts[base+2].opcode != OP_TYPE) + int base = ps->expout_ptr - last_exp_size - 3; + + if (base < 0 || ps->expout->elts[base+2].opcode != OP_TYPE) error (_("Invalid cast expression")); - type = expout->elts[base+1].type; + type = ps->expout->elts[base+1].type; /* Remove the 'Expression' and slide the UnaryExpressionNotPlusMinus down to replace it. */ for (i = 0; i < last_exp_size; i++) - expout->elts[base + i] = expout->elts[base + i + 3]; - expout_ptr -= 3; + ps->expout->elts[base + i] + = ps->expout->elts[base + i + 3]; + ps->expout_ptr -= 3; if (TYPE_CODE (type) == TYPE_CODE_STRUCT) type = lookup_pointer_type (type); - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (type); - write_exp_elt_opcode (UNOP_CAST); + write_exp_elt_opcode (ps, UNOP_CAST); + write_exp_elt_type (ps, type); + write_exp_elt_opcode (ps, UNOP_CAST); } | '(' Name Dims ')' UnaryExpressionNotPlusMinus - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (java_array_type (java_type_from_name ($2), $3)); - write_exp_elt_opcode (UNOP_CAST); } + { write_exp_elt_opcode (ps, UNOP_CAST); + write_exp_elt_type (ps, + java_array_type (java_type_from_name + ($2), $3)); + write_exp_elt_opcode (ps, UNOP_CAST); } ; MultiplicativeExpression: UnaryExpression | MultiplicativeExpression '*' UnaryExpression - { write_exp_elt_opcode (BINOP_MUL); } + { write_exp_elt_opcode (ps, BINOP_MUL); } | MultiplicativeExpression '/' UnaryExpression - { write_exp_elt_opcode (BINOP_DIV); } + { write_exp_elt_opcode (ps, BINOP_DIV); } | MultiplicativeExpression '%' UnaryExpression - { write_exp_elt_opcode (BINOP_REM); } + { write_exp_elt_opcode (ps, BINOP_REM); } ; AdditiveExpression: MultiplicativeExpression | AdditiveExpression '+' MultiplicativeExpression - { write_exp_elt_opcode (BINOP_ADD); } + { write_exp_elt_opcode (ps, BINOP_ADD); } | AdditiveExpression '-' MultiplicativeExpression - { write_exp_elt_opcode (BINOP_SUB); } + { write_exp_elt_opcode (ps, BINOP_SUB); } ; ShiftExpression: AdditiveExpression | ShiftExpression LSH AdditiveExpression - { write_exp_elt_opcode (BINOP_LSH); } + { write_exp_elt_opcode (ps, BINOP_LSH); } | ShiftExpression RSH AdditiveExpression - { write_exp_elt_opcode (BINOP_RSH); } + { write_exp_elt_opcode (ps, BINOP_RSH); } /* | ShiftExpression >>> AdditiveExpression { FIXME } */ ; RelationalExpression: ShiftExpression | RelationalExpression '<' ShiftExpression - { write_exp_elt_opcode (BINOP_LESS); } + { write_exp_elt_opcode (ps, BINOP_LESS); } | RelationalExpression '>' ShiftExpression - { write_exp_elt_opcode (BINOP_GTR); } + { write_exp_elt_opcode (ps, BINOP_GTR); } | RelationalExpression LEQ ShiftExpression - { write_exp_elt_opcode (BINOP_LEQ); } + { write_exp_elt_opcode (ps, BINOP_LEQ); } | RelationalExpression GEQ ShiftExpression - { write_exp_elt_opcode (BINOP_GEQ); } + { write_exp_elt_opcode (ps, BINOP_GEQ); } /* | RelationalExpresion INSTANCEOF ReferenceType { FIXME } */ ; EqualityExpression: RelationalExpression | EqualityExpression EQUAL RelationalExpression - { write_exp_elt_opcode (BINOP_EQUAL); } + { write_exp_elt_opcode (ps, BINOP_EQUAL); } | EqualityExpression NOTEQUAL RelationalExpression - { write_exp_elt_opcode (BINOP_NOTEQUAL); } + { write_exp_elt_opcode (ps, BINOP_NOTEQUAL); } ; AndExpression: EqualityExpression | AndExpression '&' EqualityExpression - { write_exp_elt_opcode (BINOP_BITWISE_AND); } + { write_exp_elt_opcode (ps, BINOP_BITWISE_AND); } ; ExclusiveOrExpression: AndExpression | ExclusiveOrExpression '^' AndExpression - { write_exp_elt_opcode (BINOP_BITWISE_XOR); } + { write_exp_elt_opcode (ps, BINOP_BITWISE_XOR); } ; InclusiveOrExpression: ExclusiveOrExpression | InclusiveOrExpression '|' ExclusiveOrExpression - { write_exp_elt_opcode (BINOP_BITWISE_IOR); } + { write_exp_elt_opcode (ps, BINOP_BITWISE_IOR); } ; ConditionalAndExpression: InclusiveOrExpression | ConditionalAndExpression ANDAND InclusiveOrExpression - { write_exp_elt_opcode (BINOP_LOGICAL_AND); } + { write_exp_elt_opcode (ps, BINOP_LOGICAL_AND); } ; ConditionalOrExpression: ConditionalAndExpression | ConditionalOrExpression OROR ConditionalAndExpression - { write_exp_elt_opcode (BINOP_LOGICAL_OR); } + { write_exp_elt_opcode (ps, BINOP_LOGICAL_OR); } ; ConditionalExpression: ConditionalOrExpression | ConditionalOrExpression '?' Expression ':' ConditionalExpression - { write_exp_elt_opcode (TERNOP_COND); } + { write_exp_elt_opcode (ps, TERNOP_COND); } ; AssignmentExpression: @@ -661,16 +672,16 @@ AssignmentExpression: Assignment: LeftHandSide '=' ConditionalExpression - { write_exp_elt_opcode (BINOP_ASSIGN); } + { write_exp_elt_opcode (ps, BINOP_ASSIGN); } | LeftHandSide ASSIGN_MODIFY ConditionalExpression - { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode ($2); - write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } + { write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); + write_exp_elt_opcode (ps, $2); + write_exp_elt_opcode (ps, BINOP_ASSIGN_MODIFY); } ; LeftHandSide: ForcedName - { push_expression_name ($1); } + { push_expression_name (ps, $1); } | VARIABLE /* Already written by write_dollar_variable. */ | FieldAccess @@ -690,7 +701,8 @@ Expression: /*** Needs some error checking for the float case ***/ static int -parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (struct parser_state *ps, char *p, int len, int parsed_float, + YYSTYPE *putithere) { ULONGEST n = 0; ULONGEST limit, limit_div_base; @@ -711,16 +723,16 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) suffix_len = p + len - suffix; if (suffix_len == 0) - putithere->typed_val_float.type = parse_type->builtin_double; + putithere->typed_val_float.type = parse_type (ps)->builtin_double; else if (suffix_len == 1) { /* See if it has `f' or `d' suffix (float or double). */ if (tolower (*suffix) == 'f') putithere->typed_val_float.type = - parse_type->builtin_float; + parse_type (ps)->builtin_float; else if (tolower (*suffix) == 'd') putithere->typed_val_float.type = - parse_type->builtin_double; + parse_type (ps)->builtin_double; else return ERROR; } @@ -767,12 +779,12 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) limit = ((limit << 16) << 16) | limit; if (c == 'l' || c == 'L') { - type = parse_java_type->builtin_long; + type = parse_java_type (ps)->builtin_long; len--; } else { - type = parse_java_type->builtin_int; + type = parse_java_type (ps)->builtin_int; } limit_div_base = limit / (ULONGEST) base; @@ -797,11 +809,12 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) /* 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 - parse_type->builtin_uint64 rather than parse_java_type->builtin_long. + parse_type (ps)->builtin_uint64 rather than + parse_java_type (ps)->builtin_long. 0x80000000 will become -0x80000000 instead of 0x80000000L, because we don't know the sign at this point. */ - if (type == parse_java_type->builtin_int && n > (ULONGEST)0x80000000) - type = parse_type->builtin_uint64; + if (type == parse_java_type (ps)->builtin_int && n > (ULONGEST)0x80000000) + type = parse_type (ps)->builtin_uint64; putithere->typed_val_int.val = n; putithere->typed_val_int.type = type; @@ -847,7 +860,7 @@ static const struct token tokentab2[] = /* Read one token, getting characters through lexptr. */ static int -yylex (void) +yylex (struct parser_state *ps) { int c; int namelen; @@ -899,12 +912,12 @@ yylex (void) lexptr++; c = *lexptr++; if (c == '\\') - c = parse_escape (parse_gdbarch, &lexptr); + c = parse_escape (parse_gdbarch (ps), &lexptr); else if (c == '\'') error (_("Empty character constant")); yylval.typed_val_int.val = c; - yylval.typed_val_int.type = parse_java_type->builtin_char; + yylval.typed_val_int.type = parse_java_type (ps)->builtin_char; c = *lexptr++; if (c != '\'') @@ -997,7 +1010,8 @@ yylex (void) && (*p < 'A' || *p > 'Z'))) break; } - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); + toktype = parse_number (ps, tokstart, p - tokstart, + got_dot|got_e, &yylval); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); @@ -1062,7 +1076,7 @@ yylex (void) break; case '\\': tokptr++; - c = parse_escape (parse_gdbarch, &tokptr); + c = parse_escape (parse_gdbarch (ps), &tokptr); if (c == -1) { continue; @@ -1174,7 +1188,7 @@ yylex (void) if (*tokstart == '$') { - write_dollar_variable (yylval.sval); + write_dollar_variable (ps, yylval.sval); return VARIABLE; } @@ -1185,7 +1199,7 @@ yylex (void) (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) { YYSTYPE newlval; /* Its value is ignored. */ - int hextype = parse_number (tokstart, namelen, 0, &newlval); + int hextype = parse_number (ps, tokstart, namelen, 0, &newlval); if (hextype == INTEGER_LITERAL) return NAME_OR_INT; } @@ -1193,7 +1207,7 @@ yylex (void) } void -yyerror (char *msg) +yyerror (struct parser_state *ps, char *msg) { if (prev_lexptr) lexptr = prev_lexptr; @@ -1209,6 +1223,7 @@ java_type_from_name (struct stoken name) { char *tmp = copy_name (name); struct type *typ = java_lookup_class (tmp); + if (typ == NULL || TYPE_CODE (typ) != TYPE_CODE_STRUCT) error (_("No class named `%s'"), tmp); return typ; @@ -1218,11 +1233,12 @@ java_type_from_name (struct stoken name) Otherwise, return 0. */ static int -push_variable (struct stoken name) +push_variable (struct parser_state *ps, struct stoken name) { char *tmp = copy_name (name); int is_a_field_of_this = 0; struct symbol *sym; + sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, &is_a_field_of_this); if (sym && SYMBOL_CLASS (sym) != LOC_TYPEDEF) @@ -1234,12 +1250,12 @@ push_variable (struct stoken name) innermost_block = block_found; } - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_opcode (ps, OP_VAR_VALUE); /* We want to use the selected frame, not another more inner frame which happens to be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); + write_exp_elt_block (ps, NULL); + write_exp_elt_sym (ps, sym); + write_exp_elt_opcode (ps, OP_VAR_VALUE); return 1; } if (is_a_field_of_this) @@ -1249,11 +1265,11 @@ push_variable (struct stoken name) if (innermost_block == 0 || contained_in (block_found, innermost_block)) innermost_block = block_found; - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string (name); - write_exp_elt_opcode (STRUCTOP_PTR); + write_exp_elt_opcode (ps, OP_THIS); + write_exp_elt_opcode (ps, OP_THIS); + write_exp_elt_opcode (ps, STRUCTOP_PTR); + write_exp_string (ps, name); + write_exp_elt_opcode (ps, STRUCTOP_PTR); return 1; } return 0; @@ -1264,7 +1280,7 @@ push_variable (struct stoken name) qualified name (has '.'), generate a field access for each part. */ static void -push_fieldnames (struct stoken name) +push_fieldnames (struct parser_state *ps, struct stoken name) { int i; struct stoken token; @@ -1275,9 +1291,9 @@ push_fieldnames (struct stoken name) { /* token.ptr is start of current field name. */ token.length = &name.ptr[i] - token.ptr; - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string (token); - write_exp_elt_opcode (STRUCTOP_PTR); + write_exp_elt_opcode (ps, STRUCTOP_PTR); + write_exp_string (ps, token); + write_exp_elt_opcode (ps, STRUCTOP_PTR); token.ptr += token.length + 1; } if (i >= name.length) @@ -1289,7 +1305,8 @@ push_fieldnames (struct stoken name) Handle a qualified name, where DOT_INDEX is the index of the first '.' */ static void -push_qualified_expression_name (struct stoken name, int dot_index) +push_qualified_expression_name (struct parser_state *ps, struct stoken name, + int dot_index) { struct stoken token; char *tmp; @@ -1298,11 +1315,11 @@ push_qualified_expression_name (struct stoken name, int dot_index) token.ptr = name.ptr; token.length = dot_index; - if (push_variable (token)) + if (push_variable (ps, token)) { token.ptr = name.ptr + dot_index + 1; token.length = name.length - dot_index - 1; - push_fieldnames (token); + push_fieldnames (ps, token); return; } @@ -1316,9 +1333,9 @@ push_qualified_expression_name (struct stoken name, int dot_index) { if (dot_index == name.length) { - write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type(typ); - write_exp_elt_opcode(OP_TYPE); + write_exp_elt_opcode (ps, OP_TYPE); + write_exp_elt_type (ps, typ); + write_exp_elt_opcode (ps, OP_TYPE); return; } dot_index++; /* Skip '.' */ @@ -1329,16 +1346,16 @@ push_qualified_expression_name (struct stoken name, int dot_index) dot_index++; token.ptr = name.ptr; token.length = dot_index; - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (typ); - write_exp_string (token); - write_exp_elt_opcode (OP_SCOPE); + write_exp_elt_opcode (ps, OP_SCOPE); + write_exp_elt_type (ps, typ); + write_exp_string (ps, token); + write_exp_elt_opcode (ps, OP_SCOPE); if (dot_index < name.length) { dot_index++; name.ptr += dot_index; name.length -= dot_index; - push_fieldnames (name); + push_fieldnames (ps, name); } return; } @@ -1355,7 +1372,7 @@ push_qualified_expression_name (struct stoken name, int dot_index) Handle VAR, TYPE, TYPE.FIELD1....FIELDN and VAR.FIELD1....FIELDN. */ static void -push_expression_name (struct stoken name) +push_expression_name (struct parser_state *ps, struct stoken name) { char *tmp; struct type *typ; @@ -1366,22 +1383,22 @@ push_expression_name (struct stoken name) if (name.ptr[i] == '.') { /* It's a Qualified Expression Name. */ - push_qualified_expression_name (name, i); + push_qualified_expression_name (ps, name, i); return; } } /* It's a Simple Expression Name. */ - if (push_variable (name)) + if (push_variable (ps, name)) return; tmp = copy_name (name); typ = java_lookup_class (tmp); if (typ != NULL) { - write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type(typ); - write_exp_elt_opcode(OP_TYPE); + write_exp_elt_opcode (ps, OP_TYPE); + write_exp_elt_type (ps, typ); + write_exp_elt_opcode (ps, OP_TYPE); } else { @@ -1389,7 +1406,7 @@ push_expression_name (struct stoken name) msymbol = lookup_minimal_symbol (tmp, NULL, NULL); if (msymbol != NULL) - write_exp_msymbol (msymbol); + write_exp_msymbol (ps, msymbol); else if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"file\" command")); else @@ -1413,6 +1430,7 @@ copy_exp (struct expression *expr, int endpos) int len = length_of_subexp (expr, endpos); struct expression *new = (struct expression *) malloc (sizeof (*new) + EXP_ELEM_TO_BYTES (len)); + new->nelts = len; memcpy (new->elts, expr->elts + endpos - len, EXP_ELEM_TO_BYTES (len)); new->language_defn = 0; @@ -1422,27 +1440,20 @@ copy_exp (struct expression *expr, int endpos) /* Insert the expression NEW into the current expression (expout) at POS. */ static void -insert_exp (int pos, struct expression *new) +insert_exp (struct parser_state *ps, int pos, struct expression *new) { int newlen = new->nelts; + int i; + /* Grow expout if necessary. In this function's only use at present, this should never be necessary. */ - if (expout_ptr + newlen > expout_size) - { - expout_size = max (expout_size * 2, expout_ptr + newlen + 10); - expout = (struct expression *) - realloc ((char *) expout, (sizeof (struct expression) - + EXP_ELEM_TO_BYTES (expout_size))); - } + increase_expout_size (ps, newlen); - { - int i; - for (i = expout_ptr - 1; i >= pos; i--) - expout->elts[i + newlen] = expout->elts[i]; - } + for (i = ps->expout_ptr - 1; i >= pos; i--) + ps->expout->elts[i + newlen] = ps->expout->elts[i]; - memcpy (expout->elts + pos, new->elts, EXP_ELEM_TO_BYTES (newlen)); - expout_ptr += newlen; + memcpy (ps->expout->elts + pos, new->elts, EXP_ELEM_TO_BYTES (newlen)); + ps->expout_ptr += newlen; } diff --git a/gdb/jv-lang.h b/gdb/jv-lang.h index 4344706..d34c803 100644 --- a/gdb/jv-lang.h +++ b/gdb/jv-lang.h @@ -22,10 +22,12 @@ #define JV_LANG_H struct value; +struct parser_state; -extern int java_parse (void); /* Defined in jv-exp.y */ +extern int java_parse (struct parser_state *); /* Defined in jv-exp.y */ -extern void java_error (char *); /* Defined in jv-exp.y */ +extern void java_error (struct parser_state *, char *); /* Defined + in jv-exp.y */ struct builtin_java_type {