Skip to content

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

.new(program : Program)

View source

Methods

#after_transform(node)

View source

#build_raise(msg : String, node : ASTNode)

View source

#check_arg_is_not_closure(node, message, arg)

View source

#check_args_are_not_closure(node, message)

View source

#compute_last_truthiness

View source

#false_literal

View source

#find_unreachable_parent(expanded)

View source

#flatten_collect(exp, exps)

View source

#has_enum_type?(type)

View source

#replace_unreachable_if_needed(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.

View source

#reset_last_status

View source

#simple_constant?(node, consts)

View source

#simple_constant?(node)

View source

#target_def_is_captured_block?(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).

View source

#transform(node : Call)

View source

#transform(node : Def)

View source

#transform(node : ClassDef)

View source

#transform(node : Include)

View source

#transform(node : Extend)

View source

#transform(node : Expressions)

View source

#transform(node : Case)

View source

#transform(node : Global)

View source

#transform(node : InstanceSizeOf)

View source

#transform(node : ExpandableNode)

View source

#transform(node : AssignWithRestriction)

View source

#transform(node : TypeOf)

View source

#transform(node : Primitive)

View source

#transform(node : CStructOrUnionDef)

View source

#transform(node : ProcPointer)

View source

#transform(node : ProcLiteral)

View source

#transform(node : Yield)

View source

#transform(node : While)

View source

#transform(node : If)

View source

#transform(node : IsA)

View source

#transform(node : RespondsTo)

View source

#transform(node : Cast)

View source

#transform(node : NilableCast)

View source

#transform(node : Assign)

View source

#transform(node : ExceptionHandler)

View source

#transform(node : TupleLiteral)

View source

#transform(node : NamedTupleLiteral)

View source

#transform(node : FunDef)

View source

#transform_is_a_or_responds_to

View source

#true_literal

View source

#untyped_expression(node, msg = nil)

View source

#var?(node)

View source