[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG7443a504bf6c: [clang][extract-api] Add support for true anonymous enums (authored by dang). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123533/new/ https://reviews.llvm.org/D123533 Files: clang/include/clang/ExtractAPI/API.h clang/lib/ExtractAPI/API.cpp 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,14 @@ West }; +enum { + Constant = 1 +}; + +enum { + OtherConstant = 2 +}; + //--- reference.output.json.in { "metadata": { @@ -100,6 +108,16 @@ "kind": "memberOf", "source": "c:@E@Direction@West", "target": "c:@E@Direction" +}, +{ + "kind": "memberOf", + "source": "c:@Ea@Constant@Constant", + "target": "c:@Ea@Constant" +}, +{ + "kind": "memberOf", + "source": "c:@Ea@OtherConstant@OtherConstant", + "target": "c:@Ea@OtherConstant" } ], "symbols": [ @@ -641,6 +659,182 @@ "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://INPUT_DIR/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://INPUT_DIR/input.h" + }, + "names": { +"navigator": [ + { +"kind": "identifier", +"spelling": "Constant" + } +], +"subHeading": [ + { +"kind": "identifier", +"spelling": "Constant" + } +], +"title": "Constant" + }, + "pathComponents": [ +"(anonymous)", +"Constant" + ] +}, +{ + "accessLevel": "public", + "declarationFragments": [ +{ + "kind": "keyword", + "spelling": "enum" +}, +{ + "kind": "text", + "spelling": ": " +}, +{ + "kind": "typeIdentifier", + "preciseIdentifier": "c:i", + "spelling": "unsigned int" +} + ], + "identifier": { +"interfaceLanguage": "c", +"precise": "c:@Ea@OtherConstant" + }, + "kind": { +"displayName": "Enumeration", +"identifier": "c.enum" + }, + "location": { +"position": { + "character": 1, + "line": 21 +}, +"uri": "file://INPUT_DIR/input.h" + }, + "names": { +"navigator": [ + { +"kind": "identifier", +"spelling": "(anonymous)" + } +], +"title": "(anonymous)" + }, + "pathComponents": [ +"(anonymous)" + ] +}, +{ + "accessLevel": "public", + "declarationFragments": [ +{ + "kind": "identifier", + "spelling": "OtherConstant" +} + ], + "identifier": { +"interfaceLanguage": "c", +"precise": "c:@Ea@OtherConstant@OtherConstant" + }, + "kind": { +"displayName": "Enumeration Case", +"identifier": "c.enum.case" + }, + "location": { +"position": { + "character": 3, + "line": 22 +}, +"uri": "file://INPUT_DIR/input.h" + }, + "names": { +"navigator": [ + { +"kind": "identifier", +"spelling":
[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
zixuw accepted this revision. zixuw added a comment. This revision is now accepted and ready to land. LGTM Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123533/new/ https://reviews.llvm.org/D123533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
dang updated this revision to Diff 422296. dang marked an inline comment as done. dang added a comment. Add a second anonymous enum to the test case to make sure that distinct symbols are generated for both of them. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123533/new/ https://reviews.llvm.org/D123533 Files: clang/include/clang/ExtractAPI/API.h clang/lib/ExtractAPI/API.cpp 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,14 @@ West }; +enum { + Constant = 1 +}; + +enum { + OtherConstant = 2 +}; + //--- reference.output.json.in { "metadata": { @@ -100,6 +108,16 @@ "kind": "memberOf", "source": "c:@E@Direction@West", "target": "c:@E@Direction" +}, +{ + "kind": "memberOf", + "source": "c:@Ea@Constant@Constant", + "target": "c:@Ea@Constant" +}, +{ + "kind": "memberOf", + "source": "c:@Ea@OtherConstant@OtherConstant", + "target": "c:@Ea@OtherConstant" } ], "symbols": [ @@ -641,6 +659,182 @@ "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://INPUT_DIR/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://INPUT_DIR/input.h" + }, + "names": { +"navigator": [ + { +"kind": "identifier", +"spelling": "Constant" + } +], +"subHeading": [ + { +"kind": "identifier", +"spelling": "Constant" + } +], +"title": "Constant" + }, + "pathComponents": [ +"(anonymous)", +"Constant" + ] +}, +{ + "accessLevel": "public", + "declarationFragments": [ +{ + "kind": "keyword", + "spelling": "enum" +}, +{ + "kind": "text", + "spelling": ": " +}, +{ + "kind": "typeIdentifier", + "preciseIdentifier": "c:i", + "spelling": "unsigned int" +} + ], + "identifier": { +"interfaceLanguage": "c", +"precise": "c:@Ea@OtherConstant" + }, + "kind": { +"displayName": "Enumeration", +"identifier": "c.enum" + }, + "location": { +"position": { + "character": 1, + "line": 21 +}, +"uri": "file://INPUT_DIR/input.h" + }, + "names": { +"navigator": [ + { +"kind": "identifier", +"spelling": "(anonymous)" + } +], +"title": "(anonymous)" + }, + "pathComponents": [ +"(anonymous)" + ] +}, +{ + "accessLevel": "public", + "declarationFragments": [ +{ + "kind": "identifier", + "spelling": "OtherConstant" +} + ], + "identifier": { +"interfaceLanguage": "c", +"precise": "c:@Ea@OtherConstant@OtherConstant" + }, + "kind": { +"displayName": "Enumeration Case", +"identifier": "c.enum.case" + }, + "location": { +"position": { + "character": 3, + "line": 22 +}, +"uri": "file://INPUT_DIR/input.h" + }, + "names": { +"navigator": [ + { +"kind": "identifier", +"spelling": "OtherConstant" +
[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
zixuw added inline comments. Comment at: clang/test/ExtractAPI/enum.c:693 +], +"title": "(anonymous)" + }, dang wrote: > zixuw wrote: > > So the `Name` of the record is literally `(anonymous)`? I think this might > > create problems (well I guess we always had this problem) that multiple > > anonymous records of the same kind getting the same `Name`, and `RecordMap` > > is indexed with it... > > We should switch the key of `RecordMap`s to `USR` instead probably. > Agreed, added this to this patch. Nice! Thanks Daniel! Could you please also update the test case to see if it now handles two anonymous records correctly? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123533/new/ https://reviews.llvm.org/D123533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
dang marked 3 inline comments as done. dang added inline comments. Comment at: clang/test/ExtractAPI/enum.c:693 +], +"title": "(anonymous)" + }, zixuw wrote: > So the `Name` of the record is literally `(anonymous)`? I think this might > create problems (well I guess we always had this problem) that multiple > anonymous records of the same kind getting the same `Name`, and `RecordMap` > is indexed with it... > We should switch the key of `RecordMap`s to `USR` instead probably. Agreed, added this to this patch. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123533/new/ https://reviews.llvm.org/D123533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
dang updated this revision to Diff 422160. dang added a comment. Address code review feedback: - Normalize test file URIs - Key RecordMaps by USR instead of by Name Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123533/new/ https://reviews.llvm.org/D123533 Files: clang/include/clang/ExtractAPI/API.h clang/lib/ExtractAPI/API.cpp 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://INPUT_DIR/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://INPUT_DIR/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()); Index: clang/lib/ExtractAPI/API.cpp === --- clang/lib/ExtractAPI/API.cpp +++ clang/lib/ExtractAPI/API.cpp @@ -28,13 +28,13 @@ template RecordTy *addTopLevelRecord(APISet::RecordMap , -StringRef Name, CtorArgsTy &&...CtorArgs) { - auto Result = RecordMap.insert({Name, nullptr}); +StringRef USR, CtorArgsTy &&...CtorArgs) { + auto Result = RecordMap.insert({USR, nullptr}); // Create the record if it does not already exist if (Result.second) Result.first->second = -std::make_unique(Name, std::forward(CtorArgs)...); +std::make_unique(USR, std::forward(CtorArgs)...); return
[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
zixuw added inline comments. Comment at: clang/test/ExtractAPI/enum.c:684 +}, +"uri": "file:///Users/dgrumberg/VersionControlledDocuments/oss/llvm-project/build/tools/clang/test/ExtractAPI/Output/enum.c.tmp/input.h" + }, nit: normalize Comment at: clang/test/ExtractAPI/enum.c:693 +], +"title": "(anonymous)" + }, So the `Name` of the record is literally `(anonymous)`? I think this might create problems (well I guess we always had this problem) that multiple anonymous records of the same kind getting the same `Name`, and `RecordMap` is indexed with it... We should switch the key of `RecordMap`s to `USR` instead probably. Comment at: clang/test/ExtractAPI/enum.c:720 +}, +"uri": "file:///Users/dgrumberg/VersionControlledDocuments/oss/llvm-project/build/tools/clang/test/ExtractAPI/Output/enum.c.tmp/input.h" + }, nit: normalize Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123533/new/ https://reviews.llvm.org/D123533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D123533: [clang][extract-api] Add support for true anonymous enums
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