From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2N7CF/qY718XTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:46 -0500 Received: by simark.ca (Postfix, from userid 112) id 5F1AF1F0CC; Fri, 1 Jan 2021 16:49:46 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A19CE1F0C3 for ; Fri, 1 Jan 2021 16:49:36 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C16E43939C36; Fri, 1 Jan 2021 21:49:04 +0000 (GMT) Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.187.5]) by sourceware.org (Postfix) with ESMTPS id EEDBC3938C3D for ; Fri, 1 Jan 2021 21:48:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EEDBC3938C3D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 95E01400C8F64 for ; Fri, 1 Jan 2021 15:48:58 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSI6kyOfPsvw9vSI6kLufv; Fri, 01 Jan 2021 15:48:58 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1N55CpPrTzexWphyfELc0RCMj4/YphRMNwNO3e6eLf8=; b=GF3Q0MmnZYrLPc0qCg1kO45/aR nUuJ39Mopt6n6a5n4rvCdZue5GXVbl4RR/kmlCVjQ2Sx4PeCNroJ7YvOu3omLkFBr063UJNODhdj2 MC3yftlz7dvX/hlyZ2E+oJGsg; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60426 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kvSI6-0029zC-Dn for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:58 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 183/203] Convert f-exp.y to use operations Date: Fri, 1 Jan 2021 14:47:03 -0700 Message-Id: <20210101214723.1784144-184-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210101214723.1784144-1-tom@tromey.com> References: <20210101214723.1784144-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.81.39 X-Source-L: No X-Exim-ID: 1kvSI6-0029zC-Dn X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60426 X-Source-Auth: tom+tromey.com X-Email-Count: 184 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This converts the Fortran parser to generate operations rather than exp_elements. gdb/ChangeLog 2021-01-01 Tom Tromey * f-exp.y: Create operations. (f_language::parser): Update. --- gdb/ChangeLog | 5 + gdb/f-exp.y | 322 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 198 insertions(+), 129 deletions(-) diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 6001e77060b..3aee19facce 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -55,6 +55,7 @@ #include #include #include "type-stack.h" +#include "f-exp.h" #define parse_type(ps) builtin_type (ps->gdbarch ()) #define parse_f_type(ps) builtin_f_type (ps->gdbarch ()) @@ -89,6 +90,7 @@ static void push_kind_type (LONGEST val, struct type *type); static struct type *convert_to_kind_type (struct type *basetype, int kind); +using namespace expr; %} /* Although the yacc "value" of an expression is not used, @@ -208,9 +210,7 @@ start : exp ; type_exp: type - { write_exp_elt_opcode (pstate, OP_TYPE); - write_exp_elt_type (pstate, $1); - write_exp_elt_opcode (pstate, OP_TYPE); } + { pstate->push_new ($1); } ; exp : '(' exp ')' @@ -219,31 +219,31 @@ exp : '(' exp ')' /* Expressions, not including the comma operator. */ exp : '*' exp %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_IND); } + { pstate->wrap (); } ; exp : '&' exp %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_ADDR); } + { pstate->wrap (); } ; exp : '-' exp %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_NEG); } + { pstate->wrap (); } ; exp : BOOL_NOT exp %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); } + { pstate->wrap (); } ; exp : '~' exp %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); } + { pstate->wrap (); } ; exp : SIZEOF exp %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_SIZEOF); } + { pstate->wrap (); } ; exp : KIND '(' exp ')' %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_FORTRAN_KIND); } + { pstate->wrap (); } ; /* No more explicit array operators, we treat everything in F77 as @@ -254,20 +254,50 @@ exp : KIND '(' exp ')' %prec UNARY exp : exp '(' { pstate->start_arglist (); } arglist ')' - { write_exp_elt_opcode (pstate, - OP_F77_UNDETERMINED_ARGLIST); - write_exp_elt_longcst (pstate, - pstate->end_arglist ()); - write_exp_elt_opcode (pstate, - OP_F77_UNDETERMINED_ARGLIST); } + { + std::vector args + = pstate->pop_vector (pstate->end_arglist ()); + pstate->push_new + (pstate->pop (), std::move (args)); + } ; exp : UNOP_INTRINSIC '(' exp ')' - { write_exp_elt_opcode (pstate, $1); } + { + switch ($1) + { + case UNOP_ABS: + pstate->wrap (); + break; + case UNOP_FORTRAN_FLOOR: + pstate->wrap (); + break; + case UNOP_FORTRAN_CEILING: + pstate->wrap (); + break; + default: + gdb_assert_not_reached ("unhandled intrinsic"); + } + } ; exp : BINOP_INTRINSIC '(' exp ',' exp ')' - { write_exp_elt_opcode (pstate, $1); } + { + switch ($1) + { + case BINOP_MOD: + pstate->wrap2 (); + break; + case BINOP_FORTRAN_MODULO: + pstate->wrap2 (); + break; + case BINOP_FORTRAN_CMPLX: + pstate->wrap2 (); + break; + default: + gdb_assert_not_reached ("unhandled intrinsic"); + } + } ; arglist : @@ -292,63 +322,90 @@ arglist : arglist ',' subrange %prec ABOVE_COMMA /* There are four sorts of subrange types in F90. */ subrange: exp ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, RANGE_STANDARD); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + operation_up high = pstate->pop (); + operation_up low = pstate->pop (); + pstate->push_new + (RANGE_STANDARD, std::move (low), + std::move (high), operation_up ()); + } ; subrange: exp ':' %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, - RANGE_HIGH_BOUND_DEFAULT); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + operation_up low = pstate->pop (); + pstate->push_new + (RANGE_HIGH_BOUND_DEFAULT, std::move (low), + operation_up (), operation_up ()); + } ; subrange: ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, - RANGE_LOW_BOUND_DEFAULT); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + operation_up high = pstate->pop (); + pstate->push_new + (RANGE_LOW_BOUND_DEFAULT, operation_up (), + std::move (high), operation_up ()); + } ; subrange: ':' %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, - (RANGE_LOW_BOUND_DEFAULT - | RANGE_HIGH_BOUND_DEFAULT)); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + pstate->push_new + (RANGE_LOW_BOUND_DEFAULT + | RANGE_HIGH_BOUND_DEFAULT, + operation_up (), operation_up (), + operation_up ()); + } ; /* And each of the four subrange types can also have a stride. */ subrange: exp ':' exp ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, RANGE_HAS_STRIDE); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + operation_up stride = pstate->pop (); + operation_up high = pstate->pop (); + operation_up low = pstate->pop (); + pstate->push_new + (RANGE_STANDARD | RANGE_HAS_STRIDE, + std::move (low), std::move (high), + std::move (stride)); + } ; subrange: exp ':' ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, - (RANGE_HIGH_BOUND_DEFAULT - | RANGE_HAS_STRIDE)); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + operation_up stride = pstate->pop (); + operation_up low = pstate->pop (); + pstate->push_new + (RANGE_HIGH_BOUND_DEFAULT + | RANGE_HAS_STRIDE, + std::move (low), operation_up (), + std::move (stride)); + } ; subrange: ':' exp ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, - (RANGE_LOW_BOUND_DEFAULT - | RANGE_HAS_STRIDE)); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + operation_up stride = pstate->pop (); + operation_up high = pstate->pop (); + pstate->push_new + (RANGE_LOW_BOUND_DEFAULT + | RANGE_HAS_STRIDE, + operation_up (), std::move (high), + std::move (stride)); + } ; subrange: ':' ':' exp %prec ABOVE_COMMA - { write_exp_elt_opcode (pstate, OP_RANGE); - write_exp_elt_longcst (pstate, - (RANGE_LOW_BOUND_DEFAULT - | RANGE_HIGH_BOUND_DEFAULT - | RANGE_HAS_STRIDE)); - write_exp_elt_opcode (pstate, OP_RANGE); } + { + operation_up stride = pstate->pop (); + pstate->push_new + (RANGE_LOW_BOUND_DEFAULT + | RANGE_HIGH_BOUND_DEFAULT + | RANGE_HAS_STRIDE, + operation_up (), operation_up (), + std::move (stride)); + } ; complexnum: exp ',' exp @@ -356,193 +413,197 @@ complexnum: exp ',' exp ; exp : '(' complexnum ')' - { write_exp_elt_opcode (pstate, OP_COMPLEX); - write_exp_elt_type (pstate, - parse_f_type (pstate) - ->builtin_complex_s16); - write_exp_elt_opcode (pstate, OP_COMPLEX); } + { + operation_up rhs = pstate->pop (); + operation_up lhs = pstate->pop (); + pstate->push_new + (std::move (lhs), std::move (rhs), + parse_f_type (pstate)->builtin_complex_s16); + } ; exp : '(' type ')' exp %prec UNARY - { write_exp_elt_opcode (pstate, UNOP_CAST); - write_exp_elt_type (pstate, $2); - write_exp_elt_opcode (pstate, UNOP_CAST); } + { + pstate->push_new + (pstate->pop (), $2); + } ; exp : exp '%' name - { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); - write_exp_string (pstate, $3); - write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } + { + pstate->push_new + (pstate->pop (), copy_name ($3)); + } ; exp : exp '%' name COMPLETE - { pstate->mark_struct_expression (); - write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); - write_exp_string (pstate, $3); - write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); } + { + structop_base_operation *op + = new structop_operation (pstate->pop (), + copy_name ($3)); + pstate->mark_struct_expression (op); + pstate->push (operation_up (op)); + } ; exp : exp '%' COMPLETE - { struct stoken s; - pstate->mark_struct_expression (); - write_exp_elt_opcode (pstate, STRUCTOP_PTR); - s.ptr = ""; - s.length = 0; - write_exp_string (pstate, s); - write_exp_elt_opcode (pstate, STRUCTOP_PTR); } + { + structop_base_operation *op + = new structop_operation (pstate->pop (), ""); + pstate->mark_struct_expression (op); + pstate->push (operation_up (op)); + } + ; /* Binary operators in order of decreasing precedence. */ exp : exp '@' exp - { write_exp_elt_opcode (pstate, BINOP_REPEAT); } + { pstate->wrap2 (); } ; exp : exp STARSTAR exp - { write_exp_elt_opcode (pstate, BINOP_EXP); } + { pstate->wrap2 (); } ; exp : exp '*' exp - { write_exp_elt_opcode (pstate, BINOP_MUL); } + { pstate->wrap2 (); } ; exp : exp '/' exp - { write_exp_elt_opcode (pstate, BINOP_DIV); } + { pstate->wrap2 (); } ; exp : exp '+' exp - { write_exp_elt_opcode (pstate, BINOP_ADD); } + { pstate->wrap2 (); } ; exp : exp '-' exp - { write_exp_elt_opcode (pstate, BINOP_SUB); } + { pstate->wrap2 (); } ; exp : exp LSH exp - { write_exp_elt_opcode (pstate, BINOP_LSH); } + { pstate->wrap2 (); } ; exp : exp RSH exp - { write_exp_elt_opcode (pstate, BINOP_RSH); } + { pstate->wrap2 (); } ; exp : exp EQUAL exp - { write_exp_elt_opcode (pstate, BINOP_EQUAL); } + { pstate->wrap2 (); } ; exp : exp NOTEQUAL exp - { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); } + { pstate->wrap2 (); } ; exp : exp LEQ exp - { write_exp_elt_opcode (pstate, BINOP_LEQ); } + { pstate->wrap2 (); } ; exp : exp GEQ exp - { write_exp_elt_opcode (pstate, BINOP_GEQ); } + { pstate->wrap2 (); } ; exp : exp LESSTHAN exp - { write_exp_elt_opcode (pstate, BINOP_LESS); } + { pstate->wrap2 (); } ; exp : exp GREATERTHAN exp - { write_exp_elt_opcode (pstate, BINOP_GTR); } + { pstate->wrap2 (); } ; exp : exp '&' exp - { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); } + { pstate->wrap2 (); } ; exp : exp '^' exp - { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); } + { pstate->wrap2 (); } ; exp : exp '|' exp - { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); } + { pstate->wrap2 (); } ; exp : exp BOOL_AND exp - { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); } + { pstate->wrap2 (); } ; exp : exp BOOL_OR exp - { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); } + { pstate->wrap2 (); } ; exp : exp '=' exp - { write_exp_elt_opcode (pstate, BINOP_ASSIGN); } + { pstate->wrap2 (); } ; exp : exp ASSIGN_MODIFY exp - { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode (pstate, $2); - write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); } + { + operation_up rhs = pstate->pop (); + operation_up lhs = pstate->pop (); + pstate->push_new + ($2, std::move (lhs), std::move (rhs)); + } ; exp : INT - { write_exp_elt_opcode (pstate, OP_LONG); - write_exp_elt_type (pstate, $1.type); - write_exp_elt_longcst (pstate, (LONGEST) ($1.val)); - write_exp_elt_opcode (pstate, OP_LONG); } + { + pstate->push_new + ($1.type, $1.val); + } ; exp : NAME_OR_INT { YYSTYPE val; parse_number (pstate, $1.stoken.ptr, $1.stoken.length, 0, &val); - write_exp_elt_opcode (pstate, OP_LONG); - write_exp_elt_type (pstate, val.typed_val.type); - write_exp_elt_longcst (pstate, - (LONGEST)val.typed_val.val); - write_exp_elt_opcode (pstate, OP_LONG); } + pstate->push_new + (val.typed_val.type, + val.typed_val.val); + } ; exp : FLOAT - { write_exp_elt_opcode (pstate, OP_FLOAT); - write_exp_elt_type (pstate, $1.type); - write_exp_elt_floatcst (pstate, $1.val); - write_exp_elt_opcode (pstate, OP_FLOAT); } + { + float_data data; + std::copy (std::begin ($1.val), std::end ($1.val), + std::begin (data)); + pstate->push_new ($1.type, data); + } ; exp : variable ; exp : DOLLAR_VARIABLE - { write_dollar_variable (pstate, $1); } + { pstate->push_dollar ($1); } ; exp : SIZEOF '(' type ')' %prec UNARY - { write_exp_elt_opcode (pstate, OP_LONG); - write_exp_elt_type (pstate, - parse_f_type (pstate) - ->builtin_integer); + { $3 = check_typedef ($3); - write_exp_elt_longcst (pstate, - (LONGEST) TYPE_LENGTH ($3)); - write_exp_elt_opcode (pstate, OP_LONG); } + pstate->push_new + (parse_f_type (pstate)->builtin_integer, + TYPE_LENGTH ($3)); + } ; exp : BOOLEAN_LITERAL - { write_exp_elt_opcode (pstate, OP_BOOL); - write_exp_elt_longcst (pstate, (LONGEST) $1); - write_exp_elt_opcode (pstate, OP_BOOL); - } + { pstate->push_new ($1); } ; exp : STRING_LITERAL { - write_exp_elt_opcode (pstate, OP_STRING); - write_exp_string (pstate, $1); - write_exp_elt_opcode (pstate, OP_STRING); + pstate->push_new + (copy_name ($1)); } ; variable: name_not_typename { struct block_symbol sym = $1.sym; std::string name = copy_name ($1.stoken); - write_exp_symbol_reference (pstate, name.c_str (), - sym.symbol); + pstate->push_symbol (name.c_str (), sym.symbol); } ; @@ -1415,7 +1476,10 @@ f_language::parser (struct parser_state *par_state) const scoped_restore restore_type_stack = make_scoped_restore (&type_stack, &stack); - return yyparse (); + int result = yyparse (); + if (!result) + pstate->set_operation (pstate->pop ()); + return result; } static void -- 2.26.2