本文整理汇总了Python中pycparser.parse_file函数的典型用法代码示例。如果您正苦于以下问题:Python parse_file函数的具体用法?Python parse_file怎么用?Python parse_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_with_cpp
def test_with_cpp(self):
ast = parse_file('c_files/memmgr.c', use_cpp=True,
cpp_path=CPPPATH,
cpp_args=r'-I../utils/fake_libc_include')
self.failUnless(isinstance(ast, c_ast.FileAST))
ast2 = parse_file('c_files/year.c', use_cpp=True,
cpp_path=CPPPATH,
cpp_args=r'-I../utils/fake_libc_include')
self.failUnless(isinstance(ast2, c_ast.FileAST))
开发者ID:farseerfc,项目名称:pytoken,代码行数:11,代码来源:test_general.py
示例2: test_with_cpp
def test_with_cpp(self):
c_files_path = os.path.join('tests', 'c_files')
ast = parse_file(self._find_file('memmgr.c'), use_cpp=True,
cpp_path=CPPPATH,
cpp_args='-I%s' % c_files_path)
self.failUnless(isinstance(ast, c_ast.FileAST))
ast2 = parse_file(self._find_file('year.c'), use_cpp=True,
cpp_path=CPPPATH,
cpp_args=r'-Iutils/fake_libc_include')
self.failUnless(isinstance(ast2, c_ast.FileAST))
开发者ID:pombredanne,项目名称:pycparser-1,代码行数:12,代码来源:test_general.py
示例3: get_func_decls
def get_func_decls(filename, args):
cpp_args = s_cpp_args(args)
if args.cpp.lower() == "none":
ast = parse_file(filename)
else:
ast = parse_file(filename,
use_cpp=True,
cpp_path=os.path.join(os.path.dirname(__file__), "fake_cpp"),
cpp_args=cpp_args)
v = FuncDeclVisitor()
for idx, node in ast.children():
v.visit(node)
return v._ret
开发者ID:ZMQers,项目名称:zproject,代码行数:13,代码来源:mkapi.py
示例4: test_with_cpp
def test_with_cpp(self):
memmgr_path = self._find_file('memmgr.c')
c_files_path = os.path.dirname(memmgr_path)
ast = parse_file(memmgr_path, use_cpp=True,
cpp_path=CPPPATH,
cpp_args='-I%s' % c_files_path)
self.assertTrue(isinstance(ast, c_ast.FileAST))
fake_libc = os.path.join(c_files_path, '..', '..',
'utils', 'fake_libc_include')
ast2 = parse_file(self._find_file('year.c'), use_cpp=True,
cpp_path=CPPPATH,
cpp_args=[r'-I%s' % fake_libc])
self.assertTrue(isinstance(ast2, c_ast.FileAST))
开发者ID:18600597055,项目名称:hue,代码行数:15,代码来源:test_general.py
示例5: translate_to_c
def translate_to_c(filename):
""" Simply use the c_generator module to emit a parsed AST.
"""
ast = parse_file(filename, use_cpp=True)
generator = c_generator.CGenerator()
ast.show()
print(generator.visit(ast))
开发者ID:code-injection-detection,项目名称:gcc-Linux-Implementation,代码行数:7,代码来源:c-to-c.py
示例6: create_test_case
def create_test_case(ppcg_input_file, ppcg_output_files):
assert len(ppcg_output_files) == 1, "Currently support OpenCL only for VOBLA"
# Remove PENCIL qualifiers from C code otherwise it will not parse
remove_pencil_qualifiers_from_file(ppcg_input_file)
# Pre-process and parse the file
ast = pycparser.parse_file(ppcg_input_file, use_cpp=True)
gen = c_generator.CGenerator()
gen.visit(ast)
# Find PENCIL function declarations
pencil_info = FuncDeclVisitor()
pencil_info.visit(ast)
# Find struct definitions
struct_info = StructDefintionVisitor()
struct_info.visit(ast)
# We need the struct and function prototypes to dump in the test file
ast_new_file = copy_ast_declarations(pencil_info, struct_info)
# Analyse the types of parameters in each PENCIL function
for function_name in pencil_info.functions.keys():
for formal_param in pencil_info.get_formal_params(function_name):
decorate_formal_params(formal_param, struct_info)
# Create a main function that will call the PENCIL functions
main_func = create_main(pencil_info)
ast_new_file.ext.append(main_func)
# Write the program to a file
test_file = write_to_file(ast_new_file, ppcg_input_file)
# Compile the code
binary = compile_test_case(test_file, ppcg_output_files[0])
return binary
开发者ID:carpproject,项目名称:autotuner,代码行数:28,代码来源:blas_function_testing.py
示例7: translate
def translate(filename, args, portion=None):
try:
ast = pycparser.parse_file(filename, use_cpp=True)
et_obj = EnumTranslator(ast, args.enum, args.output_class)
translate_params = {
'import_line': args.importline,
'header': args.header,
'comment': args.comment,
'hash_type': 'SHA-1',
'hash_value': sha1sum(args.header),
'portion': portion
}
et_obj.translate(translate_params, args.stop)
except pycparser.plyparser.ParseError as exc:
eprint('Translation error, try to use -p option with proper '
'boundaries')
eprint(exc)
return
except TypeError:
eprint('Translation error, try to use -s option with a stop '
'enumerator parameter')
return
if args.output:
with open(args.output, 'w') as ftw:
et_obj.write(ftw)
else:
et_obj.write()
开发者ID:mojaves,项目名称:pyrana,代码行数:30,代码来源:make_enum.py
示例8: generate_xml
def generate_xml(filename):
ast = parse_file(filename, use_cpp=True)
visitor = FuncDeclVisitor()
print '<?xml version="1.0" encoding="UTF-8"?>'
print "<blas_functions>"
visitor.visit(ast)
print "</blas_functions>"
开发者ID:pc2,项目名称:liftracc,代码行数:7,代码来源:cublas2xml.py
示例9: show_decl_file
def show_decl_file(filename):
ast = parse_file(filename, use_cpp=True)
v = FuncDefVisitor()
v.visit(ast)
v = TypeDeclVisitor()
v.visit(ast)
printTypes()
开发者ID:ndlu2,项目名称:minthint-statetransformer,代码行数:7,代码来源:typeGenerator.py
示例10: generate_test_app
def generate_test_app():
c_file = os.path.join(test_app_dir, 'pycparser_main.c')
ast = parse_file(c_file,
use_cpp=True,
cpp_path=os.path.join(os.environ.get('XMOS_TOOL_PATH'),
'bin', 'xcc'),
cpp_args=['-E',
'{}{}'.format('-I',
os.path.join('..','lib_xcore_c','api')),
'{}{}'.format('-I',
os.path.join('..','lib_xcore_c','src')),
'{}{}'.format('-I',
os.path.join('..','..','lib_trycatch','lib_trycatch','api')),
'{}{}'.format('-I',
os.path.join('..','..','lib_trycatch','lib_trycatch','src')),
'{}{}'.format('-I',
os.path.join('..','..','lib_xassert','lib_xassert','api'))
]
)
functions = LibraryFunctionExtractor()
function_call_blocks = functions.get_function_call_blocks(ast)
with open(os.path.join(test_app_dir, 'test.c'), "w") as test_c_file:
test_c_file.writelines(file_top)
test_c_file.writelines(function_call_blocks)
test_c_file.writelines(file_bottom)
开发者ID:samchesney,项目名称:lib_xcore_c,代码行数:27,代码来源:test_build_with_no_inline.py
示例11: show_func_defs
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)
开发者ID:18600597055,项目名称:hue,代码行数:7,代码来源:func_defs.py
示例12: translate_to_go
def translate_to_go(filename):
firstname = filename
if "." in filename:
firstname = filename.rsplit(".", 1)[0]
clearlog()
f = open(filename)
data = f.read()
f.close()
data = cleanup(data)
#filename = tempfile.mkstemp()[1]
filename2 = "/tmp/jeje"
f = open(filename2, "w")
f.write(data)
f.close()
try:
ast = parse_file(filename2, use_cpp=True)
except plyparser.ParseError as e:
print("Could not parse %s:" % (filename))
print("line " + "".join(str(e).split(":", 1)[1:]))
return
generator = GoGenerator()
s = generator.visit(ast)
s = generator.fix_int_to_bool(s)
s = generator.last_minute_replacements(s, firstname)
s = generator.make_header() + s
print(s)
开发者ID:glycerine,项目名称:c2go-1,代码行数:34,代码来源:c2go.py
示例13: parse_header
def parse_header(filename):
return parse_file(filename,
use_cpp=True,
cpp_args=[
r'-I{}'.format(os.path.dirname(filename)),
r'-I{}'.format(FAKE_LIBC_INCLUDE_DIR),
r'-D_DOXYGEN_ONLY_'])
开发者ID:wxh0000mm,项目名称:bladeRF,代码行数:7,代码来源:import_header.py
示例14: show_func_defs
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, cpp_args=r"-Iutils/fake_libc_include")
v = FuncDefVisitor()
v.visit(ast)
开发者ID:jamie-pate,项目名称:pycparser,代码行数:7,代码来源:func_defs.py
示例15: translate
def translate(filename):
ast = parse_file(filename,
use_cpp=True,
cpp_path='gcc',
cpp_args=[
"-E",
"-D__FBSDID(x)=", # FreeBSD identifier
"-D__attribute__(x)=", # attribute extension
"-D__builtin_va_list=void*", # include/x86/_types.h:154 typedef __builtin_va_list __va_list;
"-D__inline=",
"-D__asm(x)=",
"-D_RUNETYPE_H_=1", # skip include/runtype.h
"-D_RuneLocale=void*", # but it defines this type
"-D_Noreturn=",
"-U__BLOCKS__", # no (^) syntax: include/stdlib.h: int atexit_b(void (^)(void));
"-U__nonnull", # avoid __nonnull redefinition
"-nostdinc",
"-Ipycparser/utils/fake_libc_include",
"-Iinclude", # copy from /usr/include
])
generator = js_generator.JavaScriptGenerator()
print(generator.visit(ast))
开发者ID:deathcap,项目名称:transpile-c-to-js,代码行数:26,代码来源:ptranspile-c.py
示例16: create_func_defs
def create_func_defs(filename):
ast = parse_file(filename, use_cpp=True)
v = FuncDeclVisitor()
v.visit(ast)
return v.buffer
开发者ID:agren,项目名称:cstubgenerator,代码行数:7,代码来源:cstubgenerator.py
示例17: generate
def generate(filename, origin_path, gen_path):
ast = parse_file(os.path.join(origin_path, filename), use_cpp=True,
cpp_path='gcc',
cpp_args=['-E', r'-D' + CSMITH_MINIMAL_MACRO, r'-I' + CSMITH_RUNTIME, r'-I' + FAKE_SYS_LIB])
# parser = c_parser.CParser()
# ast = parser.parse(code)
# construct an error label
checkpoint = c_ast.FuncCall(c_ast.ID('__VERIFIER_error'), None)
error_label = c_ast.Label("ERROR", checkpoint)
num_ext_children = len(ast.ext)
print("## num of ext children: " + str(num_ext_children))
funcs = findAllFuncDef(ast)
for picked in funcs:
# picked = random.randint(0, len(funcs)-1)
seed_fun = funcs.index(picked)
print("## Function picked: " + str(seed_fun))
seed = ast.ext.index(picked)
print("## Seed: " + str(seed))
numInsert = algo.countAllInsertion(ast.ext[seed].body, 0)
print("$$$$$ numInsert is " + str(numInsert))
for i in range(1, numInsert+1):
ast_new = copy.deepcopy(ast)
ast_new.ext[seed].body = checkpoint_insert_if(ast_new.ext[seed].body, i, error_label)
code = c_generator.CGenerator().visit(ast_new)
code_new = removeNonSupport(code)
basename = filename
basename_gen, file_extension = os.path.splitext(basename)
filename_gen = gen_path + basename_gen + postfix + str(seed_fun) + '-' + str(i) + file_extension
# print "hhhhhhhhhhhhhhhhh" + basename_gen
dumpToFile(filename_gen, code_new)
print("## Generate: " + filename_gen)
开发者ID:njaliu,项目名称:GenT,代码行数:35,代码来源:prog_monkey_csmith.py
示例18: _get_imp_funcs
def _get_imp_funcs(c_fpath):
"""Gets the functions that can be imported from a C file."""
# gets the path of the fake system headers
fsh_path = os.path.join(__path__[0], 'pycparser', 'fake_libc_include')
# TODO: USE THE cpp.py MODULE TO PREPROCESS THE FILE
# gets the AST
ast = pycparser.parse_file(c_fpath, use_cpp=c_fpath, cpp_args=['-I', fsh_path])
# function definition info collector class
class FuncDefVisitor(pycparser.c_ast.NodeVisitor):
def __init__(self):
pycparser.c_ast.NodeVisitor.__init__(self)
self.func_names = []
def visit_FuncDef(self, node):
self.func_names.append(node.decl.name)
# gets the function definition info
v = FuncDefVisitor()
v.visit(ast)
# returns the function definition info
return v.func_names
开发者ID:mchouza,项目名称:cimport,代码行数:25,代码来源:__init__.py
示例19: process_file
def process_file(filename, incpath):
cppargs = ["-Iutils/fake_libc_include", "-I%s" % incpath,
"-DDECLSPEC=",
"-D_SDL_platform_h=1",
"-D_SDL_endian_h=1",
"-DSDL_FORCE_INLINE=", "-D__attribute__(x)=",
];
ast = parse_file(filename, use_cpp=True, cpp_args=cppargs);
v = visitor();
v.visit(ast);
del ast;
cppargs.append("-dM");
defines_text = preprocess_file(filename, cpp_args=cppargs);
for s in defines_text.split("\n"):
if s[:8] == "#define ":
s = s[8:];
m = re.search("(SDL_[A-Za-z0-9_]+)", s);
if m != None:
d = m.group(0);
if isinstance(d, str) and len(d) > 4 and d == d.upper():
v.defines.append(d);
generate_output("sdl2.vim", v);
开发者ID:keltar,项目名称:sdl2_vim_syntax,代码行数:25,代码来源:sdl2_vim.py
示例20: parse_jamaica_output
def parse_jamaica_output(filename, includepath = None):
"""
Use pycparser to parse a Jamaica output file.
Because Jamaica's output is pretty complex, cpp is required, and even still
some features have to be removed because it uses GCC extensions unsupported by pycparser.
Returns a pycparser.c_ast or throws ParseError
If includepath is None then the project include files are used for parsing. Else, an absolute
path to alternate includes can be provided.
"""
if '*' in filename:
filename = deglob_file(filename)
cppargs = ['-E',
'-DNDEBUG', #Disable Jamaica debug support
'-U__GNUC__', #Prevents use of __attribute__, will cause an "unsupported compiler" #warning
#'-W#warnings', #And this hides that warning
'-DJAMAICA_NATIVE_TIME_GET_HIGH_RESOLUTION_TIMESTAMP', #These use volatile asm() which is not supported by pycparser
'-DJAMAICA_NATIVE_THREAD_COMPARE_AND_SWAP',
'-D__CAICOS__', #So we can tell if we are being parsed by caicos
r'-I' + project_path("stdlibheaders"), #Override stdlib headers with blank versions (Jamaica builder doesn't use them, but includes them)
]
if includepath == None:
cppargs.append(r'-I' + project_path("projectfiles", "include"))
else:
cppargs.append(r'-I' + str(includepath))
return pycparser.parse_file(filename, use_cpp=True, cpp_path="gcc", cpp_args=cppargs)
开发者ID:carriercomm,项目名称:caicos,代码行数:29,代码来源:astcache.py
注:本文中的pycparser.parse_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论