From: Douglas Gregor Date: Mon, 13 Apr 2009 22:49:25 +0000 (+0000) Subject: Partial PCH support for FileScopeAsmDecl and BlockDecl. Both require X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1028bc67d56ea088c3a57c4c44c3f6aeff60a031;p=clang Partial PCH support for FileScopeAsmDecl and BlockDecl. Both require expression or statement serialization before we can test them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69002 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index dffc0ad6e4..83de947088 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1206,6 +1206,8 @@ public: const StringLiteral *getAsmString() const { return AsmString; } StringLiteral *getAsmString() { return AsmString; } + void setAsmString(StringLiteral *Asm) { AsmString = Asm; } + static bool classof(const Decl *D) { return D->getKind() == FileScopeAsm; } diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index e1303056f8..95916c0dae 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -330,6 +330,10 @@ namespace clang { DECL_PARM_VAR, /// \brief An OriginalParmVarDecl record. DECL_ORIGINAL_PARM_VAR, + /// \brief A FileScopeAsmDecl record. + DECL_FILE_SCOPE_ASM, + /// \brief A BlockDecl record. + DECL_BLOCK, /// \brief A record that stores the set of declarations that are /// lexically stored within a given DeclContext. /// diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index a5e29dcdcd..328ed841ce 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -58,7 +58,8 @@ namespace { void VisitVarDecl(VarDecl *VD); void VisitParmVarDecl(ParmVarDecl *PD); void VisitOriginalParmVarDecl(OriginalParmVarDecl *PD); - + void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); + void VisitBlockDecl(BlockDecl *BD); std::pair VisitDeclContext(DeclContext *DC); }; } @@ -177,6 +178,21 @@ void PCHDeclReader::VisitOriginalParmVarDecl(OriginalParmVarDecl *PD) { PD->setOriginalType(Reader.GetType(Record[Idx++])); } +void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { + VisitDecl(AD); + // FIXME: read asm string +} + +void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) { + VisitDecl(BD); + unsigned NumParams = Record[Idx++]; + llvm::SmallVector Params; + Params.reserve(NumParams); + for (unsigned I = 0; I != NumParams; ++I) + Params.push_back(cast(Reader.GetDecl(Record[Idx++]))); + BD->setParams(Reader.getContext(), &Params[0], NumParams); +} + std::pair PCHDeclReader::VisitDeclContext(DeclContext *DC) { uint64_t LexicalOffset = Record[Idx++]; @@ -1105,6 +1121,23 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { break; } + case pch::DECL_FILE_SCOPE_ASM: { + FileScopeAsmDecl *Asm = FileScopeAsmDecl::Create(Context, 0, + SourceLocation(), 0); + LoadedDecl(Index, Asm); + Reader.VisitFileScopeAsmDecl(Asm); + D = Asm; + break; + } + + case pch::DECL_BLOCK: { + BlockDecl *Block = BlockDecl::Create(Context, 0, SourceLocation()); + LoadedDecl(Index, Block); + Reader.VisitBlockDecl(Block); + D = Block; + break; + } + default: assert(false && "Cannot de-serialize this kind of declaration"); break; diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 8384177621..738e5c1879 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -262,6 +262,8 @@ namespace { void VisitVarDecl(VarDecl *D); void VisitParmVarDecl(ParmVarDecl *D); void VisitOriginalParmVarDecl(OriginalParmVarDecl *D); + void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); + void VisitBlockDecl(BlockDecl *D); void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, uint64_t VisibleOffset); }; @@ -383,6 +385,22 @@ void PCHDeclWriter::VisitOriginalParmVarDecl(OriginalParmVarDecl *D) { Code = pch::DECL_ORIGINAL_PARM_VAR; } +void PCHDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { + VisitDecl(D); + // FIXME: Emit the string literal + Code = pch::DECL_FILE_SCOPE_ASM; +} + +void PCHDeclWriter::VisitBlockDecl(BlockDecl *D) { + VisitDecl(D); + // FIXME: emit block body + Record.push_back(D->param_size()); + for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); + P != PEnd; ++P) + Writer.AddDeclRef(*P, Record); + Code = pch::DECL_BLOCK; +} + /// \brief Emit the DeclContext part of a declaration context decl. /// /// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL