From 007714a3941370ecdf5c0dd873f4e0bcc64a50e8 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Tue, 30 Sep 2003 20:42:24 +0000 Subject: [PATCH] CORE Fixed Bug 43503 : Search:f_SD_01 cannot be found in ManyClasses20 Project Fixed Bug 43680 : Fix Parser Error Handling TESTS Updated CompleteParseASTTest::testBug42872() Moved FailedCompleteParseASTTest::testBug43503() to CompleteParseASTTest::testBug43503A(). --- core/org.eclipse.cdt.core.tests/ChangeLog | 4 + .../FailedCompleteParseASTTest.java | 16 - .../parser/tests/CompleteParseASTTest.java | 13 + core/org.eclipse.cdt.core/parser/ChangeLog | 4 + .../cdt/core/parser/ast/IASTFactory.java | 74 +-- .../core/parser/DeclarationWrapper.java | 302 ++++++--- .../cdt/internal/core/parser/Parser.java | 603 +++++++++++++----- .../cdt/internal/core/parser/Scanner.java | 53 +- .../ast/complete/CompleteParseASTFactory.java | 35 +- 9 files changed, 755 insertions(+), 349 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index fdcb838fed1..46fa59ce03d 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-09-30 John Camelon + Updated CompleteParseASTTest::testBug42872() + Moved FailedCompleteParseASTTest::testBug43503() to CompleteParseASTTest::testBug43503A(). + 2003-09-30 Andrew Niefer added testBug43503_AmbiguousUsing() and testBug43503_UnableToResolveFunction() to ParserSymbolTableTest diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java index f2d5a88296c..0a955b61aec 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java @@ -114,20 +114,4 @@ public class FailedCompleteParseASTTest extends CompleteParseBaseTest assertFalse( i.hasNext() ); assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2))); } - - public void testBug43503 () throws Exception { - Iterator i = parse("class SD_01 { f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } ").getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTMethod f = (IASTMethod)j.next(); - assertFalse(j.hasNext()); - IASTFunction main = (IASTFunction) i.next(); - assertFalse(i.hasNext()); - Iterator k = getDeclarations(main); - - assertFalse(k.hasNext()); // this should be true, there is one declaration of "a" - // "a" is found to be in a multiplication expression, not a declaration - // not knowing "a" causes us to not find the reference to "f" - - } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 209985b0917..f29b1c01918 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -745,9 +745,22 @@ public class CompleteParseASTTest extends CompleteParseBaseTest IASTClassSpecifier structB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); IASTClassSpecifier structD = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); IASTFunction foo = (IASTFunction)i.next(); + IASTVariable bp = (IASTVariable)getDeclarations(foo).next(); assertFalse( i.hasNext() ); } + public void testBug43503A() throws Exception { + Iterator i = parse("class SD_01 { f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } ").getDeclarations(); + IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + Iterator j = getDeclarations(classA); + IASTMethod f = (IASTMethod)j.next(); + assertFalse(j.hasNext()); + IASTFunction main = (IASTFunction) i.next(); + assertFalse(i.hasNext()); + Iterator k = getDeclarations(main); + assertTrue(k.hasNext()); + } + public void testBug42979() throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 683ab7f81a0..6a9b7e42108 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,7 @@ +2003-09-30 John Camelon + Fixed Bug 43503 : Search:f_SD_01 cannot be found in ManyClasses20 Project + Fixed Bug 43680 : Fix Parser Error Handling + 2003-09-30 Hoda Amer -Solution to [Bug 43053] require reference cleanup for expressions Added purgeReferences() at the end of ASTExpression::acceptElement() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java index c74e02afe29..b2149ec60c0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java @@ -24,32 +24,32 @@ public interface IASTFactory String name, int startingOffset, int nameOffset, - int nameEndOffset, int endingOffset); + int nameEndOffset, int endingOffset) throws Exception; public IASTInclusion createInclusion( String name, String fileName, boolean local, int startingOffset, int nameOffset, - int nameEndOffset, int endingOffset); + int nameEndOffset, int endingOffset) throws Exception; public IASTUsingDirective createUsingDirective( IASTScope scope, ITokenDuple duple, int startingOffset, int endingOffset) - throws ASTSemanticException; + throws ASTSemanticException, Exception; public IASTUsingDeclaration createUsingDeclaration( IASTScope scope, boolean isTypeName, - ITokenDuple name, int startingOffset, int endingOffset) throws ASTSemanticException; + ITokenDuple name, int startingOffset, int endingOffset) throws ASTSemanticException, Exception; public IASTASMDefinition createASMDefinition( IASTScope scope, String assembly, int first, - int last); + int last)throws Exception; public IASTNamespaceDefinition createNamespaceDefinition( IASTScope scope, String identifier, int startingOffset, - int nameOffset, int nameEndOffset) throws ASTSemanticException; + int nameOffset, int nameEndOffset) throws ASTSemanticException, Exception; public IASTNamespaceAlias createNamespaceAlias( IASTScope scope, @@ -57,12 +57,12 @@ public interface IASTFactory ITokenDuple alias, int startingOffset, int nameOffset, - int nameEndOffset, int endOffset ) throws ASTSemanticException; + int nameEndOffset, int endOffset ) throws ASTSemanticException, Exception; - public IASTCompilationUnit createCompilationUnit(); + public IASTCompilationUnit createCompilationUnit() throws Exception; public IASTLinkageSpecification createLinkageSpecification( IASTScope scope, - String spec, int startingOffset); + String spec, int startingOffset) throws Exception; public IASTClassSpecifier createClassSpecifier( IASTScope scope, ITokenDuple name, @@ -70,7 +70,7 @@ public interface IASTFactory ClassNameType type, ASTAccessVisibility access, int startingOffset, - int nameOffset, int nameEndOffset) throws ASTSemanticException; + int nameOffset, int nameEndOffset) throws ASTSemanticException, Exception; /** * @param astClassSpec * @param isVirtual @@ -81,21 +81,21 @@ public interface IASTFactory IASTClassSpecifier astClassSpec, boolean isVirtual, ASTAccessVisibility visibility, - ITokenDuple parentClassName) throws ASTSemanticException; + ITokenDuple parentClassName) throws ASTSemanticException, Exception; public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier( IASTScope scope, ASTClassKind elaboratedClassKind, ITokenDuple typeName, - int startingOffset, int endOffset, boolean isForewardDecl) throws ASTSemanticException; + int startingOffset, int endOffset, boolean isForewardDecl) throws ASTSemanticException, Exception; public IASTEnumerationSpecifier createEnumerationSpecifier( IASTScope scope, String name, - int startingOffset, int nameOffset, int nameEndOffset) throws ASTSemanticException; + int startingOffset, int nameOffset, int nameEndOffset) throws ASTSemanticException, Exception; public void addEnumerator( IASTEnumerationSpecifier enumeration, String string, int startingOffset, - int nameOffset, int nameEndOffset, int endingOffset, IASTExpression initialValue)throws ASTSemanticException; + int nameOffset, int nameEndOffset, int endingOffset, IASTExpression initialValue)throws ASTSemanticException, Exception; public IASTExpression createExpression( IASTScope scope, IASTExpression.Kind kind, @@ -103,17 +103,17 @@ public interface IASTFactory IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, - ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException; - public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions); + ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException, Exception; + public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions)throws Exception; public IASTInitializerClause createInitializerClause( IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, - List initializerClauses); - public IASTExceptionSpecification createExceptionSpecification(IASTScope scope, List typeIds) throws ASTSemanticException; + List initializerClauses) throws Exception; + public IASTExceptionSpecification createExceptionSpecification(IASTScope scope, List typeIds) throws ASTSemanticException, Exception; /** * @param exp */ - public IASTArrayModifier createArrayModifier(IASTExpression exp); + public IASTArrayModifier createArrayModifier(IASTExpression exp) throws Exception; /** * @param duple * @param expressionList @@ -121,7 +121,7 @@ public interface IASTFactory */ public IASTConstructorMemberInitializer createConstructorMemberInitializer( IASTScope scope, - ITokenDuple duple, IASTExpression expressionList) throws ASTSemanticException; + ITokenDuple duple, IASTExpression expressionList) throws ASTSemanticException, Exception; public IASTSimpleTypeSpecifier createSimpleTypeSpecifier( IASTScope scope, IASTSimpleTypeSpecifier.Type kind, @@ -129,7 +129,7 @@ public interface IASTFactory boolean isShort, boolean isLong, boolean isSigned, - boolean isUnsigned, boolean isTypename) throws ASTSemanticException; + boolean isUnsigned, boolean isTypename) throws ASTSemanticException, Exception; public IASTFunction createFunction( IASTScope scope, String name, @@ -147,12 +147,12 @@ public interface IASTFactory boolean isVolatile, boolean isVirtual, boolean isExplicit, - boolean isPureVirtual, List constructorChain, boolean isDefinition ) throws ASTSemanticException; + boolean isPureVirtual, List constructorChain, boolean isDefinition ) throws ASTSemanticException, Exception; public IASTAbstractDeclaration createAbstractDeclaration( boolean isConst, boolean isVolatile, IASTTypeSpecifier typeSpecifier, - List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOperator); + List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOperator)throws Exception; public IASTMethod createMethod( IASTScope scope, String name, @@ -170,28 +170,28 @@ public interface IASTFactory boolean isVolatile, boolean isVirtual, boolean isExplicit, - boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition) throws ASTSemanticException; + boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition) throws ASTSemanticException, Exception; public IASTVariable createVariable(IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, - IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression ) throws ASTSemanticException; + IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression ) throws ASTSemanticException, Exception; - public IASTField createField( IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException; + public IASTField createField( IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException, Exception; - public IASTParameterDeclaration createParameterDeclaration( boolean isConst, boolean isVolatile, IASTTypeSpecifier getTypeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, String parameterName, IASTInitializerClause initializerClause, int startingOffset, int nameOffset, int nameEndOffset, int endingOffset ); + public IASTParameterDeclaration createParameterDeclaration( boolean isConst, boolean isVolatile, IASTTypeSpecifier getTypeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, String parameterName, IASTInitializerClause initializerClause, int startingOffset, int nameOffset, int nameEndOffset, int endingOffset ) throws Exception; - public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset ); + public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset ) throws Exception; - public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ); + public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ) throws Exception; - public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset); + public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset)throws Exception; - public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset); + public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset)throws Exception; - public IASTTypedefDeclaration createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset, int nameEndOffset ) throws ASTSemanticException; + public IASTTypedefDeclaration createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset, int nameEndOffset ) throws ASTSemanticException, Exception; - public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset); + public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset)throws Exception; - public boolean queryIsTypeName( IASTScope scope, ITokenDuple nameInQuestion ); + public boolean queryIsTypeName( IASTScope scope, ITokenDuple nameInQuestion ) throws Exception; static final String DOUBLE_COLON = "::"; static final String TELTA = "~"; @@ -199,14 +199,14 @@ public interface IASTFactory * @param scope * @return */ - public IASTCodeScope createNewCodeBlock(IASTScope scope); + public IASTCodeScope createNewCodeBlock(IASTScope scope)throws Exception; public IASTTypeId createTypeId( IASTScope scope, IASTSimpleTypeSpecifier.Type kind, boolean isConst, boolean isVolatile, boolean isShort, - boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods ) throws ASTSemanticException; + boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods ) throws ASTSemanticException, Exception; /** * @param astClassSpecifier */ - public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier); + public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier) throws Exception; } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java index 4e3cea1141e..8fb09a1becd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java @@ -373,17 +373,49 @@ public class DeclarationWrapper implements IDeclaratorOwner } List convertedParms = createParameterList( declarator.getParameters() ); - IASTAbstractDeclaration abs = astFactory.createAbstractDeclaration( - constt, volatil, getTypeSpecifier(), declarator.getPointerOperators(), declarator.getArrayModifiers(), - convertedParms, (ASTPointerOperator)i.next() ); + IASTAbstractDeclaration abs = null; + try + { + abs = + astFactory.createAbstractDeclaration( + constt, + volatil, + getTypeSpecifier(), + declarator.getPointerOperators(), + declarator.getArrayModifiers(), + convertedParms, + (ASTPointerOperator)i.next()); + } + catch (Exception e) + { + throw new ASTSemanticException(); + } String name = ( d.getPointerOperatorNameDuple() != null ) ? d.getPointerOperatorNameDuple().toString() + d.getName() : d.getName(); if( typedef ) - return astFactory.createTypedef( - scope, - name, - abs, getStartingOffset(), d.getNameStartOffset(), d.getNameEndOffset() ); + try + { + return astFactory.createTypedef( + scope, + name, + abs, getStartingOffset(), d.getNameStartOffset(), d.getNameEndOffset() ); + } + catch (ASTSemanticException e1) + { + throw e1; + } + catch (Exception e1) + { + throw new ASTSemanticException(); + } else - return astFactory.createVariable( scope, name, auto, d.getInitializerClause(), d.getBitFieldExpression(), abs, mutable, extern, register, staticc, getStartingOffset(), d.getNameStartOffset(), d.getNameEndOffset(), d.getConstructorExpression() ); + try + { + return astFactory.createVariable( scope, name, auto, d.getInitializerClause(), d.getBitFieldExpression(), abs, mutable, extern, register, staticc, getStartingOffset(), d.getNameStartOffset(), d.getNameEndOffset(), d.getConstructorExpression() ); + } + catch (Exception e2) + { + throw new ASTSemanticException(); + } } else @@ -399,14 +431,25 @@ public class DeclarationWrapper implements IDeclaratorOwner */ private IASTTypedefDeclaration createTypedef(Declarator declarator, boolean nested ) throws ASTSemanticException { - return astFactory.createTypedef( - scope, - nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), - astFactory.createAbstractDeclaration( - constt, - volatil, - getTypeSpecifier(), - declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), startingOffset, declarator.getNameStartOffset(), declarator.getNameEndOffset()); + try + { + return astFactory.createTypedef( + scope, + nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), + astFactory.createAbstractDeclaration( + constt, + volatil, + getTypeSpecifier(), + declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), startingOffset, declarator.getNameStartOffset(), declarator.getNameEndOffset()); + } + catch (ASTSemanticException e) + { + throw e; + } + catch (Exception e) + { + throw new ASTSemanticException(); + } } /** * @param declarator @@ -414,14 +457,57 @@ public class DeclarationWrapper implements IDeclaratorOwner */ private IASTMethod createMethodASTNode(Declarator declarator, boolean nested) throws ASTSemanticException { - return astFactory - .createMethod( + try + { + return astFactory + .createMethod( + scope, + nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), + createParameterList(declarator.getParameters()), + astFactory.createAbstractDeclaration( + constt, + volatil, + getTypeSpecifier(), + declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), + declarator.getExceptionSpecification(), + inline, + friend, + staticc, + startingOffset, + declarator.getNameStartOffset(), + declarator.getNameEndOffset(), + templateDeclaration, + declarator.isConst(), + declarator.isVolatile(), + virtual, + explicit, + declarator.isPureVirtual(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode(), + declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody()); + } + catch (ASTSemanticException e) + { + throw e; + } + catch (Exception e) + { + throw new ASTSemanticException(); + } + } + /** + * @param declarator + * @return + */ + private IASTFunction createFunctionASTNode(Declarator declarator, boolean nested) throws ASTSemanticException + { + try + { + return astFactory.createFunction( scope, - nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), - createParameterList(declarator.getParameters()), + nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), + createParameterList(declarator.getParameters()), astFactory.createAbstractDeclaration( constt, - volatil, + volatil, getTypeSpecifier(), declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), declarator.getExceptionSpecification(), @@ -431,43 +517,22 @@ public class DeclarationWrapper implements IDeclaratorOwner startingOffset, declarator.getNameStartOffset(), declarator.getNameEndOffset(), - templateDeclaration, - declarator.isConst(), - declarator.isVolatile(), - virtual, - explicit, - declarator.isPureVirtual(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode(), - declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody()); - } - /** - * @param declarator - * @return - */ - private IASTFunction createFunctionASTNode(Declarator declarator, boolean nested) throws ASTSemanticException - { - return astFactory.createFunction( - scope, - nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), - createParameterList(declarator.getParameters()), - astFactory.createAbstractDeclaration( - constt, - volatil, - getTypeSpecifier(), - declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), - declarator.getExceptionSpecification(), - inline, - friend, - staticc, - startingOffset, - declarator.getNameStartOffset(), - declarator.getNameEndOffset(), - templateDeclaration, - declarator.isConst(), - declarator.isVolatile(), - virtual, - explicit, - declarator.isPureVirtual(), - declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody() ); + templateDeclaration, + declarator.isConst(), + declarator.isVolatile(), + virtual, + explicit, + declarator.isPureVirtual(), + declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody() ); + } + catch (ASTSemanticException e) + { + throw e; + } + catch (Exception e) + { + throw new ASTSemanticException(); + } } /** * @param declarator @@ -475,26 +540,37 @@ public class DeclarationWrapper implements IDeclaratorOwner */ private IASTField createFieldASTNode(Declarator declarator, boolean nested) throws ASTSemanticException { - return astFactory.createField( - scope, - nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), - auto, - declarator.getInitializerClause(), - declarator.getBitFieldExpression(), - astFactory.createAbstractDeclaration( - constt, - volatil, - getTypeSpecifier(), - declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), - mutable, - extern, - register, - staticc, - startingOffset, - declarator.getNameStartOffset(), - declarator.getNameEndOffset(), declarator.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode()); + try + { + return astFactory.createField( + scope, + nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), + auto, + declarator.getInitializerClause(), + declarator.getBitFieldExpression(), + astFactory.createAbstractDeclaration( + constt, + volatil, + getTypeSpecifier(), + declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), + mutable, + extern, + register, + staticc, + startingOffset, + declarator.getNameStartOffset(), + declarator.getNameEndOffset(), declarator.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode()); + } + catch (ASTSemanticException e) + { + throw e; + } + catch (Exception e) + { + throw new ASTSemanticException(); + } } - private List createParameterList(List currentParameters) + private List createParameterList(List currentParameters) throws ASTSemanticException { List result = new ArrayList(); Iterator i = currentParameters.iterator(); @@ -505,16 +581,23 @@ public class DeclarationWrapper implements IDeclaratorOwner while (j.hasNext()) { Declarator declarator = (Declarator)j.next(); - result.add( - astFactory.createParameterDeclaration( - wrapper.isConst(), - wrapper.isVolatile(), - wrapper.getTypeSpecifier(), - declarator.getPointerOperators(), - declarator.getArrayModifiers(), - null, null, declarator.getName() == null - ? "" - : declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), wrapper.getEndOffset())); + try + { + result.add( + astFactory.createParameterDeclaration( + wrapper.isConst(), + wrapper.isVolatile(), + wrapper.getTypeSpecifier(), + declarator.getPointerOperators(), + declarator.getArrayModifiers(), + null, null, declarator.getName() == null + ? "" + : declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), wrapper.getEndOffset())); + } + catch (Exception e) + { + throw new ASTSemanticException(); + } } } return result; @@ -525,23 +608,34 @@ public class DeclarationWrapper implements IDeclaratorOwner */ private IASTVariable createVariableASTNode(Declarator declarator, boolean nested ) throws ASTSemanticException { - return astFactory.createVariable( - scope, - nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), - isAuto(), - declarator.getInitializerClause(), - declarator.getBitFieldExpression(), - astFactory.createAbstractDeclaration( - constt, - volatil, - getTypeSpecifier(), - declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), - mutable, - extern, - register, - staticc, - getStartingOffset(), - declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getConstructorExpression()); + try + { + return astFactory.createVariable( + scope, + nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), + isAuto(), + declarator.getInitializerClause(), + declarator.getBitFieldExpression(), + astFactory.createAbstractDeclaration( + constt, + volatil, + getTypeSpecifier(), + declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), + mutable, + extern, + register, + staticc, + getStartingOffset(), + declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getConstructorExpression()); + } + catch (ASTSemanticException e) + { + throw e; + } + catch (Exception e) + { + throw new ASTSemanticException(); + } } /* (non-Javadoc) 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 80f545657b3..7f792e2b717 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 @@ -164,8 +164,15 @@ public class Parser implements IParser */ protected void translationUnit() { - IASTCompilationUnit compilationUnit = - astFactory.createCompilationUnit(); + IASTCompilationUnit compilationUnit; + try + { + compilationUnit = astFactory.createCompilationUnit(); + } + catch (Exception e2) + { + return; + } compilationUnit.enterScope( requestor ); IToken lastBacktrack = null; @@ -281,10 +288,9 @@ public class Parser implements IParser { astUD = astFactory.createUsingDirective(scope, duple, firstToken.getOffset(), last.getEndOffset()); } - catch (ASTSemanticException e) - { - failParse(); - throw backtrack; + catch (Exception e1) + { + throw backtrack; } astUD.acceptElement(requestor); return; @@ -326,10 +332,9 @@ public class Parser implements IParser firstToken.getOffset(), last.getEndOffset()); } - catch (ASTSemanticException e) + catch (Exception e1) { - failParse(); - throw backtrack; + throw backtrack; } declaration.acceptElement( requestor ); } @@ -360,8 +365,19 @@ public class Parser implements IParser if (LT(1) == IToken.tLBRACE) { consume(IToken.tLBRACE); - IASTLinkageSpecification linkage = - astFactory.createLinkageSpecification(scope, spec.getImage(), firstToken.getOffset()); + IASTLinkageSpecification linkage; + try + { + linkage = + astFactory.createLinkageSpecification( + scope, + spec.getImage(), + firstToken.getOffset()); + } + catch (Exception e) + { + throw backtrack; + } linkage.enterScope( requestor ); linkageDeclarationLoop : while (LT(1) != IToken.tRBRACE) @@ -394,8 +410,19 @@ public class Parser implements IParser } else // single declaration { - IASTLinkageSpecification linkage = - astFactory.createLinkageSpecification(scope, spec.getImage(), firstToken.getOffset()); + IASTLinkageSpecification linkage; + try + { + linkage = + astFactory.createLinkageSpecification( + scope, + spec.getImage(), + firstToken.getOffset()); + } + catch (Exception e) + { + throw backtrack; + } linkage.enterScope( requestor ); declaration(linkage, null); linkage.exitScope( requestor ); @@ -429,10 +456,18 @@ public class Parser implements IParser if (LT(1) != IToken.tLT) { // explicit-instantiation - IASTTemplateInstantiation templateInstantiation = - astFactory.createTemplateInstantiation( - scope, - firstToken.getOffset()); + IASTTemplateInstantiation templateInstantiation; + try + { + templateInstantiation = + astFactory.createTemplateInstantiation( + scope, + firstToken.getOffset()); + } + catch (Exception e) + { + throw backtrack; + } templateInstantiation.enterScope( requestor ); declaration(scope, templateInstantiation); templateInstantiation.setEndingOffset(lastToken.getEndOffset()); @@ -448,10 +483,18 @@ public class Parser implements IParser consume(IToken.tGT); // explicit-specialization - IASTTemplateSpecialization templateSpecialization = - astFactory.createTemplateSpecialization( - scope, - firstToken.getOffset()); + IASTTemplateSpecialization templateSpecialization; + try + { + templateSpecialization = + astFactory.createTemplateSpecialization( + scope, + firstToken.getOffset()); + } + catch (Exception e) + { + throw backtrack; + } templateSpecialization.enterScope(requestor); declaration(scope, templateSpecialization); templateSpecialization.setEndingOffset( @@ -465,7 +508,20 @@ public class Parser implements IParser { List parms = templateParameterList(scope); consume(IToken.tGT); - IASTTemplateDeclaration templateDecl = astFactory.createTemplateDeclaration( scope, parms, exported, firstToken.getOffset() ); + IASTTemplateDeclaration templateDecl; + try + { + templateDecl = + astFactory.createTemplateDeclaration( + scope, + parms, + exported, + firstToken.getOffset()); + } + catch (Exception e) + { + throw backtrack; + } templateDecl.enterScope( requestor ); declaration(scope, templateDecl ); templateDecl.setEndingOffset( @@ -541,13 +597,20 @@ public class Parser implements IParser { throw bt; } - returnValue.add( - astFactory.createTemplateParameter( - kind, - ( id == null )? "" : id.getImage(), - (typeId == null) ? null : typeId.getTypeOrClassName(), - null, - null)); + try + { + returnValue.add( + astFactory.createTemplateParameter( + kind, + ( id == null )? "" : id.getImage(), + (typeId == null) ? null : typeId.getTypeOrClassName(), + null, + null)); + } + catch (Exception e) + { + throw backtrack; + } } else if (LT(1) == IToken.t_template) @@ -572,13 +635,20 @@ public class Parser implements IParser } } - returnValue.add( - astFactory.createTemplateParameter( - IASTTemplateParameter.ParamKind.TEMPLATE_LIST, - ( optionalId == null )? "" : optionalId.getImage(), - ( optionalTypeId == null ) ? "" : optionalTypeId.toString(), - null, - subResult)); + try + { + returnValue.add( + astFactory.createTemplateParameter( + IASTTemplateParameter.ParamKind.TEMPLATE_LIST, + ( optionalId == null )? "" : optionalId.getImage(), + ( optionalTypeId == null ) ? "" : optionalTypeId.toString(), + null, + subResult)); + } + catch (Exception e) + { + throw backtrack; + } } else if (LT(1) == IToken.tCOMMA) { @@ -593,21 +663,28 @@ public class Parser implements IParser (DeclarationWrapper)c.getParameters().get(0); Declarator declarator = (Declarator)wrapper.getDeclarators().next(); - returnValue.add( - astFactory.createTemplateParameter( - IASTTemplateParameter.ParamKind.PARAMETER, - null, - null, - astFactory.createParameterDeclaration( - wrapper.isConst(), - wrapper.isVolatile(), - wrapper.getTypeSpecifier(), - declarator.getPointerOperators(), - declarator.getArrayModifiers(), - null, null, declarator.getName() == null - ? "" - : declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), wrapper.getEndOffset()), - null)); + try + { + returnValue.add( + astFactory.createTemplateParameter( + IASTTemplateParameter.ParamKind.PARAMETER, + null, + null, + astFactory.createParameterDeclaration( + wrapper.isConst(), + wrapper.isVolatile(), + wrapper.getTypeSpecifier(), + declarator.getPointerOperators(), + declarator.getArrayModifiers(), + null, null, declarator.getName() == null + ? "" + : declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), wrapper.getEndOffset()), + null)); + } + catch (Exception e) + { + throw backtrack; + } } } } @@ -647,12 +724,20 @@ public class Parser implements IParser String assembly = consume(IToken.tSTRING).getImage(); consume(IToken.tRPAREN); IToken last = consume(IToken.tSEMI); - IASTASMDefinition asmDefinition = - astFactory.createASMDefinition( - scope, - assembly, - first.getOffset(), - last.getEndOffset()); + IASTASMDefinition asmDefinition; + try + { + asmDefinition = + astFactory.createASMDefinition( + scope, + assembly, + first.getOffset(), + last.getEndOffset()); + } + catch (Exception e) + { + throw backtrack; + } // if we made it this far, then we have all we need // do the callback asmDefinition.acceptElement(requestor); @@ -760,10 +845,9 @@ public class Parser implements IParser (identifier == null ? first.getOffset() : identifier.getOffset()), (identifier == null ? first.getEndOffset() : identifier.getEndOffset() )); } - catch (ASTSemanticException e) + catch (Exception e1) { - failParse(); - throw backtrack; + throw backtrack; } namespaceDefinition.enterScope( requestor ); namepsaceDeclarationLoop : while (LT(1) != IToken.tRBRACE) @@ -811,9 +895,8 @@ public class Parser implements IParser scope, identifier.toString(), duple, first.getOffset(), identifier.getOffset(), identifier.getEndOffset(), duple.getLastToken().getEndOffset() ); } - catch (ASTSemanticException e) + catch (Exception e1) { - failParse(); throw backtrack; } } @@ -852,22 +935,23 @@ public class Parser implements IParser new DeclarationWrapper(scope, firstToken.getOffset(), ownerTemplate); declSpecifierSeq(false, strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR, sdw, forKR ); - try - { - if (sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED ) - sdw.setTypeSpecifier( - astFactory.createSimpleTypeSpecifier( - scope, - sdw.getSimpleType(), - sdw.getName(), - sdw.isShort(), - sdw.isLong(), - sdw.isSigned(), - sdw.isUnsigned(), sdw.isTypeNamed())); - } catch( ASTSemanticException se ) - { - throw backtrack; - } + if (sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED ) + try + { + sdw.setTypeSpecifier( + astFactory.createSimpleTypeSpecifier( + scope, + sdw.getSimpleType(), + sdw.getName(), + sdw.isShort(), + sdw.isLong(), + sdw.isSigned(), + sdw.isUnsigned(), sdw.isTypeNamed())); + } + catch (Exception e1) + { + throw backtrack; + } Declarator declarator = null; if (LT(1) != IToken.tSEMI) @@ -950,14 +1034,21 @@ public class Parser implements IParser } else { - astFactory - .createTypeSpecDeclaration( - sdw.getScope(), - sdw.getTypeSpecifier(), - ownerTemplate, - sdw.getStartingOffset(), - lastToken.getEndOffset()) - .acceptElement(requestor); + try + { + astFactory + .createTypeSpecDeclaration( + sdw.getScope(), + sdw.getTypeSpecifier(), + ownerTemplate, + sdw.getStartingOffset(), + lastToken.getEndOffset()) + .acceptElement(requestor); + } + catch (Exception e1) + { + throw backtrack; + } } } @@ -1027,9 +1118,8 @@ public class Parser implements IParser d.getDeclarationWrapper().getScope(), duple, expressionList)); } - catch (ASTSemanticException e) + catch (Exception e1) { - failParse(); throw backtrack; } if (LT(1) == IToken.tLBRACE) @@ -1059,24 +1149,29 @@ public class Parser implements IParser DeclarationWrapper sdw = new DeclarationWrapper(scope, current.getOffset(), null); declSpecifierSeq(true, false, sdw, false); - try - { - if (sdw.getTypeSpecifier() == null - && sdw.getSimpleType() - != IASTSimpleTypeSpecifier.Type.UNSPECIFIED) - sdw.setTypeSpecifier( - astFactory.createSimpleTypeSpecifier( - scope, - sdw.getSimpleType(), - sdw.getName(), - sdw.isShort(), - sdw.isLong(), - sdw.isSigned(), - sdw.isUnsigned(), sdw.isTypeNamed())); - } - catch( ASTSemanticException se ) { - throw backtrack; - } + if (sdw.getTypeSpecifier() == null + && sdw.getSimpleType() + != IASTSimpleTypeSpecifier.Type.UNSPECIFIED) + try + { + sdw.setTypeSpecifier( + astFactory.createSimpleTypeSpecifier( + scope, + sdw.getSimpleType(), + sdw.getName(), + sdw.isShort(), + sdw.isLong(), + sdw.isSigned(), + sdw.isUnsigned(), sdw.isTypeNamed())); + } + catch (ASTSemanticException e) + { + throw backtrack; + } + catch (Exception e) + { + throw backtrack; + } if (LT(1) != IToken.tSEMI) initDeclarator(sdw, false, SimpleDeclarationStrategy.TRY_FUNCTION ); @@ -1563,6 +1658,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } sdw.setTypeSpecifier(elaboratedTypeSpec); @@ -1817,10 +1915,17 @@ public class Parser implements IParser if (LT(1) == (IToken.tRBRACE)) { consume(IToken.tRBRACE); - return astFactory.createInitializerClause( - IASTInitializerClause.Kind.EMPTY, - null, - null); + try + { + return astFactory.createInitializerClause( + IASTInitializerClause.Kind.EMPTY, + null, + null); + } + catch (Exception e) + { + throw backtrack; + } } // otherwise it is a list of initializers List initializerClauses = new ArrayList(); @@ -1833,10 +1938,17 @@ public class Parser implements IParser consume(IToken.tCOMMA); } consume(IToken.tRBRACE); - return astFactory.createInitializerClause( - IASTInitializerClause.Kind.INITIALIZER_LIST, - null, - initializerClauses); + try + { + return astFactory.createInitializerClause( + IASTInitializerClause.Kind.INITIALIZER_LIST, + null, + initializerClauses); + } + catch (Exception e) + { + throw backtrack; + } } // try this now instead // assignmentExpression || { initializerList , } || { } @@ -1845,10 +1957,17 @@ public class Parser implements IParser IASTExpression assignmentExpression = assignmentExpression(scope); - return astFactory.createInitializerClause( - IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, - assignmentExpression, - null); + try + { + return astFactory.createInitializerClause( + IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, + assignmentExpression, + null); + } + catch (Exception e) + { + throw backtrack; + } } catch (Backtrack b) { @@ -1954,8 +2073,15 @@ public class Parser implements IParser try { - if( ! astFactory.queryIsTypeName( scope, name() ) ) - failed = true; + try + { + if( ! astFactory.queryIsTypeName( scope, name() ) ) + failed = true; + } + catch (Exception e) + { + throw backtrack; + } } catch( Backtrack b ) { failed = true; @@ -2063,6 +2189,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } } // check for optional pure virtual @@ -2160,8 +2289,15 @@ public class Parser implements IParser exp = constantExpression(scope); } consume(IToken.tRBRACKET); - IASTArrayModifier arrayMod = - astFactory.createArrayModifier(exp); + IASTArrayModifier arrayMod; + try + { + arrayMod = astFactory.createArrayModifier(exp); + } + catch (Exception e) + { + throw backtrack; + } d.addArrayModifier(arrayMod); } } @@ -2324,6 +2460,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } consume(IToken.tLBRACE); while (LT(1) != IToken.tRBRACE) @@ -2359,6 +2498,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; } @@ -2379,6 +2521,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } consume(IToken.tCOMMA); } @@ -2456,12 +2601,15 @@ public class Parser implements IParser access, classKey.getOffset(), duple == null ? classKey.getOffset() : duple.getFirstToken().getOffset(), - duple == null ? classKey.getEndOffset() : duple.getFirstToken().getEndOffset() ); + duple == null ? classKey.getEndOffset() : duple.getFirstToken().getOffset() ); } catch (ASTSemanticException e) { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } sdw.setTypeSpecifier(astClassSpecifier); // base clause @@ -2516,7 +2664,14 @@ public class Parser implements IParser IToken lt = consume(IToken.tRBRACE); astClassSpecifier.setEndingOffset(lt.getEndOffset()); - astFactory.signalEndOfClassSpecifier( astClassSpecifier ); + try + { + astFactory.signalEndOfClassSpecifier( astClassSpecifier ); + } + catch (Exception e1) + { + throw backtrack; + } astClassSpecifier.exitScope( requestor ); @@ -2579,6 +2734,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } isVirtual = false; visibility = ASTAccessVisibility.PUBLIC; @@ -2602,6 +2760,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } } /** @@ -2767,7 +2928,15 @@ public class Parser implements IParser } protected void singleStatementScope(IASTScope scope) throws Backtrack { - IASTCodeScope newScope = astFactory.createNewCodeBlock( scope ); + IASTCodeScope newScope; + try + { + newScope = astFactory.createNewCodeBlock(scope); + } + catch (Exception e) + { + throw backtrack; + } newScope.enterScope( requestor ); try { @@ -2823,7 +2992,14 @@ public class Parser implements IParser IASTCodeScope newScope = null; if( createNewScope ) { - newScope = astFactory.createNewCodeBlock(scope); + try + { + newScope = astFactory.createNewCodeBlock(scope); + } + catch (Exception e) + { + throw backtrack; + } newScope.enterScope( requestor ); } IToken checkToken = null; @@ -2879,7 +3055,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -2980,7 +3158,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3013,7 +3193,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3045,7 +3227,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3079,7 +3263,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3111,7 +3297,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3144,7 +3332,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3177,7 +3367,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3209,7 +3401,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3249,7 +3443,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } break; @@ -3325,7 +3521,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3368,7 +3566,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } break; @@ -3410,7 +3610,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } break; @@ -3463,7 +3665,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } break; @@ -3504,7 +3708,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } break; @@ -3545,7 +3751,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3733,6 +3941,9 @@ public class Parser implements IParser { backup( mark ); throw backtrack; + } catch (Exception e) + { + throw backtrack; } } /** @@ -3772,7 +3983,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -3898,16 +4111,18 @@ public class Parser implements IParser // new-expression ends here. try { - return astFactory.createExpression( - scope, IASTExpression.Kind.NEW_TYPEID, - null, null, null, typeId, null, - "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions)); + return astFactory.createExpression( + scope, IASTExpression.Kind.NEW_TYPEID, + null, null, null, typeId, null, + "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions)); } catch (ASTSemanticException e) { - failParse(); - return null; - } + throw backtrack; + } catch (Exception e) + { + throw backtrack; + } } } catch (Backtrack e) @@ -3950,9 +4165,11 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); return null; - } + } catch (Exception e) + { + throw backtrack; + } } protected IASTExpression unaryOperatorCastExpression( IASTScope scope, IASTExpression.Kind kind) @@ -3972,7 +4189,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -4054,7 +4273,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } else if (unaryExpression != null && d == null) @@ -4071,7 +4292,9 @@ public class Parser implements IParser } catch (ASTSemanticException e1) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } else @@ -4141,9 +4364,11 @@ public class Parser implements IParser "", null ); } catch (ASTSemanticException ase ) { - failParse(); throw backtrack; - } + } catch (Exception e) + { + throw backtrack; + } break; // simple-type-specifier ( assignment-expression , .. ) case IToken.t_char : @@ -4250,6 +4475,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; default : @@ -4281,6 +4509,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; case IToken.tLPAREN : @@ -4304,6 +4535,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; case IToken.tINCR : @@ -4324,6 +4558,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; case IToken.tDECR : @@ -4344,6 +4581,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; case IToken.tDOT : @@ -4373,6 +4613,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; case IToken.tARROW : @@ -4402,6 +4645,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } break; default : @@ -4433,7 +4679,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } @@ -4460,6 +4708,9 @@ public class Parser implements IParser { failParse(); throw backtrack; + } catch (Exception e) + { + throw backtrack; } } /** @@ -4488,7 +4739,9 @@ public class Parser implements IParser } catch (ASTSemanticException e1) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } case IToken.tFLOATINGPT : @@ -4506,7 +4759,9 @@ public class Parser implements IParser } catch (ASTSemanticException e2) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } case IToken.tSTRING : @@ -4518,7 +4773,9 @@ public class Parser implements IParser } catch (ASTSemanticException e5) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } @@ -4538,7 +4795,9 @@ public class Parser implements IParser } catch (ASTSemanticException e3) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } @@ -4559,7 +4818,9 @@ public class Parser implements IParser } catch (ASTSemanticException e4) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } @@ -4578,7 +4839,9 @@ public class Parser implements IParser } catch (ASTSemanticException e7) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } case IToken.tLPAREN : @@ -4598,7 +4861,9 @@ public class Parser implements IParser } catch (ASTSemanticException e6) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } case IToken.tIDENTIFIER : @@ -4618,7 +4883,9 @@ public class Parser implements IParser } catch (ASTSemanticException e8) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } default : @@ -4635,7 +4902,9 @@ public class Parser implements IParser } catch (ASTSemanticException e) { - failParse(); + throw backtrack; + } catch (Exception e) + { throw backtrack; } } 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 6934e86b2df..f78b6e42753 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 @@ -344,7 +344,23 @@ public class Scanner implements IScanner { } } if (inclusionReader != null) { - IASTInclusion inclusion = astFactory.createInclusion( fileName, newPath, !useIncludePaths, beginOffset, nameOffset, nameOffset + fileName.length(), endOffset ); + IASTInclusion inclusion = null; + try + { + inclusion = + astFactory.createInclusion( + fileName, + newPath, + !useIncludePaths, + beginOffset, + nameOffset, + nameOffset + fileName.length(), + endOffset); + } + catch (Exception e) + { + /* do nothing */ + } contextStack.updateContext(inclusionReader, newPath, ScannerContext.INCLUSION, inclusion, requestor ); } } @@ -2010,10 +2026,28 @@ public class Scanner implements IScanner { { if( requestor != null ) { - IASTInclusion i = astFactory.createInclusion( f, "", !useIncludePath, beginningOffset, - startOffset, startOffset + f.length(), endOffset ); - i.enterScope( requestor ); - i.exitScope( requestor ); + IASTInclusion i = null; + try + { + i = + astFactory.createInclusion( + f, + "", + !useIncludePath, + beginningOffset, + startOffset, + startOffset + f.length(), + endOffset); + } + catch (Exception e) + { + /* do nothing */ + } + if( i != null ) + { + i.enterScope( requestor ); + i.exitScope( requestor ); + } } } else @@ -2168,7 +2202,14 @@ public class Scanner implements IScanner { throw new ScannerException( ScannerException.ErrorCode.INVALID_PREPROCESSOR_DIRECTIVE, getCurrentFile(), getCurrentOffset() ); } - astFactory.createMacro( key, beginning, offset, offset + key.length(), contextStack.getCurrentContext().getOffset() ).acceptElement( requestor ); + try + { + astFactory.createMacro( key, beginning, offset, offset + key.length(), contextStack.getCurrentContext().getOffset() ).acceptElement( requestor ); + } + catch (Exception e) + { + /* do nothing */ + } } protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index 6c8a3c6f8c3..f73186a1fbc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -154,7 +154,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result = startingScope.qualifiedLookup(name, type); } } catch (ParserSymbolTableException e) { - throw e; + if( e.reason != ParserSymbolTableException.r_UnableToResolveFunction ) + throw e; } return result; } @@ -215,14 +216,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto try { result = lookupElement(startingScope, firstSymbol.getImage(), type, parameters); -/* if(type == TypeInfo.t_function) - if (validParameterList(parameters)) - result = startingScope.unqualifiedFunctionLookup( firstSymbol.getImage(), new LinkedList(parameters)); - else - result = null; - else - result = startingScope.lookup( firstSymbol.getImage()); -*/ if( result != null ) + if( result != null ) addReference( references, createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() )); else throw new ASTSemanticException(); @@ -248,14 +242,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto { if( t == name.getLastToken() ) result = lookupElement((IContainerSymbol)result, t.getImage(), type, parameters); -/* if((type == TypeInfo.t_function) || (type == TypeInfo.t_constructor)) - if (validParameterList(parameters)) - result = ((IContainerSymbol)result).qualifiedFunctionLookup( t.getImage(), new LinkedList(parameters) ); - else - result = null; - else - result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() ); -*/ else + else result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() ); addReference( references, createReference( result, t.getImage(), t.getOffset() )); } @@ -857,7 +844,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto * Apply the usual arithmetic conversions to find out the result of an expression * that has a lhs and a rhs as indicated in the specs (section 5.Expressions, page 64) */ - protected TypeInfo usualArithmeticConversions(TypeInfo lhs, TypeInfo rhs){ + protected TypeInfo usualArithmeticConversions(TypeInfo lhs, TypeInfo rhs) throws ASTSemanticException{ // if you have a variable of type basic type, then we need to go to the basic type first while( (lhs.getType() == TypeInfo.t_type) && (lhs.getTypeSymbol() != null)){ @@ -866,6 +853,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto while( (rhs.getType() == TypeInfo.t_type) && (rhs.getTypeSymbol() != null)){ rhs = rhs.getTypeSymbol().getTypeInfo(); } + + if( lhs.isType(TypeInfo.t_class, TypeInfo.t_enumeration ) || + rhs.isType(TypeInfo.t_class, TypeInfo.t_enumeration ) ) + { + throw new ASTSemanticException(); + } TypeInfo info = new TypeInfo(); if( @@ -929,6 +922,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } } protected List getExpressionResultType(IASTExpression expression, ISymbol symbol)throws ASTSemanticException{ + + List result = new ArrayList(); TypeInfo info = new TypeInfo(); try { @@ -1163,8 +1158,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if((left != null ) && (right != null)){ TypeInfo leftType =(TypeInfo)left.getResultType().iterator().next(); TypeInfo rightType =(TypeInfo)right.getResultType().iterator().next(); - info = usualArithmeticConversions(leftType, rightType); + info = usualArithmeticConversions(leftType, rightType); } + else + throw new ASTSemanticException(); result.add(info); return result; }