Skip to content

Commit d13bc03

Browse files
alexisthedevtheosotr
authored andcommitted
Name changes and resolving PR comments
1 parent cbd3399 commit d13bc03

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

src/generators/generator.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ def get_types(self,
19511951
exclude_contravariants=False,
19521952
exclude_type_vars=False,
19531953
exclude_function_types=False,
1954-
exclude_dynamic_types=False) -> List[tp.Type]:
1954+
exclude_native_compound_types=False) -> List[tp.Type]:
19551955
"""Get all available types.
19561956
19571957
Including user-defined types, built-ins, and function types.
@@ -1965,7 +1965,7 @@ def get_types(self,
19651965
exclude_contravariants: exclude contravariant type parameters.
19661966
exclude_type_vars: exclude type variables.
19671967
exclude_function_types: exclude function types.
1968-
exclude_dynamic_types: exclude dynamic types.
1968+
exclude_native_compound_types: exclude native compound types.
19691969
19701970
Returns:
19711971
A list of available types.
@@ -1995,20 +1995,20 @@ def get_types(self,
19951995
if t.name != self.bt_factory.get_array_type().name
19961996
]
19971997

1998-
dynamic = (self.bt_factory.get_dynamic_types(self)
1999-
if not exclude_dynamic_types
1998+
compound_types = (self.bt_factory.get_compound_types(self)
1999+
if not exclude_native_compound_types
20002000
else [])
20012001
if exclude_function_types:
2002-
return usr_types + builtins + dynamic
2003-
return usr_types + builtins + dynamic + self.function_types
2002+
return usr_types + builtins + compound_types
2003+
return usr_types + builtins + compound_types + self.function_types
20042004

20052005
def select_type(self,
20062006
ret_types=True,
20072007
exclude_arrays=False,
20082008
exclude_covariants=False,
20092009
exclude_contravariants=False,
20102010
exclude_function_types=False,
2011-
exclude_dynamic_types=False) -> tp.Type:
2011+
exclude_native_compound_types=False) -> tp.Type:
20122012
"""Select a type from the all available types.
20132013
20142014
It will always instantiating type constructors to parameterized types.
@@ -2020,7 +2020,7 @@ def select_type(self,
20202020
exclude_covariants: exclude covariant type parameters.
20212021
exclude_contravariants: exclude contravariant type parameters.
20222022
exclude_function_types: exclude function types.
2023-
eclude_dynamic_types: exclude dynamic types.
2023+
exclude_native_compound_types: exclude native compound types.
20242024
20252025
Returns:
20262026
Returns a type.
@@ -2030,7 +2030,7 @@ def select_type(self,
20302030
exclude_covariants=exclude_covariants,
20312031
exclude_contravariants=exclude_contravariants,
20322032
exclude_function_types=exclude_function_types,
2033-
exclude_dynamic_types=exclude_dynamic_types)
2033+
exclude_native_compound_types=exclude_native_compound_types)
20342034
stype = ut.random.choice(types)
20352035
if stype.is_type_constructor():
20362036
exclude_type_vars = stype.name == self.bt_factory.get_array_type().name
@@ -2040,7 +2040,7 @@ def select_type(self,
20402040
exclude_contravariants=True,
20412041
exclude_type_vars=exclude_type_vars,
20422042
exclude_function_types=exclude_function_types,
2043-
exclude_dynamic_types=exclude_dynamic_types),
2043+
exclude_native_compound_types=exclude_native_compound_types),
20442044
enable_pecs=self.enable_pecs,
20452045
disable_variance_functions=self.disable_variance_functions,
20462046
variance_choices={}
@@ -2899,8 +2899,8 @@ def _create_type_params_from_etype(self, etype: tp.Type):
28992899
type_params[0].variance = tp.Invariant
29002900
return type_params, {etype: type_params[0]}, True
29012901

2902-
# the given type is combound
2903-
assert etype.is_combound() or etype.is_wildcard()
2902+
# the given type is compound
2903+
assert etype.is_compound() or etype.is_wildcard()
29042904
type_vars = etype.get_type_variables(self.bt_factory)
29052905
type_params = self.gen_type_params(
29062906
len(type_vars), with_variance=self.language == 'kotlin')

src/ir/builtins.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ def get_function_types(self, max_parameters):
138138
def get_nothing(self):
139139
raise NotImplementedError
140140

141-
def get_dynamic_types(self, gen_object):
142-
""" A type is considered dynamic if it can utilize
143-
both a builtin type and a user-defined type.
141+
def get_compound_types(self, gen_object):
142+
""" A type is considered compound if it can consist
143+
of other types. This function is used to add a lanuage's
144+
native compound types to the generator.
144145
145146
Eg. A TypeScript Union Type: string | myClass
146147

src/ir/type_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,9 @@ def unify_types(t1: tp.Type, t2: tp.Type, factory,
10401040
class A<T>
10411041
class B : A<String>()
10421042
"""
1043-
if t2.is_combound() and not t2.is_parameterized():
1043+
if t2.is_compound() and not t2.is_parameterized():
10441044
return t2.unify_types(t1, factory, same_type)
1045-
elif t1.is_combound() and t2.is_type_var():
1045+
elif t1.is_compound() and t2.is_type_var():
10461046
bound = t2.get_bound_rec(factory)
10471047
if bound is None or t1.is_subtype(bound):
10481048
return {t2: t1}
@@ -1110,8 +1110,8 @@ class B : A<String>()
11101110
if not _update_type_var_map(type_var_map, t_var, t_arg1):
11111111
return {}
11121112
continue
1113-
is_parameterized = t_var.bound.is_combound()
1114-
is_parameterized2 = t_arg1.is_combound()
1113+
is_parameterized = t_var.bound.is_compound()
1114+
is_parameterized2 = t_arg1.is_compound()
11151115
if is_parameterized and is_parameterized2:
11161116
res = unify_types(t_arg1, t_var.bound, factory)
11171117
if not res or any(

src/ir/types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def is_type_var(self):
100100
def is_wildcard(self):
101101
return False
102102

103-
def is_combound(self):
103+
def is_compound(self):
104104
return False
105105

106106
def is_parameterized(self):
@@ -354,7 +354,7 @@ def get_type_variables(self, factory):
354354
return self.bound.get_type_variables(factory)
355355
elif self.bound.is_type_var():
356356
return {self.bound: {self.bound.get_bound_rec(factory)}}
357-
elif self.bound.is_combound():
357+
elif self.bound.is_compound():
358358
return self.bound.get_type_variables(factory)
359359
else:
360360
return {}
@@ -539,7 +539,7 @@ def _to_type_variable_free(t: Type, t_param, factory) -> Type:
539539
)
540540
)
541541
return WildCardType(bound, variance)
542-
elif t.is_combound():
542+
elif t.is_compound():
543543
return t.to_type_variable_free(factory)
544544
else:
545545
return t
@@ -595,7 +595,7 @@ def __init__(self, t_constructor: TypeConstructor,
595595
# XXX revisit
596596
self.supertypes = copy(self.t_constructor.supertypes)
597597

598-
def is_combound(self):
598+
def is_compound(self):
599599
return True
600600

601601
def is_parameterized(self):
@@ -671,7 +671,7 @@ def get_type_variables(self, factory) -> Dict[TypeParameter, Set[Type]]:
671671
if t_arg.is_type_var():
672672
type_vars[t_arg].add(
673673
t_arg.get_bound_rec(factory))
674-
elif t_arg.is_combound() or t_arg.is_wildcard():
674+
elif t_arg.is_compound() or t_arg.is_wildcard():
675675
for k, v in t_arg.get_type_variables(factory).items():
676676
type_vars[k].update(v)
677677
else:

src/ir/typescript_types.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def update_add_node_to_parent(self):
9696
ts_ast.TypeAliasDeclaration: add_type_alias,
9797
}
9898

99-
def get_dynamic_types(self, gen_object):
99+
def get_compound_types(self, gen_object):
100100
return [
101101
union_types.get_union_type(gen_object),
102102
]
@@ -432,7 +432,7 @@ def __init__(self, types, name="UnionType", primitive=False):
432432
def get_types(self):
433433
return self.types
434434

435-
def is_combound(self):
435+
def is_compound(self):
436436
return True
437437

438438
@two_way_subtyping
@@ -468,7 +468,7 @@ def get_type_variables(self, factory):
468468
if t.is_type_var():
469469
type_vars[t].add(
470470
t.get_bound_rec(factory))
471-
elif t.is_combound() or t.is_wildcard():
471+
elif t.is_compound() or t.is_wildcard():
472472
for k, v in t.get_type_variables(factory).items():
473473
type_vars[k].update(v)
474474
else:
@@ -479,7 +479,7 @@ def to_variance_free(self, type_var_map=None):
479479
new_types = []
480480
for t in self.types:
481481
new_types.append(t.to_variance_free(type_var_map)
482-
if t.is_combound()
482+
if t.is_compound()
483483
else t)
484484
return UnionType(new_types)
485485

@@ -489,7 +489,7 @@ def to_type_variable_free(self, factory):
489489
# type variable free.
490490
new_types = []
491491
for t in self.types:
492-
if t.is_combound():
492+
if t.is_compound():
493493
new_type = t.to_type_variable_free(factory)
494494
elif t.is_type_var():
495495
bound = t.get_bound_rec(factory)
@@ -517,7 +517,7 @@ def unify_types(self, t1, factory, same_type=True):
517517
return {}
518518

519519
# If T1 is a union type, then get all its types.
520-
t1_types = (t1.types if t1.is_combound() and
520+
t1_types = (t1.types if t1.is_compound() and
521521
not t1.is_parameterized()
522522
else [t1])
523523

@@ -715,7 +715,7 @@ def __hash__(self):
715715
return hash(str(self.name) + str(self.types))
716716

717717

718-
class UnionTypeFactory:
718+
class UnionTypeFactory(object):
719719
def __init__(self, max_ut, max_in_union):
720720
self.max_ut = max_ut
721721
self.unions = []
@@ -728,7 +728,7 @@ def get_types_for_union(self, gen):
728728
num_of_types = self.get_number_of_types()
729729
types = set()
730730
while len(types) < num_of_types:
731-
t = gen.select_type(exclude_dynamic_types=True)
731+
t = gen.select_type(exclude_native_compound_types=True)
732732
types.add(t)
733733
return list(types)
734734

0 commit comments

Comments
 (0)