diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-08-20 21:47:29 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-08-20 21:47:29 +0000 |
commit | 98caebcbd84081b56f459524427596908af127bf (patch) | |
tree | f7659973640746f7b7555fd17d6005b6e8a21adb /lib/Serialization | |
parent | 6eed53ab5d3c252224d1df79d930d6ee04193195 (diff) | |
download | clang-98caebcbd84081b56f459524427596908af127bf.tar.gz |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340215 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 19 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 73 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 33 |
3 files changed, 81 insertions, 44 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index a6f624e326..a9acf4e2f4 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -6455,6 +6455,10 @@ class TypeLocReader : public TypeLocVisitor<TypeLocReader> { return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); } + Attr *ReadAttr() { + return Reader->ReadAttr(*F, Record, Idx); + } + public: TypeLocReader(ModuleFile &F, ASTReader &Reader, const ASTReader::RecordData &Record, unsigned &Idx) @@ -6646,20 +6650,7 @@ void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { } void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { - TL.setAttrNameLoc(ReadSourceLocation()); - if (TL.hasAttrOperand()) { - SourceRange range; - range.setBegin(ReadSourceLocation()); - range.setEnd(ReadSourceLocation()); - TL.setAttrOperandParensRange(range); - } - if (TL.hasAttrExprOperand()) { - if (Record[Idx++]) - TL.setAttrExprOperand(Reader->ReadExpr(*F)); - else - TL.setAttrExprOperand(nullptr); - } else if (TL.hasAttrEnumOperand()) - TL.setAttrEnumOperandLoc(ReadSourceLocation()); + TL.setAttr(ReadAttr()); } void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 47484f8b38..00fad25eea 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -2648,19 +2648,72 @@ void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { // Attribute Reading //===----------------------------------------------------------------------===// -/// Reads attributes from the current stream position. -void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { - for (unsigned i = 0, e = Record.readInt(); i != e; ++i) { - Attr *New = nullptr; - auto Kind = (attr::Kind)Record.readInt(); - SourceRange Range = Record.readSourceRange(); - ASTContext &Context = getContext(); +namespace { +class AttrReader { + ModuleFile *F; + ASTReader *Reader; + const ASTReader::RecordData &Record; + unsigned &Idx; -#include "clang/Serialization/AttrPCHRead.inc" +public: + AttrReader(ModuleFile &F, ASTReader &Reader, + const ASTReader::RecordData &Record, unsigned &Idx) + : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} + + const uint64_t &readInt() { return Record[Idx++]; } + + SourceRange readSourceRange() { + return Reader->ReadSourceRange(*F, Record, Idx); + } + + Expr *readExpr() { return Reader->ReadExpr(*F); } + + std::string readString() { + return Reader->ReadString(Record, Idx); + } + + TypeSourceInfo *getTypeSourceInfo() { + return Reader->GetTypeSourceInfo(*F, Record, Idx); + } + + IdentifierInfo *getIdentifierInfo() { + return Reader->GetIdentifierInfo(*F, Record, Idx); + } - assert(New && "Unable to decode attribute?"); - Attrs.push_back(New); + VersionTuple readVersionTuple() { + return ASTReader::ReadVersionTuple(Record, Idx); } + + template <typename T> T *GetLocalDeclAs(uint32_t LocalID) { + return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID)); + } +}; +} + +Attr *ASTReader::ReadAttr(ModuleFile &M, const RecordData &Rec, + unsigned &Idx) { + AttrReader Record(M, *this, Rec, Idx); + auto V = Record.readInt(); + if (!V) + return nullptr; + + 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); + SourceRange Range = Record.readSourceRange(); + ASTContext &Context = getContext(); + +#include "clang/Serialization/AttrPCHRead.inc" + + assert(New && "Unable to decode attribute?"); + return New; +} + +/// Reads attributes from the current stream position. +void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { + for (unsigned I = 0, E = Record.readInt(); I != E; ++I) + Attrs.push_back(Record.readAttr()); } //===----------------------------------------------------------------------===// diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 99606fcca5..1400c873d4 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -770,19 +770,7 @@ void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { } 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 @@ void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, // 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) { |