另一个宏上下文中的 M4 pushdef
M4 pushdef inside another macros context
define(`__for_each',
`ifelse(`$#', `1', `', `$#', `2', `(`')',
`(`')__for_each(`', shift(shift($@)))')')dnl
define(`__method_decl', `virtual () = 0;')
define(`__expose_method', `pushdef(`method', `__method_decl') popdef(`method')')dnl
define(`interface', ``struct' {
__for_each(`__expose_method', shift($@))
};')dnl
interface(iface,
method(ma, int),
method(mb, void))
我希望脚本会产生如下输出:
struct iface {
virtual int ma() = 0; virtual void mb() = 0;
};
但不是 virtual int ma() = 0; virtual void mb() = 0;
它 returns 行 space 填充行。
我应该如何在 __expose_method
评估时间定义宏 method
以获得所需的输出?
我发现实现此行为的唯一方法是以下一种方式使用 patsubst
函数:
define(`__expose_method', `patsubst(`', `method', `__method_decl')')dnl
好像是胶带。
define(`__for_each',
`ifelse(`$#', `1', `', `$#', `2', `(`')',
`(`')__for_each(`', shift(shift($@)))')')dnl
define(`__method_decl', `virtual () = 0;')
define(`__expose_method', `pushdef(`method', `__method_decl') popdef(`method')')dnl
define(`interface', ``struct' {
__for_each(`__expose_method', shift($@))
};')dnl
interface(iface,
method(ma, int),
method(mb, void))
我希望脚本会产生如下输出:
struct iface {
virtual int ma() = 0; virtual void mb() = 0;
};
但不是 virtual int ma() = 0; virtual void mb() = 0;
它 returns 行 space 填充行。
我应该如何在 __expose_method
评估时间定义宏 method
以获得所需的输出?
我发现实现此行为的唯一方法是以下一种方式使用 patsubst
函数:
define(`__expose_method', `patsubst(`', `method', `__method_decl')')dnl
好像是胶带。