From patchwork Sat Jan 5 20:41:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30969 Received: (qmail 95181 invoked by alias); 5 Jan 2019 20:41:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95030 invoked by uid 89); 5 Jan 2019 20:41:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:y, onto, elt, piece X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.38) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 05 Jan 2019 20:41:16 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 4BD07142C3 for ; Sat, 5 Jan 2019 14:41:15 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id fsksg659Q2PzOfsksglXey; Sat, 05 Jan 2019 14:41:15 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=DC7NUHxknXi/wVKbrfMwc74kPko2cH/mb9DWLxFw7N4=; b=fd1s382aQExwRo2FzBFKgxLzz7 QbFIYWkRd/wK/iqTFGB/N91+Do1dB3NwnpjuyTTNB+njjTk89XTYsFTjkc6NTRBuLZZiITsQz0utM DalIIYUJ6WT+FI8oZr2HNBMjg; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:34446 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gfsks-000OXk-NR; Sat, 05 Jan 2019 14:41:14 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] Use std::vector in type stacks Date: Sat, 5 Jan 2019 13:41:10 -0700 Message-Id: <20190105204112.26849-2-tom@tromey.com> In-Reply-To: <20190105204112.26849-1-tom@tromey.com> References: <20190105204112.26849-1-tom@tromey.com> This removes the use of VEC from parse.c and, at the same time, removes some related cleanups from c-exp.y. gdb/ChangeLog 2019-01-05 Tom Tromey * parser-defs.h (type_ptr): Remove typedef. Don't declare VEC. (union type_stack_elt) : Now a pointer to std::vector. (type_stack_cleanup): Don't declare. (push_typelist): Update. * parse.c (pop_typelist): Return a std::vector. (push_typelist): Take a std::vector. (follow_types): Update. Do not free args. (type_stack_cleanup): Remove. * c-exp.y (struct c_parse_state): New. (cpstate): New global. (type_aggregate_p, exp, ptr_operator, parameter_typelist) (nonempty_typelist): Update. (func_mod): Create a new vector. (c_parse): Create a c_parse_state. (check_parameter_typelist): Do not delete params. (function_method): Update. Do not delete type_list. --- gdb/ChangeLog | 20 ++++++++++++++ gdb/c-exp.y | 66 ++++++++++++++++++++++++++++------------------- gdb/parse.c | 24 +++++------------ gdb/parser-defs.h | 9 ++----- 4 files changed, 68 insertions(+), 51 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 3078702b75..eb6a6847cf 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -66,6 +66,20 @@ static struct parser_state *pstate = NULL; +/* Data that must be held for the duration of a parse. */ + +struct c_parse_state +{ + /* These are used to hold type lists and type stacks that are + allocated during the parse. */ + std::vector>> type_lists; + std::vector> type_stacks; +}; + +/* This is set and cleared in c_parse. */ + +static struct c_parse_state *cpstate; + int yyparse (void); static int yylex (void); @@ -101,7 +115,7 @@ static int type_aggregate_p (struct type *); enum exp_opcode opcode; struct stoken_vector svec; - VEC (type_ptr) *tvec; + std::vector *tvec; struct type_stack *type_stack; @@ -114,7 +128,7 @@ static int parse_number (struct parser_state *par_state, const char *, int, int, YYSTYPE *); static struct stoken operator_stoken (const char *); static struct stoken typename_stoken (const char *); -static void check_parameter_typelist (VEC (type_ptr) *); +static void check_parameter_typelist (std::vector *); static void write_destructor_name (struct parser_state *par_state, struct stoken); @@ -552,10 +566,9 @@ arglist : arglist ',' exp %prec ABOVE_COMMA ; function_method: exp '(' parameter_typelist ')' const_or_volatile - { int i; - VEC (type_ptr) *type_list = $3; - struct type *type_elt; - LONGEST len = VEC_length (type_ptr, type_list); + { + std::vector *type_list = $3; + LONGEST len = type_list->size (); write_exp_elt_opcode (pstate, TYPE_INSTANCE); /* Save the const/volatile qualifiers as @@ -564,13 +577,10 @@ function_method: exp '(' parameter_typelist ')' const_or_volatile write_exp_elt_longcst (pstate, follow_type_instance_flags ()); write_exp_elt_longcst (pstate, len); - for (i = 0; - VEC_iterate (type_ptr, type_list, i, type_elt); - ++i) + for (type *type_elt : *type_list) write_exp_elt_type (pstate, type_elt); write_exp_elt_longcst(pstate, len); write_exp_elt_opcode (pstate, TYPE_INSTANCE); - VEC_free (type_ptr, type_list); } ; @@ -1157,9 +1167,7 @@ ptr_operator: ptr_operator_ts: ptr_operator { $$ = get_type_stack (); - /* This cleanup is eventually run by - c_parse. */ - make_cleanup (type_stack_cleanup, $$); + cpstate->type_stacks.emplace_back ($$); } ; @@ -1209,7 +1217,10 @@ array_mod: '[' ']' ; func_mod: '(' ')' - { $$ = NULL; } + { + $$ = new std::vector; + cpstate->type_lists.emplace_back ($$); + } | '(' parameter_typelist ')' { $$ = $2; } ; @@ -1471,7 +1482,7 @@ parameter_typelist: { check_parameter_typelist ($1); } | nonempty_typelist ',' DOTDOTDOT { - VEC_safe_push (type_ptr, $1, NULL); + $1->push_back (NULL); check_parameter_typelist ($1); $$ = $1; } @@ -1480,13 +1491,16 @@ parameter_typelist: nonempty_typelist : type { - VEC (type_ptr) *typelist = NULL; - VEC_safe_push (type_ptr, typelist, $1); + std::vector *typelist = + new std::vector; + cpstate->type_lists.emplace_back (typelist); + + typelist->push_back ($1); $$ = typelist; } | nonempty_typelist ',' type { - VEC_safe_push (type_ptr, $1, $3); + $1->push_back ($3); $$ = $1; } ; @@ -1758,30 +1772,27 @@ type_aggregate_p (struct type *type) /* Validate a parameter typelist. */ static void -check_parameter_typelist (VEC (type_ptr) *params) +check_parameter_typelist (std::vector *params) { struct type *type; int ix; - for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix) + for (ix = 0; ix < params->size (); ++ix) { + type = (*params)[ix]; if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID) { if (ix == 0) { - if (VEC_length (type_ptr, params) == 1) + if (params->size () == 1) { /* Ok. */ break; } - VEC_free (type_ptr, params); error (_("parameter types following 'void'")); } else - { - VEC_free (type_ptr, params); - error (_("'void' invalid as parameter type")); - } + error (_("'void' invalid as parameter type")); } } } @@ -3276,6 +3287,9 @@ c_parse (struct parser_state *par_state) gdb_assert (par_state != NULL); pstate = par_state; + c_parse_state cstate; + scoped_restore cstate_resotre = make_scoped_restore (&cpstate, &cstate); + gdb::unique_xmalloc_ptr macro_scope; if (expression_context_block) diff --git a/gdb/parse.c b/gdb/parse.c index de2d53b9de..e7168acf7a 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -1457,7 +1457,7 @@ pop_type_int (void) /* Pop a type list element from the global type stack. */ -static VEC (type_ptr) * +static std::vector * pop_typelist (void) { gdb_assert (!type_stack.elements.empty ()); @@ -1501,7 +1501,7 @@ push_type_stack (struct type_stack *stack) /* Copy the global type stack into a newly allocated type stack and return it. The global stack is cleared. The returned type stack - must be freed with type_stack_cleanup. */ + must be freed with delete. */ struct type_stack * get_type_stack (void) @@ -1511,22 +1511,12 @@ get_type_stack (void) return result; } -/* A cleanup function that destroys a single type stack. */ - -void -type_stack_cleanup (void *arg) -{ - struct type_stack *stack = (struct type_stack *) arg; - - delete stack; -} - /* Push a function type with arguments onto the global type stack. LIST holds the argument types. If the final item in LIST is NULL, then the function will be varargs. */ void -push_typelist (VEC (type_ptr) *list) +push_typelist (std::vector *list) { type_stack_elt elt; elt.typelist_val = list; @@ -1655,14 +1645,12 @@ follow_types (struct type *follow_type) case tp_function_with_arguments: { - VEC (type_ptr) *args = pop_typelist (); + std::vector *args = pop_typelist (); follow_type = lookup_function_type_with_arguments (follow_type, - VEC_length (type_ptr, args), - VEC_address (type_ptr, - args)); - VEC_free (type_ptr, args); + args->size (), + args->data ()); } break; diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 195264f48a..5b38477895 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -200,9 +200,6 @@ struct objc_class_str int theclass; }; -typedef struct type *type_ptr; -DEF_VEC_P (type_ptr); - /* For parsing of complicated types. An array should be preceded in the list by the size of the array. */ enum type_pieces @@ -225,7 +222,7 @@ union type_stack_elt enum type_pieces piece; int int_val; struct type_stack *stack_val; - VEC (type_ptr) *typelist_val; + std::vector *typelist_val; }; /* The type stack is an instance of this structure. */ @@ -303,9 +300,7 @@ extern struct type_stack *append_type_stack (struct type_stack *to, extern void push_type_stack (struct type_stack *stack); -extern void type_stack_cleanup (void *arg); - -extern void push_typelist (VEC (type_ptr) *typelist); +extern void push_typelist (std::vector *typelist); extern int dump_subexp (struct expression *, struct ui_file *, int);