1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 14:25:37 +02:00

Fixed bug 224817.

This commit is contained in:
Sergey Prigogin 2008-03-30 23:52:09 +00:00
parent 56cf847c2a
commit f03642cfb3
2 changed files with 22 additions and 20 deletions

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.scanner;
@ -77,24 +78,26 @@ public class InclusionTests extends PreprocessorTestsBase {
}
public void testIncludeNext() throws Exception {
String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$
String i1Next = "int one; \n#include_next <foo.h>"; //$NON-NLS-1$
String i2Next = "int two; \n#include_next \"foo.h\""; //$NON-NLS-1$
String baseFile = "int zero; \n#include \"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 i3Next = "int three; \n"; //$NON-NLS-1$
IFile base = importFile( "base.cpp", baseFile ); //$NON-NLS-1$
importFile( "foo.h", i1Next ); //$NON-NLS-1$
IFolder barf = importFolder("bar"); //$NON-NLS-1$
IFolder twof = importFolder("two"); //$NON-NLS-1$
IFolder twobarf = importFolder("two/bar"); //$NON-NLS-1$
IFolder threef = importFolder("three"); //$NON-NLS-1$
importFile( "two/foo.h", i2Next ); //$NON-NLS-1$
importFile( "three/foo.h", i3Next ); //$NON-NLS-1$
IFolder threebarf = importFolder("three/bar"); //$NON-NLS-1$
IFile base = importFile("base.cpp", baseFile); //$NON-NLS-1$
importFile("bar/foo.h", i1Next); //$NON-NLS-1$
importFile("two/bar/foo.h", i2Next); //$NON-NLS-1$
importFile("three/bar/foo.h", i3Next); //$NON-NLS-1$
String [] path = new String[2];
path[0] = twof.getLocation().toOSString();
path[1] = threef.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());
initializeScanner(reader, ParserLanguage.C, ParserMode.COMPLETE_PARSE, scannerInfo);
@ -116,7 +119,7 @@ public class InclusionTests extends PreprocessorTestsBase {
validateEOF();
}
public void testIncludePathOrdering() throws Exception
{
// create directory structure:

View file

@ -9,11 +9,11 @@
* IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -757,14 +757,13 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
}
private int findIncludePos(String[] paths, File currentDirectory) {
for (int i = 0; i < paths.length; ++i)
try {
String path = new File(paths[i]).getCanonicalPath();
String parent = currentDirectory.getCanonicalPath();
if (path.equals(parent))
return i;
} catch (IOException e) {
}
for (int i = 0; i < paths.length; ++i) {
File pathDir = new File(paths[i]);
for (File dir = currentDirectory; dir != null; dir = dir.getParentFile()) {
if (dir.equals(pathDir))
return i;
}
}
return -1;
}