Page 1 of 1

Find class refences in a C++ file

Posted: Mon May 31, 2010 7:31 am
by passerby
I'm trying to match all class references in a C++ file using grep with regular expression. I'm trying to know if a specific include is usuless or not, so I have to know if there is a refence in cpp.
I wrote this RE that searches for a reference from class ABCZ, but unfortunately it isn't working as I espected:
grep -E '^[^(\/\*)(\/\/)].*[^a-zA-Z]ABCZ[]*[\*\(\<:;,{& ]'
^[^(\/\*)(\/\/)] don't math comments in the begging of the line ( // or /* )
.* followed by any character
[^a-zA-Z] do not accept any caracter before the one I'm searching (like defABCZ)
[]* any white space (I can have something like ABCZ var;)
[\*\(\<:;,{& ] followed by ( * < : ; , & { (I cant get #define "ABCZ.h" or ABCZdef for example)

Well, I can get patterns like this:
class Test: public ABCZ{
class Test: public ABCZ {
class Test :public ABCZ<T>
class NameSpace::Test :public ABCZ<T>
ABCZ var = ABCZ();
ABCZ* var = new ABCZ();
ABCZ* var = new ABCZ<T>();
teste = ABCZ(var);
teste = ABCZ(var, otherVar);
teste = ABCZ(var,otherVar);
teste = ABCZ();
funct(*ABCZ av);
struct(ABCZ, BBBB, CCCC);
const ABCZ& getNot_before(void) const;
That's all right, they are all acceptable patterns. But these I'm missing, and they are all acceptable too:
ABCZ teste;
ABCZ ¨¨¨¨ teste; //comment
ABCZ ¨¨ teste; /* comment*/
ABCZ teste;
ABCZ *teste;
¨¨ mean space...

And all these are not acceptable:
#include "ABCZ.h"
//ABCZ var = ABCZ();
ABCZdef a = ABCZdef();
DefABCZ a = DefABCZ();
ABCZdef a = ABCZdef();
/*ABCZ var = ABCZ();
I don't know if I'm missing any other patterns, if I am, please tell me =p
What am I doing wrong?
I'll be very grateful if someone answer me :)
Thanks in advance

Re: Find class refences in a C++ file

Posted: Mon May 31, 2010 11:19 am
by Weirdan
Parsing ctags output would be much easier.

Re: Find class refences in a C++ file

Posted: Tue Jun 08, 2010 6:42 am
by passerby
Thank you for your answer, I will try to use ctags