By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,423 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,423 IT Pros & Developers. It's quick & easy.

Global change of naming convention

P: n/a
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".
Sep 1 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a

Użytkownik "bim_bom" <ju******@go2.plnapisał w wiadomości
news:ed**********@news.onet.pl...
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;"
Sep 1 '06 #2

P: n/a
bim_bom schrieb:
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".

Sep 1 '06 #3

P: n/a

Uzytkownik "F.J.K." <fe***********@gmail.comnapisal w wiadomosci
news:11*********************@m73g2000cwd.googlegro ups.com...
bim_bom schrieb:
>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".
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.
Sep 1 '06 #4

P: n/a
bim_bom wrote:
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?
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

Sep 1 '06 #5

P: n/a
F.J.K. wrote:
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
Sep 1 '06 #6

P: n/a
Użytkownik "bim_bom" <ju******@go2.plnapisał w wiadomości
news:ed**********@news.onet.pl...

I found a tool which does many thing, including "changing naming
convention", but it costs 1000USD ;)
Sep 2 '06 #7

P: n/a
Jens Theisen wrote:
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-lit...html#faq-27.12

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

Sep 5 '06 #8

P: n/a

Uzytkownik "F.J.K." <fe***********@gmail.comnapisal w wiadomosci
news:11**********************@b28g2000cwb.googlegr oups.com...
Jens Theisen wrote:
>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-lit...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
Sep 5 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.