mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Allow expansion with typeids in fold expression
This commit is contained in:
parent
a5d51f2def
commit
56e5da5aa5
2 changed files with 55 additions and 0 deletions
|
@ -186,4 +186,40 @@ public class FoldExpressionTests extends AST2CPPTestBase {
|
||||||
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration();
|
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration();
|
||||||
IASTProblemExpression e1 = getExpressionOfStatement(fdef, 0);
|
IASTProblemExpression e1 = getExpressionOfStatement(fdef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template <typename T> struct predicate {
|
||||||
|
// static constexpr bool evaluated = true;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template<bool arg> struct condition {
|
||||||
|
// static constexpr bool value = arg;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template<typename... TP>
|
||||||
|
// struct fold_condition {
|
||||||
|
// static constexpr bool value = condition<(predicate<TP>::evaluated && ...)>::value;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// constexpr bool result = fold_condition<int, double>::value;
|
||||||
|
public void testFoldExpressionInClassTemplateArguments() throws Exception {
|
||||||
|
BindingAssertionHelper helper = getAssertionHelper();
|
||||||
|
helper.assertVariableValue("result", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T1> constexpr bool predicate = true;
|
||||||
|
//
|
||||||
|
// template<bool arg> struct condition {
|
||||||
|
// static constexpr bool value = arg;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template<typename... TP>
|
||||||
|
// struct fold_condition {
|
||||||
|
// static constexpr bool value = condition<(predicate<TP> && ...)>::value;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// constexpr bool result = fold_condition<int, double>::value;
|
||||||
|
public void testFoldExpressionInVariableTemplateArguments() throws Exception {
|
||||||
|
BindingAssertionHelper helper = getAssertionHelper();
|
||||||
|
helper.assertVariableValue("result", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,17 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitDestructorName;
|
import org.eclipse.cdt.core.dom.ast.IASTImplicitDestructorName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
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.ICPPASTFoldExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFoldExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPEvaluation;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPEvaluation;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.DestructorCallCollector;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.DestructorCallCollector;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFoldExpression;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFoldExpression;
|
||||||
|
@ -103,6 +106,7 @@ public class CPPASTFoldExpression extends ASTNode implements ICPPASTFoldExpressi
|
||||||
public UnexpandedParameterPackCounter() {
|
public UnexpandedParameterPackCounter() {
|
||||||
super(false);
|
super(false);
|
||||||
shouldVisitExpressions = true;
|
shouldVisitExpressions = true;
|
||||||
|
shouldVisitTypeIds = true;
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +126,21 @@ public class CPPASTFoldExpression extends ASTNode implements ICPPASTFoldExpressi
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int visit(IASTTypeId typeId) {
|
||||||
|
IType type = CPPVisitor.createType(typeId);
|
||||||
|
if (type instanceof ICPPTemplateParameter templateParameter) {
|
||||||
|
if (templateParameter.isParameterPack()) {
|
||||||
|
++count;
|
||||||
|
} else {
|
||||||
|
boolean notParameterPack = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
boolean notTemplateParameter = true;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countUnexpandedParameterPacks(IASTExpression e) {
|
private int countUnexpandedParameterPacks(IASTExpression e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue