Hi again...
I need a tool which parses a source code (especially a c++ code) and generates a new one, that's all the unused parts of the original source code (such as includes, macros, functions, variables, ...) is removed in it.
I think, this tool helps in reducing compile time and run time; also makes the code more cleaner which makes debugging easier.
Is there such a tool? If no, how can I produce this tool? (I mean, how can I recognize unused parts of a my code?)
Any help would be appreciated!
Well, I try to do that in my plugin using CLion API, but sometimes it deletes more than needed because CLion doesn't find references correctly.
See removeUnusedCode and DeletionMarkingVisitor
Maybe you could do something similar or start here and workaround broken search
I don't use CLion. I plan to test it with your plugin (JHelper), maybe later!
Could you please explain the idea behind it? how does it work? I don't know anything about Java!
Well, the idea is someone (CLion devs) parse c++ and represent source as tree of abstract objects like "function call" or "class declaration" and also provides a way to find where some object used. My code is a pretty straightforward usage of that API.
I don't think one should need java to read that code, it's pretty clear if you used any cstyle language
Great! what about I don't have this tree?! How can I generate it?
Is there any other solution for this except making a tree of abstractions?!
I think, this functionality can be find in compiler. What's your idea?
Do you know any other tools?
How can I test/use this API and your functionality outside of the CLion?
You may try to decompile their code and check what they do:)
I think, it's harder than making a new API. Do you agree?! What about any other solution?
How can I use the standalone version of this cleaner?
I've found ahmed_aly add a unused code cleaner for KawigiEdit (a Topcoder plugin).
Anybody knows this feature and the way it works?
My caide tool removes (some of) unused C++ code too :). You can test it like this:
The file submission.cpp will be created with unused code removed.
I can make a standalone code cleaner if you like it.
Thanks for your reply.
Could you please explain how does it work? Which strategy you used to recognize unused codes?
How can I use this code cleaner standalone?
It uses clang API to parse the AST and detect code unreachable from main().
You cannot yet. I will need to build another executable for that.
I've checked here for clean, but I don't get anything. Could you please explain?
Ahem, by "cleaning" test/test.cpp I meant replacing it with an empty file :)
:D Aha...
I try to make the standalone version of cleaner.
https://github.com/slycelote/caide/releases/tag/cppinliner-0.1
You may need to add paths to system include directories like this:
-isystem /full/path
(before the--
separator). In Linux you can see which directories are required withg++ -v -x c++ -E /dev/null
Thanks for the standalone version! I couldn't use it. I've downloaded this for linux. After the extraction, it gives me an executable file with name "cppcleaner-linux".
How can I clean a code with it?
Let's continue in PM