mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
org.eclipse.cdt.core
Fixed Bug 43051 : Search: cannot specify relative search paths Fixed Bug 45140 : refactor IScanner to allow use of Readers of IResource org.eclipse.cdt.core.tests org.eclipse.cdt.ui Updates for new ISourceElementRequestor interface updates.
This commit is contained in:
parent
d3890d72b5
commit
f070a52e93
14 changed files with 233 additions and 57 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2004-02-25 John Camelon
|
||||||
|
Updates for new ISourceElementRequestor interface updates.
|
||||||
|
|
||||||
2004-02-25 John Camelon
|
2004-02-25 John Camelon
|
||||||
Added ScannerTestCase::testGerman().
|
Added ScannerTestCase::testGerman().
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests;
|
package org.eclipse.cdt.core.parser.tests;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -30,6 +31,7 @@ import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||||
|
@ -672,6 +674,13 @@ public class CompleteParseBaseTest extends TestCase
|
||||||
processReference( reference );
|
processReference( reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
|
||||||
|
*/
|
||||||
|
public Reader createReader(String finalPath) {
|
||||||
|
return ParserUtil.createReader(finalPath);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Iterator getNestedScopes( IASTCodeScope scope )
|
protected Iterator getNestedScopes( IASTCodeScope scope )
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.internal.core.parser.IExpressionParser;
|
import org.eclipse.cdt.internal.core.parser.IExpressionParser;
|
||||||
import org.eclipse.cdt.internal.core.parser.InternalParserFactory;
|
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||||
|
|
||||||
public class ExprEvalTest extends TestCase {
|
public class ExprEvalTest extends TestCase {
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public class ExprEvalTest extends TestCase {
|
||||||
public void runTest(String code, int expectedValue) throws Exception {
|
public void runTest(String code, int expectedValue) throws Exception {
|
||||||
|
|
||||||
final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor();
|
final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor();
|
||||||
IExpressionParser parser = InternalParserFactory.createExpressionParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService() ), ParserLanguage.CPP, null );
|
IExpressionParser parser = InternalParserUtil.createExpressionParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService() ), ParserLanguage.CPP, null );
|
||||||
IASTExpression expression = parser.expression(null);
|
IASTExpression expression = parser.expression(null);
|
||||||
assertEquals(expectedValue, expression.evaluateExpression());
|
assertEquals(expectedValue, expression.evaluateExpression());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,14 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
* @author bgheorgh
|
* @author bgheorgh
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.DefaultProblemHandler;
|
import org.eclipse.cdt.core.parser.DefaultProblemHandler;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
||||||
|
@ -476,4 +478,10 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
|
||||||
private IASTInclusion peekInclude(){
|
private IASTInclusion peekInclude(){
|
||||||
return currentInclude;
|
return currentInclude;
|
||||||
}
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
|
||||||
|
*/
|
||||||
|
public Reader createReader(String finalPath) {
|
||||||
|
return ParserUtil.createReader(finalPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
2004-02-25 John Camelon
|
||||||
|
Fixed Bug 43051 : Search: cannot specify relative search paths
|
||||||
|
Fixed Bug 45140 : refactor IScanner to allow use of Readers of IResource
|
||||||
|
|
||||||
2004-02-25 John Camelon
|
2004-02-25 John Camelon
|
||||||
Updated Scanner to allow for invalid identifier names despite C++'s best efforts at maintaining its honour.
|
Updated Scanner to allow for invalid identifier names despite C++'s best efforts at maintaining its honour.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2002-2004 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
***********************************************************************/
|
||||||
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public class CodeReader {
|
||||||
|
|
||||||
|
public CodeReader( String filename, Reader reader )
|
||||||
|
{
|
||||||
|
this.reader = reader;
|
||||||
|
this.filename = filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Reader reader;
|
||||||
|
private final String filename;
|
||||||
|
|
||||||
|
public String getFilename()
|
||||||
|
{
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reader getUnderlyingReader()
|
||||||
|
{
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,8 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
||||||
|
@ -102,4 +104,10 @@ public interface ISourceElementRequestor {
|
||||||
public void exitNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition );
|
public void exitNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition );
|
||||||
public void exitInclusion( IASTInclusion inclusion );
|
public void exitInclusion( IASTInclusion inclusion );
|
||||||
public void exitCompilationUnit( IASTCompilationUnit compilationUnit );
|
public void exitCompilationUnit( IASTCompilationUnit compilationUnit );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param finalPath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Reader createReader(String finalPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
||||||
|
@ -31,6 +33,7 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||||
|
|
||||||
|
|
||||||
public class NullSourceElementRequestor implements ISourceElementRequestor
|
public class NullSourceElementRequestor implements ISourceElementRequestor
|
||||||
|
@ -449,4 +452,11 @@ public class NullSourceElementRequestor implements ISourceElementRequestor
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
|
||||||
|
*/
|
||||||
|
public Reader createReader(String finalPath) {
|
||||||
|
return InternalParserUtil.createFileReader( finalPath );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser;
|
package org.eclipse.cdt.internal.core.parser;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
|
@ -19,7 +24,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class InternalParserFactory extends ParserFactory {
|
public class InternalParserUtil extends ParserFactory {
|
||||||
|
|
||||||
public static IExpressionParser createExpressionParser( IScanner scanner, ParserLanguage language, IParserLogService log ) throws ParserFactoryError
|
public static IExpressionParser createExpressionParser( IScanner scanner, ParserLanguage language, IParserLogService log ) throws ParserFactoryError
|
||||||
{
|
{
|
||||||
|
@ -29,4 +34,21 @@ public class InternalParserFactory extends ParserFactory {
|
||||||
return new ExpressionParser( scanner, language, logService );
|
return new ExpressionParser( scanner, language, logService );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param finalPath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Reader createFileReader(String finalPath) {
|
||||||
|
File includeFile = new File(finalPath);
|
||||||
|
if (includeFile.exists() && includeFile.isFile())
|
||||||
|
{
|
||||||
|
//check and see
|
||||||
|
try {
|
||||||
|
return new FileReader( includeFile);
|
||||||
|
} catch (FileNotFoundException fnf) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,8 +11,6 @@
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
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,6 +26,7 @@ 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.BacktrackException;
|
||||||
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.Directives;
|
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;
|
||||||
|
@ -54,8 +53,8 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||||
import org.eclipse.cdt.internal.core.parser.*;
|
import org.eclipse.cdt.internal.core.parser.IExpressionParser;
|
||||||
import org.eclipse.cdt.internal.core.parser.InternalParserFactory;
|
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode;
|
import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode;
|
||||||
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
||||||
import org.eclipse.cdt.internal.core.parser.token.Token;
|
import org.eclipse.cdt.internal.core.parser.token.Token;
|
||||||
|
@ -309,6 +308,7 @@ public class Scanner implements IScanner {
|
||||||
buffer.append( tokenizer.nextToken() );
|
buffer.append( tokenizer.nextToken() );
|
||||||
}
|
}
|
||||||
file = new File( buffer.toString() );
|
file = new File( buffer.toString() );
|
||||||
|
path = buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( file.exists() && file.isDirectory() )
|
if( file.exists() && file.isDirectory() )
|
||||||
|
@ -496,9 +496,7 @@ 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;
|
CodeReader duple = null;
|
||||||
String newPath = null;
|
|
||||||
|
|
||||||
totalLoop: for( int i = 0; i < 2; ++i )
|
totalLoop: for( int i = 0; i < 2; ++i )
|
||||||
{
|
{
|
||||||
if( useIncludePaths ) // search include paths for this file
|
if( useIncludePaths ) // search include paths for this file
|
||||||
|
@ -509,65 +507,33 @@ public class Scanner implements IScanner {
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
|
|
||||||
String path = (String)iter.next();
|
String path = (String)iter.next();
|
||||||
File pathFile = new File(path);
|
duple = createReaderDuple( path, fileName );
|
||||||
//TODO assert pathFile.isDirectory();
|
if( duple != null )
|
||||||
StringBuffer buffer = new StringBuffer( pathFile.getPath() );
|
break totalLoop;
|
||||||
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) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inclusionReader == null )
|
if (duple == null )
|
||||||
handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true );
|
handleProblem( IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, fileName, beginOffset, false, true );
|
||||||
|
|
||||||
}
|
}
|
||||||
else // local inclusion
|
else // local inclusion
|
||||||
{
|
{
|
||||||
String currentFilename = scannerData.getContextStack().getCurrentContext().getFilename();
|
duple = createReaderDuple( new File( scannerData.getContextStack().getCurrentContext().getFilename() ).getParentFile().getAbsolutePath(), fileName );
|
||||||
File currentIncludeFile = new File( currentFilename );
|
if( duple != null )
|
||||||
String parentDirectory = currentIncludeFile.getParentFile().getAbsolutePath();
|
break totalLoop;
|
||||||
currentIncludeFile = null;
|
useIncludePaths = true;
|
||||||
|
continue totalLoop;
|
||||||
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 (duple!= null) {
|
||||||
IASTInclusion inclusion = null;
|
IASTInclusion inclusion = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
inclusion =
|
inclusion =
|
||||||
scannerData.getASTFactory().createInclusion(
|
scannerData.getASTFactory().createInclusion(
|
||||||
fileName,
|
fileName,
|
||||||
newPath,
|
duple.getFilename(),
|
||||||
!useIncludePaths,
|
!useIncludePaths,
|
||||||
beginOffset,
|
beginOffset,
|
||||||
startLine,
|
startLine,
|
||||||
|
@ -581,7 +547,7 @@ public class Scanner implements IScanner {
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
scannerData.getContextStack().updateContext(inclusionReader, newPath, ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() );
|
scannerData.getContextStack().updateContext(duple.getUnderlyingReader(), duple.getFilename(), ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() );
|
||||||
}
|
}
|
||||||
catch (ContextException e1)
|
catch (ContextException e1)
|
||||||
{
|
{
|
||||||
|
@ -2283,7 +2249,7 @@ public class Scanner implements IScanner {
|
||||||
EXPRESSION,
|
EXPRESSION,
|
||||||
new ScannerInfo( scannerData.getDefinitions(), scannerData.getOriginalConfig().getIncludePaths()),
|
new ScannerInfo( scannerData.getDefinitions(), scannerData.getOriginalConfig().getIncludePaths()),
|
||||||
ParserMode.QUICK_PARSE, scannerData.getLanguage(), new NullSourceElementRequestor(), nullLogService );
|
ParserMode.QUICK_PARSE, scannerData.getLanguage(), new NullSourceElementRequestor(), nullLogService );
|
||||||
parser = InternalParserFactory.createExpressionParser(trial, scannerData.getLanguage(), nullLogService);
|
parser = InternalParserUtil.createExpressionParser(trial, scannerData.getLanguage(), nullLogService);
|
||||||
} catch( ParserFactoryError pfe )
|
} catch( ParserFactoryError pfe )
|
||||||
{
|
{
|
||||||
handleInternalError();
|
handleInternalError();
|
||||||
|
@ -3129,4 +3095,53 @@ public class Scanner implements IScanner {
|
||||||
return ( scannerData.getContextStack().getCurrentContext() == scannerData.getContextStack().getTopContext() );
|
return ( scannerData.getContextStack().getCurrentContext() == scannerData.getContextStack().getTopContext() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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( "[/\\\\]" );
|
||||||
|
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;
|
||||||
|
if( segment.equals("..") )
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -593,4 +593,11 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
||||||
public static void verbose(String log) {
|
public static void verbose(String log) {
|
||||||
System.out.println("(" + Thread.currentThread() + ") " + log);
|
System.out.println("(" + Thread.currentThread() + ") " + log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
|
||||||
|
*/
|
||||||
|
public Reader createReader(String finalPath) {
|
||||||
|
return ParserUtil.createReader(finalPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,20 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.IDebugLogConstants;
|
import org.eclipse.cdt.internal.core.model.IDebugLogConstants;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserLogService;
|
import org.eclipse.cdt.internal.core.parser.ParserLogService;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -34,4 +46,31 @@ public class ParserUtil
|
||||||
public static IParserLogService getScannerLogService() {
|
public static IParserLogService getScannerLogService() {
|
||||||
return scannerLogService;
|
return scannerLogService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Reader createReader( String finalPath )
|
||||||
|
{
|
||||||
|
// check to see if the file which this path points to points to an
|
||||||
|
// IResource in the workspace
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
|
IPath path = new Path( finalPath );
|
||||||
|
|
||||||
|
if( workspace.getRoot().getLocation().isPrefixOf( path ) )
|
||||||
|
path = path.removeFirstSegments(workspace.getRoot().getLocation().segmentCount() );
|
||||||
|
|
||||||
|
IResource result = workspace.getRoot().findMember(path);
|
||||||
|
|
||||||
|
if( result != null && result.getType() == IResource.FILE )
|
||||||
|
{
|
||||||
|
BufferedInputStream bufferedStream = new BufferedInputStream( ((IFile) result).getContents() );
|
||||||
|
InputStreamReader reader = new InputStreamReader( bufferedStream );
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( CoreException ce )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return InternalParserUtil.createFileReader(finalPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2004-02-25 John Camelon
|
||||||
|
Updates for new ISourceElementRequestor interface updates.
|
||||||
|
|
||||||
2004-02-24 Alain Magloire
|
2004-02-24 Alain Magloire
|
||||||
|
|
||||||
New constructor for ShowInCView.
|
New constructor for ShowInCView.
|
||||||
|
|
|
@ -11,10 +11,13 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.compare;
|
package org.eclipse.cdt.internal.ui.compare;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.DefaultProblemHandler;
|
import org.eclipse.cdt.core.parser.DefaultProblemHandler;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
import org.eclipse.cdt.core.parser.ast.IASTClassReference;
|
||||||
|
@ -331,4 +334,11 @@ public class SourceElementRequestorAdapter implements ISourceElementRequestor {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
|
||||||
|
*/
|
||||||
|
public Reader createReader(String finalPath) {
|
||||||
|
return ParserUtil.createReader(finalPath);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue