diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2016-03-02 17:28:48 +0000 |
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2016-03-02 17:28:48 +0000 |
| commit | 6622029d5ee15bfddacbda4825804ee89f8c30e6 (patch) | |
| tree | bb7f94cffd80e3d0572c3f372ef4e68f57ee2ce9 /clang/lib/Serialization | |
| parent | 3ca9ee0c537768b92087f24d2609756ba72cda4f (diff) | |
| download | bcm5719-llvm-6622029d5ee15bfddacbda4825804ee89f8c30e6.tar.gz bcm5719-llvm-6622029d5ee15bfddacbda4825804ee89f8c30e6.zip | |
Serialize `#pragma comment`.
`#pragma comment` was handled by Sema calling a function on ASTConsumer, and
CodeGen then implementing this function and writing things to its output.
Instead, introduce a PragmaCommentDecl AST node and hang one off the
TranslationUnitDecl for every `#pragma comment` line, and then use the regular
serialization machinery. (Since PragmaCommentDecl has codegen relevance, it's
eagerly deserialized.)
http://reviews.llvm.org/D17799
llvm-svn: 262493
Diffstat (limited to 'clang/lib/Serialization')
| -rw-r--r-- | clang/lib/Serialization/ASTCommon.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 18 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTWriterDecl.cpp | 11 |
3 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTCommon.cpp b/clang/lib/Serialization/ASTCommon.cpp index 0b4772a5353..067653dfbf2 100644 --- a/clang/lib/Serialization/ASTCommon.cpp +++ b/clang/lib/Serialization/ASTCommon.cpp @@ -319,6 +319,7 @@ bool serialization::isRedeclarableDeclKind(unsigned Kind) { case Decl::ObjCCompatibleAlias: case Decl::LinkageSpec: case Decl::ObjCPropertyImpl: + case Decl::PragmaComment: case Decl::FileScopeAsm: case Decl::AccessSpec: case Decl::Friend: diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index f484345dfc5..a7eded1a2fd 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -68,6 +68,10 @@ namespace clang { return Reader.ReadDeclID(F, R, I); } + std::string ReadString(const RecordData &R, unsigned &I) { + return Reader.ReadString(R, I); + } + void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) { for (unsigned I = 0, Size = Record[Idx++]; I != Size; ++I) IDs.push_back(ReadDeclID(Record, Idx)); @@ -238,6 +242,7 @@ namespace clang { } void VisitDecl(Decl *D); + void VisitPragmaCommentDecl(PragmaCommentDecl *D); void VisitTranslationUnitDecl(TranslationUnitDecl *TU); void VisitNamedDecl(NamedDecl *ND); void VisitLabelDecl(LabelDecl *LD); @@ -538,6 +543,15 @@ void ASTDeclReader::VisitDecl(Decl *D) { } } +void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { + VisitDecl(D); + D->setLocation(ReadSourceLocation(Record, Idx)); + D->CommentKind = (PragmaMSCommentKind)Record[Idx++]; + std::string Arg = ReadString(Record, Idx); + memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); + D->getTrailingObjects<char>()[Arg.size()] = '\0'; +} + void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { llvm_unreachable("Translation units are not serialized"); } @@ -2418,6 +2432,7 @@ static bool isConsumerInterestedIn(Decl *D, bool HasBody) { isa<ObjCProtocolDecl>(D) || isa<ObjCImplDecl>(D) || isa<ImportDecl>(D) || + isa<PragmaCommentDecl>(D) || isa<OMPThreadPrivateDecl>(D)) return true; if (VarDecl *Var = dyn_cast<VarDecl>(D)) @@ -3335,6 +3350,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { case DECL_OMP_CAPTUREDEXPR: D = OMPCapturedExprDecl::CreateDeserialized(Context, ID); break; + case DECL_PRAGMA_COMMENT: + D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record[Idx++]); + break; case DECL_EMPTY: D = EmptyDecl::CreateDeserialized(Context, ID); break; diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 6ff3f954168..bf36af6bd5a 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -49,6 +49,7 @@ namespace clang { void Visit(Decl *D); void VisitDecl(Decl *D); + void VisitPragmaCommentDecl(PragmaCommentDecl *D); void VisitTranslationUnitDecl(TranslationUnitDecl *D); void VisitNamedDecl(NamedDecl *D); void VisitLabelDecl(LabelDecl *LD); @@ -315,6 +316,16 @@ void ASTDeclWriter::VisitDecl(Decl *D) { } } +void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) { + StringRef Arg = D->getArg(); + Record.push_back(Arg.size()); + VisitDecl(D); + Writer.AddSourceLocation(D->getLocStart(), Record); + Record.push_back(D->getCommentKind()); + Writer.AddString(Arg, Record); + Code = serialization::DECL_PRAGMA_COMMENT; +} + void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { llvm_unreachable("Translation units aren't directly serialized"); } |

