本文整理汇总了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
示例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
示例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
示例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)
示例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