diff options
author | Brett Wilson <brettw@gmail.com> | 2022-10-14 14:28:43 -0700 |
---|---|---|
committer | Brett Wilson <brettw@gmail.com> | 2022-10-14 14:59:29 -0700 |
commit | 21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54 (patch) | |
tree | 168f3cea352ff8c49025d3bbae6823d4538cf8f8 /clang-tools-extra/clang-doc/BitcodeReader.cpp | |
parent | d91b0d6816dfd82755e807105493b7c00ee91ce0 (diff) | |
download | llvm-21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54.zip llvm-21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54.tar.gz llvm-21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54.tar.bz2 |
[clang-doc] Add typedef/using information.
Read typedef and "using" type alias declarations and serialize into the
internal structures. Emit this information in the YAML output. The HTML
and MD generators are unchanged.
Separate out the logic to create the parent namespace or record object
and insert the newly created child into it. This logic was previously
duplicated for every "info" type and is now shared.
To help this, a struct containing the child vectors was separated out so
children can be added generically and without having too many templates.
A small change was made to populateParentNamespaces() to allow using
types that aren't themselves DeclContexts (typedefs are the first
example of this).
Differential Revision: https://reviews.llvm.org/D134371
Diffstat (limited to 'clang-tools-extra/clang-doc/BitcodeReader.cpp')
-rw-r--r-- | clang-tools-extra/clang-doc/BitcodeReader.cpp | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 0272726..8e1db35 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -24,12 +24,6 @@ llvm::Error decodeRecord(const Record &R, llvm::SmallVectorImpl<char> &Field, return llvm::Error::success(); } -llvm::Error decodeRecord(const Record &R, std::string &Field, - llvm::StringRef Blob) { - Field.assign(Blob.begin(), Blob.end()); - return llvm::Error::success(); -} - llvm::Error decodeRecord(const Record &R, SymbolID &Field, llvm::StringRef Blob) { if (R[0] != BitCodeConstants::USRHashSize) @@ -104,6 +98,7 @@ llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_function: case InfoType::IT_default: case InfoType::IT_enum: + case InfoType::IT_typedef: Field = IT; return llvm::Error::success(); } @@ -234,6 +229,23 @@ llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, } llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, + TypedefInfo *I) { + switch (ID) { + case TYPEDEF_USR: + return decodeRecord(R, I->USR, Blob); + case TYPEDEF_NAME: + return decodeRecord(R, I->Name, Blob); + case TYPEDEF_DEFLOCATION: + return decodeRecord(R, I->DefLoc, Blob); + case TYPEDEF_IS_USING: + return decodeRecord(R, I->IsUsing, Blob); + default: + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for TypedefInfo"); + } +} + +llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, EnumValueInfo *I) { switch (ID) { case ENUM_VALUE_NAME: @@ -424,6 +436,11 @@ template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(TypedefInfo *I, TypeInfo &&T) { + I->Underlying = std::move(T); + return llvm::Error::success(); +} + template <typename T> llvm::Error addReference(T I, Reference &&R, FieldId F) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain Reference"); @@ -475,6 +492,17 @@ template <> llvm::Error addReference(EnumInfo *I, Reference &&R, FieldId F) { } } +template <> llvm::Error addReference(TypedefInfo *I, Reference &&R, FieldId F) { + switch (F) { + case FieldId::F_namespace: + I->Namespace.emplace_back(std::move(R)); + return llvm::Error::success(); + default: + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid type cannot contain Reference"); + } +} + template <> llvm::Error addReference(NamespaceInfo *I, Reference &&R, FieldId F) { switch (F) { @@ -482,10 +510,10 @@ llvm::Error addReference(NamespaceInfo *I, Reference &&R, FieldId F) { I->Namespace.emplace_back(std::move(R)); return llvm::Error::success(); case FieldId::F_child_namespace: - I->ChildNamespaces.emplace_back(std::move(R)); + I->Children.Namespaces.emplace_back(std::move(R)); return llvm::Error::success(); case FieldId::F_child_record: - I->ChildRecords.emplace_back(std::move(R)); + I->Children.Records.emplace_back(std::move(R)); return llvm::Error::success(); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -520,7 +548,7 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) { I->VirtualParents.emplace_back(std::move(R)); return llvm::Error::success(); case FieldId::F_child_record: - I->ChildRecords.emplace_back(std::move(R)); + I->Children.Records.emplace_back(std::move(R)); return llvm::Error::success(); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -534,32 +562,37 @@ void addChild(T I, ChildInfoType &&R) { exit(1); } +// Namespace children: template <> void addChild(NamespaceInfo *I, FunctionInfo &&R) { - I->ChildFunctions.emplace_back(std::move(R)); + I->Children.Functions.emplace_back(std::move(R)); } - template <> void addChild(NamespaceInfo *I, EnumInfo &&R) { - I->ChildEnums.emplace_back(std::move(R)); + I->Children.Enums.emplace_back(std::move(R)); +} +template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { + I->Children.Typedefs.emplace_back(std::move(R)); } +// Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { - I->ChildFunctions.emplace_back(std::move(R)); + I->Children.Functions.emplace_back(std::move(R)); } - template <> void addChild(RecordInfo *I, EnumInfo &&R) { - I->ChildEnums.emplace_back(std::move(R)); + I->Children.Enums.emplace_back(std::move(R)); +} +template <> void addChild(RecordInfo *I, TypedefInfo &&R) { + I->Children.Typedefs.emplace_back(std::move(R)); } +// Other types of children: template <> void addChild(EnumInfo *I, EnumValueInfo &&R) { I->Members.emplace_back(std::move(R)); } - template <> void addChild(RecordInfo *I, BaseRecordInfo &&R) { I->Bases.emplace_back(std::move(R)); } - template <> void addChild(BaseRecordInfo *I, FunctionInfo &&R) { - I->ChildFunctions.emplace_back(std::move(R)); + I->Children.Functions.emplace_back(std::move(R)); } // Read records from bitcode into a given info. @@ -686,6 +719,13 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { addChild(I, std::move(EV)); return llvm::Error::success(); } + case BI_TYPEDEF_BLOCK_ID: { + TypedefInfo TI; + if (auto Err = readBlock(ID, &TI)) + return Err; + addChild(I, std::move(TI)); + return llvm::Error::success(); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -786,6 +826,8 @@ ClangDocBitcodeReader::readBlockToInfo(unsigned ID) { return createInfo<RecordInfo>(ID); case BI_ENUM_BLOCK_ID: return createInfo<EnumInfo>(ID); + case BI_TYPEDEF_BLOCK_ID: + return createInfo<TypedefInfo>(ID); case BI_FUNCTION_BLOCK_ID: return createInfo<FunctionInfo>(ID); default: @@ -825,6 +867,7 @@ ClangDocBitcodeReader::readBitcode() { case BI_NAMESPACE_BLOCK_ID: case BI_RECORD_BLOCK_ID: case BI_ENUM_BLOCK_ID: + case BI_TYPEDEF_BLOCK_ID: case BI_FUNCTION_BLOCK_ID: { auto InfoOrErr = readBlockToInfo(ID); if (!InfoOrErr) |