From patchwork Fri Sep 20 14:05:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 276478 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 970B72C0163 for ; Sat, 21 Sep 2013 00:06:08 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=iicc4Q8H5lxRIYfwzJwgxTutjIXacA68jJxsBBLo4bouiIVXH7WOP 0gLachHMLZIqAEp1dU700hOk+uWEYhItAHF0tilkYhE0bO2oMUqN3vsdwlkz/H5c vh+YALwEzF0xvgUPid/drqs+5milkJaqkxKZlW0yZMPPmj0oTdki5I= 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:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=LIC0oVQlXPfnVBsUEu3nMhYJWRg=; b=TEgV+0FRgGpauQAfYnaS pn9RAU2r4+lOiKa/PNR4LmIOTU926EJ2nyPVunzHXZm3N0+EssjF+j6Bmb3H8d+P 4qR5LfELxGUinaUa+kaMllZNs7ZjrTTzMOHRJyrwxbJOyGC3A5QkpO3Xgw7Z6AYF d/f0vuhSkq+OMOJv3fx5gX4= Received: (qmail 24907 invoked by alias); 20 Sep 2013 14:05:53 -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 24832 invoked by uid 89); 20 Sep 2013 14:05:52 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Sep 2013 14:05:52 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, KHOP_THREADED, RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8KE5jCp023651 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 20 Sep 2013 10:05:46 -0400 Received: from surprise.bos.redhat.com ([10.18.25.13]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8KE5itN022052; Fri, 20 Sep 2013 10:05:45 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Jan Hubicka , David Malcolm Subject: [PATCH 1/3] Parse base classes for GTY-marked types Date: Fri, 20 Sep 2013 10:05:17 -0400 Message-Id: <1379685919-9437-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1379685919-9437-1-git-send-email-dmalcolm@redhat.com> References: <1379685919-9437-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes Extend gengtype (and gtype.state reading/writing) so that it is able to parse base classes in simple cases, and only attempt to do it for GTY-marked types. * gengtype-parse.c (require_without_advance): New. (type): For GTY-marked types, parse any base classes, requiring them to be single-inheritance, and not be templates. For non-GTY-marked types, continued to skip over any C++ inheritance specification. * gengtype-state.c (state_writer::write_state_struct_type): Write base class of type (if any). (read_state_struct_type): Read base class of type (if any). * gengtype.c (new_structure): Add a "base_class" parameter. (create_optional_field_): Update for new parameter to new_structure. (adjust_field_rtx_def): Likewise. (adjust_field_tree_exp): Likewise. * gengtype.h (struct type): Add "base_class" field to the s union field. (new_structure): Add "base" parameter. --- gcc/gengtype-parse.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- gcc/gengtype-state.c | 2 ++ gcc/gengtype.c | 15 ++++++++------- gcc/gengtype.h | 4 +++- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/gcc/gengtype-parse.c b/gcc/gengtype-parse.c index 68d372e..aae2c6c 100644 --- a/gcc/gengtype-parse.c +++ b/gcc/gengtype-parse.c @@ -165,6 +165,21 @@ require (int t) return v; } +/* As per require, but do not advance. */ +static const char * +require_without_advance (int t) +{ + int u = token (); + const char *v = T.value; + if (u != t) + { + parse_error ("expected %s, have %s", + print_token (t, 0), print_token (u, v)); + return 0; + } + return v; +} + /* If the next token does not have one of the codes T1 or T2, report a parse error; otherwise return the token's value. */ static const char * @@ -818,6 +833,7 @@ type (options_p *optsp, bool nested) case STRUCT: case UNION: { + type_p base_class = NULL; options_p opts = 0; /* GTY annotations follow attribute syntax GTY_BEFORE_ID is for union/struct declarations @@ -859,9 +875,31 @@ type (options_p *optsp, bool nested) if (token () == ':') { - /* Skip over C++ inheritance specification. */ - while (token () != '{') - advance (); + if (is_gty) + { + /* For GTY-marked types, parse some C++ inheritance + specifications. + We require single-inheritance from a non-template type. */ + advance (); + const char *basename = require (ID); + /* This may be either an access specifier, or the base name. */ + if (0 == strcmp (basename, "public") + || 0 == strcmp (basename, "protected") + || 0 == strcmp (basename, "private")) + basename = require (ID); + base_class = find_structure (basename, TYPE_STRUCT); + if (!base_class) + parse_error ("unrecognized base class: %s", basename); + require_without_advance ('{'); + } + else + { + /* For types lacking GTY-markings, skip over C++ inheritance + specification (and thus avoid having to parse e.g. template + types). */ + while (token () != '{') + advance (); + } } if (is_gty) @@ -889,7 +927,8 @@ type (options_p *optsp, bool nested) return create_user_defined_type (s, &lexer_line); } - return new_structure (s, kind, &lexer_line, fields, opts); + return new_structure (s, kind, &lexer_line, fields, opts, + base_class); } } else if (token () == '{') diff --git a/gcc/gengtype-state.c b/gcc/gengtype-state.c index ba7948a..54e4287 100644 --- a/gcc/gengtype-state.c +++ b/gcc/gengtype-state.c @@ -957,6 +957,7 @@ state_writer::write_state_struct_type (type_p current) { write_state_struct_union_type (current, "struct"); write_state_type (current->u.s.lang_struct); + write_state_type (current->u.s.base_class); } /* Write a GTY user-defined struct type. */ @@ -1613,6 +1614,7 @@ read_state_struct_type (type_p type) read_state_options (&(type->u.s.opt)); read_state_lang_bitmap (&(type->u.s.bitmap)); read_state_type (&(type->u.s.lang_struct)); + read_state_type (&(type->u.s.base_class)); } else { diff --git a/gcc/gengtype.c b/gcc/gengtype.c index c3dffe8..a6dc221 100644 --- a/gcc/gengtype.c +++ b/gcc/gengtype.c @@ -674,7 +674,7 @@ resolve_typedef (const char *s, struct fileloc *pos) type_p new_structure (const char *name, enum typekind kind, struct fileloc *pos, - pair_p fields, options_p o) + pair_p fields, options_p o, type_p base_class) { type_p si; type_p s = NULL; @@ -748,6 +748,7 @@ new_structure (const char *name, enum typekind kind, struct fileloc *pos, s->u.s.bitmap = bitmap; if (s->u.s.lang_struct) s->u.s.lang_struct->u.s.bitmap |= bitmap; + s->u.s.base_class = base_class; return s; } @@ -976,7 +977,7 @@ create_optional_field_ (pair_p next, type_p type, const char *name, create_string_option (union_fields->opt, "tag", "1"); union_type = new_structure (xasprintf ("%s_%d", "fake_union", id++), TYPE_UNION, - &lexer_line, union_fields, NULL); + &lexer_line, union_fields, NULL, NULL); /* Create the field and give it the new fake union type. Add a "desc" tag that specifies the condition under which the field is valid. */ @@ -1167,7 +1168,7 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt)) create_string_option (nodot, "tag", note_insn_name[c]); } note_union_tp = new_structure ("rtx_def_note_subunion", TYPE_UNION, - &lexer_line, note_flds, NULL); + &lexer_line, note_flds, NULL, NULL); } /* Create a type to represent the various forms of SYMBOL_REF_DATA. */ { @@ -1177,7 +1178,7 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt)) sym_flds = create_field (sym_flds, constant_tp, "rt_constant"); sym_flds->opt = create_string_option (nodot, "tag", "1"); symbol_union_tp = new_structure ("rtx_def_symbol_subunion", TYPE_UNION, - &lexer_line, sym_flds, NULL); + &lexer_line, sym_flds, NULL, NULL); } for (i = 0; i < NUM_RTX_CODE; i++) { @@ -1319,7 +1320,7 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt)) sname = xasprintf ("rtx_def_%s", rtx_name[i]); substruct = new_structure (sname, TYPE_STRUCT, &lexer_line, subfields, - NULL); + NULL, NULL); ftag = xstrdup (rtx_name[i]); for (nmindex = 0; nmindex < strlen (ftag); nmindex++) @@ -1328,7 +1329,7 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt)) flds->opt = create_string_option (nodot, "tag", ftag); } return new_structure ("rtx_def_subunion", TYPE_UNION, &lexer_line, flds, - nodot); + nodot, NULL); } /* Handle `special("tree_exp")'. This is a special case for @@ -1358,7 +1359,7 @@ adjust_field_tree_exp (type_p t, options_p opt ATTRIBUTE_UNUSED) flds->opt = create_string_option (flds->opt, "default", ""); return new_structure ("tree_exp_subunion", TYPE_UNION, &lexer_line, flds, - nodot); + nodot, NULL); } /* Perform any special processing on a type T, about to become the type diff --git a/gcc/gengtype.h b/gcc/gengtype.h index f71ad97..06ebbed 100644 --- a/gcc/gengtype.h +++ b/gcc/gengtype.h @@ -291,6 +291,8 @@ struct type { field the original TYPE_LANG_STRUCT type. This is a dirty trick, see the new_structure function for details. */ type_p lang_struct; + + type_p base_class; /* the parent class, if any. */ } s; /* when TYPE_SCALAR: */ @@ -424,7 +426,7 @@ extern void do_scalar_typedef (const char *s, struct fileloc *pos); extern type_p resolve_typedef (const char *s, struct fileloc *pos); extern type_p new_structure (const char *name, enum typekind kind, struct fileloc *pos, pair_p fields, - options_p o); + options_p o, type_p base); type_p create_user_defined_type (const char *, struct fileloc *); extern type_p find_structure (const char *s, enum typekind kind); extern type_p create_scalar_type (const char *name);