|
13 | 13 | *******************************************************************************/
|
14 | 14 | package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
15 | 15 |
|
| 16 | +import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; |
| 17 | + |
16 | 18 | import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
17 | 19 | import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
18 | 20 | import org.eclipse.cdt.core.dom.ast.IASTNode;
|
| 21 | +import org.eclipse.cdt.core.dom.ast.IBinding; |
| 22 | +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; |
19 | 23 | import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
20 | 24 | import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTStaticAssertDeclaration;
|
21 | 25 | import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
22 | 26 | import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
| 27 | +import org.eclipse.cdt.internal.core.dom.parser.IntegralValue; |
| 28 | +import org.eclipse.cdt.internal.core.dom.parser.ProblemType; |
| 29 | +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalConditional; |
| 30 | +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; |
| 31 | +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecReturn; |
23 | 32 |
|
24 | 33 | public class CPPASTStaticAssertionDeclaration extends ASTNode
|
25 |
| - implements ICPPASTStaticAssertDeclaration, IASTAmbiguityParent { |
| 34 | + implements ICPPASTStaticAssertDeclaration, IASTAmbiguityParent, ICPPExecutionOwner { |
26 | 35 |
|
27 | 36 | private IASTExpression fCondition;
|
28 | 37 | private final ICPPASTLiteralExpression fMessage;
|
29 | 38 |
|
| 39 | + public static final ICPPEvaluation STATIC_ASSERT_FAILED = new EvalFixed(ProblemType.STATIC_ASSERT_FAILED, PRVALUE, |
| 40 | + IntegralValue.STATIC_ASSERT_FAILED_ERROR); |
| 41 | + |
30 | 42 | /**
|
31 | 43 | * Constructor for C++17 static_assert with only a condition.
|
32 | 44 | *
|
@@ -101,4 +113,21 @@ public void replace(IASTNode child, IASTNode other) {
|
101 | 113 | other.setPropertyInParent(child.getPropertyInParent());
|
102 | 114 | }
|
103 | 115 | }
|
| 116 | + |
| 117 | + @Override |
| 118 | + public ICPPExecution getExecution() { |
| 119 | + // Naturally this would be compilation error; simulate executing this statement via return with evaluation problem. |
| 120 | + // If no evaluation of condition is available, treat it as unsatisfied condition too. |
| 121 | + final ICPPEvaluation conditionExprEval = getCondition() instanceof ICPPASTExpression conditionExpr |
| 122 | + ? conditionExpr.getEvaluation() |
| 123 | + : CPPASTLiteralExpression.INT_ZERO.getEvaluation(); |
| 124 | + |
| 125 | + ICPPEvaluation conditionalEval = new EvalConditional(conditionExprEval, null, STATIC_ASSERT_FAILED, false, |
| 126 | + false, (IBinding) null); |
| 127 | + |
| 128 | + // ICPPExecution constexprIfExecution = new ExecIf(true, null, conditionExprEval, null, null, |
| 129 | + // new ExecReturn(STATIC_ASSERT_FAILED)); |
| 130 | + |
| 131 | + return new ExecReturn(conditionalEval); |
| 132 | + } |
104 | 133 | }
|
0 commit comments