The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Automated code modification for adherence to coding guidelines.
Discuss Automated code modification for adherence to coding guidelines. in the C Programming forum on Dev Shed. Automated code modification for adherence to coding guidelines. C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 11th, 2012, 12:06 AM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 11 m
Reputation Power: 0
|
|
|
Automated code modification for adherence to coding guidelines.
Hello,
I have this task to restructure and clean huge amounts of code, including removal of junk code, changing functions/variables names to adhere to naming conventions and similar changes.
Can you please let me know of any tools which can help me automate it as much as possible.
I came across coccinelle. Just wondering what are the other better options ?
Thanks,
Mohit
|

October 11th, 2012, 05:43 AM
|
 |
I'm Baaaaaaack!
|
|
Join Date: Jul 2003
Location: Maryland
|
|
|
While there might be something out there, I haven't seen anything and I have done this a time or twain in the past. Cleaning up code is a huge pain in the ***, I don't envy you your task. If you know unambiguously that the code is built into a finite (and small) number of end products (libraries, executables, etc) then you could try what I have done a number of times and simply start removing chunks of code from the code base and rebuilding. Tedious, I know, particularly if the code base is huge. Once, several years ago, I tried to do some semi-automated analysis by using 'ctags' and 'nm' to find code in the repo that wasn't also in any of the binaries with a bit of success. As I recall (it was some 3 years ago at a different company) I took the output of one (nm, I believe) and 'diffed' it with the other to reveal the bits that were not the same, then started to remove those chunks from the repo and rebuilding. Of course, if no one is using some of your binaries (as was the case for me and ultimately why I stopped bothering) then this 'trick' won't really help.
As for formatting, there are 'beautifiers' that can handle that aspect, I seem to recall something called 'bcpp' (or 'bc' for C code). I _think_ it would also modify comments for you as well, but it was quite a while ago when I played with it regularly.
As for bringing variables, etc. into compliance, find and replace is your only friend here and it is quite possibly only a fair weather friend. If past developers didn't provide any sort of scope tags in their naming conventions (I personally _like_ that aspect of Hungarian Notation, though have since given up taking the data type to the name, for the most part, since modern IDEs will identify the type for you with mouse hover) then a wide-scale find and replace will likely cause more heartburn than it treats. While some IDEs will allow for find and replace in a selected block of code, another alternative is to copy the function/method to a temporary file, do find/replace there, then copy back. Again, quite tedious.
An important note here: doing any sort of wholesale changes like this _without_ a comprehensive suite of regression tests is just asking for problems. Just because something compiles does _not_ mean that it functions correctly!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|