Doxygen for a multi-language API - c++

My company develops a API for engineering programs. It is developed in C++ but we create wrappers to it for the following languages:
a proprietary language that resembles VB
MATLAB
and Python.
Currently the documentation is generated by a bunch of scripts and it is starting to get time consuming to keep it 100%. I was wondering if there is a way to get doxygen/sphinx or another program to generate the documentation for C/C++, VB and MATLAB in one go. The Python part is done by SWIG. Currently the output is something like:
NameOfFunction
VB:
Function NameOfFunction(ByVal a As Long , ByRef b() As Long, ByVal c As Long) As Long
MATLAB:
value = NameOfFunction(a,b(),c)
C/C++:
value *NameOfFunction(objtype1 *a, objecttype2 *b[], int c)
+Description
+Examples

doxygen supports multiple languages,
to use this on multiple projects or folders and languages you just point doxygen to every folder you want checked in the config.
My favorite programming language is X. Can I still use doxygen?
No, not as such; doxygen needs to understand the structure of what it reads. If you don't mind spending some time on it, there are several options:
Is language X supported?
If the grammar of X is close to C or C++, then it is probably not too
hard to tweak src/scanner.l a bit so the language is supported. This
is done for all other languages directly supported by doxygen (i.e.
Java, IDL, C#, PHP). If the grammar of X is somewhat different than
you can write an input filter that translates X into something similar
enough to C/C++ for doxygen to understand (this approach is taken for
VB, Object Pascal, and Javascript, see
http://www.doxygen.nl/download.html#helpers). If the
grammar is completely different one could write a parser for X and
write a backend that produces a similar syntax tree as is done by
src/scanner.l (and also by src/tagreader.cpp while reading tag files).
however since your using a VB like proprietary , it might pick this language up if you simply just change the file extensions to that of .vb
here is how to use it with matlab
python and c++ are already supported
have a look at the FAQ page

I was wondering if there is a way to get doxygen/sphinx or another program to generate the documentation for c/c++, VB and matlab on one go.
The Zeus editor has a doxygen feature that allows you to create doxygen documentation for all items in the Zeus workspace.

The Doxygen site has a page with links to 3rd-party helpers for various languages, that you may be able to adapt:
http://www.doxygen.nl/helpers.html
VB and MatLab filters are mentioned there.

Related

Parsing string as a line of code in C++

Is it possible that a string variable can be parsed as an actual line of code in C++? For example, can this string, "x=0", be parsed as actual code and set the value of x (some random variable in the program) to zero? What I plan to do with this is that I want to make a simple plotter in C++. The user enters the function (The function will be in terms of x and y and will have the value zero) to plot as a string (like 2*y+x), which then will be converted to a code object and then evaluated accordingly using a loop.
Because C++ is a compiled and linked language it is not suitable for on-the-fly evaluation.
But I've achieved something similar to your aims in the past with C++ by embedding a Python interpretter to evaluate Python code as strings on the fly and pass the results to the C++ code.
Some other popular scripting languages that can be embedded in a C++ program are Lua and Squirrel.
In Java I've done the same by embedding a Groovy interpretter.
You need to integrate the scripting language interpretter into your code by "embedding" it and then pass values from the scripting language code to your C++ code by a process of "marshaling"
If you really want C++ syntax that can be interpretted, it is theoretically possible to develop a dynamic parser and interpretter for a subset of the language, but C++ is a complex language and such a task would be an enormous undertaking fraught with difficulty and essentially a case of using the wrong tool for the job.
The short answer is "No". You can't compile C/C++ "on the fly" like that, as it's a compiled language, not an interpreted one.
But here's an idea: you could embed a JavaScript interpreter, using the SpiderMonkey API, which can interpret all your example code snippets, as JavaScript syntax is very similar to C/C++ in this regard.
The short answer is "Yes". Compiling C++ on the fly works just fine using a C++ JIT. From llvm.org
A Just-In-Time (JIT) code generation system, which currently supports X86, X86-64, ARM, AArch64, Mips, SystemZ, PowerPC, and PowerPC-64.
The assumption is that you're willing to link most of a compiler into your program in order to achieve this. With concerted effort you should be able to write "eval" on top of the existing API.

Wanted: Compiler Tool for Users of Software System

I am not sure if the title of this question gets to the point. I have written a large software system in C C++ for Windows, and want to give the users of this system the option to add compiled code to it. The user should be able to do basic stuff, and exchange data with my program.
Currently the implemented way is via DLLs. But for this, a grown up compiler is needed, and it is not as easy as I wished. Is there a tiny C compiler that can create Windows DLLs?
Another idea is the Java native interface. But this requires a complete Java system to run in the background, and it is not easy to run code in it.
Do you have any other ideas?
Any interpreted language? (TCL and Lua were designed as extension languages, but you can nearly as easily interface with any other).
How about python integration?
You could create an python interface that interfaces with your application. Python is rather easy to learn and should integrate easily with c/c++. The python documentation has an own chapter on that.
You could also use a tool like swig to generate the interface.
The advantage of this is that they wouldn't have to compile anything. They could just supply python files that could be loaded into your application and run within the software. This is a well known use for python, and something its simple syntax promotes.
As the other says you will be best of by providing an embedded language.
I would chip in for javascript and use the google v8 engine
By using javascript you get a language nearly everbody can use and program in.
There is other javascript engines you can embed like SpiderMonkey.
See this answer for what to choose.
An interpreted language is not good enough. I need speed. The software itself is an interpreted language. So I added support for the tiny C compiler. It is only C, and I do check mingw, which probably would not be as tiny as this. Thanks for all your hints.
Added after several months:
I have now two tools, actually: TinyC and Python. The speed difference between those is noticable (factor 5-10), but that usually does not matter too much. Python is much easier for the user, though I managed to integrate both into the Euler GUI quite nicely.
One of the ways is to add scripting. You application can host scripting environment and expose its services there. Users would be able to execute JScript/VBScript scripts and interact with your application. The advantage is that with reasonable effort you can get the power of well known and well documented scripting languages into your application (I suppose there is even debugger for scripting there). You will be required to shape your app services as COM interfaces and scripts will be able to access them automatically using method names you assigned on C++ side.
C++, Win32 and Scripting: Quick way to add Scripting support to your applications
MSDN Entry Point - IActiveScript interface

Can I cross compile my AS3 code or Flex project to native C++?

I would like to tak emy existing AS3 or Flex project and compile it to run on native C++ code. Is there a way to do this? What sort of solutions exist? I do not want to change my AS3 code.
AS3 is a framework operating on prebuilt libraries you would have to replace somehow in your "translated" code. For example, what would you imagine the native code to do, when you do new Sprite()?
Haxe doesn't try to find a replacement. It takes different approach in that it lets you reuse bits of the code that would translate easily, but those that don't translate are marked as specific to certain environment. There is, however, an effort in Haxe to come up with API similar to those of Flash display list by using NME graphic engine.
Given your example with the iOS compiler - it, again, compiles against the existing library of native code that provides the functionality of display list, video and audio players and so on.
If you can convert it to Haxe (Haxe has extremely AS3 like syntax, only libraries and some language constructs differ) it should provide you with an option of compiling for "native". I've heard it even provides a C++ sourcecode or so I've been told by folks at IRC Haxe room. I could have been trolled for the code part, though he didn't seem like he was trolling...
I'ts not perfect and definitely lacks some more advanced capabilities but it's worth looking at probably.
No, because of
absense of dynamic features in C++ (you don't have Object and describeType equivalent there)
absense of Flash native types in C++ (String (std::string is not equivalent), display objects and many others)
absense of language features (event listeners, garbage collection)
absense of Flex framework equivalent in C++ (there are other good GUI frameworks in C++, but none looks like Flex - because of the reasons above.)
In short, it's much easier to write similar program in C++ (using Qt or whatever framework of comparable strength) than write convertor for that.

Embedded scripting engine for DSL

I'm working on a project which needs an embedded DSL to fullfill its expected requirements.
The DSL would be user defined event based. Here goes a mockup of the desired syntax:
user-defined-event-1 {
// event body
}
user-defined-event-2 {
// event body
}
Probably, most similar language I know based on events is LSL (from Second Life).
So, after reading other similar questions on SO, I would like to ask for the best embeddable scripting engine (Ruby, Lua, Python, etc) on C++ (I work in Qt) which allows me to create this DSL.
In my project, I would test that the script properly uses the DSL syntax (at least one event defined) and give the user all the power of the underlying scripting engine and, if possible, Qt.
It is not a requirement for the embedded language to work with Qt. It can be isolated, but it would be nice to have some integration too.
There's at least a few Qt-Lua bindings out there. Lua can somewhat do the syntax you've shown above; specifically, {} indicates a table (associative array) in Lua, and if you are only passing an anonymous table to a function, you don't need parentheses:
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> function LengthOfTable(t) print(#t) end
> LengthOfTable ({"a","b","c"})
3
> LengthOfTable {"a","b","c"}
3
Whether Lua is actually the best for your application, depends on your application, of course. Either way, Lua is very easy (IMO) to embed in C or C++.
You could look at embeddable javascript, through Google's V8 project, which is written in C++.
http://code.google.com/apis/v8/intro.html
Qt comes with the QtScript scripting module. It uses an ECMAScript based langauge (like javascript).
Tcl comes fairly close to your proposed syntax:
proc user-defined-event-1 {} {
# event body
puts "Hello World"
}
proc defines a procedure, and the extra {} braces are used for arguments. In a tcl shell, procedures can be dynamically typed in line-by-line, copied and pasted, or loaded from a file. They can also be redefined by simply reloading them.
I've never tried it but there is PyQt.
I believe boost::python is pretty easy to implement. I hear there are some python-Qt solutions too.
You seem to have very specific requirements for picking a generic DSL. You may want to try a generic DSL library (e.g. Boost.Proto) rather than a prexisting-embedded language.
For embedding a DSL within your app, I recommend ANTLR. I have used ANTLR over the years, the latest being within a JDBC driver for Cassandra. You might want to try version 4 which has a C++ runtime. Version 3 was problematic with Qt over a collision with the keyword emit.

Are there any free tools to help with automatic code generation?

A few semesters back I had a class where we wrote a very rudimentary scheme parser and eventually an interpreter. After the class, I converted my parser into a C++ parser that did a reasonably good job of parsing C++ as long as I didn't do anything fancy with the preprocessor or macros. I could use it to read over my classes and functions and do neat things like automatically generate class readers or writers or set up function callbacks from a text file.
However, my program is pretty limited. I'm sure I could spend some time to make it more robust and do more neat things, but I don't want to spend the time and effort if there are already more robust tools available that do the same thing. I figure there has to be something like this out there since parsers are an essential part of compilers, but I haven't seen tools specifically for automatic code generation that make it easy to go through and play with data structures that represent classes, functions and variables for C++ specifically. Are there tools that do this?
Edit:
Hopefully this will clarify a little bit of what I'm looking for. The program I have runs as a prebuild step in visual studio. It reads over my source files, makes a list of classes, their members, their functions, etc. which is then used to generate new code. Currently I just use it to make it easy to read and write my data structures to a plain text file, but I could do other things as well. The file readers and writers are output into plain .cpp and .h files which I include in the rest of my project just as I would any other file. What I'm looking for are tools that do similar things so I can decide if I should continue to use my own or switch to a some better solution. I'm not looking for anything that generates machine code or edits code that I've written.
A complete parser-building tool like ANTLR or YACC is necessary if you want to parse C++ from scratch, but it's overkill for your purposes.
It reads over my source files, makes a list of classes, their members, their functions, etc. which is then used to generate new code.
Two main options:
GCC-XML can generate a list of classes, members, and functions. The distribution version on their web site is quite old; try the CVS version instead. I don't know about the availability of a Windows port.
Doxygen is designed for producing documentation, but it can also produce an XML output, which you should be able to use to do what you want.
Currently I just use it to make it easy to read and write my data structures to a plain text file...
This is known as serialization. Try Boost.Serialization or maybe libs11n or Google Protocol Buffers. Stack Overflow has further discussion.
...but I could do other things as well.
Other cool applications of this kind of automatic code generation include reflection (inspecting your objects' members at runtime, using duck typing with C++, etc.) and generating wrappers for calling C++ from scripting languages. For a C++ reflection library, see Reflex. For an example of generating wrappers for scripting languages, see Boost.Python or SWIG.
The C++ FAQ Lite has references to YACC grammars for C++. YACC is an old-school parser that was used to generate parser output, clumsy and difficult to learn but very powerful. Nowadays, you'd use Gnu Bison instead of YACC.
Don't forget about Cog. It requires you to know Python. In essence it embeds the output of Python scripts into your code. It's absurdly easy to use, but it takes a totally different approach from things like ANTLR and its purpose is somewhat different.
Maybe Boost::Serialize or ANTLR?
I answered a similar question (re splitting source files into separate header and cpp files) by suggesting the use of lzz.
lzz has a very powerful C++ parser that builds a representation for everything except the bodies of functions. As long as you don't need the contents of the function bodies you you could modify 'lzz' so that it performs the generation step you want.
If you want tools that can parse production C++ code, and carry out arbitrary analyses and transformations, see our DMS Software Reengineering Toolkit and its C++ front end.
It would be straightforward to use the information DMS can provide about C++ code, its structures, types, instances, to generate such access functions. If you wanted to generate access functions in another language, DMS provides means to code transformations from the input language (in this case, C++) to that target language.
Mozilla developed Pork for this kind of thing. I can't say it's easy to use (or even to build), but it is in production.
I've already used professionally the Nvelocity engine combined with C# as a prevoius step to coding, with very good results.