diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index cbc3080929e..c73a5465641 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2004-04-15 Andrew Niefer + added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testBug57791() + 2004-04-14 John Camelon Added CompletionTest::testBug52253(). 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 915f1806b46..15eae19ae06 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 @@ -1488,6 +1488,17 @@ public class CompleteParseASTTest extends CompleteParseBaseTest assertTrue( f.isFriend() ); } + public void testBug57791() throws Exception + { + Writer writer = new StringWriter(); + writer.write(" void f() { "); + writer.write(" struct astruct astruct; "); + writer.write(" astruct.foo++; "); + writer.write(" }"); + + parse( writer.toString(), true, ParserLanguage.C ); + } + public void testBug44249() throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser index 7a9d3204fc0..38091c7082b 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser +++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser @@ -1,3 +1,6 @@ +2004-04-15 Andrew Niefer + fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=57791 - Parser infinite loop + 2004-04-14 John Camelon Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=52253 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java index 8d32b524dc9..81e5c2904ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; +import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; import org.eclipse.cdt.internal.core.parser.pst.TypeFilter; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; @@ -54,7 +55,12 @@ public class ASTNode implements IASTNode { ISymbol sym = null; if( context instanceof IASTTypedefDeclaration ){ ISymbol typedef = ((ISymbolOwner)context).getSymbol(); - TypeInfo info = typedef.getTypeInfo().getFinalType(); + TypeInfo info = null; + try{ + info = typedef.getTypeInfo().getFinalType(); + } catch( ParserSymbolTableError e ){ + throw new LookupError(); + } sym = info.getTypeSymbol(); } else if ( context instanceof IASTVariable ){ sym = ((ISymbolOwner)context).getSymbol().getTypeSymbol(); // good enough for now @@ -110,6 +116,8 @@ public class ASTNode implements IASTNode { } } catch (ParserSymbolTableException e) { throw new LookupError(); + } catch (ParserSymbolTableError e ){ + throw new LookupError(); } if(lookupResults == null) 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 dcffb80a152..b6bbe13e5c8 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 @@ -88,6 +88,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IUsingDeclarationSymbol; import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol; import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; +import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.TemplateSymbolExtension; @@ -240,6 +241,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } catch (ParserSymbolTableException e) { if( e.reason != ParserSymbolTableException.r_UnableToResolveFunction ) handleProblem( e.createProblemID(), name ); + } catch (ParserSymbolTableError e){ + handleProblem( IProblem.INTERNAL_RELATED, name ); } return result; } @@ -387,6 +390,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto handleProblem( pste.createProblemID(), image ); return null; } + catch( ParserSymbolTableError e ) + { + if( throwOnError ) + handleProblem( IProblem.INTERNAL_RELATED, image ); + return null; + } } } return result; @@ -1125,7 +1134,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ){ TypeInfo lhsInfo = ((ASTExpression)lhs).getResultType().getResult(); if(lhsInfo != null){ - TypeInfo info = lhsInfo.getFinalType(); + TypeInfo info = null; + try{ + info = lhsInfo.getFinalType(); + } catch ( ParserSymbolTableError e ){ + return null; + } ISymbol containingScope = info.getTypeSymbol(); // assert containingScope != null : "Malformed Expression"; if( containingScope instanceof IDeferredTemplateInstance ) @@ -1922,7 +1936,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto functionDeclaration = (IParameterizedSymbol) lookupQualifiedName(ownerScope, name.getFirstToken().getImage(), TypeInfo.t_function, functionParameters, 0, new ArrayList(), false, LookupType.FORDEFINITION ); - if( functionDeclaration != null ){ + if( functionDeclaration != null && symbol.isType( TypeInfo.t_function )){ previouslyDeclared = true; if( isFunctionDefinition ){ @@ -2271,24 +2285,24 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto (IParameterizedSymbol) lookupQualifiedName(ownerScope, nameDuple.toString(), isConstructor ? TypeInfo.t_constructor : TypeInfo.t_function, functionParameters, 0, functionReferences, false, LookupType.FORDEFINITION ); } - previouslyDeclared = ( functionDeclaration != null ); + previouslyDeclared = ( functionDeclaration != null ) && functionDeclaration.isType( isConstructor ? TypeInfo.t_constructor : TypeInfo.t_function ); if( isFriend ) { - if( functionDeclaration != null ) + if( functionDeclaration != null && functionDeclaration.isType( isConstructor ? TypeInfo.t_constructor : TypeInfo.t_function )) { symbol.setTypeSymbol( functionDeclaration ); // friend declaration, has no real visibility, set private visibility = ASTAccessVisibility.PRIVATE; - } else if( ownerScope.isType( TypeInfo.t_constructor ) || - ownerScope.isType( TypeInfo.t_function ) || - ownerScope.isType( TypeInfo.t_block ) ) + } else if( ownerScope.getContainingSymbol().isType( TypeInfo.t_constructor ) || + ownerScope.getContainingSymbol().isType( TypeInfo.t_function ) || + ownerScope.getContainingSymbol().isType( TypeInfo.t_block ) ) { //only needs to be previously declared if we are in a local class handleProblem( IProblem.SEMANTIC_ILLFORMED_FRIEND, nameDuple.toString(), nameDuple.getStartOffset(), nameDuple.getEndOffset(), nameDuple.getLineNumber() ); } - } else if( functionDeclaration != null ) + } else if( functionDeclaration != null && functionDeclaration.isType( isConstructor ? TypeInfo.t_constructor : TypeInfo.t_function ) ) { functionDeclaration.setTypeSymbol( symbol ); // set the definition visibility = declaration visibility @@ -2435,10 +2449,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if(!isStatic){ ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name.toString(), new ArrayList(), false, LookupType.UNQUALIFIED); - if( variableDeclaration != null ) + if( variableDeclaration != null && newSymbol.getType() == variableDeclaration.getType() ) { - variableDeclaration.setTypeSymbol( newSymbol ); - previouslyDeclared = true; + if( !newSymbol.isType( TypeInfo.t_type ) || + (newSymbol.isType( TypeInfo.t_type ) && newSymbol.getTypeSymbol() != variableDeclaration.getTypeSymbol() ) ) + { + variableDeclaration.setTypeSymbol( newSymbol ); + previouslyDeclared = true; + } } } try @@ -2647,14 +2665,17 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if(!isStatic){ List fieldReferences = new ArrayList(); ISymbol fieldDeclaration = lookupQualifiedName(ownerScope, name.toString(), fieldReferences, false, LookupType.FORDEFINITION); - - if( fieldDeclaration != null ) + + if( fieldDeclaration != null && newSymbol.getType() == fieldDeclaration.getType() ) { - previouslyDeclared = true; - fieldDeclaration.setTypeSymbol( newSymbol ); - // set the definition visibility = declaration visibility - ASTReference reference = (ASTReference) fieldReferences.iterator().next(); - visibility = ((IASTField)reference.getReferencedElement()).getVisiblity(); + if( !newSymbol.isType( TypeInfo.t_type ) || + (newSymbol.isType( TypeInfo.t_type ) && newSymbol.getTypeSymbol() != fieldDeclaration.getTypeSymbol() ) ) + { + previouslyDeclared = true; + fieldDeclaration.setTypeSymbol( newSymbol ); + // set the definition visibility = declaration visibility + ASTReference reference = (ASTReference) fieldReferences.iterator().next(); + visibility = ((IASTField)reference.getReferencedElement()).getVisiblity(); } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java index 457b6dc4222..1090d667c01 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java @@ -39,6 +39,7 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp; public class ParserSymbolTable { + public static final int TYPE_LOOP_THRESHOLD = 50; public static final String EMPTY_NAME = ""; //$NON-NLS-1$ public static final String THIS = "this"; //$NON-NLS-1$ @@ -1973,13 +1974,15 @@ public class ParserSymbolTable { ISymbol typeSymbol = topInfo.getTypeSymbol(); info = typeSymbol.getTypeInfo(); - + int j = 0; while( info.getTypeSymbol() != null && ( info.getType() == TypeInfo.t_type || info.isForwardDeclaration() ) ){ typeSymbol = info.getTypeSymbol(); returnInfo.addPtrOperator( info.getPtrOperators() ); returnInfo.setTypeInfo( ( returnInfo.getTypeInfo() | info.getTypeInfo() ) & ~TypeInfo.isTypedef & ~TypeInfo.isForward ); info = typeSymbol.getTypeInfo(); + if( ++j > TYPE_LOOP_THRESHOLD ) + throw new ParserSymbolTableError(); } if( info.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) || info.isType( TypeInfo.t_function ) ){