================ @@ -3129,42 +3129,86 @@ class AttrReader { OMPTraitInfo *readOMPTraitInfo() { return Reader.readOMPTraitInfo(); } template <typename T> T *readDeclAs() { return Reader.readDeclAs<T>(); } + + AttributeCommonInfo readAttributeCommonInfo() { + IdentifierInfo *AttrName = readIdentifier(); + IdentifierInfo *ScopeName = readIdentifier(); + SourceRange AttrRange = readSourceRange(); + SourceLocation ScopeLoc = readSourceLocation(); + unsigned ParsedKind = readInt(); + unsigned Syntax = readInt(); + unsigned SpellingIndex = readInt(); + bool IsAlignas = (ParsedKind == AttributeCommonInfo::AT_Aligned && + Syntax == AttributeCommonInfo::AS_Keyword && + SpellingIndex == AlignedAttr::Keyword_alignas); + bool IsRegularKeywordAttribute = readBool(); + + AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc, + AttributeCommonInfo::Kind(ParsedKind), + {AttributeCommonInfo::Syntax(Syntax), + SpellingIndex, IsAlignas, + IsRegularKeywordAttribute}); + return Info; + } + + std::optional<attr::Kind> readAttrKind() { + auto V = readInt(); + if (!V) + return {}; + + // Kind is stored as a 1-based integer because 0 is used to indicate a null + // Attr pointer. + return static_cast<attr::Kind>(V - 1); + } + + Attr *createAttribute(attr::Kind Kind, AttributeCommonInfo Info) { + ASTContext &Context = Reader.getContext(); + Attr *New = nullptr; + auto Record = *this; +#include "clang/Serialization/AttrPCHRead.inc" + + assert(New && "Unable to decode attribute?"); + return New; + } }; -} +} // namespace Attr *ASTRecordReader::readAttr() { AttrReader Record(*this); - auto V = Record.readInt(); - if (!V) + attr::Kind Kind; + if (auto KindOpt = Record.readAttrKind(); !KindOpt) return nullptr; + else + Kind = *KindOpt; - Attr *New = nullptr; - // Kind is stored as a 1-based integer because 0 is used to indicate a null - // Attr pointer. - auto Kind = static_cast<attr::Kind>(V - 1); - ASTContext &Context = getContext(); - - IdentifierInfo *AttrName = Record.readIdentifier(); - IdentifierInfo *ScopeName = Record.readIdentifier(); - SourceRange AttrRange = Record.readSourceRange(); - SourceLocation ScopeLoc = Record.readSourceLocation(); - unsigned ParsedKind = Record.readInt(); - unsigned Syntax = Record.readInt(); - unsigned SpellingIndex = Record.readInt(); - bool IsAlignas = (ParsedKind == AttributeCommonInfo::AT_Aligned && - Syntax == AttributeCommonInfo::AS_Keyword && - SpellingIndex == AlignedAttr::Keyword_alignas); - bool IsRegularKeywordAttribute = Record.readBool(); - - AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc, - AttributeCommonInfo::Kind(ParsedKind), - {AttributeCommonInfo::Syntax(Syntax), SpellingIndex, - IsAlignas, IsRegularKeywordAttribute}); + AttributeCommonInfo Info = Record.readAttributeCommonInfo(); + return Record.createAttribute(Kind, Info); +} -#include "clang/Serialization/AttrPCHRead.inc" +Attr *ASTRecordReader::readAttr(Decl *D) { + AttrReader Record(*this); + attr::Kind Kind; + if (auto KindOpt = Record.readAttrKind(); !KindOpt) + return nullptr; + else + Kind = *KindOpt; + + AttributeCommonInfo Info = Record.readAttributeCommonInfo(); + if (Kind == attr::PreferredName) { + bool isInherited = Record.readInt(); + bool isImplicit = Record.readInt(); + bool isPackExpansion = Record.readInt(); + serialization::TypeID TypeID = getGlobalTypeID(Record.readInt()); + SourceLocation ElaboratedTypedefSL = Record.readSourceLocation(); ---------------- VitaNuo wrote:
Thank you for the suggestion, the draft implementation is in https://github.com/llvm/llvm-project/pull/122726. https://github.com/llvm/llvm-project/pull/122250 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits