diff options
author | Brett Wilson <brettw@gmail.com> | 2022-12-07 10:26:04 -0800 |
---|---|---|
committer | Brett Wilson <brettw@gmail.com> | 2022-12-08 08:02:02 -0800 |
commit | 4a68babd9973f043fd3e40f159fbb990880606a6 (patch) | |
tree | e6579f1987b03aa880f0a21da6c0bc37cb39326b /clang-tools-extra/clang-doc/BitcodeReader.cpp | |
parent | ea4be70cea8509520db8638bb17bcd7b5d8d60ac (diff) | |
download | llvm-4a68babd9973f043fd3e40f159fbb990880606a6.zip llvm-4a68babd9973f043fd3e40f159fbb990880606a6.tar.gz llvm-4a68babd9973f043fd3e40f159fbb990880606a6.tar.bz2 |
[clang-doc] Add template support.
Reads template information from the AST and adds template parameters and
specialization information to the corresponding clang-doc structures.
Add a "QualName" to the Reference struct which includes the full
qualified type name. The Reference object represents a link in the
HTML/MD generators so is based on the unqualified name. But this does
not encode C-V qualifiers or template information that decorate the
name. The new QualName member encodes all of this information and also
makes it easier for the generators or downsteam YAML consumers to
generate the full name (before they had to process the "Path").
In test code that was changed, remove made-up paths to built-in types
like "int". In addition to slightnly cleaning up the code, these types
do not have paths in real execution, and generating incorrect references
to nonexistant data may complicate future changes in the generators.
Convert llvm::Optional to std::optional (YAML library requires this for
the new usage, and this makes everything consistent according to the
llvm::Optional -> std::optional transition).
Differential Revision: https://reviews.llvm.org/D139154
Diffstat (limited to 'clang-tools-extra/clang-doc/BitcodeReader.cpp')
-rw-r--r-- | clang-tools-extra/clang-doc/BitcodeReader.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index c6928f6..9ac60fa 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -350,6 +350,8 @@ llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, return decodeRecord(R, I->USR, Blob); case REFERENCE_NAME: return decodeRecord(R, I->Name, Blob); + case REFERENCE_QUAL_NAME: + return decodeRecord(R, I->QualName, Blob); case REFERENCE_TYPE: return decodeRecord(R, I->RefType, Blob); case REFERENCE_PATH: @@ -362,6 +364,29 @@ llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, } } +llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, + TemplateInfo *I) { + // Currently there are no child records of TemplateInfo (only child blocks). + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for TemplateParamInfo"); +} + +llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, + TemplateSpecializationInfo *I) { + if (ID == TEMPLATE_SPECIALIZATION_OF) + return decodeRecord(R, I->SpecializationOf, Blob); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for TemplateParamInfo"); +} + +llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob, + TemplateParamInfo *I) { + if (ID == TEMPLATE_PARAM_CONTENTS) + return decodeRecord(R, I->Contents, Blob); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for TemplateParamInfo"); +} + template <typename T> llvm::Expected<CommentInfo *> getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -594,6 +619,45 @@ template <> void addChild(BaseRecordInfo *I, FunctionInfo &&R) { I->Children.Functions.emplace_back(std::move(R)); } +// TemplateParam children. These go into either a TemplateInfo (for template +// parameters) or TemplateSpecializationInfo (for the specialization's +// parameters). +template <typename T> void addTemplateParam(T I, TemplateParamInfo &&P) { + llvm::errs() << "invalid container for template parameter"; + exit(1); +} +template <> void addTemplateParam(TemplateInfo *I, TemplateParamInfo &&P) { + I->Params.emplace_back(std::move(P)); +} +template <> +void addTemplateParam(TemplateSpecializationInfo *I, TemplateParamInfo &&P) { + I->Params.emplace_back(std::move(P)); +} + +// Template info. These apply to either records or functions. +template <typename T> void addTemplate(T I, TemplateInfo &&P) { + llvm::errs() << "invalid container for template info"; + exit(1); +} +template <> void addTemplate(RecordInfo *I, TemplateInfo &&P) { + I->Template.emplace(std::move(P)); +} +template <> void addTemplate(FunctionInfo *I, TemplateInfo &&P) { + I->Template.emplace(std::move(P)); +} + +// Template specializations go only into template records. +template <typename T> +void addTemplateSpecialization(T I, TemplateSpecializationInfo &&TSI) { + llvm::errs() << "invalid container for template specialization info"; + exit(1); +} +template <> +void addTemplateSpecialization(TemplateInfo *I, + TemplateSpecializationInfo &&TSI) { + I->Specialization.emplace(std::move(TSI)); +} + // Read records from bitcode into a given info. template <typename T> llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) { @@ -718,6 +782,27 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { addChild(I, std::move(EV)); return llvm::Error::success(); } + case BI_TEMPLATE_BLOCK_ID: { + TemplateInfo TI; + if (auto Err = readBlock(ID, &TI)) + return Err; + addTemplate(I, std::move(TI)); + return llvm::Error::success(); + } + case BI_TEMPLATE_SPECIALIZATION_BLOCK_ID: { + TemplateSpecializationInfo TSI; + if (auto Err = readBlock(ID, &TSI)) + return Err; + addTemplateSpecialization(I, std::move(TSI)); + return llvm::Error::success(); + } + case BI_TEMPLATE_PARAM_BLOCK_ID: { + TemplateParamInfo TPI; + if (auto Err = readBlock(ID, &TPI)) + return Err; + addTemplateParam(I, std::move(TPI)); + return llvm::Error::success(); + } case BI_TYPEDEF_BLOCK_ID: { TypedefInfo TI; if (auto Err = readBlock(ID, &TI)) |