1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Patch for 162581, by Andrew Ferguson, stack overflow in AST/PDOM.

This commit is contained in:
Markus Schorn 2006-11-08 09:30:17 +00:00
parent cc1407df9d
commit 4c73232e1c
2 changed files with 68 additions and 51 deletions

View file

@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -50,9 +51,11 @@ import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory; import org.eclipse.cdt.internal.core.dom.bid.IBindingIdentityFactory;
import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity; import org.eclipse.cdt.internal.core.dom.bid.ILocalBindingIdentity;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant; import org.eclipse.cdt.internal.core.pdom.dom.FindBindingByLinkageConstant;
import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding; import org.eclipse.cdt.internal.core.pdom.dom.FindEquivalentBinding;
@ -119,7 +122,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
return null; return null;
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
if (binding == null || binding instanceof IProblemBinding) if (binding == null || binding instanceof IProblemBinding)
// Can't tell what it is // Can't tell what it is
return null; return null;
@ -134,7 +137,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
PDOMNode parent = getAdaptedParent(binding); PDOMNode parent = getAdaptedParent(binding);
if (parent == null) if (parent == null)
return null; return null;
if (binding instanceof ICPPField && parent instanceof PDOMCPPClassType) if (binding instanceof ICPPField && parent instanceof PDOMCPPClassType)
pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, (ICPPField) binding); pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, (ICPPField) binding);
else if (binding instanceof ICPPVariable && !(binding.getScope() instanceof CPPBlockScope)) { else if (binding instanceof ICPPVariable && !(binding.getScope() instanceof CPPBlockScope)) {
@ -289,7 +292,6 @@ class PDOMCPPLinkage extends PDOMLinkage {
if (origBinding != null) if (origBinding != null)
return adaptBinding(origBinding); return adaptBinding(origBinding);
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
IASTName[] names = ((ICPPASTQualifiedName)name).getNames(); IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
if (names.length == 1) if (names.length == 1)
@ -317,7 +319,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
// reference // reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
return resolveFunctionCall((IASTIdExpression)parent, name, (IASTFunctionCallExpression) eParent); if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
return resolveFunctionCall((IASTFunctionCallExpression) eParent, (IASTIdExpression) parent, name);
}
} else { } else {
int constant = (name.getParent() instanceof ICPPASTQualifiedName int constant = (name.getParent() instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName)name.getParent()).getLastName() != name) && ((ICPPASTQualifiedName)name.getParent()).getLastName() != name)
@ -331,7 +335,6 @@ class PDOMCPPLinkage extends PDOMLinkage {
getIndex().accept(finder); getIndex().accept(finder);
PDOMBinding result = finder.getResult(); PDOMBinding result = finder.getResult();
return result; return result;
} else if (parent instanceof ICPPASTNamespaceAlias) { } else if (parent instanceof ICPPASTNamespaceAlias) {
FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACE); FindBindingByLinkageConstant finder = new FindBindingByLinkageConstant(this, name.toCharArray(), CPPNAMESPACE);
getIndex().accept(finder); getIndex().accept(finder);
@ -340,12 +343,12 @@ class PDOMCPPLinkage extends PDOMLinkage {
ICPPASTFieldReference ref = (ICPPASTFieldReference) parent; ICPPASTFieldReference ref = (ICPPASTFieldReference) parent;
IASTExpression exp = ref.getFieldOwner(); IASTExpression exp = ref.getFieldOwner();
if(exp instanceof IASTIdExpression) { if(exp instanceof IASTIdExpression) {
IASTIdExpression id = (IASTIdExpression) exp; IASTIdExpression fieldOwner = (IASTIdExpression) exp;
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
IASTFunctionCallExpression exp2 = (IASTFunctionCallExpression) eParent; if(name.getPropertyInParent().equals(IASTFieldReference.FIELD_NAME)) {
return resolveFunctionCall(id, name, exp2); return resolveFunctionCall((IASTFunctionCallExpression) eParent, fieldOwner, name);
}
} }
} }
} }
@ -353,10 +356,16 @@ class PDOMCPPLinkage extends PDOMLinkage {
return null; return null;
} }
/**
* Read type information from the AST or null if the types could not be determined
* @param paramExp the parameter expression to get types for (null indicates void function/method)
* @return an array of types or null if types could not be determined (because of missing semantic information in the AST)
*/
public IType[] getTypes(IASTExpression paramExp) { public IType[] getTypes(IASTExpression paramExp) {
IType[] types; IType[] types = null;
if(paramExp==null) {
types = new IType[0]; if(paramExp==null) { // void function/method
types = new IType[0];
} else { } else {
if(paramExp instanceof IASTExpressionList) { if(paramExp instanceof IASTExpressionList) {
IASTExpressionList list = (IASTExpressionList) paramExp; IASTExpressionList list = (IASTExpressionList) paramExp;
@ -372,10 +381,14 @@ class PDOMCPPLinkage extends PDOMLinkage {
ICPPASTNewExpression exp3 = (ICPPASTNewExpression) paramExp; ICPPASTNewExpression exp3 = (ICPPASTNewExpression) paramExp;
IType type = exp3.getExpressionType(); IType type = exp3.getExpressionType();
types = new IType[] {new CPPPointerType(type)}; types = new IType[] {new CPPPointerType(type)};
} else { } else if(paramExp instanceof CPPASTIdExpression) {
types = new IType[]{paramExp.getExpressionType()}; IBinding nameBinding = ((CPPASTIdExpression)paramExp).getName().resolveBinding();
if(nameBinding instanceof CPPVariable) {
types = new IType[] {((CPPVariable)nameBinding).getType()};
}
} }
} }
return types; return types;
} }
@ -384,39 +397,39 @@ class PDOMCPPLinkage extends PDOMLinkage {
* *
* (It does work though) * (It does work though)
*/ */
public PDOMBinding resolveFunctionCall(IASTIdExpression id, IASTName name, IASTFunctionCallExpression exp2) public PDOMBinding resolveFunctionCall(IASTFunctionCallExpression callExp, IASTIdExpression id, IASTName name) throws CoreException, DOMException {
throws CoreException, DOMException { IASTExpression paramExp = callExp.getParameterExpression();
IASTExpression paramExp = exp2.getParameterExpression();
ILocalBindingIdentity bid = null;
IType[] types = getTypes(paramExp); IType[] types = getTypes(paramExp);
if(types!=null) {
IBinding parentBinding = id.getName().getBinding(); IBinding parentBinding = id.getName().getBinding();
if(parentBinding == null) { ILocalBindingIdentity bid = null;
bid = new CPPBindingIdentity.Holder( if(parentBinding == null) { // filescope
new String(name.toCharArray()),
CPPFUNCTION,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(this, bid);
getIndex().accept(feb);
return feb.getResult();
} else if(parentBinding instanceof ICPPVariable) {
ICPPVariable v = (ICPPVariable) parentBinding;
IType type = v.getType();
if(type instanceof PDOMBinding) {
bid = new CPPBindingIdentity.Holder( bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()), new String(name.toCharArray()),
CPPMETHOD, CPPFUNCTION,
types); types);
FindEquivalentBinding feb = new FindEquivalentBinding(this, bid); FindEquivalentBinding feb = new FindEquivalentBinding(this, bid);
try { getIndex().accept(feb);
((PDOMBinding)type).accept(feb); return feb.getResult();
} catch (CoreException e) { } else if(parentBinding instanceof ICPPVariable) {
if (e.getStatus().equals(Status.OK_STATUS)) { ICPPVariable v = (ICPPVariable) parentBinding;
return feb.getResult(); IType type = v.getType();
} if(type instanceof PDOMBinding) {
else { bid = new CPPBindingIdentity.Holder(
throw e; new String(name.toCharArray()),
CPPMETHOD,
types);
FindEquivalentBinding feb = new FindEquivalentBinding(this, bid);
try {
((PDOMBinding)type).accept(feb);
} catch (CoreException e) {
if (e.getStatus().equals(Status.OK_STATUS)) {
return feb.getResult();
}
else {
throw e;
}
} }
} }
} }

View file

@ -152,16 +152,20 @@ class PDOMCPPNamespace extends PDOMCPPBinding
// reference // reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes( if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
((IASTFunctionCallExpression)eParent).getParameterExpression() IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes(
); ((IASTFunctionCallExpression)eParent).getParameterExpression()
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder( );
new String(name.toCharArray()), if(types!=null) {
PDOMCPPLinkage.CPPFUNCTION, ILocalBindingIdentity bid = new CPPBindingIdentity.Holder(
types); new String(name.toCharArray()),
FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid); PDOMCPPLinkage.CPPFUNCTION,
getIndex().accept(feb); types);
return feb.getResult(); FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid);
getIndex().accept(feb);
return feb.getResult();
}
}
} else { } else {
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(), FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(),
(name.getParent() instanceof ICPPASTQualifiedName (name.getParent() instanceof ICPPASTQualifiedName