Skip to content

Commit

Permalink
this is clang release_32
Browse files Browse the repository at this point in the history
  • Loading branch information
trolldbois committed Aug 3, 2013
1 parent 5ec998f commit 175c32d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 265 deletions.
170 changes: 15 additions & 155 deletions clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def name(self):
@staticmethod
def from_id(id):
if id >= len(CursorKind._kinds) or CursorKind._kinds[id] is None:
raise ValueError,'Unknown cursor kind %d' % id
raise ValueError,'Unknown cursor kind'
return CursorKind._kinds[id]

@staticmethod
Expand Down Expand Up @@ -721,14 +721,10 @@ def __repr__(self):
# A reference to a labeled statement.
CursorKind.LABEL_REF = CursorKind(48)

# A reference to a set of overloaded functions or function templates
# A reference toa a set of overloaded functions or function templates
# that has not yet been resolved to a specific function or function template.
CursorKind.OVERLOADED_DECL_REF = CursorKind(49)

# A reference to a variable that occurs in some non-expression
# context, e.g., a C++ lambda capture list.
CursorKind.VARIABLE_REF = CursorKind(50)

###
# Invalid/Error Kinds

Expand Down Expand Up @@ -912,26 +908,6 @@ def __repr__(self):
# pack.
CursorKind.SIZE_OF_PACK_EXPR = CursorKind(143)

# Represents a C++ lambda expression that produces a local function
# object.
#
# \code
# void abssort(float *x, unsigned N) {
# std::sort(x, x + N,
# [](float a, float b) {
# return std::abs(a) < std::abs(b);
# });
# }
# \endcode
CursorKind.LAMBDA_EXPR = CursorKind(144)

# Objective-c Boolean Literal.
CursorKind.OBJ_BOOL_LITERAL_EXPR = CursorKind(145)

# Represents the "self" expression in a ObjC method.
CursorKind.OBJ_SELF_EXPR = CursorKind(146)


# A statement whose specific kind is not exposed via this interface.
#
# Unexposed statements have the same operations as any other kind of statement;
Expand Down Expand Up @@ -1023,9 +999,6 @@ def __repr__(self):
# Windows Structured Exception Handling's finally statement.
CursorKind.SEH_FINALLY_STMT = CursorKind(228)

# A MS inline assembly statement extension.
CursorKind.MS_ASM_STMT = CursorKind(229)

# The null statement.
CursorKind.NULL_STMT = CursorKind(230)

Expand Down Expand Up @@ -1063,12 +1036,6 @@ def __repr__(self):
CursorKind.MACRO_INSTANTIATION = CursorKind(502)
CursorKind.INCLUSION_DIRECTIVE = CursorKind(503)

###
# Extra declaration

# A module import declaration.
CursorKind.MODULE_IMPORT_DECL = CursorKind(600)

### Cursors ###

class Cursor(Structure):
Expand Down Expand Up @@ -1304,17 +1271,6 @@ def translation_unit(self):
# created.
return self._tu

@property
def referenced(self):
"""
For a cursor that is a reference, returns a cursor
representing the entity that it references.
"""
if not hasattr(self, '_referenced'):
self._referenced = conf.lib.clang_getCursorReferenced(self)

return self._referenced

def get_arguments(self):
"""Return an iterator for accessing the arguments of this cursor."""
num_args = conf.lib.clang_Cursor_getNumArguments(self)
Expand Down Expand Up @@ -1347,18 +1303,6 @@ def get_tokens(self):
"""
return TokenGroup.get_tokens(self._tu, self.extent)

def is_bitfield(self):
"""
Check if the field is a bitfield.
"""
return conf.lib.clang_Cursor_isBitField(self)

def get_bitfield_width(self):
"""
Retrieve the width of a bitfield.
"""
return conf.lib.clang_getFieldDeclBitWidth(self)

@staticmethod
def from_result(res, fn, args):
assert isinstance(res, Cursor)
Expand Down Expand Up @@ -1483,9 +1427,6 @@ def __repr__(self):
TypeKind.FUNCTIONPROTO = TypeKind(111)
TypeKind.CONSTANTARRAY = TypeKind(112)
TypeKind.VECTOR = TypeKind(113)
TypeKind.INCOMPLETEARRAY = TypeKind(114)
TypeKind.VARIABLEARRAY = TypeKind(115)
TypeKind.DEPENDENTSIZEDARRAY = TypeKind(116)

class Type(Structure):
"""
Expand Down Expand Up @@ -1661,24 +1602,6 @@ def get_array_size(self):
"""
return conf.lib.clang_getArraySize(self)

def get_align(self):
"""
Retrieve the alignment of the record.
"""
return conf.lib.clang_Type_getAlignOf(self)

def get_size(self):
"""
Retrieve the size of the record.
"""
return conf.lib.clang_Type_getSizeOf(self)

def get_offset(self, fieldname):
"""
Retrieve the offset of a field in the record.
"""
return conf.lib.clang_Type_getOffsetOf(self, c_char_p(fieldname))

def __eq__(self, other):
if type(other) != type(self):
return False
Expand Down Expand Up @@ -1711,33 +1634,6 @@ class _CXUnsavedFile(Structure):
"""Helper for passing unsaved file arguments."""
_fields_ = [("name", c_char_p), ("contents", c_char_p), ('length', c_ulong)]

# Functions calls through the python interface are rather slow. Fortunately,
# for most symboles, we do not need to perform a function call. Their spelling
# never changes and is consequently provided by this spelling cache.
SpellingCache = {
# 0: CompletionChunk.Kind("Optional"),
# 1: CompletionChunk.Kind("TypedText"),
# 2: CompletionChunk.Kind("Text"),
# 3: CompletionChunk.Kind("Placeholder"),
# 4: CompletionChunk.Kind("Informative"),
# 5 : CompletionChunk.Kind("CurrentParameter"),
6: '(', # CompletionChunk.Kind("LeftParen"),
7: ')', # CompletionChunk.Kind("RightParen"),
8: ']', # CompletionChunk.Kind("LeftBracket"),
9: ']', # CompletionChunk.Kind("RightBracket"),
10: '{', # CompletionChunk.Kind("LeftBrace"),
11: '}', # CompletionChunk.Kind("RightBrace"),
12: '<', # CompletionChunk.Kind("LeftAngle"),
13: '>', # CompletionChunk.Kind("RightAngle"),
14: ', ', # CompletionChunk.Kind("Comma"),
# 15: CompletionChunk.Kind("ResultType"),
16: ':', # CompletionChunk.Kind("Colon"),
17: ';', # CompletionChunk.Kind("SemiColon"),
18: '=', # CompletionChunk.Kind("Equal"),
19: ' ', # CompletionChunk.Kind("HorizontalSpace"),
# 20: CompletionChunk.Kind("VerticalSpace")
}

class CompletionChunk:
class Kind:
def __init__(self, name):
Expand All @@ -1752,30 +1648,18 @@ def __repr__(self):
def __init__(self, completionString, key):
self.cs = completionString
self.key = key
self.__kindNumberCache = -1

def __repr__(self):
return "{'" + self.spelling + "', " + str(self.kind) + "}"

@CachedProperty
def spelling(self):
if self.__kindNumber in SpellingCache:
return SpellingCache[self.__kindNumber]
return conf.lib.clang_getCompletionChunkText(self.cs, self.key).spelling

# We do not use @CachedProperty here, as the manual implementation is
# apparently still significantly faster. Please profile carefully if you
# would like to add CachedProperty back.
@property
def __kindNumber(self):
if self.__kindNumberCache == -1:
self.__kindNumberCache = \
conf.lib.clang_getCompletionChunkKind(self.cs, self.key)
return self.__kindNumberCache

@CachedProperty
def kind(self):
return completionChunkKindMap[self.__kindNumber]
res = conf.lib.clang_getCompletionChunkKind(self.cs, self.key)
return completionChunkKindMap[res]

@CachedProperty
def string(self):
Expand All @@ -1788,19 +1672,19 @@ def string(self):
None

def isKindOptional(self):
return self.__kindNumber == 0
return self.kind == completionChunkKindMap[0]

def isKindTypedText(self):
return self.__kindNumber == 1
return self.kind == completionChunkKindMap[1]

def isKindPlaceHolder(self):
return self.__kindNumber == 3
return self.kind == completionChunkKindMap[3]

def isKindInformative(self):
return self.__kindNumber == 4
return self.kind == completionChunkKindMap[4]

def isKindResultType(self):
return self.__kindNumber == 15
return self.kind == completionChunkKindMap[15]

completionChunkKindMap = {
0: CompletionChunk.Kind("Optional"),
Expand Down Expand Up @@ -1954,7 +1838,7 @@ def __del__(self):

def read(self, path):
"""Load a TranslationUnit from the given AST file."""
return TranslationUnit.from_ast_file(path, self)
return TranslationUnit.from_ast(path, self)

def parse(self, path, args=None, unsaved_files=None, options = 0):
"""Load the translation unit from the given source code file by running
Expand Down Expand Up @@ -2081,7 +1965,7 @@ def from_source(cls, filename, args=None, unsaved_files=None, options=0,
len(args), unsaved_array,
len(unsaved_files), options)

if not ptr:
if ptr is None:
raise TranslationUnitLoadError("Error parsing translation unit.")

return cls(ptr, index=index)
Expand All @@ -2103,7 +1987,7 @@ def from_ast_file(cls, filename, index=None):
index = Index.create()

ptr = conf.lib.clang_createTranslationUnit(index, filename)
if not ptr:
if ptr is None:
raise TranslationUnitLoadError(filename)

return cls(ptr=ptr, index=index)
Expand Down Expand Up @@ -2626,10 +2510,6 @@ def cursor(self):
[Index, c_char_p],
c_object_p),

("clang_CXXMethod_isPureVirtual",
[Cursor],
bool),

("clang_CXXMethod_isStatic",
[Cursor],
bool),
Expand Down Expand Up @@ -2693,10 +2573,6 @@ def cursor(self):
[Type],
c_longlong),

("clang_getFieldDeclBitWidth",
[Cursor],
c_int),

("clang_getCanonicalCursor",
[Cursor],
Cursor,
Expand Down Expand Up @@ -3112,22 +2988,6 @@ def cursor(self):
[Cursor, c_uint],
Cursor,
Cursor.from_result),

("clang_Cursor_isBitField",
[Cursor],
bool),

("clang_Type_getAlignOf",
[Type],
c_longlong),

("clang_Type_getOffsetOf",
[Type, c_char_p],
c_longlong),

("clang_Type_getSizeOf",
[Type],
c_ulonglong),
]

class LibclangError(Exception):
Expand Down Expand Up @@ -3186,13 +3046,13 @@ def set_library_path(path):
Config.library_path = path

@staticmethod
def set_library_file(filename):
"""Set the exact location of libclang"""
def set_library_file(file):
"""Set the exact location of libclang from"""
if Config.loaded:
raise Exception("library file must be set before before using " \
"any other functionalities in libclang.")

Config.library_file = filename
Config.library_file = path

@staticmethod
def set_compatibility_check(check_status):
Expand Down
9 changes: 0 additions & 9 deletions tests/cindex/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,3 @@ def test_get_arguments():
assert len(arguments) == 2
assert arguments[0].spelling == "i"
assert arguments[1].spelling == "j"

def test_referenced():
tu = get_tu('void foo(); void bar() { foo(); }')
foo = get_cursor(tu, 'foo')
bar = get_cursor(tu, 'bar')
for c in bar.get_children():
if c.kind == CursorKind.CALL_EXPR:
assert c.referenced.spelling == foo.spelling
break
11 changes: 2 additions & 9 deletions tests/cindex/test_cursor_kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ def test_name():
assert CursorKind.UNEXPOSED_DECL.name is 'UNEXPOSED_DECL'

def test_get_all_kinds():
kinds = CursorKind.get_all_kinds()
assert CursorKind.UNEXPOSED_DECL in kinds
assert CursorKind.TRANSLATION_UNIT in kinds
assert CursorKind.VARIABLE_REF in kinds
assert CursorKind.LAMBDA_EXPR in kinds
assert CursorKind.OBJ_BOOL_LITERAL_EXPR in kinds
assert CursorKind.OBJ_SELF_EXPR in kinds
assert CursorKind.MS_ASM_STMT in kinds
assert CursorKind.MODULE_IMPORT_DECL in kinds
assert CursorKind.UNEXPOSED_DECL in CursorKind.get_all_kinds()
assert CursorKind.TRANSLATION_UNIT in CursorKind.get_all_kinds()

def test_kind_groups():
"""Check that every kind classifies to exactly one group."""
Expand Down
17 changes: 0 additions & 17 deletions tests/cindex/test_translation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from clang.cindex import SourceLocation
from clang.cindex import SourceRange
from clang.cindex import TranslationUnitSaveError
from clang.cindex import TranslationUnitLoadError
from clang.cindex import TranslationUnit
from .util import get_cursor
from .util import get_tu
Expand Down Expand Up @@ -240,19 +239,3 @@ def test_get_tokens_gc():
del tokens
gc.collect()
gc.collect() # Just in case.

def test_fail_from_source():
path = os.path.join(kInputsDir, 'non-existent.cpp')
try:
tu = TranslationUnit.from_source(path)
except TranslationUnitLoadError:
tu = None
assert tu == None

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
Loading

0 comments on commit 175c32d

Please sign in to comment.