MCPcopy Create free account
hub / github.com/compilets/compilets / strictCastExpression

Function strictCastExpression

src/cpp-syntax-utils.ts:151–168  ·  view source on GitHub ↗
(expr: Expression, target: Type)

Source from the content-addressed store, hash-verified

149 * target type.
150 */
151export 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.

Callers 1

castExpressionFunction · 0.85

Calls 4

printExpressionValueFunction · 0.90
castExpressionFunction · 0.85
isCppgcMemberMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected