really good support for list/set conversions

This commit is contained in:
David Halter
2012-08-10 17:21:14 +02:00
parent e0ebc0e3ac
commit 9b80dab77b
2 changed files with 36 additions and 9 deletions

View File

@@ -169,26 +169,27 @@ def check_array_instances(instance):
class ArrayInstance(parsing.Base): class ArrayInstance(parsing.Base):
""" """
Used for the usage of set() and list(). Used for the usage of set() and list().
At the moment this is not done lazy, maybe do that later on? This is definitely a hack, but a good one :-)
It makes it possible to use set/list conversions.
""" """
def __init__(self, instance): def __init__(self, instance):
self.instance = instance self.instance = instance
self.var_args = instance.var_args self.var_args = instance.var_args
def iter_content(self, index=None): def iter_content(self):
""" """
The index is here just ignored, because of all the appends, etc. The index is here just ignored, because of all the appends, etc.
lists/sets are too complicated too handle that. lists/sets are too complicated too handle that.
""" """
items = [] items = []
for array in evaluate.follow_call_list(self.var_args): for array in evaluate.follow_call_list(self.var_args):
if isinstance(array, evaluate.Instance) and len(array.var_args):
temp = array.var_args[0][0]
if isinstance(temp, ArrayInstance):
items += temp.iter_content()
continue
items += array.get_index_types() items += array.get_index_types()
module = self.var_args.parent_stmt.get_parent_until() module = self.var_args.parent_stmt.get_parent_until()
items += _check_array_additions(self.instance, module, str(self.instance.name) == 'list') items += _check_array_additions(self.instance, module, str(self.instance.name) == 'list')
return items return items
@property
def parent(self):
return None

View File

@@ -158,6 +158,22 @@ arr.extend("") # should ignore
##? float() int() ##? float() int()
arr[0] arr[0]
# -----------------
# set/list initialized as functions
# -----------------
st = set()
st.add(1)
#? int()
for s in st: s
lst = list()
lst.append(1)
#? int()
for i in lst: i
# ----------------- # -----------------
# renames / type changes # renames / type changes
# ----------------- # -----------------
@@ -174,5 +190,15 @@ lst = list(st)
lst.append('') lst.append('')
##? int() str() #? int() str()
lst[0]
lst = [1]
lst.append(1.0)
s = set(lst)
s.add("")
lst = list(s)
lst.append({})
#? dict() int() float() str()
lst[0] lst[0]