dang created this revision.
dang added reviewers: zixuw, ributzka, QuietMisdreavus.
Herald added a project: All.
dang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Anonymous enums without a typedef should have a "(anonymous)" identifier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123533

Files:
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/enum.c

Index: clang/test/ExtractAPI/enum.c
===================================================================
--- clang/test/ExtractAPI/enum.c
+++ clang/test/ExtractAPI/enum.c
@@ -30,6 +30,10 @@
   West
 };
 
+enum {
+  Constant = 1
+};
+
 //--- reference.output.json.in
 {
   "metadata": {
@@ -100,6 +104,11 @@
       "kind": "memberOf",
       "source": "c:@E@Direction@West",
       "target": "c:@E@Direction"
+    },
+    {
+      "kind": "memberOf",
+      "source": "c:@Ea@Constant@Constant",
+      "target": "c:@Ea@Constant"
     }
   ],
   "symbols": [
@@ -641,6 +650,94 @@
         "Direction",
         "West"
       ]
+    },
+    {
+      "accessLevel": "public",
+      "declarationFragments": [
+        {
+          "kind": "keyword",
+          "spelling": "enum"
+        },
+        {
+          "kind": "text",
+          "spelling": ": "
+        },
+        {
+          "kind": "typeIdentifier",
+          "preciseIdentifier": "c:i",
+          "spelling": "unsigned int"
+        }
+      ],
+      "identifier": {
+        "interfaceLanguage": "c",
+        "precise": "c:@Ea@Constant"
+      },
+      "kind": {
+        "displayName": "Enumeration",
+        "identifier": "c.enum"
+      },
+      "location": {
+        "position": {
+          "character": 1,
+          "line": 17
+        },
+        "uri": "file:///Users/dgrumberg/VersionControlledDocuments/oss/llvm-project/build/tools/clang/test/ExtractAPI/Output/enum.c.tmp/input.h"
+      },
+      "names": {
+        "navigator": [
+          {
+            "kind": "identifier",
+            "spelling": "(anonymous)"
+          }
+        ],
+        "title": "(anonymous)"
+      },
+      "pathComponents": [
+        "(anonymous)"
+      ]
+    },
+    {
+      "accessLevel": "public",
+      "declarationFragments": [
+        {
+          "kind": "identifier",
+          "spelling": "Constant"
+        }
+      ],
+      "identifier": {
+        "interfaceLanguage": "c",
+        "precise": "c:@Ea@Constant@Constant"
+      },
+      "kind": {
+        "displayName": "Enumeration Case",
+        "identifier": "c.enum.case"
+      },
+      "location": {
+        "position": {
+          "character": 3,
+          "line": 18
+        },
+        "uri": "file:///Users/dgrumberg/VersionControlledDocuments/oss/llvm-project/build/tools/clang/test/ExtractAPI/Output/enum.c.tmp/input.h"
+      },
+      "names": {
+        "navigator": [
+          {
+            "kind": "identifier",
+            "spelling": "Constant"
+          }
+        ],
+        "subHeading": [
+          {
+            "kind": "identifier",
+            "spelling": "Constant"
+          }
+        ],
+        "title": "Constant"
+      },
+      "pathComponents": [
+        "(anonymous)",
+        "Constant"
+      ]
     }
   ]
 }
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===================================================================
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -215,9 +215,11 @@
       return true;
 
     // Collect symbol information.
-    StringRef Name = Decl->getName();
+    std::string NameString = Decl->getQualifiedNameAsString();
+    StringRef Name(NameString);
     if (Name.empty())
       Name = getTypedefName(Decl);
+
     StringRef USR = API.recordUSR(Decl);
     PresumedLoc Loc =
         Context.getSourceManager().getPresumedLoc(Decl->getLocation());
@@ -233,8 +235,9 @@
     DeclarationFragments SubHeading =
         DeclarationFragmentsBuilder::getSubHeading(Decl);
 
-    EnumRecord *EnumRecord = API.addEnum(Name, USR, Loc, Availability, Comment,
-                                         Declaration, SubHeading);
+    EnumRecord *EnumRecord =
+        API.addEnum(API.copyString(Name), USR, Loc, Availability, Comment,
+                    Declaration, SubHeading);
 
     // Now collect information about the enumerators in this enum.
     recordEnumConstants(EnumRecord, Decl->enumerators());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to