Model type attributes as regular Attrs.
Specifically, AttributedType now tracks a regular attr::Kind rather than
having its own parallel Kind enumeration, and AttributedTypeLoc now
holds an Attr* instead of holding an ad-hoc collection of Attr fields.
Differential Revision: https://reviews.llvm.org/D50526
This reinstates r339623, reverted in r339638, with a fix to not fail
template instantiation if we instantiate a QualType with no associated
type source information and we encounter an AttributedType.
llvm-svn: 340215
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 99606fc..1400c87 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -770,19 +770,7 @@
}
void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
- Record.AddSourceLocation(TL.getAttrNameLoc());
- if (TL.hasAttrOperand()) {
- SourceRange range = TL.getAttrOperandParensRange();
- Record.AddSourceLocation(range.getBegin());
- Record.AddSourceLocation(range.getEnd());
- }
- if (TL.hasAttrExprOperand()) {
- Expr *operand = TL.getAttrExprOperand();
- Record.push_back(operand ? 1 : 0);
- if (operand) Record.AddStmt(operand);
- } else if (TL.hasAttrEnumOperand()) {
- Record.AddSourceLocation(TL.getAttrEnumOperandLoc());
- }
+ Record.AddAttr(TL.getAttr());
}
void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
@@ -4481,16 +4469,21 @@
// General Serialization Routines
//===----------------------------------------------------------------------===//
-/// Emit the list of attributes to the specified record.
-void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) {
+void ASTRecordWriter::AddAttr(const Attr *A) {
auto &Record = *this;
- Record.push_back(Attrs.size());
- for (const auto *A : Attrs) {
- Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs
- Record.AddSourceRange(A->getRange());
+ if (!A)
+ return Record.push_back(0);
+ Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs
+ Record.AddSourceRange(A->getRange());
#include "clang/Serialization/AttrPCHWrite.inc"
- }
+}
+
+/// Emit the list of attributes to the specified record.
+void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) {
+ push_back(Attrs.size());
+ for (const auto *A : Attrs)
+ AddAttr(A);
}
void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) {