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. */


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. */
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to