1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Refactoring Scanner.handleInclusion to be more modular.

This commit is contained in:
John Camelon 2004-02-25 02:41:41 +00:00
parent 54e925ee1f
commit d0ae8c2f99
4 changed files with 69 additions and 84 deletions

View file

@ -1,3 +1,6 @@
2004-02-24 John Camelon
Refactoring Scanner.handleInclusion to be more modular.
2004-02-24 Andrew Niefer
Template Explicit Specializations (bug 51485)
adding basic symbol table functionality for non-nested template specializations

View file

@ -35,18 +35,10 @@ public interface IScannerData {
* @param includePathNames The includePathNames to set.
*/
public abstract void setIncludePathNames(List includePathNames);
/**
* @param includePaths The includePaths to set.
*/
public abstract void setIncludePaths(List includePaths);
/**
* @return Returns the includePathNames.
*/
public abstract List getIncludePathNames();
/**
* @return Returns the includePaths.
*/
public abstract List getIncludePaths();
/**
* @return Returns the originalConfig.
*/

View file

@ -286,27 +286,35 @@ public class Scanner implements IScanner {
}
initialContextInitialized = true;
}
public void addIncludePath(String includePath) {
scannerData.getIncludePathNames().add(includePath);
scannerData.getIncludePaths().add( new File( includePath ) );
}
public void overwriteIncludePath(String [] newIncludePaths) {
if( newIncludePaths == null ) return;
scannerData.setIncludePathNames(new ArrayList());
scannerData.setIncludePaths( new ArrayList() );
for( int i = 0; i < newIncludePaths.length; ++i )
scannerData.getIncludePathNames().add( newIncludePaths[i] );
Iterator i = scannerData.getIncludePathNames().iterator();
while( i.hasNext() )
for( int i = 0; i < newIncludePaths.length; ++i )
{
String path = (String) i.next();
scannerData.getIncludePaths().add( new File( path ));
}
String path = newIncludePaths[i];
File file = new File( path );
if( !file.exists() && path.indexOf('\"') != -1 )
{
StringTokenizer tokenizer = new StringTokenizer(path, "\"" ); //$NON-NLS-1$
StringBuffer buffer = new StringBuffer(path.length() );
while( tokenizer.hasMoreTokens() ){
buffer.append( tokenizer.nextToken() );
}
file = new File( buffer.toString() );
}
if( file.exists() && file.isDirectory() )
scannerData.getIncludePathNames().add( path );
}
}
public void addDefinition(String key, IMacroDescriptor macro) {
@ -489,70 +497,67 @@ public class Scanner implements IScanner {
protected void handleInclusion(String fileName, boolean useIncludePaths, int beginOffset, int startLine, int nameOffset, int nameLine, int endOffset, int endLine ) throws ScannerException {
FileReader inclusionReader = null;
String newPath = null;
if( useIncludePaths ) // search include paths for this file
String newPath = null;
totalLoop: for( int i = 0; i < 2; ++i )
{
// iterate through the include paths
Iterator iter = scannerData.getIncludePaths().iterator();
while (iter.hasNext()) {
File pathFile = (File)iter.next();
String path = pathFile.getPath();
if( !pathFile.exists() && path.indexOf('\"') != -1 )
{
StringTokenizer tokenizer = new StringTokenizer(path, "\"" ); //$NON-NLS-1$
StringBuffer buffer = new StringBuffer(path.length() );
while( tokenizer.hasMoreTokens() ){
buffer.append( tokenizer.nextToken() );
}
pathFile = new File( buffer.toString() );
}
if (pathFile.isDirectory()) {
if( useIncludePaths ) // search include paths for this file
{
// iterate through the include paths
Iterator iter = scannerData.getIncludePathNames().iterator();
while (iter.hasNext()) {
String path = (String)iter.next();
File pathFile = new File(path);
//TODO assert pathFile.isDirectory();
StringBuffer buffer = new StringBuffer( pathFile.getPath() );
buffer.append( File.separatorChar );
buffer.append( fileName );
newPath = buffer.toString();
//TODO remove ".." and "." segments
File includeFile = new File(newPath);
if (includeFile.exists() && includeFile.isFile()) {
try {
inclusionReader = new FileReader(includeFile);
break;
break totalLoop;
} catch (FileNotFoundException fnf) {
// do nothing - check the next directory
continue;
}
}
}
if (inclusionReader == null )
handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true );
}
if (inclusionReader == null )
handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true );
}
else // local inclusion
{
String currentFilename = scannerData.getContextStack().getCurrentContext().getFilename();
File currentIncludeFile = new File( currentFilename );
String parentDirectory = currentIncludeFile.getParentFile().getAbsolutePath();
currentIncludeFile = null;
StringBuffer buffer = new StringBuffer( parentDirectory );
buffer.append( File.separatorChar );
buffer.append( fileName );
newPath = buffer.toString();
File includeFile = new File( newPath );
if (includeFile.exists() && includeFile.isFile()) {
try {
inclusionReader =
new FileReader(includeFile);
} catch (FileNotFoundException fnf) {
// the spec says that if finding in the local directory fails, search the include paths
handleInclusion( fileName, true, beginOffset, startLine, nameOffset, nameLine, endOffset, endLine );
}
}
else
else // local inclusion
{
// the spec says that if finding in the local directory fails, search the include paths
handleInclusion( fileName, true, beginOffset, startLine, nameOffset, nameLine, endOffset, endLine );
String currentFilename = scannerData.getContextStack().getCurrentContext().getFilename();
File currentIncludeFile = new File( currentFilename );
String parentDirectory = currentIncludeFile.getParentFile().getAbsolutePath();
currentIncludeFile = null;
StringBuffer buffer = new StringBuffer( parentDirectory );
buffer.append( File.separatorChar );
buffer.append( fileName );
newPath = buffer.toString();
//TODO remove ".." and "." segments
File includeFile = new File( newPath );
if (includeFile.exists() && includeFile.isFile()) {
try {
inclusionReader = new FileReader(includeFile);
break totalLoop;
} catch (FileNotFoundException fnf) {
useIncludePaths = true;
continue totalLoop;
}
}
else
{
useIncludePaths = true;
continue totalLoop;
}
}
}
if (inclusionReader != null) {

View file

@ -42,7 +42,6 @@ public class ScannerData implements IScannerData
private final IScanner scanner;
private final IScannerInfo originalConfig;
private List includePathNames = new ArrayList();
private List includePaths = new ArrayList();
/**
* @return Returns the contextStack.
@ -58,13 +57,6 @@ public class ScannerData implements IScannerData
this.includePathNames = includePathNames;
}
/**
* @param includePaths The includePaths to set.
*/
public void setIncludePaths(List includePaths) {
this.includePaths = includePaths;
}
/**
* @return Returns the includePathNames.
*/
@ -72,13 +64,6 @@ public class ScannerData implements IScannerData
return includePathNames;
}
/**
* @return Returns the includePaths.
*/
public List getIncludePaths() {
return includePaths;
}
/**
* @return Returns the originalConfig.
*/