回答編集履歴
1
unifdefの改造でどうか
answer
CHANGED
@@ -1,10 +1,90 @@
|
|
1
|
-
unifdefをビルドして、-sオプションをつけて.cppファイルを食わせるのはどうでしょうか。
|
2
|
-
|
1
|
+
あーたしかによくよく処理を読めば、unifdefは引数から定義されたdefineをつかってifdefを剥がすだけで、コードからdefine/undef/includeを処理しないですね。
|
2
|
+
ま、ifdefとかの処理はできるので、こういう感じの改造を入れればそれっぽく出ましたが、incldueの処理を手抜きしてあるのでちゃんと動かすならそのあたりの手当が必要かな、という感じですね。(長いので省略しましたが、outputをダミーにしておく必要もあります)
|
3
3
|
|
4
|
+
あるいはVS2019あたりを入れて、clangに食わせたほうが速いかもしれません。
|
5
|
+
```C
|
6
|
+
|
7
|
+
@@ -367,6 +367,17 @@
|
8
|
+
processinout(*argv, *argv);
|
9
|
+
argv++;
|
10
|
+
}
|
11
|
+
+
|
12
|
+
+ {
|
13
|
+
+ int i;
|
14
|
+
+ fprintf(stderr, "Symbols\n");
|
15
|
+
+ for( i=0; i< nsyms; i++){
|
16
|
+
+ if( symname[i] && value[i] ){
|
17
|
+
+ fprintf(stderr, "%s\n", symname[i] );
|
18
|
+
+ }
|
19
|
+
+
|
20
|
+
+ }
|
21
|
+
+ }
|
22
|
+
|
23
|
+
|
24
|
+
+
|
25
|
+
+static const char *getsym(const char **cpp);
|
26
|
+
+
|
27
|
+
static Linetype
|
28
|
+
parseline(void)
|
29
|
+
{
|
30
|
+
@@ -800,6 +816,57 @@
|
31
|
+
goto done;
|
32
|
+
}
|
33
|
+
keyword = tline + (cp - tline);
|
34
|
+
+
|
35
|
+
+ if ((cp = matchsym("define", keyword)) != NULL){
|
36
|
+
+ const char *end = cp + strlen(cp);
|
37
|
+
+
|
38
|
+
+ const char *sym = getsym(&cp);
|
39
|
+
+ const char *val;
|
40
|
+
+ if (sym == NULL)
|
41
|
+
+ error("Missing macro name in #define");
|
42
|
+
+ if (*cp == '(') {
|
43
|
+
+ val = "1";
|
44
|
+
+ } else {
|
45
|
+
+ cp = skipcomment(cp);
|
46
|
+
+ val = (cp < end) ? xstrdup(cp, end) : "";
|
47
|
+
+ }
|
48
|
+
+ debug("#define");
|
49
|
+
+ addsym2(false, sym, val);
|
50
|
+
+ }
|
51
|
+
+ else if ((cp = matchsym("undef", keyword)) != NULL){
|
52
|
+
+ const char *sym = getsym(&cp);
|
53
|
+
+ debug("undef:%s\n", sym);
|
54
|
+
+ addsym2( false, sym, NULL);
|
55
|
+
+ }
|
56
|
+
+ else if ((cp = matchsym("include", keyword)) != NULL){
|
57
|
+
+ int pos = strcspn( cp, "\"<\n");
|
58
|
+
+
|
59
|
+
+ if( cp[pos] == '"' )
|
60
|
+
+ {
|
61
|
+
+ const char *st = cp+pos+1;
|
62
|
+
+ const char *end = strchr( st, '"');
|
63
|
+
+ if( end ){
|
64
|
+
+ char *incl = xstrdup(st,end);
|
65
|
+
+ FILE *old = input;
|
66
|
+
+ FILE *oldout = output;
|
67
|
+
+
|
68
|
+
+ output = fbinmode(stdout);
|
69
|
+
+
|
70
|
+
+ input = fopen(incl, "rb");
|
71
|
+
+ if( input ){
|
72
|
+
+ debug("INCLUDE %s start", incl );
|
73
|
+
+ process();
|
74
|
+
+ debug("INCLUDE %s end\n", incl );
|
75
|
+
+// fclose(input);
|
76
|
+
+ }
|
77
|
+
+ output = oldout;
|
78
|
+
+ input = old;
|
79
|
+
+ }
|
80
|
+
+ }
|
81
|
+
+ }
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
~~unifdefをビルドして、-sオプションをつけて.cppファイルを食わせるのはどうでしょうか。
|
86
|
+
ビルド時点でプロジェクトによってdefineされるものは下記stackoverflowの方法で取得してunifdefに引き渡してやる必要があります。~~
|
87
|
+
|
4
88
|
http://dotat.at/prog/unifdef/
|
5
|
-
> -s Instead of processing an input file as usual, this option causes
|
6
|
-
unifdef to produce a list of macros that are used in preprocessor
|
7
|
-
directive controlling expressions.
|
8
|
-
|
9
89
|
参考 https://stackoverflow.com/questions/3665537/how-to-find-out-cl-exes-built-in-macros
|
10
90
|
参考 https://qiita.com/tokudiro/items/0643e15f5b973ec030c5
|