1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed another corner case of bug 224817.

This commit is contained in:
Sergey Prigogin 2008-04-01 06:24:44 +00:00
parent 043d848106
commit d0325299ce
2 changed files with 18 additions and 17 deletions

View file

@ -78,24 +78,25 @@ public class InclusionTests extends PreprocessorTestsBase {
} }
public void testIncludeNext() throws Exception { public void testIncludeNext() throws Exception {
String baseFile = "int zero; \n#include \"bar/foo.h\""; //$NON-NLS-1$ String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$
String i1Next = "int one; \n#include_next <bar/foo.h>"; //$NON-NLS-1$ String i1Next = "int one; \n#include_next <bar/foo.h>"; //$NON-NLS-1$
String i2Next = "int two; \n#include_next \"bar/foo.h\""; //$NON-NLS-1$ String i2Next = "int two; \n#include_next \"bar/foo.h\""; //$NON-NLS-1$
String i3Next = "int three; \n"; //$NON-NLS-1$ String i3Next = "int three; \n"; //$NON-NLS-1$
IFolder barf = importFolder("bar"); //$NON-NLS-1$ IFolder one = importFolder("one"); //$NON-NLS-1$
IFolder twof = importFolder("two"); //$NON-NLS-1$ IFolder oneTwo = importFolder("one/two"); //$NON-NLS-1$
IFolder twobarf = importFolder("two/bar"); //$NON-NLS-1$ IFolder oneTwoBar = importFolder("one/two/bar"); //$NON-NLS-1$
IFolder threef = importFolder("three"); //$NON-NLS-1$ IFolder oneThree = importFolder("one/three"); //$NON-NLS-1$
IFolder threebarf = importFolder("three/bar"); //$NON-NLS-1$ IFolder oneThreeBar = importFolder("one/three/bar"); //$NON-NLS-1$
IFile base = importFile("base.cpp", baseFile); //$NON-NLS-1$ IFile base = importFile("base.cpp", baseFile); //$NON-NLS-1$
importFile("bar/foo.h", i1Next); //$NON-NLS-1$ importFile("one/foo.h", i1Next); //$NON-NLS-1$
importFile("two/bar/foo.h", i2Next); //$NON-NLS-1$ importFile("one/two/bar/foo.h", i2Next); //$NON-NLS-1$
importFile("three/bar/foo.h", i3Next); //$NON-NLS-1$ importFile("one/three/bar/foo.h", i3Next); //$NON-NLS-1$
String [] path = new String[2]; String[] path = new String[3];
path[0] = twof.getLocation().toOSString(); path[0] = one.getLocation().toOSString();
path[1] = threef.getLocation().toOSString(); path[1] = oneTwo.getLocation().toOSString();
path[2] = oneThree.getLocation().toOSString();
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null); IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
CodeReader reader= new CodeReader(base.getLocation().toString()); CodeReader reader= new CodeReader(base.getLocation().toString());

View file

@ -757,11 +757,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
} }
private int findIncludePos(String[] paths, File currentDirectory) { private int findIncludePos(String[] paths, File currentDirectory) {
for (int i = 0; i < paths.length; ++i) { for (; currentDirectory != null; currentDirectory = currentDirectory.getParentFile()) {
File pathDir = new File(paths[i]); for (int i = 0; i < paths.length; ++i) {
for (File dir = currentDirectory; dir != null; dir = dir.getParentFile()) { File pathDir = new File(paths[i]);
if (dir.equals(pathDir)) if (currentDirectory.equals(pathDir))
return i; return i;
} }
} }