(expr: Expression, target: Type)
| 149 | * target type. |
| 150 | */ |
| 151 | export function strictCastExpression(expr: Expression, target: Type): Expression { |
| 152 | const source = expr.type; |
| 153 | // Get value from cppgc smart pointers. |
| 154 | if ((source.isCppgcMember() && !target.isCppgcMember()) || |
| 155 | (source.isPersistent && !target.isPersistent)) { |
| 156 | return new CustomExpression(source, (ctx) => { |
| 157 | return `${printExpressionValue(expr, ctx)}.Get()`; |
| 158 | }); |
| 159 | } |
| 160 | // Create cppgc smart pointers. |
| 161 | if ((!source.isCppgcMember() && target.isCppgcMember()) || |
| 162 | (!source.isPersistent && target.isPersistent)) { |
| 163 | return new CustomExpression(source, (ctx) => { |
| 164 | return `${target.print(ctx)}(${expr.print(ctx)})`; |
| 165 | }); |
| 166 | } |
| 167 | return castExpression(expr, target); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Convert args to parameter types. |
no test coverage detected