diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 76e52e6f42d..1ceb1b5e498 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-12-11 John Camelon + Expanded ContextualParseTest::testBaseCase(). + Updated tests to deal with new signatures/exceptions. + 2003-12-11 Alain Magloire New test files for the ICPathEntry in core model. diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java index dfcce1ecfde..39f7ccacc93 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseScannerTest.java @@ -15,11 +15,12 @@ import java.io.StringReader; import junit.framework.TestCase; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.NullSourceElementRequestor; +import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactoryException; import org.eclipse.cdt.core.parser.ParserLanguage; @@ -72,7 +73,7 @@ public class BaseScannerTest extends TestCase { t= scanner.nextToken(); } } - catch ( EndOfFile e) + catch ( EndOfFileException e) { } catch (ScannerException se) @@ -87,9 +88,9 @@ public class BaseScannerTest extends TestCase { IToken t= scanner.nextToken(); assertTrue(t.getType() == IToken.tIDENTIFIER); assertTrue(t.getImage().equals(expectedImage)); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { assertTrue(false); - } + } } public void validateInteger(String expectedImage) throws ScannerException @@ -98,7 +99,7 @@ public class BaseScannerTest extends TestCase { IToken t= scanner.nextToken(); assertTrue(t.getType() == IToken.tINTEGER); assertTrue(t.getImage().equals(expectedImage)); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { assertTrue(false); } } @@ -109,7 +110,7 @@ public class BaseScannerTest extends TestCase { IToken t= scanner.nextToken(); assertTrue(t.getType() == IToken.tFLOATINGPT); assertTrue(t.getImage().equals(expectedImage)); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { assertTrue(false); } } @@ -121,9 +122,9 @@ public class BaseScannerTest extends TestCase { assertTrue(t.getType() == IToken.tCHAR ); Character c = new Character( expected ); assertEquals( t.getImage(), c.toString() ); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { assertTrue(false); - } + } } public void validateChar( String expected ) throws ScannerException @@ -132,9 +133,9 @@ public class BaseScannerTest extends TestCase { IToken t= scanner.nextToken(); assertTrue(t.getType() == IToken.tCHAR ); assertEquals( t.getImage(), expected ); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { assertTrue(false); - } + } } public void validateString( String expectedImage ) throws ScannerException @@ -151,9 +152,9 @@ public class BaseScannerTest extends TestCase { else assertTrue(t.getType() == IToken.tSTRING); assertTrue(t.getImage().equals(expectedImage)); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { assertTrue(false); - } + } } public void validateToken(int tokenType) throws ScannerException @@ -161,9 +162,11 @@ public class BaseScannerTest extends TestCase { try { IToken t= scanner.nextToken(); assertTrue(t.getType() == tokenType); - } catch (EndOfFile e) { + } catch (OffsetLimitReachedException e) { assertTrue(false); - } + } catch (EndOfFileException e) { + assertTrue(false); + } } public void validateBalance(int expected) @@ -180,8 +183,10 @@ public class BaseScannerTest extends TestCase { { try { assertNull(scanner.nextToken()); - } catch (EndOfFile e) { - } + }catch (OffsetLimitReachedException e) { + assertTrue(false); + } catch (EndOfFileException e) { + } } public void validateDefinition(String name, String value) @@ -223,7 +228,7 @@ public class BaseScannerTest extends TestCase { IToken t= scanner.nextToken(); assertTrue(t.getType() == IToken.tLCHAR ); assertEquals( t.getImage(), string ); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { assertTrue(false); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java index 96da79a3830..42c8a3b9137 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java @@ -65,8 +65,6 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariableReference; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult; import org.eclipse.cdt.internal.core.parser.ParserException; /** diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java index c78b401da1c..49424eb50ec 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java @@ -7,17 +7,15 @@ package org.eclipse.cdt.core.parser.tests; import java.io.StringReader; - -import junit.framework.TestCase; +import java.io.StringWriter; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; 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.ScannerInfo; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.internal.core.parser.ParserLogService; @@ -27,17 +25,17 @@ import org.eclipse.cdt.internal.core.parser.ParserLogService; * To change the template for this generated type comment go to Window - * Preferences - Java - Code Generation - Code and Comments */ -public class ContextualParseTest extends TestCase { +public class ContextualParseTest extends CompleteParseBaseTest { + public ContextualParseTest(String name) { super(name); } protected IASTCompletionNode parse(String code, int offset) throws Exception { - ISourceElementRequestor requestor = new NullSourceElementRequestor(); IParserLogService log = new ParserLogService(); - + callback = new FullParseCallback(); IParser parser = null; parser = @@ -48,9 +46,9 @@ public class ContextualParseTest extends TestCase { new ScannerInfo(), ParserMode.CONTEXTUAL_PARSE, ParserLanguage.CPP, - requestor, + callback, log), - requestor, + callback, ParserMode.CONTEXTUAL_PARSE, ParserLanguage.CPP, log); @@ -61,9 +59,39 @@ public class ContextualParseTest extends TestCase { public void testBaseCase() throws Exception { - IASTCompletionNode node = parse( "class ABC { }; AB\n\n", 17); + StringWriter writer = new StringWriter(); + writer.write( "class ABC " ); + writer.write( "{int x;}; " ); + writer.write( "AB\n\n" ); + + IASTCompletionNode node = parse( writer.toString(), 21); assertNotNull( node ); assertNotNull( node.getCompletionPrefix() ); + assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); + assertEquals( node.getCompletionPrefix(), "A"); + assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.VARIABLE_TYPE ); + + node = parse( writer.toString(), 12); + assertNotNull( node ); + assertNotNull( node.getCompletionPrefix() ); + assertTrue( node.getCompletionScope() instanceof IASTClassSpecifier ); + assertEquals( node.getCompletionPrefix(), "i"); + assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.FIELD_TYPE ); + + + node = parse( writer.toString(), 22); + assertNotNull( node ); + assertNotNull( node.getCompletionPrefix() ); + assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); assertEquals( node.getCompletionPrefix(), "AB"); + assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.VARIABLE_TYPE ); + + node = parse( writer.toString(), 6); + assertNotNull( node ); + assertNotNull( node.getCompletionPrefix() ); + assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); + assertEquals( node.getCompletionPrefix(), ""); + assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.USER_SPECIFIED_NAME ); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java index 2c5d9b82ce7..611d167b975 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java @@ -31,7 +31,7 @@ public class ParserTestSuite extends TestCase { suite.addTestSuite(QuickParseASTTests.class); suite.addTestSuite(ParserSymbolTableTest.class); suite.addTestSuite(CModelElementsTests.class); -// suite.addTestSuite(ContextualParseTest.class); + suite.addTestSuite(ContextualParseTest.class); // suite.addTestSuite(MacroTests.class); suite.addTestSuite( PreprocessorTest.class ); suite.addTestSuite( PreprocessorConditionalTest.class ); @@ -39,7 +39,5 @@ public class ParserTestSuite extends TestCase { suite.addTestSuite( CompleteParseASTTest.class ); suite.addTestSuite( CompleteParseASTExpressionTest.class ); return suite; - } - - + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java index 5b57f09b11c..f357873703a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java @@ -14,10 +14,11 @@ import java.io.StringReader; import java.util.HashMap; import java.util.Map; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.NullSourceElementRequestor; +import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; @@ -79,7 +80,11 @@ public class PreprocessorConditionalTest extends BaseScannerTest { fail( "Got #error, should not have gotten that."); } - catch( EndOfFile eof ) + catch( OffsetLimitReachedException olre ) + { + fail( "Should never have reached OffsetLimitReachedException"); + } + catch( EndOfFileException eof ) { // expected } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java index 5eaa0b9021e..df7a0626095 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java @@ -5,7 +5,7 @@ import java.io.Writer; import java.util.ArrayList; import java.util.List; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ISourceElementRequestor; @@ -853,7 +853,7 @@ public class ScannerTestCase extends BaseScannerTest } } - public void testQuickScan() throws EndOfFile, ParserFactoryException + public void testQuickScan() throws EndOfFileException, ParserFactoryException { try { diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser index 92a2ec2ad84..59d2c640b62 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser +++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser @@ -1,3 +1,8 @@ +2003-12-11 John Camelon + Added OffsetLimitReachedException and restructured Parser exceptions. + Continued support for code assist/selection search parser. + Ensured all source in parser/ have copyright notices. + 2003-12-09 Andrew Niefer -created TypeFilter to support support filtering of what kind of symbols to find (for prefix lookup 48306) -added IContainerSymbol.isVisible for bug 48294 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Backtrack.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/BacktrackException.java similarity index 92% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Backtrack.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/BacktrackException.java index 0ca66654211..766edb3b0ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Backtrack.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/BacktrackException.java @@ -14,6 +14,6 @@ package org.eclipse.cdt.core.parser; * @author jcamelon * */ -public class Backtrack extends Exception +public class BacktrackException extends Exception { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/CompletionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/CompletionNode.java deleted file mode 100644 index ed77c1d98e1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/CompletionNode.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Created on Dec 8, 2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.cdt.core.parser; - -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTScope; - -/** - * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class CompletionNode implements IASTCompletionNode { - - private final String prefix; - private final IASTNode context; - private final IASTScope scope; - private final CompletionKind kind; - - public CompletionNode( CompletionKind kind, IASTScope scope, IASTNode context, String prefix ) - { - this.kind = kind; - this.context = context; - this.scope = scope; - this.prefix = prefix; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionKind() - */ - public CompletionKind getCompletionKind() { - return kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionScope() - */ - public IASTScope getCompletionScope() { - return scope; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionContext() - */ - public IASTNode getCompletionContext() { - return context; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionPrefix() - */ - public String getCompletionPrefix() { - return prefix; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ContextualParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ContextualParser.java index ae9c3985858..c1b71095b95 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ContextualParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ContextualParser.java @@ -1,28 +1,35 @@ -/* - * Created on Dec 8, 2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ +/********************************************************************** + * 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; +import java.util.HashSet; +import java.util.Set; + import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; import org.eclipse.cdt.internal.core.parser.Parser; +import org.eclipse.cdt.internal.core.parser.ast.*; /** * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class ContextualParser extends Parser implements IParser { - private CompletionKind kind; - private IASTScope scope; - private IASTNode context; + protected CompletionKind kind; + protected IASTScope scope; + protected IASTNode context; + protected IToken finalToken; + private Set keywordSet = new HashSet(); /** * @param scanner @@ -42,14 +49,21 @@ public class ContextualParser extends Parser implements IParser { public IASTCompletionNode parse(int offset) throws ParserNotImplementedException { scanner.setOffsetBoundary(offset); translationUnit(); - return new CompletionNode( getCompletionKind(), getCompletionScope(), getCompletionContext(), getCompletionPrefix() ); + return new ASTCompletionNode( getCompletionKind(), getCompletionScope(), getCompletionContext(), getCompletionPrefix(), getKeywordSet() ); + } + + /** + * @return + */ + private Set getKeywordSet() { + return keywordSet; } /** * @return */ private String getCompletionPrefix() { - return lastToken == null ? "" : lastToken.getImage(); + return ( finalToken == null ? "" : finalToken.getImage() ); } /** @@ -101,7 +115,7 @@ public class ContextualParser extends Parser implements IParser { this.kind = kind; } - protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile + protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws BacktrackException, EndOfFileException { if ( isInlineFunction ) skipOverCompoundStatement(); @@ -109,9 +123,17 @@ public class ContextualParser extends Parser implements IParser { functionBody(scope); } - protected void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile + protected void catchBlockCompoundStatement(IASTScope scope) throws BacktrackException, EndOfFileException { compoundStatement(scope, true); } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.Parser#handleOffsetLimitException() + */ + protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException, OffsetLimitReachedException { + finalToken = exception.getFinalToken(); + throw exception; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/EndOfFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/EndOfFileException.java similarity index 92% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/EndOfFile.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/EndOfFileException.java index 9a759d58c04..91faf911f9b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/EndOfFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/EndOfFileException.java @@ -14,6 +14,6 @@ package org.eclipse.cdt.core.parser; * @author jcamelon * */ -public class EndOfFile extends Backtrack +public class EndOfFileException extends Exception { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java index d97a2736904..b547010ed45 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java @@ -54,10 +54,10 @@ public interface IParser { * @param expression Optional parameter representing an expression object that * your particular IParserCallback instance would appreciate * - * @throws Backtrack thrown if the Scanner/Stream provided does not yield a valid + * @throws BacktrackException thrown if the Scanner/Stream provided does not yield a valid * expression */ - public IASTExpression expression(IASTScope scope) throws Backtrack; + public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException; /** * If an error was encountered, give us the offset of the token that caused the error. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java index fd5991f9a88..422eb9455b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java @@ -22,13 +22,13 @@ public interface IScanner { public void addIncludePath(String includePath); public void overwriteIncludePath( String [] newIncludePaths ); - public IToken nextToken() throws ScannerException, EndOfFile; - public IToken nextToken( boolean next ) throws ScannerException, EndOfFile; + public IToken nextToken() throws ScannerException, EndOfFileException, OffsetLimitReachedException; + public IToken nextToken( boolean next ) throws ScannerException, EndOfFileException, OffsetLimitReachedException; public int getCount(); public int getDepth(); - public IToken nextTokenForStringizing() throws ScannerException, EndOfFile; + public IToken nextTokenForStringizing() throws ScannerException, EndOfFileException, OffsetLimitReachedException; public void setTokenizingMacroReplacementList(boolean b); public void setThrowExceptionOnBadCharacterRead( boolean throwOnBad ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java new file mode 100644 index 00000000000..3bd27e8dda9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java @@ -0,0 +1,32 @@ +/********************************************************************** + * 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 OffsetLimitReachedException extends EndOfFileException { + + private final IToken finalToken; + + public OffsetLimitReachedException( IToken token ) + { + finalToken = token; + } + + /** + * @return Returns the finalToken. + */ + public IToken getFinalToken() { + return finalToken; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserNotImplementedException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserNotImplementedException.java index 010cefac206..57dd85a6809 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserNotImplementedException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserNotImplementedException.java @@ -1,16 +1,17 @@ -/* - * Created on Dec 8, 2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ +/********************************************************************** + * 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 - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class ParserNotImplementedException extends Exception { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/SyntaxErrorException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/SyntaxErrorException.java new file mode 100644 index 00000000000..65f0cdae3fd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/SyntaxErrorException.java @@ -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.core.parser; + +/** + * @author jcamelon + */ +public class SyntaxErrorException extends Exception { + + private final IProblem problem; + + public IProblem getProblem() + { + return problem; + } + + public SyntaxErrorException( IProblem problem ) + { + this.problem = problem; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java index 6ffcf5021bd..eef0bd9e028 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java @@ -10,6 +10,8 @@ ***********************************************************************/ package org.eclipse.cdt.core.parser.ast; +import java.util.Iterator; + import org.eclipse.cdt.core.parser.Enum; /** @@ -20,22 +22,55 @@ public interface IASTCompletionNode { public static class CompletionKind extends Enum { + // x.[ ] x->[ ] public static final CompletionKind MEMBER_REFERENCE = new CompletionKind( 0 ); + // x::[ ] public static final CompletionKind SCOPED_REFERENCE = new CompletionKind( 1 ); + + // class member declaration type reference public static final CompletionKind FIELD_TYPE = new CompletionKind( 2 ); + + // stand-alone declaration type reference public static final CompletionKind VARIABLE_TYPE = new CompletionKind( 3 ); + + // function/method argument type reference public static final CompletionKind ARGUMENT_TYPE = new CompletionKind( 4 ); + + // inside code body - name reference public static final CompletionKind SINGLE_NAME_REFERENCE = new CompletionKind( 5 ); + + // any place one can expect a type public static final CompletionKind TYPE_REFERENCE = new CompletionKind( 6 ); + + // any place where one can expect a class name public static final CompletionKind CLASS_REFERENCE = new CompletionKind( 7 ); + + // any place where a namespace name is expected public static final CompletionKind NAMESPACE_REFERENCE = new CompletionKind( 8 ); + + // any place where an exception name is expected public static final CompletionKind EXCEPTION_REFERENCE = new CompletionKind( 9 ); + + // any place where exclusively a preprocessor macro name would be expected public static final CompletionKind MACRO_REFERENCE = new CompletionKind( 10 ); + + // any place where function arguments are expected public static final CompletionKind FUNCTION_REFERENCE = new CompletionKind( 11 ); + + // any place where constructor arguments are expected public static final CompletionKind CONSTRUCTOR_REFERENCE = new CompletionKind( 12 ); + + // any place where exclusively a keyword is expected public static final CompletionKind KEYWORD = new CompletionKind( 13 ); - //TODO MORE TO COME + // any place where exclusively a preprocessor directive is expected + public static final CompletionKind PREPROCESSOR_DIRECTIVE = new CompletionKind( 14 ); + + // any place where a type or variable name is expected to be introduced + public static final CompletionKind USER_SPECIFIED_NAME = new CompletionKind( 15 ); + + // error condition -- a place in the grammar where there is nothing to lookup + public static final CompletionKind NO_SUCH_KIND = new CompletionKind( 200 ); /** * @param enumValue */ @@ -68,4 +103,10 @@ public interface IASTCompletionNode { * @return the prefix */ public String getCompletionPrefix(); + + /** + * @return + */ + public Iterator getKeywords(); + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java index a72b8a6ca92..2e260e4e588 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java @@ -48,7 +48,7 @@ public interface IASTNode { } } - public static class InvalidLookupKind extends Exception + public static class LookupException extends Exception { } @@ -56,9 +56,8 @@ public interface IASTNode { { public String getPrefix(); public Iterator getNodes(); - public Iterator getKeywords(); } - public LookupResult lookup( String prefix, LookupKind kind ); + public LookupResult lookup( String prefix, LookupKind kind ) throws LookupException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BaseProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BaseProblemFactory.java index b308f3265e8..54f8e8c912f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BaseProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BaseProblemFactory.java @@ -17,7 +17,6 @@ import org.eclipse.cdt.core.parser.IProblem; /** * @author jcamelon - * */ public abstract class BaseProblemFactory { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java index c6fa07e640f..e618bee5b28 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java @@ -1,13 +1,17 @@ -/* - * Created on Dec 5, 2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ +/********************************************************************** + * 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; -import org.eclipse.cdt.core.parser.Backtrack; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.ISourceElementRequestor; @@ -21,9 +25,6 @@ import org.eclipse.cdt.core.parser.ast.IASTScope; /** * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class CompleteParser extends Parser { @@ -40,7 +41,7 @@ public class CompleteParser extends Parser { scanner.setASTFactory(astFactory); } - protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile + protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws BacktrackException, EndOfFileException { if ( isInlineFunction ) skipOverCompoundStatement(); @@ -48,7 +49,7 @@ public class CompleteParser extends Parser { functionBody(scope); } - protected void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile + protected void catchBlockCompoundStatement(IASTScope scope) throws BacktrackException, EndOfFileException { compoundStatement(scope, true); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/LimitedScannerContext.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/LimitedScannerContext.java index 46bcb28d8fd..f01443529d0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/LimitedScannerContext.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/LimitedScannerContext.java @@ -1,9 +1,13 @@ -/* - * Created on Dec 4, 2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ +/********************************************************************** + * 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; import java.io.IOException; @@ -11,9 +15,6 @@ import java.io.Reader; /** * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class LimitedScannerContext extends ScannerContext diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 87e2056f006..648b05d6009 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -10,18 +10,20 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Stack; -import org.eclipse.cdt.core.parser.Backtrack; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; +import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ScannerException; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; @@ -46,6 +48,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; import org.eclipse.cdt.core.parser.ast.IASTScope; +import org.eclipse.cdt.core.parser.ast.IASTScopedElement; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTemplate; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; @@ -57,6 +60,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; +import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; /** @@ -71,9 +75,9 @@ public abstract class Parser implements IParser { protected final IParserLogService log; private static final List EMPTY_LIST = new ArrayList(); - private static int DEFAULT_OFFSET = -1; + private static int FIRST_ERROR_OFFSET_UNSET = -1; // sentinel initial value for offsets - protected int firstErrorOffset = DEFAULT_OFFSET; + protected int firstErrorOffset = FIRST_ERROR_OFFSET_UNSET; // offset where the first parse error occurred // are we doing the high-level parse, or an in depth parse? @@ -86,17 +90,17 @@ public abstract class Parser implements IParser * This is the single entry point for setting parsePassed to * false, and also making note what token offset we failed upon. * - * @throws EndOfFile + * @throws EndOfFileException */ - protected void failParse() throws EndOfFile + protected void failParse() { try { - if (firstErrorOffset == DEFAULT_OFFSET) + if (firstErrorOffset == FIRST_ERROR_OFFSET_UNSET ) firstErrorOffset = LA(1).getOffset(); - } catch( EndOfFile eof ) + } catch( EndOfFileException eof ) { - throw eof; + // do nothing } finally { @@ -118,12 +122,14 @@ public abstract class Parser implements IParser IParserLogService log ) { this.scanner = scanner; - requestor = callback; + this.requestor = callback; this.language = language; this.log = log; } + // counter that keeps track of the number of times Parser.parse() is called private static int parseCount = 0; + /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParser#parse() */ @@ -174,12 +180,12 @@ public abstract class Parser implements IParser if (LA(1) == checkToken) errorHandling(); } - catch (EndOfFile e) + catch (EndOfFileException e) { // Good break; } - catch (Backtrack b) + catch (BacktrackException b) { try { @@ -197,17 +203,14 @@ public abstract class Parser implements IParser lastBacktrack = LA(1); } } - catch (EndOfFile e) + catch (EndOfFileException e) { break; } } catch (Exception e) { - try { - failParse(); - } catch (EndOfFile e1) { - } + failParse(); break; } } @@ -217,9 +220,9 @@ public abstract class Parser implements IParser * This function is called whenever we encounter and error that we cannot backtrack out of and we * still wish to try and continue on with the parse to do a best-effort parse for our client. * - * @throws EndOfFile We can potentially hit EndOfFile here as we are skipping ahead. + * @throws EndOfFileException We can potentially hit EndOfFile here as we are skipping ahead. */ - protected void errorHandling() throws EndOfFile + protected void errorHandling() throws EndOfFileException { failParse(); consume(); @@ -251,10 +254,10 @@ public abstract class Parser implements IParser * using namespace ::? nested-name-specifier? namespace-name ; * * @param container Callback object representing the scope these definitions fall into. - * @throws Backtrack request for a backtrack + * @throws BacktrackException request for a backtrack */ protected void usingClause(IASTScope scope) - throws Backtrack + throws EndOfFileException, BacktrackException { IToken firstToken = consume(IToken.t_using); if (LT(1) == IToken.t_namespace) @@ -340,10 +343,10 @@ public abstract class Parser implements IParser * | extern "string literal" { declaration-seq } * * @param container Callback object representing the scope these definitions fall into. - * @throws Backtrack request for a backtrack + * @throws BacktrackException request for a backtrack */ protected void linkageSpecification(IASTScope scope) - throws Backtrack + throws EndOfFileException, BacktrackException { IToken firstToken = consume(IToken.t_extern); if (LT(1) != IToken.tSTRING) @@ -381,7 +384,7 @@ public abstract class Parser implements IParser { declaration(linkage, null); } - catch (Backtrack bt) + catch (BacktrackException bt) { failParse(); if (checkToken == LA(1)) @@ -426,10 +429,10 @@ public abstract class Parser implements IParser * explicit-specialization: template <> declaration * * @param container Callback object representing the scope these definitions fall into. - * @throws Backtrack request for a backtrack + * @throws BacktrackException request for a backtrack */ protected void templateDeclaration(IASTScope scope) - throws Backtrack + throws EndOfFileException, BacktrackException { IToken firstToken = null; boolean exported = false; @@ -517,7 +520,7 @@ public abstract class Parser implements IParser templateDecl.exitScope( requestor ); } - catch (Backtrack bt) + catch (BacktrackException bt) { throw bt; } @@ -545,10 +548,10 @@ public abstract class Parser implements IParser * id-expression * * @param templateDeclaration Callback's templateDeclaration which serves as a scope to this list. - * @throws Backtrack request for a backtrack + * @throws BacktrackException request for a backtrack */ protected List templateParameterList(IASTScope scope) - throws Backtrack + throws BacktrackException, EndOfFileException { // if we have gotten this far then we have a true template-declaration // iterate through the template parameter list @@ -581,7 +584,7 @@ public abstract class Parser implements IParser } } - catch (Backtrack bt) + catch (BacktrackException bt) { throw bt; } @@ -697,12 +700,12 @@ public abstract class Parser implements IParser * templateDeclaration * * @param container IParserCallback object which serves as the owner scope for this declaration. - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void declaration( IASTScope scope, IASTTemplate ownerTemplate) - throws Backtrack + throws EndOfFileException, BacktrackException { setCurrentScope(scope); switch (LT(1)) @@ -750,13 +753,22 @@ public abstract class Parser implements IParser default : simpleDeclarationStrategyUnion(scope, ownerTemplate); } + if( scope instanceof IASTScopedElement ) + setCurrentScope( ((IASTScopedElement)scope).getOwnerScope() ); + else + setCurrentScope( null ); } protected void simpleDeclarationStrategyUnion( IASTScope scope, IASTTemplate ownerTemplate) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { IToken mark = mark(); + + if( scope instanceof IASTClassSpecifier ) + setCompletionKind( CompletionKind.FIELD_TYPE ); + else + setCompletionKind( CompletionKind.VARIABLE_TYPE ); try { simpleDeclaration( @@ -765,7 +777,7 @@ public abstract class Parser implements IParser ownerTemplate); // try it first with the original strategy } - catch (Backtrack bt) + catch (BacktrackException bt) { // did not work backup(mark); @@ -777,7 +789,7 @@ public abstract class Parser implements IParser scope, ownerTemplate); } - catch( Backtrack bt2 ) + catch( BacktrackException bt2 ) { backup( mark ); @@ -788,7 +800,7 @@ public abstract class Parser implements IParser scope, ownerTemplate); } - catch( Backtrack b3 ) + catch( BacktrackException b3 ) { backup( mark ); throw b3; @@ -804,11 +816,11 @@ public abstract class Parser implements IParser * namespace-body: * declaration-seq? * @param container IParserCallback object which serves as the owner scope for this declaration. - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void namespaceDefinition(IASTScope scope) - throws Backtrack + throws BacktrackException, EndOfFileException { IToken first = consume(IToken.t_namespace); @@ -849,7 +861,7 @@ public abstract class Parser implements IParser { declaration(namespaceDefinition, null); } - catch (Backtrack bt) + catch (BacktrackException bt) { failParse(); if (checkToken == LA(1)) @@ -907,13 +919,13 @@ public abstract class Parser implements IParser * @param container IParserCallback object which serves as the owner scope for this declaration. * @param tryConstructor true == take strategy1 (constructor ) : false == take strategy 2 ( pointer to function) * @param forKR Is this for K&R-style parameter declaration (true) or simple declaration (false) - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void simpleDeclaration( SimpleDeclarationStrategy strategy, IASTScope scope, IASTTemplate ownerTemplate) - throws Backtrack + throws BacktrackException, EndOfFileException { IToken firstToken = LA(1); DeclarationWrapper sdw = @@ -1056,9 +1068,9 @@ public abstract class Parser implements IParser } } - protected abstract void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile; + protected abstract void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws BacktrackException, EndOfFileException; - protected void skipOverCompoundStatement() throws Backtrack, EndOfFile + protected void skipOverCompoundStatement() throws BacktrackException, EndOfFileException { // speed up the parser by skiping the body // simply look for matching brace and return @@ -1086,10 +1098,10 @@ public abstract class Parser implements IParser * classname * identifier * @param declarator IParserCallback object that represents the declarator (constructor) that owns this initializer - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void ctorInitializer(Declarator d ) - throws Backtrack + throws EndOfFileException, BacktrackException { consume(IToken.tCOLON); @@ -1126,7 +1138,7 @@ public abstract class Parser implements IParser consume(IToken.tCOMMA); } } - catch (Backtrack bt) + catch (BacktrackException bt) { throw backtrack; @@ -1137,11 +1149,11 @@ public abstract class Parser implements IParser * This routine parses a parameter declaration * * @param containerObject The IParserCallback object representing the parameterDeclarationClause owning the parm. - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void parameterDeclaration( IParameterCollection collection, IASTScope scope) - throws Backtrack + throws BacktrackException, EndOfFileException { IToken current = LA(1); @@ -1246,10 +1258,10 @@ public abstract class Parser implements IParser /** * @param flags input flags that are used to make our decision * @return whether or not this looks like a constructor (true or false) - * @throws EndOfFile we could encounter EOF while looking ahead + * @throws EndOfFileException we could encounter EOF while looking ahead */ private boolean lookAheadForConstructorOrConversion(Flags flags, DeclarationWrapper sdw ) - throws EndOfFile + throws EndOfFileException { if (flags.isForParameterDeclaration()) return false; @@ -1262,7 +1274,7 @@ public abstract class Parser implements IParser { consumeTemplatedOperatorName( d ); } - catch (Backtrack e) + catch (BacktrackException e) { backup( mark ); return false; @@ -1303,16 +1315,16 @@ public abstract class Parser implements IParser /** * @param flags input flags that are used to make our decision * @return whether or not this looks like a a declarator follows - * @throws EndOfFile we could encounter EOF while looking ahead + * @throws EndOfFileException we could encounter EOF while looking ahead */ - private boolean lookAheadForDeclarator(Flags flags) throws EndOfFile + private boolean lookAheadForDeclarator(Flags flags) throws EndOfFileException { return flags.haveEncounteredTypename() && ((LT(2) != IToken.tIDENTIFIER || (LT(3) != IToken.tLPAREN && LT(3) != IToken.tASSIGN)) && !LA(2).isPointer()); } - private void callbackSimpleDeclToken(Flags flags) throws Backtrack + private void callbackSimpleDeclToken(Flags flags) throws BacktrackException, EndOfFileException { flags.setEncounteredRawType(true); consume(); @@ -1339,13 +1351,13 @@ public abstract class Parser implements IParser * @param decl IParserCallback object representing the declaration that owns this specifier sequence * @param parm Is this for a parameter declaration (true) or simple declaration (false) * @param tryConstructor true for constructor, false for pointer to function strategy - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void declSpecifierSeq( boolean parm, boolean tryConstructor, DeclarationWrapper sdw ) - throws Backtrack + throws BacktrackException, EndOfFileException { Flags flags = new Flags(parm, tryConstructor); IToken typeNameBegin = null; @@ -1551,6 +1563,7 @@ public abstract class Parser implements IParser if (typeNameBegin != null) sdw.setTypeName( new TokenDuple(typeNameBegin, typeNameEnd)); + return; } @@ -1568,7 +1581,7 @@ public abstract class Parser implements IParser flags.setEncounteredTypename(true); break; } - catch (Backtrack bt) + catch (BacktrackException bt) { elaboratedTypeSpecifier(sdw); flags.setEncounteredTypename(true); @@ -1581,7 +1594,7 @@ public abstract class Parser implements IParser flags.setEncounteredTypename(true); break; } - catch (Backtrack bt) + catch (BacktrackException bt) { // this is an elaborated class specifier elaboratedTypeSpecifier(sdw); @@ -1599,10 +1612,10 @@ public abstract class Parser implements IParser * Parse an elaborated type specifier. * * @param decl Declaration which owns the elaborated type - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void elaboratedTypeSpecifier(DeclarationWrapper sdw) - throws Backtrack + throws BacktrackException, EndOfFileException { // this is an elaborated class specifier IToken t = consume(); @@ -1658,10 +1671,10 @@ public abstract class Parser implements IParser * * @param previousLast Previous "last" token (returned if nothing was consumed) * @return Last consumed token, or previousLast if nothing was consumed - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected IToken consumeTemplateParameters(IToken previousLast) - throws Backtrack + throws EndOfFileException, BacktrackException { IToken last = previousLast; if (LT(1) == IToken.tLT) @@ -1709,9 +1722,9 @@ public abstract class Parser implements IParser /** * Parse an identifier. * - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ - protected IToken identifier() throws Backtrack + protected IToken identifier() throws EndOfFileException, BacktrackException { IToken first = consume(IToken.tIDENTIFIER); // throws backtrack if its not that return first; @@ -1721,9 +1734,9 @@ public abstract class Parser implements IParser * * class-name: identifier | template-id * - * @throws Backtrack + * @throws BacktrackException */ - protected ITokenDuple className() throws Backtrack + protected ITokenDuple className() throws EndOfFileException, BacktrackException { ITokenDuple duple = name(); IToken last = duple.getLastToken(); @@ -1742,9 +1755,9 @@ public abstract class Parser implements IParser * * @return the last token that we consumed in a successful parse * - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ - protected IToken templateId() throws Backtrack + protected IToken templateId() throws EndOfFileException, BacktrackException { ITokenDuple duple = name(); IToken last = consumeTemplateParameters(duple.getLastToken()); @@ -1759,9 +1772,9 @@ public abstract class Parser implements IParser * name2 * : IDENTIFER * - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ - protected TokenDuple name() throws Backtrack + protected TokenDuple name() throws BacktrackException, EndOfFileException { IToken first = LA(1); IToken last = null; @@ -1780,7 +1793,7 @@ public abstract class Parser implements IParser try { last = consumeTemplateParameters(last); - } catch( Backtrack bt ) + } catch( BacktrackException bt ) { backup( secondMark ); } @@ -1818,11 +1831,11 @@ public abstract class Parser implements IParser * TODO: fix this * @param ptrOp Pointer Operator that const-volatile applies to. * @return Returns the same object sent in. - * @throws Backtrack + * @throws BacktrackException */ protected IToken cvQualifier( IDeclarator declarator) - throws Backtrack + throws EndOfFileException, BacktrackException { IToken result = null; switch (LT(1)) @@ -1856,11 +1869,11 @@ public abstract class Parser implements IParser * : declarator ("=" initializerClause | "(" expressionList ")")? * @param owner IParserCallback object that represents the owner declaration object. * @return declarator that this parsing produced. - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected Declarator initDeclarator( DeclarationWrapper sdw, SimpleDeclarationStrategy strategy ) - throws Backtrack + throws EndOfFileException, BacktrackException { Declarator d = declarator(sdw, sdw.getScope(), strategy ); if( language == ParserLanguage.CPP ) @@ -1872,7 +1885,7 @@ public abstract class Parser implements IParser } protected void optionalCPPInitializer(Declarator d) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { // handle initializer if (LT(1) == IToken.tASSIGN) @@ -1891,7 +1904,7 @@ public abstract class Parser implements IParser astExpression = expression(d.getDeclarationWrapper().getScope()); consume(IToken.tRPAREN); d.setConstructorExpression(astExpression); - } catch( Backtrack bt ) + } catch( BacktrackException bt ) { backup( mark ); throw bt; @@ -1899,7 +1912,7 @@ public abstract class Parser implements IParser } } - protected void optionalCInitializer( Declarator d ) throws Backtrack + protected void optionalCInitializer( Declarator d ) throws EndOfFileException, BacktrackException { if( LT(1) == IToken.tASSIGN ) { @@ -1914,7 +1927,7 @@ public abstract class Parser implements IParser protected IASTInitializerClause cInitializerClause( IASTScope scope, List designators) - throws Backtrack + throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tLBRACE) { @@ -1971,7 +1984,7 @@ public abstract class Parser implements IParser throw backtrack; } } - catch (Backtrack b) + catch (BacktrackException b) { // do nothing } @@ -1981,7 +1994,7 @@ public abstract class Parser implements IParser * */ protected IASTInitializerClause initializerClause(IASTScope scope) - throws Backtrack + throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tLBRACE) { @@ -2046,14 +2059,18 @@ public abstract class Parser implements IParser throw backtrack; } } - catch (Backtrack b) + catch (BacktrackException b) { // do nothing + } + catch ( EndOfFileException eof ) + { + } throw backtrack; } - protected List designatorList(IASTScope scope) throws EndOfFile, Backtrack + protected List designatorList(IASTScope scope) throws EndOfFileException, BacktrackException { List designatorList = new ArrayList(); // designated initializers for C @@ -2108,11 +2125,11 @@ public abstract class Parser implements IParser * * @param container IParserCallback object that represents the owner declaration. * @return declarator that this parsing produced. - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected Declarator declarator( IDeclaratorOwner owner, IASTScope scope, SimpleDeclarationStrategy strategy ) - throws Backtrack + throws EndOfFileException, BacktrackException { Declarator d = null; DeclarationWrapper sdw = owner.getDeclarationWrapper(); @@ -2157,7 +2174,7 @@ public abstract class Parser implements IParser { throw backtrack; } - } catch( Backtrack b ) + } catch( BacktrackException b ) { failed = true; } @@ -2238,7 +2255,7 @@ public abstract class Parser implements IParser duple = typeId(scope, false); exceptionSpecIds.add(duple); } - catch (Backtrack e) + catch (BacktrackException e) { failParse(); log.traceLog( @@ -2320,7 +2337,7 @@ public abstract class Parser implements IParser return d; } protected void consumeTemplatedOperatorName(Declarator d) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { if (LT(1) == IToken.t_operator) operatorId(d, null); @@ -2332,7 +2349,7 @@ public abstract class Parser implements IParser d.setName(duple); } - catch (Backtrack bt) + catch (BacktrackException bt) { Declarator d1 = d; Declarator d11 = d1; @@ -2364,7 +2381,7 @@ public abstract class Parser implements IParser } } protected void consumeArrayModifiers( IDeclarator d, IASTScope scope ) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { while (LT(1) == IToken.tLBRACKET) { @@ -2392,7 +2409,7 @@ public abstract class Parser implements IParser protected void operatorId( Declarator d, IToken originalToken) - throws Backtrack, EndOfFile + throws BacktrackException, EndOfFileException { // we know this is an operator IToken operatorToken = consume(IToken.t_operator); @@ -2448,9 +2465,9 @@ public abstract class Parser implements IParser * | ::? nestedNameSpecifier "*" (cvQualifier)* * * @param owner Declarator that this pointer operator corresponds to. - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ - protected IToken consumePointerOperators(IDeclarator d) throws Backtrack + protected IToken consumePointerOperators(IDeclarator d) throws EndOfFileException, BacktrackException { IToken result = null; for( ; ; ) @@ -2471,7 +2488,7 @@ public abstract class Parser implements IParser { nameDuple = name(); } - catch( Backtrack bt ) + catch( BacktrackException bt ) { backup( mark ); return null; @@ -2516,10 +2533,10 @@ public abstract class Parser implements IParser * enumerator: identifier * * @param owner IParserCallback object that represents the declaration that owns this type specifier. - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void enumSpecifier(DeclarationWrapper sdw) - throws Backtrack + throws BacktrackException, EndOfFileException { IToken mark = mark(); IToken identifier = null; @@ -2633,17 +2650,18 @@ public abstract class Parser implements IParser * : classKey name (baseClause)? "{" (memberSpecification)* "}" * * @param owner IParserCallback object that represents the declaration that owns this classSpecifier - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ protected void classSpecifier(DeclarationWrapper sdw) - throws Backtrack + throws BacktrackException, EndOfFileException { ClassNameType nameType = ClassNameType.IDENTIFIER; ASTClassKind classKind = null; ASTAccessVisibility access = ASTAccessVisibility.PUBLIC; IToken classKey = null; IToken mark = mark(); - // class key + + // class key switch (LT(1)) { case IToken.t_class : @@ -2663,7 +2681,10 @@ public abstract class Parser implements IParser throw backtrack; } + ITokenDuple duple = null; + + setCompletionKind( CompletionKind.USER_SPECIFIED_NAME ); // class name if (LT(1) == IToken.tIDENTIFIER) duple = className(); @@ -2737,7 +2758,7 @@ public abstract class Parser implements IParser { declaration(astClassSpecifier, null); } - catch (Backtrack bt) + catch (BacktrackException bt) { failParse(); if (checkToken == LA(1)) @@ -2775,11 +2796,11 @@ public abstract class Parser implements IParser * accessspecifier virtual? ::? nestednamespecifier? classname * accessspecifier: private | protected | public * @param classSpecOwner - * @throws Backtrack + * @throws BacktrackException */ protected void baseSpecifier( IASTClassSpecifier astClassSpec) - throws Backtrack + throws EndOfFileException, BacktrackException { consume(IToken.tCOLON); boolean isVirtual = false; @@ -2855,18 +2876,18 @@ public abstract class Parser implements IParser /** * Parses a function body. * - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ - protected void functionBody( IASTScope scope ) throws Backtrack + protected void functionBody( IASTScope scope ) throws EndOfFileException, BacktrackException { compoundStatement( scope, false ); } /** * Parses a statement. * - * @throws Backtrack request a backtrack + * @throws BacktrackException request a backtrack */ - protected void statement(IASTScope scope) throws Backtrack + protected void statement(IASTScope scope) throws EndOfFileException, BacktrackException { switch (LT(1)) @@ -2998,7 +3019,7 @@ public abstract class Parser implements IParser thisExpression.acceptElement( requestor ); return; } - catch (Backtrack b) + catch (BacktrackException b) { backup( mark ); } @@ -3007,7 +3028,7 @@ public abstract class Parser implements IParser } } protected void catchHandlerSequence(IASTScope scope) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { if( LT(1) != IToken.t_catch ) throw backtrack; // error, need at least one of these @@ -3025,9 +3046,9 @@ public abstract class Parser implements IParser } } - protected abstract void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile; + protected abstract void catchBlockCompoundStatement(IASTScope scope) throws BacktrackException, EndOfFileException; - protected void singleStatementScope(IASTScope scope) throws Backtrack + protected void singleStatementScope(IASTScope scope) throws EndOfFileException, BacktrackException { IASTCodeScope newScope; try @@ -3050,9 +3071,9 @@ public abstract class Parser implements IParser } /** - * @throws Backtrack + * @throws BacktrackException */ - protected void condition( IASTScope scope ) throws Backtrack + protected void condition( IASTScope scope ) throws BacktrackException, EndOfFileException { IASTExpression someExpression = expression( scope ); someExpression.acceptElement(requestor); @@ -3060,22 +3081,22 @@ public abstract class Parser implements IParser } /** - * @throws Backtrack + * @throws BacktrackException */ - protected void forInitStatement( IASTScope scope ) throws Backtrack + protected void forInitStatement( IASTScope scope ) throws BacktrackException, EndOfFileException { try { simpleDeclarationStrategyUnion(scope,null); } - catch( Backtrack bt ) + catch( BacktrackException bt ) { try { IASTExpression e = expression( scope ); e.acceptElement(requestor); } - catch( Backtrack b ) + catch( BacktrackException b ) { failParse(); throw b; @@ -3084,9 +3105,9 @@ public abstract class Parser implements IParser } /** - * @throws Backtrack + * @throws BacktrackException */ - protected void compoundStatement( IASTScope scope, boolean createNewScope ) throws Backtrack + protected void compoundStatement( IASTScope scope, boolean createNewScope ) throws EndOfFileException, BacktrackException { consume(IToken.tLBRACE); @@ -3111,7 +3132,7 @@ public abstract class Parser implements IParser { statement(createNewScope ? newScope : scope ); } - catch( Backtrack b ) + catch( BacktrackException b ) { failParse(); if( LA(1) == checkToken ) @@ -3125,17 +3146,17 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression constantExpression( IASTScope scope ) - throws Backtrack + throws BacktrackException, EndOfFileException { return conditionalExpression(scope); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParser#expression(java.lang.Object) */ - public IASTExpression expression(IASTScope scope) throws Backtrack + public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException { IASTExpression assignmentExpression = assignmentExpression(scope); while (LT(1) == IToken.tCOMMA) @@ -3166,10 +3187,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression assignmentExpression(IASTScope scope) - throws Backtrack { + throws EndOfFileException, BacktrackException { if (LT(1) == IToken.t_throw) { return throwExpression(scope); } @@ -3241,7 +3262,7 @@ public abstract class Parser implements IParser protected IASTExpression assignmentOperatorExpression( IASTScope scope, IASTExpression.Kind kind, IASTExpression lhs ) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { consume(); IASTExpression assignmentExpression = assignmentExpression(scope); @@ -3267,10 +3288,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression throwExpression( IASTScope scope ) - throws Backtrack + throws EndOfFileException, BacktrackException { consume(IToken.t_throw); IASTExpression throwExpression = null; @@ -3278,7 +3299,7 @@ public abstract class Parser implements IParser { throwExpression = expression(scope); } - catch (Backtrack b) + catch (BacktrackException b) { } try @@ -3303,10 +3324,10 @@ public abstract class Parser implements IParser /** * @param expression * @return - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression conditionalExpression( IASTScope scope ) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = logicalOrExpression(scope); if (LT(1) == IToken.tQUESTION) @@ -3339,10 +3360,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression logicalOrExpression(IASTScope scope) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = logicalAndExpression(scope); while (LT(1) == IToken.tOR) @@ -3374,10 +3395,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression logicalAndExpression( IASTScope scope ) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = inclusiveOrExpression( scope ); while (LT(1) == IToken.tAND) @@ -3408,10 +3429,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression inclusiveOrExpression( IASTScope scope ) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = exclusiveOrExpression(scope); while (LT(1) == IToken.tBITOR) @@ -3443,15 +3464,16 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression exclusiveOrExpression( IASTScope scope ) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = andExpression( scope ); while (LT(1) == IToken.tXOR) { consume(); + IASTExpression secondExpression = andExpression( scope ); try @@ -3478,9 +3500,9 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ - protected IASTExpression andExpression(IASTScope scope) throws Backtrack + protected IASTExpression andExpression(IASTScope scope) throws EndOfFileException, BacktrackException { IASTExpression firstExpression = equalityExpression(scope); while (LT(1) == IToken.tAMPER) @@ -3512,10 +3534,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression equalityExpression( IASTScope scope ) - throws Backtrack + throws EndOfFileException, BacktrackException { IASTExpression firstExpression = relationalExpression(scope); for (;;) @@ -3557,10 +3579,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression relationalExpression(IASTScope scope) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = shiftExpression(scope); for (;;) @@ -3636,10 +3658,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression shiftExpression(IASTScope scope) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = additiveExpression(scope); for (;;) @@ -3680,10 +3702,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression additiveExpression( IASTScope scope ) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = multiplicativeExpression( scope ); for (;;) @@ -3724,10 +3746,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression multiplicativeExpression( IASTScope scope ) - throws Backtrack + throws BacktrackException, EndOfFileException { IASTExpression firstExpression = pmExpression(scope); for (;;) @@ -3779,9 +3801,9 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ - protected IASTExpression pmExpression( IASTScope scope ) throws Backtrack + protected IASTExpression pmExpression( IASTScope scope ) throws EndOfFileException, BacktrackException { IASTExpression firstExpression = castExpression(scope); for (;;) @@ -3825,7 +3847,7 @@ public abstract class Parser implements IParser * : unaryExpression * | "(" typeId ")" castExpression */ - protected IASTExpression castExpression( IASTScope scope ) throws Backtrack + protected IASTExpression castExpression( IASTScope scope ) throws EndOfFileException, BacktrackException { // TO DO: we need proper symbol checkint to ensure type name if (LT(1) == IToken.tLPAREN) @@ -3858,18 +3880,19 @@ public abstract class Parser implements IParser throw backtrack; } } - catch (Backtrack b) + catch (BacktrackException b) { backup(mark); } } return unaryExpression(scope); + } /** - * @throws Backtrack + * @throws BacktrackException */ - protected IASTTypeId typeId(IASTScope scope, boolean skipArrayModifiers ) throws Backtrack + protected IASTTypeId typeId(IASTScope scope, boolean skipArrayModifiers ) throws EndOfFileException, BacktrackException { IToken mark = mark(); ITokenDuple name = null; @@ -3887,7 +3910,7 @@ public abstract class Parser implements IParser kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; break; } - catch (Backtrack b) + catch (BacktrackException b) { // do nothing } @@ -4010,7 +4033,7 @@ public abstract class Parser implements IParser { name = name(); kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; - } catch( Backtrack b ) + } catch( BacktrackException b ) { backup( mark ); throw backtrack; @@ -4053,10 +4076,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression deleteExpression( IASTScope scope ) - throws Backtrack + throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tCOLONCOLON) { @@ -4098,7 +4121,7 @@ public abstract class Parser implements IParser * Pazse a new-expression. * * @param expression - * @throws Backtrack + * @throws BacktrackException * * * newexpression: ::? new newplacement? newtypeid newinitializer? @@ -4110,7 +4133,7 @@ public abstract class Parser implements IParser * directnewdeclarator [ constantexpression ] * newinitializer: ( expressionlist? ) */ - protected IASTExpression newExpression( IASTScope scope ) throws Backtrack + protected IASTExpression newExpression( IASTScope scope ) throws BacktrackException, EndOfFileException { if (LT(1) == IToken.tCOLONCOLON) { @@ -4145,7 +4168,7 @@ public abstract class Parser implements IParser typeIdInParen = true; } } - catch (Backtrack e) + catch (BacktrackException e) { backup(backtrackMarker); } @@ -4180,7 +4203,7 @@ public abstract class Parser implements IParser backtrackMarker = mark(); typeId = typeId(scope, true); } - catch (Backtrack e) + catch (BacktrackException e) { // Hmmm, so it wasn't typeId after all... Then it is // CASE: new (typeid-looking-as-placement) @@ -4230,7 +4253,7 @@ public abstract class Parser implements IParser } } } - catch (Backtrack e) + catch (BacktrackException e) { // CASE: new (typeid-looking-as-placement)(initializer-not-looking-as-typeid) // Fallback to initializer processing @@ -4278,7 +4301,7 @@ public abstract class Parser implements IParser } protected IASTExpression unaryOperatorCastExpression( IASTScope scope, IASTExpression.Kind kind) - throws Backtrack + throws EndOfFileException, BacktrackException { IASTExpression castExpression = castExpression(scope); try @@ -4302,10 +4325,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression unaryExpression( IASTScope scope ) - throws Backtrack + throws EndOfFileException, BacktrackException { switch (LT(1)) { @@ -4354,7 +4377,7 @@ public abstract class Parser implements IParser d = typeId(scope, false); consume(IToken.tRPAREN); } - catch (Backtrack bt) + catch (BacktrackException bt) { backup(mark); unaryExpression = unaryExpression(scope); @@ -4424,10 +4447,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression postfixExpression( IASTScope scope ) - throws Backtrack + throws EndOfFileException, BacktrackException { IASTExpression firstExpression = null; boolean isTemplate = false; @@ -4448,7 +4471,7 @@ public abstract class Parser implements IParser { templateId = new TokenDuple( current, templateId() ); } - catch( Backtrack bt ) + catch( BacktrackException bt ) { if( templateTokenConsumed ) throw bt; @@ -4556,7 +4579,7 @@ public abstract class Parser implements IParser { typeId = typeId(scope, false); } - catch (Backtrack b) + catch (BacktrackException b) { isTypeId = false; lhs = expression(scope); @@ -4762,7 +4785,7 @@ public abstract class Parser implements IParser } protected IASTExpression specialCastExpression( IASTScope scope, IASTExpression.Kind kind) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { consume(); consume(IToken.tLT); @@ -4792,7 +4815,7 @@ public abstract class Parser implements IParser } protected IASTExpression simpleTypeConstructorExpression( IASTScope scope, Kind type) - throws EndOfFile, Backtrack + throws EndOfFileException, BacktrackException { consume(); consume(IToken.tLPAREN); @@ -4820,10 +4843,10 @@ public abstract class Parser implements IParser } /** * @param expression - * @throws Backtrack + * @throws BacktrackException */ protected IASTExpression primaryExpression( IASTScope scope ) - throws Backtrack + throws EndOfFileException, BacktrackException { IToken t = null; switch (LT(1)) @@ -4981,7 +5004,7 @@ public abstract class Parser implements IParser { duple = name(); } - catch( Backtrack bt ) + catch( BacktrackException bt ) { Declarator d = new Declarator( new DeclarationWrapper(scope, 0, null) ); @@ -5099,17 +5122,13 @@ public abstract class Parser implements IParser } // the static instance we always use - private static Backtrack backtrack = new Backtrack(); - // the static instance we always use - public static EndOfFile endOfFile = new EndOfFile(); - // Token management - + private static BacktrackException backtrack = new BacktrackException(); + + // Token management protected IScanner scanner; protected IToken currToken, // current token we plan to consume next lastToken; // last token we consumed - private int highWaterOffset = 0; - protected void setCurrentScope( IASTScope scope ) { } @@ -5118,20 +5137,18 @@ public abstract class Parser implements IParser * Fetches a token from the scanner. * * @return the next token from the scanner - * @throws EndOfFile thrown when the scanner.nextToken() yields no tokens + * @throws EndOfFileException thrown when the scanner.nextToken() yields no tokens */ - private IToken fetchToken() throws EndOfFile + protected IToken fetchToken() throws EndOfFileException { try { - IToken t = scanner.nextToken(); - if( t.getEndOffset() > highWaterOffset ) - highWaterOffset = t.getEndOffset(); - return t; + return scanner.nextToken(); } - catch (EndOfFile e) + catch( OffsetLimitReachedException olre ) { - throw e; + handleOffsetLimitException(olre); + return null; } catch (ScannerException e) { @@ -5141,14 +5158,19 @@ public abstract class Parser implements IParser return fetchToken(); } } - /** + + protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException { + // unexpected, throw EOF instead (equivalent) + throw new EndOfFileException(); + } + /** * Look Ahead in the token list to see what is coming. * * @param i How far ahead do you wish to peek? * @return the token you wish to observe - * @throws EndOfFile if looking ahead encounters EOF, throw EndOfFile + * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile */ - protected IToken LA(int i) throws EndOfFile + protected IToken LA(int i) throws EndOfFileException { if (i < 1) // can't go backwards return null; @@ -5168,9 +5190,9 @@ public abstract class Parser implements IParser * * @param i How far ahead do you wish to peek? * @return The type of that token - * @throws EndOfFile if looking ahead encounters EOF, throw EndOfFile + * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile */ - protected int LT(int i) throws EndOfFile + protected int LT(int i) throws EndOfFileException { return LA(i).getType(); } @@ -5178,9 +5200,9 @@ public abstract class Parser implements IParser * Consume the next token available, regardless of the type. * * @return The token that was consumed and removed from our buffer. - * @throws EndOfFile If there is no token to consume. + * @throws EndOfFileException If there is no token to consume. */ - protected IToken consume() throws EndOfFile + protected IToken consume() throws EndOfFileException { if (currToken == null) currToken = fetchToken(); @@ -5194,9 +5216,9 @@ public abstract class Parser implements IParser * * @param type The type of token that you are expecting. * @return the token that was consumed and removed from our buffer. - * @throws Backtrack If LT(1) != type + * @throws BacktrackException If LT(1) != type */ - protected IToken consume(int type) throws Backtrack + protected IToken consume(int type) throws EndOfFileException, BacktrackException { if (LT(1) == type) return consume(); @@ -5207,9 +5229,9 @@ public abstract class Parser implements IParser * Mark our place in the buffer so that we could return to it should we have to. * * @return The current token. - * @throws EndOfFile If there are no more tokens. + * @throws EndOfFileException If there are no more tokens. */ - protected IToken mark() throws EndOfFile + protected IToken mark() throws EndOfFileException { if (currToken == null) currToken = fetchToken(); @@ -5254,5 +5276,10 @@ public abstract class Parser implements IParser protected void setCompletionKind( IASTCompletionNode.CompletionKind kind ) { - } + } + + protected void setCompletionKeywords( Collection keywords ) + { + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java index 356988d0e98..43c78edf831 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Preprocessor.java @@ -12,11 +12,12 @@ package org.eclipse.cdt.internal.core.parser; import java.io.Reader; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IPreprocessor; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerException; @@ -49,7 +50,12 @@ public class Preprocessor extends Scanner implements IPreprocessor { // callback IProblem here log.errorLog("Preprocessor Exception "+ se.getProblem().getMessage()); //$NON-NLS-1$h } - catch( EndOfFile eof ) + catch( OffsetLimitReachedException olre ) + { + // callback IProblem here + log.errorLog("Preprocessor Exception "+ olre.getMessage()); //$NON-NLS-1$h + } + catch( EndOfFileException eof ) { // expected } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java index 571ac18a988..a5c05a5d58d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java @@ -1,13 +1,17 @@ -/* - * Created on Dec 5, 2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ +/********************************************************************** + * 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; -import org.eclipse.cdt.core.parser.Backtrack; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.ISourceElementRequestor; @@ -21,9 +25,6 @@ import org.eclipse.cdt.core.parser.ast.IASTScope; /** * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class QuickParser extends Parser { @@ -40,12 +41,12 @@ public class QuickParser extends Parser { scanner.setASTFactory(astFactory); } - protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile + protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws BacktrackException, EndOfFileException { skipOverCompoundStatement(); } - protected void catchBlockCompoundStatement(IASTScope scope) throws Backtrack, EndOfFile + protected void catchBlockCompoundStatement(IASTScope scope) throws BacktrackException, EndOfFileException { skipOverCompoundStatement(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java index 18bce47a102..e0876f31984 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java @@ -26,8 +26,8 @@ import java.util.Map; import java.util.StringTokenizer; import java.util.Vector; -import org.eclipse.cdt.core.parser.Backtrack; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.ILineOffsetReconciler; import org.eclipse.cdt.core.parser.IMacroDescriptor; import org.eclipse.cdt.core.parser.IParser; @@ -38,6 +38,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.NullSourceElementRequestor; +import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactoryException; import org.eclipse.cdt.core.parser.ParserLanguage; @@ -64,6 +65,7 @@ public class Scanner implements IScanner { private boolean initialContextInitialized = false; private final String filename; private final Reader reader; + protected IToken finalToken; protected void handleProblem( int problemID, String argument, int beginningOffset, boolean warning, boolean error ) throws ScannerException { @@ -128,7 +130,7 @@ public class Scanner implements IScanner { contextStack.push( context, requestor ); } catch( ContextException ce ) { - // should never occur + handleInternalError(); } initialContextInitialized = true; } @@ -179,7 +181,7 @@ public class Scanner implements IScanner { while ((c != NOCHAR) && ((c == ' ') || (c == '\t'))) { c = getChar(); - result = true; + result = true; } if (c != NOCHAR) ungetChar(c); @@ -284,9 +286,10 @@ public class Scanner implements IScanner { private void setCurrentToken(IToken t) { if (currentToken != null) currentToken.setNext(t); + finalToken = t; currentToken = t; } - + protected void resetStorageBuffer() { if( storageBuffer != null ) @@ -691,15 +694,15 @@ public class Scanner implements IScanner { getChar(); } - public IToken nextToken() throws ScannerException, EndOfFile { + public IToken nextToken() throws ScannerException, EndOfFileException, OffsetLimitReachedException { return nextToken( true, false ); } - public IToken nextToken(boolean pasting) throws ScannerException, EndOfFile { + public IToken nextToken(boolean pasting) throws ScannerException, EndOfFileException, OffsetLimitReachedException { return nextToken( pasting, false ); } - public IToken nextToken( boolean pasting, boolean lookingForNextAlready ) throws ScannerException, EndOfFile + public IToken nextToken( boolean pasting, boolean lookingForNextAlready ) throws ScannerException, EndOfFileException, OffsetLimitReachedException { if( ! initialContextInitialized ) setupInitialContext(); @@ -793,7 +796,7 @@ public class Scanner implements IScanner { IToken next = null; try{ next = nextToken( true, true ); - } catch( EndOfFile e ){ + } catch( EndOfFileException e ){ next = null; } @@ -804,7 +807,7 @@ public class Scanner implements IScanner { currentToken = returnToken; try{ next = nextToken( true, true ); - } catch( EndOfFile e ){ + } catch( EndOfFileException e ){ next = null; } } @@ -1598,11 +1601,11 @@ public class Scanner implements IScanner { } default : handleProblem( IProblem.SCANNER_BAD_CHARACTER, new Character( (char)c ).toString(), getCurrentOffset(), false, true, throwExceptionOnBadCharacterRead ); - c = ' '; + c = getChar(); continue; } - throw Parser.endOfFile; + throwEOF(); } } @@ -1613,7 +1616,8 @@ public class Scanner implements IScanner { } // we're done - throw Parser.endOfFile; + throwEOF(); + return null; } @@ -1683,7 +1687,7 @@ public class Scanner implements IScanner { // the static instance we always use protected static endOfMacroTokenException endOfMacroToken = new endOfMacroTokenException(); - public IToken nextTokenForStringizing() throws ScannerException, EndOfFile + public IToken nextTokenForStringizing() throws ScannerException, EndOfFileException, OffsetLimitReachedException { int beginOffset = getCurrentOffset(); int c = getChar(); @@ -1771,10 +1775,24 @@ public class Scanner implements IScanner { } // we're done - throw Parser.endOfFile; + throwEOF(); + return null; } + /** + * + */ + protected void throwEOF() throws EndOfFileException, OffsetLimitReachedException { + if( offsetLimit == NO_OFFSET_LIMIT ) + throw new EndOfFileException(); + + if( finalToken.getEndOffset() == offsetLimit ) + throw new OffsetLimitReachedException(finalToken); + throw new OffsetLimitReachedException( null ); + } + + static { cppKeywords.put("and", new Integer(IToken.t_and)); cppKeywords.put("and_eq", new Integer(IToken.t_and_eq)); @@ -1956,20 +1974,21 @@ public class Scanner implements IScanner { parser = ParserFactory.createParser(trial, nullCallback, ParserMode.QUICK_PARSE, language, log ); } catch( ParserFactoryException pfe ) { - // TODO - make INTERNAL IProblem - // should never happen + handleInternalError(); } try { IASTExpression exp = parser.expression(null); if( exp.evaluateExpression() == 0 ) return false; return true; - } catch( Backtrack backtrack ) + } catch( BacktrackException backtrack ) { handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true, true ); } catch (ExpressionEvaluationException e) { handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true, true ); + } catch (EndOfFileException e) { + handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true, true ); } return true; } @@ -2058,10 +2077,13 @@ public class Scanner implements IScanner { try { t = helperScanner.nextToken(false); - } catch (EndOfFile eof) { + } catch (OffsetLimitReachedException e) { handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#include " + includeLine, beginningOffset, false, true, true ); return; - } + } catch (EndOfFileException eof) { + handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#include " + includeLine, beginningOffset, false, true, true ); + return; + } try { if (t.getType() == IToken.tSTRING) { @@ -2091,7 +2113,7 @@ public class Scanner implements IScanner { endOffset = baseOffset + t.getEndOffset(); - } catch (EndOfFile eof) { + } catch (EndOfFileException eof) { handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#include " + includeLine, beginningOffset, false, true, true ); return; } @@ -2105,10 +2127,13 @@ public class Scanner implements IScanner { } else handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#include " + includeLine, beginningOffset, false, true, true ); } - catch( EndOfFile eof ) + catch (OffsetLimitReachedException e) { + handleInternalError(); + } + catch( EndOfFileException eof ) { // good - } + } } else handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#include " + includeLine, beginningOffset, false, true, true ); @@ -2172,7 +2197,7 @@ public class Scanner implements IScanner { forInclusion = b; } - protected void poundDefine(int beginning) throws ScannerException, EndOfFile { + protected void poundDefine(int beginning) throws ScannerException, EndOfFileException { skipOverWhitespace(); // definition String key = getNextIdentifier(); @@ -2245,8 +2270,12 @@ public class Scanner implements IScanner { } catch (ParserFactoryException e1) { } helperScanner.setTokenizingMacroReplacementList( true ); - IToken t = helperScanner.nextToken(false); - + IToken t = null; + try { + t = helperScanner.nextToken(false); + } catch (OffsetLimitReachedException e2) { + handleInternalError(); + } try { while (true) { //each # preprocessing token in the replacement list shall be followed @@ -2268,7 +2297,11 @@ public class Scanner implements IScanner { t = helperScanner.nextToken(false); } } - catch( EndOfFile eof ) + catch( OffsetLimitReachedException olre ) + { + handleInternalError(); + } + catch( EndOfFileException eof ) { // good } @@ -2363,7 +2396,6 @@ public class Scanner implements IScanner { } else if( newDefinition instanceof String ) { - if( previousDefinition instanceof String ) { Scanner previous = new Scanner( new StringReader( (String)previousDefinition ), "redef-test", new ScannerInfo(), new NullSourceElementRequestor(), @@ -2383,7 +2415,11 @@ public class Scanner implements IScanner { break; } - catch( EndOfFile eof ) + catch( OffsetLimitReachedException olre ) + { + handleInternalError(); + } + catch( EndOfFileException eof ) { if( ( p != null ) && ( c == null ) ) break; @@ -2394,12 +2430,16 @@ public class Scanner implements IScanner { c = current.nextToken(); break; } - catch( EndOfFile eof2 ) + catch( OffsetLimitReachedException olre ) + { + handleInternalError(); + } + catch( EndOfFileException eof2 ) { return; } } - } + } } } } @@ -2408,7 +2448,15 @@ public class Scanner implements IScanner { } } - protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException { + /** + * + */ + protected void handleInternalError() { + // TODO Auto-generated method stub + + } + + 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); tokenizer.setThrowExceptionOnBadCharacterRead(false); @@ -2449,10 +2497,16 @@ public class Scanner implements IScanner { } space = true; } - } catch (EndOfFile e) { + } + catch( OffsetLimitReachedException olre ) + { + handleInternalError(); + } + catch (EndOfFileException e) { // Good parameterValues.add(str); } + return parameterValues; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParser.java index 332adc07fb4..06c3b24c322 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParser.java @@ -1,13 +1,17 @@ -/* - * Created on Dec 8, 2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ +/********************************************************************** + * 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; -import org.eclipse.cdt.core.parser.Backtrack; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IScanner; @@ -22,9 +26,6 @@ import org.eclipse.cdt.core.parser.ast.IASTScope; /** * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class StructuralParser extends Parser implements IParser { @@ -46,7 +47,7 @@ public class StructuralParser extends Parser implements IParser { protected void handleFunctionBody( IASTScope scope, boolean isInlineFunction) - throws Backtrack, EndOfFile { + throws BacktrackException, EndOfFileException { skipOverCompoundStatement(); } @@ -54,7 +55,7 @@ public class StructuralParser extends Parser implements IParser { * @see org.eclipse.cdt.internal.core.parser.Parser#catchBlockCompoundStatement(org.eclipse.cdt.core.parser.ast.IASTScope) */ protected void catchBlockCompoundStatement(IASTScope scope) - throws Backtrack, EndOfFile { + throws BacktrackException, EndOfFileException { skipOverCompoundStatement(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTCompletionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTCompletionNode.java new file mode 100644 index 00000000000..6dfa5dac3dd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTCompletionNode.java @@ -0,0 +1,77 @@ +/********************************************************************** + * 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.ast; + +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; +import org.eclipse.cdt.core.parser.ast.IASTNode; +import org.eclipse.cdt.core.parser.ast.IASTScope; + +/** + * @author jcamelon + */ +public class ASTCompletionNode implements IASTCompletionNode { + + private final String prefix; + private final IASTNode context; + private final IASTScope scope; + private final CompletionKind kind; + private final Set keywordSet; + + public ASTCompletionNode( CompletionKind kind, IASTScope scope, IASTNode context, String prefix, Set keywords ) + { + this.kind = kind; + this.context = context; + this.scope = scope; + this.prefix = prefix; + this.keywordSet = keywords; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionKind() + */ + public CompletionKind getCompletionKind() { + return kind; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionScope() + */ + public IASTScope getCompletionScope() { + return scope; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionContext() + */ + public IASTNode getCompletionContext() { + return context; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionPrefix() + */ + public String getCompletionPrefix() { + return prefix; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getKeywords() + */ + public Iterator getKeywords() { + if( keywordSet == null ) + return new EmptyIterator(); + return keywordSet.iterator(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java index 6be2575ea3a..658266dc46c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java @@ -32,7 +32,9 @@ public abstract class ASTSymbol extends ASTSymbolOwner implements ISymbolOwner, */ public IASTScope getOwnerScope() { - return (IASTScope)symbol.getContainingSymbol().getASTExtension().getPrimaryDeclaration(); + if( symbol.getContainingSymbol() != null ) + return (IASTScope)symbol.getContainingSymbol().getASTExtension().getPrimaryDeclaration(); + return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTCompilationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTCompilationUnit.java index 89f14a8137d..4840d2477fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTCompilationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTCompilationUnit.java @@ -17,8 +17,6 @@ import java.util.List; import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java index dda4a92f78a..e8608659d26 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java @@ -18,9 +18,6 @@ import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; /** * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class TypeFilter { diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java index a65b2ffc7e3..566862dd221 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java @@ -18,13 +18,14 @@ import java.io.StringReader; import java.util.Iterator; import java.util.LinkedList; -import org.eclipse.cdt.core.parser.EndOfFile; +import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IQuickParseCallback; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.NullSourceElementRequestor; +import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactoryException; import org.eclipse.cdt.core.parser.ParserLanguage; @@ -362,7 +363,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte try { token = scanner.nextToken(); - } catch (EndOfFile e) { + } catch (EndOfFileException e) { } catch (ScannerException e) { } @@ -581,7 +582,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte } } } - } catch (EndOfFile e) { + } catch (EndOfFileException e) { list.addLast( name.toCharArray() ); } catch (ScannerException e) { } diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index c6ab4001172..2cf102c1e19 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,6 @@ +2003-12-11 John Camelon + Updated CompletionEngine to deal with new signatures/exceptions in parser. + 2002-12-11 David Inglis Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=48596 diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java index 3ade7428144..355ad05bd99 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java @@ -43,6 +43,7 @@ import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.core.parser.ast.IASTNode.LookupException; import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult; import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.model.IWorkingCopy; @@ -176,8 +177,6 @@ public class CompletionEngine implements RelevanceConstants{ try { result = parser.parse(completionOffset); } catch (ParserNotImplementedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } return result; } else { @@ -275,8 +274,6 @@ public class CompletionEngine implements RelevanceConstants{ IASTNode node = (IASTNode) nodes.next(); addNodeToCompletions(node, result.getPrefix()); } - Iterator keywords = result.getKeywords(); - addKeywordsToCompletions(keywords); return ; } @@ -297,15 +294,38 @@ public class CompletionEngine implements RelevanceConstants{ // Completing after a dot // 1. Get the search scope node IASTNode searchNode = completionNode.getCompletionScope(); + + LookupResult result = null; // 2. lookup fields & add to completion proposals - LookupResult result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.FIELDS); - addToCompletions (result); - // 3. looup methods & add to completion proposals - result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS); - addToCompletions (result); - // 4. lookup nested structures & add to completion proposals - result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.STRUCTURES); - addToCompletions (result); + try + { + result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.FIELDS); + addToCompletions (result); + } + catch( IASTNode.LookupException ilk ) + { + + } + + try + { + // 3. looup methods & add to completion proposals + result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS); + addToCompletions (result); + } + catch( IASTNode.LookupException ilk ) + { + + } + + + try { + // 4. lookup nested structures & add to completion proposals + result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.STRUCTURES); + addToCompletions (result); + } catch (LookupException e) { + } + } private void completionOnTypeReference(IASTCompletionNode completionNode){ // completing on a type @@ -314,8 +334,13 @@ public class CompletionEngine implements RelevanceConstants{ // if the prefix is not empty if(completionNode.getCompletionPrefix().length() > 0 ) { // 2. Lookup all types that could be used here - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.STRUCTURES); - addToCompletions(result); + LookupResult result; + try { + result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.STRUCTURES); + addToCompletions(result); + } catch (LookupException e) { + } + // 3. Lookup keywords // basic types should be in the keyword list List keywords = lookupKeyword(completionNode.getCompletionPrefix(), BASIC_TYPES_KEYWORDS); @@ -334,8 +359,15 @@ public class CompletionEngine implements RelevanceConstants{ // 3. lookup methods // we are at a field declaration place, the user could be trying to override a function. // We have to lookup functions that could be overridden here. - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS); - addToCompletions(result); + LookupResult result; + try { + result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS); + addToCompletions(result); + } catch (LookupException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } private void completionOnVariableType(IASTCompletionNode completionNode){ // 1. basic completion on all types @@ -349,13 +381,28 @@ public class CompletionEngine implements RelevanceConstants{ if (completionNode.getCompletionPrefix().length() > 0){ // here we have to look for anything that could be referenced within this scope // 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.ALL); - addToCompletions(result); + try + { + LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.ALL); + addToCompletions(result); + } + catch( LookupException ilk ) + { + + } } else // prefix is empty { - // 1. look only for local variables - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.LOCAL_VARIABLES); - addToCompletions(result); + // 1. look only for local variables + try + { + LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.LOCAL_VARIABLES); + addToCompletions(result); + } + catch( LookupException ilk ) + { + + } + // 2. and what can be accessed through the "this" pointer // TODO : complete the lookup call } @@ -366,23 +413,42 @@ public class CompletionEngine implements RelevanceConstants{ IASTNode searchNode = completionNode.getCompletionScope(); // here we have to look for anything that could be referenced within this scope // 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.ALL); - addToCompletions(result); + try + { + LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.ALL); + addToCompletions(result); + } + catch( LookupException ilk ) + { + + } } private void completionOnClassReference(IASTCompletionNode completionNode){ // 1. Get the search scope node IASTNode searchNode = completionNode.getCompletionScope(); // only look for classes - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.CLASSES); - addToCompletions(result); + try + { + LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.CLASSES); + addToCompletions(result); + } + catch( LookupException ilk ) + { + } } private void completionOnNamespaceReference(IASTCompletionNode completionNode){ // 1. Get the search scope node IASTNode searchNode = completionNode.getCompletionScope(); // only look for classes - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.NAMESPACES); - addToCompletions(result); + try + { + LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.NAMESPACES); + addToCompletions(result); + } + catch( LookupException ilk ) + { + } } private void completionOnExceptionReference(IASTCompletionNode completionNode){ // here we have to look for all types @@ -396,8 +462,14 @@ public class CompletionEngine implements RelevanceConstants{ // 1. Get the search scope node IASTNode searchNode = completionNode.getCompletionScope(); // only look for macros - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.MACROS); - addToCompletions(result); + try + { + LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.MACROS); + addToCompletions(result); + } + catch( LookupException ilk ) + { + } } private void completionOnFunctionReference(IASTCompletionNode completionNode){ // TODO: complete the lookups @@ -406,7 +478,14 @@ public class CompletionEngine implements RelevanceConstants{ // 1. Get the search scope node IASTNode searchNode = completionNode.getCompletionScope(); // only lookup constructors - LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.CONSTRUCTORS); + try + { + LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.CONSTRUCTORS); + } + catch( LookupException ilk ) + { + } + } private void completionOnKeyword(IASTCompletionNode completionNode){ // lookup every type of keywords @@ -485,6 +564,7 @@ public class CompletionEngine implements RelevanceConstants{ completionOnKeyword(completionNode); } + addKeywordsToCompletions( completionNode.getKeywords()); completionList.addAll(completions); return completionNode;