diff options
author | Zixu Wang <zixu_wang@apple.com> | 2022-03-16 17:49:31 -0700 |
---|---|---|
committer | Zixu Wang <zixu_wang@apple.com> | 2022-03-23 09:41:21 -0700 |
commit | 71b4c22612a06c950d31db83a45dee7412a64c64 (patch) | |
tree | 3f5c02729d313e9d0dd377e7001bcf019ba5489a /clang/lib/ExtractAPI/API.cpp | |
parent | 5a2e56b70e2fa7ad0d82e54bc4c741b16f05e475 (diff) | |
download | llvm-71b4c22612a06c950d31db83a45dee7412a64c64.zip llvm-71b4c22612a06c950d31db83a45dee7412a64c64.tar.gz llvm-71b4c22612a06c950d31db83a45dee7412a64c64.tar.bz2 |
[clang][extract-api] Add enum support
Add support for enum records
- Add `EnumConstantRecord` and `EnumRecord` to store API information for
enums
- Implement `VisitEnumDecl` in `ExtractAPIVisitor`
- Implement serializatin for enum records and `MemberOf` relationship
- Add test case for enum records
- Few other improvements
Depends on D122160
Differential Revision: https://reviews.llvm.org/D121873
Diffstat (limited to 'clang/lib/ExtractAPI/API.cpp')
-rw-r--r-- | clang/lib/ExtractAPI/API.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp index 45eef3d..fd9e92c 100644 --- a/clang/lib/ExtractAPI/API.cpp +++ b/clang/lib/ExtractAPI/API.cpp @@ -59,6 +59,31 @@ APISet::addFunction(StringRef Name, StringRef USR, PresumedLoc Loc, Comment, Fragments, SubHeading, Signature); } +EnumConstantRecord *APISet::addEnumConstant( + EnumRecord *Enum, StringRef Name, StringRef USR, PresumedLoc Loc, + const AvailabilityInfo &Availability, const DocComment &Comment, + DeclarationFragments Declaration, DeclarationFragments SubHeading) { + auto Record = + APIRecordUniquePtr<EnumConstantRecord>(new (Allocator) EnumConstantRecord{ + Name, USR, Loc, Availability, Comment, Declaration, SubHeading}); + return Enum->Constants.emplace_back(std::move(Record)).get(); +} + +EnumRecord *APISet::addEnum(StringRef Name, StringRef USR, PresumedLoc Loc, + const AvailabilityInfo &Availability, + const DocComment &Comment, + DeclarationFragments Declaration, + DeclarationFragments SubHeading) { + auto Result = Enums.insert({Name, nullptr}); + if (Result.second) { + // Create the record if it does not already exist. + auto Record = APIRecordUniquePtr<EnumRecord>(new (Allocator) EnumRecord{ + Name, USR, Loc, Availability, Comment, Declaration, SubHeading}); + Result.first->second = std::move(Record); + } + return Result.first->second.get(); +} + StringRef APISet::recordUSR(const Decl *D) { SmallString<128> USR; index::generateUSRForDecl(D, USR); |