def veval_ast_assign(astc : 'AstContext', local_field : 'values.Field', graph : 'Graph'): assert(isinstance(astc.nast, gast.gast.Assign)) value = veval_ast(astc.c(astc.nast.value), local_field, graph) if value is None: if config.show_warnings: print('It is possible that assiging value is invalid in L.{}'.format(astc.lineno)) return None targets = veval_ast(astc.c(astc.nast.targets[0]), local_field, graph) isTuple = False if isinstance(targets, values.TupleValue): targets = targets.values isTuple = True if isTuple: for i in range(len(targets)): node_assign = nodes.NodeAssign(targets[i], value.values[i].get_value(), astc.lineno) targets[i].revise(value.values[i].get_value()) graph.add_node(node_assign) else: node_assign = nodes.NodeAssign(targets, value, astc.lineno) targets.revise(value.get_value()) graph.add_node(node_assign)
def veval_ast_assign(astc: 'AstContext', local_field: 'values.Field', graph: 'Graph'): assert (isinstance(astc.nast, gast.gast.Assign)) lineprop = utils.LineProperty(astc.lineno) value = veval_ast(astc.c(astc.nast.value), local_field, graph) value_obj = try_get_ref(value, 'assign', lineprop) if value is None: if config.show_warnings: print( 'It is possible that assiging value is invalid in L.{}'.format( astc.lineno)) return None target_option = VEvalOption() target_option.eval_as_written_target = True targets = veval_ast(astc.c(astc.nast.targets[0]), local_field, graph, target_option) def return_value_or_ref(obj: 'value.Object'): if isinstance(obj.get_value(), values.NumberValue): return values.ValueRef(obj.get_value()) if isinstance(obj.get_value(), values.StrValue): return values.ValueRef(obj.get_value()) if isinstance(obj.get_value(), values.BoolValue): return values.ValueRef(obj.get_value()) if isinstance(obj.get_value(), values.NoneValue): return values.ValueRef(obj.get_value()) if isinstance(obj.get_value(), values.TupleValue): return values.ValueRef(obj.get_value()) return obj if isinstance(targets, list): # ex. a,b = (1,2) if not isinstance(value_obj.get_value(), values.TupleValue): # TODO fix it assert (False) # not supported for i in range(len(targets)): node_assign = nodes.NodeAssign( targets[i], value_obj.get_value().get_constant_value()[i], astc.lineno) targets[i].revise( try_get_ref(value_obj.get_value().get_constant_value()[i], 'assign', lineprop)) graph.add_node(node_assign) else: assigned_obj = return_value_or_ref(value_obj) node_assign = nodes.NodeAssign(targets, assigned_obj, astc.lineno) targets.revise(assigned_obj) graph.add_node(node_assign)
def veval_ast_assign(astc: 'AstContext', local_field: 'values.Field', graph: 'Graph'): assert (isinstance(astc.nast, gast.gast.Assign)) lineprop = utils.LineProperty(astc.lineno) value = veval_ast(astc.c(astc.nast.value), local_field, graph) value_obj = try_get_obj(value, 'assign', lineprop) if value is None: if config.show_warnings: print( 'It is possible that assiging value is invalid in L.{}'.format( astc.lineno)) return None target_option = VEvalOption() target_option.eval_as_written_target = True targets = veval_ast(astc.c(astc.nast.targets[0]), local_field, graph, target_option) isTuple = False if targets.has_obj() and isinstance(targets.get_obj().get_value(), values.TupleValue): targets = targets.get_obj().values isTuple = True if isTuple: for i in range(len(targets)): node_assign = nodes.NodeAssign(targets[i], value.values[i], astc.lineno) targets[i].revise(value.values[i]) graph.add_node(node_assign) else: node_assign = nodes.NodeAssign(targets, value_obj, astc.lineno) targets.revise(value_obj) graph.add_node(node_assign)