[cfe-commits] r69320 - /cfe/trunk/lib/Frontend/PCHReader.cpp
Douglas Gregor
dgregor at apple.com
Thu Apr 16 15:29:51 PDT 2009
Author: dgregor
Date: Thu Apr 16 17:29:51 2009
New Revision: 69320
URL: http://llvm.org/viewvc/llvm-project?rev=69320&view=rev
Log:
Clean up the declaration-decoding step in the PCH reader, using the
same ueber-easy visitor scheme used for expressions/statements.
Modified:
cfe/trunk/lib/Frontend/PCHReader.cpp
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69320&r1=69319&r2=69320&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Thu Apr 16 17:29:51 2009
@@ -16,6 +16,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclGroup.h"
+#include "clang/AST/DeclVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/Type.h"
@@ -37,7 +38,8 @@
// Declaration deserialization
//===----------------------------------------------------------------------===//
namespace {
- class VISIBILITY_HIDDEN PCHDeclReader {
+ class VISIBILITY_HIDDEN PCHDeclReader
+ : public DeclVisitor<PCHDeclReader, void> {
PCHReader &Reader;
const PCHReader::RecordData &Record;
unsigned &Idx;
@@ -1479,114 +1481,79 @@
case pch::DECL_TRANSLATION_UNIT:
assert(Index == 0 && "Translation unit must be at index 0");
- Reader.VisitTranslationUnitDecl(Context.getTranslationUnitDecl());
D = Context.getTranslationUnitDecl();
- LoadedDecl(Index, D);
break;
case pch::DECL_TYPEDEF: {
- TypedefDecl *Typedef = TypedefDecl::Create(Context, 0, SourceLocation(),
- 0, QualType());
- LoadedDecl(Index, Typedef);
- Reader.VisitTypedefDecl(Typedef);
- D = Typedef;
+ D = TypedefDecl::Create(Context, 0, SourceLocation(), 0, QualType());
break;
}
case pch::DECL_ENUM: {
- EnumDecl *Enum = EnumDecl::Create(Context, 0, SourceLocation(), 0, 0);
- LoadedDecl(Index, Enum);
- Reader.VisitEnumDecl(Enum);
- D = Enum;
+ D = EnumDecl::Create(Context, 0, SourceLocation(), 0, 0);
break;
}
case pch::DECL_RECORD: {
- RecordDecl *Record = RecordDecl::Create(Context, TagDecl::TK_struct,
- 0, SourceLocation(), 0, 0);
- LoadedDecl(Index, Record);
- Reader.VisitRecordDecl(Record);
- D = Record;
+ D = RecordDecl::Create(Context, TagDecl::TK_struct, 0, SourceLocation(),
+ 0, 0);
break;
}
case pch::DECL_ENUM_CONSTANT: {
- EnumConstantDecl *ECD = EnumConstantDecl::Create(Context, 0,
- SourceLocation(), 0,
- QualType(), 0,
- llvm::APSInt());
- LoadedDecl(Index, ECD);
- Reader.VisitEnumConstantDecl(ECD);
- D = ECD;
+ D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
+ 0, llvm::APSInt());
break;
}
case pch::DECL_FUNCTION: {
- FunctionDecl *Function = FunctionDecl::Create(Context, 0, SourceLocation(),
- DeclarationName(),
- QualType());
- LoadedDecl(Index, Function);
- Reader.VisitFunctionDecl(Function);
- D = Function;
+ D = FunctionDecl::Create(Context, 0, SourceLocation(), DeclarationName(),
+ QualType());
break;
}
case pch::DECL_FIELD: {
- FieldDecl *Field = FieldDecl::Create(Context, 0, SourceLocation(), 0,
- QualType(), 0, false);
- LoadedDecl(Index, Field);
- Reader.VisitFieldDecl(Field);
- D = Field;
+ D = FieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(), 0,
+ false);
break;
}
case pch::DECL_VAR: {
- VarDecl *Var = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
- VarDecl::None, SourceLocation());
- LoadedDecl(Index, Var);
- Reader.VisitVarDecl(Var);
- D = Var;
+ D = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
+ VarDecl::None, SourceLocation());
break;
}
case pch::DECL_PARM_VAR: {
- ParmVarDecl *Parm = ParmVarDecl::Create(Context, 0, SourceLocation(), 0,
- QualType(), VarDecl::None, 0);
- LoadedDecl(Index, Parm);
- Reader.VisitParmVarDecl(Parm);
- D = Parm;
+ D = ParmVarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
+ VarDecl::None, 0);
break;
}
case pch::DECL_ORIGINAL_PARM_VAR: {
- OriginalParmVarDecl *Parm
- = OriginalParmVarDecl::Create(Context, 0, SourceLocation(), 0,
+ D = OriginalParmVarDecl::Create(Context, 0, SourceLocation(), 0,
QualType(), QualType(), VarDecl::None,
0);
- LoadedDecl(Index, Parm);
- Reader.VisitOriginalParmVarDecl(Parm);
- D = Parm;
break;
}
case pch::DECL_FILE_SCOPE_ASM: {
- FileScopeAsmDecl *Asm = FileScopeAsmDecl::Create(Context, 0,
- SourceLocation(), 0);
- LoadedDecl(Index, Asm);
- Reader.VisitFileScopeAsmDecl(Asm);
- D = Asm;
+ D = FileScopeAsmDecl::Create(Context, 0, SourceLocation(), 0);
break;
}
case pch::DECL_BLOCK: {
- BlockDecl *Block = BlockDecl::Create(Context, 0, SourceLocation());
- LoadedDecl(Index, Block);
- Reader.VisitBlockDecl(Block);
- D = Block;
+ D = BlockDecl::Create(Context, 0, SourceLocation());
break;
}
}
+ assert(D && "Unknown declaration creating PCH file");
+ if (D) {
+ LoadedDecl(Index, D);
+ Reader.Visit(D);
+ }
+
// If this declaration is also a declaration context, get the
// offsets for its tables of lexical and visible declarations.
if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
More information about the cfe-commits
mailing list