Tool to delete unneeded methods/enums, etc.

Discussion in 'C++' started by Julek, Jun 30, 2008.

  1. Julek

    Julek Guest

    Hi,
    is there a tool which parses cpp and h files, finds unused things, and
    deletes them from code? For example unused methods, enums, enum
    values, defines... It doesn't have to be sophisticated (it doesn't
    have to check, that ClassA::funX is used somewhere, but ClassB::funX
    is not used anywhere, so we can delete only ClassB::funX).

    Thanks in advance!
    Julek, Jun 30, 2008
    #1
    1. Advertising

  2. Julek

    Jerry Coffin Guest

    In article <62e3029a-2655-4b63-9511-d561acba7a89@
    34g2000hsh.googlegroups.com>, says...
    > Hi,
    > is there a tool which parses cpp and h files, finds unused things, and
    > deletes them from code?


    Yes. It's called an "optimizing compiler". :)

    > For example unused methods, enums, enum
    > values, defines... It doesn't have to be sophisticated (it doesn't
    > have to check, that ClassA::funX is used somewhere, but ClassB::funX
    > is not used anywhere, so we can delete only ClassB::funX).


    Realistically, getting something like this to work correctly would be
    quite difficult -- little short of a full-blown compiler could really do
    the job correctly.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
    Jerry Coffin, Jun 30, 2008
    #2
    1. Advertising

  3. Julek

    James Kanze Guest

    On Jun 30, 5:57 pm, Jerry Coffin <> wrote:
    > In article <62e3029a-2655-4b63-9511-d561acba7a89@
    > 34g2000hsh.googlegroups.com>, says...


    > > is there a tool which parses cpp and h files, finds unused
    > > things, and deletes them from code?


    > Yes. It's called an "optimizing compiler". :)


    > > For example unused methods, enums, enum
    > > values, defines... It doesn't have to be sophisticated (it doesn't
    > > have to check, that ClassA::funX is used somewhere, but ClassB::funX
    > > is not used anywhere, so we can delete only ClassB::funX).


    > Realistically, getting something like this to work correctly would be
    > quite difficult -- little short of a full-blown compiler could really do
    > the job correctly.


    FWIW: one Fortran compiler I used (around 1978) did output a
    message when it suppressed a line because it couldn't be
    reached, or otherwise did something which had no effect. This
    could actually be very helpful---in one case, I remember getting
    messages to the effect:
    line x: removed, because variable YO is never used.
    line y: variable Y0 used without being set.
    I'm not sure about the relative utility of such a thing in C++,
    however. The preprocessor makes it a bit awkward: what if I
    don't use the enum E (defined in some header); maybe some other
    code in another application does use it.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Jun 30, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2VubnkgTS4=?=

    making an unneeded post back

    =?Utf-8?B?S2VubnkgTS4=?=, Jan 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    299
    =?Utf-8?B?Q2hpbm1heQ==?=
    Jan 25, 2005
  2. =?utf-8?b?QXNiasO4cm4gU8OmYsO4?=

    Enums without identifier, enums and typedef

    =?utf-8?b?QXNiasO4cm4gU8OmYsO4?=, Jan 19, 2007, in forum: C Programming
    Replies:
    10
    Views:
    1,127
    Keith Thompson
    Jan 20, 2007
  3. Mikhail Teterin

    enums, using methods as initializers

    Mikhail Teterin, Nov 14, 2007, in forum: Java
    Replies:
    27
    Views:
    812
    Mikhail Teterin
    Dec 12, 2007
  4. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    389
    Fredrik Lundh
    Aug 13, 2008
  5. Jet Koten
    Replies:
    9
    Views:
    178
    Robert Klemme
    Feb 27, 2010
Loading...

Share This Page