class Crystal::CleanupTransformer
inherits Crystal::Transformer
¶
This visitor runs at the end and does some simplifications to the resulting AST node.
For example, it rewrites and if true; 1; else; 2; end
to a single 1
. It does
so for other "always true conditions", such as x.is_a?(Foo)
where x
can only
be of type Foo
. These simplifications are needed because the codegen would have no
idea on how to generate code for unreachable branches, because they have no type,
and for now the codegen only deals with typed nodes.
Class methods¶
Methods¶
#replace_unreachable_if_needed(node, expanded)
¶
(node, expanded)
If any of the types checked in case
is an enum, it can happen that
the unreachable can be reached by doing SomeEnum.new(some_value)
.
In that case we replace the Unreachable node with raise "..."
.
In the future we should disallow creating such values.
#target_def_is_captured_block?(arg : Call)
¶
(arg : Call)
Checks whether arg's target def has the following definition:
def f(&block)
block
end
That is, the def returns its captured block and does nothing else. An example is Proc.new(&block).