Started work on a tool to be included in Arduino code development. Want to parse all 10000 plus lines of "code" to "automatically" delete unused code. Not just commented out, deleted. Something similar to "Auto Format". Be happy to build just a custom class, not necessary to include in IDE as menu option, Maybe later. Never done "parsing " application and any free contributions will be appreciated. Cheers Vaclav
far from trivial.
Can you define unused code ? how do you want to determine?
you might investigate a tool like LINT ...
If I write the code in a sketch, I plan for that code to be used.
How would you determine that anything was unused?
Or are you thinking the IDE only?
I usually have basic concept of the program defined, however, things change as I go. At some point I find it prudent to replace / rename a function instead of keeping it modified. I find it handy to keep the old function just to remind myself what did and what did not work. Of course I can comment the unused function out when memory became an issue. (The program memory is OK , but just found out the hard way to keep an eye on RAM usage! ) When the project is done I would like to clean it up automatically, just being lazy.
If compiler can "assemble " the used / working stuff, why it could not be modified to delete unused function?
I'll take a look at LINT.
Vaclav: If compiler can "assemble " the used / working stuff, why it could not be modified to delete unused function?
The linker produces a list of discarded things, including function names , so this could be used to edit source files for specific cases. A completely general solution is impossible because of the macro preprocessor - the source code seen by the compiler may not correspond at all to the original input file.
If I want to keep old code for a bit I put it inside #ifdef OLD ... #endif. That guarantees it won't bloat the object code and is easy to tidy up later.
Thanks, I was just thinking similar way - the compiler builds a symbol table so if it is ASCII readable I could get started there. All my processing is done in setup function by functions , four in the last project. I could just check the symbol file for them and just parse each function again , recursively.
As far as using preprocessor to bypass the unused stuff, I already have about 10 of them using selected code during debug.
Seems as the best immediate solution, just KISS.
Either way - where are the descriptions of all the files Arduino compiler builds and where are they? Or do I have to go all the way to GCC??
I guess I skip this project for now. I have DDS output on "mother code" but zilch on the new derived code. I need to find the missing piece, bug , first!
the compiler builds a symbol table so if it is ASCII readable
It isn't. That would imply that it is written to a file.
If I were faced with the problem, I would use a combination of the gnu flex parser and bison compiler. they each produce c code to link with each other and your main();
I've even used them to translate source code from one language to source code for another language, ie. Oracle's Sql to MySql.
I've been using these tools (formally Unix lex and yacc) for over twenty years. I don't know how I'd have gotten along without them have to face a number of difficult parsing projects!