Thread: RE: [GD-General] remove unused functions
Brought to you by:
vexxed72
From: Tom F. <to...@mu...> - 2003-05-19 19:45:07
|
Maybe you can add a prologue to every function that does two things: (a) declares a static instance of a class whose constructor adds the string "__FILE__ __LINE__" to a table. (b) when it is called, finds and removes the string from the table. Play the game for a while, go through as many different codepaths and behaviours as you can think of, then dump the table to disk or whatever. And there you go - a list of all the functions (well, where they are - maybe there's a MS #define that lists the function name?) that haven't been called this time around. Then add ASSERT (!"Nobody ever calls me or they would have removed this assert") to each file, leave it a couple of weeks, and then kill all the functions that still have that assert. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Corrinne Yu [mailto:cor...@sp...] > Sent: 19 May 2003 19:58 > To: gam...@li... > Subject: [GD-General] remove unused functions > > > The game engine and game code base has gotten very very big. And it is > about time to clean things up and improve its structure and > documentation. > > One thing I would like to do to it is to start removing un-used > functions. I tried to use MSDev to remove un-referenced functions as a > start but didn't find any. It turns out quite a few of the "un-used" > functions are "referenced" (and thus can't be that easily > automatically > determined) but I know from how the game and engine code is > supposed to > run that they won't ever be called. > > They are not exactly unreachable code either, so doing the unreachable > code thing also doesn't work. > > I truly "dread" :D the idea to have to manually step through all the > code and manually cull out every single un-used function by > hand (it is > a lot of code to wade through!). I wonder what tools exist inside of > MSDev (or simple easy to use small external tools) that can help me in > my highly un fun task of cleaning up my code base, specifically in the > task of removing "un-used" functions. > > Thank you for your experience in this task, and your suggestions. > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ObjectStore. > If flattening out C++ or Java code to make your application fit in a > relational database is painful, don't do it! Check out ObjectStore. > Now part of Progress Software. http://www.objectstore.net/sourceforge > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > |
From: Jim S. <ja...@mi...> - 2003-05-20 01:37:06
|
> maybe there's a MS #define that lists the function name? yep. __FUNCTION__ |
From: Ken P. <ke...@dr...> - 2003-05-20 02:23:39
|
At 08:07 PM 5/19/2003, you wrote: > > maybe there's a MS #define that lists the function name? > >yep. __FUNCTION__ In what version? MSVC++ 6 certainly doesn't expose it. |
From: Daniel V. <vo...@ep...> - 2003-05-20 02:54:15
|
You're stuck with __FILE__ and __LINE__ then. -- Daniel, Epic Games Inc. > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...]On Behalf Of > Ken Paulson > Sent: Monday, May 19, 2003 10:24 PM > To: gam...@li... > Subject: RE: [GD-General] remove unused functions > > > At 08:07 PM 5/19/2003, you wrote: > > > > maybe there's a MS #define that lists the function name? > > > >yep. __FUNCTION__ > > In what version? MSVC++ 6 certainly doesn't expose it. > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ObjectStore. > If flattening out C++ or Java code to make your application fit in a > relational database is painful, don't do it! Check out ObjectStore. > Now part of Progress Software. http://www.objectstore.net/sourceforge > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > |
From: Daniel V. <vo...@ep...> - 2003-05-20 05:50:50
|
Sorry, meant to be a bit more elaborate - AFAIK __FUNCTION__ only works with gcc and not with VC. -- Daniel, Epic Games Inc. > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...]On Behalf Of > Daniel Vogel > Sent: Monday, May 19, 2003 10:54 PM > To: gam...@li... > Subject: RE: [GD-General] remove unused functions > > > You're stuck with __FILE__ and __LINE__ then. > > -- Daniel, Epic Games Inc. > > > -----Original Message----- > > From: gam...@li... > > [mailto:gam...@li...]On Behalf Of > > Ken Paulson > > Sent: Monday, May 19, 2003 10:24 PM > > To: gam...@li... > > Subject: RE: [GD-General] remove unused functions > > > > > > At 08:07 PM 5/19/2003, you wrote: > > > > > > maybe there's a MS #define that lists the function name? > > > > > >yep. __FUNCTION__ > > > > In what version? MSVC++ 6 certainly doesn't expose it. > > > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: ObjectStore. > > If flattening out C++ or Java code to make your application fit in a > > relational database is painful, don't do it! Check out ObjectStore. > > Now part of Progress Software. http://www.objectstore.net/sourceforge > > _______________________________________________ > > Gamedevlists-general mailing list > > Gam...@li... > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ObjectStore. > If flattening out C++ or Java code to make your application fit in a > relational database is painful, don't do it! Check out ObjectStore. > Now part of Progress Software. http://www.objectstore.net/sourceforge > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > |
From: <Lag...@wa...> - 2003-05-20 07:34:43
|
Not totaly correct : __FUNCTION__ work with MSVC 7 --------------------- Lagarde Sébastien Neko entertainment ----- Original Message ----- From: "Daniel Vogel" <vo...@ep...> To: <gam...@li...> Sent: Tuesday, May 20, 2003 7:50 AM Subject: RE: [GD-General] remove unused functions > Sorry, meant to be a bit more elaborate - AFAIK __FUNCTION__ only works with > gcc and not with VC. > > -- Daniel, Epic Games Inc. > > > -----Original Message----- > > From: gam...@li... > > [mailto:gam...@li...]On Behalf Of > > Daniel Vogel > > Sent: Monday, May 19, 2003 10:54 PM > > To: gam...@li... > > Subject: RE: [GD-General] remove unused functions > > > > > > You're stuck with __FILE__ and __LINE__ then. > > > > -- Daniel, Epic Games Inc. > > > > > -----Original Message----- > > > From: gam...@li... > > > [mailto:gam...@li...]On Behalf Of > > > Ken Paulson > > > Sent: Monday, May 19, 2003 10:24 PM > > > To: gam...@li... > > > Subject: RE: [GD-General] remove unused functions > > > > > > > > > At 08:07 PM 5/19/2003, you wrote: > > > > > > > > maybe there's a MS #define that lists the function name? > > > > > > > >yep. __FUNCTION__ > > > > > > In what version? MSVC++ 6 certainly doesn't expose it. > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.net email is sponsored by: ObjectStore. > > > If flattening out C++ or Java code to make your application fit in a > > > relational database is painful, don't do it! Check out ObjectStore. > > > Now part of Progress Software. http://www.objectstore.net/sourceforge > > > _______________________________________________ > > > Gamedevlists-general mailing list > > > Gam...@li... > > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > > > Archives: > > > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: ObjectStore. > > If flattening out C++ or Java code to make your application fit in a > > relational database is painful, don't do it! Check out ObjectStore. > > Now part of Progress Software. http://www.objectstore.net/sourceforge > > _______________________________________________ > > Gamedevlists-general mailing list > > Gam...@li... > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ObjectStore. > If flattening out C++ or Java code to make your application fit in a > relational database is painful, don't do it! Check out ObjectStore. > Now part of Progress Software. http://www.objectstore.net/sourceforge > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Peter D. <pd...@mm...> - 2003-05-20 10:01:08
|
Ken Paulson wrote: > At 08:07 PM 5/19/2003, you wrote: > >>> maybe there's a MS #define that lists the function name? >> >> yep. __FUNCTION__ > > In what version? MSVC++ 6 certainly doesn't expose it. 7 and above. __FUNCSIG__ is even better. |
From: Ken P. <ke...@dr...> - 2003-05-20 10:28:08
|
One more thing to nudge me towards an upgrade I suppose... At 05:00 AM 5/20/2003, you wrote: >Ken Paulson wrote: > > At 08:07 PM 5/19/2003, you wrote: > > > >>> maybe there's a MS #define that lists the function name? > >> > >> yep. __FUNCTION__ > > > > In what version? MSVC++ 6 certainly doesn't expose it. > >7 and above. __FUNCSIG__ is even better. > > >------------------------------------------------------- >This SF.net email is sponsored by: ObjectStore. >If flattening out C++ or Java code to make your application fit in a >relational database is painful, don't do it! Check out ObjectStore. >Now part of Progress Software. http://www.objectstore.net/sourceforge >_______________________________________________ >Gamedevlists-general mailing list >Gam...@li... >https://lists.sourceforge.net/lists/listinfo/gamedevlists-general >Archives: >http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Daniel V. <vo...@ep...> - 2003-05-20 19:18:51
|
> > In what version? MSVC++ 6 certainly doesn't expose it. > > 7 and above. __FUNCSIG__ is even better. Learning something new every day - thanks! Time to upgrade some macros :) -- Daniel, Epic Games Inc. |
From: George W. <ge...@ap...> - 2003-05-20 16:29:39
|
On Mon, 19 May 2003 13:57:48 -0500, "Corrinne Yu" <cor...@sp...> wrote: > One thing I would like to do to it is to start removing un-used > functions. A "low tech" solution would be to "#if 0" disable all the routines in a selected sub-set of source file and then try to build your project. When the linker complains go back and re-enable (un-disable) the "missing" routines. -- Enjoy, George Warner, Schizophrenic Optimization Scientists Apple Developer Technical Support (DTS) |
From: Colin F. <cp...@ea...> - 2003-05-19 20:40:05
|
Perhaps you could profile your code (Linux: gprof? Windows: VC++ 6.0 profile option), and dump the output to a text file. Report the function entry counts, not timings or line numbers. Strip out functions with non-zero total entries (if list is sorted by counts, just chop off the non-zero part of the list). What you do next depends on what you want to do, and how much work you are willing to put in to this. For me it would be fairly easy to write a program to use the list of functions to search through all source code files, identify both calling instances and function implementations, and prompt the user to approve proposed changes (e.g., removal or commenting out). It's tricky for situations like: if (never_true) { if (unused_function( x, y, z )) { // ... } } and: f = unused_function( x, y, z ); since you have to do more than strip out the function call itself! But maybe you CAN just strip out the function calling instance, and replace with a blank, or junk, and wait for compile errors to alert people to required fixes. That sounds risky. If you go with the prompting approach, you can have your utility propose a variety of substitutions for the block and vicinity. Based on the context you can come up with one or more likely "fixes" that the user can choose from. I'm sure hitting single keys for "SKIP", "PROPOSED MODIFICATION #1", "PROPOSED MODIFICATION #2", etc, per fix, would be a very fast process for a human. If you have methods with identical names in several C++ classes, things get a little trickier, since you are starting to do the work of the compiler to analyze code! Actually, this whole thing sounds like a fun utility to write, like "lint", but with the added information from a profiler. Maybe such a thing already exists... --- Colin ----- Original Message ----- From: "Tom Forsyth" <to...@mu...> To: <gam...@li...> Sent: Monday, May 19, 2003 12:38 PM Subject: RE: [GD-General] remove unused functions > Maybe you can add a prologue to every function that does two things: > > (a) declares a static instance of a class whose constructor adds the string > "__FILE__ __LINE__" to a table. > > (b) when it is called, finds and removes the string from the table. > > > Play the game for a while, go through as many different codepaths and > behaviours as you can think of, then dump the table to disk or whatever. And > there you go - a list of all the functions (well, where they are - maybe > there's a MS #define that lists the function name?) that haven't been called > this time around. > > Then add ASSERT (!"Nobody ever calls me or they would have removed this > assert") to each file, leave it a couple of weeks, and then kill all the > functions that still have that assert. > > > Tom Forsyth - Muckyfoot bloke and Microsoft MVP. > > This email is the product of your deranged imagination, > and does not in any way imply existence of the author. > > > -----Original Message----- > > From: Corrinne Yu [mailto:cor...@sp...] > > Sent: 19 May 2003 19:58 > > To: gam...@li... > > Subject: [GD-General] remove unused functions > > > > > > The game engine and game code base has gotten very very big. And it is > > about time to clean things up and improve its structure and > > documentation. > > > > One thing I would like to do to it is to start removing un-used > > functions. I tried to use MSDev to remove un-referenced functions as a > > start but didn't find any. It turns out quite a few of the "un-used" > > functions are "referenced" (and thus can't be that easily > > automatically > > determined) but I know from how the game and engine code is > > supposed to > > run that they won't ever be called. > > > > They are not exactly unreachable code either, so doing the unreachable > > code thing also doesn't work. > > > > I truly "dread" :D the idea to have to manually step through all the > > code and manually cull out every single un-used function by > > hand (it is > > a lot of code to wade through!). I wonder what tools exist inside of > > MSDev (or simple easy to use small external tools) that can help me in > > my highly un fun task of cleaning up my code base, specifically in the > > task of removing "un-used" functions. > > > > Thank you for your experience in this task, and your suggestions. > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: ObjectStore. > > If flattening out C++ or Java code to make your application fit in a > > relational database is painful, don't do it! Check out ObjectStore. > > Now part of Progress Software. http://www.objectstore.net/sourceforge > > _______________________________________________ > > Gamedevlists-general mailing list > > Gam...@li... > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=557 > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ObjectStore. > If flattening out C++ or Java code to make your application fit in a > relational database is painful, don't do it! Check out ObjectStore. > Now part of Progress Software. http://www.objectstore.net/sourceforge > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=557 |