1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +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;
@ -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,9 +356,15 @@ 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) {
if(paramExp==null) { // void function/method
types = new IType[0]; types = new IType[0];
} else { } else {
if(paramExp instanceof IASTExpressionList) { if(paramExp instanceof IASTExpressionList) {
@ -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,15 +397,14 @@ 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;
if(parentBinding == null) { // filescope
bid = new CPPBindingIdentity.Holder( bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()), new String(name.toCharArray()),
CPPFUNCTION, CPPFUNCTION,
@ -421,6 +433,7 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
} }
} }
}
return null; return null;
} }

View file

@ -152,9 +152,11 @@ class PDOMCPPNamespace extends PDOMCPPBinding
// reference // reference
IASTNode eParent = parent.getParent(); IASTNode eParent = parent.getParent();
if (eParent instanceof IASTFunctionCallExpression) { if (eParent instanceof IASTFunctionCallExpression) {
if(parent.getPropertyInParent().equals(IASTFunctionCallExpression.FUNCTION_NAME)) {
IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes( IType[] types = ((PDOMCPPLinkage)getLinkage()).getTypes(
((IASTFunctionCallExpression)eParent).getParameterExpression() ((IASTFunctionCallExpression)eParent).getParameterExpression()
); );
if(types!=null) {
ILocalBindingIdentity bid = new CPPBindingIdentity.Holder( ILocalBindingIdentity bid = new CPPBindingIdentity.Holder(
new String(name.toCharArray()), new String(name.toCharArray()),
PDOMCPPLinkage.CPPFUNCTION, PDOMCPPLinkage.CPPFUNCTION,
@ -162,6 +164,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding
FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid); FindEquivalentBinding feb = new FindEquivalentBinding(getLinkageImpl(), bid);
getIndex().accept(feb); getIndex().accept(feb);
return feb.getResult(); 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