当前位置: 首页>>代码示例>>Python>>正文


Python pycparser.parse_file函数代码示例

本文整理汇总了Python中pycparser.parse_file函数的典型用法代码示例。如果您正苦于以下问题:Python parse_file函数的具体用法?Python parse_file怎么用?Python parse_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的pycparser.parse_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。