summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid L. Jones <dlj@google.com>2017-01-24 01:04:30 +0000
committerDavid L. Jones <dlj@google.com>2017-01-24 01:04:30 +0000
commit267b884e81ce1b8d34082c846466298f98e35fc3 (patch)
tree84fcacdf312bb68c7d149d633e55b50561fe2375
parent9a6d49f4516f8707a74ac0256ebe35ebb120ed37 (diff)
downloadbcm5719-llvm-267b884e81ce1b8d34082c846466298f98e35fc3.tar.gz
bcm5719-llvm-267b884e81ce1b8d34082c846466298f98e35fc3.zip
Switch TableGen to emit calls to ASTRecordReader for AttrPCHRead.
Summary: This patch changes TableGen-generated code in AttrPCHRead to call functions on ASTRecordReader, instead of passing separate parameters to ASTReader. This is a follow-up to r290217. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28007 llvm-svn: 292868
-rw-r--r--clang/include/clang/Serialization/ASTReader.h13
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp11
-rw-r--r--clang/utils/TableGen/ClangAttrEmitter.cpp38
3 files changed, 34 insertions, 28 deletions
diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index 93994e2c519..d15bda4bffc 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2098,8 +2098,7 @@ public:
unsigned &Idx);
/// \brief Reads attributes from the current stream position.
- void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
- const RecordData &Record, unsigned &Idx);
+ void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs);
/// \brief Reads a statement.
Stmt *ReadStmt(ModuleFile &F);
@@ -2284,6 +2283,14 @@ public:
/// \brief Reads a sub-expression operand during statement reading.
Expr *readSubExpr() { return Reader->ReadSubExpr(); }
+ /// \brief Reads a declaration with the given local ID in the given module.
+ ///
+ /// \returns The requested declaration, casted to the given return type.
+ template<typename T>
+ T *GetLocalDeclAs(uint32_t LocalID) {
+ return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID));
+ }
+
/// \brief Reads a TemplateArgumentLocInfo appropriate for the
/// given TemplateArgument kind, advancing Idx.
TemplateArgumentLocInfo
@@ -2455,7 +2462,7 @@ public:
/// \brief Reads attributes from the current stream position, advancing Idx.
void readAttributes(AttrVec &Attrs) {
- return Reader->ReadAttributes(*F, Attrs, Record, Idx);
+ return Reader->ReadAttributes(*this, Attrs);
}
/// \brief Reads a token out of a record, advancing Idx.
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index c6919193391..4a7e24c007a 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1831,7 +1831,7 @@ void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
SourceLocation *StoredLocs = D->getTrailingObjects<SourceLocation>();
for (unsigned I = 0, N = Record.back(); I != N; ++I)
StoredLocs[I] = ReadSourceLocation();
- (void)Record.readInt(); // The number of stored source locations.
+ Record.skipInts(1); // The number of stored source locations.
}
void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
@@ -2471,12 +2471,11 @@ void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
//===----------------------------------------------------------------------===//
/// \brief Reads attributes from the current stream position.
-void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
- const RecordData &Record, unsigned &Idx) {
- for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
+void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) {
+ for (unsigned i = 0, e = Record.readInt(); i != e; ++i) {
Attr *New = nullptr;
- attr::Kind Kind = (attr::Kind)Record[Idx++];
- SourceRange Range = ReadSourceRange(F, Record, Idx);
+ attr::Kind Kind = (attr::Kind)Record.readInt();
+ SourceRange Range = Record.readSourceRange();
#include "clang/Serialization/AttrPCHRead.inc"
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 27ab34c1309..990b860deae 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -90,13 +90,13 @@ GetFlattenedSpellings(const Record &Attr) {
static std::string ReadPCHRecord(StringRef type) {
return StringSwitch<std::string>(type)
- .EndsWith("Decl *", "GetLocalDeclAs<"
- + std::string(type, 0, type.size()-1) + ">(F, Record[Idx++])")
- .Case("TypeSourceInfo *", "GetTypeSourceInfo(F, Record, Idx)")
- .Case("Expr *", "ReadExpr(F)")
- .Case("IdentifierInfo *", "GetIdentifierInfo(F, Record, Idx)")
- .Case("StringRef", "ReadString(Record, Idx)")
- .Default("Record[Idx++]");
+ .EndsWith("Decl *", "Record.GetLocalDeclAs<"
+ + std::string(type, 0, type.size()-1) + ">(Record.readInt())")
+ .Case("TypeSourceInfo *", "Record.getTypeSourceInfo()")
+ .Case("Expr *", "Record.readExpr()")
+ .Case("IdentifierInfo *", "Record.getIdentifierInfo()")
+ .Case("StringRef", "Record.readString()")
+ .Default("Record.readInt()");
}
// Get a type that is suitable for storing an object of the specified type.
@@ -413,7 +413,7 @@ namespace {
void writePCHReadDecls(raw_ostream &OS) const override {
OS << " std::string " << getLowerName()
- << "= ReadString(Record, Idx);\n";
+ << "= Record.readString();\n";
}
void writePCHReadArgs(raw_ostream &OS) const override {
@@ -539,13 +539,13 @@ namespace {
}
void writePCHReadDecls(raw_ostream &OS) const override {
- OS << " bool is" << getLowerName() << "Expr = Record[Idx++];\n";
+ OS << " bool is" << getLowerName() << "Expr = Record.readInt();\n";
OS << " void *" << getLowerName() << "Ptr;\n";
OS << " if (is" << getLowerName() << "Expr)\n";
- OS << " " << getLowerName() << "Ptr = ReadExpr(F);\n";
+ OS << " " << getLowerName() << "Ptr = Record.readExpr();\n";
OS << " else\n";
OS << " " << getLowerName()
- << "Ptr = GetTypeSourceInfo(F, Record, Idx);\n";
+ << "Ptr = Record.getTypeSourceInfo();\n";
}
void writePCHWrite(raw_ostream &OS) const override {
@@ -658,7 +658,7 @@ namespace {
}
void writePCHReadDecls(raw_ostream &OS) const override {
- OS << " unsigned " << getLowerName() << "Size = Record[Idx++];\n";
+ OS << " unsigned " << getLowerName() << "Size = Record.readInt();\n";
OS << " SmallVector<" << getType() << ", 4> "
<< getLowerName() << ";\n";
OS << " " << getLowerName() << ".reserve(" << getLowerName()
@@ -783,7 +783,7 @@ namespace {
void writePCHReadDecls(raw_ostream &OS) const override {
OS << " " << getAttrName() << "Attr::" << type << " " << getLowerName()
<< "(static_cast<" << getAttrName() << "Attr::" << type
- << ">(Record[Idx++]));\n";
+ << ">(Record.readInt()));\n";
}
void writePCHReadArgs(raw_ostream &OS) const override {
@@ -906,14 +906,14 @@ namespace {
}
void writePCHReadDecls(raw_ostream &OS) const override {
- OS << " unsigned " << getLowerName() << "Size = Record[Idx++];\n";
+ OS << " unsigned " << getLowerName() << "Size = Record.readInt();\n";
OS << " SmallVector<" << QualifiedTypeName << ", 4> " << getLowerName()
<< ";\n";
OS << " " << getLowerName() << ".reserve(" << getLowerName()
<< "Size);\n";
OS << " for (unsigned i = " << getLowerName() << "Size; i; --i)\n";
OS << " " << getLowerName() << ".push_back(" << "static_cast<"
- << QualifiedTypeName << ">(Record[Idx++]));\n";
+ << QualifiedTypeName << ">(Record.readInt()));\n";
}
void writePCHWrite(raw_ostream &OS) const override {
@@ -996,7 +996,7 @@ namespace {
void writePCHReadDecls(raw_ostream &OS) const override {
OS << " VersionTuple " << getLowerName()
- << "= ReadVersionTuple(Record, Idx);\n";
+ << "= Record.readVersionTuple();\n";
}
void writePCHReadArgs(raw_ostream &OS) const override {
@@ -2126,9 +2126,9 @@ void EmitClangAttrPCHRead(RecordKeeper &Records, raw_ostream &OS) {
OS << " case attr::" << R.getName() << ": {\n";
if (R.isSubClassOf(InhClass))
- OS << " bool isInherited = Record[Idx++];\n";
- OS << " bool isImplicit = Record[Idx++];\n";
- OS << " unsigned Spelling = Record[Idx++];\n";
+ OS << " bool isInherited = Record.readInt();\n";
+ OS << " bool isImplicit = Record.readInt();\n";
+ OS << " unsigned Spelling = Record.readInt();\n";
ArgRecords = R.getValueAsListOfDefs("Args");
Args.clear();
for (const auto *Arg : ArgRecords) {
OpenPOWER on IntegriCloud