mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-06 15:55:47 +02:00
Bug 468033 - Writing Variadic Templates with ASTWriter
Change-Id: If724d328e99dfe3e1c0974025c4e517511cbfa25 Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
parent
8328943db8
commit
216f842984
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>;
|
template<typename T> using Alias = S<T>;
|
||||||
Alias<int> sInt;
|
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.IASTPointerOperator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
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.ICPPASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator.RefQualifier;
|
||||||
|
@ -63,6 +64,8 @@ public class DeclaratorWriter extends NodeWriter {
|
||||||
writeFieldDeclarator((IASTFieldDeclarator) declarator);
|
writeFieldDeclarator((IASTFieldDeclarator) declarator);
|
||||||
} else if (declarator instanceof ICASTKnRFunctionDeclarator) {
|
} else if (declarator instanceof ICASTKnRFunctionDeclarator) {
|
||||||
writeCKnRFunctionDeclarator((ICASTKnRFunctionDeclarator) declarator);
|
writeCKnRFunctionDeclarator((ICASTKnRFunctionDeclarator) declarator);
|
||||||
|
} else if (declarator instanceof ICPPASTDeclarator) {
|
||||||
|
writeCPPDeclarator((ICPPASTDeclarator) declarator);
|
||||||
} else {
|
} else {
|
||||||
writeDefaultDeclarator(declarator);
|
writeDefaultDeclarator(declarator);
|
||||||
}
|
}
|
||||||
|
@ -319,4 +322,11 @@ public class DeclaratorWriter extends NodeWriter {
|
||||||
protected void writeKnRParameterNames(ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) {
|
protected void writeKnRParameterNames(ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) {
|
||||||
writeNodeList(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.ICPPASTFieldReference;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
|
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.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.ICPPASTSimpleTypeConstructorExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||||
|
@ -154,6 +155,8 @@ public class ExpressionWriter extends NodeWriter{
|
||||||
writeSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression) expression);
|
writeSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression) expression);
|
||||||
} else if (expression instanceof ICPPASTLambdaExpression) {
|
} else if (expression instanceof ICPPASTLambdaExpression) {
|
||||||
writeLambdaExpression((ICPPASTLambdaExpression) expression);
|
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$
|
return ALIGNOF_OP + "("; //$NON-NLS-1$
|
||||||
case IASTTypeIdExpression.op_typeof:
|
case IASTTypeIdExpression.op_typeof:
|
||||||
return TYPEOF_OP;
|
return TYPEOF_OP;
|
||||||
|
case IASTTypeIdExpression.op_sizeofParameterPack:
|
||||||
|
return SIZEOF_PARAMETER_PACK_OP + "("; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown TypeId Type"); //$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);
|
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) {
|
private void writeSimpleTypeTemplateParameter(ICPPASTSimpleTypeTemplateParameter simple) {
|
||||||
switch (simple.getParameterType()) {
|
switch (simple.getParameterType()) {
|
||||||
case ICPPASTSimpleTypeTemplateParameter.st_class:
|
case ICPPASTSimpleTypeTemplateParameter.st_class:
|
||||||
scribe.printStringSpace(Keywords.CLASS);
|
scribe.print(Keywords.CLASS);
|
||||||
break;
|
break;
|
||||||
case ICPPASTSimpleTypeTemplateParameter.st_typename:
|
case ICPPASTSimpleTypeTemplateParameter.st_typename:
|
||||||
scribe.printStringSpace(Keywords.TYPENAME);
|
scribe.print(Keywords.TYPENAME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (simple.isParameterPack()) {
|
||||||
|
scribe.print(VAR_ARGS);
|
||||||
|
}
|
||||||
|
scribe.printSpace();
|
||||||
visitNodeIfNotNull(simple.getName());
|
visitNodeIfNotNull(simple.getName());
|
||||||
|
|
||||||
if (simple.getDefaultType() != null){
|
if (simple.getDefaultType() != null){
|
||||||
|
|
Loading…
Add table
Reference in a new issue