def visit_AnnAssign(self, ast_ann_assign: AnnAssign): # create Big-O AST assign node assign_node = AssignNode() # coord = coordinate(ast_ann_assign.col_offset, ast_ann_assign.lineno) # self.set_coordinate(assign_node, coord) assign_node.target = self.visit(ast_ann_assign.targets[0]) assign_node.value = self.visit(ast_ann_assign.value) return assign_node
def visit_EnhancedForControl( self, java_enhanced_for_control: EnhancedForControl): for_node = ForNode() self.set_coordinate(for_node, java_enhanced_for_control) #init assign_node = AssignNode() variable_node = self.visit(java_enhanced_for_control.var)[0].target constant_node = ConstantNode() assign_node.target = variable_node assign_node.value = constant_node for_node.init.append(assign_node) #condiction operator_node = Operator() operator_node.op = '<' operator_node.left = variable_node operator_node.right = self.visit(java_enhanced_for_control.iterable) operator_node.add_children(operator_node.left) operator_node.add_children(operator_node.right) for_node.term = operator_node #update update_operator_node = Operator() update_const_node = ConstantNode() update_const_node.value = 1 update_operator_node.right = update_const_node update_operator_node.left = variable_node update_operator_node.op = '+' update_assign_node = AssignNode() update_assign_node.target = variable_node update_assign_node.value = update_operator_node for_node.update.append(update_assign_node) return for_node
def visit_Assignment(self, pyc_assign: Assignment): # need to do some trick of +=, -=, *=, /= if len(pyc_assign.op) > 1: op = pyc_assign.op[:-1] if op == '+' or op == '-' or op == '*' or op == '/': new_op = BinaryOp(op, pyc_assign.lvalue, pyc_assign.rvalue) else: raise Exception("does not support operator: ", pyc_assign.op) pyc_assign.op = '=' pyc_assign.rvalue = new_op # create Big-O AST assign node assign_node = AssignNode() self.set_coordinate(assign_node, pyc_assign.coord) assign_node.target = self.visit(pyc_assign.lvalue) assign_node.value = self.visit(pyc_assign.rvalue) return assign_node
def visit_VariableDeclarator(self, java_var: VariableDeclarator): assign_node = AssignNode() self.set_coordinate(assign_node, java_var) variable_node = VariableNode() self.set_coordinate(variable_node, java_var) # target variable_node.name = java_var.name assign_node.target = variable_node # value if hasattr(java_var, 'initializer'): if java_var.initializer: assign_node.value = self.visit(java_var.initializer) return assign_node
def visit_Decl(self, pyc_decl: Decl): variable_node = VariableNode() self.set_coordinate(variable_node, pyc_decl.coord) variable_node.name = pyc_decl.name if type(pyc_decl.type) == ArrayDecl: pyc_arr = pyc_decl while type(pyc_arr.type) == ArrayDecl: variable_node.add_children(self.visit(pyc_arr.type.dim)) pyc_arr = pyc_arr.type # if have init, then create assign node if pyc_decl.init: assign_node = AssignNode() self.set_coordinate(assign_node, pyc_decl.coord) assign_node.target = variable_node assign_node.value = self.visit(pyc_decl.init) return assign_node else: return variable_node
def visit_AugAssign(self, ast_aug_assign: AugAssign): # need to do some trick of +=, -=, *=, /= if type(ast_aug_assign.op) == Add: new_op = BinOp(ast_aug_assign.target, Add(), ast_aug_assign.value) elif type(ast_aug_assign.op) == Sub: new_op = BinOp(ast_aug_assign.target, Sub(), ast_aug_assign.value) elif type(ast_aug_assign.op) == Mult: new_op = BinOp(ast_aug_assign.target, Mult(), ast_aug_assign.value) elif type(ast_aug_assign.op) == Div: new_op = BinOp(ast_aug_assign.target, Div(), ast_aug_assign.value) else: raise Exception("does not support operator: ", ast_aug_assign.op) ast_assign = Assign(ast_aug_assign.target, new_op) # create Big-O AST assign node assign_node = AssignNode() # coord = coordinate(ast_aug_assign.col_offset, ast_aug_assign.lineno) # self.set_coordinate(assign_node, coord) assign_node.target = self.visit(ast_assign.targets) assign_node.value = self.visit(ast_assign.value) return assign_node
def visit_Assignment(self, java_assign: Assignment): assign_node = AssignNode() self.set_coordinate(assign_node, java_assign) # need to do some trick of +=, -=, *=, /= if len(java_assign.type) > 1: op = java_assign.type[:-1] if op == '+' or op == '-' or op == '*' or op == '/': new_op = BinaryOperation() self.set_coordinate(new_op, java_assign) new_op.operator = op new_op.operandl = java_assign.expressionl new_op.operandr = java_assign.value else: raise Exception("does not support operator: ", java_assign.op) java_assign.type = '=' java_assign.value = new_op assign_node.target = self.visit(java_assign.expressionl) assign_node.value = self.visit(java_assign.value) return assign_node
def visit_AssignNode(self, assign_node: AssignNode): target = assign_node.target value = assign_node.value self.visit(target) value_tc = 0 if type(value) is not list: self.visit(value) value_tc = value.time_complexity else: for child in value: self.visit(child) value_tc += child.time_complexity assign_node.time_complexity = value_tc pass
def visit_AssignNode(self, assign_node: AssignNode): target = assign_node.target value = assign_node.value self.visit(target) value_tc = 0 self.backward_table_manager.add_symbol(assign_node) if type(value) is not list: self.visit(value) value_tc = value.time_complexity else: for child in value: self.visit(child) value_tc += child.time_complexity assign_node.time_complexity = value_tc pass