Global change of naming convention

B

bim_bom

Hi,
is there any tool to change naming convention in c++ sources?
I mean something, that parses cpp and h files in my project, and it finds,
what variables are there declared. I think, it should have a public
"CALLBACK" function (which would be impemented by me), which would tell the
program, how to rename variables and functions.

It should work like that:

I have sourcecode:

const int GLOBALX=1;

int main()
{
int VAR=2;
};

This program would parse this file, and find, that there are 2 variables:
GLOBALX and VAR. This function to tell, how to change names (created by me)
would look like this:

char * ChangeNameToWhatName(char *OldName,char *Type,bool IsGlobal)
{
char *dup=strdup(OldName); // make a copy
for(int a=0;a<strlen(dup);++a) // make to lower
dup[a]=tolower(dup[a]);
if(IsGlobal) // if global variable, change first letter to uppercase
dup[0]=toupper(dup[0]);
}

and after that, this program should change my sourcecode to:

const int Globalx=1;

int main()
{
int var=2;
};

I know, that sometimes there are variables of the same name dclared in 2 or
more different places, but this program could exclude these variables from
changing, so that exrything would compile after that without problems.

Are there any such parsing programs? I want to change naming convention in
my program, and don't want to do it manually ;)

I don't use many macros, so this program don't have to be "#define - aware".
 
B

bim_bom

char * ChangeNameToWhatName(char *OldName,char *Type,bool IsGlobal)
{
char *dup=strdup(OldName); // make a copy
for(int a=0;a<strlen(dup);++a) // make to lower
dup[a]=tolower(dup[a]);
if(IsGlobal) // if global variable, change first letter to uppercase
dup[0]=toupper(dup[0]);
}

Of course it should end like that: "return dup;"
 
F

F.J.K.

bim_bom said:
Hi,
is there any tool to change naming convention in c++ sources?
I mean something, that parses cpp and h files in my project, and it finds,
what variables are there declared. I think, it should have a public

If all your variables are VARIABLES and all your functions are
FunctionsDoingSomething() those should be recognizable patterns. Any
good text editor or a simple sed script would do that. Google for
"regular expressions".
 
B

bim_bom

Uzytkownik "F.J.K. said:
If all your variables are VARIABLES and all your functions are
FunctionsDoingSomething() those should be recognizable patterns. Any
good text editor or a simple sed script would do that. Google for
"regular expressions".

Is it that simple? I think, that finding declarations is quite easy, but I
wanted to make my naming convention based on more things - if this is const,
or if this is a pointer, or if this variable is a member of function, of
class, or is it global. I would not be able to write it in "regular
expressions" - this is not a language for me ;) If nobody helps me, I think
I will write this "parser" by myself.
 
F

F.J.K.

bim_bom said:
Is it that simple?

Yes it is
I think, that finding declarations is quite easy, but I

No it isn't, at least not in the general case.
wanted to make my naming convention based on more things - if this is const,
or if this is a pointer, or if this variable is a member of function, of
class, or is it global.

Are you trying to create reasons why you can't just do it now? In that
case the following recipee should quell all that efforts ;-)
a) find all tokens to change with ctags -x
b) use the output to get valid substitution rules for sed or a text
editor.
c) apply the substitution rules
Automate this as much as you (want/need/it makes you finish faster) by
scripting. (Tcl/TK/bash/python/perl..., whatever turns you on).
I would not be able to write it in "regular
expressions" - this is not a language for me ;)

"Those who don't understand regular expressions are doomed to reinvent
them - poorly."
If nobody helps me, I think
I will write this "parser" by myself.

Have fun!

What you describe is a C++ syntax parser and will need the efforts of
at least several months. Oh, btw, I think the whole project is
pointless to start with. Use the new convention for new code and let
the old code rot in peace.

Anyway, not really a C++ issue, rather an issue of bad time management
;-(

FJK
 
J

Jens Theisen

F.J.K. said:
What you describe is a C++ syntax parser and will need the efforts of
at least several months. Oh, btw, I think the whole project is
pointless to start with. Use the new convention for new code and let
the old code rot in peace.

There are C++ parsers already, naturally, that could be used to build
something on top of that with this functionality.

It is not unconceivable that such a tool exists, and it would certainly
be useful, so I think the question is valid an interesting. I don't
think there is such a tool though.

Jens
 
F

F.J.K.

Jens said:
It is not unconceivable that such a tool exists, and it would certainly
be useful, so I think the question is valid an interesting. I don't
think there is such a tool though.

A tool would only be useful, if changing naming conventions was. And it
is not, in 99.9% of all cases ;-) See
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.12

But go ahead, everybody is entitled to waste his time the way he likes
it best ;-)
 
B

bim_bom

Uzytkownik "F.J.K. said:
A tool would only be useful, if changing naming conventions was. And it
is not, in 99.9% of all cases ;-) See
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.12

But go ahead, everybody is entitled to waste his time the way he likes
it best ;-)

I know that changing everything manually would be very long, but if it would
be done automantically, it would henp very much. In my programs all
functions, methods, macros, and variables are in the same naming convention
and changint it automatically would make my code look better and simpier to
read
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top