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

Bug 452416 - Move takesVarArgs() up from ICPPFunctionType to

IFunctionType

Change-Id: Ifd0cf6c4ca026587f2bbccfbc3d7f849c95b92de
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-02-09 03:12:19 -05:00 committed by Gerrit Code Review @ Eclipse.org
parent 34c84eba3c
commit fd11d42d89
8 changed files with 48 additions and 10 deletions

View file

@ -7574,4 +7574,12 @@ public class AST2Tests extends AST2TestBase {
public void testAtomicBuiltin_bug456131() throws Exception {
parseAndCheckBindings(true);
}
// void waldo(...);
public void testVariadicCFunction_452416() throws Exception {
String code= getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, false /* not C++ */);
IFunction waldo = bh.assertNonProblem("waldo");
assertTrue(waldo.getType().takesVarArgs());
}
}

View file

@ -25,4 +25,10 @@ public interface IFunctionType extends IType {
* ISO C99 6.7.5.3, ISO C++98 8.3.4-3
*/
public IType[] getParameterTypes();
/**
* Whether the function type takes variable number of arguments.
* @since 5.9
*/
public boolean takesVarArgs();
}

View file

@ -46,6 +46,7 @@ public interface ICPPFunctionType extends IFunctionType {
* Whether the function type takes variable number of arguments.
* @since 5.2
*/
@Override
public boolean takesVarArgs();
/**

View file

@ -22,10 +22,16 @@ import org.eclipse.core.runtime.CoreException;
public class CFunctionType implements IFunctionType, ISerializableType {
private final IType[] parameters;
private final IType returnType;
private final boolean takesVarargs;
public CFunctionType(IType returnType, IType[] types) {
public CFunctionType(IType returnType, IType[] parameters) {
this(returnType, parameters, false);
}
public CFunctionType(IType returnType, IType[] parameters, boolean takesVarargs) {
this.returnType = returnType;
this.parameters = types;
this.parameters = parameters;
this.takesVarargs = takesVarargs;
}
@Override
@ -75,9 +81,10 @@ public class CFunctionType implements IFunctionType, ISerializableType {
@Override
public void marshal(ITypeMarshalBuffer buffer) throws CoreException {
short firstBytes = ITypeMarshalBuffer.FUNCTION_TYPE;
if (takesVarargs) firstBytes |= ITypeMarshalBuffer.FLAG1;
int len= parameters.length & 0xffff;
int codedLen= len * ITypeMarshalBuffer.FIRST_FLAG;
int codedLen= len * ITypeMarshalBuffer.FLAG2;
if (codedLen < ITypeMarshalBuffer.LAST_FLAG) {
firstBytes |= codedLen;
buffer.putShort(firstBytes);
@ -98,13 +105,19 @@ public class CFunctionType implements IFunctionType, ISerializableType {
if (((firstBytes & ITypeMarshalBuffer.LAST_FLAG) != 0)) {
len= buffer.getInt();
} else {
len= (firstBytes & (ITypeMarshalBuffer.LAST_FLAG - 1)) / ITypeMarshalBuffer.FIRST_FLAG;
len= (firstBytes & (ITypeMarshalBuffer.LAST_FLAG - 1)) / ITypeMarshalBuffer.FLAG2;
}
IType rt= buffer.unmarshalType();
IType[] pars= new IType[len];
for (int i = 0; i < pars.length; i++) {
pars[i]= buffer.unmarshalType();
}
return new CFunctionType(rt, pars);
return new CFunctionType(rt, pars,
(firstBytes & ITypeMarshalBuffer.FLAG1) != 0); // takes varargs
}
@Override
public boolean takesVarArgs() {
return takesVarargs;
}
}

View file

@ -1342,7 +1342,9 @@ public class CVisitor extends ASTQueries {
IType[] pTypes = getParmTypes(declarator);
returnType = setupPointerChain(declarator.getPointerOperators(), returnType);
IType type = new CFunctionType(returnType, pTypes);
boolean takesVarargs = declarator instanceof IASTStandardFunctionDeclarator &&
((IASTStandardFunctionDeclarator) declarator).takesVarArgs();
IType type = new CFunctionType(returnType, pTypes, takesVarargs);
IASTDeclarator nested = declarator.getNestedDeclarator();
if (nested != null) {

View file

@ -74,8 +74,9 @@ public class CCompositesFactory extends AbstractCompositeFactory {
IType r2= getCompositeType(r);
IType[] p= ft.getParameterTypes();
IType[] p2= getCompositeTypes(p);
boolean takesVarargs = ft.takesVarArgs();
if (r != r2 || p != p2) {
return new CFunctionType(r2, p2);
return new CFunctionType(r2, p2, takesVarargs);
}
return ft;
}

View file

@ -257,10 +257,11 @@ public class PDOM extends PlatformObject implements IPDOM {
* 180.0 - Internal types of enumerators, bug 446711.
* 180.1 - Storing types of unknown members, bug 447728.
* 180.2 - Do not apply significant macros to source files, bug 450888.
* 181.0 - C function type with varargs, bug 452416.
*/
private static final int MIN_SUPPORTED_VERSION= version(180, 2);
private static final int MAX_SUPPORTED_VERSION= version(180, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(180, 2);
private static final int MIN_SUPPORTED_VERSION= version(181, 0);
private static final int MAX_SUPPORTED_VERSION= version(181, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(181, 0);
private static int version(int major, int minor) {
return (major << 16) + minor;

View file

@ -58,4 +58,10 @@ public class C99FunctionType implements IFunctionType {
}
}
@Override
public boolean takesVarArgs() {
// Not implemented
return false;
}
}