mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +02:00
Put back the work to reconcile relative paths w/IResource readers which was lost upon merge.
This commit is contained in:
parent
f28275b669
commit
2805a77fe0
4 changed files with 126 additions and 9 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2004-03-09 John Camelon
|
||||||
|
Put back the work to reconcile relative paths w/IResource readers which was lost upon merge.
|
||||||
|
|
||||||
2004-03-09 Dave Daoust
|
2004-03-09 Dave Daoust
|
||||||
Removed the Strings associated with constant value tokens and keywords -- it looks cleaner, and reduces the number of objects created (only by 30 to 40 K) (about 2% quicker)
|
Removed the Strings associated with constant value tokens and keywords -- it looks cleaner, and reduces the number of objects created (only by 30 to 40 K) (about 2% quicker)
|
||||||
Buffered the File I/O associated with reading inclusions.
|
Buffered the File I/O associated with reading inclusions.
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser;
|
package org.eclipse.cdt.internal.core.parser;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
@ -44,7 +45,8 @@ public class InternalParserUtil extends ParserFactory {
|
||||||
{
|
{
|
||||||
//check and see
|
//check and see
|
||||||
try {
|
try {
|
||||||
return new FileReader( includeFile);
|
|
||||||
|
return new BufferedReader( new FileReader( includeFile) );
|
||||||
} catch (FileNotFoundException fnf) {
|
} catch (FileNotFoundException fnf) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,7 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
@ -28,7 +25,9 @@ import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.BacktrackException;import org.eclipse.cdt.core.parser.Directives;
|
import org.eclipse.cdt.core.parser.BacktrackException;
|
||||||
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
|
import org.eclipse.cdt.core.parser.Directives;
|
||||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
|
@ -506,7 +505,119 @@ public class Scanner implements IScanner {
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CodeReader createReaderDuple( String path, String fileName )
|
||||||
|
{
|
||||||
|
File pathFile = new File(path);
|
||||||
|
//TODO assert pathFile.isDirectory();
|
||||||
|
StringBuffer newPathBuffer = new StringBuffer( pathFile.getPath() );
|
||||||
|
newPathBuffer.append( File.separatorChar );
|
||||||
|
newPathBuffer.append( fileName );
|
||||||
|
//remove ".." and "." segments
|
||||||
|
String finalPath = reconcilePath( newPathBuffer.toString() );
|
||||||
|
Reader r = scannerData.getClientRequestor().createReader( finalPath );
|
||||||
|
if( r != null )
|
||||||
|
return new CodeReader( finalPath, r );
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String reconcilePath(String originalPath ) {
|
||||||
|
if( originalPath == null ) return null;
|
||||||
|
String [] segments = originalPath.split( "[/\\\\]" ); //$NON-NLS-1$
|
||||||
|
if( segments.length == 1 ) return originalPath;
|
||||||
|
Vector results = new Vector();
|
||||||
|
for( int i = 0; i < segments.length; ++i )
|
||||||
|
{
|
||||||
|
String segment = segments[i];
|
||||||
|
if( segment.equals( ".") ) continue; //$NON-NLS-1$
|
||||||
|
if( segment.equals("..") ) //$NON-NLS-1$
|
||||||
|
{
|
||||||
|
if( results.size() > 0 )
|
||||||
|
results.removeElementAt( results.size() - 1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
results.add( segment );
|
||||||
|
}
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
Iterator i = results.iterator();
|
||||||
|
while( i.hasNext() )
|
||||||
|
{
|
||||||
|
buffer.append( (String)i.next() );
|
||||||
|
if( i.hasNext() )
|
||||||
|
buffer.append( File.separatorChar );
|
||||||
|
}
|
||||||
|
scannerData.getLogService().traceLog( "Path has been reduced to " + buffer.toString()); //$NON-NLS-1$
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
|
CodeReader duple = null;
|
||||||
|
totalLoop: for( int i = 0; i < 2; ++i )
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
duple = createReaderDuple( path, fileName );
|
||||||
|
if( duple != null )
|
||||||
|
break totalLoop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duple == null )
|
||||||
|
handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true );
|
||||||
|
|
||||||
|
}
|
||||||
|
else // local inclusion
|
||||||
|
{
|
||||||
|
duple = createReaderDuple( new File( scannerData.getContextStack().getCurrentContext().getFilename() ).getParentFile().getAbsolutePath(), fileName );
|
||||||
|
if( duple != null )
|
||||||
|
break totalLoop;
|
||||||
|
useIncludePaths = true;
|
||||||
|
continue totalLoop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duple!= null) {
|
||||||
|
IASTInclusion inclusion = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inclusion =
|
||||||
|
scannerData.getASTFactory().createInclusion(
|
||||||
|
fileName,
|
||||||
|
duple.getFilename(),
|
||||||
|
!useIncludePaths,
|
||||||
|
beginOffset,
|
||||||
|
startLine,
|
||||||
|
nameOffset,
|
||||||
|
nameOffset + fileName.length(), nameLine, endOffset, endLine);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
/* do nothing */
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scannerData.getContextStack().updateContext(duple.getUnderlyingReader(), duple.getFilename(), ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() );
|
||||||
|
}
|
||||||
|
catch (ContextException e1)
|
||||||
|
{
|
||||||
|
handleProblem( e1.getId(), fileName, beginOffset, false, true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* protected void handleInclusion(String fileName, boolean useIncludePaths, int beginOffset, int startLine, int nameOffset, int nameLine, int endOffset, int endLine ) throws ScannerException {
|
||||||
// if useIncludePaths is true then
|
// if useIncludePaths is true then
|
||||||
// #include <foo.h>
|
// #include <foo.h>
|
||||||
// else
|
// else
|
||||||
|
@ -568,7 +679,7 @@ public class Scanner implements IScanner {
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
/* do nothing */
|
do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -581,7 +692,7 @@ public class Scanner implements IScanner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// constants
|
// constants
|
||||||
private static final int NOCHAR = -1;
|
private static final int NOCHAR = -1;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
|
@ -64,8 +65,8 @@ public class ParserUtil
|
||||||
if( result != null && result.getType() == IResource.FILE )
|
if( result != null && result.getType() == IResource.FILE )
|
||||||
{
|
{
|
||||||
BufferedInputStream bufferedStream = new BufferedInputStream( ((IFile) result).getContents() );
|
BufferedInputStream bufferedStream = new BufferedInputStream( ((IFile) result).getContents() );
|
||||||
InputStreamReader reader = new InputStreamReader( bufferedStream );
|
InputStreamReader inputReader = new InputStreamReader( bufferedStream );
|
||||||
return reader;
|
return new BufferedReader( inputReader );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( CoreException ce )
|
catch( CoreException ce )
|
||||||
|
|
Loading…
Add table
Reference in a new issue