Skip to content

class Crystal::TypeDeclarationVisitor
inherits Crystal::SemanticVisitor

In this pass we check type declarations like:

@x : Int32
@@x : Int32
$x : Int32

In this way we declare their type before the "main" code.

This allows to put "main" code before these declarations, so order matters less in the end.

This visitor also processes the following:

  • C struct/union fields
  • fun declarations
  • alias declarations

We do this now because in a previous pass, TopLevelVisitor declared all types so now we can search them and always find them, not needing any kind of forward referencing.

Class methods

.new(mod, instance_vars : Hash(Type, Hash(String, TypeDeclarationWithLocation)))

View source

Methods

#add_external(external : External)

View source

#declare_c_struct_or_union_field(node)

View source

#declare_c_struct_or_union_field(type, field_name, var, location)

View source

#declare_class_var(node, var, uninitialized)

View source

#declare_instance_var(owner, node, var)

View source

#declare_instance_var(node, var)

View source

#include_c_struct(node)

View source

#visit(node : ExternalVar)

View source

#visit(node : FunDef)

View source

#visit(node : TypeDeclaration)

View source

#visit(node : LibDef)

View source

#visit(node : Assign)

View source

#visit(node : ProcLiteral)

View source

#visit(node : Include)

View source

#visit(node : Alias)

View source