Dump the function def of a macro or call block.
493886
def macro_body(self, node, frame, children=None):
        """"""
        frame = self.function_scoping(node, frame, children)
        # macros are delayed, they never require output checks
        frame.require_output_check = False
        args = frame.arguments
        # XXX: this is an ugly fix for the loop nesting bug
        # (tests.test_old_bugs.test_loop_call_bug).  This works around
        # a identifier nesting problem we have in general.  It's just more
        # likely to happen in loops which is why we work around it.  The
        # real solution would be "nonlocal" all the identifiers that are
        # leaking into a new python frame and might be used both unassigned
        # and assigned.
        if 'loop' in frame.identifiers.declared:
            args = args + ['l_loop=l_loop']
        self.writeline('def macro(%s):' % ', '.join(args), node)
        self.indent()
        self.buffer(frame)
        self.pull_locals(frame)
        self.blockvisit(node.body, frame)
        self.return_buffer_contents(frame)
        self.outdent()
        return frame
1270865
def function_parser(function, parser):
    """"""

    # Store the function pointer on the parser for later use
    parser.set_defaults(func=function)

    # Get the help text and parse it for params
    help_text = inspect.getdoc(function)
    main_text, params_help = parser_help_text(help_text)

    # Get the function information
    args, varargs, keywords, defaults = inspect.getargspec(function)
    if args is None:
        args = []

    if defaults is None:
        defaults = []

    # If the function is a class method, it will have a self that needs to be removed
    if len(args) and args[0] == 'self':
        args.pop(0)

    # Work out whether the argument has a default by subtracting the length
    # of the default args from the number of arguments
    num_required_args = len(args) - len(defaults)
    for idx, arg in enumerate(args):
        if idx < num_required_args:
            arg_name, arg_params = calculate_default_type(arg, False, None, params_help)
        else:
            default_value = defaults[idx - num_required_args]
            arg_name, arg_params = calculate_default_type(arg, True, default_value, params_help)

        parser.add_argument(arg_name, **arg_params)
656443
def macro_def(self, macro_ref, frame):
        """"""
        arg_tuple = ', '.join(repr(x.name) for x in macro_ref.node.args)
        name = getattr(macro_ref.node, 'name', None)
        if len(macro_ref.node.args) == 1:
            arg_tuple += ','
        self.write('Macro(environment, macro, %r, (%s), %r, %r, %r, '
                   'context.eval_ctx.autoescape)' %
                   (name, arg_tuple, macro_ref.accesses_kwargs,
                    macro_ref.accesses_varargs, macro_ref.accesses_caller))
1108918
def Macro(self, macro):
        """"""
        if macro.location is None:
            log.info('Ignoring %s with no location', macro.name)
            return
        if self.generate_locations:
            print("# %s:%s" % (macro.location), file=self.stream)
        if self.generate_comments:
            self.print_comment(macro)
        print("%s = %s # macro" % (macro.name, macro.body), file=self.stream)
        self.macros += 1
        self.names.add(macro.name)
        return
1309041
def trace(self, func):
        """"""

        def wrapper(*args, **kwargs):
            # Print out the call to the function with its arguments.
            s = self.Stanza(self.indent)
            s.add([self.GREEN, func.__name__, self.NORMAL, '('])
            s.indent += 4
            sep = ''
            for arg in args:
                s.add([self.CYAN, self.safe_repr(arg), self.NORMAL], sep)
                sep = ', '
            for name, value in sorted(kwargs.items()):
                s.add([name + '=', self.CYAN, self.safe_repr(value),
                       self.NORMAL], sep)
                sep = ', '
            s.add(')', wrap=False)
            self.writer.write(s.chunks)

            # Call the function.
            self.indent += 2
            try:
                result = func(*args, **kwargs)
            except:
                # Display an exception.
                self.indent -= 2
                etype, evalue, etb = self.sys.exc_info()
                info = self.inspect.getframeinfo(etb.tb_next, context=3)
                s = self.Stanza(self.indent)
                s.add([self.RED, '!> ', self.safe_repr(evalue), self.NORMAL])
                s.add(['at ', info.filename, ':', info.lineno], ' ')
                lines = self.unindent(info.code_context)
                firstlineno = info.lineno - info.index
                fmt = '%' + str(len(str(firstlineno + len(lines)))) + 'd'
                for i, line in enumerate(lines):
                    s.newline()
                    s.add([
                        i == info.index and self.MAGENTA or '',
                        fmt % (i + firstlineno),
                        i == info.index and '> ' or ': ', line, self.NORMAL])
                self.writer.write(s.chunks)
                raise

            # Display the return value.
            self.indent -= 2
            s = self.Stanza(self.indent)
            s.add([self.GREEN, '-> ', self.CYAN, self.safe_repr(result),
                   self.NORMAL])
            self.writer.write(s.chunks)
            return result
        return self.functools.update_wrapper(wrapper, func)
260345
def calldefs(
            self,
            name=None,
            function=None,
            return_type=None,
            arg_types=None,
            header_dir=None,
            header_file=None,
            recursive=None,
            allow_empty=None):
        """"""
        return (
            self._find_multiple(
                self._impl_matchers[scopedef_t.calldef],
                name=name,
                function=function,
                decl_type=self._impl_decl_types[
                    scopedef_t.calldef],
                return_type=return_type,
                arg_types=arg_types,
                header_dir=header_dir,
                header_file=header_file,
                recursive=recursive,
                allow_empty=allow_empty)
        )
931826
def visit_functiondef(self, node):
        """"""
        decorate = node.decorators.accept(self) if node.decorators else ""
        docs = self._docs_dedent(node.doc) if node.doc else ""
        trailer = ":"
        if node.returns:
            return_annotation = "->" + node.returns.as_string()
            trailer = return_annotation + ":"
        def_format = "\n%sdef %s(%s)%s%s\n%s"
        return def_format % (
            decorate,
            node.name,
            node.args.accept(self),
            trailer,
            docs,
            self._stmt_list(node.body),
        )
1347136
def main(arguments=None):   # suppress(unused-function)
    """"""
    result = _parse_arguments(arguments)
    linter_funcs = _ordered(linter_functions_from_filters,
                            result.whitelist,
                            result.blacklist)
    global_options = vars(result)
    tool_options = tool_options_from_global(global_options, len(result.files))
    any_would_run = _any_would_run(_run_lint_on_file_exceptions,
                                   result.files,
                                   result.stamp_file_path,
                                   result.log_technical_terms_to,
                                   linter_funcs,
                                   tool_options,
                                   result.fix_what_you_can)

    if any_would_run:
        for linter_function in linter_funcs.values():
            if linter_function.before_all:
                linter_function.before_all(global_options, tool_options)

        use_multiprocessing = _should_use_multiprocessing(len(result.files))
    else:
        use_multiprocessing = False

    if use_multiprocessing:
        mapper = parmap.map
    else:
        # suppress(E731)
        mapper = lambda f, i, *a: [f(*((x, ) + a)) for x in i]

    errors = list(itertools.chain(*mapper(_run_lint_on_file_stamped,
                                          result.files,
                                          result.stamp_file_path,
                                          result.log_technical_terms_to,
                                          linter_funcs,
                                          tool_options,
                                          result.fix_what_you_can)))

    for error in sorted(errors):
        _report_lint_error(error.failure, os.path.relpath(error.absolute_path))

    if any_would_run:
        for linter_funcs in linter_funcs.values():
            if linter_funcs.after_all:
                linter_funcs.after_all(global_options, tool_options)

    return len(errors)
998655
def dump(self, value: Any) -> Any:
        
        index = self.index(value)
        func = self.handlers[index][1]
        return func(self, value)
279138
def function_call_action(self, text, loc, fun):
        """"""
        exshared.setpos(loc, text)
        if DEBUG > 0:
            print("FUN_CALL:",fun)
            if DEBUG == 2: self.symtab.display()
            if DEBUG > 2: return
        #check number of arguments
        if len(self.function_arguments) != self.symtab.get_attribute(self.function_call_index):
            raise SemanticException("Wrong number of arguments for function '%s'" % fun.name)
        #arguments should be pushed to stack in reverse order
        self.function_arguments.reverse()
        self.codegen.function_call(self.function_call_index, self.function_arguments)
        self.codegen.restore_used_registers()
        return_type = self.symtab.get_type(self.function_call_index)
        #restore previous function call data
        self.function_call_index = self.function_call_stack.pop()
        self.function_arguments = self.function_arguments_stack.pop()
        register = self.codegen.take_register(return_type)
        #move result to a new free register, to allow the next function call
        self.codegen.move(self.codegen.take_function_register(return_type), register)
        return register
973478
def dump(cls):
        """"""
        with cls.lock:
            if not cls.instances: return
            atexit.unregister(cls.dump)

            for self in cls.instances.values():
                self.fh.close()
999518
def _print_function(self, f, prefix, fullname, func):
    """"""
    heading = prefix + " `" + fullname
    if not isinstance(func, property):
      heading += self._generate_signature_for_function(func)
    heading += "` {#%s}" % _get_anchor(self._module_to_name, fullname)
    print(heading, file=f)
    print("", file=f)
    self._print_formatted_docstring(inspect.getdoc(func), f)
    print("", file=f)
981513
def dump(self, function_name):
        

        assert isinstance(function_name, str)
        self.stdout.write(function_name)
        self.stdout.write("\n")
        self.stdout.write("-" * len(function_name))
        self.stdout.write("\n\n")

        byte_code = self.interpreter.compiled_functions[function_name]
        self.stdout.write(byte_code.dump())
        self.stdout.write("\n")
1240031
def compile_func(arg_names, statements, name='_the_func', debug=False):
    
    func_def = ast.FunctionDef(
        name=name,
        args=ast.arguments(
            args=[ast.arg(arg=n, annotation=None) for n in arg_names],
            kwonlyargs=[],
            kw_defaults=[],
            defaults=[ex_literal(None) for _ in arg_names],
        ),
        body=statements,
        decorator_list=[],
    )

    mod = ast.Module([func_def])
    ast.fix_missing_locations(mod)

    prog = compile(mod, '<generated>', 'exec')

    # Debug: show bytecode.
    if debug:
        dis.dis(prog)
        for const in prog.co_consts:
            if isinstance(const, types.CodeType):
                dis.dis(const)

    the_locals = {}
    exec(prog, {}, the_locals)
    return the_locals[name]
973056
def func_call(self, t):
        
        func, params = t
        func_name = func.value
        func.value = "({}({}))".format(func_name, params)
        return func
334891
def dump(self):
        
        logger.warn('This function is deprecated and replaced by `dump_np_vars`.')

        ret = False

        if self.system.files.no_output:
            # return ``True`` because it did not fail
            return True

        if self.write_lst() and self.write_dat():
            ret = True

        return ret
1225355
def _dump_impl():
    # type: () -> List[FunctionData]
    """"""
    filtered_signatures = _filter_types(collected_signatures)
    sorted_by_file = sorted(iteritems(filtered_signatures),
                            key=(lambda p: (p[0].path, p[0].line, p[0].func_name)))
    res = []  # type: List[FunctionData]
    for function_key, signatures in sorted_by_file:
        comments = [_make_type_comment(args, ret_type) for args, ret_type in signatures]
        res.append(
            {
                'path': function_key.path,
                'line': function_key.line,
                'func_name': function_key.func_name,
                'type_comments': comments,
                'samples': num_samples.get(function_key, 0),
            }
        )
    return res