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¶
#check_ditto(node : Def | Assign | FunDef | Const | Macro, location : Location?) : Nil
¶
(node : Def | Assign | FunDef | Const | Macro, location : Location?) : Nil
#new_expansions : Array({original: Crystal::Def, expanded: Crystal::Def})
¶
: Array({original: Crystal::Def, expanded: Crystal::Def})
These are new
methods (expanded) that was created from initialize
methods (original)
#process_finished_hooks
¶
Turns all finished macros into expanded nodes, and adds them to the program