使用gcc插件修改变量声明的顺序 [英] Use gcc plugins to modify the order of variable declarations
问题描述
我知道这很难做,我应该避免,但我有我的理由。
我想在编译时修改一些字段声明的顺序,例如:
I know this is very hard to do, and that I should avoid that, but I have my reasons for this. I want to modify the order of some field declarations in compilation time, for example :
class A {
char c;
int i;
}
必须转到:
class A {
int i;
char c;
}
如果我选择交换 i
和 c
,
我想知道如何改变位置
字段声明其树
任何人都知道如何做到这一点?
感谢!
Anyone know how can I do this ?? thanks !
我使用g ++ 4.9.2版本的插件
I use the g++ 4.9.2 version of plugins
推荐答案
如果我要尝试这个,我会尝试两种不同的方法。
If I was going to try this, I would try two different approaches.
-
PLUGIN_FINISH_TYPE
事件并重写其中的类型。要重写它,重新排序字段并强制类型的重新布局。
Hook in to the
PLUGIN_FINISH_TYPE
event and rewrite the type there. To rewrite it, reorder the fields and force a relayout of the type. You'll have to read a bit of GCC source to understand how to invalidate the layout and force a new one.
如果这不起作用,请添加一个GCC源代码,一个新的pass,它只是在gimplification之后运行,并尝试重写那里的类型。我怀疑这不太可能工作。
If that didn't work, add a new pass that is run just after gimplification, and try to rewrite the types there. I suspect this is not likely to work, though.
这篇关于使用gcc插件修改变量声明的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!