Macros M4 pushdef在另一个宏上下文中
我希望脚本将产生如下输出:Macros M4 pushdef在另一个宏上下文中,macros,m4,Macros,M4,我希望脚本将产生如下输出: define(`__for_each', `ifelse(`$#', `1', `', `$#', `2', `$1(`$2')', `$1(`$2')__for_each(`$1', shift(shift($@)))')')dnl define(`__method_decl', `virtual $2 $1() = 0;') define(`__expose_method', `pushdef(`method', `__method_decl')$1
define(`__for_each',
`ifelse(`$#', `1', `', `$#', `2', `$1(`$2')',
`$1(`$2')__for_each(`$1', shift(shift($@)))')')dnl
define(`__method_decl', `virtual $2 $1() = 0;')
define(`__expose_method', `pushdef(`method', `__method_decl')$1 popdef(`method')')dnl
define(`interface', ``struct' $1 {
__for_each(`__expose_method', shift($@))
};')dnl
interface(iface,
method(ma, int),
method(mb, void))
而不是virtualint ma()=0;虚空mb()=0代码>返回行空间填充的行。
如何在\u expose\u method
求值时定义宏方法
,以获得所需的输出?我发现实现此行为的唯一方法是以下一种方式使用patsubst
函数:
struct iface {
virtual int ma() = 0; virtual void mb() = 0;
};
好像是胶带
define(`__expose_method', `patsubst(`$1', `method', `__method_decl')')dnl