diff options
author | Jonathan Coe <jbcoe@me.com> | 2016-04-27 12:48:25 +0000 |
---|---|---|
committer | Jonathan Coe <jbcoe@me.com> | 2016-04-27 12:48:25 +0000 |
commit | 2956535b7c44fb4cf742667ec4b61cf176f9d32d (patch) | |
tree | 2e5cb14efb2deae8228fa30d6b554473b8262969 /clang/bindings/python/tests | |
parent | 7ac9628648c6ba72114d08c9669f00422f328533 (diff) | |
download | bcm5719-llvm-2956535b7c44fb4cf742667ec4b61cf176f9d32d.tar.gz bcm5719-llvm-2956535b7c44fb4cf742667ec4b61cf176f9d32d.zip |
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
llvm-svn: 267706
Diffstat (limited to 'clang/bindings/python/tests')
-rw-r--r-- | clang/bindings/python/tests/cindex/test_cursor.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py index c5ea50516ad..6c8230d4283 100644 --- a/clang/bindings/python/tests/cindex/test_cursor.py +++ b/clang/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_; };' |