29
29
from src .generators import utils as gu
30
30
from src .generators .config import cfg
31
31
from src .ir import ast , types as tp , type_utils as tu , kotlin_types as kt
32
- from src .ir .context import Context , get_decl
32
+ from src .ir .context import Context
33
33
from src .ir .builtins import BuiltinFactory
34
34
from src .ir import BUILTIN_FACTORIES
35
- from src .modules .logging import Logger
35
+ from src .modules .logging import Logger , log
36
36
37
37
38
38
class Generator ():
@@ -857,7 +857,10 @@ def generate_expr(self,
857
857
if find_subtype :
858
858
subtypes = tu .find_subtypes (expr_type , self .get_types (),
859
859
include_self = True , concrete_only = True )
860
+ old_type = expr_type
860
861
expr_type = ut .random .choice (subtypes )
862
+ msg = "Found subtype of {}: {}" .format (old_type , expr_type )
863
+ log (self .logger , msg )
861
864
generators = self .get_generators (expr_type , only_leaves , subtype ,
862
865
exclude_var , sam_coercion = sam_coercion )
863
866
expr = ut .random .choice (generators )(expr_type )
@@ -1022,7 +1025,8 @@ def gen_field_access(self,
1022
1025
self .depth += 1
1023
1026
objs = self ._get_matching_objects (etype , subtype , 'fields' )
1024
1027
if not objs :
1025
- type_f = self ._get_matching_class (etype , subtype , 'fields' )
1028
+ type_f = self ._get_matching_class (etype , subtype = subtype ,
1029
+ attr_name = 'fields' )
1026
1030
if type_f is None :
1027
1031
type_f = self ._gen_matching_class (
1028
1032
etype , 'fields' , not_void = True ,
@@ -1477,10 +1481,16 @@ def _gen_func_call(self,
1477
1481
only_leaves: do not generate new leaves except from `expr`.
1478
1482
subtype: The returned type could be a subtype of `etype`.
1479
1483
"""
1484
+ log (self .logger , "Generating function call of type {}" .format (etype ))
1480
1485
funcs = self ._get_matching_function_declarations (etype , subtype )
1481
1486
if not funcs :
1482
- type_fun = self ._get_matching_class (etype , subtype , 'functions' )
1487
+ msg = "No compatible functions in the current scope for type {}"
1488
+ log (self .logger , msg .format (etype ))
1489
+ type_fun = self ._get_matching_class (etype , subtype = subtype ,
1490
+ attr_name = 'functions' )
1483
1491
if type_fun is None :
1492
+ msg = "No compatible classes for type {}"
1493
+ log (self .logger , msg .format (etype ))
1484
1494
# Here, we generate a function or a class containing a function
1485
1495
# whose return type is 'etype'.
1486
1496
type_fun = self ._gen_matching_func (etype , not_void = True )
@@ -1489,7 +1499,7 @@ def _gen_func_call(self,
1489
1499
else self .generate_expr (type_fun .receiver_t , only_leaves )
1490
1500
)
1491
1501
funcs .append (gu .AttrReceiverInfo (receiver , type_fun .receiver_inst ,
1492
- type_fun .attr_decl , type_fun .attr_inst ))
1502
+ type_fun .attr_decl , type_fun .attr_inst ))
1493
1503
1494
1504
rand_func = ut .random .choice (funcs )
1495
1505
receiver = rand_func .receiver_expr
@@ -1498,6 +1508,10 @@ def _gen_func_call(self,
1498
1508
func_type_map = rand_func .attr_inst
1499
1509
1500
1510
params_map .update (func_type_map or {})
1511
+
1512
+ msg = ("Selected callee method {}: type {}; receiver {}; "
1513
+ "TypeVarMap {}" .format (func .name , etype , receiver , params_map ))
1514
+ log (self .logger , msg )
1501
1515
args = []
1502
1516
initial_depth = self .depth
1503
1517
self .depth += 1
@@ -1796,7 +1810,7 @@ def _gen_func_ref(self, etype: tp.Type,
1796
1810
# Get function references from methods of classes.
1797
1811
# ie create receiver
1798
1812
type_fun = self ._get_matching_class (
1799
- etype , False , 'functions' , signature = True )
1813
+ etype , subtype = False , attr_name = 'functions' , signature = True )
1800
1814
1801
1815
# Generate a matching function.
1802
1816
if not type_fun :
@@ -2007,6 +2021,8 @@ def select_type(self,
2007
2021
disable_variance_functions = self .disable_variance_functions ,
2008
2022
variance_choices = {}
2009
2023
)
2024
+ msg = "Instantiating type constructor {}" .format (stype )
2025
+ log (self .logger , msg )
2010
2026
return stype
2011
2027
2012
2028
def gen_type_params (self ,
@@ -2439,6 +2455,9 @@ def _get_matching_function_declarations(self,
2439
2455
)
2440
2456
# First find all top-level functions or methods included
2441
2457
# in the current class.
2458
+ msg = ("Searching for function declarations that match type {};"
2459
+ " checking signature {}" )
2460
+ log (self .logger , msg .format (etype , signature ))
2442
2461
for func in self .context .get_funcs (self .namespace ).values ():
2443
2462
# The receiver object for this kind of functions is None.
2444
2463
if func .get_type () == self .bt_factory .get_void_type ():
@@ -2524,14 +2543,16 @@ def _gen_matching_func(self,
2524
2543
func_type_var_map = tu .instantiate_parameterized_function (
2525
2544
func .type_parameters , self .get_types (),
2526
2545
only_regular = True , type_var_map = {})
2546
+ msg = "Generating a method {} of type {}; TypeVarMap {}" .format (
2547
+ func .name , etype , func_type_var_map )
2548
+ log (self .logger , msg )
2527
2549
return gu .AttrAccessInfo (None , {}, func , func_type_var_map )
2528
2550
# Generate a class containing the requested function
2529
2551
return self ._gen_matching_class (etype , 'functions' ,
2530
2552
signature = signature )
2531
2553
2532
-
2533
2554
def _get_matching_class (self ,
2534
- etype :tp .Type ,
2555
+ etype : tp .Type ,
2535
2556
subtype : bool ,
2536
2557
attr_name : str ,
2537
2558
signature = False ) -> gu .AttrAccessInfo :
@@ -2552,8 +2573,10 @@ def _get_matching_class(self,
2552
2573
An AttrAccessInfo with a matched class type and attribute
2553
2574
declaration (field or function).
2554
2575
"""
2576
+ msg = "Searching for class that contains {} of type {}"
2577
+ log (self .logger , msg .format (attr_name , etype ))
2555
2578
class_decls = self ._get_matching_class_decls (
2556
- etype , subtype , attr_name , signature )
2579
+ etype , subtype = subtype , attr_name = attr_name , signature = signature )
2557
2580
if not class_decls :
2558
2581
return None
2559
2582
cls , type_var_map , attr = ut .random .choice (class_decls )
@@ -2575,6 +2598,9 @@ def _get_matching_class(self,
2575
2598
disable_variance_functions = self .disable_variance_functions ,
2576
2599
variance_choices = variance_choices
2577
2600
)
2601
+ msg = ("Found parameterized class {} with TypeVarMap {} and "
2602
+ "incomplete TypeVarMap {}" )
2603
+ log (self .logger , msg .format (cls .name , params_map , type_var_map ))
2578
2604
if is_parameterized_func :
2579
2605
# Here we have found a parameterized function in a
2580
2606
# parameterized class. So wee need to both instantiate
@@ -2611,6 +2637,12 @@ def _get_matching_class(self,
2611
2637
attr .type_parameters , self .get_types (),
2612
2638
only_regular = True , type_var_map = type_var_map )
2613
2639
cls_type , params_map = cls .get_type (), {}
2640
+
2641
+ attr_msg = "Attribute {}; type: {}, TypeVarMap{}" .format (
2642
+ attr_name , etype , func_type_var_map )
2643
+ msg = "Selected class {} with TypeVarMap {};" " matches {}" .format (
2644
+ cls .name , params_map , attr_msg )
2645
+ log (self .logger , msg )
2614
2646
return gu .AttrAccessInfo (cls_type , params_map , attr , func_type_var_map )
2615
2647
2616
2648
def _is_sigtype_compatible (self , attr , etype , type_var_map ,
@@ -2807,6 +2839,8 @@ def _gen_matching_class(self,
2807
2839
attr .type_parameters , self .get_types (), only_regular = True ,
2808
2840
type_var_map = params_map )
2809
2841
2842
+ msg = "Generated a class {} with an attribute {} of type {}"
2843
+ log (self .logger , msg .format (cls .name , attr_name , etype ))
2810
2844
return gu .AttrAccessInfo (cls_type , params_map , attr ,
2811
2845
func_type_var_map )
2812
2846
return None
0 commit comments