Honza: following up from our IRC chat, I've ported the symtab, cgraph
and varpool nodes from the current hand-coded inheritance-in-C scheme
to being a C+ class hierarchy.

I know you're in the middle of making lots of other changes to this code,
so I've written a script to automate the parts of the conversion where
appropriate - see below.

In summary,
  struct GTY(()) symtab_node_base
becomes:
  class GTY((user)) symtab_node_base

and the subclasses:
  struct GTY(()) cgraph_node
and:
  struct GTY(()) varpool_node

become (respectively):
  struct GTY((user)) cgraph_node : public symtab_node_base
and:
  class GTY((user)) varpool_node : public symtab_node_base

The symtab_node_def union goes away, as do the "symbol" fields at the
top of the two subclasses.

I kept the existing names for things, and the "struct" for cgraph_node
since it is often referred to as "struct cgraph_node".

The patch is in three parts; all three are needed.

  * a fix for a bug in gengtype:
      http://gcc.gnu.org/ml/gcc-patches/2013-08/msg00882.html
    This is needed to avoid generating a malfunctioning gtype-desc.c
    *some* of the time - in capriciously changing ways as the sources
    change... :(   I sent it separately since I'm running into this
    issue with other changes I'm trying out; it "randomly" appears
    when trying to use GTY((user)).

  * Patch 1 of the 2 in this series is the hand-written part of the
    conversion.  This makes the changes above, plus various workarounds
    for dealing with yet more issues in how gengtype handles
    GTY((user)).

  * Patch 2 of the 2 in this series is the autogenerated part.
    Currently to access the base symtab fields of a cgraph or varpool
    node, the code has e.g.

       node->symbol.decl

    whereas with C++ inheritance, the "symbol" field is no more, and we
    directly use the base-class field:

       node->decl
    
    The script that makes the patch is for Python (2.7), and is in:
       https://github.com/davidmalcolm/gcc-refactoring-scripts
    as refactor_symtab.py and there's a test suite in
    test_refactor_symtab.py.   It's basically a glorified sed, but it
    also autogenerates the ChangeLog entries.  It expects the gcc
    checkout to be in a sister directory named "src".

Successfully bootstrapped and regtested on x86_64-unknown-linux-gnu
(using all three patches together, showing same results as an unpatched
source tree).

How does this look?  Are there other automated changes you'd like me
to make?   How should I go about getting this into trunk, given that you
have many other changes to this code on the way?

Thanks; hope this is helpful
Dave

David Malcolm (2):
  Convert symtab, cgraph and varpool nodes into a real class hierarchy
  Autogenerated fixes of "->symbol." to "->"

 gcc/ada/gcc-interface/trans.c |   2 +-
 gcc/ada/gcc-interface/utils.c |   2 +-
 gcc/asan.c                    |  10 +-
 gcc/c-family/c-gimplify.c     |   2 +-
 gcc/c-family/c-pragma.c       |   2 +-
 gcc/cfgexpand.c               |   2 +-
 gcc/cgraph.c                  | 480 ++++++++++++++++++++++++++++++------------
 gcc/cgraph.h                  | 150 +++++++------
 gcc/cgraphbuild.c             |  10 +-
 gcc/cgraphclones.c            |  84 ++++----
 gcc/cgraphunit.c              | 260 +++++++++++------------
 gcc/config/i386/i386.c        |  18 +-
 gcc/coverage.c                |   4 +-
 gcc/cp/call.c                 |   2 +-
 gcc/cp/decl2.c                |  24 +--
 gcc/cp/tree.c                 |   4 +-
 gcc/dbxout.c                  |   2 +-
 gcc/dwarf2out.c               |   4 +-
 gcc/gimple-fold.c             |   8 +-
 gcc/gimplify.c                |   4 +-
 gcc/ipa-cp.c                  |  66 +++---
 gcc/ipa-inline-analysis.c     |  48 ++---
 gcc/ipa-inline-transform.c    |  46 ++--
 gcc/ipa-inline.c              | 166 +++++++--------
 gcc/ipa-prop.c                |  56 ++---
 gcc/ipa-pure-const.c          |  54 ++---
 gcc/ipa-ref-inline.h          |   4 +-
 gcc/ipa-ref.c                 |  14 +-
 gcc/ipa-ref.h                 |   6 +-
 gcc/ipa-reference.c           |  60 +++---
 gcc/ipa-split.c               |  26 +--
 gcc/ipa-utils.c               |  46 ++--
 gcc/ipa.c                     | 410 ++++++++++++++++++------------------
 gcc/is-a.h                    |   8 +-
 gcc/java/decl.c               |   2 +-
 gcc/lto-cgraph.c              | 224 ++++++++++----------
 gcc/lto-streamer-in.c         |   4 +-
 gcc/lto-streamer-out.c        |  38 ++--
 gcc/lto-symtab.c              | 198 ++++++++---------
 gcc/lto/lto-partition.c       | 126 +++++------
 gcc/lto/lto.c                 |  26 +--
 gcc/passes.c                  |  28 +--
 gcc/symtab.c                  | 372 ++++++++++++++++----------------
 gcc/toplev.c                  |   6 +-
 gcc/trans-mem.c               |  94 ++++-----
 gcc/tree-eh.c                 |   4 +-
 gcc/tree-emutls.c             |  38 ++--
 gcc/tree-inline.c             |  36 ++--
 gcc/tree-nested.c             |  10 +-
 gcc/tree-pretty-print.c       |   2 +-
 gcc/tree-profile.c            |  20 +-
 gcc/tree-sra.c                |  20 +-
 gcc/tree-ssa-structalias.c    |  40 ++--
 gcc/tree-vectorizer.c         |   2 +-
 gcc/tree.c                    |  10 +-
 gcc/value-prof.c              |  18 +-
 gcc/varasm.c                  |  30 +--
 gcc/varpool.c                 | 118 +++++------
 58 files changed, 1881 insertions(+), 1669 deletions(-)

-- 
1.7.11.7

Reply via email to