annotate lib/swig/swigwin-2.0.11/CCache/unify.c @ 2456:83174b7b3763

removed VideoPlayer.cpp/h and CShow.cpp/.h for MVS 2012
author Ritor1
date Sat, 26 Jul 2014 08:39:35 +0600
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 Copyright (C) Andrew Tridgell 2002
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 (at your option) any later version.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 GNU General Public License for more details.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 along with this program; if not, write to the Free Software
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 C/C++ unifier
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 the idea is that changes that don't affect the resulting C code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 should not change the hash. This is achieved by folding white-space
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 and other non-semantic fluff in the input into a single unified format.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 This unifier was design to match the output of the unifier in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 compilercache, which is flex based. The major difference is that
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 this unifier is much faster (about 2x) and more forgiving of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 syntactic errors. Continuing on syntactic errors is important to
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 cope with C/C++ extensions in the local compiler (for example,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 inline assembly systems).
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 #include "ccache.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 static char *s_tokens[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 "...", ">>=", "<<=", "+=", "-=", "*=", "/=", "%=", "&=", "^=",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 "|=", ">>", "<<", "++", "--", "->", "&&", "||", "<=", ">=",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 "==", "!=", ";", "{", "<%", "}", "%>", ",", ":", "=",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 "(", ")", "[", "<:", "]", ":>", ".", "&", "!", "~",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 "-", "+", "*", "/", "%", "<", ">", "^", "|", "?",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 #define C_ALPHA 1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 #define C_SPACE 2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 #define C_TOKEN 4
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 #define C_QUOTE 8
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 #define C_DIGIT 16
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 #define C_HEX 32
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 #define C_FLOAT 64
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 #define C_SIGN 128
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 static struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 unsigned char type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 unsigned char num_toks;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 char *toks[7];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 } tokens[256];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 /* build up the table used by the unifier */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 static void build_table(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 unsigned char c;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 static int done;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 if (done) return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 done = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 memset(tokens, 0, sizeof(tokens));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 for (c=0;c<128;c++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 if (isalpha(c) || c == '_') tokens[c].type |= C_ALPHA;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 if (isdigit(c)) tokens[c].type |= C_DIGIT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 if (isspace(c)) tokens[c].type |= C_SPACE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 if (isxdigit(c)) tokens[c].type |= C_HEX;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 tokens['\''].type |= C_QUOTE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 tokens['"'].type |= C_QUOTE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 tokens['l'].type |= C_FLOAT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 tokens['L'].type |= C_FLOAT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 tokens['f'].type |= C_FLOAT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 tokens['F'].type |= C_FLOAT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 tokens['U'].type |= C_FLOAT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 tokens['u'].type |= C_FLOAT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 tokens['-'].type |= C_SIGN;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 tokens['+'].type |= C_SIGN;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 for (i=0;s_tokens[i];i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 c = s_tokens[i][0];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 tokens[c].type |= C_TOKEN;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 tokens[c].toks[tokens[c].num_toks] = s_tokens[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 tokens[c].num_toks++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 /* buffer up characters before hashing them */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 static void pushchar(unsigned char c)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 static unsigned char buf[64];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 static int len;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 if (c == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103 if (len > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104 hash_buffer((char *)buf, len);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105 len = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 hash_buffer(NULL, 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111 buf[len++] = c;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 if (len == 64) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 hash_buffer((char *)buf, len);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114 len = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 /* hash some C/C++ code after unifying */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 static void unify(unsigned char *p, size_t size)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121 size_t ofs;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122 unsigned char q;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
124
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
125 build_table();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
126
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
127 for (ofs=0; ofs<size;) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
128 if (p[ofs] == '#') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
129 if ((size-ofs) > 2 && p[ofs+1] == ' ' && isdigit(p[ofs+2])) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
130 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
131 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
132 } while (ofs < size && p[ofs] != '\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
133 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
134 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
135 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
136 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
137 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
138 } while (ofs < size && p[ofs] != '\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
139 pushchar('\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
140 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
141 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
142 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
143 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
144
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
145 if (tokens[p[ofs]].type & C_ALPHA) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
146 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
147 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
148 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
149 } while (ofs < size &&
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
150 (tokens[p[ofs]].type & (C_ALPHA|C_DIGIT)));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
151 pushchar('\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
152 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
153 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
154
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
155 if (tokens[p[ofs]].type & C_DIGIT) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
156 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
157 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
158 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
159 } while (ofs < size &&
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
160 ((tokens[p[ofs]].type & C_DIGIT) || p[ofs] == '.'));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
161 if (ofs < size && (p[ofs] == 'x' || p[ofs] == 'X')) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
162 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
163 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
164 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
165 } while (ofs < size && (tokens[p[ofs]].type & C_HEX));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
166 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
167 if (ofs < size && (p[ofs] == 'E' || p[ofs] == 'e')) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
168 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
169 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
170 while (ofs < size &&
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
171 (tokens[p[ofs]].type & (C_DIGIT|C_SIGN))) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
172 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
173 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
174 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
175 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
176 while (ofs < size && (tokens[p[ofs]].type & C_FLOAT)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
177 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
178 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
179 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
180 pushchar('\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
181 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
182 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
183
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
184 if (tokens[p[ofs]].type & C_SPACE) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
185 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
186 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
187 } while (ofs < size && (tokens[p[ofs]].type & C_SPACE));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
188 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
189 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
190
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
191 if (tokens[p[ofs]].type & C_QUOTE) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
192 q = p[ofs];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
193 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
194 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
195 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
196 while (ofs < size-1 && p[ofs] == '\\') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
197 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
198 pushchar(p[ofs+1]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
199 ofs+=2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
200 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
201 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
202 } while (ofs < size && p[ofs] != q);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
203 pushchar('\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
204 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
205 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
206 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
207
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
208 if (tokens[p[ofs]].type & C_TOKEN) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
209 q = p[ofs];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
210 for (i=0;i<tokens[q].num_toks;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
211 unsigned char *s = (unsigned char *)tokens[q].toks[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
212 int len = strlen((char *)s);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
213 if (size >= ofs+len && memcmp(&p[ofs], s, len) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
214 int j;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
215 for (j=0;s[j];j++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
216 pushchar(s[j]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
217 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
218 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
219 pushchar('\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
220 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
221 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
222 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
223 if (i < tokens[q].num_toks) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
224 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
225 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
226 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
227
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
228 pushchar(p[ofs]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
229 pushchar('\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
230 ofs++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
231 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
232 pushchar(0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
233 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
234
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
235
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
236 /* hash a file that consists of preprocessor output, but remove any line
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
237 number information from the hash
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
238 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
239 int unify_hash(const char *fname)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
240 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
241 #ifdef _WIN32
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
242 HANDLE file;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
243 HANDLE section;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
244 DWORD filesize_low;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
245 char *map;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
246 int ret = -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
247
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
248 file = CreateFileA(fname, GENERIC_READ, FILE_SHARE_READ, NULL,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
249 OPEN_EXISTING, 0, NULL);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
250 if (file != INVALID_HANDLE_VALUE) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
251 filesize_low = GetFileSize(file, NULL);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
252 if (!(filesize_low == INVALID_FILE_SIZE && GetLastError() != NO_ERROR)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
253 section = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
254 CloseHandle(file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
255 if (section != NULL) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
256 map = MapViewOfFile(section, FILE_MAP_READ, 0, 0, 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
257 CloseHandle(section);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
258 if (map != NULL)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
259 ret = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
260 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
261 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
262 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
263
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
264 if (ret == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
265 cc_log("Failed to open preprocessor output %s\n", fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
266 stats_update(STATS_PREPROCESSOR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
267 return -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
268 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
269
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
270 /* pass it through the unifier */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
271 unify((unsigned char *)map, filesize_low);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
272
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
273 UnmapViewOfFile(map);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
274
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
275 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
276 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
277 int fd;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
278 struct stat st;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
279 char *map;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
280
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
281 fd = open(fname, O_RDONLY|O_BINARY);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
282 if (fd == -1 || fstat(fd, &st) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
283 cc_log("Failed to open preprocessor output %s\n", fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
284 stats_update(STATS_PREPROCESSOR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
285 return -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
286 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
287
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
288 /* we use mmap() to make it easy to handle arbitrarily long
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
289 lines in preprocessor output. I have seen lines of over
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
290 100k in length, so this is well worth it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
291 map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
292 if (map == (char *)-1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
293 cc_log("Failed to mmap %s\n", fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
294 stats_update(STATS_PREPROCESSOR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
295 return -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
296 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
297 close(fd);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
298
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
299 /* pass it through the unifier */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
300 unify((unsigned char *)map, st.st_size);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
301
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
302 munmap(map, st.st_size);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
303
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
304 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
305 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
306 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
307