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
|
||||
Added CompletionTest::testBug52253().
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ) ){
|
||||
|
|
Loading…
Add table
Reference in a new issue