Skip to content

[libclang/python] Add a few things to the python api #120590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion clang/bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,9 @@ def from_location(tu, location):

return cursor

def __hash__(self):
return self.hash

def __eq__(self, other):
return conf.lib.clang_equalCursors(self, other) # type: ignore [no-any-return]

Expand Down Expand Up @@ -1797,7 +1800,7 @@ def mangled_name(self):
return self._mangled_name

@property
def location(self):
def location(self) -> SourceLocation:
"""
Return the source location (the starting character) of the entity
pointed at by the cursor.
Expand Down Expand Up @@ -2022,6 +2025,14 @@ def lexical_parent(self):

return self._lexical_parent

@property
def specialized_template(self):
"""Return the base template that this cursor is a specialization of, if any."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if "base template" should be replaced with the Standard term "primary template".

return Cursor.from_cursor_result(
conf.lib.clang_getSpecializedCursorTemplate(self),
self
)

@property
def translation_unit(self):
"""Returns the TranslationUnit to which this Cursor belongs."""
Expand Down Expand Up @@ -2143,6 +2154,9 @@ def get_bitfield_width(self):
"""
return conf.lib.clang_getFieldDeclBitWidth(self) # type: ignore [no-any-return]

def has_attrs(self):
return bool(conf.lib.clang_Cursor_hasAttrs(self))

@staticmethod
def from_result(res, arg):
assert isinstance(res, Cursor)
Expand Down Expand Up @@ -3401,6 +3415,12 @@ def __str__(self):
def __repr__(self):
return "<File: %s>" % (self.name)

def __eq__(self, other):
return isinstance(other, File) and bool(conf.lib.clang_File_isEqual(self, other))

def __ne__(self, other):
return not self.__eq__(other)

@staticmethod
def from_result(res, arg):
assert isinstance(res, c_object_p)
Expand Down Expand Up @@ -3795,6 +3815,7 @@ def write_main_file_to_stdout(self):
("clang_getCursorType", [Cursor], Type),
("clang_getCursorUSR", [Cursor], _CXString),
("clang_Cursor_getMangling", [Cursor], _CXString),
("clang_Cursor_hasAttrs", [Cursor], c_uint),
# ("clang_getCXTUResourceUsage",
# [TranslationUnit],
# CXTUResourceUsage),
Expand All @@ -3819,6 +3840,7 @@ def write_main_file_to_stdout(self):
("clang_getFile", [TranslationUnit, c_interop_string], c_object_p),
("clang_getFileName", [File], _CXString),
("clang_getFileTime", [File], c_uint),
("clang_File_isEqual", [File, File], c_int),
("clang_getIBOutletCollectionType", [Cursor], Type),
("clang_getIncludedFile", [Cursor], c_object_p),
(
Expand Down
Loading