2018-06-05 01:22:20 +08:00
|
|
|
//===-- BitcodeReader.cpp - ClangDoc Bitcode Reader ------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-06-05 01:22:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "BitcodeReader.h"
|
|
|
|
#include "llvm/ADT/IndexedMap.h"
|
|
|
|
#include "llvm/ADT/Optional.h"
|
2018-08-16 00:02:28 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
2018-06-05 01:22:20 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace doc {
|
|
|
|
|
|
|
|
using Record = llvm::SmallVector<uint64_t, 1024>;
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl<char> &Field,
|
|
|
|
llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
Field.assign(Blob.begin(), Blob.end());
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, SymbolID &Field, llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
if (R[0] != BitCodeConstants::USRHashSize)
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Incorrect USR size.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
// First position in the record is the length of the following array, so we
|
|
|
|
// copy the following elements to the field.
|
|
|
|
for (int I = 0, E = R[0]; I < E; ++I)
|
|
|
|
Field[I] = R[I + 1];
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, bool &Field, llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
Field = R[0] != 0;
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, int &Field, llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
if (R[0] > INT_MAX)
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Integer too large to parse.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
Field = (int)R[0];
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, AccessSpecifier &Field,
|
|
|
|
llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (R[0]) {
|
|
|
|
case AS_public:
|
|
|
|
case AS_private:
|
|
|
|
case AS_protected:
|
|
|
|
case AS_none:
|
|
|
|
Field = (AccessSpecifier)R[0];
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid value for AccessSpecifier.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, TagTypeKind &Field, llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (R[0]) {
|
|
|
|
case TTK_Struct:
|
|
|
|
case TTK_Interface:
|
|
|
|
case TTK_Union:
|
|
|
|
case TTK_Class:
|
|
|
|
case TTK_Enum:
|
|
|
|
Field = (TagTypeKind)R[0];
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid value for TagTypeKind.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, llvm::Optional<Location> &Field,
|
|
|
|
llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
if (R[0] > INT_MAX)
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Integer too large to parse.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
Field.emplace((int)R[0], Blob);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, InfoType &Field, llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (auto IT = static_cast<InfoType>(R[0])) {
|
|
|
|
case InfoType::IT_namespace:
|
|
|
|
case InfoType::IT_record:
|
|
|
|
case InfoType::IT_function:
|
|
|
|
case InfoType::IT_default:
|
|
|
|
case InfoType::IT_enum:
|
|
|
|
Field = IT;
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Invalid value for InfoType.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, FieldId &Field, llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (auto F = static_cast<FieldId>(R[0])) {
|
|
|
|
case FieldId::F_namespace:
|
|
|
|
case FieldId::F_parent:
|
|
|
|
case FieldId::F_vparent:
|
|
|
|
case FieldId::F_type:
|
2018-08-03 04:10:17 +08:00
|
|
|
case FieldId::F_child_namespace:
|
|
|
|
case FieldId::F_child_record:
|
2018-06-05 01:22:20 +08:00
|
|
|
case FieldId::F_default:
|
|
|
|
Field = F;
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Invalid value for FieldId.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R,
|
|
|
|
llvm::SmallVectorImpl<llvm::SmallString<16>> &Field,
|
|
|
|
llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
Field.push_back(Blob);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl<Location> &Field,
|
|
|
|
llvm::StringRef Blob) {
|
2018-06-05 01:22:20 +08:00
|
|
|
if (R[0] > INT_MAX)
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Integer too large to parse.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
Field.emplace_back((int)R[0], Blob);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
const unsigned VersionNo) {
|
2018-06-05 01:22:20 +08:00
|
|
|
if (ID == VERSION && R[0] == VersionNo)
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Mismatched bitcode version number.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
NamespaceInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case NAMESPACE_USR:
|
|
|
|
return decodeRecord(R, I->USR, Blob);
|
|
|
|
case NAMESPACE_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
2019-07-13 02:32:00 +08:00
|
|
|
case NAMESPACE_PATH:
|
|
|
|
return decodeRecord(R, I->Path, Blob);
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid field for NamespaceInfo.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
RecordInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case RECORD_USR:
|
|
|
|
return decodeRecord(R, I->USR, Blob);
|
|
|
|
case RECORD_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
2019-07-13 02:32:00 +08:00
|
|
|
case RECORD_PATH:
|
|
|
|
return decodeRecord(R, I->Path, Blob);
|
2018-06-05 01:22:20 +08:00
|
|
|
case RECORD_DEFLOCATION:
|
|
|
|
return decodeRecord(R, I->DefLoc, Blob);
|
|
|
|
case RECORD_LOCATION:
|
|
|
|
return decodeRecord(R, I->Loc, Blob);
|
|
|
|
case RECORD_TAG_TYPE:
|
|
|
|
return decodeRecord(R, I->TagType, Blob);
|
2019-06-25 03:31:02 +08:00
|
|
|
case RECORD_IS_TYPE_DEF:
|
|
|
|
return decodeRecord(R, I->IsTypeDef, Blob);
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid field for RecordInfo.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
EnumInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case ENUM_USR:
|
|
|
|
return decodeRecord(R, I->USR, Blob);
|
|
|
|
case ENUM_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
|
|
|
case ENUM_DEFLOCATION:
|
|
|
|
return decodeRecord(R, I->DefLoc, Blob);
|
|
|
|
case ENUM_LOCATION:
|
|
|
|
return decodeRecord(R, I->Loc, Blob);
|
|
|
|
case ENUM_MEMBER:
|
|
|
|
return decodeRecord(R, I->Members, Blob);
|
|
|
|
case ENUM_SCOPED:
|
|
|
|
return decodeRecord(R, I->Scoped, Blob);
|
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Invalid field for EnumInfo.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
FunctionInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case FUNCTION_USR:
|
|
|
|
return decodeRecord(R, I->USR, Blob);
|
|
|
|
case FUNCTION_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
|
|
|
case FUNCTION_DEFLOCATION:
|
|
|
|
return decodeRecord(R, I->DefLoc, Blob);
|
|
|
|
case FUNCTION_LOCATION:
|
|
|
|
return decodeRecord(R, I->Loc, Blob);
|
|
|
|
case FUNCTION_ACCESS:
|
|
|
|
return decodeRecord(R, I->Access, Blob);
|
|
|
|
case FUNCTION_IS_METHOD:
|
|
|
|
return decodeRecord(R, I->IsMethod, Blob);
|
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid field for FunctionInfo.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
TypeInfo *I) {
|
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
FieldTypeInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case FIELD_TYPE_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Invalid field for TypeInfo.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
MemberTypeInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case MEMBER_TYPE_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
|
|
|
case MEMBER_TYPE_ACCESS:
|
|
|
|
return decodeRecord(R, I->Access, Blob);
|
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid field for MemberTypeInfo.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
CommentInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case COMMENT_KIND:
|
|
|
|
return decodeRecord(R, I->Kind, Blob);
|
|
|
|
case COMMENT_TEXT:
|
|
|
|
return decodeRecord(R, I->Text, Blob);
|
|
|
|
case COMMENT_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
|
|
|
case COMMENT_DIRECTION:
|
|
|
|
return decodeRecord(R, I->Direction, Blob);
|
|
|
|
case COMMENT_PARAMNAME:
|
|
|
|
return decodeRecord(R, I->ParamName, Blob);
|
|
|
|
case COMMENT_CLOSENAME:
|
|
|
|
return decodeRecord(R, I->CloseName, Blob);
|
|
|
|
case COMMENT_ATTRKEY:
|
|
|
|
return decodeRecord(R, I->AttrKeys, Blob);
|
|
|
|
case COMMENT_ATTRVAL:
|
|
|
|
return decodeRecord(R, I->AttrValues, Blob);
|
|
|
|
case COMMENT_ARG:
|
|
|
|
return decodeRecord(R, I->Args, Blob);
|
|
|
|
case COMMENT_SELFCLOSING:
|
|
|
|
return decodeRecord(R, I->SelfClosing, Blob);
|
|
|
|
case COMMENT_EXPLICIT:
|
|
|
|
return decodeRecord(R, I->Explicit, Blob);
|
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid field for CommentInfo.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
|
|
|
|
Reference *I, FieldId &F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case REFERENCE_USR:
|
|
|
|
return decodeRecord(R, I->USR, Blob);
|
|
|
|
case REFERENCE_NAME:
|
|
|
|
return decodeRecord(R, I->Name, Blob);
|
|
|
|
case REFERENCE_TYPE:
|
|
|
|
return decodeRecord(R, I->RefType, Blob);
|
2019-07-13 02:32:00 +08:00
|
|
|
case REFERENCE_PATH:
|
|
|
|
return decodeRecord(R, I->Path, Blob);
|
2018-06-05 01:22:20 +08:00
|
|
|
case REFERENCE_FIELD:
|
|
|
|
return decodeRecord(R, F, Blob);
|
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Invalid field for Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <typename T> llvm::Expected<CommentInfo *> getCommentInfo(T I) {
|
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain CommentInfo.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Expected<CommentInfo *> getCommentInfo(FunctionInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->Description.emplace_back();
|
|
|
|
return &I->Description.back();
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Expected<CommentInfo *> getCommentInfo(NamespaceInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->Description.emplace_back();
|
|
|
|
return &I->Description.back();
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Expected<CommentInfo *> getCommentInfo(RecordInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->Description.emplace_back();
|
|
|
|
return &I->Description.back();
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Expected<CommentInfo *> getCommentInfo(EnumInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->Description.emplace_back();
|
|
|
|
return &I->Description.back();
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Expected<CommentInfo *> getCommentInfo(CommentInfo *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->Children.emplace_back(llvm::make_unique<CommentInfo>());
|
|
|
|
return I->Children.back().get();
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <>
|
|
|
|
llvm::Expected<CommentInfo *> getCommentInfo(std::unique_ptr<CommentInfo> &I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
return getCommentInfo(I.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename TTypeInfo>
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error addTypeInfo(T I, TTypeInfo &&TI) {
|
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain TypeInfo.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Error addTypeInfo(RecordInfo *I, MemberTypeInfo &&T) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->Members.emplace_back(std::move(T));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Error addTypeInfo(FunctionInfo *I, TypeInfo &&T) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->ReturnType = std::move(T);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Error addTypeInfo(FunctionInfo *I, FieldTypeInfo &&T) {
|
2018-06-05 01:22:20 +08:00
|
|
|
I->Params.emplace_back(std::move(T));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <typename T> llvm::Error addReference(T I, Reference &&R, FieldId F) {
|
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Error addReference(TypeInfo *I, Reference &&R, FieldId F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (F) {
|
|
|
|
case FieldId::F_type:
|
|
|
|
I->Type = std::move(R);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <>
|
|
|
|
llvm::Error addReference(FieldTypeInfo *I, Reference &&R, FieldId F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (F) {
|
|
|
|
case FieldId::F_type:
|
|
|
|
I->Type = std::move(R);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <>
|
|
|
|
llvm::Error addReference(MemberTypeInfo *I, Reference &&R, FieldId F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (F) {
|
|
|
|
case FieldId::F_type:
|
|
|
|
I->Type = std::move(R);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Error addReference(EnumInfo *I, Reference &&R, FieldId F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (F) {
|
|
|
|
case FieldId::F_namespace:
|
|
|
|
I->Namespace.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <>
|
|
|
|
llvm::Error addReference(NamespaceInfo *I, Reference &&R, FieldId F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (F) {
|
|
|
|
case FieldId::F_namespace:
|
|
|
|
I->Namespace.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-08-03 04:10:17 +08:00
|
|
|
case FieldId::F_child_namespace:
|
|
|
|
I->ChildNamespaces.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-08-03 04:10:17 +08:00
|
|
|
case FieldId::F_child_record:
|
|
|
|
I->ChildRecords.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <>
|
|
|
|
llvm::Error addReference(FunctionInfo *I, Reference &&R, FieldId F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (F) {
|
|
|
|
case FieldId::F_namespace:
|
|
|
|
I->Namespace.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
case FieldId::F_parent:
|
|
|
|
I->Parent = std::move(R);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (F) {
|
|
|
|
case FieldId::F_namespace:
|
|
|
|
I->Namespace.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
case FieldId::F_parent:
|
|
|
|
I->Parents.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
case FieldId::F_vparent:
|
|
|
|
I->VirtualParents.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-08-03 04:10:17 +08:00
|
|
|
case FieldId::F_child_record:
|
|
|
|
I->ChildRecords.emplace_back(std::move(R));
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid type cannot contain Reference.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-03 04:10:17 +08:00
|
|
|
template <typename T, typename ChildInfoType>
|
|
|
|
void addChild(T I, ChildInfoType &&R) {
|
|
|
|
llvm::errs() << "Invalid child type for info.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> void addChild(NamespaceInfo *I, FunctionInfo &&R) {
|
|
|
|
I->ChildFunctions.emplace_back(std::move(R));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> void addChild(NamespaceInfo *I, EnumInfo &&R) {
|
|
|
|
I->ChildEnums.emplace_back(std::move(R));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> void addChild(RecordInfo *I, FunctionInfo &&R) {
|
|
|
|
I->ChildFunctions.emplace_back(std::move(R));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> void addChild(RecordInfo *I, EnumInfo &&R) {
|
|
|
|
I->ChildEnums.emplace_back(std::move(R));
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:22:20 +08:00
|
|
|
// Read records from bitcode into a given info.
|
2018-08-16 00:02:28 +08:00
|
|
|
template <typename T>
|
|
|
|
llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
Record R;
|
|
|
|
llvm::StringRef Blob;
|
2019-06-27 03:50:12 +08:00
|
|
|
llvm::Expected<unsigned> MaybeRecID = Stream.readRecord(ID, R, &Blob);
|
|
|
|
if (!MaybeRecID)
|
|
|
|
return MaybeRecID.takeError();
|
|
|
|
return parseRecord(R, MaybeRecID.get(), Blob, I);
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
template <>
|
|
|
|
llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
Record R;
|
|
|
|
llvm::StringRef Blob;
|
2019-06-27 03:50:12 +08:00
|
|
|
llvm::Expected<unsigned> MaybeRecID = Stream.readRecord(ID, R, &Blob);
|
|
|
|
if (!MaybeRecID)
|
|
|
|
return MaybeRecID.takeError();
|
|
|
|
return parseRecord(R, MaybeRecID.get(), Blob, I, CurrentReferenceField);
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read a block of records into a single info.
|
2018-08-16 00:02:28 +08:00
|
|
|
template <typename T>
|
|
|
|
llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
|
2019-06-27 03:50:12 +08:00
|
|
|
if (llvm::Error Err = Stream.EnterSubBlock(ID))
|
|
|
|
return Err;
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
unsigned BlockOrCode = 0;
|
|
|
|
Cursor Res = skipUntilRecordOrBlock(BlockOrCode);
|
|
|
|
|
|
|
|
switch (Res) {
|
|
|
|
case Cursor::BadBlock:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Bad block found.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
case Cursor::BlockEnd:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
case Cursor::BlockBegin:
|
2019-06-27 03:50:12 +08:00
|
|
|
if (llvm::Error Err = readSubBlock(BlockOrCode, I)) {
|
|
|
|
if (llvm::Error Skipped = Stream.SkipBlock())
|
|
|
|
return joinErrors(std::move(Err), std::move(Skipped));
|
2018-08-16 00:02:28 +08:00
|
|
|
return Err;
|
|
|
|
}
|
2018-06-05 01:22:20 +08:00
|
|
|
continue;
|
|
|
|
case Cursor::Record:
|
|
|
|
break;
|
|
|
|
}
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readRecord(BlockOrCode, I))
|
|
|
|
return Err;
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
2018-08-03 04:10:17 +08:00
|
|
|
// Blocks can only have Comment, Reference, TypeInfo, FunctionInfo, or
|
|
|
|
// EnumInfo subblocks
|
2018-08-16 00:02:28 +08:00
|
|
|
case BI_COMMENT_BLOCK_ID: {
|
|
|
|
auto Comment = getCommentInfo(I);
|
|
|
|
if (!Comment)
|
|
|
|
return Comment.takeError();
|
|
|
|
if (auto Err = readBlock(ID, Comment.get()))
|
|
|
|
return Err;
|
|
|
|
return llvm::Error::success();
|
|
|
|
}
|
2018-06-05 01:22:20 +08:00
|
|
|
case BI_TYPE_BLOCK_ID: {
|
|
|
|
TypeInfo TI;
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, &TI))
|
|
|
|
return Err;
|
|
|
|
if (auto Err = addTypeInfo(I, std::move(TI)))
|
|
|
|
return Err;
|
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
case BI_FIELD_TYPE_BLOCK_ID: {
|
|
|
|
FieldTypeInfo TI;
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, &TI))
|
|
|
|
return Err;
|
|
|
|
if (auto Err = addTypeInfo(I, std::move(TI)))
|
|
|
|
return Err;
|
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
case BI_MEMBER_TYPE_BLOCK_ID: {
|
|
|
|
MemberTypeInfo TI;
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, &TI))
|
|
|
|
return Err;
|
|
|
|
if (auto Err = addTypeInfo(I, std::move(TI)))
|
|
|
|
return Err;
|
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
case BI_REFERENCE_BLOCK_ID: {
|
|
|
|
Reference R;
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, &R))
|
|
|
|
return Err;
|
|
|
|
if (auto Err = addReference(I, std::move(R), CurrentReferenceField))
|
|
|
|
return Err;
|
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
2018-08-03 04:10:17 +08:00
|
|
|
case BI_FUNCTION_BLOCK_ID: {
|
|
|
|
FunctionInfo F;
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, &F))
|
|
|
|
return Err;
|
|
|
|
addChild(I, std::move(F));
|
|
|
|
return llvm::Error::success();
|
2018-08-03 04:10:17 +08:00
|
|
|
}
|
|
|
|
case BI_ENUM_BLOCK_ID: {
|
|
|
|
EnumInfo E;
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, &E))
|
|
|
|
return Err;
|
|
|
|
addChild(I, std::move(E));
|
|
|
|
return llvm::Error::success();
|
2018-08-03 04:10:17 +08:00
|
|
|
}
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Invalid subblock type.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClangDocBitcodeReader::Cursor
|
|
|
|
ClangDocBitcodeReader::skipUntilRecordOrBlock(unsigned &BlockOrRecordID) {
|
|
|
|
BlockOrRecordID = 0;
|
|
|
|
|
|
|
|
while (!Stream.AtEndOfStream()) {
|
2019-06-27 03:50:12 +08:00
|
|
|
Expected<unsigned> MaybeCode = Stream.ReadCode();
|
|
|
|
if (!MaybeCode) {
|
|
|
|
// FIXME this drops the error on the floor.
|
|
|
|
consumeError(MaybeCode.takeError());
|
|
|
|
return Cursor::BadBlock;
|
|
|
|
}
|
2018-06-05 01:22:20 +08:00
|
|
|
|
2019-07-06 04:22:40 +08:00
|
|
|
unsigned Code = MaybeCode.get();
|
|
|
|
if (Code >= static_cast<unsigned>(llvm::bitc::FIRST_APPLICATION_ABBREV)) {
|
|
|
|
BlockOrRecordID = Code;
|
|
|
|
return Cursor::Record;
|
|
|
|
}
|
|
|
|
switch (static_cast<llvm::bitc::FixedAbbrevIDs>(Code)) {
|
2018-06-05 01:22:20 +08:00
|
|
|
case llvm::bitc::ENTER_SUBBLOCK:
|
2019-06-27 03:50:12 +08:00
|
|
|
if (Expected<unsigned> MaybeID = Stream.ReadSubBlockID())
|
|
|
|
BlockOrRecordID = MaybeID.get();
|
|
|
|
else {
|
|
|
|
// FIXME this drops the error on the floor.
|
|
|
|
consumeError(MaybeID.takeError());
|
|
|
|
}
|
2018-06-05 01:22:20 +08:00
|
|
|
return Cursor::BlockBegin;
|
|
|
|
case llvm::bitc::END_BLOCK:
|
|
|
|
if (Stream.ReadBlockEnd())
|
|
|
|
return Cursor::BadBlock;
|
|
|
|
return Cursor::BlockEnd;
|
|
|
|
case llvm::bitc::DEFINE_ABBREV:
|
2019-06-27 03:50:12 +08:00
|
|
|
if (llvm::Error Err = Stream.ReadAbbrevRecord()) {
|
|
|
|
// FIXME this drops the error on the floor.
|
|
|
|
consumeError(std::move(Err));
|
|
|
|
}
|
2018-06-05 01:22:20 +08:00
|
|
|
continue;
|
|
|
|
case llvm::bitc::UNABBREV_RECORD:
|
|
|
|
return Cursor::BadBlock;
|
2019-07-06 04:22:40 +08:00
|
|
|
case llvm::bitc::FIRST_APPLICATION_ABBREV:
|
|
|
|
llvm_unreachable("Unexpected abbrev id.");
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
llvm_unreachable("Premature stream end.");
|
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error ClangDocBitcodeReader::validateStream() {
|
2018-06-05 01:22:20 +08:00
|
|
|
if (Stream.AtEndOfStream())
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Premature end of stream.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
// Sniff for the signature.
|
2019-06-27 03:50:12 +08:00
|
|
|
for (int Idx = 0; Idx != 4; ++Idx) {
|
|
|
|
Expected<llvm::SimpleBitstreamCursor::word_t> MaybeRead = Stream.Read(8);
|
|
|
|
if (!MaybeRead)
|
|
|
|
return MaybeRead.takeError();
|
|
|
|
else if (MaybeRead.get() != BitCodeConstants::Signature[Idx])
|
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Invalid bitcode signature.\n", llvm::inconvertibleErrorCode());
|
|
|
|
}
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
|
2019-06-27 03:50:12 +08:00
|
|
|
Expected<Optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
|
|
|
|
Stream.ReadBlockInfoBlock();
|
|
|
|
if (!MaybeBlockInfo)
|
|
|
|
return MaybeBlockInfo.takeError();
|
|
|
|
else
|
|
|
|
BlockInfo = MaybeBlockInfo.get();
|
2018-06-05 01:22:20 +08:00
|
|
|
if (!BlockInfo)
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Unable to parse BlockInfoBlock.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
Stream.setBlockInfo(&*BlockInfo);
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::Error::success();
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Expected<std::unique_ptr<Info>>
|
|
|
|
ClangDocBitcodeReader::createInfo(unsigned ID) {
|
2018-06-05 01:22:20 +08:00
|
|
|
std::unique_ptr<Info> I = llvm::make_unique<T>();
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, static_cast<T *>(I.get())))
|
|
|
|
return std::move(Err);
|
2019-07-13 02:32:00 +08:00
|
|
|
return std::unique_ptr<Info>{std::move(I)};
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-16 00:02:28 +08:00
|
|
|
llvm::Expected<std::unique_ptr<Info>>
|
|
|
|
ClangDocBitcodeReader::readBlockToInfo(unsigned ID) {
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
case BI_NAMESPACE_BLOCK_ID:
|
|
|
|
return createInfo<NamespaceInfo>(ID);
|
|
|
|
case BI_RECORD_BLOCK_ID:
|
|
|
|
return createInfo<RecordInfo>(ID);
|
|
|
|
case BI_ENUM_BLOCK_ID:
|
|
|
|
return createInfo<EnumInfo>(ID);
|
|
|
|
case BI_FUNCTION_BLOCK_ID:
|
|
|
|
return createInfo<FunctionInfo>(ID);
|
|
|
|
default:
|
2018-08-16 00:02:28 +08:00
|
|
|
return llvm::make_error<llvm::StringError>("Cannot create info.\n",
|
|
|
|
llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point
|
2018-08-03 04:10:17 +08:00
|
|
|
llvm::Expected<std::vector<std::unique_ptr<Info>>>
|
|
|
|
ClangDocBitcodeReader::readBitcode() {
|
2018-06-05 01:22:20 +08:00
|
|
|
std::vector<std::unique_ptr<Info>> Infos;
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = validateStream())
|
|
|
|
return std::move(Err);
|
2018-06-05 01:22:20 +08:00
|
|
|
|
|
|
|
// Read the top level blocks.
|
|
|
|
while (!Stream.AtEndOfStream()) {
|
2019-06-27 03:50:12 +08:00
|
|
|
Expected<unsigned> MaybeCode = Stream.ReadCode();
|
|
|
|
if (!MaybeCode)
|
|
|
|
return MaybeCode.takeError();
|
|
|
|
if (MaybeCode.get() != llvm::bitc::ENTER_SUBBLOCK)
|
2018-08-03 04:10:17 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
2018-08-16 00:02:28 +08:00
|
|
|
"No blocks in input.\n", llvm::inconvertibleErrorCode());
|
2019-06-27 03:50:12 +08:00
|
|
|
Expected<unsigned> MaybeID = Stream.ReadSubBlockID();
|
|
|
|
if (!MaybeID)
|
|
|
|
return MaybeID.takeError();
|
|
|
|
unsigned ID = MaybeID.get();
|
2018-06-05 01:22:20 +08:00
|
|
|
switch (ID) {
|
|
|
|
// NamedType and Comment blocks should not appear at the top level
|
|
|
|
case BI_TYPE_BLOCK_ID:
|
|
|
|
case BI_FIELD_TYPE_BLOCK_ID:
|
|
|
|
case BI_MEMBER_TYPE_BLOCK_ID:
|
|
|
|
case BI_COMMENT_BLOCK_ID:
|
|
|
|
case BI_REFERENCE_BLOCK_ID:
|
2018-08-03 04:10:17 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
2018-08-16 00:02:28 +08:00
|
|
|
"Invalid top level block.\n", llvm::inconvertibleErrorCode());
|
2018-06-05 01:22:20 +08:00
|
|
|
case BI_NAMESPACE_BLOCK_ID:
|
|
|
|
case BI_RECORD_BLOCK_ID:
|
|
|
|
case BI_ENUM_BLOCK_ID:
|
2018-08-16 00:02:28 +08:00
|
|
|
case BI_FUNCTION_BLOCK_ID: {
|
|
|
|
auto InfoOrErr = readBlockToInfo(ID);
|
|
|
|
if (!InfoOrErr)
|
|
|
|
return InfoOrErr.takeError();
|
|
|
|
Infos.emplace_back(std::move(InfoOrErr.get()));
|
2018-08-03 04:10:17 +08:00
|
|
|
continue;
|
2018-08-16 00:02:28 +08:00
|
|
|
}
|
2018-06-05 01:22:20 +08:00
|
|
|
case BI_VERSION_BLOCK_ID:
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlock(ID, VersionNumber))
|
|
|
|
return std::move(Err);
|
|
|
|
continue;
|
2018-06-05 01:22:20 +08:00
|
|
|
case llvm::bitc::BLOCKINFO_BLOCK_ID:
|
2018-08-16 00:02:28 +08:00
|
|
|
if (auto Err = readBlockInfoBlock())
|
|
|
|
return std::move(Err);
|
|
|
|
continue;
|
2018-06-05 01:22:20 +08:00
|
|
|
default:
|
2019-06-27 03:50:12 +08:00
|
|
|
if (llvm::Error Err = Stream.SkipBlock()) {
|
|
|
|
// FIXME this drops the error on the floor.
|
|
|
|
consumeError(std::move(Err));
|
|
|
|
}
|
|
|
|
continue;
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
}
|
2018-08-03 04:10:17 +08:00
|
|
|
return std::move(Infos);
|
2018-06-05 01:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace doc
|
|
|
|
} // namespace clang
|