From fd11d42d89d073278daed91eb645aedd09e70243 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Mon, 9 Feb 2015 03:12:19 -0500 Subject: [PATCH] Bug 452416 - Move takesVarArgs() up from ICPPFunctionType to IFunctionType Change-Id: Ifd0cf6c4ca026587f2bbccfbc3d7f849c95b92de Signed-off-by: Nathan Ridge --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 8 +++++++ .../cdt/core/dom/ast/IFunctionType.java | 6 +++++ .../core/dom/ast/cpp/ICPPFunctionType.java | 1 + .../core/dom/parser/c/CFunctionType.java | 23 +++++++++++++++---- .../internal/core/dom/parser/c/CVisitor.java | 4 +++- .../index/composite/c/CCompositesFactory.java | 3 ++- .../eclipse/cdt/internal/core/pdom/PDOM.java | 7 +++--- .../c99/bindings/C99FunctionType.java | 6 +++++ 8 files changed, 48 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 2475c998b30..2a8c6c41fdf 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -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()); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java index 5772caab0bc..12c09c0cc08 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunctionType.java @@ -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(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java index fbf9f9515ae..26999b2e0bc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunctionType.java @@ -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(); /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java index b50e0cb3f4b..0e7fd6e3276 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunctionType.java @@ -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; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 03ec6b5e14a..bd76dcc387e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java index a2520259234..4a66c0a08b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index d71d0ed93f0..793d0c393fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -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; diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java index dca26f8098a..f683d7f9127 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java @@ -58,4 +58,10 @@ public class C99FunctionType implements IFunctionType { } } + + @Override + public boolean takesVarArgs() { + // Not implemented + return false; + } }