I'm looking for a tool, regex or other magic to do some heavy code replacements.
Ideally I would be able to replace all instances of the new
operator with a call to a function preserving the arguments.
What are my options?
Update:
Example:
ClassA* a = new ClassA<int>(1,2,3,4,new ClassB(1,2),"horrible");
Should transform to:
ClassA* a = FUNCTION(ClassA<int>(1,2,3,4,FUNCTION(ClassB(1,2)),"horrible"));
Where FUNCTION will do something like:
FUNCTION(...) Debug(new __VA_ARGS__, __FILE__)
A simple replace nearly does it well, it only lacks the last )
.
Update:
My initial thought was to use a macro to track some additional info like __FILE__
, store it in a std container and then call new. What will happen if the container calls new? How do I add __FILE__
inside an overloaded new?