1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

Added traceLogs into Scanner. Fixed Bug 46402 : expression evaluation error on branch not taken. Added beginning of IScannerExtension and GCCScannerExtension support for gcc specific aspects. Added separate Scanner log category for tracing and updated clients to use it.

This commit is contained in:
John Camelon 2004-01-27 01:23:29 +00:00
parent d4ca6eb809
commit b5d5e34e25
37 changed files with 387 additions and 159 deletions

View file

@ -1,3 +1,7 @@
2004-01-26 John Camelon
Updated clients to use new Scanner logging service.
Added ScannerTestCase.testBug46402().
2004-01-22 John Camelon 2004-01-22 John Camelon
Updated Scanner tests for package updates in the core. Updated Scanner tests for package updates in the core.

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener; import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IScannerInfoProvider;
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.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
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;
@ -982,7 +983,7 @@ public class ManagedBuildTests extends TestCase {
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 StringReader( "#include <header.h>\n int A::i = 1;" ),
"TEST", info, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, callback, null); "TEST", info, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, callback, new NullLogService());
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

@ -17,6 +17,7 @@ import junit.framework.TestCase;
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.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserFactoryError; import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -50,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, null), quickParseCallback, mode, lang, null ); parser = ParserFactory.createParser( ParserFactory.createScanner( new StringReader( code ), "code", new ScannerInfo(), mode, lang, quickParseCallback, new NullLogService()), quickParseCallback, mode, lang, null );
if( ! parser.parse() && throwExceptionOnError ) if( ! parser.parse() && throwExceptionOnError )
throw new ParserException("Parse failure"); throw new ParserException("Parse failure");
return quickParseCallback.getCompilationUnit(); return quickParseCallback.getCompilationUnit();

View file

@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2003,2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.util.EmptyStackException; import java.util.EmptyStackException;
@ -8,11 +18,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.BranchTracker;
/** /**
* @author jcamelon * @author jcamelon
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/ */
public class BranchTrackerTest extends TestCase { public class BranchTrackerTest extends TestCase {
@ -42,13 +47,13 @@ public class BranchTrackerTest extends TestCase {
* #endif * #endif
*/ */
assertFalse( bt.poundif( false ) ); assertFalse( bt.poundIf( false ) );
assertFalse( bt.poundif( true ) ); assertFalse( bt.poundIf( true ) );
assertFalse( bt.poundelif( true ) ); assertFalse( bt.poundElif( true ) );
assertFalse( bt.poundelse() ); assertFalse( bt.poundElse() );
assertFalse( bt.poundendif() ); assertFalse( bt.poundEndif() );
assertTrue( bt.poundelse() ); assertTrue( bt.poundElse() );
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
/* /*
* #if 0 * #if 0
@ -67,19 +72,19 @@ public class BranchTrackerTest extends TestCase {
*/ */
bt = new BranchTracker(); bt = new BranchTracker();
assertFalse( bt.poundif( false ) ); assertFalse( bt.poundIf( false ) );
assertFalse( bt.poundif( true )); assertFalse( bt.poundIf( true ));
assertFalse( bt.poundelif( true ) ); assertFalse( bt.poundElif( true ) );
assertFalse( bt.poundelse() ); assertFalse( bt.poundElse() );
assertFalse( bt.poundendif() ); assertFalse( bt.poundEndif() );
assertTrue( bt.poundelse() ); assertTrue( bt.poundElse() );
assertFalse( bt.poundif( false ) ); assertFalse( bt.poundIf( false ) );
assertTrue( bt.poundelif( true ) ); assertTrue( bt.poundElif( true ) );
assertFalse( bt.poundelif( false ) ); assertFalse( bt.poundElif( false ) );
assertFalse( bt.poundelif( true ) ); assertFalse( bt.poundElif( true ) );
assertFalse( bt.poundelse() ); assertFalse( bt.poundElse() );
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
assertEquals( 0, bt.getDepth() ); assertEquals( 0, bt.getDepth() );
/* /*
@ -110,31 +115,31 @@ public class BranchTrackerTest extends TestCase {
* #endif * #endif
*/ */
assertFalse(bt.poundif(false)); assertFalse(bt.poundIf(false));
assertFalse(bt.poundif(true)); assertFalse(bt.poundIf(true));
assertFalse(bt.poundelif(false)); assertFalse(bt.poundElif(false));
assertFalse(bt.poundelif(true)); assertFalse(bt.poundElif(true));
assertFalse(bt.poundelse()); assertFalse(bt.poundElse());
assertFalse( bt.poundendif() ); assertFalse( bt.poundEndif() );
assertFalse(bt.poundelif(false)); assertFalse(bt.poundElif(false));
assertFalse(bt.poundif(false)); assertFalse(bt.poundIf(false));
assertFalse(bt.poundelif(false)); assertFalse(bt.poundElif(false));
assertFalse(bt.poundelif(true)); assertFalse(bt.poundElif(true));
assertFalse(bt.poundelse()); assertFalse(bt.poundElse());
assertFalse( bt.poundendif()); assertFalse( bt.poundEndif());
assertTrue(bt.poundelif(true)); assertTrue(bt.poundElif(true));
assertFalse(bt.poundif(false)); assertFalse(bt.poundIf(false));
assertFalse(bt.poundelif(false)); assertFalse(bt.poundElif(false));
assertFalse(bt.poundelif(false)); assertFalse(bt.poundElif(false));
assertTrue(bt.poundelse()); assertTrue(bt.poundElse());
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
assertFalse(bt.poundelse()); assertFalse(bt.poundElse());
assertFalse(bt.poundif(true)); assertFalse(bt.poundIf(true));
assertFalse(bt.poundelif(false)); assertFalse(bt.poundElif(false));
assertFalse(bt.poundelif(true)); assertFalse(bt.poundElif(true));
assertFalse(bt.poundelse()); assertFalse(bt.poundElse());
assertFalse( bt.poundendif() ); assertFalse( bt.poundEndif() );
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
assertEquals(0, bt.getDepth()); assertEquals(0, bt.getDepth());
} catch (EmptyStackException se) { } catch (EmptyStackException se) {
fail("Unexpected Scanner exception thrown"); fail("Unexpected Scanner exception thrown");
@ -152,9 +157,9 @@ public class BranchTrackerTest extends TestCase {
* #endif * #endif
*/ */
BranchTracker bt = new BranchTracker(); BranchTracker bt = new BranchTracker();
assertTrue( bt.poundif( true ) ); assertTrue( bt.poundIf( true ) );
assertFalse( bt.poundelse() ); assertFalse( bt.poundElse() );
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
/* /*
* code sequence is * code sequence is
@ -167,13 +172,13 @@ public class BranchTrackerTest extends TestCase {
* #endif * #endif
*/ */
bt = new BranchTracker(); bt = new BranchTracker();
assertTrue( bt.poundif( true )); assertTrue( bt.poundIf( true ));
assertFalse( bt.poundif( false )); assertFalse( bt.poundIf( false ));
assertFalse( bt.poundelif( false )); assertFalse( bt.poundElif( false ));
assertTrue( bt.poundelse()); assertTrue( bt.poundElse());
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
assertFalse( bt.poundelse() ); assertFalse( bt.poundElse() );
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
/* /*
* #if 1 * #if 1
@ -184,11 +189,11 @@ public class BranchTrackerTest extends TestCase {
*/ */
bt = new BranchTracker(); bt = new BranchTracker();
assertTrue( bt.poundif( true ) ); assertTrue( bt.poundIf( true ) );
assertFalse( bt.poundelif( true )); assertFalse( bt.poundElif( true ));
assertFalse( bt.poundelif( false )); assertFalse( bt.poundElif( false ));
assertFalse( bt.poundelse()); assertFalse( bt.poundElse());
assertTrue( bt.poundendif() ); assertTrue( bt.poundEndif() );
} }
@ -197,5 +202,4 @@ public class BranchTrackerTest extends TestCase {
fail( "Exception" ); fail( "Exception" );
} }
} }
} }

View file

@ -25,6 +25,7 @@ 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;
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.ParserFactoryError; import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -697,7 +698,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(), ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(),
ParserMode.COMPLETE_PARSE, language, callback, null ), callback, ParserMode.COMPLETE_PARSE, language, null ParserMode.COMPLETE_PARSE, language, callback, new NullLogService() ), callback, ParserMode.COMPLETE_PARSE, language, null
); );
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE");
return callback.getCompilationUnit(); return callback.getCompilationUnit();

View file

@ -12,10 +12,11 @@ import java.io.Writer;
import java.util.Iterator; import java.util.Iterator;
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.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.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope; import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
@ -28,7 +29,6 @@ import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult; import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.internal.core.parser.ParserLogService;
/** /**
* @author jcamelon * @author jcamelon
@ -45,7 +45,6 @@ public class ContextualParseTest extends CompleteParseBaseTest {
protected IASTCompletionNode parse(String code, int offset) protected IASTCompletionNode parse(String code, int offset)
throws Exception { throws Exception {
IParserLogService log = new ParserLogService();
callback = new FullParseCallback(); callback = new FullParseCallback();
IParser parser = null; IParser parser = null;
@ -58,11 +57,11 @@ public class ContextualParseTest extends CompleteParseBaseTest {
ParserMode.COMPLETION_PARSE, ParserMode.COMPLETION_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
callback, callback,
log), new NullLogService()),
callback, callback,
ParserMode.COMPLETION_PARSE, ParserMode.COMPLETION_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
log); ParserUtil.getParserLogService());
return parser.parse( offset ); return parser.parse( offset );

View file

@ -7,12 +7,13 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
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.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserLanguage;
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.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
public class ExprEvalTest extends TestCase { public class ExprEvalTest extends TestCase {
@ -27,7 +28,7 @@ public class ExprEvalTest extends TestCase {
public void runTest(String code, int expectedValue) throws Exception { public void runTest(String code, int expectedValue) throws Exception {
final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor(); final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor();
IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, null ), nullCallback, ParserMode.QUICK_PARSE, ParserLanguage.CPP, null ); IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService() ), nullCallback, ParserMode.QUICK_PARSE, ParserLanguage.CPP, null );
IASTExpression expression = parser.expression(null); IASTExpression expression = parser.expression(null);
assertEquals(expectedValue, expression.evaluateExpression()); assertEquals(expectedValue, expression.evaluateExpression());
} }

View file

@ -23,6 +23,7 @@ import java.util.StringTokenizer;
import junit.framework.Test; import junit.framework.Test;
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.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;
@ -241,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, null ), nullCallback, ParserMode.QUICK_PARSE, language, null ); ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, new NullLogService() ), nullCallback, ParserMode.QUICK_PARSE, language, null );
parser.parse(); parser.parse();
} catch ( Exception e ){ } catch ( Exception e ){

View file

@ -1,3 +1,14 @@
/*******************************************************************************
* Copyright (c) 2003,2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.io.StringWriter; import java.io.StringWriter;
@ -18,11 +29,6 @@ import org.eclipse.cdt.internal.core.parser.token.Token;
/** /**
* @author jcamelon * @author jcamelon
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/ */
public class ScannerTestCase extends BaseScannerTest public class ScannerTestCase extends BaseScannerTest
{ {
@ -1528,4 +1534,17 @@ public class ScannerTestCase extends BaseScannerTest
assertEquals( callback.inclusions.size(), 1 ); assertEquals( callback.inclusions.size(), 1 );
assertEquals( callback.inclusions.get(0), "stdio.h"); assertEquals( callback.inclusions.get(0), "stdio.h");
} }
public void testBug46402() throws Exception
{
StringBuffer buffer = new StringBuffer();
buffer.append( "#define X 5\n" );
buffer.append( "#if defined( X )\n" );
buffer.append( "// blah\n" );
buffer.append( "#elif Y > 5 \n" );
buffer.append( "// coo\n" );
buffer.append( "#endif\n" );
initializeScanner( buffer.toString(), ParserMode.COMPLETE_PARSE );
validateEOF();
}
} }

View file

@ -24,6 +24,7 @@ import junit.framework.Test;
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.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;
@ -280,7 +281,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, null ), nullCallback, parserMode, language, null); ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), parserMode, language, nullCallback, new NullLogService() ), nullCallback, parserMode, language, null);
mapping = ParserFactory.createLineOffsetReconciler( new StringReader( code ) ); mapping = ParserFactory.createLineOffsetReconciler( new StringReader( code ) );

View file

@ -18,6 +18,7 @@ import junit.framework.TestCase;
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.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
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;
@ -58,7 +59,7 @@ public class ParseTestOnSearchFiles extends TestCase
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 ), name, new ScannerInfo(), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, requestor, null ); IScanner scanner = ParserFactory.createScanner( new InputStreamReader( fileIn ), name, new ScannerInfo(), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, requestor, new NullLogService() );
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

@ -6,6 +6,9 @@ org.eclipse.cdt.core/debug/model=false
# Reports parser activity # Reports parser activity
org.eclipse.cdt.core/debug/parser=false org.eclipse.cdt.core/debug/parser=false
# Reports scanner activity
org.eclipse.cdt.core/debug/scanner=false
# Reports background indexer activity: indexing, saving index file, index queries # Reports background indexer activity: indexing, saving index file, index queries
org.eclipse.cdt.core/debug/indexmanager=false org.eclipse.cdt.core/debug/indexmanager=false

View file

@ -1,3 +1,6 @@
2004-01-26 John Camelon
Updated clients to use new Scanner logging service.
2004-01-06 Alain Magloire 2004-01-06 Alain Magloire
Simple draft implementation of debug format parsing. Simple draft implementation of debug format parsing.

View file

@ -1,3 +1,6 @@
2004-01-26 John Camelon
Updated clients to use new Scanner logging service.
2003-10-22 Bogdan Gheorghe 2003-10-22 Bogdan Gheorghe
Added updateDependencies() to the IndexManager to request Added updateDependencies() to the IndexManager to request

View file

@ -91,7 +91,7 @@ public class SourceIndexer extends AbstractIndexer {
try try
{ {
parser = ParserFactory.createParser( parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( document.getStringContent() ), resourceFile.getLocation().toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getParserLogService() ), ParserFactory.createScanner( new StringReader( document.getStringContent() ), resourceFile.getLocation().toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getScannerLogService() ),
requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() ); requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() );
} catch( ParserFactoryError pfe ) } catch( ParserFactoryError pfe )
{ {

View file

@ -26,6 +26,7 @@ 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.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IScannerInfoProvider;
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.ParserFactoryError; import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -126,7 +127,7 @@ public class CModelBuilder {
mode, mode,
language, language,
quickParseCallback, quickParseCallback,
ParserUtil.getParserLogService()) quickParseMode ? new NullLogService() : ParserUtil.getScannerLogService())
,quickParseCallback, ,quickParseCallback,
mode, mode,
language, language,

View file

@ -1,26 +1,30 @@
/* /**********************************************************************
* Created on Aug 25, 2003 * Copyright (c) 2002,2003,2004 Rational Software Corporation and others.
* * All rights reserved. This program and the accompanying materials
* To change the template for this generated file go to * are made available under the terms of the Common Public License v0.5
* Window>Preferences>Java>Code Generation>Code and Comments * which accompanies this distribution, and is available at
*/ * http://www.eclipse.org/legal/cpl-v05.html
package org.eclipse.cdt.internal.core.model; *
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.parser.Enum;
/** /**
* @author bgheorgh * @author bgheorgh
* *
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/ */
public interface IDebugLogConstants { public interface IDebugLogConstants {
public class DebugLogConstant { public class DebugLogConstant extends Enum {
private DebugLogConstant( int value ) protected DebugLogConstant( int value )
{ {
this.value = value; super( value );
} }
private final int value;
} }
public static final DebugLogConstant PARSER = new DebugLogConstant( 1 ); public static final DebugLogConstant PARSER = new DebugLogConstant( 1 );
public static final DebugLogConstant MODEL = new DebugLogConstant ( 2 ); public static final DebugLogConstant MODEL = new DebugLogConstant ( 2 );
public static final DebugLogConstant SCANNER = new DebugLogConstant( 3 );
} }

View file

@ -25,6 +25,7 @@ import org.eclipse.core.runtime.Status;
public class Util implements ICLogConstants { public class Util implements ICLogConstants {
public static boolean VERBOSE_PARSER = false; public static boolean VERBOSE_PARSER = false;
public static boolean VERBOSE_SCANNER = false;
public static boolean VERBOSE_MODEL = false; public static boolean VERBOSE_MODEL = false;
private Util() { private Util() {
@ -214,6 +215,8 @@ public class Util implements ICLogConstants {
if (client.equals(IDebugLogConstants.PARSER)){ if (client.equals(IDebugLogConstants.PARSER)){
return VERBOSE_PARSER; return VERBOSE_PARSER;
} }
else if (client.equals(IDebugLogConstants.SCANNER ))
return VERBOSE_SCANNER;
else if (client.equals(IDebugLogConstants.MODEL)){ else if (client.equals(IDebugLogConstants.MODEL)){
return VERBOSE_MODEL; return VERBOSE_MODEL;
} }

View file

@ -1,3 +1,9 @@
2004-01-26 John Camelon
Added traceLogs into Scanner.
Fixed Bug 46402 : expression evaluation error on branch not taken
Added beginning of IScannerExtension and GCCScannerExtension support for gcc specific aspects.
Added separate Scanner log category for tracing and updated clients to use it.
2004-01-23 John Camelon 2004-01-23 John Camelon
Added support for content assist in the scanner.. Added support for content assist in the scanner..

View file

@ -0,0 +1,19 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.parser;
/**
* @author jcamelon
*/
public interface IScannerExtension {
public String initializeMacroValue( String original );
}

View file

@ -0,0 +1,30 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.parser;
/**
* @author jcamelon
*/
public class NullLogService implements IParserLogService {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String)
*/
public void traceLog(String message) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IParserLogService#errorLog(java.lang.String)
*/
public void errorLog(String message) {
}
}

View file

@ -26,6 +26,7 @@ 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.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
@ -191,4 +192,18 @@ public class ContextualParser extends Parser implements IParser {
{ {
return finalToken; return finalToken;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionContextForExpression(org.eclipse.cdt.core.parser.ast.IASTExpression, boolean)
*/
protected void setCompletionContextForExpression(
IASTExpression firstExpression,
boolean isTemplate) {
setCompletionContext( astFactory.getCompletionContext( (isTemplate
? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS
: IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION),
firstExpression ) );
}
} }

View file

@ -4805,11 +4805,8 @@ public abstract class Parser implements IParser
setCompletionToken( null ); setCompletionToken( null );
} }
IASTNode context = astFactory.getCompletionContext( (isTemplate
? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS setCompletionContextForExpression( firstExpression, isTemplate );
: IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION),
firstExpression );
setCompletionContext( context );
setCompletionKind( IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); setCompletionKind( IASTCompletionNode.CompletionKind.MEMBER_REFERENCE );
secondExpression = primaryExpression(scope); secondExpression = primaryExpression(scope);
@ -4855,11 +4852,7 @@ public abstract class Parser implements IParser
setCompletionToken( null ); setCompletionToken( null );
} }
context = astFactory.getCompletionContext( (isTemplate setCompletionContextForExpression( firstExpression, isTemplate );
? IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP
: IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION),
firstExpression );
setCompletionContext( context );
setCompletionKind( IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); setCompletionKind( IASTCompletionNode.CompletionKind.MEMBER_REFERENCE );
secondExpression = primaryExpression(scope); secondExpression = primaryExpression(scope);
@ -4897,6 +4890,12 @@ public abstract class Parser implements IParser
/** /**
* @param firstExpression
* @param isTemplate
*/
protected void setCompletionContextForExpression(IASTExpression firstExpression, boolean isTemplate) {
}
/**
* @return * @return
* @throws EndOfFileException * @throws EndOfFileException
*/ */

View file

@ -41,7 +41,7 @@ public class BranchTracker {
* evaluates to true or false * evaluates to true or false
* @return boolean - are we set to continue scanning or not? * @return boolean - are we set to continue scanning or not?
*/ */
public boolean poundif( boolean taken ) public boolean poundIf( boolean taken )
{ {
if( ignore == IGNORE_SENTINEL ) if( ignore == IGNORE_SENTINEL )
{ {
@ -63,7 +63,22 @@ public class BranchTracker {
} }
} }
public boolean poundelif( boolean taken ) throws EmptyStackException public boolean queryCurrentBranchForElif()
{
if( ignore != IGNORE_SENTINEL && ignore < branches.size() )
return true;
return !((Boolean)branches.peek()).booleanValue();
}
public boolean queryCurrentBranchForIf()
{
if( branches.isEmpty() ) return true;
if( ignore != IGNORE_SENTINEL & ignore < branches.size() )
return false;
return ((Boolean)branches.peek()).booleanValue();
}
public boolean poundElif( boolean taken ) throws EmptyStackException
{ {
if( ignore != IGNORE_SENTINEL && ignore < branches.size() ) if( ignore != IGNORE_SENTINEL && ignore < branches.size() )
{ {
@ -110,7 +125,7 @@ public class BranchTracker {
return false; return false;
} }
public boolean poundelse() throws EmptyStackException public boolean poundElse() throws EmptyStackException
{ {
if( ignore != IGNORE_SENTINEL && ignore < branches.size() ) if( ignore != IGNORE_SENTINEL && ignore < branches.size() )
{ {
@ -151,7 +166,7 @@ public class BranchTracker {
} }
// taken only on an #endif // taken only on an #endif
public boolean poundendif( ) public boolean poundEndif( )
{ {
if( ignore == branches.size() ) if( ignore == branches.size() )
ignore = IGNORE_SENTINEL; ignore = IGNORE_SENTINEL;

View file

@ -69,6 +69,8 @@ public class ContextStack {
{ {
if( !inclusions.add( context.getFilename() ) ) if( !inclusions.add( context.getFilename() ) )
throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION ); throw new ContextException( IProblem.PREPROCESSOR_CIRCULAR_INCLUSION );
log.traceLog( "Scanner::ContextStack: entering inclusion " +context.getFilename());
context.getExtension().enterScope( requestor ); context.getExtension().enterScope( requestor );
} else if( context.getKind() == IScannerContext.ContextKind.MACROEXPANSION ) } else if( context.getKind() == IScannerContext.ContextKind.MACROEXPANSION )
@ -93,6 +95,7 @@ public class ContextStack {
if( currentContext.getKind() == IScannerContext.ContextKind.INCLUSION ) if( currentContext.getKind() == IScannerContext.ContextKind.INCLUSION )
{ {
log.traceLog( "Scanner::ContextStack: ending inclusion " +currentContext.getFilename());
inclusions.remove( currentContext.getFilename() ); inclusions.remove( currentContext.getFilename() );
currentContext.getExtension().exitScope( requestor ); currentContext.getExtension().exitScope( requestor );
} else if( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION ) } else if( currentContext.getKind() == IScannerContext.ContextKind.MACROEXPANSION )

View file

@ -0,0 +1,29 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
import org.eclipse.cdt.core.parser.IScannerExtension;
/**
* @author jcamelon
*/
public class GCCScannerExtension implements IScannerExtension {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScannerExtension#initializeMacroValue(java.lang.String)
*/
public String initializeMacroValue(String original) {
if( original == null || original.equals( "") )
return "1";
return original;
}
}

View file

@ -34,7 +34,7 @@ public class Preprocessor extends Scanner implements IPreprocessor {
* @param defns * @param defns
*/ */
public Preprocessor(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService logService ) { public Preprocessor(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService logService ) {
super(reader, filename, info, requestor, mode, language, logService ); super(reader, filename, info, requestor, mode, language, logService );
} }
public void process() public void process()

View file

@ -33,10 +33,12 @@ import org.eclipse.cdt.core.parser.IParser;
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;
import org.eclipse.cdt.core.parser.IScannerExtension;
import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo;
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;
import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.Keywords;
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.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
@ -60,7 +62,6 @@ import org.eclipse.cdt.internal.core.parser.token.Token;
public class Scanner implements IScanner { public class Scanner implements IScanner {
protected final IParserLogService log; protected final IParserLogService log;
private final static String SCRATCH = "<scratch>"; private final static String SCRATCH = "<scratch>";
private IProblemFactory problemFactory = new ScannerProblemFactory(); private IProblemFactory problemFactory = new ScannerProblemFactory();
@ -68,6 +69,7 @@ public class Scanner implements IScanner {
private final String filename; private final String filename;
private final Reader reader; private final Reader reader;
protected IToken finalToken; protected IToken finalToken;
private final IScannerExtension scannerExtension;
protected void handleProblem( int problemID, String argument, int beginningOffset, boolean warning, boolean error ) throws ScannerException protected void handleProblem( int problemID, String argument, int beginningOffset, boolean warning, boolean error ) throws ScannerException
{ {
@ -101,6 +103,9 @@ public class Scanner implements IScanner {
this.filename = filename; this.filename = filename;
this.reader = reader; this.reader = reader;
this.language = language; this.language = language;
//support GNU by default for now
scannerExtension = new GCCScannerExtension();
astFactory = ParserFactory.createASTFactory( mode, language ); astFactory = ParserFactory.createASTFactory( mode, language );
contextStack = new ContextStack( log ); contextStack = new ContextStack( log );
try { try {
@ -116,26 +121,48 @@ public class Scanner implements IScanner {
} }
originalConfig = info; originalConfig = info;
log.traceLog( "Scanner constructed with the following configuration:");
log.traceLog( "\tPreprocessor definitions from IScannerInfo: ");
if( info.getDefinedSymbols() != null ) if( info.getDefinedSymbols() != null )
{ {
Iterator i = info.getDefinedSymbols().keySet().iterator(); Iterator i = info.getDefinedSymbols().keySet().iterator();
Map m = info.getDefinedSymbols(); Map m = info.getDefinedSymbols();
int numberOfSymbolsLogged = 0;
while( i.hasNext() ) while( i.hasNext() )
{ {
String symbolName = (String) i.next(); String symbolName = (String) i.next();
Object value = m.get( symbolName ); Object value = m.get( symbolName );
if( value instanceof String ) if( value instanceof String )
addDefinition( symbolName, (String) value); {
addDefinition( symbolName, scannerExtension.initializeMacroValue((String) value));
log.traceLog( "\t\tNAME = " + symbolName + " VALUE = " + value.toString() );
++numberOfSymbolsLogged;
}
else if( value instanceof IMacroDescriptor ) else if( value instanceof IMacroDescriptor )
addDefinition( symbolName, (IMacroDescriptor)value); addDefinition( symbolName, (IMacroDescriptor)value);
} }
} if( numberOfSymbolsLogged == 0 )
log.traceLog( "\t\tNo definitions specified.");
if( info.getIncludePaths() != null ) }
overwriteIncludePath( info.getIncludePaths() ); else
log.traceLog( "\t\tNo definitions specified.");
log.traceLog( "\tInclude paths from IScannerInfo: ");
if( info.getIncludePaths() != null )
{
overwriteIncludePath( info.getIncludePaths() );
for( int i = 0; i < info.getIncludePaths().length; ++i )
log.traceLog( "\t\tPATH: " + info.getIncludePaths()[i]);
}
else
log.traceLog("\t\tNo include paths specified.");
} }
private void setupInitialContext() private void setupInitialContext()
@ -174,7 +201,7 @@ public class Scanner implements IScanner {
while( i.hasNext() ) while( i.hasNext() )
{ {
String path = (String) i.next(); String path = (String) i.next();
includePaths.add( new File( path )); includePaths.add( new File( path ));
} }
@ -1199,26 +1226,27 @@ public class Scanner implements IScanner {
int currentOffset = getCurrentOffset(); int currentOffset = getCurrentOffset();
String expression = getRestOfPreprocessorLine(); String expression = getRestOfPreprocessorLine();
boolean expressionEvalResult = false; if (expression.trim().equals(""))
try{ handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#if", beginningOffset, false, true );
expressionEvalResult = evaluateExpression(expression, currentOffset);
} catch( ScannerException e ){}
passOnToClient = branches.poundif( expressionEvalResult ); boolean expressionEvalResult = false;
if( branches.queryCurrentBranchForIf() )
expressionEvalResult = evaluateExpression(expression, currentOffset);
passOnToClient = branches.poundIf( expressionEvalResult );
c = getChar(); c = getChar();
continue; continue;
case PreprocessorDirectives.IFDEF : case PreprocessorDirectives.IFDEF :
//TODO add in content assist stuff here //TODO add in content assist stuff here
skipOverWhitespace(); skipOverWhitespace();
if (getDefinition(getNextIdentifier()) == null) { if (getDefinition(getNextIdentifier()) == null) {
// not defined // not defined
passOnToClient = branches.poundif( false ); passOnToClient = branches.poundIf( false );
skipOverTextUntilNewline(); skipOverTextUntilNewline();
} else { } else {
passOnToClient = branches.poundif( true ); passOnToClient = branches.poundIf( true );
// continue along, act like nothing is wrong :-) // continue along, act like nothing is wrong :-)
c = getChar(); c = getChar();
} }
@ -1231,7 +1259,7 @@ public class Scanner implements IScanner {
buffer.append( restOfLine ); buffer.append( restOfLine );
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, buffer.toString(), beginningOffset, false, true ); handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, buffer.toString(), beginningOffset, false, true );
} }
passOnToClient = branches.poundendif(); passOnToClient = branches.poundEndif();
c = getChar(); c = getChar();
continue; continue;
@ -1241,9 +1269,9 @@ public class Scanner implements IScanner {
if (getDefinition(getNextIdentifier()) != null) { if (getDefinition(getNextIdentifier()) != null) {
// not defined // not defined
skipOverTextUntilNewline(); skipOverTextUntilNewline();
passOnToClient = branches.poundif( false ); passOnToClient = branches.poundIf( false );
} else { } else {
passOnToClient = branches.poundif( true ); passOnToClient = branches.poundIf( true );
// continue along, act like nothing is wrong :-) // continue along, act like nothing is wrong :-)
c = getChar(); c = getChar();
} }
@ -1253,7 +1281,7 @@ public class Scanner implements IScanner {
//TODO add in content assist stuff here //TODO add in content assist stuff here
try try
{ {
passOnToClient = branches.poundelse(); passOnToClient = branches.poundElse();
} }
catch( EmptyStackException ese ) catch( EmptyStackException ese )
{ {
@ -1276,11 +1304,12 @@ public class Scanner implements IScanner {
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#elif", beginningOffset, false, true ); handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#elif", beginningOffset, false, true );
boolean elsifResult = false; boolean elsifResult = false;
elsifResult = evaluateExpression(elsifExpression, co ); if( branches.queryCurrentBranchForElif() )
elsifResult = evaluateExpression(elsifExpression, co );
try try
{ {
passOnToClient = branches.poundelif( elsifResult ); passOnToClient = branches.poundElif( elsifResult );
} }
catch( EmptyStackException ese ) catch( EmptyStackException ese )
{ {
@ -2026,8 +2055,8 @@ public class Scanner implements IScanner {
new StringReader(expressionBuffer.toString()), new StringReader(expressionBuffer.toString()),
EXPRESSION, EXPRESSION,
new ScannerInfo( definitions, originalConfig.getIncludePaths()), new ScannerInfo( definitions, originalConfig.getIncludePaths()),
ParserMode.QUICK_PARSE, language, nullCallback, log ); ParserMode.QUICK_PARSE, language, nullCallback, nullLogService );
parser = ParserFactory.createParser(trial, nullCallback, ParserMode.QUICK_PARSE, language, log ); parser = ParserFactory.createParser(trial, nullCallback, ParserMode.QUICK_PARSE, language, nullLogService);
} catch( ParserFactoryError pfe ) } catch( ParserFactoryError pfe )
{ {
handleInternalError(); handleInternalError();
@ -2129,7 +2158,7 @@ public class Scanner implements IScanner {
new ScannerInfo(definitions, originalConfig.getIncludePaths()), new ScannerInfo(definitions, originalConfig.getIncludePaths()),
new NullSourceElementRequestor(), new NullSourceElementRequestor(),
mode, mode,
language, log ); language, nullLogService );
helperScanner.setForInclusion( true ); helperScanner.setForInclusion( true );
IToken t = null; IToken t = null;
@ -2243,6 +2272,7 @@ public class Scanner implements IScanner {
protected boolean forInclusion = false; protected boolean forInclusion = false;
private final static IParserLogService nullLogService = new NullLogService();
/** /**
* @param b * @param b
*/ */
@ -2265,7 +2295,7 @@ public class Scanner implements IScanner {
new ScannerInfo(), new ScannerInfo(),
mode, mode,
language, language,
new NullSourceElementRequestor(), log); new NullSourceElementRequestor(), nullLogService);
} catch (ParserFactoryError e1) { } catch (ParserFactoryError e1) {
} }
helperScanner.setTokenizingMacroReplacementList( true ); helperScanner.setTokenizingMacroReplacementList( true );
@ -2533,7 +2563,7 @@ public class Scanner implements IScanner {
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException { protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
Scanner tokenizer = new Scanner(new StringReader(params), TEXT, new ScannerInfo( definitions, originalConfig.getIncludePaths() ), new NullSourceElementRequestor(), mode, language, log); Scanner tokenizer = new Scanner(new StringReader(params), TEXT, new ScannerInfo( definitions, originalConfig.getIncludePaths() ), new NullSourceElementRequestor(), mode, language, nullLogService );
tokenizer.setThrowExceptionOnBadCharacterRead(false); tokenizer.setThrowExceptionOnBadCharacterRead(false);
Vector parameterValues = new Vector(); Vector parameterValues = new Vector();
Token t = null; Token t = null;

View file

@ -1,3 +1,6 @@
2004-01-26 John Camelon
Updated clients to use new Scanner logging service.
2003-10-23 Bogdan Gheorghe 2003-10-23 Bogdan Gheorghe
- Added AcceptMatchOperation to get around Bug 45324. The search - Added AcceptMatchOperation to get around Bug 45324. The search

View file

@ -20,10 +20,12 @@ import java.util.LinkedList;
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.IProblem; import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IQuickParseCallback; import org.eclipse.cdt.core.parser.IQuickParseCallback;
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.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;
import org.eclipse.cdt.core.parser.ParserFactoryError; import org.eclipse.cdt.core.parser.ParserFactoryError;
@ -183,7 +185,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
callback, callback,
ParserUtil.getParserLogService()); nullLog);
} catch (ParserFactoryError e) { } catch (ParserFactoryError e) {
} }
@ -253,7 +255,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
callback,ParserUtil.getParserLogService()); callback, nullLog);
} catch (ParserFactoryError e) { } catch (ParserFactoryError e) {
} }
@ -295,7 +297,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
callback,ParserUtil.getParserLogService()); callback, nullLog);
} catch (ParserFactoryError e) { } catch (ParserFactoryError e) {
} }
@ -312,6 +314,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
return new MethodDeclarationPattern( name, qualifications, parameters, matchMode, searchFor, limitTo, caseSensitive ); return new MethodDeclarationPattern( name, qualifications, parameters, matchMode, searchFor, limitTo, caseSensitive );
} }
private static final IParserLogService nullLog = new NullLogService();
/** /**
* @param patternString * @param patternString
* @param limitTo * @param limitTo
@ -353,12 +356,11 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
callback,ParserUtil.getParserLogService()); callback, nullLog );
} catch (ParserFactoryError e1) { } catch (ParserFactoryError e1) {
} }
IToken token = null; IToken token = null;
ASTClassKind kind = null;
try { try {
token = scanner.nextToken(); token = scanner.nextToken();
@ -417,7 +419,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
new ScannerInfo(), new ScannerInfo(),
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
ParserLanguage.CPP, ParserLanguage.CPP,
callback,ParserUtil.getParserLogService()); callback,new NullLogService());
} catch (ParserFactoryError e1) { } catch (ParserFactoryError e1) {
} }
IQuickParseCallback callback = ParserFactory.createQuickParseCallback(); IQuickParseCallback callback = ParserFactory.createQuickParseCallback();

View file

@ -440,7 +440,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
IParser parser = null; IParser parser = null;
try try
{ {
IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, this, ParserUtil.getParserLogService() ); IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, this, ParserUtil.getScannerLogService() );
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 )

View file

@ -718,6 +718,7 @@ public class CCorePlugin extends Plugin {
private static final String SEARCH = CCorePlugin.PLUGIN_ID + "/debug/search" ; //$NON-NLS-1$ private static final String SEARCH = CCorePlugin.PLUGIN_ID + "/debug/search" ; //$NON-NLS-1$
private static final String MATCH_LOCATOR = CCorePlugin.PLUGIN_ID + "/debug/matchlocator" ; //$NON-NLS-1$ private static final String MATCH_LOCATOR = CCorePlugin.PLUGIN_ID + "/debug/matchlocator" ; //$NON-NLS-1$
private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$ private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$
private static final String SCANNER = CCorePlugin.PLUGIN_ID + "/debug/scanner"; //$NON-NLS-1$
private static final String DELTA = CCorePlugin.PLUGIN_ID + "/debug/deltaprocessor" ; private static final String DELTA = CCorePlugin.PLUGIN_ID + "/debug/deltaprocessor" ;
private static final String CONTENTASSIST = CCorePlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$ private static final String CONTENTASSIST = CCorePlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$
/** /**
@ -729,6 +730,9 @@ public class CCorePlugin extends Plugin {
String option = Platform.getDebugOption(PARSER); String option = Platform.getDebugOption(PARSER);
if(option != null) Util.VERBOSE_PARSER = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ if(option != null) Util.VERBOSE_PARSER = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
option = Platform.getDebugOption(SCANNER);
if( option != null ) Util.VERBOSE_SCANNER = option.equalsIgnoreCase("true");
option = Platform.getDebugOption(MODEL); option = Platform.getDebugOption(MODEL);
if(option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ if(option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$

View file

@ -10,6 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants;
import org.eclipse.cdt.internal.core.parser.ParserLogService; import org.eclipse.cdt.internal.core.parser.ParserLogService;
/** /**
@ -18,10 +19,19 @@ import org.eclipse.cdt.internal.core.parser.ParserLogService;
*/ */
public class ParserUtil public class ParserUtil
{ {
public static IParserLogService getParserLogService() public static IParserLogService getParserLogService()
{ {
return parserLogService; return parserLogService;
} }
private static IParserLogService parserLogService = new ParserLogService(); private static IParserLogService parserLogService = new ParserLogService(IDebugLogConstants.PARSER );
private static IParserLogService scannerLogService = new ParserLogService(IDebugLogConstants.SCANNER );
/**
* @return
*/
public static IParserLogService getScannerLogService() {
return scannerLogService;
}
} }

View file

@ -14,6 +14,7 @@ import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants; import org.eclipse.cdt.internal.core.model.IDebugLogConstants;
import org.eclipse.cdt.internal.core.model.Util; import org.eclipse.cdt.internal.core.model.Util;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant;
/** /**
* @author jcamelon * @author jcamelon
@ -22,12 +23,20 @@ import org.eclipse.cdt.internal.core.model.Util;
public class ParserLogService implements IParserLogService public class ParserLogService implements IParserLogService
{ {
final DebugLogConstant topic;
/**
* @param constant
*/
public ParserLogService(DebugLogConstant constant) {
topic = constant;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String) * @see org.eclipse.cdt.core.parser.IParserLogService#traceLog(java.lang.String)
*/ */
public void traceLog(String message) public void traceLog(String message)
{ {
Util.debugLog( message, IDebugLogConstants.PARSER ); Util.debugLog( message, topic );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,3 +1,6 @@
2004-01-26 John Camelon
Updated clients to use new Scanner logging service.
2004-01-26 Hoda Amer 2004-01-26 Hoda Amer
Content Assist Work: More Tuning of Completion Engine Content Assist Work: More Tuning of Completion Engine

View file

@ -12,6 +12,7 @@ import java.io.InputStreamReader;
import java.io.StringReader; 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.ParserUtil; 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;
@ -73,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,ParserUtil.getParserLogService()); ParserFactory.createScanner(new StringReader(s), "code", new ScannerInfo(), ParserMode.QUICK_PARSE, ParserLanguage.CPP, builder, new NullLogService());
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

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
***********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
import java.io.CharArrayReader; import java.io.CharArrayReader;
@ -73,7 +73,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
* and a given completion offset. * and a given completion offset.
* *
*/ */
public class CompletionEngine implements RelevanceConstants{ public class CompletionEngine implements RelevanceConstants {
ICompletionRequestor requestor; ICompletionRequestor requestor;
int completionStart = 0; int completionStart = 0;
int completionLength = 0; int completionLength = 0;
@ -191,7 +191,7 @@ public class CompletionEngine implements RelevanceConstants{
macroMap.clear(); macroMap.clear();
try try
{ {
scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETION_PARSE, language, requestor, ParserUtil.getParserLogService() ); scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETION_PARSE, language, requestor, ParserUtil.getScannerLogService() );
parser = ParserFactory.createParser( scanner, requestor, ParserMode.COMPLETION_PARSE, language, ParserUtil.getParserLogService() ); parser = ParserFactory.createParser( scanner, requestor, ParserMode.COMPLETION_PARSE, language, ParserUtil.getParserLogService() );
} }
catch( ParserFactoryError pfe ) catch( ParserFactoryError pfe )
@ -824,7 +824,7 @@ public class CompletionEngine implements RelevanceConstants{
StringBuffer kindName = new StringBuffer("Looking For "); StringBuffer kindName = new StringBuffer("Looking For ");
for(int i = 0; i<kinds.length; i++){ for(int i = 0; i<kinds.length; i++){
LookupKind kind = (LookupKind) kinds[i]; LookupKind kind = kinds[i];
if(kind == IASTNode.LookupKind.ALL) if(kind == IASTNode.LookupKind.ALL)
kindName.append("ALL"); kindName.append("ALL");
else if(kind == IASTNode.LookupKind.STRUCTURES) else if(kind == IASTNode.LookupKind.STRUCTURES)