diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp --- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp +++ b/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()); diff --git a/clang/test/ExtractAPI/enum.c b/clang/test/ExtractAPI/enum.c --- a/clang/test/ExtractAPI/enum.c +++ b/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" + ] } ] }