Generally, I see many people using :
CallSite CS(function->use_back());
to create callsite.
However, use_back() seems not appear in the lately released LLVM. So how can achieve the same goal in the newest LLVM.
How about Value::uses().Remember to take care of ConstantExprs and whatnot because in some cases the functions will go through a BitCastConstantExpr before being called
Related
I've been using LuaJIT for some times now. The tip of the iceberg was enought for my needs until now, but my recent project require me to dig a little deeper.
My actual knowledge of LuaJIT is making function available from C++ to Lua and from Lua to C++. That include passing parameters, tables and retrieving return values.
This is the model I am used to:
I tried to search around for "scoped environement luajit" and multiple variation of the query, but unfortunately I did not find anything relevant. I might not use the right words?
This is the model I want to achieve :
I want to make a "global script environment" that I will share the C++ functions with then make it available to the "scoped script environments".
//push arguments
luaScopedEnvironment1->call("doSomething");
I just want a starting point, help for the terminology and maybe some pointers to related documentation :)
Thanks you for taking time to read me.
I dont think Lua or LuaJIT supports such a thing but if I'm not mistaken, what you are after is called "sandboxing".
It creates a new environment with which you can strip out or add functionality to. Its handy for removing IO and OS functionality.
I know wrapping with macro can be used for getting caller of a function. But when it comes to constructors it is not possible as far as I know. I am not using gcc so backtrace() function is not an option for me.
Edit:
I am using msvc.
An ideal tool for this is a debugger, which doesn't require you to make any modifications to your program.
However, if you really want to get the caller locally within the program, that is also possible - but not in standard C++ without using platform specific or wrapper libraries (Except by modifying the constructor and using the macro trick).
I am not using gcc so backtrace() function is not an option for me.
Then you will need to figure out which compiler you are using, and use whatever alternative they provide for stack unwinding.
There is a portable library libunwind which you might use, that works without access to backtrace. It doesn't seem to be ported to windows however.
I know wrapping with macro can be used for getting caller of a function
Wrapping the initialization should work in a similar fashion.
I am embarking on setting up my VIM with better autocompletion, mainly for classes. In my google research I came across omnicppcomplete and clang. I can't seem to figure out the advantage/disadvantage of the two. Does anyone know?
Also, is one easier to install on third party systems than the other?
Any feedback will help. Thanks!
Clang really 'understands' c++. That means it can tell the difference between a local variable named foo and a member function named foo. If you want to complete thisObject.fo..., it will not give you the fooContainer completion, but only the Object::fooMethod.
Also, Clang can handle all C-type languages, which ctags cannot.
Omnicppcomlete is based on ctags, which is merely a textual index of your source tree. So it will be denser, will most of the time do what you want; sometimes it will be less accurate. Which isn't a real problem.
I have not yet installed the Clang completion though :( You probably have to build clang yourself, while ctags most likely comes with your distribution.
I'm working on some custom C++ static code analysis for my PHD thesis. As part of an extension to the C++ type system, I want to take a C++ code base and enumerate its available functions, methods, and classes, along with their type signatures, with minimal effort (it's just a prototype). What's the best approach to doing something like this quickly and easily? Should I be hacking on Clang to spit out the information I need? Should I look at parsing header files with something like SWIG? Or is there an even easier thing I could be doing?
GCCXML, based on GCC, might be the ticket.
As I understand it, it collects and dumps all definitions but not the content of functions/methods.
Others will likely mention CLANG, which certainly parses code and must have access to the definitions of the symbols in a compilation unit. (I have no experience here).
For completeness, you should know about our DMS Software Reengineering Toolkit
with its C++ Front End. (The CLANG answers seem to say "walk the AST"). The DMS solution provides an enumerable symbol table containing all the type information. You can walk the AST, too, if you want.
Often a static analysis leads to a diagnosis, and a desire to change the source code.
DMS can apply source-to-source program transformations to carry out such changes conditioned
by the analysis.
I heartily recommend LLVM for statical analysis (see also Clang Static Analyzer)
I think your best bet is hacking on clang and getting the AST. There is a good tutorial for that here. Its very easy to modify its syntax and it also has a static analyzer.
At my work, I use the API from a software package called "Understand 4 C++" by scitools. I use this to write all my static analysis tools. I even wrote a .NET API to wrap their C API. Which I put on codeplex.
Once you have that, dumping all class types is easy:
ClassType[] allclasses = Database.GetAllClassTypes()
foreach (ClassType c in allclasses)
{
Console.WriteLine("Class Name: {0}", c.NameLong);
}
Now for a little backstory about a task I had that is similar to yours.
In some years we have to keep our SDK binary backwards compatible with the previous years SDK. In that case it's useful to compare the SDK code between releases to check for potential breaking changes. However with a couple of hundred files, and tens of thousands of lines of comments that can be a big headache using a text diff tool like Beyond Compare or Araxis. So what I really need to look at is actual code changes, not re-ordering, not moving code up and down in the file, not adding comments etc...
So, a tool I wrote to dump out all the code.
In one text file I dump all all the classes. For each class I print its inheritance tree, its member functions both virtual and non-virtual. For each virtual function I print what parent class virtual methods it overrides (if any). I also print out its member variables.
Same goes with the structs.
In another file I print all the macro's.
In another file I print all the typedefs.
Then using this I can diff these files with files from a previous release. It then becomes apparent instantly what has changed from release to release. For instance it's easy to see where a function parameter was changed from TCHAR* to const TCHAR* for instance.
You might consider developping a GCC Plugin for your purpose.
And GCC MELT is a high level domain specific language (that I designed & implemented) for easily extend GCC.
The paper at GROW09 workshop by Peter Collingbourne and Paul Kelly on a A Compile-Time Infrastructure for GCC Using Haskell might be relevant for your work.
Is there a way to identify unused attributes/methods in Visual C++ 2008 Professional? If it's not possible by default, recommendations of 3rd-party tools are also much appreciated.
Thanks,
Florian
Edit: nDepend only works for .NET assemblies. I'm looking for something that can be used with native C++ applications.
Try PC-Lint. It's pretty good at finding redundant code.
I haven't tried version 9 yet. Version 8 does take some time to configure.
Try the online interactive demo.
I have not personally used their productivity tools (I use their windows control suit), but it looks like DevExpress has a C++ refactor'er called Refactor! for C++. I didn't immediately spot the features that you are looking for, but maybe they have it?
Coverage Validator can show unused C++ code (but not attributes). It does it dynamically so you have to 'exersize' the app to get the results:
http://successfulsoftware.net/2008/03/10/coverage-validator/
The tricky bit is that many functions in C++ have to exist, even if they are not called.
Boost especially will cause this, but even the regular STL code can do this. And your code has to play along. You might define a copy ctor because std::vector formally requires it. But if you don't instantiate any std::vector member that actually does copy a T, your copy ctor will remain unused.
Even if they don't have to, they often exist for safety. For example, declaring a private copy constructor can prevent an object from unintended copying. Without the private declaration, the compiler would define a public, memberwise copy ctor for you. Now, is this "unused" and do you want to be warned about them?
PC-Lint is very powerful, but hard to lean. Of course that pretty well describes C and C++ doesn't it?
Another tool I think is excellent is Whole Tomato's Visual Assist X which integrates right into the IDE.
There are some big gotchas in C++ when searching for unreferenced code: templates, callbacks, and message handlers may be critical to your project but are never directly called. For example the handler for a thread is not called directly, but is a parameter when you create a new thread. The "On_buttonpress" type messages in MFC or WTL projects will also show up as un-called methods.
Once you find them you can configure PC-Lint to ignore these, but the first time through its a lot of work.
nDepend will do it, along with cleaning your house and taking the dog for a walk. There's a nagware version available for free.
The following code query language statement will get you a list of unused methods
WARN IF Count > 0 IN SELECT TOP 10 METHODS WHERE MethodCa == 0 AND
!IsPublic AND !IsEntryPoint AND !IsExplicitInterfaceImpl AND
!IsClassConstructor AND !IsFinalizer