[clang] [WIP] [Modules] Delay reading type source info of the preferred_name attribute. (PR #122250)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 10 04:56:58 PST 2025
================
@@ -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();
----------------
ilya-biryukov wrote:
Instead of doing this, could we have a single function (e.g. `readAttrImpl`) that handles both cases and just asserts `Decl*` is not null whenever it sees the `PreferredName`?
That way, we only have one copy of the code and `readAttributeCommonInfo` is not really needed.
https://github.com/llvm/llvm-project/pull/122250
More information about the cfe-commits
mailing list