# HG changeset patch # User Alexander Simon # Date 1447251186 -10800 # Wed Nov 11 17:13:06 2015 +0300 # Branch release81 # Node ID 8be6e83baced87536f8be28740172982fbaaa75c # Parent 9e3d45fe33607b9fff3b708bdb1e76bfccdd7c7e fixed Bug #216611 Change in include directive causes wrong macro hyperlink - additional fix diff --git a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/DeepReparsingUtils.java b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/DeepReparsingUtils.java --- a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/DeepReparsingUtils.java +++ b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/DeepReparsingUtils.java @@ -166,7 +166,7 @@ if (contentChanged) { APTDriver.invalidateAPT(changedFile.getBuffer()); } - boolean scheduleParsing = true; + boolean scheduleParsing = true; ParentFiles top = changedFileProject.getGraph().getTopParentFiles(changedFile); Set cuStartFiles = top.getCompilationUnits(); Set parents = top.getParentFiles(); @@ -185,7 +185,7 @@ Set parentOrphanFiles = orphanCandidateTop.getParentFiles(); if (parentOrphanFiles.size() == 1 && parentOrphanFiles.contains(impl)) { // header is orphan now - invalidateFileAndPreprocState(changedFileProject, impl); +// invalidateFileAndPreprocState(changedFileProject, impl); changedFileProject.markAsParsingPreprocStates(impl); if (scheduleParsing) { ParserQueue.instance().add(impl, changedFileProject.getPreprocHandlersForParse(impl, Interrupter.DUMMY), ParserQueue.Position.HEAD); diff --git a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FileImpl.java b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FileImpl.java --- a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FileImpl.java +++ b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FileImpl.java @@ -1533,13 +1533,14 @@ parser.init(this, filteredTokenStream, parseParams.callback); parseResult = parser.parse(parseParams.lazyCompound ? CsmParser.ConstructionKind.TRANSLATION_UNIT : CsmParser.ConstructionKind.TRANSLATION_UNIT_WITH_COMPOUND); - + PreprocHandler.State ppOrigState = ppState; + PreprocHandler.State ppUsedState = parseParams.tsp.getPreprocHandlerStartState(); if (!cacheTokens) { pcState = parseParams.tsp.release(); } assert pcState != null; - startProject.setParsedPCState(this, ppState, pcState); + startProject.setParsedPCState(this, ppOrigState, ppUsedState, pcState); if (emptyAstStatictics) { time = System.currentTimeMillis() - time; diff --git a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/ProjectBase.java b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/ProjectBase.java --- a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/ProjectBase.java +++ b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/ProjectBase.java @@ -2156,7 +2156,7 @@ } } - void setParsedPCState(FileImpl csmFile, State ppState, FilePreprocessorConditionState pcState) { + void setParsedPCState(FileImpl csmFile, State ppOrigState, State ppUsedState, FilePreprocessorConditionState pcState) { CharSequence fileKey = csmFile.getAbsolutePath(); FileContainer.FileEntry entry = getFileContainer().getEntry(fileKey); if (entry == null) { @@ -2165,17 +2165,17 @@ } boolean updateFileContainer; Object lock = entry.getLock(); - StartEntry startEntry = APTHandlersSupport.extractStartEntry(ppState); + StartEntry startEntry = APTHandlersSupport.extractStartEntry(ppOrigState); boolean updateStartProjectStorage = false; ProjectBase startProject = Utils.getStartProject(startEntry); // IZ#179861: unstable test RepositoryValidation synchronized (lock) { // update FileContainer entry if possible - updateFileContainer = updateFileEntryBasedOnParsedState(entry, fileKey, ppState, pcState); + updateFileContainer = updateFileEntryBasedOnParsedState(entry, fileKey, ppOrigState, ppUsedState, pcState); // update include storage of start project FileEntry includedEntry = startProject.includedFileContainer.getIncludedFileEntry(lock, this, fileKey); if (includedEntry != null) { - updateStartProjectStorage = updateFileEntryBasedOnParsedState(includedEntry, fileKey, ppState, pcState); + updateStartProjectStorage = updateFileEntryBasedOnParsedState(includedEntry, fileKey, ppOrigState, ppUsedState, pcState); } } if (updateFileContainer) { @@ -2187,11 +2187,11 @@ } } - private static boolean updateFileEntryBasedOnParsedState(FileEntry entry, CharSequence fileKey, State ppState, FilePreprocessorConditionState pcState) { + private static boolean updateFileEntryBasedOnParsedState(FileEntry entry, CharSequence fileKey, State ppOrigState, State ppUsedState, FilePreprocessorConditionState pcState) { List statesToKeep = new ArrayList<>(4); Collection entryStatePairs = entry.getStatePairs(); if (TraceFlags.TRACE_182342_BUG) { - System.err.printf("setParsedPCState: original states for file: %s %n with new state: %s%n and pcState: %s%n", fileKey, ppState, pcState); + System.err.printf("setParsedPCState: original states for file: %s %n with new state: %s%n and pcState: %s%n", fileKey, ppUsedState, pcState); if (entryStatePairs.isEmpty()) { System.err.println("NO ORIGINAL STATES"); } else { @@ -2209,7 +2209,7 @@ assert pair.state != null : "state can not be null in pair " + pair + " for file " + fileKey; if ((pair.pcState == FilePreprocessorConditionState.PARSING) && // there coud be invalidated state which is in parsing phase now - APTHandlersSupport.equalsIgnoreInvalid(pair.state, ppState)) { + APTHandlersSupport.equalsIgnoreInvalid(pair.state, ppOrigState)) { assert !entryFound; entryFound = true; } else { @@ -2233,11 +2233,11 @@ switch (comparisonResult) { case REPLACE_OTHERS: CndUtils.assertTrueInConsole(statesToKeep.isEmpty(), "states to keep must be empty 3"); // NOI18N - entry.setStates(statesToKeep, new PreprocessorStatePair(ppState, pcState)); + entry.setStates(statesToKeep, new PreprocessorStatePair(ppUsedState, pcState)); break; case KEEP_WITH_OTHERS: assert !statesToKeep.isEmpty(); - entry.setStates(statesToKeep, new PreprocessorStatePair(ppState, pcState)); + entry.setStates(statesToKeep, new PreprocessorStatePair(ppUsedState, pcState)); break; case DISCARD: assert !copy.isEmpty(); diff --git a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTTokenStreamProducer.java b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTTokenStreamProducer.java --- a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTTokenStreamProducer.java +++ b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/apt/APTTokenStreamProducer.java @@ -126,6 +126,7 @@ PreprocHandler preprocHandler = projectImpl.createEmptyPreprocHandler(ownerAbsPath); PreprocHandler restorePreprocHandlerFromIncludeStack = restorePreprocHandlerFromIncludeStack(projectImpl, reverseInclStack, ownerAbsPath, preprocHandler, includeOwnerState, Interrupter.DUMMY); // using restored preprocessor handler, ask included file for parsing token stream filtered by language + resetHandler(restorePreprocHandlerFromIncludeStack); TokenStream includedFileTS = createParsingTokenStreamForHandler(includedFile, restorePreprocHandlerFromIncludeStack, true); return includedFileTS; } diff --git a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/spi/TokenStreamProducer.java b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/spi/TokenStreamProducer.java --- a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/spi/TokenStreamProducer.java +++ b/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/parser/spi/TokenStreamProducer.java @@ -82,6 +82,7 @@ public abstract class TokenStreamProducer { private PreprocHandler curPreprocHandler; + private PreprocHandler.State curPreprocHandlerStartState; private FileImpl startFile; private String language = APTLanguageSupport.GNU_CPP; private String languageFlavor = APTLanguageSupport.FLAVOR_UNKNOWN; @@ -125,6 +126,7 @@ public void prepare(PreprocHandler handler, String language, String languageFlavor, boolean allowToCacheOnRelease) { assert handler != null : "null preprocHandler is not allowed"; curPreprocHandler = handler; + curPreprocHandlerStartState = handler.getState(); startFile = Utils.getStartFile(handler.getState()); assert language != null : "null language is not allowed"; this.language = language; @@ -136,7 +138,11 @@ public PreprocHandler getCurrentPreprocHandler() { return curPreprocHandler; } - + + public PreprocHandler.State getPreprocHandlerStartState() { + return curPreprocHandlerStartState; + } + public String getLanguage() { return language; } @@ -175,6 +181,7 @@ protected void resetHandler(PreprocHandler ppHandler) { this.curPreprocHandler = ppHandler; + this.curPreprocHandlerStartState = ppHandler.getState(); } public void setCodePatch(CodePatch codePatch) {