You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The binding files are currently written in C++ in order to be able to take advantage of clang for parsing and constructing the AST. In order to get at the information we need, this means that the binding file structure is quite subtle and easy to get wrong as we're making use of a number of unrelated features (regular definitions, type aliases, annotation attributes, explicit template instantiaion) to tie the declarations in the binding to the corresponding declarations in the source library.
For instance, in order to properly declare a template method on a template class, one has to do this little dance:
namespacecppmm_bind {
template <classT> classVec3 {
public:template <classS> voidsetValue(S a, S b, S c);
} CPPMM_VALUETYPE;
// explicitly instantiate the class templatetemplate classVec3<float>;
// note the 'extern' here otherwise we get an error because we're not// defining the template body up aboveexterntemplate void Vec3<float>::setValue(float a, float b, float c);
} // namespace cppmm_bind// and now we do the same for the source library - very confusingtemplate classImath::Vec3<float>;
externtemplate void Imath::Vec3<float>::setValue(float a, float b, float c);
This is needless to say very error prone. I wrote the AST generator and I myself have to refer back to the example bindings to remember how to do it correctly
One thing we could do to improve this is to make a simple binding language that could be transpiled into the C++ that we feed to astgen on the fly (this would be done in-memory and provided to clang as virtual files).
My first idea about what that might look like is something like this:
#include <OpenEXR/ImathVec.h>
namespace Imath = IMATH_INTERNAL_NAMESPACE;
template<T>
class Vec3
binds Imath::Vec3<T>
as valuetype
for V3f = Imath::Vec3<float>; V3i = Imath::Vec3<int>; {{
Imath::Vec3<T> normalized() const;
template<S> void setValue(S a, S b, S c);
}}
The text was updated successfully, but these errors were encountered:
My first thoughts is that writing a language parser seems like a lot of work and could detract from the siggraph deadline we've given ourselves. Could this be done as a c++ api/library instead ?
Well I think calling it a language parser is overselling it. I'm trying to design it such that it just parses out a few keyword/identifier tuples then copy/pastes the rest straight into the resulting c++ file.
In any case this is for further down the line anyway.
The binding files are currently written in C++ in order to be able to take advantage of clang for parsing and constructing the AST. In order to get at the information we need, this means that the binding file structure is quite subtle and easy to get wrong as we're making use of a number of unrelated features (regular definitions, type aliases, annotation attributes, explicit template instantiaion) to tie the declarations in the binding to the corresponding declarations in the source library.
For instance, in order to properly declare a template method on a template class, one has to do this little dance:
This is needless to say very error prone. I wrote the AST generator and I myself have to refer back to the example bindings to remember how to do it correctly
One thing we could do to improve this is to make a simple binding language that could be transpiled into the C++ that we feed to astgen on the fly (this would be done in-memory and provided to clang as virtual files).
My first idea about what that might look like is something like this:
The text was updated successfully, but these errors were encountered: