mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-27 19:05:38 +02:00
Refactoring Scanner.handleInclusion to be more modular.
This commit is contained in:
parent
54e925ee1f
commit
d0ae8c2f99
4 changed files with 69 additions and 84 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2004-02-24 John Camelon
|
||||||
|
Refactoring Scanner.handleInclusion to be more modular.
|
||||||
|
|
||||||
2004-02-24 Andrew Niefer
|
2004-02-24 Andrew Niefer
|
||||||
Template Explicit Specializations (bug 51485)
|
Template Explicit Specializations (bug 51485)
|
||||||
adding basic symbol table functionality for non-nested template specializations
|
adding basic symbol table functionality for non-nested template specializations
|
||||||
|
|
|
@ -35,18 +35,10 @@ public interface IScannerData {
|
||||||
* @param includePathNames The includePathNames to set.
|
* @param includePathNames The includePathNames to set.
|
||||||
*/
|
*/
|
||||||
public abstract void setIncludePathNames(List includePathNames);
|
public abstract void setIncludePathNames(List includePathNames);
|
||||||
/**
|
|
||||||
* @param includePaths The includePaths to set.
|
|
||||||
*/
|
|
||||||
public abstract void setIncludePaths(List includePaths);
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the includePathNames.
|
* @return Returns the includePathNames.
|
||||||
*/
|
*/
|
||||||
public abstract List getIncludePathNames();
|
public abstract List getIncludePathNames();
|
||||||
/**
|
|
||||||
* @return Returns the includePaths.
|
|
||||||
*/
|
|
||||||
public abstract List getIncludePaths();
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the originalConfig.
|
* @return Returns the originalConfig.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -286,27 +286,35 @@ public class Scanner implements IScanner {
|
||||||
}
|
}
|
||||||
initialContextInitialized = true;
|
initialContextInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIncludePath(String includePath) {
|
public void addIncludePath(String includePath) {
|
||||||
scannerData.getIncludePathNames().add(includePath);
|
scannerData.getIncludePathNames().add(includePath);
|
||||||
scannerData.getIncludePaths().add( new File( includePath ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void overwriteIncludePath(String [] newIncludePaths) {
|
public void overwriteIncludePath(String [] newIncludePaths) {
|
||||||
if( newIncludePaths == null ) return;
|
if( newIncludePaths == null ) return;
|
||||||
scannerData.setIncludePathNames(new ArrayList());
|
scannerData.setIncludePathNames(new ArrayList());
|
||||||
scannerData.setIncludePaths( new ArrayList() );
|
|
||||||
|
|
||||||
for( int i = 0; i < newIncludePaths.length; ++i )
|
for( int i = 0; i < newIncludePaths.length; ++i )
|
||||||
scannerData.getIncludePathNames().add( newIncludePaths[i] );
|
|
||||||
|
|
||||||
Iterator i = scannerData.getIncludePathNames().iterator();
|
|
||||||
while( i.hasNext() )
|
|
||||||
{
|
{
|
||||||
String path = (String) i.next();
|
String path = newIncludePaths[i];
|
||||||
scannerData.getIncludePaths().add( new File( path ));
|
|
||||||
}
|
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) {
|
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 {
|
protected void handleInclusion(String fileName, boolean useIncludePaths, int beginOffset, int startLine, int nameOffset, int nameLine, int endOffset, int endLine ) throws ScannerException {
|
||||||
|
|
||||||
FileReader inclusionReader = null;
|
FileReader inclusionReader = null;
|
||||||
String newPath = null;
|
String newPath = null;
|
||||||
if( useIncludePaths ) // search include paths for this file
|
|
||||||
|
totalLoop: for( int i = 0; i < 2; ++i )
|
||||||
{
|
{
|
||||||
// iterate through the include paths
|
if( useIncludePaths ) // search include paths for this file
|
||||||
Iterator iter = scannerData.getIncludePaths().iterator();
|
{
|
||||||
|
// iterate through the include paths
|
||||||
while (iter.hasNext()) {
|
Iterator iter = scannerData.getIncludePathNames().iterator();
|
||||||
|
|
||||||
File pathFile = (File)iter.next();
|
while (iter.hasNext()) {
|
||||||
String path = pathFile.getPath();
|
|
||||||
if( !pathFile.exists() && path.indexOf('\"') != -1 )
|
String path = (String)iter.next();
|
||||||
{
|
File pathFile = new File(path);
|
||||||
StringTokenizer tokenizer = new StringTokenizer(path, "\"" ); //$NON-NLS-1$
|
//TODO assert pathFile.isDirectory();
|
||||||
StringBuffer buffer = new StringBuffer(path.length() );
|
|
||||||
while( tokenizer.hasMoreTokens() ){
|
|
||||||
buffer.append( tokenizer.nextToken() );
|
|
||||||
}
|
|
||||||
pathFile = new File( buffer.toString() );
|
|
||||||
}
|
|
||||||
if (pathFile.isDirectory()) {
|
|
||||||
StringBuffer buffer = new StringBuffer( pathFile.getPath() );
|
StringBuffer buffer = new StringBuffer( pathFile.getPath() );
|
||||||
buffer.append( File.separatorChar );
|
buffer.append( File.separatorChar );
|
||||||
buffer.append( fileName );
|
buffer.append( fileName );
|
||||||
newPath = buffer.toString();
|
newPath = buffer.toString();
|
||||||
|
//TODO remove ".." and "." segments
|
||||||
File includeFile = new File(newPath);
|
File includeFile = new File(newPath);
|
||||||
if (includeFile.exists() && includeFile.isFile()) {
|
if (includeFile.exists() && includeFile.isFile()) {
|
||||||
try {
|
try {
|
||||||
inclusionReader = new FileReader(includeFile);
|
inclusionReader = new FileReader(includeFile);
|
||||||
break;
|
break totalLoop;
|
||||||
} catch (FileNotFoundException fnf) {
|
} catch (FileNotFoundException fnf) {
|
||||||
// do nothing - check the next directory
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inclusionReader == null )
|
||||||
|
handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else // local inclusion
|
||||||
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
|
|
||||||
{
|
{
|
||||||
// the spec says that if finding in the local directory fails, search the include paths
|
String currentFilename = scannerData.getContextStack().getCurrentContext().getFilename();
|
||||||
handleInclusion( fileName, true, beginOffset, startLine, nameOffset, nameLine, endOffset, endLine );
|
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) {
|
if (inclusionReader != null) {
|
||||||
|
|
|
@ -42,7 +42,6 @@ public class ScannerData implements IScannerData
|
||||||
private final IScanner scanner;
|
private final IScanner scanner;
|
||||||
private final IScannerInfo originalConfig;
|
private final IScannerInfo originalConfig;
|
||||||
private List includePathNames = new ArrayList();
|
private List includePathNames = new ArrayList();
|
||||||
private List includePaths = new ArrayList();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the contextStack.
|
* @return Returns the contextStack.
|
||||||
|
@ -58,13 +57,6 @@ public class ScannerData implements IScannerData
|
||||||
this.includePathNames = includePathNames;
|
this.includePathNames = includePathNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param includePaths The includePaths to set.
|
|
||||||
*/
|
|
||||||
public void setIncludePaths(List includePaths) {
|
|
||||||
this.includePaths = includePaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the includePathNames.
|
* @return Returns the includePathNames.
|
||||||
*/
|
*/
|
||||||
|
@ -72,13 +64,6 @@ public class ScannerData implements IScannerData
|
||||||
return includePathNames;
|
return includePathNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns the includePaths.
|
|
||||||
*/
|
|
||||||
public List getIncludePaths() {
|
|
||||||
return includePaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the originalConfig.
|
* @return Returns the originalConfig.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue