Class: Yadriggy::C::ClangTypeChecker

Inherits:
RubyTypeInferer show all
Includes:
CType
Defined in:
lib/yadriggy/c/ctypecheck.rb

Direct Known Subclasses

OclTypeChecker

Constant Summary

Constants included from CType

Yadriggy::C::CType::Float32Array, Yadriggy::C::CType::FloatArray, Yadriggy::C::CType::Int, Yadriggy::C::CType::IntArray, Yadriggy::C::CType::Void

Constants included from Yadriggy

DynType, Undef, VERSION, Void

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CType

#arrayof, #typedecl

Methods inherited from RubyTypeInferer

#bind_local_var, #get_instance_variable_type

Methods inherited from RubyTypeChecker

#bind_local_var, #get_call_expr_type, #get_name_type, #get_return_type, #lookup_ruby_classes, #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 Yadriggy::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

#initialize(syntax = nil) ⇒ ClangTypeChecker

Returns a new instance of ClangTypeChecker.



59
60
61
62
63
# File 'lib/yadriggy/c/ctypecheck.rb', line 59

def initialize(syntax=nil)
  super(syntax || C::syntax)
  @local_vars_table = {}
  @instance_variables = Set.new
end

Instance Attribute Details

#instance_variablesSet<IvarObj> (readonly)

Returns accessed instance variables.

Returns:

  • (Set<IvarObj>)

    accessed instance variables.



57
58
59
# File 'lib/yadriggy/c/ctypecheck.rb', line 57

def instance_variables
  @instance_variables
end

#local_vars_tableHash<Def,Hash<Symbol,Type>> (readonly)

Returns a map from functions to their local variables.

Returns:

  • (Hash<Def,Hash<Symbol,Type>>)

    a map from functions to their local variables.



54
55
56
# File 'lib/yadriggy/c/ctypecheck.rb', line 54

def local_vars_table
  @local_vars_table
end

Instance Method Details

#is_subsumed_by?(sub_type, super_type) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
# File 'lib/yadriggy/c/ctypecheck.rb', line 78

def is_subsumed_by?(sub_type, super_type)
  (valid_var_type?(sub_type) && valid_var_type?(super_type)) ||
    sub_type <= super_type
end

#method_with_block?(name) ⇒ Boolean

Specifies the names of methods with a block.

Parameters:

  • name (String)

    a method name.

Returns:

  • (Boolean)

See Also:



321
322
323
# File 'lib/yadriggy/c/ctypecheck.rb', line 321

def method_with_block?(name)
  name == 'times'
end

#typecheck_call_with_block(call_ast) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/yadriggy/c/ctypecheck.rb', line 325

def typecheck_call_with_block(call_ast)
  type_assert(ast.name.name == 'times',
              "no such method: #{ast.name.name}")
  type_assert(type(ast.receiver) == RubyClass::Integer,
              'the receiver must be an integer')
  type_assert(ast.block.params.size == 1,
              "wrong number of block parameters")
  type_as(ast.block.params[0], RubyClass::Integer)
  tenv = type_env.new_tenv
  tenv.bind_name(ast.block.params[0], RubyClass::Integer)
  tenv.bind_name(:return, Void)
  type(ast.block, tenv)
  Void
end

#valid_type?(t) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/yadriggy/c/ctypecheck.rb', line 74

def valid_type?(t)
  valid_var_type?(t) || ArrayType.role(t)
end

#valid_var_type?(t) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
# File 'lib/yadriggy/c/ctypecheck.rb', line 65

def valid_var_type?(t)
  if t.is_a?(Type)
    et = t.exact_type
    et == Integer || et == Float || et == String || et == Float32
  else
    false
  end
end