Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
admin
/
installer
/
css
/
sass
/
sym404
/
root
/
opt
/
alt
/
python38
/
share
/
doc
/
alt-python38-pycparser
/
examples
:
func_defs.py
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
#----------------------------------------------------------------- # pycparser: func_defs.py # # Using pycparser for printing out all the functions defined in a # C file. # # This is a simple example of traversing the AST generated by # pycparser. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- from __future__ import print_function import sys from pycparser import c_parser, c_ast, parse_file # A simple visitor for FuncDef nodes that prints the names and # locations of function definitions. class FuncDefVisitor(c_ast.NodeVisitor): def visit_FuncDef(self, node): print('%s at %s' % (node.decl.name, node.decl.coord)) def show_func_defs(filename): # Note that cpp is used. Provide a path to your own cpp or # make sure one exists in PATH. ast = parse_file(filename, use_cpp=True) v = FuncDefVisitor() v.visit(ast) if __name__ == "__main__": if len(sys.argv) > 1: filename = sys.argv[1] else: filename = 'examples/c_files/memmgr.c' show_func_defs(filename)