# stage2: rework AstGen for switch expressions · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/2a1dd174cdb3a084eef295613b03e94be4d843b9)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 2a1dd174cdb3a084eef295613b03e94be4d843b9

Requested commit: 2a1dd174cdb3a084eef295613b03e94be4d843b9

Commit: 2a1dd174cdb3a084eef295613b03e94be4d843b9

Tree: 49be90404a7d3471aac6f3ab1ebe864ca438629f

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: rework AstGen for switch expressions

The switch_br ZIR instructions are now switch_block instructions. This
avoids a pointless block always surrounding a switchbr in emitted ZIR
code.

Introduce typeof_elem ZIR instruction for getting the type of the
element of a pointer value in 1 instruction.

Change typeof to be un_node, not un_tok.

Introduce switch_capture ZIR instructions for obtaining the capture
value of switch prongs.

Introduce Sema.resolveBody for when you want to extract a *Inst out of a
block and you know that there is only going to be 1 break from it.

What's not working yet: AstGen does not correctly elide
store instructions when it turns out that the result location does not
need to be used as a pointer.

Also Sema validation code for duplicate switch items is not yet
implemented.

```

## Parents

- [195ddab2be938c1201767909d39106cdf99fd07e](https://git.cafe/gitcafe/zig/commit/195ddab2be938c1201767909d39106cdf99fd07e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/2a1dd174cdb3a084eef295613b03e94be4d843b9?format=markdown)
