macros - 另一个宏上下文中的 M4 pushdef
问题描述
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))
我希望脚本会产生如下输出:
struct iface {
virtual int ma() = 0; virtual void mb() = 0;
};
但virtual int ma() = 0; virtual void mb() = 0;
它不是返回行空间填充的行。method
我应该如何在评估时定义宏__expose_method
以获得所需的输出?
解决方案
我发现实现此行为的唯一方法是以以下patsubst
方式使用函数:
define(`__expose_method', `patsubst(`$1', `method', `__method_decl')')dnl
好像是胶带。
推荐阅读
- php - 使用 CSV 文件更新 MySQL 中已插入的数据
- keras - 重复部分 Keras 模型,取决于输入的数量
- vue.js - 如何在 VueJs 中重置选择下拉菜单
- linux - 守护程序中的线程未运行
- javascript - PHP 将文件文本附加到所有 JavaScript 文件
- wpf - Visual Studio 设计窗口中的 XAML 标记错误
- php - 带有 JQuery AJAX 的搜索功能
- angular - 为什么我在 Angular 6 中的服务出现错误?
- android - 在父级中居中嵌套相对布局
- ios - facebook/twitter 深度链接的分支测试应用程序链接奇怪行为 - iOS