1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

fix handling of particular type of problem binding in KnR style function declarations

This commit is contained in:
Andrew Ferguson 2007-03-19 12:08:51 +00:00
parent ff9b1c4616
commit 00ebcad325
3 changed files with 31 additions and 7 deletions

View file

@ -15,6 +15,8 @@ import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -72,4 +74,14 @@ public class CFunctionTests extends PDOMTestBase {
assertTrue(((IFunction) bindings[0]).takesVarArgs());
}
public void testKnRStyleFunctionWithProblemParameters() throws Exception {
IBinding[] bindings = findQualifiedName(pdom, "KnRfunctionWithProblemParameters");
assertEquals(1, bindings.length);
IFunction f= (IFunction) bindings[0];
IParameter[] params= f.getParameters();
assertEquals(3, params.length);
assertNull(params[0].getType()); // its a problem binding in the DOM
assertTrue(params[1].getType() instanceof ICBasicType);
assertTrue(params[2].getType() instanceof ICBasicType);
}
}

View file

@ -18,4 +18,13 @@ void spin() {
normalCDeclaration2();
forwardCDeclaration();
}
// p1 is a particular type of problem binding as it
// has no corresponding declarator
void KnRfunctionWithProblemParameters(p1,p2,c)
long p2;
int c;
{
}

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
@ -52,12 +53,14 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter {
db.putInt(record + NEXT_PARAM, 0);
try {
IType type = param.getType();
while(type instanceof ITypedef)
type = ((ITypedef)type).getType();
if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
if(!(param instanceof IProblemBinding)) {
IType type = param.getType();
while(type instanceof ITypedef)
type = ((ITypedef)type).getType();
if (type != null) {
PDOMNode typeNode = getLinkageImpl().addType(this, type);
db.putInt(record + TYPE, typeNode != null ? typeNode.getRecord() : 0);
}
}
} catch(DOMException e) {
throw new CoreException(Util.createStatus(e));