Skip to content

Commit

Permalink
Added String into List append and any_list
Browse files Browse the repository at this point in the history
  • Loading branch information
bannsec committed Mar 31, 2016
1 parent 79ea761 commit effae9e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pyObjectManager/List.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pyObjectManager.Real import Real
from pyObjectManager.BitVec import BitVec
from pyObjectManager.Char import Char
from pyObjectManager.String import String
import pyState

logger = logging.getLogger("ObjectManager:List")
Expand Down Expand Up @@ -95,12 +96,12 @@ def append(self,var,kwargs=None):
if type(var) is Char:
self.state.addConstraint(self.variables[-1].getZ3Object() == var.getZ3Object())

elif type(var) is List:
logger.debug("append: adding List")
elif type(var) in [List, String]:
logger.debug("append: adding {0}".format(type(var)))
self.variables.append(var)

else:
err = "append: Don't know how to append/resolve object '{0}'".format(var)
err = "append: Don't know how to append/resolve object '{0}'".format(type(var))
logger.error(err)
raise Exception(err)

Expand Down
1 change: 0 additions & 1 deletion pyObjectManager/String.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pyObjectManager.Int import Int
from pyObjectManager.Real import Real
from pyObjectManager.BitVec import BitVec
from pyObjectManager.List import List
from pyObjectManager.Char import Char
import pyState

Expand Down
2 changes: 2 additions & 0 deletions pyState/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ def any_list(self,var,ctx=None):
out.append(self.any_list(elm,ctx=ctx))
elif type(elm) is Char:
out.append(self.any_char(elm,ctx=ctx))
elif type(elm) is String:
out.append(self.any_str(elm,ctx=ctx))
else:
err = "any_list: unable to resolve object '{0}'".format(elm)
logger.error(err)
Expand Down
5 changes: 3 additions & 2 deletions pyState/functions/List/append.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pyObjectManager.Real import Real
from pyObjectManager.BitVec import BitVec
from pyObjectManager.Char import Char
from pyObjectManager.String import String

logger = logging.getLogger("pyState:SimFunction:List:append")

Expand All @@ -25,9 +26,9 @@ def handle(state,call,var):
root.append(var)
state.addConstraint(root[-1].getZ3Object() == var.getZ3Object())

elif type(var) is List:
elif type(var) in [List, String]:
root.append(state.recursiveCopy(var))

else:
err = "handle: Don't know how to handle appending type {0}".format(type(var))
logger.error(err)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_pyState_ListComp.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
l = [x for x in s if x == "b"]
"""

test8 = """
l = [str(i) for i in range(10)]
"""

def test_pyState_ListComp_MoreFunctions():
b = ast.parse(test8).body
p = Path(b,source=test8)
pg = PathGroup(p)

pg.explore()
assert len(pg.completed) == 1
assert pg.completed[0].state.any_list('l') == [str(i) for i in range(10)]


def test_pyState_ListComp_StringCmp():
b = ast.parse(test7).body
p = Path(b,source=test7)
Expand Down

0 comments on commit effae9e

Please sign in to comment.