Revert r339623 "Model type attributes as regular Attrs."

This breaks compiling atlwin.h in Chromium. I'm sure the code is invalid
in some way, but we put a lot of work into accepting it, and I'm sure
rejecting it was not an intended consequence of this refactoring. :)

llvm-svn: 339638
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index a9acf4e..a6f624e 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -6455,10 +6455,6 @@
     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)
@@ -6650,7 +6646,20 @@
 }
 
 void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
-  TL.setAttr(ReadAttr());
+  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());
 }
 
 void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 8e7dc7c..2b8cfac 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2648,72 +2648,19 @@
 // Attribute Reading
 //===----------------------------------------------------------------------===//
 
-namespace {
-class AttrReader {
-  ModuleFile *F;
-  ASTReader *Reader;
-  const ASTReader::RecordData &Record;
-  unsigned &Idx;
-
-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);
-  }
-
-  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();
+/// 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();
 
 #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());
+    assert(New && "Unable to decode attribute?");
+    Attrs.push_back(New);
+  }
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index f2fde2c..ea3a75d 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -770,7 +770,19 @@
 }
 
 void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
-  Record.AddAttr(TL.getAttr());
+  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());
+  }
 }
 
 void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
@@ -4469,21 +4481,16 @@
 // General Serialization Routines
 //===----------------------------------------------------------------------===//
 
-void ASTRecordWriter::AddAttr(const Attr *A) {
-  auto &Record = *this;
-  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);
+  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());
+
+#include "clang/Serialization/AttrPCHWrite.inc"
+  }
 }
 
 void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) {