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


Python TranslationUnit.from_ast_file方法代码示例

本文整理汇总了Python中clang.cindex.TranslationUnit.from_ast_file方法的典型用法代码示例。如果您正苦于以下问题:Python TranslationUnit.from_ast_file方法的具体用法?Python TranslationUnit.from_ast_file怎么用?Python TranslationUnit.from_ast_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clang.cindex.TranslationUnit的用法示例。


在下文中一共展示了TranslationUnit.from_ast_file方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fail_from_ast_file

# 需要导入模块: from clang.cindex import TranslationUnit [as 别名]
# 或者: from clang.cindex.TranslationUnit import from_ast_file [as 别名]
def test_fail_from_ast_file():
    path = os.path.join(kInputsDir, 'non-existent.ast')
    try:
        tu = TranslationUnit.from_ast_file(path)
    except TranslationUnitLoadError:
        tu = None
    assert tu == None
开发者ID:AntonBikineev,项目名称:clang,代码行数:9,代码来源:test_translation_unit.py

示例2: test_load_pathlike

# 需要导入模块: from clang.cindex import TranslationUnit [as 别名]
# 或者: from clang.cindex.TranslationUnit import from_ast_file [as 别名]
    def test_load_pathlike(self):
        """Ensure TranslationUnits can be constructed from saved files -
        PathLike variant."""
        tu = get_tu('int foo();')
        self.assertEqual(len(tu.diagnostics), 0)
        with save_tu(tu) as path:
            tu2 = TranslationUnit.from_ast_file(filename=str_to_path(path))
            self.assertEqual(len(tu2.diagnostics), 0)

            foo = get_cursor(tu2, 'foo')
            self.assertIsNotNone(foo)

            # Just in case there is an open file descriptor somewhere.
            del tu2
开发者ID:LegalizeAdulthood,项目名称:clang,代码行数:16,代码来源:test_translation_unit.py

示例3: test_load

# 需要导入模块: from clang.cindex import TranslationUnit [as 别名]
# 或者: from clang.cindex.TranslationUnit import from_ast_file [as 别名]
    def test_load(self):
        """Ensure TranslationUnits can be constructed from saved files."""

        tu = get_tu('int foo();')
        self.assertEqual(len(tu.diagnostics), 0)
        with save_tu(tu) as path:
            self.assertTrue(os.path.exists(path))
            self.assertGreater(os.path.getsize(path), 0)

            tu2 = TranslationUnit.from_ast_file(filename=path)
            self.assertEqual(len(tu2.diagnostics), 0)

            foo = get_cursor(tu2, 'foo')
            self.assertIsNotNone(foo)

            # Just in case there is an open file descriptor somewhere.
            del tu2
开发者ID:LegalizeAdulthood,项目名称:clang,代码行数:19,代码来源:test_translation_unit.py

示例4: test_load

# 需要导入模块: from clang.cindex import TranslationUnit [as 别名]
# 或者: from clang.cindex.TranslationUnit import from_ast_file [as 别名]
def test_load():
    """Ensure TranslationUnits can be constructed from saved files."""

    tu = get_tu('int foo();')
    assert len(tu.diagnostics) == 0
    path = save_tu(tu)

    assert os.path.exists(path)
    assert os.path.getsize(path) > 0

    tu2 = TranslationUnit.from_ast_file(filename=path)
    assert len(tu2.diagnostics) == 0

    foo = get_cursor(tu2, 'foo')
    assert foo is not None

    # Just in case there is an open file descriptor somewhere.
    del tu2

    os.unlink(path)
开发者ID:AntonBikineev,项目名称:clang,代码行数:22,代码来源:test_translation_unit.py

示例5: _ast_files_to_callinfo

# 需要导入模块: from clang.cindex import TranslationUnit [as 别名]
# 或者: from clang.cindex.TranslationUnit import from_ast_file [as 别名]
def _ast_files_to_callinfo(directory):
    index = Index(conf.lib.clang_createIndex(False, True))

    # don't list comprehend so we can get better error reporting
    units = []
    for path in _ast_files(directory):
        try:
            units.append((os.path.abspath(path),
                          TranslationUnit.from_ast_file(path, index)))
        except Exception as e:
            print("error parsing {}, python clang version might be different"
                  "from compiled clang version?".format(path))
            print(e.args)
            print(e.message)
            raise

    ci = CallInfo()

    for path, tu in units:
        for cursor in tu.cursor.get_children():
            # seems hacky, probably misses c++ cases
            # stuff from includes has the include's filename
            if ((cursor.kind == CursorKind.VAR_DECL) and
                (cursor.location.file.name == tu.spelling)):
                ci.add_global(cursor)

    for path, tu in units:
        # WARNING: this will fail silently and unexpectedly if
        # the version of clang that generated the .ast files is
        # different from the python clang library
        sys.stderr.write("  processing ast file {}\n".format(path))
        sys.stderr.flush()
        for cursor in tu.cursor.get_children():
            if (cursor.kind == CursorKind.FUNCTION_DECL or
                cursor.kind == CursorKind.VAR_DECL):
                decl = ci.add_decl(cursor)
                ci.walk_decl(cursor, decl)
    return ci
开发者ID:charredlot,项目名称:misc-crap,代码行数:40,代码来源:calltree_from_ast.py


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