class Crystal::TopLevelVisitor

Overview

In this pass we traverse the AST nodes to declare and process:

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".

Defined in:

compiler/crystal/semantic/top_level_visitor.cr

Instance Method Summary

Instance methods inherited from class Crystal::SemanticVisitor

check_allowed_in_lib(node, type = node.type.instance_type) check_allowed_in_lib, check_class_var_annotations check_class_var_annotations, check_declare_var_type(node, declared_type, variable_kind) check_declare_var_type, check_outside_exp(node, op) check_outside_exp, class_var_owner(node) class_var_owner, current_type : ModuleType current_type, current_type=(current_type : ModuleType) current_type=, end_visit_any(node) end_visit_any, eval_macro(node, &) eval_macro, expand_inline_macro(node, mode = nil, accept = true) expand_inline_macro, expand_macro(node, raise_on_missing_const = true, first_pass = false, accept = true)
expand_macro(the_macro, node, mode = nil, *, visibility : Visibility, accept = true, &)
expand_macro
, expand_macro_argument(node, expansion_scope) expand_macro_argument, expand_macro_arguments(call, expansion_scope) expand_macro_arguments, free_vars : Hash(String, TypeVar) | Nil free_vars, inside_exp? inside_exp?, interpret_enum_value(node : ASTNode, target_type : IntegerType | Nil = nil) interpret_enum_value, lookup_annotation(ann) lookup_annotation, lookup_type(node : ASTNode, free_vars = nil, find_root_generic_type_parameters = true) lookup_type, nesting_exp?(node) nesting_exp?, process_annotations(annotations, &) process_annotations, program : Program program, pushing_type(type : ModuleType, &) pushing_type, read_annotations read_annotations, scope : Type scope, scope=(scope : Type)
scope=(scope : Crystal::Type | Nil)
scope=
, scope? : Type | Nil scope?, validate_annotation(annotation_type, ann) validate_annotation, vars : MetaVars vars, vars=(vars : MetaVars) vars=, visit(node : Require)
visit(node : ClassDef)
visit(node : ModuleDef)
visit(node : AnnotationDef)
visit(node : EnumDef)
visit(node : LibDef)
visit(node : Include)
visit(node : Extend)
visit(node : Alias)
visit(node : Def)
visit(node : Macro)
visit(node : Annotation)
visit(node : Call)
visit(node : MacroExpression)
visit(node : MacroIf)
visit(node : MacroFor)
visit(node : MacroVerbatim)
visit(node : ExternalVar | Path | Generic | ProcNotation | Union | Metaclass | Self | TypeOf)
visit(node : ASTNode)
visit
, visit_any(node) visit_any

Constructor methods inherited from class Crystal::SemanticVisitor

new(program : Crystal::Program, vars : Hash(String, Crystal::MetaVar) = MetaVars.new) new

Instance methods inherited from class Crystal::Visitor

accept(node) accept, end_visit(node) end_visit, end_visit_any(node) end_visit_any, visit_any(node) visit_any

Instance methods inherited from class Reference

==(other : self)
==(other : JSON::Any)
==(other : YAML::Any)
==(other)
==
, dup dup, hash(hasher) hash, initialize initialize, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference) : Bool
same?(other : Nil)
same?
, to_s(io : IO) : Nil to_s

Constructor methods inherited from class Reference

new new, unsafe_construct(address : Pointer, *args, **opts) : self unsafe_construct

Class methods inherited from class Reference

pre_initialize(address : Pointer) pre_initialize

Instance methods inherited from class Object

! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other)
===
, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash
hash
, in?(collection : Object) : Bool
in?(*values : Object) : Bool
in?
, inspect(io : IO) : Nil
inspect : String
inspect
, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil!
not_nil!
, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String
to_json
, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil
to_pretty_json
, to_s(io : IO) : Nil
to_s : String
to_s
, to_yaml(io : IO) : Nil
to_yaml : String
to_yaml
, try(&) try, unsafe_as(type : T.class) forall T unsafe_as

Class methods inherited from class Object

from_json(string_or_io : String | IO, root : String)
from_json(string_or_io : String | IO)
from_json
, from_yaml(string_or_io : String | IO) from_yaml

Macros inherited from class Object

class_getter(*names, &block) class_getter, class_getter!(*names) class_getter!, class_getter?(*names, &block) class_getter?, class_property(*names, &block) class_property, class_property!(*names) class_property!, class_property?(*names, &block) class_property?, class_setter(*names) class_setter, def_clone def_clone, def_equals(*fields) def_equals, def_equals_and_hash(*fields) def_equals_and_hash, def_hash(*fields) def_hash, delegate(*methods, to object) delegate, forward_missing_to(delegate) forward_missing_to, getter(*names, &block) getter, getter!(*names) getter!, getter?(*names, &block) getter?, property(*names, &block) property, property!(*names) property!, property?(*names, &block) property?, setter(*names) setter

Instance Method Detail

def annotations_doc(annotations) #

[View source]
def attach_doc(type, node, annotations) #

[View source]
def check_ditto(node : Def | Assign | FunDef | Const | Macro, location : Location | Nil) : Nil #

[View source]
def check_type_is_type_container(scope, path) #

[View source]
def define_enum_none_question_method(enum_type, node) #

[View source]
def define_enum_question_method(enum_type, member, is_flags) #

[View source]
def has_hooks?(type_with_hooks) #

[View source]
def include_in(current_type, node, kind : HookKind) #

[View source]
def lookup_type_def(node : ASTNode) #

[View source]
def lookup_type_def_name_creating_modules(path : Path) #

[View source]
def lookup_type_def_scope(node : ASTNode, path : Path) #

[View source]
def new_expansions : Hash(Def, Def) #

These are new methods (values) that was created from initialize methods (keys)


[View source]
def parse_call_convention(ann, call_convention) #

[View source]
def process_def_annotations(node, annotations, &) #

[View source]
def process_finished_hooks #

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


[View source]
def run_hooks(type_with_hooks, current_type, kind : HookKind, node, call = nil) #

[View source]
def type_assign(target : Var, value, node) #

[View source]
def type_assign(target : Path, value, node) #

[View source]
def type_assign(target, value, node) #

[View source]
def visit(node : ClassDef) #

[View source]
def visit(node : ModuleDef) #

[View source]
def visit(node : AnnotationDef) #

[View source]
def visit(node : Alias) #

[View source]
def visit(node : Macro) #

[View source]
def visit(node : Arg) #

[View source]
def visit(node : Def) #

[View source]
def visit(node : Include) #

[View source]
def visit(node : Extend) #

[View source]
def visit(node : LibDef) #

[View source]
def visit(node : CStructOrUnionDef) #

[View source]
def visit(node : TypeDef) #

[View source]
def visit(node : EnumDef) #

[View source]
def visit(node : Expressions) #

[View source]
def visit(node : Assign) #

[View source]
def visit(node : VisibilityModifier) #

[View source]
def visit(node : ProcLiteral) #

[View source]
def visit(node : FunDef) #

[View source]
def visit(node : TypeDeclaration) #

[View source]
def visit(node : UninitializedVar) #

[View source]
def visit(node : MultiAssign) #

[View source]
def visit(node : Rescue) #

[View source]
def visit(node : Call) #

[View source]
def visit(node : ProcPointer) #

[View source]
def visit(node : Out) #

[View source]
def visit(node : Block) #

[View source]
def visit_enum_member(node, member, existed, enum_type, previous_counter = nil) #

[View source]
def visit_enum_members(node, members, existed, enum_type, previous_counter = nil) #

[View source]