[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Committed r307771 with correct attribution.


Repository:
  rL LLVM

https://reviews.llvm.org/D35187



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-12 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307769: [libclang] Support for querying whether an enum is 
scoped (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D35187?vs=106066=106173#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35187

Files:
  cfe/trunk/bindings/python/clang/cindex.py
  cfe/trunk/bindings/python/tests/cindex/test_cursor.py
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/test/Index/print-type-declaration.cpp
  cfe/trunk/tools/c-index-test/c-index-test.c
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/tools/libclang/libclang.exports

Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -7807,6 +7807,15 @@
   return (Method && Method->isVirtual()) ? 1 : 0;
 }
 
+unsigned clang_EnumDecl_isScoped(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  auto *Enum = dyn_cast_or_null(D);
+  return (Enum && Enum->isScoped()) ? 1 : 0;
+}
+
 //===--===//
 // Attribute introspection.
 //===--===//
Index: cfe/trunk/tools/libclang/libclang.exports
===
--- cfe/trunk/tools/libclang/libclang.exports
+++ cfe/trunk/tools/libclang/libclang.exports
@@ -12,6 +12,7 @@
 clang_CXXMethod_isPureVirtual
 clang_CXXMethod_isStatic
 clang_CXXMethod_isVirtual
+clang_EnumDecl_isScoped
 clang_Cursor_getArgument
 clang_Cursor_getNumTemplateArguments
 clang_Cursor_getTemplateArgumentKind
Index: cfe/trunk/tools/c-index-test/c-index-test.c
===
--- cfe/trunk/tools/c-index-test/c-index-test.c
+++ cfe/trunk/tools/c-index-test/c-index-test.c
@@ -804,6 +804,8 @@
   printf(" (const)");
 if (clang_CXXMethod_isPureVirtual(Cursor))
   printf(" (pure)");
+if (clang_EnumDecl_isScoped(Cursor))
+  printf(" (scoped)");
 if (clang_Cursor_isVariadic(Cursor))
   printf(" (variadic)");
 if (clang_Cursor_isObjCOptional(Cursor))
Index: cfe/trunk/bindings/python/clang/cindex.py
===
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -1478,6 +1478,11 @@
 """
 return conf.lib.clang_CXXMethod_isVirtual(self)
 
+def is_scoped_enum(self):
+"""Returns True if the cursor refers to a scoped enum declaration.
+"""
+return conf.lib.clang_EnumDecl_isScoped(self)
+
 def get_definition(self):
 """
 If the cursor is a reference to a declaration or a declaration of
@@ -3314,6 +3319,10 @@
[Cursor],
bool),
 
+  ("clang_EnumDecl_isScoped",
+   [Cursor],
+   bool),
+
   ("clang_defaultDiagnosticDisplayOptions",
[],
c_uint),
Index: cfe/trunk/bindings/python/tests/cindex/test_cursor.py
===
--- cfe/trunk/bindings/python/tests/cindex/test_cursor.py
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py
@@ -255,6 +255,22 @@
 assert foo.is_virtual_method()
 assert not bar.is_virtual_method()
 
+def test_is_scoped_enum():
+"""Ensure Cursor.is_scoped_enum works."""
+source = 'class X {}; enum RegularEnum {}; enum class ScopedEnum {};'
+tu = get_tu(source, lang='cpp')
+
+cls = get_cursor(tu, 'X')
+regular_enum = get_cursor(tu, 'RegularEnum')
+scoped_enum = get_cursor(tu, 'ScopedEnum')
+assert cls is not None
+assert regular_enum is not None
+assert scoped_enum is not None
+
+assert not cls.is_scoped_enum()
+assert not regular_enum.is_scoped_enum()
+assert scoped_enum.is_scoped_enum()
+
 def test_underlying_type():
 tu = get_tu('typedef int foo;')
 typedef = get_cursor(tu, 'foo')
Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -4417,6 +4417,11 @@
 CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
 
 /**
+ * \brief Determine if an enum declaration refers to a scoped enum.
+ */
+CINDEX_LINKAGE unsigned clang_EnumDecl_isScoped(CXCursor C);
+
+/**
  * \brief Determine if a C++ member function or member function template is
  * declared 'const'.
  */
Index: cfe/trunk/test/Index/print-type-declaration.cpp
===
--- cfe/trunk/test/Index/print-type-declaration.cpp
+++ cfe/trunk/test/Index/print-type-declaration.cpp
@@ -7,6 +7,13 @@
   auto b = a;
 }
 
+enum RegularEnum {};
+
+enum class ScopedEnum {};
+
 // RUN: c-index-test -test-print-type-declaration -std=c++11 %s | FileCheck %s
 

[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Sure, I'll commit it today.


https://reviews.llvm.org/D35187



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-11 Thread Johann Klähn via Phabricator via cfe-commits
jklaehn added a comment.

I do not have commit access, it would be great if you could commit it. Thanks!


https://reviews.llvm.org/D35187



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM. Do you have commit access or would you like me to commit it on your 
behalf?


https://reviews.llvm.org/D35187



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-11 Thread Johann Klähn via Phabricator via cfe-commits
jklaehn updated this revision to Diff 106066.
jklaehn added a project: clang.

https://reviews.llvm.org/D35187

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_cursor.py
  include/clang-c/Index.h
  test/Index/print-type-declaration.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -12,6 +12,7 @@
 clang_CXXMethod_isPureVirtual
 clang_CXXMethod_isStatic
 clang_CXXMethod_isVirtual
+clang_EnumDecl_isScoped
 clang_Cursor_getArgument
 clang_Cursor_getNumTemplateArguments
 clang_Cursor_getTemplateArgumentKind
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7807,6 +7807,15 @@
   return (Method && Method->isVirtual()) ? 1 : 0;
 }
 
+unsigned clang_EnumDecl_isScoped(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  auto *Enum = dyn_cast_or_null(D);
+  return (Enum && Enum->isScoped()) ? 1 : 0;
+}
+
 //===--===//
 // Attribute introspection.
 //===--===//
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -804,6 +804,8 @@
   printf(" (const)");
 if (clang_CXXMethod_isPureVirtual(Cursor))
   printf(" (pure)");
+if (clang_EnumDecl_isScoped(Cursor))
+  printf(" (scoped)");
 if (clang_Cursor_isVariadic(Cursor))
   printf(" (variadic)");
 if (clang_Cursor_isObjCOptional(Cursor))
Index: test/Index/print-type-declaration.cpp
===
--- test/Index/print-type-declaration.cpp
+++ test/Index/print-type-declaration.cpp
@@ -7,6 +7,13 @@
   auto b = a;
 }
 
+enum RegularEnum {};
+
+enum class ScopedEnum {};
+
 // RUN: c-index-test -test-print-type-declaration -std=c++11 %s | FileCheck %s
 // CHECK: VarDecl=a:6:8 (Definition) [typedeclaration=Test] [typekind=Record]
 // CHECK: VarDecl=b:7:8 (Definition) [typedeclaration=Test] [typekind=Record]
+// CHECK: EnumDecl=RegularEnum:10:6 (Definition) [typedeclaration=RegularEnum] [typekind=Enum]
+// CHECK: EnumDecl=ScopedEnum:12:12 (Definition) (scoped) [typedeclaration=ScopedEnum] [typekind=Enum]
+
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -4417,6 +4417,11 @@
 CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
 
 /**
+ * \brief Determine if an enum declaration refers to a scoped enum.
+ */
+CINDEX_LINKAGE unsigned clang_EnumDecl_isScoped(CXCursor C);
+
+/**
  * \brief Determine if a C++ member function or member function template is
  * declared 'const'.
  */
Index: bindings/python/tests/cindex/test_cursor.py
===
--- bindings/python/tests/cindex/test_cursor.py
+++ bindings/python/tests/cindex/test_cursor.py
@@ -255,6 +255,22 @@
 assert foo.is_virtual_method()
 assert not bar.is_virtual_method()
 
+def test_is_scoped_enum():
+"""Ensure Cursor.is_scoped_enum works."""
+source = 'class X {}; enum RegularEnum {}; enum class ScopedEnum {};'
+tu = get_tu(source, lang='cpp')
+
+cls = get_cursor(tu, 'X')
+regular_enum = get_cursor(tu, 'RegularEnum')
+scoped_enum = get_cursor(tu, 'ScopedEnum')
+assert cls is not None
+assert regular_enum is not None
+assert scoped_enum is not None
+
+assert not cls.is_scoped_enum()
+assert not regular_enum.is_scoped_enum()
+assert scoped_enum.is_scoped_enum()
+
 def test_underlying_type():
 tu = get_tu('typedef int foo;')
 typedef = get_cursor(tu, 'foo')
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1478,6 +1478,11 @@
 """
 return conf.lib.clang_CXXMethod_isVirtual(self)
 
+def is_scoped_enum(self):
+"""Returns True if the cursor refers to a scoped enum declaration.
+"""
+return conf.lib.clang_EnumDecl_isScoped(self)
+
 def get_definition(self):
 """
 If the cursor is a reference to a declaration or a declaration of
@@ -3314,6 +3319,10 @@
[Cursor],
bool),
 
+  ("clang_EnumDecl_isScoped",
+   [Cursor],
+   bool),
+
   ("clang_defaultDiagnosticDisplayOptions",
[],
c_uint),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-10 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Thanks for the patch.
I have just one minor comment:




Comment at: tools/libclang/CIndex.cpp:7815
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const EnumDecl *Enum = D ? dyn_cast_or_null(D) : nullptr;
+  return (Enum && Enum->isScoped()) ? 1 : 0;

`dyn_cast_or_null` already checks if `D` is null, so the ternary operator is 
redundant. You can also use `const auto *` once you use just the 
`dyn_cast_or_null`.


https://reviews.llvm.org/D35187



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-09 Thread Johann Klähn via Phabricator via cfe-commits
jklaehn created this revision.

This patch allows checking whether an enum declaration is scoped
through libclang and clang.cindex (Python).


https://reviews.llvm.org/D35187

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_cursor.py
  include/clang-c/Index.h
  test/Index/print-type-declaration.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -12,6 +12,7 @@
 clang_CXXMethod_isPureVirtual
 clang_CXXMethod_isStatic
 clang_CXXMethod_isVirtual
+clang_EnumDecl_isScoped
 clang_Cursor_getArgument
 clang_Cursor_getNumTemplateArguments
 clang_Cursor_getTemplateArgumentKind
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7807,6 +7807,15 @@
   return (Method && Method->isVirtual()) ? 1 : 0;
 }
 
+unsigned clang_EnumDecl_isScoped(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const EnumDecl *Enum = D ? dyn_cast_or_null(D) : nullptr;
+  return (Enum && Enum->isScoped()) ? 1 : 0;
+}
+
 //===--===//
 // Attribute introspection.
 //===--===//
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -804,6 +804,8 @@
   printf(" (const)");
 if (clang_CXXMethod_isPureVirtual(Cursor))
   printf(" (pure)");
+if (clang_EnumDecl_isScoped(Cursor))
+  printf(" (scoped)");
 if (clang_Cursor_isVariadic(Cursor))
   printf(" (variadic)");
 if (clang_Cursor_isObjCOptional(Cursor))
Index: test/Index/print-type-declaration.cpp
===
--- test/Index/print-type-declaration.cpp
+++ test/Index/print-type-declaration.cpp
@@ -7,6 +7,13 @@
   auto b = a;
 }
 
+enum RegularEnum {};
+
+enum class ScopedEnum {};
+
 // RUN: c-index-test -test-print-type-declaration -std=c++11 %s | FileCheck %s
 // CHECK: VarDecl=a:6:8 (Definition) [typedeclaration=Test] [typekind=Record]
 // CHECK: VarDecl=b:7:8 (Definition) [typedeclaration=Test] [typekind=Record]
+// CHECK: EnumDecl=RegularEnum:10:6 (Definition) [typedeclaration=RegularEnum] [typekind=Enum]
+// CHECK: EnumDecl=ScopedEnum:12:12 (Definition) (scoped) [typedeclaration=ScopedEnum] [typekind=Enum]
+
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -4417,6 +4417,11 @@
 CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
 
 /**
+ * \brief Determine if an enum declaration refers to a scoped enum.
+ */
+CINDEX_LINKAGE unsigned clang_EnumDecl_isScoped(CXCursor C);
+
+/**
  * \brief Determine if a C++ member function or member function template is
  * declared 'const'.
  */
Index: bindings/python/tests/cindex/test_cursor.py
===
--- bindings/python/tests/cindex/test_cursor.py
+++ bindings/python/tests/cindex/test_cursor.py
@@ -255,6 +255,22 @@
 assert foo.is_virtual_method()
 assert not bar.is_virtual_method()
 
+def test_is_scoped_enum():
+"""Ensure Cursor.is_scoped_enum works."""
+source = 'class X {}; enum RegularEnum {}; enum class ScopedEnum {};'
+tu = get_tu(source, lang='cpp')
+
+cls = get_cursor(tu, 'X')
+regular_enum = get_cursor(tu, 'RegularEnum')
+scoped_enum = get_cursor(tu, 'ScopedEnum')
+assert cls is not None
+assert regular_enum is not None
+assert scoped_enum is not None
+
+assert not cls.is_scoped_enum()
+assert not regular_enum.is_scoped_enum()
+assert scoped_enum.is_scoped_enum()
+
 def test_underlying_type():
 tu = get_tu('typedef int foo;')
 typedef = get_cursor(tu, 'foo')
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1478,6 +1478,11 @@
 """
 return conf.lib.clang_CXXMethod_isVirtual(self)
 
+def is_scoped_enum(self):
+"""Returns True if the cursor refers to a scoped enum declaration.
+"""
+return conf.lib.clang_EnumDecl_isScoped(self)
+
 def get_definition(self):
 """
 If the cursor is a reference to a declaration or a declaration of
@@ -3314,6 +3319,10 @@
[Cursor],
bool),
 
+  ("clang_EnumDecl_isScoped",
+   [Cursor],
+   bool),
+
   ("clang_defaultDiagnosticDisplayOptions",
[],
c_uint),