def t_livevar_ifandorthen_engine_attach(): #raise nose.SkipTest blocks, functions = cf_analyze(''' var f = func(x) { var c if ((x > 5 || x < 3) && (1 < x || x < 4)) { c = 1 } else { c = 2 } return c } print f(10) ''') df.analyze(livevar.LiveVariable, functions, True, True) f2 = functions['f2'] def ids(pairs): return set(id for id in pairs.iterkeys()) assert ids(f2.live('b2')['inn']) == set([]) assert ids(f2.live('b2')['out']) == set([1]) assert ids(f2.live('b3')['inn']) == set([]) assert ids(f2.live('b3')['out']) == set([11]) assert ids(f2.live('b4')['inn']) == set([11]) assert ids(f2.live('b4')['out']) == set([]) assert ids(f2.live('b5')['inn']) == set([]) assert ids(f2.live('b5')['out']) == set([11]) assert ids(f2.live('b6')['inn']) == set([1]) assert ids(f2.live('b6')['out']) == set([1]) assert ids(f2.live('b7')['inn']) == set([1]) assert ids(f2.live('b7')['out']) == set([]) assert ids(f2.live('b8')['inn']) == set([1]) assert ids(f2.live('b8')['out']) == set([1])
def t_livevar_ifthen_engine_attach(): #raise nose.SkipTest blocks, functions = cf_analyze(''' var f = func(x) { var c = 3 if (x > 0) { c = f(x-1) } return c } print f(10) ''') df.analyze(livevar.LiveVariable, functions, True, True) f2 = functions['f2'] def ids(types): return set(typ.id for typ in types) assert ids(f2.livetypes('b2', 'inn')) == set([0]) assert ids(f2.livetypes('b2', 'out')) == set([0, 1, 2]) assert ids(f2.livetypes('b3', 'inn')) == set([0, 1]) assert ids(f2.livetypes('b3', 'out')) == set([2]) assert ids(f2.livetypes('b4', 'inn')) == set([2]) assert ids(f2.livetypes('b4', 'out')) == set([])
def t_reachdef_ifandorthen_engine(): #raise nose.SkipTest blocks, functions = cf_analyze(''' var f = func(x) { var c if ((x > 5 || x < 3) && (1 < x || x < 4)) { c = 1 } else { c = 2 } return c } print f(10) ''') name = reachdef.ReachingDefintions.name df.analyze(reachdef.ReachingDefintions, functions, True) f2 = functions['f2'] b1_inn = functions['main'].df[name].inn['b1'] b1_out = functions['main'].df[name].out['b1'] b2_inn = functions['f2'].df[name].inn['b2'] b2_out = functions['f2'].df[name].out['b2'] b3_inn = functions['f2'].df[name].inn['b3'] b3_out = functions['f2'].df[name].out['b3'] b4_inn = functions['f2'].df[name].inn['b4'] b4_out = functions['f2'].df[name].out['b4'] b5_inn = functions['f2'].df[name].inn['b5'] b5_out = functions['f2'].df[name].out['b5'] b6_inn = functions['f2'].df[name].inn['b6'] b6_out = functions['f2'].df[name].out['b6'] b7_inn = functions['f2'].df[name].inn['b7'] b7_out = functions['f2'].df[name].out['b7'] b8_inn = functions['f2'].df[name].inn['b8'] b8_out = functions['f2'].df[name].out['b8'] assert b1_inn == set() assert b1_out == set([('b1', 0), ('b1', 3)]) assert b2_inn == set([]) assert b2_out == set([('b2', 1), ('b2', 0)]) assert b3_inn == set([('b6', 0), ('b8', 0), ('b7', 0), ('b2', 1), ('b2', 0)]) assert b3_out == set([('b6', 0), ('b3', 0), ('b8', 0), ('b7', 0), ('b2', 1), ('b2', 0)]) assert b4_inn == set([('b6', 0), ('b3', 0), ('b8', 0), ('b7', 0), ('b5', 0), ('b2', 1), ('b2', 0)]) assert b4_out == set([('b6', 0), ('b5', 0), ('b3', 0), ('b8', 0), ('b7', 0), ('b2', 1), ('b2', 0)]) assert b5_inn == set([('b6', 0), ('b8', 0), ('b7', 0), ('b2', 1), ('b2', 0)]) assert b5_out == set([('b6', 0), ('b5', 0), ('b8', 0), ('b7', 0), ('b2', 1), ('b2', 0)]) assert b6_inn == set([('b2', 1), ('b2', 0), ('b8', 0)]) assert b6_out == set([('b6', 0), ('b2', 1), ('b2', 0), ('b8', 0)]) assert b7_inn == set([('b6', 0), ('b2', 1), ('b2', 0), ('b8', 0)]) assert b7_out == set([('b7', 0), ('b6', 0), ('b2', 1), ('b2', 0), ('b8', 0)]) assert b8_inn == set([('b2', 1), ('b2', 0)]) assert b8_out == set([('b2', 1), ('b2', 0), ('b8', 0)])
def t_reachdef_ifthenelse_engine(): #raise nose.SkipTest() blocks, functions = cf_analyze(''' var f = func(x) { var c = 3 if (x > 0) { c = f(x-1) } else { c = x } return c } print f(10) ''') df.analyze(reachdef.ReachingDefintions, functions, True) name = reachdef.ReachingDefintions.name b1_inn = functions['main'].df[name].inn['b1'] b1_out = functions['main'].df[name].out['b1'] b2_inn = functions['f2'].df[name].inn['b2'] b2_out = functions['f2'].df[name].out['b2'] b3_inn = functions['f2'].df[name].inn['b3'] b3_out = functions['f2'].df[name].out['b3'] b4_inn = functions['f2'].df[name].inn['b4'] b4_out = functions['f2'].df[name].out['b4'] b5_inn = functions['f2'].df[name].inn['b5'] b5_out = functions['f2'].df[name].out['b5'] assert b1_inn == set() assert b1_out == set([('b1', 0), ('b1', 3)]) assert b2_inn == set() assert b2_out == set([('b2', 1), ('b2', 2), ('b2', 0)]) assert b3_inn == set([('b2', 1), ('b2', 2), ('b2', 0)]) assert b3_out == set([('b3', 4), ('b2', 2), ('b3', 0), ('b3', 1), ('b2', 0)]) assert b4_inn == set([('b3', 4), ('b2', 2), ('b3', 0), ('b3', 1), ('b5', 0), ('b2', 0)]) assert b4_out == set([('b3', 4), ('b2', 2), ('b5', 0), ('b3', 0), ('b3', 1), ('b2', 0)]) assert b5_inn == set([('b2', 1), ('b2', 2), ('b2', 0)]) assert b5_out == set([('b5', 0), ('b2', 2), ('b2', 0)])
def t_livevar_ifthenelse_engine(): blocks, functions = cf_analyze(''' var f = func(x) { var c = 3 if (x > 0) { c = f(x-1) } else { c = x } return c } print f(10) ''') df.analyze(livevar.LiveVariable, functions, True) name = livevar.LiveVariable.name b1_inn = functions['main'].df[name].inn['b1'] b1_out = functions['main'].df[name].out['b1'] b2_inn = functions['f2'].df[name].inn['b2'] b2_out = functions['f2'].df[name].out['b2'] b3_inn = functions['f2'].df[name].inn['b3'] b3_out = functions['f2'].df[name].out['b3'] b4_inn = functions['f2'].df[name].inn['b4'] b4_out = functions['f2'].df[name].out['b4'] b5_inn = functions['f2'].df[name].inn['b5'] b5_out = functions['f2'].df[name].out['b5'] assert b1_inn == set([0]) assert b1_out == set([]) assert b2_inn == set([0]) assert b2_out == set([0, 1]) assert b3_inn == set([0, 1]) assert b3_out == set([2]) assert b4_inn == set([2]) assert b4_out == set([]) assert b5_inn == set([1]) assert b5_out == set([2])