From patchwork Sat Aug 15 06:57:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 8229 Received: (qmail 123657 invoked by alias); 15 Aug 2015 06:57:48 -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 123647 invoked by uid 89); 15 Aug 2015 06:57:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f174.google.com Received: from mail-yk0-f174.google.com (HELO mail-yk0-f174.google.com) (209.85.160.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 15 Aug 2015 06:57:45 +0000 Received: by ykfw73 with SMTP id w73so33302884ykf.3 for ; Fri, 14 Aug 2015 23:57:43 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.170.145.10 with SMTP id m10mr48902426ykc.108.1439621863415; Fri, 14 Aug 2015 23:57:43 -0700 (PDT) Received: by 10.129.40.67 with HTTP; Fri, 14 Aug 2015 23:57:43 -0700 (PDT) Date: Sat, 15 Aug 2015 08:57:43 +0200 Message-ID: Subject: [PATCH] [D] Allow enum scopes to be looked up. From: Iain Buclaw To: GDB Patches X-IsSubscribed: yes Hi, In D, all named enums are scoped (the C++ equivalent of enum class) so they should be handled in the language-specific symbol lookup. However so as to support D compilers that don't emit enums as DW_AT_enum_class (currently none, but I'm will shortly be adding it to gdc), need to make sure that proper a safeguard is in place. Regards Iain. --- 2015-08-15 Iain Buclaw * d-exp.y (type_aggregate_p): New function. (PrimaryExpression : TypeExp '.' IdentifierExp): Use it. (classify_inner_name): Likewise. * d-namespace.c (d_lookup_nested_symbol): Handle TYPE_CODE_ENUM. diff --git a/gdb/d-exp.y b/gdb/d-exp.y index e23a0aa..05dc449 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -126,6 +126,8 @@ static int yylex (void); void yyerror (char *); +static int type_aggregate_p (struct type *); + %} /* Although the yacc "value" of an expression is not used, @@ -554,9 +556,7 @@ PrimaryExpression: /* Check if the qualified name resolves as a member of an aggregate or an enum type. */ - if (!(TYPE_CODE (type) == TYPE_CODE_STRUCT - || TYPE_CODE (type) == TYPE_CODE_UNION - || TYPE_CODE (type) == TYPE_CODE_ENUM)) + if (!type_aggregate_p (type)) error (_("`%s' is not defined as an aggregate type."), TYPE_SAFE_NAME (type)); @@ -695,6 +695,17 @@ BasicType: %% +/* Return true if the type is aggregate-like. */ + +static int +type_aggregate_p (struct type *type) +{ + return (TYPE_CODE (type) == TYPE_CODE_STRUCT + || TYPE_CODE (type) == TYPE_CODE_UNION + || (TYPE_CODE (type) == TYPE_CODE_ENUM + && TYPE_DECLARED_CLASS (type))); +} + /* Take care of parsing a number (anything that starts with a digit). Set yylval and return the token type; update lexptr. LEN is the number of characters in it. */ @@ -1440,6 +1451,8 @@ classify_inner_name (struct parser_state *par_state, return classify_name (par_state, block); type = check_typedef (context); + if (!type_aggregate_p (type)) + return ERROR; copy = copy_name (yylval.ssym.stoken); yylval.ssym.sym = d_lookup_nested_symbol (type, copy, block); diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c index 9a558d1..bed8d5b 100644 --- a/gdb/d-namespace.c +++ b/gdb/d-namespace.c @@ -308,6 +308,7 @@ d_lookup_nested_symbol (struct type *parent_type, { case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: + case TYPE_CODE_ENUM: case TYPE_CODE_MODULE: { int size;