From patchwork Tue Jul 24 01:55:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28579 Received: (qmail 104990 invoked by alias); 24 Jul 2018 01:55:42 -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 104891 invoked by uid 89); 24 Jul 2018 01:55:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, 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=alternating, classification X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.130) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Jul 2018 01:55:32 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 02BDD1556AD for ; Mon, 23 Jul 2018 20:55:31 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id hmXlf1TwFbXuJhmXtf8Hde; Mon, 23 Jul 2018 20:55:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=LFlwifa/35GrQsQttZ2i40A8A78cUuilG0gMD+adKZI=; b=ibwfNa5JviBVcATrIrENVacaCi /u/TUwfFp9Em9VaS77gUtaBrijWNalTCRtCqQIrhLBsVeObP3zUNlyLDZQy96PlkiVSw1PE+wR4NK SWDWoX6VLYOqIcfAdZmvEBLzk; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:37292 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fhmXl-003eSw-Fz; Mon, 23 Jul 2018 20:55:17 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Remove some uses of VEC Date: Mon, 23 Jul 2018 19:55:13 -0600 Message-Id: <20180724015513.14260-1-tom@tromey.com> This changes a few uses of VEC to std::vector instead. Tested by the buildbot. gdb/ChangeLog 2018-07-23 Tom Tromey * c-exp.y (struct token_and_value): Remove typedef and DEF_VEC. (token_fifo): Now a std::vector. (yylex, c_parse): Update. * d-exp.y (struct token_and_value): Remove typedef and DEF_VEC. (token_fifo): Now a std::vector. (yylex, d_parse): Update. * go-exp.y (struct token_and_value): Remove typedef and DEF_VEC. (token_fifo): Now a std::vector. (yylex, go_parse): Update. --- gdb/ChangeLog | 12 ++++++++++++ gdb/c-exp.y | 43 ++++++++++++++++++++--------------------- gdb/d-exp.y | 62 +++++++++++++++++++++++++++++------------------------------ gdb/go-exp.y | 22 ++++++++++----------- 4 files changed, 74 insertions(+), 65 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index a9ccbdcb65e..0326ee090e1 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2854,17 +2854,15 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) } /* An object of this type is pushed on a FIFO by the "outer" lexer. */ -typedef struct +struct token_and_value { int token; YYSTYPE value; -} token_and_value; - -DEF_VEC_O (token_and_value); +}; /* A FIFO of tokens that have been read but not yet returned to the parser. */ -static VEC (token_and_value) *token_fifo; +static std::vector token_fifo; /* Non-zero if the lexer should return tokens from the FIFO. */ static int popping; @@ -3089,7 +3087,7 @@ yylex (void) const struct block *search_block; bool is_quoted_name, last_lex_was_structop; - if (popping && !VEC_empty (token_and_value, token_fifo)) + if (popping && !token_fifo.empty ()) goto do_pop; popping = 0; @@ -3110,7 +3108,7 @@ yylex (void) /* Read any sequence of alternating "::" and name-like tokens into the token FIFO. */ current.value = yylval; - VEC_safe_push (token_and_value, token_fifo, ¤t); + token_fifo.push_back (current); last_was_coloncolon = current.token == COLONCOLON; while (1) { @@ -3120,7 +3118,7 @@ yylex (void) Subsequent ones do not have any special meaning. */ current.token = lex_one_token (pstate, &ignore); current.value = yylval; - VEC_safe_push (token_and_value, token_fifo, ¤t); + token_fifo.push_back (current); if ((last_was_coloncolon && current.token != NAME) || (!last_was_coloncolon && current.token != COLONCOLON)) @@ -3131,10 +3129,10 @@ yylex (void) /* We always read one extra token, so compute the number of tokens to examine accordingly. */ - last_to_examine = VEC_length (token_and_value, token_fifo) - 2; + last_to_examine = token_fifo.size () - 2; next_to_examine = 0; - current = *VEC_index (token_and_value, token_fifo, next_to_examine); + current = token_fifo[next_to_examine]; ++next_to_examine; name_obstack.clear (); @@ -3158,16 +3156,16 @@ yylex (void) while (next_to_examine <= last_to_examine) { - token_and_value *next; + token_and_value next; - next = VEC_index (token_and_value, token_fifo, next_to_examine); + next = token_fifo[next_to_examine]; ++next_to_examine; - if (next->token == NAME && last_was_coloncolon) + if (next.token == NAME && last_was_coloncolon) { int classification; - yylval = next->value; + yylval = next.value; classification = classify_inner_name (pstate, search_block, context_type); /* We keep going until we either run out of names, or until @@ -3184,8 +3182,8 @@ yylex (void) /* We don't want to put a leading "::" into the name. */ obstack_grow_str (&name_obstack, "::"); } - obstack_grow (&name_obstack, next->value.sval.ptr, - next->value.sval.length); + obstack_grow (&name_obstack, next.value.sval.ptr, + next.value.sval.length); yylval.sval.ptr = (const char *) obstack_base (&name_obstack); yylval.sval.length = obstack_object_size (&name_obstack); @@ -3199,7 +3197,7 @@ yylex (void) context_type = yylval.tsym.type; } - else if (next->token == COLONCOLON && !last_was_coloncolon) + else if (next.token == COLONCOLON && !last_was_coloncolon) last_was_coloncolon = 1; else { @@ -3217,14 +3215,15 @@ yylex (void) current.value.sval.ptr, current.value.sval.length); - VEC_replace (token_and_value, token_fifo, 0, ¤t); + token_fifo[0] = current; if (checkpoint > 1) - VEC_block_remove (token_and_value, token_fifo, 1, checkpoint - 1); + token_fifo.erase (token_fifo.begin () + 1, + token_fifo.begin () + checkpoint); } do_pop: - current = *VEC_index (token_and_value, token_fifo, 0); - VEC_ordered_remove (token_and_value, token_fifo, 0); + current = token_fifo[0]; + token_fifo.erase (token_fifo.begin ()); yylval = current.value; return current.token; } @@ -3266,7 +3265,7 @@ c_parse (struct parser_state *par_state) last_was_structop = false; saw_name_at_eof = 0; - VEC_free (token_and_value, token_fifo); + token_fifo.clear (); popping = 0; name_obstack.clear (); diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 74e4b637d0d..c09fe7a3f36 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -1313,17 +1313,16 @@ lex_one_token (struct parser_state *par_state) } /* An object of this type is pushed on a FIFO by the "outer" lexer. */ -typedef struct +struct token_and_value { int token; YYSTYPE value; -} token_and_value; +}; -DEF_VEC_O (token_and_value); /* A FIFO of tokens that have been read but not yet returned to the parser. */ -static VEC (token_and_value) *token_fifo; +static std::vector token_fifo; /* Non-zero if the lexer should return tokens from the FIFO. */ static int popping; @@ -1419,7 +1418,7 @@ yylex (void) int last_to_examine, next_to_examine, checkpoint; const struct block *search_block; - if (popping && !VEC_empty (token_and_value, token_fifo)) + if (popping && !token_fifo.empty ()) goto do_pop; popping = 0; @@ -1431,14 +1430,14 @@ yylex (void) /* Read any sequence of alternating "." and identifier tokens into the token FIFO. */ current.value = yylval; - VEC_safe_push (token_and_value, token_fifo, ¤t); + token_fifo.push_back (current); last_was_dot = current.token == '.'; while (1) { current.token = lex_one_token (pstate); current.value = yylval; - VEC_safe_push (token_and_value, token_fifo, ¤t); + token_fifo.push_back (current); if ((last_was_dot && current.token != IDENTIFIER) || (!last_was_dot && current.token != '.')) @@ -1450,10 +1449,10 @@ yylex (void) /* We always read one extra token, so compute the number of tokens to examine accordingly. */ - last_to_examine = VEC_length (token_and_value, token_fifo) - 2; + last_to_examine = token_fifo.size () - 2; next_to_examine = 0; - current = *VEC_index (token_and_value, token_fifo, next_to_examine); + current = token_fifo[next_to_examine]; ++next_to_examine; /* If we are not dealing with a typename, now is the time to find out. */ @@ -1476,17 +1475,17 @@ yylex (void) while (next_to_examine <= last_to_examine) { - token_and_value *next; + token_and_value next; - next = VEC_index (token_and_value, token_fifo, next_to_examine); + next = token_fifo[next_to_examine]; ++next_to_examine; - if (next->token == IDENTIFIER && last_was_dot) + if (next.token == IDENTIFIER && last_was_dot) { /* Update the partial name we are constructing. */ obstack_grow_str (&name_obstack, "."); - obstack_grow (&name_obstack, next->value.sval.ptr, - next->value.sval.length); + obstack_grow (&name_obstack, next.value.sval.ptr, + next.value.sval.length); yylval.sval.ptr = (char *) obstack_base (&name_obstack); yylval.sval.length = obstack_object_size (&name_obstack); @@ -1498,13 +1497,13 @@ yylex (void) if (current.token == TYPENAME) { /* Install it as the first token in the FIFO. */ - VEC_replace (token_and_value, token_fifo, 0, ¤t); - VEC_block_remove (token_and_value, token_fifo, 1, - next_to_examine - 1); + token_fifo[0] = current; + token_fifo.erase (token_fifo.begin () + 1, + token_fifo.begin () + next_to_examine); break; } } - else if (next->token == '.' && !last_was_dot) + else if (next.token == '.' && !last_was_dot) last_was_dot = 1; else { @@ -1515,7 +1514,7 @@ yylex (void) /* Reset our current token back to the start, if we found nothing this means that we will just jump to do pop. */ - current = *VEC_index (token_and_value, token_fifo, 0); + current = token_fifo[0]; next_to_examine = 1; } if (current.token != TYPENAME && current.token != '.') @@ -1539,16 +1538,16 @@ yylex (void) while (next_to_examine <= last_to_examine) { - token_and_value *next; + token_and_value next; - next = VEC_index (token_and_value, token_fifo, next_to_examine); + next = token_fifo[next_to_examine]; ++next_to_examine; - if (next->token == IDENTIFIER && last_was_dot) + if (next.token == IDENTIFIER && last_was_dot) { int classification; - yylval = next->value; + yylval = next.value; classification = classify_inner_name (pstate, search_block, context_type); /* We keep going until we either run out of names, or until @@ -1565,8 +1564,8 @@ yylex (void) /* We don't want to put a leading "." into the name. */ obstack_grow_str (&name_obstack, "."); } - obstack_grow (&name_obstack, next->value.sval.ptr, - next->value.sval.length); + obstack_grow (&name_obstack, next.value.sval.ptr, + next.value.sval.length); yylval.sval.ptr = (char *) obstack_base (&name_obstack); yylval.sval.length = obstack_object_size (&name_obstack); @@ -1580,7 +1579,7 @@ yylex (void) context_type = yylval.tsym.type; } - else if (next->token == '.' && !last_was_dot) + else if (next.token == '.' && !last_was_dot) last_was_dot = 1; else { @@ -1593,14 +1592,15 @@ yylex (void) the FIFO, and delete the other constituent tokens. */ if (checkpoint > 0) { - VEC_replace (token_and_value, token_fifo, 0, ¤t); + token_fifo[0] = current; if (checkpoint > 1) - VEC_block_remove (token_and_value, token_fifo, 1, checkpoint - 1); + token_fifo.erase (token_fifo.begin () + 1, + token_fifo.begin () + checkpoint); } do_pop: - current = *VEC_index (token_and_value, token_fifo, 0); - VEC_ordered_remove (token_and_value, token_fifo, 0); + current = token_fifo[0]; + token_fifo.erase (token_fifo.begin ()); yylval = current.value; return current.token; } @@ -1620,7 +1620,7 @@ d_parse (struct parser_state *par_state) last_was_structop = 0; saw_name_at_eof = 0; - VEC_free (token_and_value, token_fifo); + token_fifo.clear (); popping = 0; name_obstack.clear (); diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 47570d59111..a2436145491 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -1279,17 +1279,15 @@ lex_one_token (struct parser_state *par_state) } /* An object of this type is pushed on a FIFO by the "outer" lexer. */ -typedef struct +struct token_and_value { int token; YYSTYPE value; -} token_and_value; - -DEF_VEC_O (token_and_value); +}; /* A FIFO of tokens that have been read but not yet returned to the parser. */ -static VEC (token_and_value) *token_fifo; +static std::vector token_fifo; /* Non-zero if the lexer should return tokens from the FIFO. */ static int popping; @@ -1485,10 +1483,10 @@ yylex (void) { token_and_value current, next; - if (popping && !VEC_empty (token_and_value, token_fifo)) + if (popping && !token_fifo.empty ()) { - token_and_value tv = *VEC_index (token_and_value, token_fifo, 0); - VEC_ordered_remove (token_and_value, token_fifo, 0); + token_and_value tv = token_fifo[0]; + token_fifo.erase (token_fifo.begin ()); yylval = tv.value; /* There's no need to fall through to handle package.name as that can never happen here. In theory. */ @@ -1541,12 +1539,12 @@ yylex (void) } } - VEC_safe_push (token_and_value, token_fifo, &next); - VEC_safe_push (token_and_value, token_fifo, &name2); + token_fifo.push_back (next); + token_fifo.push_back (name2); } else { - VEC_safe_push (token_and_value, token_fifo, &next); + token_fifo.push_back (next); } /* If we arrive here we don't have a package-qualified name. */ @@ -1571,7 +1569,7 @@ go_parse (struct parser_state *par_state) last_was_structop = 0; saw_name_at_eof = 0; - VEC_free (token_and_value, token_fifo); + token_fifo.clear (); popping = 0; name_obstack.clear ();