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

Fix for 189299, stack overflow in name resolution, 2nd attempt.

This commit is contained in:
Markus Schorn 2007-06-20 07:05:13 +00:00
parent 2f007e8a06
commit ebe2158c23
3 changed files with 19 additions and 7 deletions

View file

@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
* @author jcamelon
*/
public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionContext {
private final static class RecursionResolvingBinding extends ProblemBinding {
final static class RecursionResolvingBinding extends ProblemBinding {
public RecursionResolvingBinding() {
super(null, IProblemBinding.SEMANTIC_RECURSION_IN_LOOKUP, CharArrayUtils.EMPTY);
}
@ -45,7 +45,7 @@ public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionCo
private static final char[] EMPTY_CHAR_ARRAY = {};
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final int MAX_RESOLUTION_DEPTH = 5;
static final int MAX_RESOLUTION_DEPTH = 5;
private IBinding binding = null;
private int fResolutionDepth= 0;

View file

@ -66,17 +66,20 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
private IASTNode [] templateArguments = null;
private IBinding binding = null;
private boolean resolving = false;
private int fResolutionDepth= 0;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
*/
public IBinding resolveBinding() {
if (binding == null && !resolving) {
if (binding == null) {
// protect for infinite recursion
resolving = true;
if (++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) {
binding= new CPPASTName.RecursionResolvingBinding(this);
}
else {
binding = CPPTemplates.createBinding( this );
resolving = false;
}
}
return binding;
@ -155,6 +158,7 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
*/
public void setBinding(IBinding binding) {
this.binding = binding;
fResolutionDepth= 0;
}
public void replace(IASTNode child, IASTNode other) {
@ -178,4 +182,9 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I
return false;
}
public void incResolutionDepth() {
if (binding == null && ++fResolutionDepth > CPPASTName.MAX_RESOLUTION_DEPTH) {
binding= new CPPASTName.RecursionResolvingBinding(this);
}
}
}

View file

@ -996,6 +996,9 @@ public class CPPVisitor {
if (name instanceof CPPASTName) {
((CPPASTName) name).incResolutionDepth();
}
else if (name instanceof CPPASTTemplateId) {
((CPPASTTemplateId) name).incResolutionDepth();
}
IBinding binding = name.getBinding();
if( binding == null ){
binding = CPPSemantics.resolveBinding( name );