summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorJonathan Coe <jbcoe@me.com>2016-04-27 12:48:25 +0000
committerJonathan Coe <jbcoe@me.com>2016-04-27 12:48:25 +0000
commitf376e8cf301479a7c40942d31e8e59dedac95230 (patch)
treedd606f4847062d0c32af768837c07f1e70315699 /bindings
parent7e12e0954b5ece78dfb5d26fb404f2ecd7b99f27 (diff)
Expose cxx constructor and method properties through libclang and python bindings.
Summary: I have exposed the following function through libclang and the clang.cindex python bindings: clang_CXXConstructor_isConvertingConstructor, clang_CXXConstructor_isCopyConstructor, clang_CXXConstructor_isDefaultConstructor, clang_CXXConstructor_isMoveConstructor, clang_CXXMethod_isDefaulted I need (some of) these methods for a C++ code model I am building in Python to drive a code generator. Reviewers: compnerd, skalinichev Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15469 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py46
-rw-r--r--bindings/python/tests/cindex/test_cursor.py82
2 files changed, 128 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 4d450eca18..ba68c0bd8e 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1174,6 +1174,32 @@ class Cursor(Structure):
"""
return conf.lib.clang_CXXMethod_isConst(self)
+ def is_converting_constructor(self):
+ """Returns True if the cursor refers to a C++ converting constructor.
+ """
+ return conf.lib.clang_CXXConstructor_isConvertingConstructor(self)
+
+ def is_copy_constructor(self):
+ """Returns True if the cursor refers to a C++ copy constructor.
+ """
+ return conf.lib.clang_CXXConstructor_isCopyConstructor(self)
+
+ def is_default_constructor(self):
+ """Returns True if the cursor refers to a C++ default constructor.
+ """
+ return conf.lib.clang_CXXConstructor_isDefaultConstructor(self)
+
+ def is_move_constructor(self):
+ """Returns True if the cursor refers to a C++ move constructor.
+ """
+ return conf.lib.clang_CXXConstructor_isMoveConstructor(self)
+
+ def is_default_method(self):
+ """Returns True if the cursor refers to a C++ member function or member
+ function template that is declared '= default'.
+ """
+ return conf.lib.clang_CXXMethod_isDefaulted(self)
+
def is_mutable_field(self):
"""Returns True if the cursor refers to a C++ field that is declared
'mutable'.
@@ -2918,6 +2944,22 @@ functionList = [
[Index, c_char_p],
c_object_p),
+ ("clang_CXXConstructor_isConvertingConstructor",
+ [Cursor],
+ bool),
+
+ ("clang_CXXConstructor_isCopyConstructor",
+ [Cursor],
+ bool),
+
+ ("clang_CXXConstructor_isDefaultConstructor",
+ [Cursor],
+ bool),
+
+ ("clang_CXXConstructor_isMoveConstructor",
+ [Cursor],
+ bool),
+
("clang_CXXField_isMutable",
[Cursor],
bool),
@@ -2926,6 +2968,10 @@ functionList = [
[Cursor],
bool),
+ ("clang_CXXMethod_isDefaulted",
+ [Cursor],
+ bool),
+
("clang_CXXMethod_isPureVirtual",
[Cursor],
bool),
diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py
index c5ea50516a..6c8230d428 100644
--- a/bindings/python/tests/cindex/test_cursor.py
+++ b/bindings/python/tests/cindex/test_cursor.py
@@ -112,6 +112,88 @@ def test_is_const_method():
assert foo.is_const_method()
assert not bar.is_const_method()
+def test_is_converting_constructor():
+ """Ensure Cursor.is_converting_constructor works."""
+ source = 'class X { explicit X(int); X(double); X(); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+
+ assert len(xs) == 4
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+ assert cs[2].kind == CursorKind.CONSTRUCTOR
+
+ assert not cs[0].is_converting_constructor()
+ assert cs[1].is_converting_constructor()
+ assert not cs[2].is_converting_constructor()
+
+
+def test_is_copy_constructor():
+ """Ensure Cursor.is_copy_constructor works."""
+ source = 'class X { X(); X(const X&); X(X&&); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+ assert cs[2].kind == CursorKind.CONSTRUCTOR
+
+ assert not cs[0].is_copy_constructor()
+ assert cs[1].is_copy_constructor()
+ assert not cs[2].is_copy_constructor()
+
+def test_is_default_constructor():
+ """Ensure Cursor.is_default_constructor works."""
+ source = 'class X { X(); X(int); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+
+ assert cs[0].is_default_constructor()
+ assert not cs[1].is_default_constructor()
+
+def test_is_move_constructor():
+ """Ensure Cursor.is_move_constructor works."""
+ source = 'class X { X(); X(const X&); X(X&&); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ assert xs[0].kind == CursorKind.CLASS_DECL
+ cs = xs[1:]
+ assert cs[0].kind == CursorKind.CONSTRUCTOR
+ assert cs[1].kind == CursorKind.CONSTRUCTOR
+ assert cs[2].kind == CursorKind.CONSTRUCTOR
+
+ assert not cs[0].is_move_constructor()
+ assert not cs[1].is_move_constructor()
+ assert cs[2].is_move_constructor()
+
+def test_is_default_method():
+ """Ensure Cursor.is_default_method works."""
+ source = 'class X { X() = default; }; class Y { Y(); };'
+ tu = get_tu(source, lang='cpp')
+
+ xs = get_cursors(tu, 'X')
+ ys = get_cursors(tu, 'Y')
+
+ assert len(xs) == 2
+ assert len(ys) == 2
+
+ xc = xs[1]
+ yc = ys[1]
+
+ assert xc.is_default_method()
+ assert not yc.is_default_method()
+
def test_is_mutable_field():
"""Ensure Cursor.is_mutable_field works."""
source = 'class X { int x_; mutable int y_; };'