SVF icon indicating copy to clipboard operation
SVF copied to clipboard

Enhancement: Introduce an SVF namespace

Open gerion0 opened this issue 4 years ago • 8 comments

Especially when using SVF as library, it would be nice if all symbols and preprocessor constants are prefixed with SVF, i.e. to use a namespace SVF for C++ itself and the prefix "SVF_" for preprocessor constansts.

For example, I currently include the SVF with the following lines:

#define VERSION_BKP VERSION
#undef VERSION
#include <Graphs/VFGNode.h>
#include <SVF-FE/PAGBuilder.h>
#include <Util/BasicTypes.h>
#include <WPA/Andersen.h>
#undef VERSION
#define VERSION VERSION_BKP
#undef VERSION_BKP

gerion0 avatar Jul 16 '20 16:07 gerion0

Good suggestion! Would you be able to help us with adding SVF as the namespace?

SVF-tools avatar Jul 17 '20 03:07 SVF-tools

Hi guys, I'd be willing to help you with that. Especially in adding a C++ namespace. Please let me know how you'd like to proceed on this!

pzieris avatar Jul 27 '20 08:07 pzieris

Thanks, you could add a namespace called "SVF" for all the classes and methods. It would be good to do the minimum changes to the project.

yuleisui avatar Jul 27 '20 08:07 yuleisui

Hi Yulei, by the way, while adding the namespace I noticed that at lot of cpp files have using namespace SVFUtil but then either don't require the namespace at all or still call methods through SVFUtil::foo(). If it's okay with you I would remove all those unnecessary using namespace SVFUtil to clean up the code a bit. What do you think?

pzieris avatar Jul 30 '20 13:07 pzieris

Sounds good to me. Please go ahead and thanks.

yuleisui avatar Jul 30 '20 13:07 yuleisui

Hi again, I just started removing using namespace SVFUtil and adding SVFUtil:: to functions where necessary, when I realized how many calls to functions from the SVFUtil namespace there actually are. So, to be clear, when I continue with this, there will be a lot of changes.

As an alternative, I thought about keeping using namespace SVFUtil but then removing the SVFUtil:: everywhere to be consistent. However, after doing this for some files, compiling SVF gave me ambiguous calls to casting functions, e.g., to SVFUtil::dyn_cast() and llvm::dyn_cast(). As far as I see, the only option to continue with this alternative would be to remove include/Util/Casting.h altogether and instead rely on the LLVM casting functions. However, I cannot tell whether there is a reason why these casting functions are re-implemented in SVF?

Do you have any preference on how to proceed?

pzieris avatar Jul 30 '20 17:07 pzieris

remove include/Util/Casting.h would be a good option. Since we have too many dyn_cast and isa in SVF, can we remove llvm:: and typedef it here: https://github.com/SVF-tools/SVF/blob/master/include/Util/BasicTypes.h

yuleisui avatar Jul 31 '20 00:07 yuleisui

Not directly this namespace but goes in the same direction, therefore I mention it here. It would be nice if the headers also would be in an SVF directory.

So one has to write:

#include <SVF/Graphs/SVFG.h>

instead of

#include <Graphs/SVFG.h>

gerion0 avatar Aug 31 '20 00:08 gerion0