mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 10:25:32 +02:00
Bug 468033 - Writing Variadic Templates with ASTWriter
Change-Id: If724d328e99dfe3e1c0974025c4e517511cbfa25
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
(cherry picked from commit 216f842984
)
This commit is contained in:
parent
e51f7256e5
commit
fdbe2a4543
4 changed files with 42 additions and 4 deletions
|
@ -17,3 +17,18 @@ template<typename T> struct S
|
|||
};
|
||||
template<typename T> using Alias = S<T>;
|
||||
Alias<int> sInt;
|
||||
|
||||
//!Variadic Function Template
|
||||
//%CPP
|
||||
template<typename T, typename... Args>
|
||||
void f(T t, Args... args)
|
||||
{
|
||||
f(args...);
|
||||
}
|
||||
|
||||
//!Variadic Class Template
|
||||
//%CPP
|
||||
template<typename... Args> struct S
|
||||
{
|
||||
static const int size = sizeof...(Args);
|
||||
};
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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){
|
||||
|
|
Loading…
Add table
Reference in a new issue