class Crystal::TypeGuessVisitor

Overview

Guess the type of class and instance variables from assignments to them.

Defined in:

compiler/crystal/semantic/type_guess_visitor.cr

Constructors

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

Constructor Detail

def self.new(mod, explicit_instance_vars : Hash(Type, Hash(String, TypeDeclarationWithLocation)), guessed_instance_vars : Hash(Type, Hash(String, InstanceVarTypeInfo)), initialize_infos : Hash(Type, Array(InitializeInfo)), instance_vars_outside : Hash(Type, Array(String)), errors : Hash(Type, Hash(String, Error))) #

[View source]

Instance Method Detail

def add_instance_var_type_info(vars, name, type : Type, node) #

[View source]
def add_to_initialize_info(name) #

[View source]
def add_type_info(vars, name, type, node) #

[View source]
def args_hash #

[View source]
def check_can_be_stored(node, type) #

[View source]
def check_has_self(node) #

[View source]
def check_var_is_self(node : Var) #

[View source]

[View source]
def current_type #
Description copied from class Crystal::SemanticVisitor

At every point there's a current type. In the beginning this is the Program (top-level), but when a class definition is visited this changes to that type, and so on.


[View source]

[View source]
def gather_returns(node) #

[View source]
def guess_array_literal_element_types(node) #

[View source]
def guess_from_two(type1, type2, is_or = false) #

[View source]
def guess_hash_literal_key_value_types(node : HashLiteral) #

[View source]
def guess_type(node : NumberLiteral) #

[View source]
def guess_type(node : CharLiteral) #

[View source]
def guess_type(node : BoolLiteral) #

[View source]
def guess_type(node : NilLiteral) #

[View source]
def guess_type(node : StringLiteral) #

[View source]
def guess_type(node : StringInterpolation) #

[View source]
def guess_type(node : SymbolLiteral) #

[View source]
def guess_type(node : ArrayLiteral) #

[View source]
def guess_type(node : HashLiteral) #

[View source]
def guess_type(node : RangeLiteral) #

[View source]
def guess_type(node : RegexLiteral) #

[View source]
def guess_type(node : TupleLiteral) #

[View source]
def guess_type(node : NamedTupleLiteral) #

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

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

[View source]
def guess_type(node : Cast) #

[View source]
def guess_type(node : NilableCast) #

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

[View source]
def guess_type(node : Var) #

[View source]
def guess_type(node : InstanceVar) #

[View source]
def guess_type(node : BinaryOp) #

[View source]
def guess_type(node : If) #

[View source]
def guess_type(node : Unless) #

[View source]
def guess_type(node : Case) #

[View source]
def guess_type(node : Path) #

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

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

[View source]
def guess_type(node : Not) #

[View source]
def guess_type(node : IsA) #

[View source]
def guess_type(node : RespondsTo) #

[View source]
def guess_type(node : SizeOf) #

[View source]
def guess_type(node : InstanceSizeOf) #

[View source]
def guess_type(node : AlignOf) #

[View source]
def guess_type(node : InstanceAlignOf) #

[View source]
def guess_type(node : OffsetOf) #

[View source]
def guess_type(node : Nop) #

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

[View source]
def guess_type_call_lib_fun(node) #

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

[View source]
def guess_type_call_pointer_malloc_two_args(node) #

If it's Pointer.malloc(size, value), infer element type from value to T and then infer to Pointer(T)


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

Guess type from T.method, where T is a Path and method solves to a method with a type annotation (use the type annotation)


[View source]
def guess_type_from_class_method(obj_type, node : Call) #

[View source]
def guess_type_from_class_method_impl(obj_type : Crystal::Type | Nil, node : Call) #

[View source]
def guess_type_from_method(obj_type, node : Call) #

[View source]
def guess_type_from_method_impl(obj_type, node : Call) #

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

[View source]

[View source]
def lookup_type?(node, root = nil, self_type = nil) #

[View source]
def lookup_type_no_check?(node) #

[View source]
def lookup_type_var?(node, root = current_type) #

[View source]
def process_assign(target, value) #

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

[View source]
def process_assign_class_var(target, value) #

[View source]
def process_assign_instance_var(owner, target, value) #

[View source]
def process_assign_instance_var(target, value) #

[View source]
def process_lib_out(owner, target, type) #

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

[View source]
def process_uninitialized_instance_var(owner, target, value) #

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

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

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

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

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

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

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

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

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

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

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

[View source]

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

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

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

[View source]