<class '_ast.Name'> {'ctx': <class '_ast.Store'>, 'id': <type 'str'>, 'col_offset': <type 'int'>, 'lineno': <type 'int'>} <class '_ast.Pass'> {'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.Pow'> {} <class '_ast.Print'> {'dest': <type 'NoneType'>, 'values': <type 'list'>, 'nl': <type 'bool'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.Raise'> {'tback': <type 'NoneType'>, 'type': <class '_ast.Name'>, 'inst': <type 'NoneType'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.Repr'> {'value': <class '_ast.Num'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.Return'> {'value': <class '_ast.Name'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.Set'> {'elts': <type 'list'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.Slice'> {'upper': <class '_ast.Num'>, 'lower': <class '_ast.Num'>, 'step': <type 'NoneType'>} - they can all be None <class '_ast.Str'> {'s': <type 'str'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.Subscript'> {'value': <class '_ast.List'>, 'slice': <class '_ast.Index'>, 'ctx': <class '_ast.Load'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.TryExcept'> {'body': <type 'list'>, 'orelse': <type 'list'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>, 'handlers': <type 'list'>} - handlers is a list of ExceptHandler <class '_ast.TryFinally'> {'body': <type 'list'>, 'finalbody': <type 'list'>, 'col_offset': <type 'int'>, 'lineno': <type 'int'>} <class '_ast.Tuple'> {'elts': <type 'list'>, 'ctx': <class '_ast.Load'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.UnaryOp'> {'operand': <class '_ast.Name'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>, 'op': <class '_ast.USub'>} <class '_ast.While'> {'body': <type 'list'>, 'test': <class '_ast.Num'>, 'orelse': <type 'list'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} <class '_ast.With'> {'body': <type 'list'>, 'optional_vars': <type 'NoneType'>, 'context_expr': <class '_ast.Name'>, 'col_offset': <type 'int'>, 'lineno': <type 'int'>} - optional_vars can be a name that it gets with'd as - context_expr is the with object <class '_ast.Yield'> {'value': <class '_ast.Num'>, 'lineno': <type 'int'>, 'col_offset': <type 'int'>} - Yield is an expression?? """ ast1 = parse(test_1, "text").body[0] ast2 = parse(test_2, "text").body[0] show(parse(""" global a """.strip(), "text").body[0].names)
comp.queue_scope(node, initial_state, parent_scope) input, output = comp.compute(definedness_bb, definedness_aggregator) if isinstance(node, (_ast.FunctionDef, _ast.Lambda)): assert not parent_scope.names errors = [] for errs in comp.errors.itervalues(): errors += errs.items() return input, output, errors if __name__ == "__main__": fn = sys.argv[1] source = open(fn).read() try: node = ast_utils.parse(source, fn) except SyntaxError: print "Failed to parse %s due to a syntax error" % (fn,) sys.exit(1) assert isinstance(node, _ast.Module), node try: input, output, errors = get_definedness(node) except: print "Failed on", fn raise print "input:" for n, s in sorted(input.items()): print n, s print print "output:"
return [j.set_dest, make_connect(next)] return on_gen return on_gen class TestAnalyzer(object): def __init__(self): self.start_prop = set() def update_func(self, state, bid, input_): rtn = set(input_) rtn.add(bid) return rtn def merge_func(self, inputs, output): new_output = set() for i in inputs: if not i: continue new_output.update(i) if not output: return new_output, True assert len(new_output) >= len(output) return new_output, (len(new_output) > len(output)) if __name__ == "__main__": fn = sys.argv[1] cfa(ast_utils.parse(open(fn).read(), fn)).show()
if __name__ == "__main__": t = """ try: 1/0 except Exception: print "bad!" except Exception2: print "second bad!" else: print "else" finally: print "finally" print "done" """.strip() cfg = cfa(ast_utils.parse(t, "test")) cfg.show() sys.exit(-1) t = """ with f() as b: print b """.strip() t = """ x = 1 # 1 while x: # 2 if 1: # 3 continue elif 2: # 4 break