From patchwork Wed Sep 16 11:55:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 518368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A9E8E140134 for ; Wed, 16 Sep 2015 21:55:48 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=dSZl8cNI; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=Sz8cq/WC9fqv/1BUxVLeVqOCTRrp4WqbvavsWoSXRvALWM hWD/QQXgk2kRC1a9Da6+X6WtoUF+0w98YqPTrB4ixZz0AgP3nnFVuHhv3k8IlqtR QY9EbIZZOcZHiD4a/nv+GPVNN+AST/TpBcivVXzG5KScYOdwoEwAoNYrqz1uc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=Qqg0GiUwjAZN17ZeFXWDgjwdffU=; b=dSZl8cNIctckqk933h95 VOf7e+B3lIWwABVXsYLVLGYu6Dgk5GiRz2YVZFbI2GeK0050FottyLLw2pksAuC9 Q7Kw1oX/jbWAwhhyvvJjhtr/+AQ1sMZmf0bSi+g+ZDWH1/K1jVrEdOLOhne5jQIj VaLMCT3wdie597BlC+a5P4I= Received: (qmail 54436 invoked by alias); 16 Sep 2015 11:55:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 54419 invoked by uid 89); 16 Sep 2015 11:55:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vk0-f54.google.com Received: from mail-vk0-f54.google.com (HELO mail-vk0-f54.google.com) (209.85.213.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 16 Sep 2015 11:55:37 +0000 Received: by vkao3 with SMTP id o3so86940770vka.2 for ; Wed, 16 Sep 2015 04:55:35 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.31.170.80 with SMTP id t77mr21852172vke.156.1442404535218; Wed, 16 Sep 2015 04:55:35 -0700 (PDT) Received: by 10.103.37.195 with HTTP; Wed, 16 Sep 2015 04:55:35 -0700 (PDT) Date: Wed, 16 Sep 2015 14:55:35 +0300 Message-ID: Subject: [PATCH, RFC] Implement N4230, Nested namespace definition From: Ville Voutilainen To: "gcc-patches@gcc.gnu.org" , Jason Merrill This is the first stab, I haven't written the tests yet. Feedback would be most welcome; should I put this code into a separate function? Is the minor code duplication with the regular namespace definition ok? diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3a68dd7..00f18fb 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16750,7 +16750,7 @@ cp_parser_namespace_definition (cp_parser* parser) tree identifier, attribs; bool has_visibility; bool is_inline; - + cp_token* token; cp_ensure_no_omp_declare_simd (parser); if (cp_lexer_next_token_is_keyword (parser->lexer, RID_INLINE)) { @@ -16762,7 +16762,7 @@ cp_parser_namespace_definition (cp_parser* parser) is_inline = false; /* Look for the `namespace' keyword. */ - cp_parser_require_keyword (parser, RID_NAMESPACE, RT_NAMESPACE); + token = cp_parser_require_keyword (parser, RID_NAMESPACE, RT_NAMESPACE); /* Get the name of the namespace. We do not attempt to distinguish between an original-namespace-definition and an @@ -16776,6 +16776,33 @@ cp_parser_namespace_definition (cp_parser* parser) /* Parse any specified attributes. */ attribs = cp_parser_attributes_opt (parser); + if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)) + { + if (is_inline) + error_at (token->location, "a nested % definition cannot be inline"); + push_namespace (identifier); + int nest_count = 0; + while (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)) + { + cp_lexer_consume_token (parser->lexer); + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + identifier = cp_parser_identifier (parser); + else + { + cp_parser_error (parser, "nested identifier required"); + break; + } + ++nest_count; + push_namespace (identifier); + } + cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE); + cp_parser_namespace_body (parser); + while (nest_count--) + pop_namespace (); + pop_namespace (); + cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); + return; + } /* Look for the `{' to start the namespace. */ cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE); /* Start the namespace. */