如何编写一个以C ++代码为输入的C ++代码生成器? [英] How to write a C++ code generator that takes C++ code as input?
问题描述
我们有一个CORBA实现,为我们自动生成Java和C ++存根。因为CORBA生成的代码很难使用,我们需要在CORBA代码周围编写wrapper / helpers。所以我们有一个两步代码生成过程(是的,我知道这是坏):
CORBA IDL - >恼人的CORBA生成的代码 - >有用的包装/帮助函数
使用Java的反射,我可以检查CORBA生成的代码,并使用它来生成额外的代码。但是,因为C ++没有反射,我不知道如何在C ++方面做到这一点。我应该使用C ++解析器吗? C ++模板?
TLDR:如何使用生成的C ++代码作为输入生成C ++代码?
您是否考虑退一步,使用IDL作为自定义代码生成器的源代码?可能你有一些包装代码隐藏的东西,如复制,var,ptr等。我们有一个基于Ruby的CORBA IDL编译器,目前生成Ruby和C ++代码。这可以通过客户生成器扩展,有关RIDL和R2CORBA,请参见 http://www.remedy.nl 。 / p>
另一种选择是检查我们正在处理的IDL到C ++ 11语言映射,更多细节在 http://taox11.remedy.nl 。这种新的语言映射更容易使用,并使用标准类型和STL容器来处理。
We have a CORBA implementation that autogenerates Java and C++ stubs for us. Because the CORBA-generated code is difficult to work with, we need to write wrappers/helpers around the CORBA code. So we have a 2-step code generation process (yes, I know this is bad):
CORBA IDL -> annoying CORBA-generated code -> useful wrappers/helper functions
Using Java's reflection, I can inspect the CORBA-generated code and use that to generate additional code. However, because C++ doesn't have reflection, I am not sure how to do this on the C++ side. Should I use a C++ parser? C++ templates?
TLDR: How to generate C++ code using generated C++ code as input?
Have you considered to take a step back and use the IDL as source for a custom code generator? Probably you have some wrapper code that hides things like duplicate, var, ptr, etc. We have a Ruby based CORBA IDL compiler that currently generates Ruby and C++ code. That could be extended with a customer generator, see http://www.remedy.nl for RIDL and R2CORBA.
Another option would be to check out the IDL to C++11 language mapping we are working on, more details on http://taox11.remedy.nl. This new language mapping is much easier to use and uses standard types and STL containers to work with.
这篇关于如何编写一个以C ++代码为输入的C ++代码生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!