mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix bug 57791 - Parser Infiinite loop
This commit is contained in:
parent
92d011ea1d
commit
b8ff553e9a
6 changed files with 69 additions and 20 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2004-04-15 Andrew Niefer
|
||||||
|
added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testBug57791()
|
||||||
|
|
||||||
2004-04-14 John Camelon
|
2004-04-14 John Camelon
|
||||||
Added CompletionTest::testBug52253().
|
Added CompletionTest::testBug52253().
|
||||||
|
|
||||||
|
|
|
@ -1488,6 +1488,17 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
||||||
assertTrue( f.isFriend() );
|
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
|
public void testBug44249() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -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
|
2004-04-14 John Camelon
|
||||||
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=52253
|
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=52253
|
||||||
|
|
||||||
|
|
|
@ -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.ISymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner;
|
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.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.ParserSymbolTableException;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
|
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
|
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
|
||||||
|
@ -54,7 +55,12 @@ public class ASTNode implements IASTNode {
|
||||||
ISymbol sym = null;
|
ISymbol sym = null;
|
||||||
if( context instanceof IASTTypedefDeclaration ){
|
if( context instanceof IASTTypedefDeclaration ){
|
||||||
ISymbol typedef = ((ISymbolOwner)context).getSymbol();
|
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();
|
sym = info.getTypeSymbol();
|
||||||
} else if ( context instanceof IASTVariable ){
|
} else if ( context instanceof IASTVariable ){
|
||||||
sym = ((ISymbolOwner)context).getSymbol().getTypeSymbol(); // good enough for now
|
sym = ((ISymbolOwner)context).getSymbol().getTypeSymbol(); // good enough for now
|
||||||
|
@ -110,6 +116,8 @@ public class ASTNode implements IASTNode {
|
||||||
}
|
}
|
||||||
} catch (ParserSymbolTableException e) {
|
} catch (ParserSymbolTableException e) {
|
||||||
throw new LookupError();
|
throw new LookupError();
|
||||||
|
} catch (ParserSymbolTableError e ){
|
||||||
|
throw new LookupError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lookupResults == null)
|
if(lookupResults == null)
|
||||||
|
|
|
@ -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.IUsingDirectiveSymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension;
|
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.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.ParserSymbolTableException;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
|
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.TemplateSymbolExtension;
|
import org.eclipse.cdt.internal.core.parser.pst.TemplateSymbolExtension;
|
||||||
|
@ -240,6 +241,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
} catch (ParserSymbolTableException e) {
|
} catch (ParserSymbolTableException e) {
|
||||||
if( e.reason != ParserSymbolTableException.r_UnableToResolveFunction )
|
if( e.reason != ParserSymbolTableException.r_UnableToResolveFunction )
|
||||||
handleProblem( e.createProblemID(), name );
|
handleProblem( e.createProblemID(), name );
|
||||||
|
} catch (ParserSymbolTableError e){
|
||||||
|
handleProblem( IProblem.INTERNAL_RELATED, name );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -387,6 +390,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
handleProblem( pste.createProblemID(), image );
|
handleProblem( pste.createProblemID(), image );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
catch( ParserSymbolTableError e )
|
||||||
|
{
|
||||||
|
if( throwOnError )
|
||||||
|
handleProblem( IProblem.INTERNAL_RELATED, image );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1125,7 +1134,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
){
|
){
|
||||||
TypeInfo lhsInfo = ((ASTExpression)lhs).getResultType().getResult();
|
TypeInfo lhsInfo = ((ASTExpression)lhs).getResultType().getResult();
|
||||||
if(lhsInfo != null){
|
if(lhsInfo != null){
|
||||||
TypeInfo info = lhsInfo.getFinalType();
|
TypeInfo info = null;
|
||||||
|
try{
|
||||||
|
info = lhsInfo.getFinalType();
|
||||||
|
} catch ( ParserSymbolTableError e ){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
ISymbol containingScope = info.getTypeSymbol();
|
ISymbol containingScope = info.getTypeSymbol();
|
||||||
// assert containingScope != null : "Malformed Expression";
|
// assert containingScope != null : "Malformed Expression";
|
||||||
if( containingScope instanceof IDeferredTemplateInstance )
|
if( containingScope instanceof IDeferredTemplateInstance )
|
||||||
|
@ -1922,7 +1936,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
functionDeclaration =
|
functionDeclaration =
|
||||||
(IParameterizedSymbol) lookupQualifiedName(ownerScope, name.getFirstToken().getImage(), TypeInfo.t_function, functionParameters, 0, new ArrayList(), false, LookupType.FORDEFINITION );
|
(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;
|
previouslyDeclared = true;
|
||||||
|
|
||||||
if( isFunctionDefinition ){
|
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 );
|
(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( isFriend )
|
||||||
{
|
{
|
||||||
if( functionDeclaration != null )
|
if( functionDeclaration != null && functionDeclaration.isType( isConstructor ? TypeInfo.t_constructor : TypeInfo.t_function ))
|
||||||
{
|
{
|
||||||
symbol.setTypeSymbol( functionDeclaration );
|
symbol.setTypeSymbol( functionDeclaration );
|
||||||
// friend declaration, has no real visibility, set private
|
// friend declaration, has no real visibility, set private
|
||||||
visibility = ASTAccessVisibility.PRIVATE;
|
visibility = ASTAccessVisibility.PRIVATE;
|
||||||
} else if( ownerScope.isType( TypeInfo.t_constructor ) ||
|
} else if( ownerScope.getContainingSymbol().isType( TypeInfo.t_constructor ) ||
|
||||||
ownerScope.isType( TypeInfo.t_function ) ||
|
ownerScope.getContainingSymbol().isType( TypeInfo.t_function ) ||
|
||||||
ownerScope.isType( TypeInfo.t_block ) )
|
ownerScope.getContainingSymbol().isType( TypeInfo.t_block ) )
|
||||||
{
|
{
|
||||||
//only needs to be previously declared if we are in a local class
|
//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() );
|
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 );
|
functionDeclaration.setTypeSymbol( symbol );
|
||||||
// set the definition visibility = declaration visibility
|
// set the definition visibility = declaration visibility
|
||||||
|
@ -2435,10 +2449,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
if(!isStatic){
|
if(!isStatic){
|
||||||
ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name.toString(), new ArrayList(), false, LookupType.UNQUALIFIED);
|
ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name.toString(), new ArrayList(), false, LookupType.UNQUALIFIED);
|
||||||
|
|
||||||
if( variableDeclaration != null )
|
if( variableDeclaration != null && newSymbol.getType() == variableDeclaration.getType() )
|
||||||
{
|
{
|
||||||
variableDeclaration.setTypeSymbol( newSymbol );
|
if( !newSymbol.isType( TypeInfo.t_type ) ||
|
||||||
previouslyDeclared = true;
|
(newSymbol.isType( TypeInfo.t_type ) && newSymbol.getTypeSymbol() != variableDeclaration.getTypeSymbol() ) )
|
||||||
|
{
|
||||||
|
variableDeclaration.setTypeSymbol( newSymbol );
|
||||||
|
previouslyDeclared = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
@ -2647,14 +2665,17 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
if(!isStatic){
|
if(!isStatic){
|
||||||
List fieldReferences = new ArrayList();
|
List fieldReferences = new ArrayList();
|
||||||
ISymbol fieldDeclaration = lookupQualifiedName(ownerScope, name.toString(), fieldReferences, false, LookupType.FORDEFINITION);
|
ISymbol fieldDeclaration = lookupQualifiedName(ownerScope, name.toString(), fieldReferences, false, LookupType.FORDEFINITION);
|
||||||
|
|
||||||
if( fieldDeclaration != null )
|
if( fieldDeclaration != null && newSymbol.getType() == fieldDeclaration.getType() )
|
||||||
{
|
{
|
||||||
previouslyDeclared = true;
|
if( !newSymbol.isType( TypeInfo.t_type ) ||
|
||||||
fieldDeclaration.setTypeSymbol( newSymbol );
|
(newSymbol.isType( TypeInfo.t_type ) && newSymbol.getTypeSymbol() != fieldDeclaration.getTypeSymbol() ) )
|
||||||
// set the definition visibility = declaration visibility
|
{
|
||||||
ASTReference reference = (ASTReference) fieldReferences.iterator().next();
|
previouslyDeclared = true;
|
||||||
visibility = ((IASTField)reference.getReferencedElement()).getVisiblity();
|
fieldDeclaration.setTypeSymbol( newSymbol );
|
||||||
|
// set the definition visibility = declaration visibility
|
||||||
|
ASTReference reference = (ASTReference) fieldReferences.iterator().next();
|
||||||
|
visibility = ((IASTField)reference.getReferencedElement()).getVisiblity(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
|
||||||
|
|
||||||
public class ParserSymbolTable {
|
public class ParserSymbolTable {
|
||||||
|
|
||||||
|
public static final int TYPE_LOOP_THRESHOLD = 50;
|
||||||
public static final String EMPTY_NAME = ""; //$NON-NLS-1$
|
public static final String EMPTY_NAME = ""; //$NON-NLS-1$
|
||||||
public static final String THIS = "this"; //$NON-NLS-1$
|
public static final String THIS = "this"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -1973,13 +1974,15 @@ public class ParserSymbolTable {
|
||||||
ISymbol typeSymbol = topInfo.getTypeSymbol();
|
ISymbol typeSymbol = topInfo.getTypeSymbol();
|
||||||
|
|
||||||
info = typeSymbol.getTypeInfo();
|
info = typeSymbol.getTypeInfo();
|
||||||
|
int j = 0;
|
||||||
while( info.getTypeSymbol() != null && ( info.getType() == TypeInfo.t_type || info.isForwardDeclaration() ) ){
|
while( info.getTypeSymbol() != null && ( info.getType() == TypeInfo.t_type || info.isForwardDeclaration() ) ){
|
||||||
typeSymbol = info.getTypeSymbol();
|
typeSymbol = info.getTypeSymbol();
|
||||||
|
|
||||||
returnInfo.addPtrOperator( info.getPtrOperators() );
|
returnInfo.addPtrOperator( info.getPtrOperators() );
|
||||||
returnInfo.setTypeInfo( ( returnInfo.getTypeInfo() | info.getTypeInfo() ) & ~TypeInfo.isTypedef & ~TypeInfo.isForward );
|
returnInfo.setTypeInfo( ( returnInfo.getTypeInfo() | info.getTypeInfo() ) & ~TypeInfo.isTypedef & ~TypeInfo.isForward );
|
||||||
info = typeSymbol.getTypeInfo();
|
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 ) ){
|
if( info.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) || info.isType( TypeInfo.t_function ) ){
|
||||||
|
|
Loading…
Add table
Reference in a new issue