From 1b67403176582dcc0592423f8322ede89b4be86c Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 2 Jan 2012 13:37:14 +0100 Subject: [PATCH] Bug 367316: Relative includes when parsing in context. --- .../core/index/IndexBasedFileContentProvider.java | 10 ++++++++++ .../internal/core/parser/scanner/CPreprocessor.java | 9 ++++++--- .../parser/scanner/InternalFileContentProvider.java | 7 +++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedFileContentProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedFileContentProvider.java index 944e6cc9817..1f4d1358277 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedFileContentProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedFileContentProvider.java @@ -295,4 +295,14 @@ public final class IndexBasedFileContentProvider extends InternalFileContentProv } return IIndexFile.EMPTY_FILE_ARRAY; } + + @Override + public String getContextPath() { + if (fContextToHeaderGap != null) + try { + return fPathResolver.getASTPath(fContextToHeaderGap[0].getLocation()); + } catch (CoreException e) { + } + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index 7f216f7b0a6..89a574118af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -297,11 +297,14 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { fMacroExpander= new MacroExpander(this, fMacroDictionary, fLocationMap, fLexOptions); fIncludeFileResolutionHeuristics= fFileContentProvider.getIncludeHeuristics(); - final String filePath= fRootContent.getFileLocation(); - configureIncludeSearchPath(new File(filePath).getParentFile(), info); + String contextPath= fFileContentProvider.getContextPath(); + if (contextPath == null) { + contextPath= fRootContent.getFileLocation(); + } + configureIncludeSearchPath(new File(contextPath).getParentFile(), info); setupMacroDictionary(configuration, info, language); - ILocationCtx ctx= fLocationMap.pushTranslationUnit(filePath, fRootContent.getSource()); + ILocationCtx ctx= fLocationMap.pushTranslationUnit(fRootContent.getFileLocation(), fRootContent.getSource()); Lexer lexer = new Lexer(fRootContent.getSource(), fLexOptions, this, this); fRootContext= fCurrentContext= new ScannerContext(ctx, null, lexer); if (info instanceof IExtendedScannerInfo) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContentProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContentProvider.java index ed41e88c356..1899ef3bc29 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContentProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContentProvider.java @@ -134,5 +134,12 @@ public abstract class InternalFileContentProvider extends IncludeFileContentProv } list.add(sig); } + } + + /** + * Return the path of the context of null, if there is no context. + */ + public String getContextPath() { + return null; } }