From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95050 invoked by alias); 5 Jan 2019 20:41:20 -0000 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 Received: (qmail 94950 invoked by uid 89); 5 Jan 2019 20:41:19 -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, Storage, promises, H*Ad:U*tom X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.133) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 05 Jan 2019 20:41:16 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 81B1D400CB721 for ; Sat, 5 Jan 2019 14:41:15 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id fsktg1X9kdnCefsktg84sU; 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=VQfxPfq4UWgnUVLOvP/x0vgToSZbjJ7unQKuExnBmpE=; b=ycSInuzVNXJ+CanGPsfPbMVw3x 8iVIf+3PKCJWhyRwRWgCC2MHgAeo/DLH1fHn1lKxLkaiWut0SRDXSa4Y9KCL5FOoC/g6W42CWFgHG pxW0C5pCo4qAgnlMN7jOOKSQP; 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 1gfskt-000OXk-A2; Sat, 05 Jan 2019 14:41:15 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/3] Remove remaining cleanups from c-exp.y Date: Sat, 05 Jan 2019 20:41:00 -0000 Message-Id: <20190105204112.26849-4-tom@tromey.com> In-Reply-To: <20190105204112.26849-1-tom@tromey.com> References: <20190105204112.26849-1-tom@tromey.com> X-SW-Source: 2019-01/txt/msg00078.txt.bz2 This removes the remaining cleanups from c-exp.y by moving some globals into c_parse_state, and changing expansion_obstack to be an auto_obstack. gdb/ChangeLog 2019-01-05 Tom Tromey * c-exp.y (struct c_parse_state) : New member. (macro_original_text, expansion_obstack): Remove globals. (scan_macro_expansion, scanning_macro_expansion) (finished_macro_expansion): Update. (scan_macro_cleanup): Remove. (yylex, c_parse): Update. --- gdb/ChangeLog | 10 ++++++ gdb/c-exp.y | 93 ++++++++++++++++++++------------------------------- 2 files changed, 46 insertions(+), 57 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 83b2aa3fdd..7339dfd51c 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -77,6 +77,33 @@ struct c_parse_state /* Storage for some strings allocated during the parse. */ std::vector> strings; + + /* When we find that lexptr (the global var defined in parse.c) is + pointing at a macro invocation, we expand the invocation, and call + scan_macro_expansion to save the old lexptr here and point lexptr + into the expanded text. When we reach the end of that, we call + end_macro_expansion to pop back to the value we saved here. The + macro expansion code promises to return only fully-expanded text, + so we don't need to "push" more than one level. + + This is disgusting, of course. It would be cleaner to do all macro + expansion beforehand, and then hand that to lexptr. But we don't + really know where the expression ends. Remember, in a command like + + (gdb) break *ADDRESS if CONDITION + + we evaluate ADDRESS in the scope of the current frame, but we + evaluate CONDITION in the scope of the breakpoint's location. So + it's simply wrong to try to macro-expand the whole thing at once. */ + const char *macro_original_text = nullptr; + + /* We save all intermediate macro expansions on this obstack for the + duration of a single parse. The expansion text may sometimes have + to live past the end of the expansion, due to yacc lookahead. + Rather than try to be clever about saving the data for a single + token, we simply keep it all and delete it after parsing has + completed. */ + auto_obstack expansion_obstack; }; /* This is set and cleared in c_parse. */ @@ -2427,32 +2454,6 @@ static const struct token ident_tokens[] = {"typeid", TYPEID, OP_TYPEID, FLAG_CXX} }; -/* When we find that lexptr (the global var defined in parse.c) is - pointing at a macro invocation, we expand the invocation, and call - scan_macro_expansion to save the old lexptr here and point lexptr - into the expanded text. When we reach the end of that, we call - end_macro_expansion to pop back to the value we saved here. The - macro expansion code promises to return only fully-expanded text, - so we don't need to "push" more than one level. - - This is disgusting, of course. It would be cleaner to do all macro - expansion beforehand, and then hand that to lexptr. But we don't - really know where the expression ends. Remember, in a command like - - (gdb) break *ADDRESS if CONDITION - - we evaluate ADDRESS in the scope of the current frame, but we - evaluate CONDITION in the scope of the breakpoint's location. So - it's simply wrong to try to macro-expand the whole thing at once. */ -static const char *macro_original_text; - -/* We save all intermediate macro expansions on this obstack for the - duration of a single parse. The expansion text may sometimes have - to live past the end of the expansion, due to yacc lookahead. - Rather than try to be clever about saving the data for a single - token, we simply keep it all and delete it after parsing has - completed. */ -static struct obstack expansion_obstack; static void scan_macro_expansion (char *expansion) @@ -2460,44 +2461,35 @@ scan_macro_expansion (char *expansion) char *copy; /* We'd better not be trying to push the stack twice. */ - gdb_assert (! macro_original_text); + gdb_assert (! cpstate->macro_original_text); /* Copy to the obstack, and then free the intermediate expansion. */ - copy = (char *) obstack_copy0 (&expansion_obstack, expansion, + copy = (char *) obstack_copy0 (&cpstate->expansion_obstack, expansion, strlen (expansion)); xfree (expansion); /* Save the old lexptr value, so we can return to it when we're done parsing the expanded text. */ - macro_original_text = lexptr; + cpstate->macro_original_text = lexptr; lexptr = copy; } static int scanning_macro_expansion (void) { - return macro_original_text != 0; + return cpstate->macro_original_text != 0; } static void finished_macro_expansion (void) { /* There'd better be something to pop back to. */ - gdb_assert (macro_original_text); + gdb_assert (cpstate->macro_original_text); /* Pop back to the original text. */ - lexptr = macro_original_text; - macro_original_text = 0; -} - -static void -scan_macro_cleanup (void *dummy) -{ - if (macro_original_text) - finished_macro_expansion (); - - obstack_free (&expansion_obstack, NULL); + lexptr = cpstate->macro_original_text; + cpstate->macro_original_text = 0; } /* Return true iff the token represents a C++ cast operator. */ @@ -3262,7 +3254,7 @@ yylex (void) if (checkpoint > 0) { current.value.sval.ptr - = (const char *) obstack_copy0 (&expansion_obstack, + = (const char *) obstack_copy0 (&cpstate->expansion_obstack, current.value.sval.ptr, current.value.sval.length); @@ -3282,9 +3274,6 @@ yylex (void) int c_parse (struct parser_state *par_state) { - int result; - struct cleanup *back_to; - /* Setting up the parser state. */ scoped_restore pstate_restore = make_scoped_restore (&pstate); gdb_assert (par_state != NULL); @@ -3305,13 +3294,6 @@ c_parse (struct parser_state *par_state) scoped_restore restore_macro_scope = make_scoped_restore (&expression_macro_scope, macro_scope.get ()); - /* Initialize macro expansion code. */ - obstack_init (&expansion_obstack); - gdb_assert (! macro_original_text); - /* Note that parsing (within yyparse) freely installs cleanups - assuming they'll be run here (below). */ - back_to = make_cleanup (scan_macro_cleanup, 0); - scoped_restore restore_yydebug = make_scoped_restore (&yydebug, parser_debug); @@ -3323,10 +3305,7 @@ c_parse (struct parser_state *par_state) popping = 0; name_obstack.clear (); - result = yyparse (); - do_cleanups (back_to); - - return result; + return yyparse (); } #ifdef YYBISON -- 2.17.2