Lines 63-68
Link Here
|
63 |
*/ |
63 |
*/ |
64 |
public final class FilePreprocessorConditionState { |
64 |
public final class FilePreprocessorConditionState { |
65 |
public static final FilePreprocessorConditionState PARSING = new FilePreprocessorConditionState("PARSING", new int[]{0, Integer.MAX_VALUE}); // NOI18N |
65 |
public static final FilePreprocessorConditionState PARSING = new FilePreprocessorConditionState("PARSING", new int[]{0, Integer.MAX_VALUE}); // NOI18N |
|
|
66 |
private static final int ERROR_DIRECTIVE_MARKER = Integer.MAX_VALUE; |
67 |
private static final int PRAGMA_ONCE_DIRECTIVE_MARKER = Integer.MAX_VALUE - 1; |
66 |
|
68 |
|
67 |
/** a SORTED array of blocks [start-end] for which conditionals were evaluated to false */ |
69 |
/** a SORTED array of blocks [start-end] for which conditionals were evaluated to false */ |
68 |
private final int[] offsets; |
70 |
private final int[] offsets; |
Lines 138-146
Link Here
|
138 |
if (i > 0) { |
140 |
if (i > 0) { |
139 |
sb.append("][");//NOI18N |
141 |
sb.append("][");//NOI18N |
140 |
} |
142 |
} |
141 |
if (state.offsets[i+1] == Integer.MAX_VALUE) { |
143 |
if (state.offsets[i+1] == ERROR_DIRECTIVE_MARKER) { |
142 |
sb.append(Integer.MAX_VALUE-state.offsets[i]); |
144 |
sb.append(ERROR_DIRECTIVE_MARKER-state.offsets[i]); |
143 |
sb.append("#error");//NOI18N |
145 |
sb.append("#error");//NOI18N |
|
|
146 |
} else if (state.offsets[i + 1] == PRAGMA_ONCE_DIRECTIVE_MARKER) { |
147 |
sb.append(state.offsets[i]); |
148 |
sb.append("#pragma once");//NOI18N |
144 |
} else { |
149 |
} else { |
145 |
sb.append(state.offsets[i]); |
150 |
sb.append(state.offsets[i]); |
146 |
sb.append("-");//NOI18N |
151 |
sb.append("-");//NOI18N |
Lines 226-232
Link Here
|
226 |
if (this.offsets.length == 0 || this == PARSING) { |
231 |
if (this.offsets.length == 0 || this == PARSING) { |
227 |
return false; |
232 |
return false; |
228 |
} |
233 |
} |
229 |
return offsets[offsets.length-1] == Integer.MAX_VALUE; |
234 |
return offsets[offsets.length-1] == ERROR_DIRECTIVE_MARKER; |
230 |
} |
235 |
} |
231 |
|
236 |
|
232 |
public static final class Builder implements APTParseFileWalker.EvalCallback { |
237 |
public static final class Builder implements APTParseFileWalker.EvalCallback { |
Lines 258-266
Link Here
|
258 |
* adds offset of dead branch to offsets array |
263 |
* adds offset of dead branch to offsets array |
259 |
*/ |
264 |
*/ |
260 |
@Override |
265 |
@Override |
261 |
public void onStoppedDirective(APT apt) { |
266 |
public void onErrorDirective(APT apt) { |
262 |
// on error directive we add special dead block |
267 |
// on error directive we add special dead block |
263 |
addBlockImpl(Integer.MAX_VALUE-apt.getToken().getOffset(), Integer.MAX_VALUE); |
268 |
addBlockImpl(ERROR_DIRECTIVE_MARKER-apt.getToken().getOffset(), ERROR_DIRECTIVE_MARKER); |
|
|
269 |
} |
270 |
|
271 |
/** |
272 |
* Implements APTParseFileWalker.EvalCallback - adds offset of dead |
273 |
* branch to offsets array |
274 |
*/ |
275 |
@Override |
276 |
public void onPragmaOnceDirective(APT apt) { |
277 |
// on pragma once directive we add dead block from pragma till the end |
278 |
addBlockImpl(apt.getToken().getOffset(), PRAGMA_ONCE_DIRECTIVE_MARKER); |
264 |
} |
279 |
} |
265 |
|
280 |
|
266 |
/** |
281 |
/** |
Lines 316-322
Link Here
|
316 |
int size = 0; |
331 |
int size = 0; |
317 |
for (int[] deadInterval : blocks) { |
332 |
for (int[] deadInterval : blocks) { |
318 |
size++; |
333 |
size++; |
319 |
if (deadInterval[1] == Integer.MAX_VALUE) { |
334 |
if (deadInterval[1] == ERROR_DIRECTIVE_MARKER) { |
320 |
break; |
335 |
break; |
321 |
} |
336 |
} |
322 |
} |
337 |
} |
Lines 325-331
Link Here
|
325 |
for (int[] deadInterval : blocks) { |
340 |
for (int[] deadInterval : blocks) { |
326 |
offsets[index++] = deadInterval[0]; |
341 |
offsets[index++] = deadInterval[0]; |
327 |
offsets[index++] = deadInterval[1]; |
342 |
offsets[index++] = deadInterval[1]; |
328 |
if (deadInterval[1] == Integer.MAX_VALUE) { |
343 |
if (deadInterval[1] == ERROR_DIRECTIVE_MARKER) { |
329 |
break; |
344 |
break; |
330 |
} |
345 |
} |
331 |
} |
346 |
} |
Lines 355-363
Link Here
|
355 |
if (i++ > 0) { |
370 |
if (i++ > 0) { |
356 |
sb.append("][");//NOI18N |
371 |
sb.append("][");//NOI18N |
357 |
} |
372 |
} |
358 |
if (deadInterval[1] == Integer.MAX_VALUE) { |
373 |
if (deadInterval[1] == ERROR_DIRECTIVE_MARKER) { |
359 |
sb.append(Integer.MAX_VALUE-deadInterval[0]); |
374 |
sb.append(ERROR_DIRECTIVE_MARKER-deadInterval[0]); |
360 |
sb.append("#error");//NOI18N |
375 |
sb.append("#error");//NOI18N |
|
|
376 |
} else if (deadInterval[1] == PRAGMA_ONCE_DIRECTIVE_MARKER) { |
377 |
sb.append(deadInterval[0]); |
378 |
sb.append("#pragma once");//NOI18N |
361 |
} else { |
379 |
} else { |
362 |
sb.append(deadInterval[0]); |
380 |
sb.append(deadInterval[0]); |
363 |
sb.append("-");//NOI18N |
381 |
sb.append("-");//NOI18N |