Class: Yadriggy::Py::PyTypeChecker

Inherits:
RubyTypeChecker show all
Defined in:
lib/yadriggy/py/py_typechecker.rb

Constant Summary

Constants included from Yadriggy

DynType, Undef, VERSION, Void

Instance Method Summary collapse

Methods inherited from RubyTypeChecker

#bind_local_var, #get_call_expr_type, #get_name_type, #get_return_type, #type_args_and_block, #type_assert_params, #type_assert_subsume, #type_parameters

Methods inherited from TypeChecker

#add_typedef, #error_group, #make_base_env, #type, #type?, #type_as, #type_assert, #type_assert_false, #type_assert_later, #type_env, #typecheck, #typedef

Methods inherited from Checker

#ast, #ast_env, #check, #check_all, #check_later, #error!, #error_found!, #error_messages, #errors?, #last_error, #make_base_env, #proceed, rule

Methods included from Yadriggy

debug, debug=, define_syntax, reify, reset_pry

Constructor Details

#initializePyTypeChecker

Returns a new instance of PyTypeChecker.



9
10
11
12
# File 'lib/yadriggy/py/py_typechecker.rb', line 9

def initialize()
  super(Py::Syntax)
  @free_variables = Hash.new
end

Instance Method Details

#clear_referencesObject

Makes the references set empty. The references set is a set of constants returned by #references.



23
24
25
# File 'lib/yadriggy/py/py_typechecker.rb', line 23

def clear_references
  @free_variables = Hash.new
end

#collect_free_variables(an_ast, type) ⇒ Object

Collect free variables.

Parameters:



35
36
37
38
39
40
41
42
# File 'lib/yadriggy/py/py_typechecker.rb', line 35

def collect_free_variables(an_ast, type)
  unless InstanceType.role(type).nil?
    obj = type.object
    unless obj.is_a?(Numeric) || obj.is_a?(String) || obj.is_a?(Symbol) || obj.is_a?(Module)
      @free_variables[obj] = an_ast.name
    end
  end
end

#lookup_ruby_classes(type_env, arg_types, recv_type, method_name) ⇒ Object

Computes the type of the Call expression by searching the receiver class for the called method. If the method is not found or the method is provided by Object or its super class, DynType is returned.

This overrides the super's method but if the called method is not found, it returns DynType; it does not raise an error.



51
52
53
54
55
56
57
58
59
60
# File 'lib/yadriggy/py/py_typechecker.rb', line 51

def lookup_ruby_classes(type_env, arg_types, recv_type, method_name)
  begin
    mth = Type.get_instance_method_object(recv_type, method_name)
  rescue CheckError
    return DynType
  end
  return DynType if mth.owner > Object
  new_tenv = type_env.new_base_tenv(recv_type.exact_type)
  get_return_type(ast, mth, new_tenv, arg_types)
end

#referencesHash<Object,String>

values to their free variable names.

Returns:

  • (Hash<Object,String>)

    all free variables. A hash table from



16
17
18
# File 'lib/yadriggy/py/py_typechecker.rb', line 16

def references
  @free_variables
end