#===- cindex.py - Python Indexing Library Bindings -----------*- python -*--===#
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#
r"""
Clang Indexing Library Bindings
===============================
This module provides an interface to the Clang indexing library. It is a
low-level interface to the indexing library which attempts to match the Clang
API directly while also being "pythonic". Notable differences from the C API
are:
* string results are returned as Python strings, not CXString objects.
* null cursors are translated to None.
* access to child cursors is done via iteration, not visitation.
The major indexing objects are:
Index
The top-level object which manages some global library state.
TranslationUnit
High-level object encapsulating the AST for a single translation unit. These
can be loaded from .ast files or parsed on the fly.
Cursor
Generic object for representing a node in the AST.
SourceRange, SourceLocation, and File
Objects representing information about the input source.
Most object information is exposed using properties, when the underlying API
call is efficient.
"""
# TODO
# ====
#
# o API support for invalid translation units. Currently we can't even get the
# diagnostics on failure because they refer to locations in an object that
# will have been invalidated.
#
# o fix memory management issues (currently client must hold on to index and
# translation unit, or risk crashes).
#
# o expose code completion APIs.
#
# o cleanup ctypes wrapping, would be nice to separate the ctypes details more
# clearly, and hide from the external interface (i.e., help(cindex)).
#
# o implement additional SourceLocation, SourceRange, and File methods.
from ctypes import *
import collections
import clang.enumerations
# ctypes doesn't implicitly convert c_void_p to the appropriate wrapper
# object. This is a problem, because it means that from_parameter will see an
# integer and pass the wrong value on platforms where int != void*. Work around
# this by marshalling object arguments as void**.
c_object_p = POINTER(c_void_p)
callbacks = {}
### Exception Classes ###
class TranslationUnitLoadError(Exception):
"""Represents an error that occurred when loading a TranslationUnit.
This is raised in the case where a TranslationUnit could not be
instantiated due to failure in the libclang library.
FIXME: Make libclang expose additional error information in this scenario.
"""
pass
class TranslationUnitSaveError(Exception):
"""Represents an error that occurred when saving a TranslationUnit.
Each error has associated with it an enumerated value, accessible under
e.save_error. Consumers can compare the value with one of the ERROR_
constants in this class.
"""
# Indicates that an unknown error occurred. This typically indicates that
# I/O failed during save.
ERROR_UNKNOWN = 1
# Indicates that errors during translation prevented saving. The errors
# should be available via the TranslationUnit's diagnostics.
ERROR_TRANSLATION_ERRORS = 2
# Indicates that the translation unit was somehow invalid.
ERROR_INVALID_TU = 3
def __init__(self, enumeration, message):
assert isinstance(enumeration, int)
if enumeration < 1 or enumeration > 3:
raise Exception("Encountered undefined TranslationUnit save error "
"constant: %d. Please file a bug to have this "
"value supported." % enumeration)
self.save_error = enumeration
Exception.__init__(self, 'Error %d: %s' % (enumeration, message))
### Structures and Utility Classes ###
class CachedProperty(object):
"""Decorator that lazy-loads the value of a property.
The first time the property is accessed, the original property function is
executed. The value it returns is set as the new value of that instance's
property, replacing the original method.
"""
def __init__(self, wrapped):
self.wrapped = wrapped
try:
self.__doc__ = wrapped.__doc__
except:
pass
def __get__(self, instance, instance_type=None):
if instance is None:
return self
value = self.wrapped(instance)
setattr(instance, self.wrapped.__name__, value)
return value
class _CXString(Structure):
"""Helper for transforming CXString results."""
_fields_ = [("spelling", c_char_p), ("free", c_int)]
def __del__(self):
conf.lib.clang_disposeString(self)
@staticmethod
def from_result(res, fn, args):
assert isinstance(res, _CXString)
return conf.lib.clang_getCString(res)
class SourceLocation(Structure):
"""
A SourceLocation represents a particular location within a source file.
"""
_fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
_data = None
def _get_instantiation(self):
if self._data is None:
f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
conf.lib.clang_getInstantiationLocation(self, byref(f), byref(l),
byref(c), byref(o))
if f:
f = File(f)
else:
f = None
self._data = (f, int(l.value), int(c.value), int(o.value))
return self._data
@staticmethod
def from_position(tu, file, line, column):
"""
Retrieve the source location associated with a given file/line/column in
a particular translation unit.
"""
return conf.lib.clang_getLocation(tu, file, line, column)
@staticmethod
def from_offset(tu, file, offset):
"""Retrieve a SourceLocation from a given character offset.
tu -- TranslationUnit file belongs to
file -- File instance to obtain offset from
offset -- Integer character offset within file
"""
return conf.lib.clang_getLocationForOffset(tu, file, offset)
@property
def file(self):
"""Get the file represented by this source location."""
return self._get_instantiation()[0]
@property
def line(self):
"""Get the line represented by this source location."""
return self._get_instantiation()[1]
@property
def column(self):
"""Get the column represented by this source location."""
return self._get_instantiation()[2]
@property
def offset(self):
"""Get the file offset represented by this source location."""
return self._get_instantiation()[3]
def __eq__(self, other):
return conf.lib.clang_equalLocations(self, other)
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
if self.file:
filename = self.file.name
else:
filename = None
return "<SourceLocation file %r, line %r, column %r>" % (
filename, self.line, self.column)
class SourceRange(Structure):
"""
A SourceRange describes a range of source locations within the source
code.
"""
_fields_ = [
("ptr_data", c_void_p * 2),
("begin_int_data", c_uint),
("end_int_data", c_uint)]
# FIXME: Eliminate this and make normal constructor? Requires hiding ctypes
# object.
@staticmethod
def from_locations(start, end):
return conf.lib.clang_getRange(start, end)
@property
def start(self):
"""
Return a SourceLocation representing the first character within a
source range.
"""
return conf.lib.clang_getRangeStart(self)
@property
def end(self):
"""
Return a SourceLocation representing the last character within a
source r
没有合适的资源?快使用搜索试试~ 我知道了~
nuclide源码_ReactNative IDE
共3418个文件
js:1846个
png:334个
json:282个
4星 · 超过85%的资源 需积分: 10 22 下载量 39 浏览量
2016-06-16
17:51:28
上传
评论
收藏 23MB ZIP 举报
温馨提示
2016.6.16最新,从GitHub上下载来的Facebook的nuclide源码,它是React_Native IDE。An open IDE for web and native mobile development, built on top of Atom http://nuclide.io。nuclide-master
资源推荐
资源详情
资源评论
收起资源包目录
nuclide源码_ReactNative IDE (3418个子文件)
.arcconfig 78B
atom-script 2KB
undo.backupfiles 71B
undo.backupfiles 2B
undo.bookmarks 0B
undo.bookmarks 0B
undo.branch 7B
undo.branch 7B
branch2-served 94B
branch2-served 94B
branchheads-served 1B
BUCK 427B
BUCK 172B
.buckconfig 1KB
.buckconfig 35B
.buckconfig 30B
.buckconfig 27B
.buckconfig 0B
.buckconfig 0B
.buckversion 42B
.buckversion 41B
.buckversion 41B
.buckversion 41B
.buckversion 41B
.buckversion 41B
process.c 191B
check_dependencies 1KB
CNAME 11B
openssl.cnf 1KB
completionhints 13B
completionhints 13B
threading.cpp 592B
outline.cpp 458B
test.cpp 165B
test.cpp 55B
a.cpp 13B
b.cpp 13B
create_package 6KB
hack.cson 108KB
ansi2.cson 20KB
ansi.cson 20KB
mercurial-commit-message.cson 2KB
javascript.cson 318B
objective-c.cson 246B
java.cson 201B
hack-fragment.cson 126B
EA2EC948C7D7C063B.css 55KB
21FF71D0D2122923F.css 47KB
537C133D913A8D41D.css 46KB
16C102A36B2DBC6E6.css 40KB
C32E9F0C757C29D4A.css 40KB
9C4B82DF21AA64A37.css 40KB
740083249BEF005F6.css 32KB
8E2ED03EAA5ED8BE2.css 32KB
E62638AD5B5A9C61A.css 32KB
B65C7771D2CCC2100.css 32KB
CB3CA0F49552DA871.css 30KB
B5A3A718F52798BF7.css 30KB
BC699FA675F9356E3.css 25KB
F0E469574253DABD5.css 25KB
7C6BEE7159DD678EF.css 23KB
888DDF1B4B9C1A5D5.css 22KB
52BE923A462D3F7AA.css 22KB
143BB439096CFDFC4.css 22KB
47EF802870551C878.css 22KB
695AC8DE58C109BF3.css 19KB
11F30310EFD3175B0.css 19KB
3919129618BB6AFD8.css 18KB
timelinePanel.css 18KB
inspectorStyle.css 17KB
elementsPanel.css 16KB
2C6F673F0C1CF0A97.css 16KB
E83A474C5EE950C81.css 16KB
helpScreen.css 15KB
networkLogView.css 13KB
responsiveDesignView.css 12KB
consoleView.css 10KB
resourcesPanel.css 9KB
statusBar.css 9KB
codemirror.css 7KB
cmdevtools.css 6KB
sourcesPanel.css 6KB
profilesPanel.css 6KB
elementsTreeOutline.css 6KB
overrides.css 6KB
sidebarPane.css 6KB
networkPanel.css 5KB
tabbedPane.css 5KB
splitView.css 5KB
inspectorSyntaxHighlight.css 5KB
heapProfiler.css 5KB
dataGrid.css 5KB
breakpointsList.css 4KB
canvasProfiler.css 4KB
popover.css 4KB
sourcesView.css 4KB
screencastView.css 4KB
auditsPanel.css 4KB
sourcesSearch.css 4KB
filter.css 4KB
共 3418 条
- 1
- 2
- 3
- 4
- 5
- 6
- 35
资源评论
- wht7916723002017-01-24我看的也不是很明白。。。
- myjf0072016-07-03怎么使用啊,看不是很明白
xiaoCong2015
- 粉丝: 4
- 资源: 62
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功