changeset: 272292:08b8921689a6 branch: release74 tag: tip user: Vladimir Voskresensky date: Sun Sep 29 18:51:24 2013 +0400 summary: fixed #236435 - [Regression] Unable to resolve all of the identifiers in files with pragma once diff --git a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FilePreprocessorConditionState.java b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FilePreprocessorConditionState.java --- a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FilePreprocessorConditionState.java +++ b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FilePreprocessorConditionState.java @@ -63,6 +63,8 @@ */ public final class FilePreprocessorConditionState { public static final FilePreprocessorConditionState PARSING = new FilePreprocessorConditionState("PARSING", new int[]{0, Integer.MAX_VALUE}); // NOI18N + private static final int ERROR_DIRECTIVE_MARKER = Integer.MAX_VALUE; + private static final int PRAGMA_ONCE_DIRECTIVE_MARKER = Integer.MAX_VALUE - 1; /** a SORTED array of blocks [start-end] for which conditionals were evaluated to false */ private final int[] offsets; @@ -138,9 +140,12 @@ if (i > 0) { sb.append("][");//NOI18N } - if (state.offsets[i+1] == Integer.MAX_VALUE) { - sb.append(Integer.MAX_VALUE-state.offsets[i]); + if (state.offsets[i+1] == ERROR_DIRECTIVE_MARKER) { + sb.append(ERROR_DIRECTIVE_MARKER-state.offsets[i]); sb.append("#error");//NOI18N + } else if (state.offsets[i + 1] == PRAGMA_ONCE_DIRECTIVE_MARKER) { + sb.append(state.offsets[i]); + sb.append("#pragma once");//NOI18N } else { sb.append(state.offsets[i]); sb.append("-");//NOI18N @@ -226,7 +231,7 @@ if (this.offsets.length == 0 || this == PARSING) { return false; } - return offsets[offsets.length-1] == Integer.MAX_VALUE; + return offsets[offsets.length-1] == ERROR_DIRECTIVE_MARKER; } public static final class Builder implements APTParseFileWalker.EvalCallback { @@ -258,9 +263,19 @@ * adds offset of dead branch to offsets array */ @Override - public void onStoppedDirective(APT apt) { + public void onErrorDirective(APT apt) { // on error directive we add special dead block - addBlockImpl(Integer.MAX_VALUE-apt.getToken().getOffset(), Integer.MAX_VALUE); + addBlockImpl(ERROR_DIRECTIVE_MARKER-apt.getToken().getOffset(), ERROR_DIRECTIVE_MARKER); + } + + /** + * Implements APTParseFileWalker.EvalCallback - adds offset of dead + * branch to offsets array + */ + @Override + public void onPragmaOnceDirective(APT apt) { + // on pragma once directive we add dead block from pragma till the end + addBlockImpl(apt.getToken().getOffset(), PRAGMA_ONCE_DIRECTIVE_MARKER); } /** @@ -316,7 +331,7 @@ int size = 0; for (int[] deadInterval : blocks) { size++; - if (deadInterval[1] == Integer.MAX_VALUE) { + if (deadInterval[1] == ERROR_DIRECTIVE_MARKER) { break; } } @@ -325,7 +340,7 @@ for (int[] deadInterval : blocks) { offsets[index++] = deadInterval[0]; offsets[index++] = deadInterval[1]; - if (deadInterval[1] == Integer.MAX_VALUE) { + if (deadInterval[1] == ERROR_DIRECTIVE_MARKER) { break; } } @@ -355,9 +370,12 @@ if (i++ > 0) { sb.append("][");//NOI18N } - if (deadInterval[1] == Integer.MAX_VALUE) { - sb.append(Integer.MAX_VALUE-deadInterval[0]); + if (deadInterval[1] == ERROR_DIRECTIVE_MARKER) { + sb.append(ERROR_DIRECTIVE_MARKER-deadInterval[0]); sb.append("#error");//NOI18N + } else if (deadInterval[1] == PRAGMA_ONCE_DIRECTIVE_MARKER) { + sb.append(deadInterval[0]); + sb.append("#pragma once");//NOI18N } else { sb.append(deadInterval[0]); sb.append("-");//NOI18N diff --git a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTParseFileWalker.java b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTParseFileWalker.java --- a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTParseFileWalker.java +++ b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTParseFileWalker.java @@ -101,7 +101,9 @@ void onEval(APT apt, boolean result); - void onStoppedDirective(APT apt); + void onErrorDirective(APT apt); + + void onPragmaOnceDirective(APT apt); } private FileContent fileContent; private final boolean triggerParsingActivity; @@ -110,7 +112,8 @@ @Override public void onEval(APT apt, boolean result) { } @Override - public void onStoppedDirective(APT apt) { } + public void onErrorDirective(APT apt) { } + public void onPragmaOnceDirective(APT apt) { } }; private final CsmCorePackageAccessor csmCorePackageAccessor; @@ -182,7 +185,7 @@ @Override protected void onErrorNode(APT apt) { super.onErrorNode(apt); - evalCallback.onStoppedDirective(apt); + evalCallback.onErrorDirective(apt); if (needMacroAndIncludes()) { this.fileContent.addError(createError((APTError)apt)); } @@ -192,7 +195,7 @@ protected void onPragmaNode(APT apt) { super.onPragmaNode(apt); if (isStopped()) { - evalCallback.onStoppedDirective(apt); + evalCallback.onPragmaOnceDirective(apt); } else { APTPragma pragma = (APTPragma) apt; APTToken name = pragma.getName();