Is there some way to get info from libclang whether C++ code in source file has correct syntax? Libclang tries to create translation unit even with not valid C++ code.
The generic answer for the generic question is yes. Take a look at this Sublime Text plugin that uses libclang to do that: https://github.com/quarnster/SublimeClang.
It uses the libclang Python binding to process the current file in the editor and flag errors and warnings, as well as providing other useful features like auto-completion and 'Go to definition'.
Related
I would like to build a visual studio code extension for include what you use. In order to properly invoke the tool I must find out which parameters are passed to the compiler. I know I can retrieve this data form the "compile_commands.json" file.
I was wondering if it is possible to retrieve this from the running vscode c/c++ plugin.
vscode c/c++ plugin requires this file itself to provide better IntelliSense, otherwise it uses own tag parser algorithms and knows nothing about compile instructions for particular file.
I have a prebuild-event tool (written in Ruby) in my C++ toolchain, that generates additional C++ code from existing C++ source code. I would like to replace this tool with a faster generator and using clang would be the best option.
Is there a way to write a C++ application that parses C++ source code of a file, so I can implement this prebuild tool in Clang? I am looking for a keyword or page with how to start. Any help is highly appreciated!
Parsing C++ is not a simple thing. Compile-time trickery and implicit semantics make it incredibly hard. Because of this I would suggest going with Clang. Its developers made it possible to use Clang as a library. Check out this guide to see different interfaces Clang has. If you want real C++ experience you might want to choose LibTooling.
I want to warn you though that in order for any C/C++ parser to work as expected they absolutely need compilation options used by the real compiler. Without include directories or macro definitions the code can make little to no sense. Basically your build system should tell your custom tool how to compile each file. The simplest approach would be using compilation database. It is a go-to solution for many Clang-based tools. However, it looks like you're making it a part of your build system, so maybe incorporating your tool and using options directly from the build system can be not such of a burden for you.
I hope this information is helpful!
I am new to antlr.
Can somebody provide a working example for any simple grammar in antlr for C++ target. I tried antlrworks and created the lexer and parser. But am not able to proceed while getting it compiled. Searched in codeproject also for a working sample, but dint find any.
I am planning to use Visual Studio 2013. Thanks in advance...
I've used ANTLR3 in a C++ application for years already, but actually used the C target, not C++. The latter proved to be a problem both in terms of compilation speed (for a highly complex parser) and complexity (all based on templates). So I settled on the C target, which is easy to integrate into C++ application. You only need a small C++ wrapper for your app and you will get a really fast parser.
In case of C++ target try this branch: https://github.com/ibre5041/antlr3/tree/master/runtime/Cpp/tests. This is more up to date version, including various performance bug fixes, memory leak fixes and also AST generation.
In the tests directory you find some examples.
Now I'm not sure whether it will work with MSVC 2013, I recall I used some C++11.
It would be best if you compiled the whole tool from these sources, not only the runtime is different, but also generated source codes slightly differ.
No not use Java 8 to compile and run antlr tool. For some mysterious reason JRE8 generates different sources then JRE7, when using the same tool .jar.
When having your grammar compiled (sources are generated), then you have to create, a traits class to be used as "configuration" for generated sources.
Up to now i tried Eclipse, KDevelop and Code::Blocks.
Code::Blocks (12.11) seems not to be able to display documentation at all.
Eclipse (4.3.2) is able to display the documentation of at least the standard libraries during code completion and on hover, but it looks like there is no way to generate or add custom documentation. By now I was able to use DoxygenCPPInfo to convert the xml documentation to a "Java Serialization Data" file, which is useable by libhover. But the documentation is only visible on hover, but not on code completion.
KDevelop (4.7) does only show the comment, which normally contains the documentation, on hover and a heavily shortened version on code completion.
Is there another IDE or something else I could do to benefit from in code documentation while writing new code?
DoxygenCPPInfo can be compiled using the following files from eclipse-linuxtools:
ClassInfo.java
FunctionInfo.java
LibHoverInfo.java
MemberInfo.java
TypedefInfo.java
DoxygenCPPInfo.java
The xml documentation needs to be in one file to be used with DoxygenCPPInfo. This can be done by using xsltproc with combine.xslt and index.xml as input files. The final output of DoxygenCPPInfo can be placed in workspace/.metadata/.plugins/org.eclipse.linuxtools.cdt.libhover/CPP/ and will be loaded on next start of eclipse using that workspace. The documentation is only shown on hover and not on code completion.
You want to document a function in one file and use that function in another file. While using that function you want to reference the documentation written earlier in a tooltip without having to compile the first file. This can be done easily in kdevelop ide. There are not much IDEs I have come across that provide such ease of cross-referencing. Eclipse lib-hover plugin for C but it is clunky and I have had trouble working with that earlier. Here is the link to kdevelop-handbook .
Documenting in doxygen style in kdevelop
I'm a vi user for coding in Python. I love it: powerful, lowlevel, minimal gui without useless buttons, etc.
Now I'm approaching C++ with an opensource project that—as usual happened in opensource project—has poor documentation and sometimes (well, a lot of times) I have to open declaration and implementation and see what a particular function does.
In Eclipse this is really easy to do due to the Open Declaration (shortcut F3) feature. But I don't like the CDT plugin for Eclipse. I have a makefile project and it indicates some error in importing external .cpp files inside this opensource framework that requires a custom structure for directory and build path (and it's annoying to create a project every time in Eclipse for this custom structure).
I wish to have the same feature in vi. Do you know of anything?
Vim doesn't offer a feature like that by itself. A rudimentary way would be to use gd in command mode. If you want more sophisticated support, take a look at ctags and cscope. Those tools offer which you ask for and integrate nicely into Vim. A quick google search brought me to this link, which explains how to use cscope within Vim. Using ctags quite as easy: generate the ctags database/tags file and use Ctrl+] on an identifier to jump to its declaration. See :help ctags for more information.
One option: Use QT Creator with FakeVim mode enabled. You can follow declarations with F2.