1 | mut expr_type_sym := g.table.sym(g.unwrap_generic(node.expr_type)) |
2 | if mut expr_type_sym.info is ast.SumType { |
3 | dot := if node.expr_type.is_ptr() { '->' } else { '.' } |
4 | - if sym.info is ast.FnType { |
5 | - g.write('/* as */ (${styp})__as_cast(') |
6 | - } else { |
7 | - g.write('/* as */ *(${styp}*)__as_cast(') |
8 | + $if !msvc { |
9 | + if node.expr is ast.CallExpr { |
10 | + tmp_var := g.new_tmp_var() |
11 | + expr_styp := g.typ(node.expr_type) |
12 | + g.write('({ ${expr_styp} ${tmp_var} = ') |
13 | + g.expr(node.expr) |
14 | + g.write('; ') |
15 | + if sym.info is ast.FnType { |
16 | + g.write('/* as */ (${styp})__as_cast(') |
17 | + } else { |
18 | + g.write('/* as */ *(${styp}*)__as_cast(') |
19 | + } |
20 | + g.write(tmp_var) |
21 | + g.write(dot) |
22 | + g.write('_${sym.cname},') |
23 | + g.write(tmp_var) |
24 | + g.write(dot) |
25 | + sidx := g.type_sidx(unwrapped_node_typ) |
26 | + g.write('_typ, ${sidx}); }) /*expected idx: ${sidx}, name: ${sym.name} */ ') |
27 | + } else { |
28 | + if sym.info is ast.FnType { |
29 | + g.write('/* as */ (${styp})__as_cast(') |
30 | + } else { |
31 | + g.write('/* as */ *(${styp}*)__as_cast(') |
32 | + } |
33 | + g.write('(') |
34 | + g.expr(node.expr) |
35 | + g.write(')') |
36 | + g.write(dot) |
37 | + g.write('_${sym.cname},') |
38 | + g.write('(') |
39 | + g.expr(node.expr) |
40 | + g.write(')') |
41 | + g.write(dot) |
42 | + // g.write('typ, /*expected:*/$node.typ)') |
43 | + sidx := g.type_sidx(unwrapped_node_typ) |
44 | + g.write('_typ, ${sidx}) /*expected idx: ${sidx}, name: ${sym.name} */ ') |
45 | + } |
46 | + } $else { |
47 | + if sym.info is ast.FnType { |
48 | + g.write('/* as */ (${styp})__as_cast(') |
49 | + } else { |
50 | + g.write('/* as */ *(${styp}*)__as_cast(') |
51 | + } |
52 | + g.write('(') |
53 | + g.expr(node.expr) |
54 | + g.write(')') |
55 | + g.write(dot) |
56 | + g.write('_${sym.cname},') |
57 | + g.write('(') |
58 | + g.expr(node.expr) |
59 | + g.write(')') |
60 | + g.write(dot) |
61 | + // g.write('typ, /*expected:*/$node.typ)') |
62 | + sidx := g.type_sidx(unwrapped_node_typ) |
63 | + g.write('_typ, ${sidx}) /*expected idx: ${sidx}, name: ${sym.name} */ ') |
64 | } |
65 | - g.write('(') |
66 | - g.expr(node.expr) |
67 | - g.write(')') |
68 | - g.write(dot) |
69 | - g.write('_${sym.cname},') |
70 | - g.write('(') |
71 | - g.expr(node.expr) |
72 | - g.write(')') |
73 | - g.write(dot) |
74 | - // g.write('typ, /*expected:*/$node.typ)') |
75 | - sidx := g.type_sidx(unwrapped_node_typ) |
76 | - g.write('_typ, ${sidx}) /*expected idx: ${sidx}, name: ${sym.name} */ ') |
77 | |
78 | // fill as cast name table |
79 | for variant in expr_type_sym.info.variants { |
80 | |