Can I use SN to ask questions about C++?

Ian Roxborough irox@redhat.com
Sun Sep 24 12:41:00 GMT 2000


Mark Stankus wrote:
>   I was wondering if there is an API for SN so that I could write small
> programs
> (or write data base queries) to ask questions about the C++ code which
> has been "SN-ed".
> The goal is to look for inefficiencies in C++ code and improve
> maintainability of C++ via computer programs.

Code Refactoring.  This is something I want to add to SN sometime
down the line.  The requirements of code refactoring would make a 
good start for how well the parsers should work.

> The questions below are samples (requiring some
> SQL would be
> fine or, even better, a C++ interface).
> 
> (Note, if any of the following questions can be answered by an existing
> tool,
> I would like to know.)

There is documentation on the database API (Programmers Reference Guide)
with should help you do most of these things.

Note: alot of these questions seem to require knowledge about the
compiler and action the compiler will take, SN knows nothing about
what the compiler is thinking.  But hopeful you should beadle to
get the information you need from the database.

> 1) Determine all class names which have a default constructor generated
> by the compiler.

Is this the same as "Determine all class name which don't have a
default constructor in the source code".

> 2) Determine all class names which have a default constructor generated
> by the compiler
>    and it is used.

> 3) Determine all class names which have a copy constructor generated by
> the compiler.
> 4) Determine all class names which have a copy constructor generated by
> the compiler
>    and it is used.

I don't really know enough about C++ to answer this.

> 5) Find all class names which use the macro
> USE_GENERATED_DEFAULT_CONSTRUCTOR

This should be relative easy.

> 6) Find all class names which use the macro
>    USE_GENERATED_DEFAULT_CONSTRUCTOR, and define a default constructor.
>    ( This would be some "AND" in terms of data base queries or a list
> intersection
>      for a C++ interface. )
>    (BY THE WAY, I would like to start putting EITHER
> USE_GENERATED_DEFAULT_CONSTRUCTOR or X()
>     but not both in every class X which I write so that my intentions
> are clear.)
> 7) Find all instances of 'bool operator==(unsigned int,int)' in the
> code.
>    (For example,  int main() {
>                     unsigned int a,b;
>                     int c;
>                     bool d = a==b;
>                     bool e = a==c;
>                     bool f = 0==1L;
>                     bool g = 0U==1;
>                     return 0;
>                   }
>                   would indicate the 'e' and 'g' lines.)

This could probably be done with a little hacking.
Maybe improving the C++ parser could help a little here.
 
> 8) Determine all locations where adding the keyword 'explicit' to a
>    constructor, say 'X(const Y &)', will create a compiler error.
>    (See http://www.calpoly.edu/~mstankus/mozilla )
> 9) Find all locations where adding the keyword 'explicit' to the code
>    wherever appropriate would generate compiler errors.
>    (See http://www.calpoly.edu/~mstankus/mozilla )
> 10) Determine when temporaries are created.

I'm not sure if SN handles the keyword 'explicit' (if it doesn't
choke it might just ignore it).

How can we determine when temporaries are created?
(by looking at the source code).

Ian.


More information about the Sourcenav mailing list