def create_get_type_of_member(owner_var, member_name, lineno, col_offset, test_unreferenced=True): comment = create_src_comment( "Obtaining the member '{0}' of a type".format(member_name), lineno) localization = create_localization(lineno, col_offset) # TODO: Remove? # get_type_of_member_func = core_language_copy.create_Name('get_type_of_member') # get_type_of_member_call = functions_copy.create_call(get_type_of_member_func, [localization, owner_var, # core_language_copy.create_str( # member_name)]) get_type_of_member_func = core_language_copy.create_attribute( owner_var, 'get_type_of_member') if not test_unreferenced: get_type_of_member_call = functions_copy.create_call( get_type_of_member_func, [ localization, core_language_copy.create_str(member_name), core_language_copy.create_Name('False') ]) else: get_type_of_member_call = functions_copy.create_call( get_type_of_member_func, [localization, core_language_copy.create_str(member_name)]) member_stmts, member_var = create_temp_Assign(get_type_of_member_call, lineno, col_offset) return flatten_lists(comment, member_stmts), member_var
def create_get_type_of(var_name, lineno, col_offset, test_unreferenced=True): get_type_of_comment = create_src_comment( "Getting the type of '{0}'".format(var_name), lineno) get_type_of_method = core_language_copy.create_attribute( default_module_type_store_var_name, "get_type_of", line=lineno, column=col_offset) localization = create_localization(lineno, col_offset) if test_unreferenced: get_type_of_call = functions_copy.create_call( get_type_of_method, [localization, core_language_copy.create_str(var_name)]) else: get_type_of_call = functions_copy.create_call(get_type_of_method, [ localization, core_language_copy.create_str(var_name), core_language_copy.create_Name('False') ]) assign_stmts, temp_assign = create_temp_Assign(get_type_of_call, lineno, col_offset) return flatten_lists(get_type_of_comment, assign_stmts), temp_assign
def create_set_unreferenced_var_check(state): if ENABLE_CODING_ADVICES: attribute = core_language_copy.create_attribute( "type_store", "set_check_unreferenced_vars") call_ = functions_copy.create_call_expression( attribute, [core_language_copy.create_Name(str(state))]) return call_ else: return []
def create_print_errors(): """ Creates AST Nodes that encode "ErrorType.print_error_msgs()" """ attribute = core_language_copy.create_attribute("ErrorType", "print_error_msgs") expr = ast.Expr() expr.value = functions_copy.create_call(attribute, []) return expr
def create_add_stored_type(owner_var, index, value, lineno, col_offset): comment = create_src_comment("Storing an element on a container", lineno) localization = create_localization(lineno, col_offset) add_type_func = core_language_copy.create_attribute( owner_var, 'add_key_and_value_type') param_tuple = ast.Tuple() param_tuple.elts = [index, value] set_type_of_member_call = functions_copy.create_call_expression( add_type_func, [localization, param_tuple]) return flatten_lists(comment, set_type_of_member_call)
def create_add_alias(alias_name, var_name, lineno, col_offset): get_type_of_comment = create_src_comment("Adding an alias") get_type_of_method = core_language_copy.create_attribute( default_module_type_store_var_name, "add_alias", line=lineno, column=col_offset) get_type_of_call = functions_copy.create_call_expression( get_type_of_method, [alias_name, var_name]) return flatten_lists(get_type_of_comment, get_type_of_call)
def create_store_return_from_function(lineno, col_offset): set_type_of_comment = create_src_comment("Storing return type", lineno) set_type_of_method = core_language_copy.create_attribute( default_module_type_store_var_name, "store_return_type_of_current_context") return_var_name = core_language_copy.create_Name( default_function_ret_var_name) set_type_of_call = functions_copy.create_call_expression( set_type_of_method, [return_var_name]) return flatten_lists(set_type_of_comment, set_type_of_call)
def create_context_unset(): """ Creates an AST Node that model the call to the type_store.unset_context method :return: An AST Expr node """ # Code to pop a stack trace once the function finishes. attribute = core_language_copy.create_attribute("type_store", "unset_context") context_unset_call = create_call(attribute, []) context_unset = ast.Expr() context_unset.value = context_unset_call return context_unset
def create_stacktrace_pop(): """ Creates an AST Node that model the call to the localitazion.unset_stack_trace method :return: An AST Expr node """ # Code to pop a stack trace once the function finishes. attribute = core_language_copy.create_attribute("localization", "unset_stack_trace") stack_pop_call = create_call(attribute, []) stack_pop = ast.Expr() stack_pop.value = stack_pop_call return stack_pop
def create_set_type_of(var_name, new_value, lineno, col_offset): set_type_of_comment = create_src_comment("Type assignment", lineno) set_type_of_method = core_language_copy.create_attribute( default_module_type_store_var_name, "set_type_of") localization = create_localization(lineno, col_offset) set_type_of_call = functions_copy.create_call_expression( set_type_of_method, [ localization, core_language_copy.create_str(var_name, lineno, col_offset), new_value ]) return flatten_lists(set_type_of_comment, set_type_of_call)
def create_set_type_store(type_store_param, clone=True): attribute = core_language_copy.create_attribute("type_store", "set_type_store") if clone: clone_param = core_language_copy.create_Name("True") else: clone_param = core_language_copy.create_Name("False") set_call = functions_copy.create_call(attribute, [type_store_param, clone_param]) set_expr = ast.Expr() set_expr.value = set_call return set_expr
def create_stacktrace_push(func_name, declared_arguments): """ Creates an AST Node that model the call to the localitazion.set_stack_trace method :param func_name: Name of the function that will do the push to the stack trace :param declared_arguments: Arguments of the call :return: An AST Expr node """ # Code to push a new stack trace to handle errors. attribute = core_language_copy.create_attribute("localization", "set_stack_trace") arguments_var = core_language_copy.create_Name("arguments") stack_push_call = create_call(attribute, [core_language_copy.create_str(func_name), declared_arguments, arguments_var]) stack_push = ast.Expr() stack_push.value = stack_push_call return stack_push
def create_context_set(func_name, lineno, col_offset): """ Creates an AST Node that model the call to the type_store.set_context method :param func_name: Name of the function that will do the push to the stack trace :param lineno: Line :param col_offset: Column :return: An AST Expr node """ attribute = core_language_copy.create_attribute("type_store", "set_context") context_set_call = create_call(attribute, [core_language_copy.create_str(func_name), core_language_copy.create_num(lineno), core_language_copy.create_num(col_offset)]) context_set = ast.Expr() context_set.value = context_set_call return context_set
def create_set_type_of_member(owner_var, member_name, value, lineno, col_offset): comment = create_src_comment( "Setting the type of the member '{0}' of a type".format(member_name), lineno) localization = create_localization(lineno, col_offset) # TODO: Remove? # set_type_of_member_func = core_language_copy.create_Name('set_type_of_member') # set_type_of_member_call = functions_copy.create_call_expression(set_type_of_member_func, [localization, onwer_var, # core_language_copy.create_str( # member_name), value]) set_type_of_member_func = core_language_copy.create_attribute( owner_var, 'set_type_of_member') set_type_of_member_call = functions_copy.create_call_expression( set_type_of_member_func, [localization, core_language_copy.create_str(member_name), value]) return flatten_lists(comment, set_type_of_member_call)
def create_clone_type_store(): attribute = core_language_copy.create_attribute("type_store", "clone_type_store") clone_call = functions_copy.create_call(attribute, []) return create_temp_type_store_Assign(clone_call)