From c3a011ab817f6649825b552e09aed8a2a05c0dc8 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 25 May 2008 23:11:38 +0000 Subject: [PATCH] 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. --- .../parser/cpp/semantics/CPPSemantics.java | 3 +- .../parser/cpp/semantics/CPPTemplates.java | 18 +++++---- .../dom/parser/cpp/semantics/CPPVisitor.java | 39 ++++++++++--------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 63a1247df8c..925e690e82c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -663,8 +663,7 @@ public class CPPSemantics { // now scope is fully cached. final IBinding[] bindings = scope.getBindings(data.astName, true, data.prefixLookup, fileSet); mergeResults(data, bindings, true); - } - else { + } else { boolean done= false; if (!ASTInternal.isFullyCached(scope)) { final IASTName[] names= lookupInScope(data, scope, blockItem); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 5263a338a41..08e7d364e64 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -1636,8 +1636,14 @@ public class CPPTemplates { } static private boolean isValidArgument(ICPPTemplateParameter param, IType argument) { - //TODO - return true; + try { + 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) { @@ -1658,7 +1664,6 @@ public class CPPTemplates { return false; } - int size = pParams.length; if (aParams.length != size) { return false; @@ -1666,9 +1671,8 @@ public class CPPTemplates { for (int i = 0; i < size; i++) { if ((pParams[i] instanceof ICPPTemplateTypeParameter && !(aParams[i] instanceof ICPPTemplateTypeParameter)) || - (pParams[i] instanceof ICPPTemplateTemplateParameter && !(aParams[i] instanceof ICPPTemplateTemplateParameter)) || - (pParams[i] instanceof ICPPTemplateNonTypeParameter && !(aParams[i] instanceof ICPPTemplateNonTypeParameter))) - { + (pParams[i] instanceof ICPPTemplateTemplateParameter && !(aParams[i] instanceof ICPPTemplateTemplateParameter)) || + (pParams[i] instanceof ICPPTemplateNonTypeParameter && !(aParams[i] instanceof ICPPTemplateNonTypeParameter))) { return false; } } @@ -1696,7 +1700,7 @@ public class CPPTemplates { if (cost == null || cost.rank == Cost.NO_MATCH_RANK) { return false; } - } catch(DOMException e) { + } catch (DOMException e) { return false; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index 3857028542f..bdbbc9e398f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -499,7 +499,7 @@ public class CPPVisitor { IProblemBinding.SEMANTIC_NAME_NOT_FOUND, alias.getAlias().toCharArray()); } } - } catch(DOMException e) { + } catch (DOMException e) { binding = e.getProblem(); } @@ -967,7 +967,7 @@ public class CPPVisitor { IASTFunctionDefinition fdef = (IASTFunctionDefinition) parent; return ((ICPPASTFunctionDeclarator)fdef.getDeclarator()).getFunctionScope(); } - } catch(DOMException e) { + } catch (DOMException e) { IProblemBinding problem = e.getProblem(); if (problem instanceof ICPPScope) return problem; @@ -1245,8 +1245,7 @@ public class CPPVisitor { } else if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) { IASTNode p = name.getParent().getParent(); if (p instanceof IASTSimpleDeclaration && - ((IASTSimpleDeclaration)p).getDeclarators().length == 0) - { + ((IASTSimpleDeclaration) p).getDeclarators().length == 0) { break; } } else if (prop == IASTDeclarator.DECLARATOR_NAME) { @@ -1608,16 +1607,17 @@ public class CPPVisitor { private static IType getPointerTypes(IType type, IASTDeclarator declarator) { IASTPointerOperator[] ptrOps = declarator.getPointerOperators(); for (IASTPointerOperator ptrOp : ptrOps) { - if (ptrOp instanceof IGPPASTPointerToMember) + if (ptrOp instanceof IGPPASTPointerToMember) { type = new GPPPointerToMemberType(type, (IGPPASTPointerToMember) ptrOp); - else if (ptrOp instanceof ICPPASTPointerToMember) + } else if (ptrOp instanceof ICPPASTPointerToMember) { type = new CPPPointerToMemberType(type, (ICPPASTPointerToMember) ptrOp); - else if (ptrOp instanceof IGPPASTPointer) + } else if (ptrOp instanceof IGPPASTPointer) { type = new GPPPointerType(type, (IGPPASTPointer) ptrOp); - else if (ptrOp instanceof IASTPointer) + } else if (ptrOp instanceof IASTPointer) { type = new CPPPointerType(type, (IASTPointer) ptrOp); - else if (ptrOp instanceof ICPPASTReferenceOperator) + } else if (ptrOp instanceof ICPPASTReferenceOperator) { type = new CPPReferenceType(type); + } } return type; } @@ -1651,14 +1651,15 @@ public class CPPVisitor { node = node.getParent(); } - if (node instanceof IASTParameterDeclaration) + if (node instanceof IASTParameterDeclaration) { declSpec = ((IASTParameterDeclaration) node).getDeclSpecifier(); - else if (node instanceof IASTSimpleDeclaration) + } else if (node instanceof IASTSimpleDeclaration) { declSpec = ((IASTSimpleDeclaration)node).getDeclSpecifier(); - else if (node instanceof IASTFunctionDefinition) + } else if (node instanceof IASTFunctionDefinition) { declSpec = ((IASTFunctionDefinition)node).getDeclSpecifier(); - else if (node instanceof IASTTypeId) + } else if (node instanceof IASTTypeId) { declSpec = ((IASTTypeId)node).getDeclSpecifier(); + } IType type = createType(declSpec); type = createType(type, declarator); @@ -1718,7 +1719,7 @@ public class CPPVisitor { } else if (binding instanceof ICPPTemplateNonTypeParameter) { //TODO workaround... is there anything better? try { - type = ((ICPPTemplateNonTypeParameter)binding).getType(); + type = ((ICPPTemplateNonTypeParameter) binding).getType(); } catch (DOMException e) { type = e.getProblem(); } @@ -1872,7 +1873,7 @@ public class CPPVisitor { return op.getType().getReturnType(); } } - } catch(DOMException e) { + } catch (DOMException e) { return e.getProblem(); } } else if (binding instanceof ITypedef) { @@ -1965,7 +1966,7 @@ public class CPPVisitor { IType type = getExpressionType(((IASTUnaryExpression)expression).getOperand()); while (type instanceof ITypedef) { try { - type = ((ITypeContainer)type).getType(); + type = ((ITypedef) type).getType(); } catch (DOMException e) { break; } @@ -1976,7 +1977,7 @@ public class CPPVisitor { if (operator != null) { return operator.getType().getReturnType(); } - } catch(DOMException de) { + } catch (DOMException de) { return de.getProblem(); } } @@ -2063,7 +2064,7 @@ public class CPPVisitor { return ((IPointerType)t).getType(); else if (t instanceof IArrayType) return ((IArrayType)t).getType(); - } catch(DOMException e) { + } catch (DOMException e) { } } else if (expression instanceof IGNUASTCompoundStatementExpression) { IASTCompoundStatement compound = ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(); @@ -2329,7 +2330,7 @@ public class CPPVisitor { return !(tp.getReturnType() instanceof ICPPReferenceType); } } - } catch(DOMException de) { + } catch (DOMException de) { // fall-through } }