diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts index 7d68787a8a4..3bd0783b0c9 100644 --- a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts +++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts @@ -17,3 +17,18 @@ template struct S }; template using Alias = S; Alias sInt; + +//!Variadic Function Template +//%CPP +template +void f(T t, Args... args) +{ + f(args...); +} + +//!Variadic Class Template +//%CPP +template struct S +{ + static const int size = sizeof...(Args); +}; \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java index f5ee1c59b70..abd8f93abb4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPointer; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier; @@ -63,6 +64,8 @@ public class DeclaratorWriter extends NodeWriter { writeFieldDeclarator((IASTFieldDeclarator) declarator); } else if (declarator instanceof ICASTKnRFunctionDeclarator) { writeCKnRFunctionDeclarator((ICASTKnRFunctionDeclarator) declarator); + } else if (declarator instanceof ICPPASTDeclarator) { + writeCPPDeclarator((ICPPASTDeclarator) declarator); } else { writeDefaultDeclarator(declarator); } @@ -319,4 +322,11 @@ public class DeclaratorWriter extends NodeWriter { protected void writeKnRParameterNames(ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) { writeNodeList(parameterNames); } + + protected void writeCPPDeclarator(ICPPASTDeclarator declarator) { + if (declarator.declaresParameterPack()) { + scribe.print(VAR_ARGS); + } + writeDefaultDeclarator(declarator); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java index ab70bc5ce78..62a8b85797c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression; @@ -69,7 +70,7 @@ public class ExpressionWriter extends NodeWriter{ private static final String TYPEID_OP = "typeid ("; //$NON-NLS-1$ private static final String OPEN_BRACKET_OP = "("; //$NON-NLS-1$ private static final String SIZEOF_OP = "sizeof "; //$NON-NLS-1$ - private static final String SIZEOF_PARAMETER_PACK_OP = "sizeof... "; //$NON-NLS-1$ + private static final String SIZEOF_PARAMETER_PACK_OP = "sizeof..."; //$NON-NLS-1$ private static final String NOT_OP = "!"; //$NON-NLS-1$ private static final String TILDE_OP = "~"; //$NON-NLS-1$ private static final String AMPERSAND_OP = "&"; //$NON-NLS-1$ @@ -154,6 +155,8 @@ public class ExpressionWriter extends NodeWriter{ writeSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression) expression); } else if (expression instanceof ICPPASTLambdaExpression) { writeLambdaExpression((ICPPASTLambdaExpression) expression); + } else if (expression instanceof ICPPASTPackExpansionExpression) { + writePackExpansionExpression((ICPPASTPackExpansionExpression) expression); } } @@ -509,6 +512,8 @@ public class ExpressionWriter extends NodeWriter{ return ALIGNOF_OP + "("; //$NON-NLS-1$ case IASTTypeIdExpression.op_typeof: return TYPEOF_OP; + case IASTTypeIdExpression.op_sizeofParameterPack: + return SIZEOF_PARAMETER_PACK_OP + "("; //$NON-NLS-1$ } throw new IllegalArgumentException("Unknown TypeId Type"); //$NON-NLS-1$ } @@ -567,5 +572,10 @@ public class ExpressionWriter extends NodeWriter{ capture.getIdentifier().accept(visitor); } } + + private void writePackExpansionExpression(ICPPASTPackExpansionExpression expression) { + visitNodeIfNotNull(expression.getPattern()); + scribe.print(VAR_ARGS); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java index d4e09f4d925..d71de7fd3fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java @@ -70,13 +70,16 @@ public class TemplateParameterWriter extends NodeWriter { private void writeSimpleTypeTemplateParameter(ICPPASTSimpleTypeTemplateParameter simple) { switch (simple.getParameterType()) { case ICPPASTSimpleTypeTemplateParameter.st_class: - scribe.printStringSpace(Keywords.CLASS); + scribe.print(Keywords.CLASS); break; case ICPPASTSimpleTypeTemplateParameter.st_typename: - scribe.printStringSpace(Keywords.TYPENAME); + scribe.print(Keywords.TYPENAME); break; } - + if (simple.isParameterPack()) { + scribe.print(VAR_ARGS); + } + scribe.printSpace(); visitNodeIfNotNull(simple.getName()); if (simple.getDefaultType() != null){