Skip to content

class Crystal::TopLevelVisitor
inherits Crystal::SemanticVisitor

In this pass we traverse the AST nodes to declare and process: - class - struct - module - include - extend - enum (checking their value, since these need to be numbers or simple math operations) - macro - def (without going inside them) - alias (without resolution) - constants (without checking their value) - macro calls (only surface macros, because we don't go inside defs) - lib and everything inside them - fun with body (without going inside them)

Macro calls are expanded, but only the first pass is done to them. This allows macros to define new classes and methods.

We also process @[Link] annotations.

After this pass we have completely defined the whole class hierarchy, including methods. After this point no new classes or methods can be introduced since in next passes we only go inside methods and top-level code, but we already analyzed top-level (surface) macros that could have expanded to class/method definitions.

Now that we know the whole hierarchy, when someone types Foo, we know whether Foo has subclasses or not and we can tag it as "virtual" (having subclasses), but that concept might disappear in the future and we'll make consider everything as "maybe virtual".

Methods

#annotations_doc(annotations)

View source

#attach_doc(type, node, annotations)

View source

#check_ditto(node : Def | Assign | FunDef | Const | Macro, location : Location?) : Nil

View source

#check_type_is_type_container(scope, path)

View source

#current_type_scope(node)

View source

#define_enum_none_question_method(enum_type, node)

View source

#define_enum_question_method(enum_type, member, is_flags)

View source

#include_in(current_type, node, kind)

View source

#lookup_type_def(node : ASTNode)

View source

#lookup_type_def_name(node : ASTNode)

View source

#lookup_type_def_name(path : Path)

View source

#lookup_type_def_name_creating_modules(path : Path)

View source

#new_expansions : Array({original: Crystal::Def, expanded: Crystal::Def})

These are new methods (expanded) that was created from initialize methods (original)

View source

#parse_call_convention(ann, call_convention)

View source

#process_def_annotations

View source

#process_finished_hooks

Turns all finished macros into expanded nodes, and adds them to the program

View source

#run_hooks(type_with_hooks, current_type, kind, node, call = nil)

View source

#type_assign(target : Path, value, node)

View source

#type_assign(target : Var, value, node)

View source

#type_assign(target, value, node)

View source

#visit(node : ClassDef)

View source

#visit(node : ModuleDef)

View source

#visit(node : AnnotationDef)

View source

#visit(node : Alias)

View source

#visit(node : Macro)

View source

#visit(node : Def)

View source

#visit(node : Include)

View source

#visit(node : Extend)

View source

#visit(node : LibDef)

View source

#visit(node : TypeDef)

View source

#visit(node : EnumDef)

View source

#visit(node : ProcLiteral)

View source

#visit(node : Expressions)

View source

#visit(node : Assign)

View source

#visit(node : Block)

View source

#visit(node : Out)

View source

#visit(node : Call)

View source

#visit(node : Rescue)

View source

#visit(node : MultiAssign)

View source

#visit(node : TypeDeclaration)

View source

#visit(node : FunDef)

View source

#visit(node : ProcPointer)

View source

#visit_enum_member(node, member, counter, all_value, overflow, **options)

View source

#visit_enum_members(node, members, counter, all_value, overflow, **options)

View source