From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5709D3855594 for ; Mon, 16 Oct 2023 15:00:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5709D3855594 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5709D3855594 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697468432; cv=none; b=iaLXY1eTJxDkfllWd1R1j4LLltXQFoeU7FSQYVx+MKbvfZqjZNi45VrNCcaC0rQ6+iTDSGdHil4NmdfWA5fJE1aeViYRb7BP80sB51q2eA13NEsbn7SkNlRFQvjCArPSXr2eBsLCoVqM46ACD8ERdRqQkvNdNf3kwQhFF3CfG4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697468432; c=relaxed/simple; bh=9oZCjqXqFAiv/yOhZr7/cfOo+KEgxRzDajNmnL4Ah7U=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=Lr8Ei3DMfaULviAAVFa57kw6oSVscFeojHOk0sgGOJFxY/SxLzF+d8/zG1nvU7ZekhImZZ+Gzbsmhf2y3N4SNJsRCkvEVc/ZsUl8qWJiyAnJ+ut6PN6//MVuQsVf3clPPcqJwUwWO8SiOSn7+01lSrLAhkS9E3M++/W6UllC30Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697468430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PXu7lUJN23a5eJnVsTzs9sR4/kCZxGLMEOHlIkTiDCY=; b=bcRKxVraBAaZ7ExML5JCOLNEXFwm4twnCh7+Zrd8MfZpPbuxLL4XNe/FpY6KbHhCExtoFl TbLJQ2YiUmvut4tcRiKlPhXAd2FZLPA77BvyBb6c9flGnEQOSB0sscxEKjYoXOdnIjIyr7 WvyYShK22xhbCSvaxgjIqDu0mRTXmdc= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-600--mXej98oNx2lkW53c-DB4Q-1; Mon, 16 Oct 2023 11:00:27 -0400 X-MC-Unique: -mXej98oNx2lkW53c-DB4Q-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7740cf4136aso533499485a.2 for ; Mon, 16 Oct 2023 08:00:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697468427; x=1698073227; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PXu7lUJN23a5eJnVsTzs9sR4/kCZxGLMEOHlIkTiDCY=; b=YE4hiJVorwme+CdkSiMWTFzZR8KtI19/I0K/LjRr9JrLc6etQNBKWhA3Q7Wg+97O+y MI7RqW/Spd0OXIEJ0sryeEVQ41CCxXzKdRNc8HEpztSlR3y03B2hOfioFTB9Q40B1t4A +A0dHnGNqDPXxNOKetyrZQTuVNISfS98VAldAin5X4iKHIGEubGGpF93BEMRuvc93rez vNTn/0KMwodxDsReTnPWhN+4W1GHm/N4qwZrryMDli2jRQXYUoKzPlH35echIKLb9jkj Ev1r40utBY+qUJBEIORIwgVHrhwHrwra75O0p6kxZ7XkbCF7irWjK5pvRmlsHP5/hzxH vaUg== X-Gm-Message-State: AOJu0YzbUIHLovW9jOuQ9iD775xzAIctw/SrgmPFmQ1ESi+ZPxGfpf0Q C9gDqfuS/RwNgptLmH7N6N8ZFzbe49XwKyNUy1F1BGAIc8lxryPw+xMvTHX1cjyPwkDxi5R2dCE i8IJKZJZrmMyFLgM= X-Received: by 2002:a05:620a:8a03:b0:777:27f9:7e54 with SMTP id qt3-20020a05620a8a0300b0077727f97e54mr16974731qkn.50.1697468427154; Mon, 16 Oct 2023 08:00:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnD5VFWqHF4bSvLn9HlcwSYpWxRJJ+43jGEZg8v6J1Mo0WVCFr4dpPi2DvGew37FAbpdre5Q== X-Received: by 2002:a05:620a:8a03:b0:777:27f9:7e54 with SMTP id qt3-20020a05620a8a0300b0077727f97e54mr16974708qkn.50.1697468426812; Mon, 16 Oct 2023 08:00:26 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id i10-20020a05620a144a00b00774652483b7sm3059365qkl.33.2023.10.16.08.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 08:00:26 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 16 Oct 2023 11:00:25 -0400 (EDT) To: Ken Matsui cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH v20 03/40] c++: Accept the use of built-in trait identifiers In-Reply-To: <20231016001227.2717180-4-kmatsui@gcc.gnu.org> Message-ID: <6c0ab6f7-4a4e-6b65-78b8-30d6593c33e5@idea> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-4-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sun, 15 Oct 2023, Ken Matsui wrote: > This patch accepts the use of built-in trait identifiers when they are > actually not used as traits. Specifically, we check if the subsequent token > is '(' for ordinary built-in traits or is '<' only for the special > __type_pack_element built-in trait. If those identifiers are used > differently, the parser treats them as normal identifiers. This allows > us to accept code like: struct __is_pointer {};. LGTM, thanks > > gcc/cp/ChangeLog: > > * parser.cc (cp_lexer_lookup_trait): Rename to ... > (cp_lexer_peek_trait): ... this. Handle a subsequent token for > the corresponding built-in trait. > (cp_lexer_lookup_trait_expr): Rename to ... > (cp_lexer_peek_trait_expr): ... this. > (cp_lexer_lookup_trait_type): Rename to ... > (cp_lexer_peek_trait_type): ... this. > (cp_lexer_next_token_is_decl_specifier_keyword): Call > cp_lexer_peek_trait_type. > (cp_parser_simple_type_specifier): Likewise. > (cp_parser_primary_expression): Call cp_lexer_peek_trait_expr. > > Signed-off-by: Ken Matsui > --- > gcc/cp/parser.cc | 48 ++++++++++++++++++++++++++++++------------------ > 1 file changed, 30 insertions(+), 18 deletions(-) > > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > index eba5272be03..0f2a1baee6a 100644 > --- a/gcc/cp/parser.cc > +++ b/gcc/cp/parser.cc > @@ -246,12 +246,12 @@ static void cp_lexer_start_debugging > (cp_lexer *) ATTRIBUTE_UNUSED; > static void cp_lexer_stop_debugging > (cp_lexer *) ATTRIBUTE_UNUSED; > -static const cp_trait *cp_lexer_lookup_trait > - (const cp_token *); > -static const cp_trait *cp_lexer_lookup_trait_expr > - (const cp_token *); > -static const cp_trait *cp_lexer_lookup_trait_type > - (const cp_token *); > +static const cp_trait *cp_lexer_peek_trait > + (cp_lexer *lexer, const cp_token *); > +static const cp_trait *cp_lexer_peek_trait_expr > + (cp_lexer *lexer, const cp_token *); > +static const cp_trait *cp_lexer_peek_trait_type > + (cp_lexer *lexer, const cp_token *); > > static cp_token_cache *cp_token_cache_new > (cp_token *, cp_token *); > @@ -1195,19 +1195,31 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) > } > } > > -/* Look ups the corresponding built-in trait if a given token is > +/* Peeks the corresponding built-in trait if a given token is > a built-in trait. Otherwise, returns nullptr. */ > > static const cp_trait * > -cp_lexer_lookup_trait (const cp_token *token) > +cp_lexer_peek_trait (cp_lexer *lexer, const cp_token *token1) > { > - tree id = token->u.value; > + tree id = token1->u.value; > > - if (token->type == CPP_NAME > + if (token1->type == CPP_NAME > && TREE_CODE (id) == IDENTIFIER_NODE > && IDENTIFIER_TRAIT_P (id)) > - return &cp_traits[IDENTIFIER_CP_INDEX (id)]; > + { > + const cp_trait &trait = cp_traits[IDENTIFIER_CP_INDEX (id)]; > + const bool is_pack_element = (trait.kind == CPTK_TYPE_PACK_ELEMENT); > > + /* Check if the subsequent token is a `<' token to > + __type_pack_element or is a `(' token to everything else. */ > + const cp_token *token2 = cp_lexer_peek_nth_token (lexer, 2); > + if (is_pack_element && token2->type != CPP_LESS) > + return nullptr; > + if (!is_pack_element && token2->type != CPP_OPEN_PAREN) > + return nullptr; > + > + return &trait; > + } > return nullptr; > } > > @@ -1215,9 +1227,9 @@ cp_lexer_lookup_trait (const cp_token *token) > built-in trait. */ > > static const cp_trait * > -cp_lexer_lookup_trait_expr (const cp_token *token) > +cp_lexer_peek_trait_expr (cp_lexer *lexer, const cp_token *token1) > { > - const cp_trait *trait = cp_lexer_lookup_trait (token); > + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); > if (trait && !trait->type) > return trait; > > @@ -1228,9 +1240,9 @@ cp_lexer_lookup_trait_expr (const cp_token *token) > built-in trait. */ > > static const cp_trait * > -cp_lexer_lookup_trait_type (const cp_token *token) > +cp_lexer_peek_trait_type (cp_lexer *lexer, const cp_token *token1) > { > - const cp_trait *trait = cp_lexer_lookup_trait (token); > + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); > if (trait && trait->type) > return trait; > > @@ -1245,7 +1257,7 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) > cp_token *token; > > token = cp_lexer_peek_token (lexer); > - if (cp_lexer_lookup_trait_type (token)) > + if (cp_lexer_peek_trait_type (lexer, token)) > return true; > return cp_keyword_starts_decl_specifier_p (token->keyword); > } > @@ -6117,7 +6129,7 @@ cp_parser_primary_expression (cp_parser *parser, > keyword. */ > case CPP_NAME: > { > - const cp_trait* trait = cp_lexer_lookup_trait_expr (token); > + const cp_trait* trait = cp_lexer_peek_trait_expr (parser->lexer, token); > if (trait) > return cp_parser_trait (parser, trait); > } > @@ -20126,7 +20138,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, > } > > /* If token is a type-yielding built-in traits, parse it. */ > - const cp_trait* trait = cp_lexer_lookup_trait_type (token); > + const cp_trait* trait = cp_lexer_peek_trait_type (parser->lexer, token); > if (trait) > { > type = cp_parser_trait (parser, trait); > -- > 2.42.0 > >