Generating a Vapi file for a Vala library - vala

I've got a library written in Vala that has always worked fine generating a .vapi file for itself, I think because it's a free operation with valac but I'm not positive on that. I went and tried to use VAPIGEN_CHECK in my configure.ac file and the associated VAPIGEN_MAKEFILE in my Makefile.am and now I get:
error: The type name `GLib.TypeInstance' could not be found
My corresponding .gir file contains:
<field name="parent_instance">
<type name="GObject.TypeInstance" c:type="GTypeInstance"/>
</field>
So the error seems to make sense because I can't find the GObject.TypeInstance class/struct in any .vapi file, but GTypeInstance is in one of the GLib headers.
Should I even be doing it this way if I'm writing everything in Vala already? Is there a possibility that this is missing from the Vapi?
Edit: Possibly just due to my not deriving GLib.Object which I thought was implicit. Still trying to fix something else that prevents this but once that's done I will update this to say whether or not it actually matters.

To generate a VAPI file from a Vala program you should simply use the --vapi option with valac, e.g.:
valac --vapi my_library_name.vapi my_library.vala
From what you are describing I think you are generating a GIR (GObject Introspection Repository) file with valac, then using vapigen to create the VAPI file. vapigen is part of Vala and maintained in the Vala source code, but it is a tool for generating a VAPI file to bind to non-Vala projects. If the non-Vala project distributes a GIR file it makes the binding very easy.
When using vapigen you need to give the packages it uses, so you need to check you are including the right pkg-config flags, e.g.:
vapigen --pkg glib-2.0 --pkg gobject-2.0 my_library.gir
The other possibility is there is no binding for GTypeInstance in Vala. I've had a quick look and I'm not finding anything.

Related

Objectbox configuration for Swift Package

I would like to use objectbox inside a swift package, not inside a project, but on the documentation I couldn't find a procedure to follow to complete the operation.
I found no problem adding the library as a dependency:
.package(url: "https://github.com/objectbox/objectbox-swift", from: "1.8.0")
My problem is finding the correct strategy to use the code generator.
The documentation and scripts in the package say to call Sourcery like this:
"$sourcery" --xcode-project "${PROJECT_FILE_PATH}" --xcode-target "${TARGETNAME}" $MODULENAME1 $MODULENAME2 $#
In my case, the entities are present in my Package, so inside a directory, it would be correct if I use the Sourcery based ObjectBox code generator indicating the path "source" and the "output" instead of the project "--xcode-project " and of the "target"?
If this is not the correct way to go, do you have alternative ideas?

Add 'library' directive to dart code generated using protoc

Can someone tell me how to get protoc to generate dart files with a leading library directive?
I'm using the dart-protoc-plugin (v0.10.2) to generate my dart, c++, c#, js and java models from proto files. I was under the impression there was no way to get protoc to add a 'library' directive to the generated dart files, until I noticed the directive appearing in another project (see date.pb.dart).
If I take the same file (date.proto) I cannot get protoc to generate a dart file containing a 'library' directive.
In short: I want to take a .proto file with the following content
syntax = "proto3";
package another.proj.nspace;
message MyObj {
...
}
and produce a .dart file with a leading 'library' directive similar to the following snippet
///
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
library another.proj.nspace;
...
NOTE: I don't care about the actual value of the directive since I can restructure my code to get the desired result. I just need a way for protoc to add the library directive...
The basic command I'm using to generate the dart files is
protoc --proto_path=./ --dart_out="./" ./another/proj/nspace/date.proto
Unfortunately the dart-protoc-plugin's README isn't very helpful and I had to go through the source to find out which options are available; and currently it seems like the only dart-specific option is related to grpc.
I've tried options from the other languages (e.g. 'library', and 'basepath') without any success.
It would simplify my workflow quite a bit if this is possible, but I'm starting to get the impression that the library directive in date.pb.dart is added after the code was generated...
After asking around a little bit, it seems that the library directive was removed from the protoc plugin at some stage (see pull request), thus it is no longer supported.

AST of a project by Clang

I use the Clang python binding to extract the AST of c/c++ files. It works perfectly for a simple program I wrote. The problem is when I want to employ it for a big project like openssl. I can run clang for any single file of the project, but clang seems to miss some headers of the project, and just gives me the AST of a few functions of the file, not all of the functions. I set the include folder by -I, but still getting part of the functions.
This is my code:
import clang.cindex as cl
cl.Config.set_library_path(clang_lib_dir)
index = cl.Index.create()
lib = 'Path to include folder'
args = ['-I{}'.format(lib)]
translation_unit = index.parse(source_file, args=args)
my_get_info(translation_unit.cursor)
I receive too many header files not found errors.
UPDATE
I used Make to compile openssl by clang? I can pass -emit-ast option to clang to dump the ast of each file, but I cannot read it now by the clang python binding.
Any clues how I can save the the serialized representation of the translation units so that I will be able to read it by index.read()?
Thank you!
You would "simply" need to provide the right args. But be aware of two possible issues.
Different files may require different arguments for parsing. The easiest solution is to obtain compilation database and then extract compile commands from it. If you go this way be aware that you would need to filter out the arguments a bit and remove things like -c FooBar.cpp (potentially some others), otherwise you may get something like ASTReadError.
Another issue is that the include paths (-I ...) may be relative to the source directory. I.e., if a file main.cpp compiled from a directory /opt/project/ with -I include/path argument, then before calling index.parse(source_file, args=args) you need to step in (chdir) into the /opt/project, and when you are done you will probably need to go back to the original working directory. So the code may look like this (pseudocode):
cwd = getcwd()
chdir('/opt/project')
translation_unit = index.parse(source_file, args=args)
chdir(cwd)
I hope it helps.

Add #include's to the headers of a program using llvm clang

I need to add headers to an already existing program by transforming it with LLVM and Clang.
I have used clang's rewriter to accomplish a similar thing in the changing function names and arguments, etc.
But the header files aren't present in clang's AST. I already know we need to use PPCallbacks (https://clang.llvm.org/doxygen/classclang_1_1PPCallbacks.html) but I am in dire need of some examples on how to make it work with the rewriter if at all possible.
Alternatively, adding a #include statement just before the first
using namespace <namespace>;
Also works. I would like to know an example of this as well.
Any help would be appreciated.
There is a bit of confusion in your question. You need to understand in details how the preprocessor works. Be aware that most of C++ compilation happens after the preprocessing phase (so most C++ static analyzers work after that phase).
In other words, the C++ specification (and also the C specification) defines first what is preprocessing, and then what is the syntax and the semantics of the preprocessed form.
In other words, when compiling foo.cc your compiler see the preprocessed form foo.ii that you could obtain with clang++ -C -E foo.cc > foo.ii
In the 1980s the preprocessor /lib/cpp was a separate program forked by the compiler (and some temporary foo.ii was sitting on the disk and removed at end of compilation). Today, it is -for performance reasons- some initial processing done inside the compiler. But you could reason as if it was still separate.
Either you want to alter the Clang compiler, and it deals (like every other C++ compiler or C++ static analyzer) mostly with the preprocessed form. Then you don't want to add new #include-s, but you want to alter the flow of AST given to the compiler (after preprocessing), and that is a different question: you then want to add some AST between existing AST elements (independently of any preprocessor directives).
Or you want to automatically change the C++ source code. The hard part is determining what you want to change and at what place. I suppose that you have used complex stuff to determine that a #include <vector> has to be inserted after line 34 of file foo.cc. Once you've got that information (and getting it is the hard thing), doing the insertion is pretty trivial. For example, you could read every C++ source line, and insert your line when you have read enough lines.

is there a good way to find function define in header file in ace framework

As a ace framework newer, i always encounter some problem when using this framework.
I copy some example code from website and execute it in linux. however some error throw out because of no include correspond header file. for exmaple some error like this: error: ‘sleep’ is not a member of ‘ACE_OS’.
so how can i found this function define in which header file
Most easiest is just to do a "grep sleep $ACE_ROOT/ace/OS*.h", that tells you the file where this method is defined. Other option is to use the most recent doxygen tree at http://doxygen.theaceorb.nl/libace-doc/index.html

Resources