我曾经使用 OpenC++ ( http://opencxx.sourceforge.net/opencxx/html/overview.html ) 来执行代码生成,例如:
资源:
class MyKeyword A {
public:
void myMethod(inarg double x, inarg const std::vector<int>& y, outarg double& z);
};
生成:
class A {
public:
void myMethod(const string& x, double& y);
// generated method below:
void _myMehtod(const string& serializedInput, string& serializedOutput) {
double x;
std::vector<int> y;
// deserialized x and y from serializedInput
double z;
myMethod(x, y, z);
}
};
这种代码生成直接匹配OpenC++教程(http://www.csg.is.titech.ac.jp/~chiba/opencxx/tutorial.pdf)中的用例,通过编写元级程序进行处理“MyKeyword”、“inarg”和“outarg”并执行代码生成。但是,OpenC++ 现在有点过时且不活跃,我的代码生成器只能在 g++ 3.2 上运行,并且在解析更高版本的 g++ 头文件时会触发错误。
我看过 VivaCore,但它没有提供编译元级程序的基础结构。我也在看 LLVM,但我找不到指导我解决源到源编译用法的文档。我也知道 ROSE 编译器框架,但我不确定它是否适合我的使用,以及它的专有 C++ 前端二进制文件是否可以在商业产品中使用,以及是否有 Windows 版本可用。
非常感谢任何对特定教程/论文/文档的评论和指针。