[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

Jorn Vernee via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 27 12:06:58 PDT 2019


JornVernee created this revision.
JornVernee added reviewers: yvvan, nik, rsmith.
JornVernee added a project: clang.
Herald added a subscriber: arphaman.

https://reviews.llvm.org/D54996 Changed the behaviour of clang_Cursor_isAnonymous, but there is no alternative available to get the old behaviour in some cases, which is essential for determining if a record is syntactically accessible, e.g.

  struct {
    int x;
    int y;
  } foo;
  
  struct {
    struct {
      int x;
      int y;
    };
  } bar;
  
  void fun(struct { int x; int y; } *param);

The only 'anonymous' struct here is the one nested in bar, since there is no way to reference the struct itself, only the fields within. Though the anonymity applies to the instance itself, not the type.

To avoid confusion, I have added a new function called clang_Cursor_isAnonymousRecordDecl which has the old behaviour of clang_Cursor_isAnonymous  (and updated the doc for the latter as well, which was seemingly forgotten).


Repository:
  rC Clang

https://reviews.llvm.org/D61232

Files:
  include/clang-c/Index.h
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===================================================================
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@

   return 0;
 }
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+  if (!clang_isDeclaration(C.kind))
+    return 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const RecordDecl *FD = dyn_cast_or_null<RecordDecl>(D))
+    return FD->isAnonymousStructOrUnion();
+  return 0;
+}
+
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: include/clang-c/Index.h
===================================================================
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -3920,11 +3920,17 @@
  */
 CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);

+/**
+ * Determine whether the given cursor represents an anonymous
+ * tag or namespace
+ */
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+
 /**
  * Determine whether the given cursor represents an anonymous record
  * declaration.
  */
-CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C);

 enum CXRefQualifierKind {
   /** No ref-qualifier was provided. */


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61232.196983.patch
Type: text/x-patch
Size: 1319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190427/ccc881f3/attachment.bin>


More information about the cfe-commits mailing list