1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Changed the interface to the Scanner to take a CodeReader object.

A CodeReader simply contains a char[] and the name of the file, if any,
that the char[] is the contents of. This leads us down the path of using
char[]s in the parser instead of Strings in an attempt to cut down on
our memory usage.
This commit is contained in:
Doug Schaefer 2004-06-04 21:01:48 +00:00
parent 98800badf4
commit a206e32d2a
47 changed files with 327 additions and 322 deletions

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.managedbuild.core.tests; package org.eclipse.cdt.managedbuild.core.tests;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -23,6 +22,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
@ -1508,8 +1508,8 @@ public class ManagedBuildCoreTests extends TestCase {
IScannerInfo info = provider.getScannerInformation( project ); IScannerInfo info = provider.getScannerInformation( project );
ISourceElementRequestor callback = new NullSourceElementRequestor(); ISourceElementRequestor callback = new NullSourceElementRequestor();
IScanner scanner = ParserFactory.createScanner( new StringReader( "#include <header.h>\n int A::i = 1;" ), IScanner scanner = ParserFactory.createScanner( new CodeReader( "#include <header.h>\n int A::i = 1;".toCharArray() ),
"TEST", info, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, callback, new NullLogService(), null); info, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, callback, new NullLogService(), null);
IParser parser = ParserFactory.createParser( scanner, callback, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, null ); IParser parser = ParserFactory.createParser( scanner, callback, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, null );
assertTrue( parser.parse() ); assertTrue( parser.parse() );

View file

@ -117,6 +117,8 @@ import org.eclipse.core.runtime.Platform;
//Delete project //Delete project
if (testProject.exists()){ if (testProject.exists()){
try { try {
System.gc();
System.runFinalization();
testProject.delete(true,monitor); testProject.delete(true,monitor);
} catch (CoreException e) { } catch (CoreException e) {
fail(getMessage(e.getStatus())); fail(getMessage(e.getStatus()));
@ -470,8 +472,7 @@ import org.eclipse.core.runtime.Platform;
j++; j++;
} }
if (postDepTestModelLocal.length != postDepTestIncludes.length) assertEquals(postDepTestModelLocal.length, postDepTestIncludes.length);
fail("Number of included files differs from model");
Arrays.sort(postDepTestModelLocal); Arrays.sort(postDepTestModelLocal);
Arrays.sort(postDepTestIncludes); Arrays.sort(postDepTestIncludes);

View file

@ -89,6 +89,8 @@ public class IndexManagerTests extends TestCase {
//Delete project //Delete project
if (testProject.exists()) { if (testProject.exists()) {
try { try {
System.gc();
System.runFinalization();
testProject.delete(true, monitor); testProject.delete(true, monitor);
} catch (CoreException e) { } catch (CoreException e) {
fail(getMessage(e.getStatus())); fail(getMessage(e.getStatus()));
@ -239,6 +241,8 @@ public class IndexManagerTests extends TestCase {
* @param testProject * @param testProject
*/ */
private void safeDelete(IProject testProject) throws InterruptedException, CoreException { private void safeDelete(IProject testProject) throws InterruptedException, CoreException {
System.gc();
System.runFinalization();
try { try {
testProject.delete(true, monitor); testProject.delete(true, monitor);
} catch (CoreException e) { } catch (CoreException e) {
@ -277,6 +281,9 @@ public class IndexManagerTests extends TestCase {
} }
//Delete mail.cpp from the project, give some time to remove index //Delete mail.cpp from the project, give some time to remove index
IResource resourceHdl = testProject.findMember("mail.cpp") ; IResource resourceHdl = testProject.findMember("mail.cpp") ;
// Cleaning up file handles before delete
System.gc();
System.runFinalization();
resourceHdl.delete(true,monitor); resourceHdl.delete(true,monitor);
Thread.sleep(10000); Thread.sleep(10000);
//See if the index is still there //See if the index is still there

View file

@ -175,6 +175,8 @@ public class BinaryTests extends TestCase {
* Called after every test case method. * Called after every test case method.
*/ */
protected void tearDown() throws CoreException, InterruptedException { protected void tearDown() throws CoreException, InterruptedException {
System.gc();
System.runFinalization();
CProjectHelper.delete(testProject); CProjectHelper.delete(testProject);
} }

View file

@ -58,7 +58,7 @@ public class AutomatedTest extends AutomatedFramework {
String filePath = file.getCanonicalPath(); String filePath = file.getCanonicalPath();
ParserLanguage language = ((String)natures.get( filePath )).equalsIgnoreCase("cpp") ? ParserLanguage.CPP : ParserLanguage.C; //$NON-NLS-1$ ParserLanguage language = ((String)natures.get( filePath )).equalsIgnoreCase("cpp") ? ParserLanguage.CPP : ParserLanguage.C; //$NON-NLS-1$
parser = ParserFactory.createParser( ParserFactory.createScanner( new InputStreamReader (stream), filePath, new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, null, null ), nullCallback, ParserMode.QUICK_PARSE, language, null); parser = ParserFactory.createParser( ParserFactory.createScanner(filePath, new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, null, null ), nullCallback, ParserMode.QUICK_PARSE, language, null);
mapping = ParserFactory.createLineOffsetReconciler( new InputStreamReader( stream ) ); mapping = ParserFactory.createLineOffsetReconciler( new InputStreamReader( stream ) );

View file

@ -10,11 +10,11 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.util.Iterator; import java.util.Iterator;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IQuickParseCallback; import org.eclipse.cdt.core.parser.IQuickParseCallback;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
@ -51,7 +51,7 @@ public class BaseASTTest extends TestCase
{ {
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
quickParseCallback = ParserFactory.createQuickParseCallback(); quickParseCallback = ParserFactory.createQuickParseCallback();
parser = ParserFactory.createParser( ParserFactory.createScanner( new StringReader( code ), "code", new ScannerInfo(), mode, lang, quickParseCallback, new NullLogService(), null), quickParseCallback, mode, lang, null ); //$NON-NLS-1$ parser = ParserFactory.createParser( ParserFactory.createScanner( new CodeReader(code.toCharArray()), new ScannerInfo(), mode, lang, quickParseCallback, new NullLogService(), null), quickParseCallback, mode, lang, null ); //$NON-NLS-1$
if( ! parser.parse() && throwExceptionOnError ) if( ! parser.parse() && throwExceptionOnError )
throw new ParserException("Parse failure"); //$NON-NLS-1$ throw new ParserException("Parse failure"); //$NON-NLS-1$
return quickParseCallback.getCompilationUnit(); return quickParseCallback.getCompilationUnit();

View file

@ -11,10 +11,9 @@
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
@ -47,7 +46,7 @@ public class BaseScannerTest extends TestCase {
protected void initializeScanner( String input, ParserMode mode, ISourceElementRequestor requestor ) throws ParserFactoryError protected void initializeScanner( String input, ParserMode mode, ISourceElementRequestor requestor ) throws ParserFactoryError
{ {
scanner= ParserFactory.createScanner( new StringReader(input),"TEXT", new ScannerInfo(), mode, ParserLanguage.CPP, requestor, null, null ); //$NON-NLS-1$ scanner= ParserFactory.createScanner( new CodeReader(input.toCharArray()), new ScannerInfo(), mode, ParserLanguage.CPP, requestor, null, null ); //$NON-NLS-1$
} }
protected void initializeScanner(String input) throws ParserFactoryError protected void initializeScanner(String input) throws ParserFactoryError

View file

@ -6,10 +6,10 @@
*/ */
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
@ -67,7 +67,7 @@ public class CompleteParseASTSymbolIteratorTest extends CompleteParseBaseTest {
{ {
callback = new CompilationUnitCallback(); callback = new CompilationUnitCallback();
IParser parser = ParserFactory.createParser( IParser parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(), //$NON-NLS-1$ ParserFactory.createScanner( new CodeReader(code.toCharArray()), new ScannerInfo(),
ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null
); );
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$

View file

@ -10,8 +10,6 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Hashtable; import java.util.Hashtable;
@ -22,6 +20,7 @@ import java.util.Stack;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
@ -737,7 +736,7 @@ public class CompleteParseBaseTest extends TestCase
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
*/ */
public Reader createReader(String finalPath, Iterator workingCopies) { public CodeReader createReader(String finalPath, Iterator workingCopies) {
return ParserUtil.createReader(finalPath,workingCopies); return ParserUtil.createReader(finalPath,workingCopies);
} }
@ -796,7 +795,7 @@ public class CompleteParseBaseTest extends TestCase
{ {
callback = new FullParseCallback(); callback = new FullParseCallback();
IParser parser = ParserFactory.createParser( IParser parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(), //$NON-NLS-1$ ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), //$NON-NLS-1$
ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null
); );
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$

View file

@ -10,10 +10,10 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
@ -51,8 +51,7 @@ public class CompletionParseBaseTest extends CompleteParseBaseTest {
parser = parser =
ParserFactory.createParser( ParserFactory.createParser(
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(code), new CodeReader(code.toCharArray()),
"completion-test", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.COMPLETION_PARSE, ParserMode.COMPLETION_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
@ -73,8 +72,7 @@ public class CompletionParseBaseTest extends CompleteParseBaseTest {
parser = parser =
ParserFactory.createParser( ParserFactory.createParser(
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(code), new CodeReader(code.toCharArray()),
"completion-test", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.COMPLETION_PARSE, ParserMode.COMPLETION_PARSE,
lang, lang,

View file

@ -1,11 +1,10 @@
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
@ -28,7 +27,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 = InternalParserUtil.createExpressionParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService(), null ), ParserLanguage.CPP, null ); IExpressionParser parser = InternalParserUtil.createExpressionParser(ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService(), null ), ParserLanguage.CPP, null );
IASTExpression expression = parser.expression(null,null, null); IASTExpression expression = parser.expression(null,null, null);
assertEquals(expectedValue, expression.evaluateExpression()); assertEquals(expectedValue, expression.evaluateExpression());
} }

View file

@ -15,13 +15,13 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
@ -242,7 +242,7 @@ public class FractionalAutomatedTest extends AutomatedFramework {
result = null; result = null;
ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C; ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C;
IParser parser = ParserFactory.createParser( IParser parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, new NullLogService(), null ), nullCallback, ParserMode.QUICK_PARSE, language, null ); ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, new NullLogService(), null ), nullCallback, ParserMode.QUICK_PARSE, language, null );
parser.parse(); parser.parse();
} catch ( Exception e ){ } catch ( Exception e ){

View file

@ -10,10 +10,10 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
@ -36,10 +36,9 @@ public class PreprocessorConditionalTest extends BaseScannerTest
protected void initializeScanner(String input, Map definitions ) throws Exception protected void initializeScanner(String input, Map definitions ) throws Exception
{ {
scanner= ParserFactory.createScanner( new StringReader(input),"TEXT", new ScannerInfo( definitions ), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, nullSourceElementRequestor, null, null ); //$NON-NLS-1$ scanner= ParserFactory.createScanner( new CodeReader(input.toCharArray()), new ScannerInfo( definitions ), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, nullSourceElementRequestor, null, null );
} }
protected void evaluateConditionalsPositive( String conditional, Map definitions ) throws Exception protected void evaluateConditionalsPositive( String conditional, Map definitions ) throws Exception
{ {

View file

@ -1156,7 +1156,7 @@ public class QuickParseASTTests extends BaseASTTest
String code = "#include <stdio.h>\n#define DEF VALUE\n"; //$NON-NLS-1$ String code = "#include <stdio.h>\n#define DEF VALUE\n"; //$NON-NLS-1$
IASTCompilationUnit tu = parse( code ); IASTCompilationUnit tu = parse( code.toString() );
assertFalse( tu.getDeclarations().hasNext()); assertFalse( tu.getDeclarations().hasNext());
Iterator inclusions = quickParseCallback.getInclusions(); Iterator inclusions = quickParseCallback.getInclusions();
Iterator macros = quickParseCallback.getMacros(); Iterator macros = quickParseCallback.getMacros();
@ -2244,9 +2244,4 @@ public class QuickParseASTTests extends BaseASTTest
assertFalse( iter.hasNext() ); assertFalse( iter.hasNext() );
} }
} }
public void testBug61972() throws Exception
{
parse( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;", true, false ); //$NON-NLS-1$
}
} }

View file

@ -9,8 +9,7 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader; import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
@ -43,8 +42,7 @@ public class SelectionParseBaseTest extends CompleteParseBaseTest {
parser = parser =
ParserFactory.createParser( ParserFactory.createParser(
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(code), new CodeReader(code.toCharArray()),
"completion-test", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.SELECTION_PARSE, ParserMode.SELECTION_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,

View file

@ -1,19 +1,12 @@
/*
* Created on Jun 3, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.Reader;
import java.io.StringReader;
import java.util.Collections; import java.util.Collections;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
@ -23,54 +16,43 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.parser.QuickParseCallback; import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
/** // A test that just calculates the speed of the parser
* @author Doug Schaefer // Eventually, we'll peg a max time and fail the test if it exceeds it
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SpeedTest extends TestCase { public class SpeedTest extends TestCase {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
new SpeedTest().runTest(1); new SpeedTest().test();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.out.println(e);
} }
} }
public void test() throws Exception { public void test() throws Exception {
runTest(1);
}
public void runTest(int n) throws Exception {
for (int i = 0; i < n; ++i) {
System.gc();
String code = String code =
"#include <windows.h>\n" + "#include <windows.h>\n" +
"#include <stdio.h>\n" + "#include <stdio.h>\n" +
"#include <iostream>\n"; "#include <iostream>\n";
Reader reader = new StringReader(code); CodeReader reader = new CodeReader(code.toCharArray());
IScannerInfo info = mingwScannerInfo(false); IScannerInfo info = mingwScannerInfo(false);
//IScannerInfo info = msvcScannerInfo(quick); //IScannerInfo info = msvcScannerInfo(quick);
testParse(reader, "text", false, info, ParserLanguage.CPP); testParse(reader, false, info, ParserLanguage.CPP);
}
} }
/** /**
* @param path * @param path
* @param quick TODO * @param quick TODO
*/ */
protected void testParse(Reader reader, String path, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception { protected void testParse(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception {
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
IScanner scanner = ParserFactory.createScanner(reader, path, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST ); IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST );
IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null); IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null);
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
long totalTime; long totalTime;
parser.parse(); parser.parse();
totalTime = System.currentTimeMillis() - startTime; totalTime = System.currentTimeMillis() - startTime;
System.out.println( "Resulting parse for " + path + " took " + totalTime + " millisecs"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println( "Resulting parse took " + totalTime + " millisecs"); //$NON-NLS-1$ //$NON-NLS-2$
} }
private static final QuickParseCallback CALLBACK = new QuickParseCallback(); private static final QuickParseCallback CALLBACK = new QuickParseCallback();
@ -93,6 +75,7 @@ public class SpeedTest extends TestCase {
} }
protected IScannerInfo mingwScannerInfo(boolean quick) { protected IScannerInfo mingwScannerInfo(boolean quick) {
// TODO It would be easier and more flexible if we used discovery for this
if( quick ) if( quick )
return new ScannerInfo(); return new ScannerInfo();
Map definitions = new Hashtable(); Map definitions = new Hashtable();

View file

@ -13,11 +13,11 @@
*/ */
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.util.Iterator; import java.util.Iterator;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
@ -59,7 +59,7 @@ public class StructuralParseTest extends TestCase {
{ {
callback = new StructuralParseCallback(); callback = new StructuralParseCallback();
IParser parser = ParserFactory.createParser( IParser parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(), //$NON-NLS-1$ ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), //$NON-NLS-1$
ParserMode.STRUCTURAL_PARSE, language, callback, new NullLogService(), null ), ParserMode.STRUCTURAL_PARSE, language, callback, new NullLogService(), null ),
callback, ParserMode.STRUCTURAL_PARSE, language, null callback, ParserMode.STRUCTURAL_PARSE, language, null
); );

View file

@ -22,6 +22,7 @@ import java.util.StringTokenizer;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ILineOffsetReconciler; import org.eclipse.cdt.core.parser.ILineOffsetReconciler;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.NullLogService;
@ -281,7 +282,7 @@ public class TortureTest extends FractionalAutomatedTest {
ParserMode parserMode = quickParse ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; ParserMode parserMode = quickParse ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C; ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C;
parser = ParserFactory.createParser( parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), parserMode, language, nullCallback, new NullLogService(), null ), nullCallback, parserMode, language, null); ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), parserMode, language, nullCallback, new NullLogService(), null ), nullCallback, parserMode, language, null);
mapping = ParserFactory.createLineOffsetReconciler( new StringReader( code ) ); mapping = ParserFactory.createLineOffsetReconciler( new StringReader( code ) );

View file

@ -11,8 +11,6 @@
package org.eclipse.cdt.core.search.tests; package org.eclipse.cdt.core.search.tests;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -34,7 +32,6 @@ import org.eclipse.core.runtime.Path;
*/ */
public class ParseTestOnSearchFiles extends TestCase public class ParseTestOnSearchFiles extends TestCase
{ {
private FileInputStream fileIn;
private String name; private String name;
private String fullPathName; private String fullPathName;
/** /**
@ -56,13 +53,12 @@ public class ParseTestOnSearchFiles extends TestCase
name = "resources/search/classDecl.cpp"; name = "resources/search/classDecl.cpp";
File f = CTestPlugin.getDefault().getFileInPlugin(new Path(name)); File f = CTestPlugin.getDefault().getFileInPlugin(new Path(name));
fullPathName = f.getAbsolutePath(); fullPathName = f.getAbsolutePath();
fileIn = new FileInputStream(f);
} }
public void testParseOfAndrewsFile() throws Exception public void testParseOfAndrewsFile() throws Exception
{ {
ISourceElementRequestor requestor = new NullSourceElementRequestor(); ISourceElementRequestor requestor = new NullSourceElementRequestor();
IScanner scanner = ParserFactory.createScanner( new InputStreamReader( fileIn ), fullPathName, new ScannerInfo(), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, requestor, new NullLogService(), null ); IScanner scanner = ParserFactory.createScanner( fullPathName, new ScannerInfo(), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, requestor, new NullLogService(), null );
IParser parser = ParserFactory.createParser( scanner, requestor, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, null ); IParser parser = ParserFactory.createParser( scanner, requestor, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, null );
assertTrue( parser.parse() ); assertTrue( parser.parse() );
} }

View file

@ -110,6 +110,8 @@ public class CProjectHelper {
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
} finally { } finally {
try { try {
System.gc();
System.runFinalization();
cproject.getProject().delete(true, true, null); cproject.getProject().delete(true, true, null);
} catch (CoreException e2) { } catch (CoreException e2) {
Assert.fail(getMessage(e2.getStatus())); Assert.fail(getMessage(e2.getStatus()));

View file

@ -11,13 +11,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.browser.cache; package org.eclipse.cdt.internal.core.browser.cache;
import java.io.CharArrayReader; import java.io.IOException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -38,6 +33,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.DefaultProblemHandler; import org.eclipse.cdt.core.parser.DefaultProblemHandler;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
@ -54,7 +50,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil; 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.ASTClassKind; import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
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;
@ -86,6 +81,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference;
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTypedefReference; import org.eclipse.cdt.core.parser.ast.IASTTypedefReference;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
@ -285,7 +281,7 @@ public class TypeParser implements ISourceElementRequestor {
return; // not C or C++ return; // not C or C++
} }
Reader reader = null; CodeReader reader = null;
Object stackObject = null; Object stackObject = null;
if (workingCopy != null) { if (workingCopy != null) {
@ -358,46 +354,44 @@ public class TypeParser implements ISourceElementRequestor {
return projectLanguage; return projectLanguage;
} }
private Reader createWorkingCopyReader(IWorkingCopy workingCopy) { private CodeReader createWorkingCopyReader(IWorkingCopy workingCopy) {
Reader reader = null; CodeReader reader = null;
IResource resource = workingCopy.getResource(); IResource resource = workingCopy.getResource();
if (resource != null && resource.isAccessible()) { if (resource != null && resource.isAccessible()) {
char[] contents = workingCopy.getContents(); char[] contents = workingCopy.getContents();
if (contents != null) if (contents != null)
reader = new CharArrayReader(contents); reader = new CodeReader(resource.getLocation().toOSString(), contents);
} }
return reader; return reader;
} }
private Reader createResourceReader(IResource resource) { private CodeReader createResourceReader(IResource resource) {
Reader reader = null; CodeReader reader = null;
if (resource.isAccessible() && resource instanceof IFile) { if (resource.isAccessible() && resource instanceof IFile) {
IFile file = (IFile) resource; IFile file = (IFile) resource;
try { try {
InputStream contents = file.getContents(); InputStream contents = file.getContents();
if (contents != null) if (contents != null)
reader = new InputStreamReader(contents); reader = new CodeReader(resource.getLocation().toOSString(), contents);
} catch (CoreException ex) { } catch (CoreException ex) {
ex.printStackTrace(); ex.printStackTrace();
} catch (IOException e) {
} }
} }
return reader; return reader;
} }
private Reader createFileReader(IPath path) { private CodeReader createFileReader(IPath path) {
Reader reader = null; CodeReader reader = null;
File file = path.toFile();
if (file != null) {
try { try {
reader = new FileReader(file); reader = new CodeReader(path.toOSString());
} catch (FileNotFoundException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
}
return reader; return reader;
} }
private void parseContents(IPath realPath, IProject project, Reader reader, ParserLanguage language, IProgressMonitor progressMonitor) throws InterruptedException { private void parseContents(IPath realPath, IProject project, CodeReader reader, ParserLanguage language, IProgressMonitor progressMonitor) throws InterruptedException {
IScannerInfo scanInfo = null; IScannerInfo scanInfo = null;
if (project != null) { if (project != null) {
@ -418,7 +412,7 @@ public class TypeParser implements ISourceElementRequestor {
try { try {
fProgressMonitor = progressMonitor; fProgressMonitor = progressMonitor;
IScanner scanner = ParserFactory.createScanner(reader, realPath.toOSString(), scanInfo, IScanner scanner = ParserFactory.createScanner(reader, scanInfo,
ParserMode.STRUCTURAL_PARSE, language, this, ParserUtil.getScannerLogService(), null); ParserMode.STRUCTURAL_PARSE, language, this, ParserUtil.getScannerLogService(), null);
IParser parser = ParserFactory.createParser(scanner, this, ParserMode.STRUCTURAL_PARSE, language, ParserUtil.getParserLogService()); IParser parser = ParserFactory.createParser(scanner, this, ParserMode.STRUCTURAL_PARSE, language, ParserUtil.getParserLogService());
parser.parse(); parser.parse();
@ -711,7 +705,7 @@ public class TypeParser implements ISourceElementRequestor {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
*/ */
public Reader createReader(String finalPath, Iterator workingCopies) { public CodeReader createReader(String finalPath, Iterator workingCopies) {
return ParserUtil.createReader(finalPath, workingCopies); return ParserUtil.createReader(finalPath, workingCopies);
} }

View file

@ -16,14 +16,13 @@ package org.eclipse.cdt.internal.core.search.indexing;
*/ */
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants; import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IScannerInfoProvider;
@ -103,10 +102,10 @@ public class SourceIndexer extends AbstractIndexer {
try try
{ {
CodeReader reader = new CodeReader(resourceFile.getLocation().toOSString(), resourceFile.getContents());
BufferedInputStream inStream = new BufferedInputStream(resourceFile.getContents()); BufferedInputStream inStream = new BufferedInputStream(resourceFile.getContents());
parser = ParserFactory.createParser( parser = ParserFactory.createParser(
ParserFactory.createScanner( new BufferedReader(new InputStreamReader(inStream)), resourceFile.getLocation().toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getScannerLogService(), null ), ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getScannerLogService(), null ),
requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() ); requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() );
} catch( ParserFactoryError pfe ) } catch( ParserFactoryError pfe )
{ {

View file

@ -16,7 +16,6 @@ package org.eclipse.cdt.internal.core.search.indexing;
*/ */
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -26,6 +25,7 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.parser.CodeReader;
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;
@ -566,7 +566,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
*/ */
public Reader createReader(String finalPath, Iterator workingCopies) { public CodeReader createReader(String finalPath, Iterator workingCopies) {
return ParserUtil.createReader(finalPath,workingCopies); return ParserUtil.createReader(finalPath,workingCopies);
} }

View file

@ -10,8 +10,6 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -23,6 +21,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IProblemRequestor; import org.eclipse.cdt.core.model.IProblemRequestor;
import org.eclipse.cdt.core.model.ITemplate; import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IQuickParseCallback; import org.eclipse.cdt.core.parser.IQuickParseCallback;
@ -164,12 +163,13 @@ public class CModelBuilder {
} }
} }
CodeReader reader =
translationUnit.getUnderlyingResource() != null
? new CodeReader(translationUnit.getUnderlyingResource().getLocation().toOSString(), code.toCharArray())
: new CodeReader(code.toCharArray());
parser = ParserFactory.createParser( parser = ParserFactory.createParser(
ParserFactory.createScanner( ParserFactory.createScanner(
new BufferedReader( new StringReader( code ) ), reader,
(translationUnit.getUnderlyingResource() != null ?
translationUnit.getUnderlyingResource().getLocation().toOSString() :
""), //$NON-NLS-1$
scanInfo, scanInfo,
mode, mode,
language, language,

View file

@ -10,29 +10,92 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import java.io.Reader; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CodeReader { public class CodeReader {
public CodeReader( String filename, Reader reader ) private static final String NOFILE = "<text>";
{
this.reader = reader; public final char[] buffer;
public final String filename;
// If you already have preloaded the buffer, e.g. working copy
public CodeReader(String filename, char[] buffer) {
this.filename = filename; this.filename = filename;
this.buffer = buffer;
} }
private final Reader reader; // If you are just scanning a string
private final String filename; public CodeReader(char[] buffer) {
this(NOFILE, buffer);
}
public String getFilename() // If you are loading up a file normally
public CodeReader(String filename) throws IOException
{ {
return filename; this.filename = filename;
FileInputStream stream = new FileInputStream(filename);
buffer = load(stream);
} }
public Reader getUnderlyingReader() // If you have a handle on a stream to the file, e.g. IFile.getContents()
{ public CodeReader(String filename, InputStream stream) throws IOException {
return reader; this.filename = filename;
FileInputStream fstream =
(stream instanceof FileInputStream)
? (FileInputStream)stream
: new FileInputStream(filename);
buffer = load(fstream);
}
private char[] load(FileInputStream stream) throws IOException {
FileChannel channel = stream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocateDirect((int)channel.size());
channel.read(byteBuffer);
byteBuffer.rewind();
// TODO use the real encoding
CharBuffer charBuffer = Charset.forName("UTF-8").decode(byteBuffer);
if (charBuffer.hasArray())
return charBuffer.array();
else {
// Got to copy it out
char[] buff = new char[charBuffer.length()];
charBuffer.get(buff);
return buff;
} }
} }
private char[] xload(FileInputStream stream) throws IOException {
FileChannel channel = stream.getChannel();
MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
// TODO use the real encoding
CharBuffer charBuffer = Charset.forName("UTF-8").decode(map);
if (charBuffer.hasArray())
return charBuffer.array();
else {
// Got to copy it out
char[] buff = new char[charBuffer.length()];
charBuffer.get(buff);
return buff;
}
}
public boolean isFile() {
return filename != NOFILE;
}
}

View file

@ -10,7 +10,6 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import java.io.Reader;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
@ -114,7 +113,7 @@ public interface ISourceElementRequestor {
* @param finalPath * @param finalPath
* @return * @return
*/ */
public Reader createReader(String finalPath, Iterator workingCopies ); public CodeReader createReader(String finalPath, Iterator workingCopies );
/** /**
* The parser asks the client if it wishes to time out * The parser asks the client if it wishes to time out
* in case it is taking more than the expected time. * in case it is taking more than the expected time.

View file

@ -1,7 +1,6 @@
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import java.io.Reader;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
@ -460,7 +459,7 @@ public class NullSourceElementRequestor implements ISourceElementRequestor
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
*/ */
public Reader createReader(String finalPath, Iterator workingCopies) { public CodeReader createReader(String finalPath, Iterator workingCopies) {
return InternalParserUtil.createFileReader( finalPath ); return InternalParserUtil.createFileReader( finalPath );
} }

View file

@ -10,7 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import java.io.BufferedReader; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -97,22 +97,22 @@ public class ParserFactory {
* @return * @return
* @throws ParserFactoryError - erroneous input provided * @throws ParserFactoryError - erroneous input provided
*/ */
public static IScanner createScanner( Reader input, String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError public static IScanner createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError
{ {
if( input == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_READER );
Reader ourReader = input;
if( !(input instanceof BufferedReader ))
ourReader = new BufferedReader( input );
if( fileName == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_FILENAME );
if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG ); if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG );
if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE ); if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE );
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log; IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode ); ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor ); ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
IScanner s = new Scanner( ourReader, fileName, config, ourRequestor, ourMode, language, logService, extensionFactory.createScannerExtension(), workingCopies ); IScanner s = new Scanner( code, config, ourRequestor, ourMode, language, logService, extensionFactory.createScannerExtension(), workingCopies );
return s; return s;
} }
public static IScanner createScanner( String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError, IOException
{
return createScanner(new CodeReader(fileName), config, mode, language, requestor, log, workingCopies);
}
public static ILineOffsetReconciler createLineOffsetReconciler( Reader input ) public static ILineOffsetReconciler createLineOffsetReconciler( Reader input )
{ {
return new LineOffsetReconciler( input ); return new LineOffsetReconciler( input );

View file

@ -10,12 +10,10 @@
*******************************************************************************/ *******************************************************************************/
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.IOException;
import java.io.FileReader;
import java.io.Reader;
import org.eclipse.cdt.core.parser.CodeReader;
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;
@ -43,16 +41,13 @@ public class InternalParserUtil extends ParserFactory {
* @param finalPath * @param finalPath
* @return * @return
*/ */
public static Reader createFileReader(String finalPath) { public static CodeReader createFileReader(String finalPath) {
File includeFile = new File(finalPath); File includeFile = new File(finalPath);
if (includeFile.exists() && includeFile.isFile()) if (includeFile.exists() && includeFile.isFile())
{ {
//check and see
try { try {
return new CodeReader(finalPath);
return new BufferedReader( new FileReader( includeFile) ); } catch (IOException e) {
} catch (FileNotFoundException fnf) {
} }
} }
return null; return null;

View file

@ -214,6 +214,7 @@ public abstract class Parser extends ExpressionParser implements IParser
if( e instanceof Exception ) if( e instanceof Exception )
logException( "translationUnit", (Exception) e ); //$NON-NLS-1$ logException( "translationUnit", (Exception) e ); //$NON-NLS-1$
failParse(); failParse();
break;
} }
} }
compilationUnit.exitScope( requestor, astFactory.getReferenceManager() ); compilationUnit.exitScope( requestor, astFactory.getReferenceManager() );

View file

@ -11,8 +11,7 @@
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.Reader; import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
@ -112,9 +111,9 @@ public class ContextStack {
scanner.setScannerContext(sentinel); scanner.setScannerContext(sentinel);
} }
public void updateInclusionContext(Reader reader, String filename, IASTInclusion inclusion, ISourceElementRequestor requestor) throws ContextException { public void updateInclusionContext(CodeReader code, IASTInclusion inclusion, ISourceElementRequestor requestor) throws ContextException {
addInclusionFilename( filename ); addInclusionFilename( code.filename );
ScannerContextInclusion context = new ScannerContextInclusion( reader, filename, inclusion, currentInclusionIndex - 1 ); ScannerContextInclusion context = new ScannerContextInclusion( code, inclusion, currentInclusionIndex - 1 );
if( isCircularInclusion( context.getContextName() ) ) if( isCircularInclusion( context.getContextName() ) )
throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION ); throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION );

View file

@ -189,7 +189,13 @@ public class GCCScannerExtension implements IScannerExtension {
// search through include paths // search through include paths
while (iter.hasNext()) { while (iter.hasNext()) {
String path = (String)iter.next(); String path = (String)iter.next();
duple = ScannerUtility.createReaderDuple( path, parsedDirective.getFilename(), iscanner.getClientRequestor(), iscanner.getWorkingCopies() ); String finalPath = ScannerUtility.createReconciledPath(path, parsedDirective.getFilename());
duple = (CodeReader)iscanner.getFileCache().get(finalPath);
if (duple == null) {
duple = ScannerUtility.createReaderDuple( finalPath, iscanner.getClientRequestor(), iscanner.getWorkingCopies() );
if (duple != null && duple.isFile())
iscanner.getFileCache().put(duple.filename, duple);
}
if( duple != null ) if( duple != null )
break; break;
} }
@ -198,7 +204,7 @@ public class GCCScannerExtension implements IScannerExtension {
{ {
try try
{ {
iscanner.getContextStack().updateInclusionContext(duple.getUnderlyingReader(), duple.getFilename(), inclusion, iscanner.getClientRequestor() ); iscanner.getContextStack().updateInclusionContext(duple, inclusion, iscanner.getClientRequestor() );
TraceUtil.outputTrace( iscanner.getLogService(), "GCCScannerExtension handling #include_next directive successfully pushed on new include file" ); //$NON-NLS-1$ TraceUtil.outputTrace( iscanner.getLogService(), "GCCScannerExtension handling #include_next directive successfully pushed on new include file" ); //$NON-NLS-1$
} }
catch (ContextException e1) catch (ContextException e1)

View file

@ -10,11 +10,11 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.Reader;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.CodeReader;
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.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
@ -30,6 +30,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionPars
* @author jcamelon * @author jcamelon
*/ */
public interface IScannerData { public interface IScannerData {
public Map getFileCache();
/** /**
* @return Returns the contextStack. * @return Returns the contextStack.
*/ */
@ -59,10 +60,6 @@ public interface IScannerData {
* @return Returns the problemFactory. * @return Returns the problemFactory.
*/ */
public abstract IProblemFactory getProblemFactory(); public abstract IProblemFactory getProblemFactory();
/**
* @return Returns the filename.
*/
public abstract String getInitialFilename();
/** /**
* @return Returns the language. * @return Returns the language.
*/ */
@ -74,7 +71,7 @@ public interface IScannerData {
/** /**
* @return Returns the reader. * @return Returns the reader.
*/ */
public abstract Reader getInitialReader(); public abstract CodeReader getInitialReader();
/** /**
* @return Returns the requestor. * @return Returns the requestor.
*/ */

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.Reader; import org.eclipse.cdt.core.parser.CodeReader;
/** /**
* @author jcamelon * @author jcamelon
@ -30,8 +30,8 @@ public class LimitedScannerContext
* @param object * @param object
* @param offsetLimit * @param offsetLimit
*/ */
public LimitedScannerContext(Scanner scanner, Reader reader, String string, int offsetLimit, int index ) { public LimitedScannerContext(Scanner scanner, CodeReader code, int offsetLimit, int index ) {
super( reader, string, null, index ); super( code, null, index );
this.scanner = scanner; this.scanner = scanner;
limit = offsetLimit; limit = offsetLimit;
} }

View file

@ -12,8 +12,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.Reader;
import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
@ -88,8 +86,7 @@ public final class Scanner implements IScanner, IScannerData {
private IASTFactory astFactory = null; private IASTFactory astFactory = null;
private ISourceElementRequestor requestor; private ISourceElementRequestor requestor;
private ParserMode parserMode; private ParserMode parserMode;
private final String filename; private final CodeReader reader;
private final Reader reader;
private final ParserLanguage language; private final ParserLanguage language;
protected IParserLogService log; protected IParserLogService log;
private final IProblemFactory problemFactory = new ScannerProblemFactory(); private final IProblemFactory problemFactory = new ScannerProblemFactory();
@ -109,6 +106,8 @@ public final class Scanner implements IScanner, IScannerData {
private boolean limitReached = false; private boolean limitReached = false;
private IScannerContext currentContext; private IScannerContext currentContext;
private final Map fileCache = new HashMap(100);
public void setScannerContext(IScannerContext context) { public void setScannerContext(IScannerContext context) {
currentContext = context; currentContext = context;
} }
@ -137,13 +136,12 @@ public final class Scanner implements IScanner, IScannerData {
throw new ScannerException( problem ); throw new ScannerException( problem );
} }
Scanner( Reader reader, String filename, Map definitions, List includePaths, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService log, IScannerExtension extension ) Scanner( CodeReader reader, Map definitions, List includePaths, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService log, IScannerExtension extension )
{ {
String [] incs = (String [])includePaths.toArray(STRING_ARRAY); String [] incs = (String [])includePaths.toArray(STRING_ARRAY);
this.log = log; this.log = log;
this.requestor = requestor; this.requestor = requestor;
this.parserMode = mode; this.parserMode = mode;
this.filename = filename;
this.reader = reader; this.reader = reader;
this.language = language; this.language = language;
this.originalConfig = new ScannerInfo( definitions, incs ); this.originalConfig = new ScannerInfo( definitions, incs );
@ -152,15 +150,18 @@ public final class Scanner implements IScanner, IScannerData {
this.scannerExtension = extension; this.scannerExtension = extension;
this.definitions = definitions; this.definitions = definitions;
this.includePathNames = includePaths; this.includePathNames = includePaths;
if (reader.isFile())
fileCache.put(reader.filename, reader);
setupBuiltInMacros(); setupBuiltInMacros();
} }
public Scanner(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtension extension, List workingCopies ) { public Scanner(CodeReader reader, IScannerInfo info, ISourceElementRequestor requestor, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtension extension, List workingCopies ) {
this.log = log; this.log = log;
this.requestor = requestor; this.requestor = requestor;
this.parserMode = parserMode; this.parserMode = parserMode;
this.filename = filename;
this.reader = reader; this.reader = reader;
this.language = language; this.language = language;
this.originalConfig = info; this.originalConfig = info;
@ -169,6 +170,9 @@ public final class Scanner implements IScanner, IScannerData {
this.scannerExtension = extension; this.scannerExtension = extension;
this.astFactory = ParserFactory.createASTFactory( this, parserMode, language ); this.astFactory = ParserFactory.createASTFactory( this, parserMode, language );
if (reader.isFile())
fileCache.put(reader.filename, reader);
TraceUtil.outputTrace(log, "Scanner constructed with the following configuration:"); //$NON-NLS-1$ TraceUtil.outputTrace(log, "Scanner constructed with the following configuration:"); //$NON-NLS-1$
TraceUtil.outputTrace(log, "\tPreprocessor definitions from IScannerInfo: "); //$NON-NLS-1$ TraceUtil.outputTrace(log, "\tPreprocessor definitions from IScannerInfo: "); //$NON-NLS-1$
@ -351,14 +355,13 @@ public final class Scanner implements IScanner, IScannerData {
private void setupInitialContext() private void setupInitialContext()
{ {
String resolvedFilename = filename == null ? TEXT : filename;
IScannerContext context = null; IScannerContext context = null;
try try
{ {
if( offsetLimit == NO_OFFSET_LIMIT ) if( offsetLimit == NO_OFFSET_LIMIT )
context = new ScannerContextTop(reader, resolvedFilename); context = new ScannerContextTop(reader);
else else
context = new LimitedScannerContext( this, reader, resolvedFilename, offsetLimit, 0 ); context = new LimitedScannerContext( this, reader, offsetLimit, 0 );
contextStack.pushInitialContext( context ); contextStack.pushInitialContext( context );
} catch( ContextException ce ) } catch( ContextException ce )
{ {
@ -586,7 +589,13 @@ public final class Scanner implements IScanner, IScannerData {
while (iter.hasNext()) { while (iter.hasNext()) {
String path = (String)iter.next(); String path = (String)iter.next();
duple = ScannerUtility.createReaderDuple( path, fileName, requestor, getWorkingCopies() ); String finalPath = ScannerUtility.createReconciledPath(path, fileName);
duple = (CodeReader)fileCache.get(finalPath);
if (duple == null) {
duple = ScannerUtility.createReaderDuple( finalPath, requestor, getWorkingCopies() );
if (duple != null && duple.isFile())
fileCache.put(duple.filename, duple);
}
if( duple != null ) if( duple != null )
break totalLoop; break totalLoop;
} }
@ -597,7 +606,13 @@ public final class Scanner implements IScanner, IScannerData {
} }
else // local inclusion else // local inclusion
{ {
duple = ScannerUtility.createReaderDuple( new File( currentContext.getContextName() ).getParentFile().getAbsolutePath(), fileName, requestor, getWorkingCopies() ); String finalPath = ScannerUtility.createReconciledPath(new File( currentContext.getContextName() ).getParentFile().getAbsolutePath(), fileName);
duple = (CodeReader)fileCache.get(finalPath);
if (duple == null) {
duple = ScannerUtility.createReaderDuple( finalPath, requestor, getWorkingCopies() );
if (duple != null && duple.isFile())
fileCache.put(duple.filename, duple);
}
if( duple != null ) if( duple != null )
break totalLoop; break totalLoop;
useIncludePaths = true; useIncludePaths = true;
@ -612,7 +627,7 @@ public final class Scanner implements IScanner, IScannerData {
inclusion = inclusion =
getASTFactory().createInclusion( getASTFactory().createInclusion(
fileName, fileName,
duple.getFilename(), duple.filename,
!useIncludePaths, !useIncludePaths,
beginOffset, beginOffset,
startLine, startLine,
@ -627,8 +642,7 @@ public final class Scanner implements IScanner, IScannerData {
try try
{ {
contextStack.updateInclusionContext( contextStack.updateInclusionContext(
duple.getUnderlyingReader(), duple,
duple.getFilename(),
inclusion, inclusion,
requestor); requestor);
} }
@ -1557,6 +1571,7 @@ public final class Scanner implements IScanner, IScannerData {
strbuff.append( next ); strbuff.append( next );
if( !processUniversalCharacterName() ) if( !processUniversalCharacterName() )
return null; return null;
c = getChar(false);
continue; // back to top of loop continue; // back to top of loop
} }
ungetChar( next ); ungetChar( next );
@ -2141,8 +2156,7 @@ public final class Scanner implements IScanner, IScannerData {
if( ! expression.trim().equals(EMPTY_STRING)) if( ! expression.trim().equals(EMPTY_STRING))
{ {
IScanner subScanner = new Scanner( IScanner subScanner = new Scanner(
new StringReader(expression), new CodeReader(expression.toCharArray()),
SCRATCH,
getTemporaryHashtable(), getTemporaryHashtable(),
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
NULL_REQUESTOR, NULL_REQUESTOR,
@ -2589,8 +2603,7 @@ public final class Scanner implements IScanner, IScannerData {
strbuff.append(';'); strbuff.append(';');
IScanner trial = new Scanner( IScanner trial = new Scanner(
new StringReader(strbuff.toString()), new CodeReader(strbuff.toString().toCharArray()),
EXPRESSION,
definitions, definitions,
includePathNames, includePathNames,
NULL_REQUESTOR, NULL_REQUESTOR,
@ -3591,17 +3604,10 @@ public final class Scanner implements IScanner, IScannerData {
return branches; return branches;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getInitialFilename()
*/
public String getInitialFilename() {
return filename;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getInitialReader() * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getInitialReader()
*/ */
public Reader getInitialReader() { public CodeReader getInitialReader() {
return reader; return reader;
} }
@ -3639,4 +3645,8 @@ public final class Scanner implements IScanner, IScannerData {
public void setIncludePathNames(List includePathNames) { public void setIncludePathNames(List includePathNames) {
this.includePathNames = includePathNames; this.includePathNames = includePathNames;
} }
public Map getFileCache() {
return fileCache;
}
} }

View file

@ -11,16 +11,13 @@
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.IOException; import org.eclipse.cdt.core.parser.CodeReader;
import java.io.Reader;
import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.ast.IASTInclusion;
public class ScannerContextInclusion implements IScannerContext public class ScannerContextInclusion implements IScannerContext
{ {
public static final int UNDO_BUFFER_SIZE = 4; public static final int UNDO_BUFFER_SIZE = 4;
protected Reader reader; public CodeReader code;
private String filename;
private IASTInclusion inc; private IASTInclusion inc;
private final int index; private final int index;
private int line; private int line;
@ -29,9 +26,8 @@ public class ScannerContextInclusion implements IScannerContext
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion) * @see org.eclipse.cdt.internal.core.parser.IScannerContext#initialize(Reader, String, int, IASTInclusion)
*/ */
public ScannerContextInclusion(Reader r, String f, IASTInclusion i, int index) { public ScannerContextInclusion(CodeReader code, IASTInclusion i, int index) {
reader = r; this.code = code;
filename = f;
line = 1; line = 1;
inc = i; inc = i;
this.index = index; this.index = index;
@ -41,37 +37,32 @@ public class ScannerContextInclusion implements IScannerContext
public final String getContextName() public final String getContextName()
{ {
return filename; return code.filename;
} }
public int getOffset() public int getOffset()
{ {
return offset - pos; return offset;
} }
public void close() { public void close() {
try { //TODO remove close and replace by releasing from file cache
reader.close();
}
catch (IOException ie) {
}
}
protected int pos = 0;
protected int undo[] = new int[UNDO_BUFFER_SIZE];
public final void ungetChar(int c) {
undo[pos++] = c;
} }
public int getChar() { public int getChar() {
if (pos > 0) if (offset == code.buffer.length)
return undo[--pos]; return -1;
try {
++offset; int c = code.buffer[offset++];
int c = reader.read();
if ((char)c == '\n') line++; if ((char)c == '\n') line++;
return c; return c;
} }
catch (IOException e) {
return -1; /* (non-Javadoc)
} * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerContext#ungetChar(int)
*/
public void ungetChar(int undo) {
--offset;
} }
/** /**

View file

@ -11,12 +11,12 @@
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.Reader; import org.eclipse.cdt.core.parser.CodeReader;
public class ScannerContextTop extends ScannerContextInclusion public class ScannerContextTop extends ScannerContextInclusion
{ {
ScannerContextTop(Reader r, String f) { ScannerContextTop(CodeReader code) {
super(r,f,null, 0); super(code, null, 0);
} }
public int getKind() { public int getKind() {

View file

@ -10,7 +10,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.Reader;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
@ -67,13 +66,9 @@ public class ScannerUtility {
} }
static CodeReader createReaderDuple( String path, String fileName, ISourceElementRequestor requestor, Iterator workingCopies ) static CodeReader createReaderDuple( String path, ISourceElementRequestor requestor, Iterator workingCopies )
{ {
String finalPath = createReconciledPath(path, fileName); return requestor.createReader( path, workingCopies );
Reader r = requestor.createReader( finalPath, workingCopies );
if( r != null )
return new CodeReader( finalPath, r );
return null;
} }
/** /**

View file

@ -14,10 +14,10 @@
package org.eclipse.cdt.internal.core.search.matching; package org.eclipse.cdt.internal.core.search.matching;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
@ -179,8 +179,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
try { try {
scanner = scanner =
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(patternString), new CodeReader(patternString.toCharArray()),
"TEXT", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
@ -250,8 +249,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
try { try {
scanner = scanner =
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(patternString), new CodeReader(patternString.toCharArray()),
"TEXT", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
@ -292,8 +290,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
try { try {
scanner = scanner =
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(nameString), new CodeReader(nameString.toCharArray()),
"TEXT", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
@ -351,8 +348,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
try { try {
scanner = scanner =
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(patternString), new CodeReader(patternString.toCharArray()),
"TEXT", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
@ -403,8 +399,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
try { try {
scanner = scanner =
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(patternString), new CodeReader(patternString.toCharArray()),
"TEXT", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
@ -429,8 +424,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
try { try {
scanner = scanner =
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(patternString), new CodeReader(patternString.toCharArray()),
"TEXT", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
@ -464,8 +458,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
try { try {
scanner = scanner =
ParserFactory.createScanner( ParserFactory.createScanner(
new StringReader(functionString), new CodeReader(functionString.toCharArray()),
"TEXT", //$NON-NLS-1$
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,

View file

@ -13,11 +13,7 @@
*/ */
package org.eclipse.cdt.internal.core.search.matching; package org.eclipse.cdt.internal.core.search.matching;
import java.io.CharArrayReader; import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -27,6 +23,7 @@ import java.util.LinkedList;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
@ -389,7 +386,7 @@ public class MatchLocator implements IMatchLocator{
if (!searchScope.encloses(pathString)) continue; if (!searchScope.encloses(pathString)) continue;
Reader reader = null; CodeReader reader = null;
realPath = null; realPath = null;
IProject project = null; IProject project = null;
@ -400,7 +397,7 @@ public class MatchLocator implements IMatchLocator{
if( workingCopy != null ){ if( workingCopy != null ){
currentResource = workingCopy.getResource(); currentResource = workingCopy.getResource();
if ( currentResource != null && currentResource.isAccessible() ) { if ( currentResource != null && currentResource.isAccessible() ) {
reader = new CharArrayReader( workingCopy.getContents() ); reader = new CodeReader(currentResource.getLocation().toOSString(), workingCopy.getContents());
realPath = currentResource.getLocation(); realPath = currentResource.getLocation();
project = currentResource.getProject(); project = currentResource.getProject();
} else { } else {
@ -413,7 +410,7 @@ public class MatchLocator implements IMatchLocator{
if( currentResource != null ){ if( currentResource != null ){
if (currentResource.isAccessible() && currentResource instanceof IFile) { if (currentResource.isAccessible() && currentResource instanceof IFile) {
IFile file = (IFile) currentResource; IFile file = (IFile) currentResource;
reader = new InputStreamReader( file.getContents() ); reader = new CodeReader(currentResource.getLocation().toOSString(), file.getContents());
realPath = currentResource.getLocation(); realPath = currentResource.getLocation();
project = file.getProject(); project = file.getProject();
} else { } else {
@ -422,16 +419,18 @@ public class MatchLocator implements IMatchLocator{
} }
} catch ( CoreException e ){ } catch ( CoreException e ){
continue; continue;
} catch ( IOException e ) {
continue;
} }
} }
} }
if( currentResource == null ) { if( currentResource == null ) {
IPath path = new Path( pathString );
try { try {
IPath path = new Path( pathString );
currentPath = path; currentPath = path;
reader = new FileReader( path.toFile() ); reader = new CodeReader(pathString);
realPath = currentPath; realPath = currentPath;
} catch (FileNotFoundException e) { } catch (IOException e) {
continue; continue;
} }
} }
@ -456,7 +455,7 @@ public class MatchLocator implements IMatchLocator{
IParser parser = null; IParser parser = null;
try try
{ {
IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, this, ParserUtil.getScannerLogService(), null ); IScanner scanner = ParserFactory.createScanner( reader, scanInfo, ParserMode.COMPLETE_PARSE, language, this, ParserUtil.getScannerLogService(), null );
parser = ParserFactory.createParser( scanner, this, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() ); parser = ParserFactory.createParser( scanner, this, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() );
} }
catch( ParserFactoryError pfe ) catch( ParserFactoryError pfe )
@ -628,9 +627,10 @@ public class MatchLocator implements IMatchLocator{
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
*/ */
public Reader createReader(String finalPath, Iterator workingCopies) { public CodeReader createReader(String finalPath, Iterator workingCopies) {
return ParserUtil.createReader(finalPath,workingCopies); return ParserUtil.createReader(finalPath,workingCopies);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#parserTimeout() * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#parserTimeout()
*/ */

View file

@ -10,9 +10,9 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.core; package org.eclipse.cdt.core;
import java.io.StringReader;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
@ -222,8 +222,7 @@ public class CConventions {
// assuming that you are given a valid identifier // assuming that you are given a valid identifier
IToken token = null; IToken token = null;
IScanner scanner = ParserFactory.createScanner( IScanner scanner = ParserFactory.createScanner(
new StringReader( name ), new CodeReader(name.toCharArray()),
"",
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,

View file

@ -10,11 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import java.io.BufferedInputStream; import java.io.IOException;
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
@ -51,7 +47,7 @@ public class ParserUtil
return scannerLogService; return scannerLogService;
} }
public static Reader createReader( String finalPath, Iterator workingCopies ) public static CodeReader createReader( String finalPath, Iterator workingCopies )
{ {
// check to see if the file which this path points to points to an // check to see if the file which this path points to points to an
// IResource in the workspace // IResource in the workspace
@ -65,25 +61,20 @@ public class ParserUtil
// check the working copy // check the working copy
if( workingCopies.hasNext() ) if( workingCopies.hasNext() )
{ {
Reader r = findWorkingCopy( resultingResource, workingCopies ); char[] buffer = findWorkingCopy( resultingResource, workingCopies );
if( r != null ) return r; if( buffer != null )
return new CodeReader(finalPath, buffer);
} }
return createResourceReader(resultingResource); return new CodeReader(finalPath, ((IFile)resultingResource).getContents());
} }
} }
catch( CoreException ce ) catch( CoreException ce )
{ {
} }
return InternalParserUtil.createFileReader(finalPath); catch( IOException e )
{
} }
return InternalParserUtil.createFileReader(finalPath);
/**
* @param resource
* @return
* @throws CoreException
*/
public static BufferedReader createResourceReader(IResource resource) throws CoreException {
return new BufferedReader( new InputStreamReader( new BufferedInputStream( ((IFile) resource).getContents() ) ) );
} }
/** /**
@ -106,7 +97,7 @@ public class ParserUtil
* @param workingCopies * @param workingCopies
* @return * @return
*/ */
protected static Reader findWorkingCopy(IResource resultingResource, Iterator workingCopies) { protected static char[] findWorkingCopy(IResource resultingResource, Iterator workingCopies) {
if( parserLogService.isTracing() ) if( parserLogService.isTracing() )
parserLogService.traceLog( "Attempting to find the working copy for " + resultingResource.getName() ); //$NON-NLS-1$ parserLogService.traceLog( "Attempting to find the working copy for " + resultingResource.getName() ); //$NON-NLS-1$
while( workingCopies.hasNext() ) while( workingCopies.hasNext() )
@ -116,10 +107,9 @@ public class ParserUtil
IWorkingCopy copy = (IWorkingCopy) next; IWorkingCopy copy = (IWorkingCopy) next;
if( copy.getResource().equals(resultingResource )) if( copy.getResource().equals(resultingResource ))
{ {
CharArrayReader arrayReader = new CharArrayReader( copy.getContents() );
if( parserLogService.isTracing() ) if( parserLogService.isTracing() )
parserLogService.traceLog( "Working copy found!!" ); //$NON-NLS-1$ parserLogService.traceLog( "Working copy found!!" ); //$NON-NLS-1$
return new BufferedReader( arrayReader ); return copy.getContents();
} }
} }
if( parserLogService.isTracing() ) if( parserLogService.isTracing() )

View file

@ -9,17 +9,17 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.StringReader;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
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.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.compare.IEditableContent; import org.eclipse.compare.IEditableContent;
@ -74,7 +74,7 @@ public class CStructureCreator implements IStructureCreator {
//are bugs while parsing C files, we might want to create a separate Structure //are bugs while parsing C files, we might want to create a separate Structure
//compare for c files, but we'll never be completely right about .h files //compare for c files, but we'll never be completely right about .h files
IScanner scanner = IScanner scanner =
ParserFactory.createScanner(new StringReader(s), "code", new ScannerInfo(), ParserMode.QUICK_PARSE, ParserLanguage.CPP, builder, new NullLogService(), null); //$NON-NLS-1$ ParserFactory.createScanner(new CodeReader(s.toCharArray()), new ScannerInfo(), ParserMode.QUICK_PARSE, ParserLanguage.CPP, builder, new NullLogService(), null); //$NON-NLS-1$
IParser parser = ParserFactory.createParser(scanner, builder, ParserMode.QUICK_PARSE, ParserLanguage.CPP, ParserUtil.getParserLogService() ); IParser parser = ParserFactory.createParser(scanner, builder, ParserMode.QUICK_PARSE, ParserLanguage.CPP, ParserUtil.getParserLogService() );
parser.parse(); parser.parse();
} catch (Exception e) { } catch (Exception e) {

View file

@ -11,9 +11,9 @@
package org.eclipse.cdt.internal.ui.compare; package org.eclipse.cdt.internal.ui.compare;
import java.io.Reader;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.parser.CodeReader;
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;
@ -340,7 +340,7 @@ public class SourceElementRequestorAdapter implements ISourceElementRequestor {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
*/ */
public Reader createReader(String finalPath, Iterator workingCopies) { public CodeReader createReader(String finalPath, Iterator workingCopies) {
return ParserUtil.createReader(finalPath, workingCopies ); return ParserUtil.createReader(finalPath, workingCopies );
} }

View file

@ -11,14 +11,12 @@
package org.eclipse.cdt.internal.ui.search.actions; package org.eclipse.cdt.internal.ui.search.actions;
import java.io.CharArrayReader; import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IScannerInfoProvider;
@ -98,20 +96,20 @@ public class SelectionParseAction extends Action {
} }
IParser parser = null; IParser parser = null;
Reader reader = null; CodeReader reader = null;
try { try {
if( workingCopy == null ) if( workingCopy == null )
reader = new FileReader(resourceFile.getLocation().toFile()); reader = new CodeReader(resourceFile.getLocation().toOSString());
else else
reader = new CharArrayReader( workingCopy.getContents() ); reader = new CodeReader(resourceFile.getLocation().toOSString(), workingCopy.getContents());
} catch (FileNotFoundException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
try try
{ {
parser = ParserFactory.createParser( parser = ParserFactory.createParser(
ParserFactory.createScanner( reader, resourceFile.getLocation().toOSString(), scanInfo, ParserMode.SELECTION_PARSE, language, new NullSourceElementRequestor(), ParserUtil.getScannerLogService(), null ), ParserFactory.createScanner( reader, scanInfo, ParserMode.SELECTION_PARSE, language, new NullSourceElementRequestor(), ParserUtil.getScannerLogService(), null ),
new NullSourceElementRequestor(), ParserMode.SELECTION_PARSE, language, ParserUtil.getParserLogService() ); new NullSourceElementRequestor(), ParserMode.SELECTION_PARSE, language, ParserUtil.getParserLogService() );
} catch( ParserFactoryError pfe ){} } catch( ParserFactoryError pfe ){}

View file

@ -10,9 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
@ -25,6 +22,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IMacroDescriptor;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
@ -152,7 +150,7 @@ public class CompletionEngine implements RelevanceConstants {
IResource currentResource = sourceUnit.getResource(); IResource currentResource = sourceUnit.getResource();
IPath realPath = currentResource.getLocation(); IPath realPath = currentResource.getLocation();
IProject project = currentResource.getProject(); IProject project = currentResource.getProject();
Reader reader = new BufferedReader( new CharArrayReader( sourceUnit.getContents() )); CodeReader reader = new CodeReader(realPath.toOSString(), sourceUnit.getContents());
//Get the scanner info //Get the scanner info
IScannerInfo scanInfo = new ScannerInfo(); IScannerInfo scanInfo = new ScannerInfo();
@ -170,7 +168,7 @@ public class CompletionEngine implements RelevanceConstants {
IScanner scanner = null; IScanner scanner = null;
try try
{ {
scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETION_PARSE, language, elementRequestor, ParserUtil.getScannerLogService(), Arrays.asList(CUIPlugin.getSharedWorkingCopies()) ); scanner = ParserFactory.createScanner( reader, scanInfo, ParserMode.COMPLETION_PARSE, language, elementRequestor, ParserUtil.getScannerLogService(), Arrays.asList(CUIPlugin.getSharedWorkingCopies()) );
parser = ParserFactory.createParser( scanner, elementRequestor, ParserMode.COMPLETION_PARSE, language, ParserUtil.getParserLogService() ); parser = ParserFactory.createParser( scanner, elementRequestor, ParserMode.COMPLETION_PARSE, language, ParserUtil.getParserLogService() );
} }
catch( ParserFactoryError pfe ) catch( ParserFactoryError pfe )

View file

@ -10,9 +10,9 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
import java.io.Reader;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.utils.TimeOut; import org.eclipse.cdt.utils.TimeOut;
@ -32,7 +32,7 @@ public class ContentAssistElementRequestor extends NullSourceElementRequestor im
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String)
*/ */
public Reader createReader(String finalPath, Iterator workingCopies) { public CodeReader createReader(String finalPath, Iterator workingCopies) {
return ParserUtil.createReader(finalPath, workingCopies ); return ParserUtil.createReader(finalPath, workingCopies );
} }