1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed infinite loop in indexer that happened when CPPTypedefSpecialization.getType method returned the same object as this. This problematic behavior was triggered by a template argument containing a wrapped ProblemBinding.

This commit is contained in:
Sergey Prigogin 2008-05-25 23:11:38 +00:00
parent 4116aadcb0
commit c3a011ab81
3 changed files with 32 additions and 28 deletions

View file

@ -663,8 +663,7 @@ public class CPPSemantics {
// now scope is fully cached. // now scope is fully cached.
final IBinding[] bindings = scope.getBindings(data.astName, true, data.prefixLookup, fileSet); final IBinding[] bindings = scope.getBindings(data.astName, true, data.prefixLookup, fileSet);
mergeResults(data, bindings, true); mergeResults(data, bindings, true);
} } else {
else {
boolean done= false; boolean done= false;
if (!ASTInternal.isFullyCached(scope)) { if (!ASTInternal.isFullyCached(scope)) {
final IASTName[] names= lookupInScope(data, scope, blockItem); final IASTName[] names= lookupInScope(data, scope, blockItem);

View file

@ -1636,8 +1636,14 @@ public class CPPTemplates {
} }
static private boolean isValidArgument(ICPPTemplateParameter param, IType argument) { static private boolean isValidArgument(ICPPTemplateParameter param, IType argument) {
//TODO try {
return true; while (argument instanceof ITypeContainer) {
argument = ((ITypeContainer) argument).getType();
}
} catch (DOMException e) {
return false;
}
return !(argument instanceof IProblemBinding);
} }
static protected boolean matchTemplateParameterAndArgument(ICPPTemplateParameter param, IType argument, ObjectMap map) { static protected boolean matchTemplateParameterAndArgument(ICPPTemplateParameter param, IType argument, ObjectMap map) {
@ -1658,7 +1664,6 @@ public class CPPTemplates {
return false; return false;
} }
int size = pParams.length; int size = pParams.length;
if (aParams.length != size) { if (aParams.length != size) {
return false; return false;
@ -1667,8 +1672,7 @@ public class CPPTemplates {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
if ((pParams[i] instanceof ICPPTemplateTypeParameter && !(aParams[i] instanceof ICPPTemplateTypeParameter)) || if ((pParams[i] instanceof ICPPTemplateTypeParameter && !(aParams[i] instanceof ICPPTemplateTypeParameter)) ||
(pParams[i] instanceof ICPPTemplateTemplateParameter && !(aParams[i] instanceof ICPPTemplateTemplateParameter)) || (pParams[i] instanceof ICPPTemplateTemplateParameter && !(aParams[i] instanceof ICPPTemplateTemplateParameter)) ||
(pParams[i] instanceof ICPPTemplateNonTypeParameter && !(aParams[i] instanceof ICPPTemplateNonTypeParameter))) (pParams[i] instanceof ICPPTemplateNonTypeParameter && !(aParams[i] instanceof ICPPTemplateNonTypeParameter))) {
{
return false; return false;
} }
} }
@ -1696,7 +1700,7 @@ public class CPPTemplates {
if (cost == null || cost.rank == Cost.NO_MATCH_RANK) { if (cost == null || cost.rank == Cost.NO_MATCH_RANK) {
return false; return false;
} }
} catch(DOMException e) { } catch (DOMException e) {
return false; return false;
} }
} }

View file

@ -499,7 +499,7 @@ public class CPPVisitor {
IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray()); IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray());
} }
} }
} catch(DOMException e) { } catch (DOMException e) {
binding = e.getProblem(); binding = e.getProblem();
} }
@ -967,7 +967,7 @@ public class CPPVisitor {
IASTFunctionDefinition fdef = (IASTFunctionDefinition) parent; IASTFunctionDefinition fdef = (IASTFunctionDefinition) parent;
return ((ICPPASTFunctionDeclarator)fdef.getDeclarator()).getFunctionScope(); return ((ICPPASTFunctionDeclarator)fdef.getDeclarator()).getFunctionScope();
} }
} catch(DOMException e) { } catch (DOMException e) {
IProblemBinding problem = e.getProblem(); IProblemBinding problem = e.getProblem();
if (problem instanceof ICPPScope) if (problem instanceof ICPPScope)
return problem; return problem;
@ -1245,8 +1245,7 @@ public class CPPVisitor {
} else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
IASTNode p = name.getParent().getParent(); IASTNode p = name.getParent().getParent();
if (p instanceof IASTSimpleDeclaration && if (p instanceof IASTSimpleDeclaration &&
((IASTSimpleDeclaration)p).getDeclarators().length == 0) ((IASTSimpleDeclaration) p).getDeclarators().length == 0) {
{
break; break;
} }
} else if (prop == IASTDeclarator.DECLARATOR_NAME) { } else if (prop == IASTDeclarator.DECLARATOR_NAME) {
@ -1608,17 +1607,18 @@ public class CPPVisitor {
private static IType getPointerTypes(IType type, IASTDeclarator declarator) { private static IType getPointerTypes(IType type, IASTDeclarator declarator) {
IASTPointerOperator[] ptrOps = declarator.getPointerOperators(); IASTPointerOperator[] ptrOps = declarator.getPointerOperators();
for (IASTPointerOperator ptrOp : ptrOps) { for (IASTPointerOperator ptrOp : ptrOps) {
if (ptrOp instanceof IGPPASTPointerToMember) if (ptrOp instanceof IGPPASTPointerToMember) {
type = new GPPPointerToMemberType(type, (IGPPASTPointerToMember) ptrOp); type = new GPPPointerToMemberType(type, (IGPPASTPointerToMember) ptrOp);
else if (ptrOp instanceof ICPPASTPointerToMember) } else if (ptrOp instanceof ICPPASTPointerToMember) {
type = new CPPPointerToMemberType(type, (ICPPASTPointerToMember) ptrOp); type = new CPPPointerToMemberType(type, (ICPPASTPointerToMember) ptrOp);
else if (ptrOp instanceof IGPPASTPointer) } else if (ptrOp instanceof IGPPASTPointer) {
type = new GPPPointerType(type, (IGPPASTPointer) ptrOp); type = new GPPPointerType(type, (IGPPASTPointer) ptrOp);
else if (ptrOp instanceof IASTPointer) } else if (ptrOp instanceof IASTPointer) {
type = new CPPPointerType(type, (IASTPointer) ptrOp); type = new CPPPointerType(type, (IASTPointer) ptrOp);
else if (ptrOp instanceof ICPPASTReferenceOperator) } else if (ptrOp instanceof ICPPASTReferenceOperator) {
type = new CPPReferenceType(type); type = new CPPReferenceType(type);
} }
}
return type; return type;
} }
@ -1651,14 +1651,15 @@ public class CPPVisitor {
node = node.getParent(); node = node.getParent();
} }
if (node instanceof IASTParameterDeclaration) if (node instanceof IASTParameterDeclaration) {
declSpec = ((IASTParameterDeclaration) node).getDeclSpecifier(); declSpec = ((IASTParameterDeclaration) node).getDeclSpecifier();
else if (node instanceof IASTSimpleDeclaration) } else if (node instanceof IASTSimpleDeclaration) {
declSpec = ((IASTSimpleDeclaration)node).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration)node).getDeclSpecifier();
else if (node instanceof IASTFunctionDefinition) } else if (node instanceof IASTFunctionDefinition) {
declSpec = ((IASTFunctionDefinition)node).getDeclSpecifier(); declSpec = ((IASTFunctionDefinition)node).getDeclSpecifier();
else if (node instanceof IASTTypeId) } else if (node instanceof IASTTypeId) {
declSpec = ((IASTTypeId)node).getDeclSpecifier(); declSpec = ((IASTTypeId)node).getDeclSpecifier();
}
IType type = createType(declSpec); IType type = createType(declSpec);
type = createType(type, declarator); type = createType(type, declarator);
@ -1718,7 +1719,7 @@ public class CPPVisitor {
} else if (binding instanceof ICPPTemplateNonTypeParameter) { } else if (binding instanceof ICPPTemplateNonTypeParameter) {
//TODO workaround... is there anything better? //TODO workaround... is there anything better?
try { try {
type = ((ICPPTemplateNonTypeParameter)binding).getType(); type = ((ICPPTemplateNonTypeParameter) binding).getType();
} catch (DOMException e) { } catch (DOMException e) {
type = e.getProblem(); type = e.getProblem();
} }
@ -1872,7 +1873,7 @@ public class CPPVisitor {
return op.getType().getReturnType(); return op.getType().getReturnType();
} }
} }
} catch(DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
} else if (binding instanceof ITypedef) { } else if (binding instanceof ITypedef) {
@ -1965,7 +1966,7 @@ public class CPPVisitor {
IType type = getExpressionType(((IASTUnaryExpression)expression).getOperand()); IType type = getExpressionType(((IASTUnaryExpression)expression).getOperand());
while (type instanceof ITypedef) { while (type instanceof ITypedef) {
try { try {
type = ((ITypeContainer)type).getType(); type = ((ITypedef) type).getType();
} catch (DOMException e) { } catch (DOMException e) {
break; break;
} }
@ -1976,7 +1977,7 @@ public class CPPVisitor {
if (operator != null) { if (operator != null) {
return operator.getType().getReturnType(); return operator.getType().getReturnType();
} }
} catch(DOMException de) { } catch (DOMException de) {
return de.getProblem(); return de.getProblem();
} }
} }
@ -2063,7 +2064,7 @@ public class CPPVisitor {
return ((IPointerType)t).getType(); return ((IPointerType)t).getType();
else if (t instanceof IArrayType) else if (t instanceof IArrayType)
return ((IArrayType)t).getType(); return ((IArrayType)t).getType();
} catch(DOMException e) { } catch (DOMException e) {
} }
} else if (expression instanceof IGNUASTCompoundStatementExpression) { } else if (expression instanceof IGNUASTCompoundStatementExpression) {
IASTCompoundStatement compound = ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(); IASTCompoundStatement compound = ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement();
@ -2329,7 +2330,7 @@ public class CPPVisitor {
return !(tp.getReturnType() instanceof ICPPReferenceType); return !(tp.getReturnType() instanceof ICPPReferenceType);
} }
} }
} catch(DOMException de) { } catch (DOMException de) {
// fall-through // fall-through
} }
} }