clang API Documentation
00001 //===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements serialization for Declarations. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "clang/Serialization/ASTWriter.h" 00015 #include "ASTCommon.h" 00016 #include "clang/AST/DeclCXX.h" 00017 #include "clang/AST/DeclContextInternals.h" 00018 #include "clang/AST/DeclTemplate.h" 00019 #include "clang/AST/DeclVisitor.h" 00020 #include "clang/AST/Expr.h" 00021 #include "clang/Basic/SourceManager.h" 00022 #include "clang/Serialization/ASTReader.h" 00023 #include "llvm/ADT/Twine.h" 00024 #include "llvm/Bitcode/BitstreamWriter.h" 00025 #include "llvm/Support/ErrorHandling.h" 00026 using namespace clang; 00027 using namespace serialization; 00028 00029 //===----------------------------------------------------------------------===// 00030 // Declaration serialization 00031 //===----------------------------------------------------------------------===// 00032 00033 namespace clang { 00034 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> { 00035 00036 ASTWriter &Writer; 00037 ASTContext &Context; 00038 typedef ASTWriter::RecordData RecordData; 00039 RecordData &Record; 00040 00041 public: 00042 serialization::DeclCode Code; 00043 unsigned AbbrevToUse; 00044 00045 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record) 00046 : Writer(Writer), Context(Context), Record(Record) { 00047 } 00048 00049 void Visit(Decl *D); 00050 00051 void VisitDecl(Decl *D); 00052 void VisitTranslationUnitDecl(TranslationUnitDecl *D); 00053 void VisitNamedDecl(NamedDecl *D); 00054 void VisitLabelDecl(LabelDecl *LD); 00055 void VisitNamespaceDecl(NamespaceDecl *D); 00056 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); 00057 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); 00058 void VisitTypeDecl(TypeDecl *D); 00059 void VisitTypedefNameDecl(TypedefNameDecl *D); 00060 void VisitTypedefDecl(TypedefDecl *D); 00061 void VisitTypeAliasDecl(TypeAliasDecl *D); 00062 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); 00063 void VisitTagDecl(TagDecl *D); 00064 void VisitEnumDecl(EnumDecl *D); 00065 void VisitRecordDecl(RecordDecl *D); 00066 void VisitCXXRecordDecl(CXXRecordDecl *D); 00067 void VisitClassTemplateSpecializationDecl( 00068 ClassTemplateSpecializationDecl *D); 00069 void VisitClassTemplatePartialSpecializationDecl( 00070 ClassTemplatePartialSpecializationDecl *D); 00071 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); 00072 void VisitVarTemplatePartialSpecializationDecl( 00073 VarTemplatePartialSpecializationDecl *D); 00074 void VisitClassScopeFunctionSpecializationDecl( 00075 ClassScopeFunctionSpecializationDecl *D); 00076 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); 00077 void VisitValueDecl(ValueDecl *D); 00078 void VisitEnumConstantDecl(EnumConstantDecl *D); 00079 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); 00080 void VisitDeclaratorDecl(DeclaratorDecl *D); 00081 void VisitFunctionDecl(FunctionDecl *D); 00082 void VisitCXXMethodDecl(CXXMethodDecl *D); 00083 void VisitCXXConstructorDecl(CXXConstructorDecl *D); 00084 void VisitCXXDestructorDecl(CXXDestructorDecl *D); 00085 void VisitCXXConversionDecl(CXXConversionDecl *D); 00086 void VisitFieldDecl(FieldDecl *D); 00087 void VisitMSPropertyDecl(MSPropertyDecl *D); 00088 void VisitIndirectFieldDecl(IndirectFieldDecl *D); 00089 void VisitVarDecl(VarDecl *D); 00090 void VisitImplicitParamDecl(ImplicitParamDecl *D); 00091 void VisitParmVarDecl(ParmVarDecl *D); 00092 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); 00093 void VisitTemplateDecl(TemplateDecl *D); 00094 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); 00095 void VisitClassTemplateDecl(ClassTemplateDecl *D); 00096 void VisitVarTemplateDecl(VarTemplateDecl *D); 00097 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); 00098 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); 00099 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); 00100 void VisitUsingDecl(UsingDecl *D); 00101 void VisitUsingShadowDecl(UsingShadowDecl *D); 00102 void VisitLinkageSpecDecl(LinkageSpecDecl *D); 00103 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); 00104 void VisitImportDecl(ImportDecl *D); 00105 void VisitAccessSpecDecl(AccessSpecDecl *D); 00106 void VisitFriendDecl(FriendDecl *D); 00107 void VisitFriendTemplateDecl(FriendTemplateDecl *D); 00108 void VisitStaticAssertDecl(StaticAssertDecl *D); 00109 void VisitBlockDecl(BlockDecl *D); 00110 void VisitCapturedDecl(CapturedDecl *D); 00111 void VisitEmptyDecl(EmptyDecl *D); 00112 00113 void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, 00114 uint64_t VisibleOffset); 00115 template <typename T> void VisitRedeclarable(Redeclarable<T> *D); 00116 00117 00118 // FIXME: Put in the same order is DeclNodes.td? 00119 void VisitObjCMethodDecl(ObjCMethodDecl *D); 00120 void VisitObjCContainerDecl(ObjCContainerDecl *D); 00121 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); 00122 void VisitObjCIvarDecl(ObjCIvarDecl *D); 00123 void VisitObjCProtocolDecl(ObjCProtocolDecl *D); 00124 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); 00125 void VisitObjCCategoryDecl(ObjCCategoryDecl *D); 00126 void VisitObjCImplDecl(ObjCImplDecl *D); 00127 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); 00128 void VisitObjCImplementationDecl(ObjCImplementationDecl *D); 00129 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); 00130 void VisitObjCPropertyDecl(ObjCPropertyDecl *D); 00131 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); 00132 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); 00133 00134 void AddFunctionDefinition(const FunctionDecl *FD) { 00135 assert(FD->doesThisDeclarationHaveABody()); 00136 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) 00137 Writer.AddCXXCtorInitializers(CD->CtorInitializers, 00138 CD->NumCtorInitializers, Record); 00139 Writer.AddStmt(FD->getBody()); 00140 } 00141 }; 00142 } 00143 00144 void ASTDeclWriter::Visit(Decl *D) { 00145 DeclVisitor<ASTDeclWriter>::Visit(D); 00146 00147 // Source locations require array (variable-length) abbreviations. The 00148 // abbreviation infrastructure requires that arrays are encoded last, so 00149 // we handle it here in the case of those classes derived from DeclaratorDecl 00150 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)){ 00151 Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record); 00152 } 00153 00154 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs 00155 // have been written. We want it last because we will not read it back when 00156 // retrieving it from the AST, we'll just lazily set the offset. 00157 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 00158 Record.push_back(FD->doesThisDeclarationHaveABody()); 00159 if (FD->doesThisDeclarationHaveABody()) 00160 Writer.AddStmt(FD->getBody()); 00161 } 00162 } 00163 00164 void ASTDeclWriter::VisitDecl(Decl *D) { 00165 Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record); 00166 Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record); 00167 Record.push_back(D->isInvalidDecl()); 00168 Record.push_back(D->hasAttrs()); 00169 if (D->hasAttrs()) 00170 Writer.WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(), 00171 D->getAttrs().size()), Record); 00172 Record.push_back(D->isImplicit()); 00173 Record.push_back(D->isUsed(false)); 00174 Record.push_back(D->isReferenced()); 00175 Record.push_back(D->isTopLevelDeclInObjCContainer()); 00176 Record.push_back(D->getAccess()); 00177 Record.push_back(D->isModulePrivate()); 00178 Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation())); 00179 00180 // If this declaration injected a name into a context different from its 00181 // lexical context, and that context is an imported namespace, we need to 00182 // update its visible declarations to include this name. 00183 // 00184 // This happens when we instantiate a class with a friend declaration or a 00185 // function with a local extern declaration, for instance. 00186 if (D->isOutOfLine()) { 00187 auto *DC = D->getDeclContext(); 00188 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) { 00189 if (!NS->isFromASTFile()) 00190 break; 00191 Writer.AddUpdatedDeclContext(NS->getPrimaryContext()); 00192 if (!NS->isInlineNamespace()) 00193 break; 00194 DC = NS->getParent(); 00195 } 00196 } 00197 } 00198 00199 void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { 00200 llvm_unreachable("Translation units aren't directly serialized"); 00201 } 00202 00203 void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) { 00204 VisitDecl(D); 00205 Writer.AddDeclarationName(D->getDeclName(), Record); 00206 if (needsAnonymousDeclarationNumber(D)) 00207 Record.push_back(Writer.getAnonymousDeclarationNumber(D)); 00208 } 00209 00210 void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) { 00211 VisitNamedDecl(D); 00212 Writer.AddSourceLocation(D->getLocStart(), Record); 00213 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); 00214 } 00215 00216 void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) { 00217 VisitRedeclarable(D); 00218 VisitTypeDecl(D); 00219 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); 00220 Record.push_back(D->isModed()); 00221 if (D->isModed()) 00222 Writer.AddTypeRef(D->getUnderlyingType(), Record); 00223 } 00224 00225 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) { 00226 VisitTypedefNameDecl(D); 00227 if (!D->hasAttrs() && 00228 !D->isImplicit() && 00229 D->getFirstDecl() == D->getMostRecentDecl() && 00230 !D->isInvalidDecl() && 00231 !D->isTopLevelDeclInObjCContainer() && 00232 !D->isModulePrivate() && 00233 !needsAnonymousDeclarationNumber(D) && 00234 D->getDeclName().getNameKind() == DeclarationName::Identifier) 00235 AbbrevToUse = Writer.getDeclTypedefAbbrev(); 00236 00237 Code = serialization::DECL_TYPEDEF; 00238 } 00239 00240 void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) { 00241 VisitTypedefNameDecl(D); 00242 Writer.AddDeclRef(D->getDescribedAliasTemplate(), Record); 00243 Code = serialization::DECL_TYPEALIAS; 00244 } 00245 00246 void ASTDeclWriter::VisitTagDecl(TagDecl *D) { 00247 VisitRedeclarable(D); 00248 VisitTypeDecl(D); 00249 Record.push_back(D->getIdentifierNamespace()); 00250 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding 00251 if (!isa<CXXRecordDecl>(D)) 00252 Record.push_back(D->isCompleteDefinition()); 00253 Record.push_back(D->isEmbeddedInDeclarator()); 00254 Record.push_back(D->isFreeStanding()); 00255 Record.push_back(D->isCompleteDefinitionRequired()); 00256 Writer.AddSourceLocation(D->getRBraceLoc(), Record); 00257 00258 if (D->hasExtInfo()) { 00259 Record.push_back(1); 00260 Writer.AddQualifierInfo(*D->getExtInfo(), Record); 00261 } else if (auto *TD = D->getTypedefNameForAnonDecl()) { 00262 Record.push_back(2); 00263 Writer.AddDeclRef(TD, Record); 00264 Writer.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo(), Record); 00265 } else if (auto *DD = D->getDeclaratorForAnonDecl()) { 00266 Record.push_back(3); 00267 Writer.AddDeclRef(DD, Record); 00268 } else { 00269 Record.push_back(0); 00270 } 00271 } 00272 00273 void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) { 00274 VisitTagDecl(D); 00275 Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record); 00276 if (!D->getIntegerTypeSourceInfo()) 00277 Writer.AddTypeRef(D->getIntegerType(), Record); 00278 Writer.AddTypeRef(D->getPromotionType(), Record); 00279 Record.push_back(D->getNumPositiveBits()); 00280 Record.push_back(D->getNumNegativeBits()); 00281 Record.push_back(D->isScoped()); 00282 Record.push_back(D->isScopedUsingClassTag()); 00283 Record.push_back(D->isFixed()); 00284 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) { 00285 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record); 00286 Record.push_back(MemberInfo->getTemplateSpecializationKind()); 00287 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record); 00288 } else { 00289 Writer.AddDeclRef(nullptr, Record); 00290 } 00291 00292 if (!D->hasAttrs() && 00293 !D->isImplicit() && 00294 !D->isUsed(false) && 00295 !D->hasExtInfo() && 00296 !D->getTypedefNameForAnonDecl() && 00297 !D->getDeclaratorForAnonDecl() && 00298 D->getFirstDecl() == D->getMostRecentDecl() && 00299 !D->isInvalidDecl() && 00300 !D->isReferenced() && 00301 !D->isTopLevelDeclInObjCContainer() && 00302 D->getAccess() == AS_none && 00303 !D->isModulePrivate() && 00304 !CXXRecordDecl::classofKind(D->getKind()) && 00305 !D->getIntegerTypeSourceInfo() && 00306 !D->getMemberSpecializationInfo() && 00307 !needsAnonymousDeclarationNumber(D) && 00308 D->getDeclName().getNameKind() == DeclarationName::Identifier) 00309 AbbrevToUse = Writer.getDeclEnumAbbrev(); 00310 00311 Code = serialization::DECL_ENUM; 00312 } 00313 00314 void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) { 00315 VisitTagDecl(D); 00316 Record.push_back(D->hasFlexibleArrayMember()); 00317 Record.push_back(D->isAnonymousStructOrUnion()); 00318 Record.push_back(D->hasObjectMember()); 00319 Record.push_back(D->hasVolatileMember()); 00320 00321 if (!D->hasAttrs() && 00322 !D->isImplicit() && 00323 !D->isUsed(false) && 00324 !D->hasExtInfo() && 00325 !D->getTypedefNameForAnonDecl() && 00326 !D->getDeclaratorForAnonDecl() && 00327 D->getFirstDecl() == D->getMostRecentDecl() && 00328 !D->isInvalidDecl() && 00329 !D->isReferenced() && 00330 !D->isTopLevelDeclInObjCContainer() && 00331 D->getAccess() == AS_none && 00332 !D->isModulePrivate() && 00333 !CXXRecordDecl::classofKind(D->getKind()) && 00334 !needsAnonymousDeclarationNumber(D) && 00335 D->getDeclName().getNameKind() == DeclarationName::Identifier) 00336 AbbrevToUse = Writer.getDeclRecordAbbrev(); 00337 00338 Code = serialization::DECL_RECORD; 00339 } 00340 00341 void ASTDeclWriter::VisitValueDecl(ValueDecl *D) { 00342 VisitNamedDecl(D); 00343 Writer.AddTypeRef(D->getType(), Record); 00344 } 00345 00346 void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) { 00347 VisitValueDecl(D); 00348 Record.push_back(D->getInitExpr()? 1 : 0); 00349 if (D->getInitExpr()) 00350 Writer.AddStmt(D->getInitExpr()); 00351 Writer.AddAPSInt(D->getInitVal(), Record); 00352 00353 Code = serialization::DECL_ENUM_CONSTANT; 00354 } 00355 00356 void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) { 00357 VisitValueDecl(D); 00358 Writer.AddSourceLocation(D->getInnerLocStart(), Record); 00359 Record.push_back(D->hasExtInfo()); 00360 if (D->hasExtInfo()) 00361 Writer.AddQualifierInfo(*D->getExtInfo(), Record); 00362 } 00363 00364 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { 00365 VisitRedeclarable(D); 00366 VisitDeclaratorDecl(D); 00367 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record); 00368 Record.push_back(D->getIdentifierNamespace()); 00369 00370 // FunctionDecl's body is handled last at ASTWriterDecl::Visit, 00371 // after everything else is written. 00372 00373 Record.push_back(D->getStorageClass()); // FIXME: stable encoding 00374 Record.push_back(D->IsInline); 00375 Record.push_back(D->isInlineSpecified()); 00376 Record.push_back(D->isVirtualAsWritten()); 00377 Record.push_back(D->isPure()); 00378 Record.push_back(D->hasInheritedPrototype()); 00379 Record.push_back(D->hasWrittenPrototype()); 00380 Record.push_back(D->isDeletedAsWritten()); 00381 Record.push_back(D->isTrivial()); 00382 Record.push_back(D->isDefaulted()); 00383 Record.push_back(D->isExplicitlyDefaulted()); 00384 Record.push_back(D->hasImplicitReturnZero()); 00385 Record.push_back(D->isConstexpr()); 00386 Record.push_back(D->HasSkippedBody); 00387 Record.push_back(D->isLateTemplateParsed()); 00388 Record.push_back(D->getLinkageInternal()); 00389 Writer.AddSourceLocation(D->getLocEnd(), Record); 00390 00391 Record.push_back(D->getTemplatedKind()); 00392 switch (D->getTemplatedKind()) { 00393 case FunctionDecl::TK_NonTemplate: 00394 break; 00395 case FunctionDecl::TK_FunctionTemplate: 00396 Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record); 00397 break; 00398 case FunctionDecl::TK_MemberSpecialization: { 00399 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo(); 00400 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record); 00401 Record.push_back(MemberInfo->getTemplateSpecializationKind()); 00402 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record); 00403 break; 00404 } 00405 case FunctionDecl::TK_FunctionTemplateSpecialization: { 00406 FunctionTemplateSpecializationInfo * 00407 FTSInfo = D->getTemplateSpecializationInfo(); 00408 Writer.AddDeclRef(FTSInfo->getTemplate(), Record); 00409 Record.push_back(FTSInfo->getTemplateSpecializationKind()); 00410 00411 // Template arguments. 00412 Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record); 00413 00414 // Template args as written. 00415 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr); 00416 if (FTSInfo->TemplateArgumentsAsWritten) { 00417 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs); 00418 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs; 00419 i!=e; ++i) 00420 Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i], 00421 Record); 00422 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc, 00423 Record); 00424 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc, 00425 Record); 00426 } 00427 00428 Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record); 00429 00430 if (D->isCanonicalDecl()) { 00431 // Write the template that contains the specializations set. We will 00432 // add a FunctionTemplateSpecializationInfo to it when reading. 00433 Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record); 00434 } 00435 break; 00436 } 00437 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { 00438 DependentFunctionTemplateSpecializationInfo * 00439 DFTSInfo = D->getDependentSpecializationInfo(); 00440 00441 // Templates. 00442 Record.push_back(DFTSInfo->getNumTemplates()); 00443 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i) 00444 Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record); 00445 00446 // Templates args. 00447 Record.push_back(DFTSInfo->getNumTemplateArgs()); 00448 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i) 00449 Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record); 00450 Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record); 00451 Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record); 00452 break; 00453 } 00454 } 00455 00456 Record.push_back(D->param_size()); 00457 for (auto P : D->params()) 00458 Writer.AddDeclRef(P, Record); 00459 Code = serialization::DECL_FUNCTION; 00460 } 00461 00462 void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { 00463 VisitNamedDecl(D); 00464 // FIXME: convert to LazyStmtPtr? 00465 // Unlike C/C++, method bodies will never be in header files. 00466 bool HasBodyStuff = D->getBody() != nullptr || 00467 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr; 00468 Record.push_back(HasBodyStuff); 00469 if (HasBodyStuff) { 00470 Writer.AddStmt(D->getBody()); 00471 Writer.AddDeclRef(D->getSelfDecl(), Record); 00472 Writer.AddDeclRef(D->getCmdDecl(), Record); 00473 } 00474 Record.push_back(D->isInstanceMethod()); 00475 Record.push_back(D->isVariadic()); 00476 Record.push_back(D->isPropertyAccessor()); 00477 Record.push_back(D->isDefined()); 00478 Record.push_back(D->IsOverriding); 00479 Record.push_back(D->HasSkippedBody); 00480 00481 Record.push_back(D->IsRedeclaration); 00482 Record.push_back(D->HasRedeclaration); 00483 if (D->HasRedeclaration) { 00484 assert(Context.getObjCMethodRedeclaration(D)); 00485 Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record); 00486 } 00487 00488 // FIXME: stable encoding for @required/@optional 00489 Record.push_back(D->getImplementationControl()); 00490 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway 00491 Record.push_back(D->getObjCDeclQualifier()); 00492 Record.push_back(D->hasRelatedResultType()); 00493 Writer.AddTypeRef(D->getReturnType(), Record); 00494 Writer.AddTypeSourceInfo(D->getReturnTypeSourceInfo(), Record); 00495 Writer.AddSourceLocation(D->getLocEnd(), Record); 00496 Record.push_back(D->param_size()); 00497 for (const auto *P : D->params()) 00498 Writer.AddDeclRef(P, Record); 00499 00500 Record.push_back(D->SelLocsKind); 00501 unsigned NumStoredSelLocs = D->getNumStoredSelLocs(); 00502 SourceLocation *SelLocs = D->getStoredSelLocs(); 00503 Record.push_back(NumStoredSelLocs); 00504 for (unsigned i = 0; i != NumStoredSelLocs; ++i) 00505 Writer.AddSourceLocation(SelLocs[i], Record); 00506 00507 Code = serialization::DECL_OBJC_METHOD; 00508 } 00509 00510 void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) { 00511 VisitNamedDecl(D); 00512 Writer.AddSourceLocation(D->getAtStartLoc(), Record); 00513 Writer.AddSourceRange(D->getAtEndRange(), Record); 00514 // Abstract class (no need to define a stable serialization::DECL code). 00515 } 00516 00517 void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { 00518 VisitRedeclarable(D); 00519 VisitObjCContainerDecl(D); 00520 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record); 00521 00522 Record.push_back(D->isThisDeclarationADefinition()); 00523 if (D->isThisDeclarationADefinition()) { 00524 // Write the DefinitionData 00525 ObjCInterfaceDecl::DefinitionData &Data = D->data(); 00526 00527 Writer.AddDeclRef(D->getSuperClass(), Record); 00528 Writer.AddSourceLocation(D->getSuperClassLoc(), Record); 00529 Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record); 00530 Record.push_back(Data.HasDesignatedInitializers); 00531 00532 // Write out the protocols that are directly referenced by the @interface. 00533 Record.push_back(Data.ReferencedProtocols.size()); 00534 for (const auto *P : D->protocols()) 00535 Writer.AddDeclRef(P, Record); 00536 for (const auto &PL : D->protocol_locs()) 00537 Writer.AddSourceLocation(PL, Record); 00538 00539 // Write out the protocols that are transitively referenced. 00540 Record.push_back(Data.AllReferencedProtocols.size()); 00541 for (ObjCList<ObjCProtocolDecl>::iterator 00542 P = Data.AllReferencedProtocols.begin(), 00543 PEnd = Data.AllReferencedProtocols.end(); 00544 P != PEnd; ++P) 00545 Writer.AddDeclRef(*P, Record); 00546 00547 00548 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) { 00549 // Ensure that we write out the set of categories for this class. 00550 Writer.ObjCClassesWithCategories.insert(D); 00551 00552 // Make sure that the categories get serialized. 00553 for (; Cat; Cat = Cat->getNextClassCategoryRaw()) 00554 (void)Writer.GetDeclRef(Cat); 00555 } 00556 } 00557 00558 Code = serialization::DECL_OBJC_INTERFACE; 00559 } 00560 00561 void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) { 00562 VisitFieldDecl(D); 00563 // FIXME: stable encoding for @public/@private/@protected/@package 00564 Record.push_back(D->getAccessControl()); 00565 Record.push_back(D->getSynthesize()); 00566 00567 if (!D->hasAttrs() && 00568 !D->isImplicit() && 00569 !D->isUsed(false) && 00570 !D->isInvalidDecl() && 00571 !D->isReferenced() && 00572 !D->isModulePrivate() && 00573 !D->getBitWidth() && 00574 !D->hasExtInfo() && 00575 D->getDeclName()) 00576 AbbrevToUse = Writer.getDeclObjCIvarAbbrev(); 00577 00578 Code = serialization::DECL_OBJC_IVAR; 00579 } 00580 00581 void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { 00582 VisitRedeclarable(D); 00583 VisitObjCContainerDecl(D); 00584 00585 Record.push_back(D->isThisDeclarationADefinition()); 00586 if (D->isThisDeclarationADefinition()) { 00587 Record.push_back(D->protocol_size()); 00588 for (const auto *I : D->protocols()) 00589 Writer.AddDeclRef(I, Record); 00590 for (const auto &PL : D->protocol_locs()) 00591 Writer.AddSourceLocation(PL, Record); 00592 } 00593 00594 Code = serialization::DECL_OBJC_PROTOCOL; 00595 } 00596 00597 void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { 00598 VisitFieldDecl(D); 00599 Code = serialization::DECL_OBJC_AT_DEFS_FIELD; 00600 } 00601 00602 void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { 00603 VisitObjCContainerDecl(D); 00604 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record); 00605 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record); 00606 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record); 00607 Writer.AddDeclRef(D->getClassInterface(), Record); 00608 Record.push_back(D->protocol_size()); 00609 for (const auto *I : D->protocols()) 00610 Writer.AddDeclRef(I, Record); 00611 for (const auto &PL : D->protocol_locs()) 00612 Writer.AddSourceLocation(PL, Record); 00613 Code = serialization::DECL_OBJC_CATEGORY; 00614 } 00615 00616 void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { 00617 VisitNamedDecl(D); 00618 Writer.AddDeclRef(D->getClassInterface(), Record); 00619 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS; 00620 } 00621 00622 void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { 00623 VisitNamedDecl(D); 00624 Writer.AddSourceLocation(D->getAtLoc(), Record); 00625 Writer.AddSourceLocation(D->getLParenLoc(), Record); 00626 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record); 00627 // FIXME: stable encoding 00628 Record.push_back((unsigned)D->getPropertyAttributes()); 00629 Record.push_back((unsigned)D->getPropertyAttributesAsWritten()); 00630 // FIXME: stable encoding 00631 Record.push_back((unsigned)D->getPropertyImplementation()); 00632 Writer.AddDeclarationName(D->getGetterName(), Record); 00633 Writer.AddDeclarationName(D->getSetterName(), Record); 00634 Writer.AddDeclRef(D->getGetterMethodDecl(), Record); 00635 Writer.AddDeclRef(D->getSetterMethodDecl(), Record); 00636 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record); 00637 Code = serialization::DECL_OBJC_PROPERTY; 00638 } 00639 00640 void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) { 00641 VisitObjCContainerDecl(D); 00642 Writer.AddDeclRef(D->getClassInterface(), Record); 00643 // Abstract class (no need to define a stable serialization::DECL code). 00644 } 00645 00646 void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { 00647 VisitObjCImplDecl(D); 00648 Writer.AddIdentifierRef(D->getIdentifier(), Record); 00649 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record); 00650 Code = serialization::DECL_OBJC_CATEGORY_IMPL; 00651 } 00652 00653 void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { 00654 VisitObjCImplDecl(D); 00655 Writer.AddDeclRef(D->getSuperClass(), Record); 00656 Writer.AddSourceLocation(D->getSuperClassLoc(), Record); 00657 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record); 00658 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record); 00659 Record.push_back(D->hasNonZeroConstructors()); 00660 Record.push_back(D->hasDestructors()); 00661 Writer.AddCXXCtorInitializers(D->IvarInitializers, D->NumIvarInitializers, 00662 Record); 00663 Code = serialization::DECL_OBJC_IMPLEMENTATION; 00664 } 00665 00666 void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { 00667 VisitDecl(D); 00668 Writer.AddSourceLocation(D->getLocStart(), Record); 00669 Writer.AddDeclRef(D->getPropertyDecl(), Record); 00670 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record); 00671 Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record); 00672 Writer.AddStmt(D->getGetterCXXConstructor()); 00673 Writer.AddStmt(D->getSetterCXXAssignment()); 00674 Code = serialization::DECL_OBJC_PROPERTY_IMPL; 00675 } 00676 00677 void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) { 00678 VisitDeclaratorDecl(D); 00679 Record.push_back(D->isMutable()); 00680 if (D->InitStorage.getInt() == FieldDecl::ISK_BitWidthOrNothing && 00681 D->InitStorage.getPointer() == nullptr) { 00682 Record.push_back(0); 00683 } else if (D->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) { 00684 Record.push_back(D->InitStorage.getInt() + 1); 00685 Writer.AddTypeRef( 00686 QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0), 00687 Record); 00688 } else { 00689 Record.push_back(D->InitStorage.getInt() + 1); 00690 Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer())); 00691 } 00692 if (!D->getDeclName()) 00693 Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record); 00694 00695 if (!D->hasAttrs() && 00696 !D->isImplicit() && 00697 !D->isUsed(false) && 00698 !D->isInvalidDecl() && 00699 !D->isReferenced() && 00700 !D->isTopLevelDeclInObjCContainer() && 00701 !D->isModulePrivate() && 00702 !D->getBitWidth() && 00703 !D->hasInClassInitializer() && 00704 !D->hasExtInfo() && 00705 !ObjCIvarDecl::classofKind(D->getKind()) && 00706 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) && 00707 D->getDeclName()) 00708 AbbrevToUse = Writer.getDeclFieldAbbrev(); 00709 00710 Code = serialization::DECL_FIELD; 00711 } 00712 00713 void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) { 00714 VisitDeclaratorDecl(D); 00715 Writer.AddIdentifierRef(D->getGetterId(), Record); 00716 Writer.AddIdentifierRef(D->getSetterId(), Record); 00717 Code = serialization::DECL_MS_PROPERTY; 00718 } 00719 00720 void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { 00721 VisitValueDecl(D); 00722 Record.push_back(D->getChainingSize()); 00723 00724 for (const auto *P : D->chain()) 00725 Writer.AddDeclRef(P, Record); 00726 Code = serialization::DECL_INDIRECTFIELD; 00727 } 00728 00729 void ASTDeclWriter::VisitVarDecl(VarDecl *D) { 00730 VisitRedeclarable(D); 00731 VisitDeclaratorDecl(D); 00732 Record.push_back(D->getStorageClass()); 00733 Record.push_back(D->getTSCSpec()); 00734 Record.push_back(D->getInitStyle()); 00735 Record.push_back(D->isExceptionVariable()); 00736 Record.push_back(D->isNRVOVariable()); 00737 Record.push_back(D->isCXXForRangeDecl()); 00738 Record.push_back(D->isARCPseudoStrong()); 00739 Record.push_back(D->isConstexpr()); 00740 Record.push_back(D->isInitCapture()); 00741 Record.push_back(D->isPreviousDeclInSameBlockScope()); 00742 Record.push_back(D->getLinkageInternal()); 00743 00744 if (D->getInit()) { 00745 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2)); 00746 Writer.AddStmt(D->getInit()); 00747 } else { 00748 Record.push_back(0); 00749 } 00750 00751 enum { 00752 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization 00753 }; 00754 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) { 00755 Record.push_back(VarTemplate); 00756 Writer.AddDeclRef(TemplD, Record); 00757 } else if (MemberSpecializationInfo *SpecInfo 00758 = D->getMemberSpecializationInfo()) { 00759 Record.push_back(StaticDataMemberSpecialization); 00760 Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record); 00761 Record.push_back(SpecInfo->getTemplateSpecializationKind()); 00762 Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record); 00763 } else { 00764 Record.push_back(VarNotTemplate); 00765 } 00766 00767 if (!D->hasAttrs() && 00768 !D->isImplicit() && 00769 !D->isUsed(false) && 00770 !D->isInvalidDecl() && 00771 !D->isReferenced() && 00772 !D->isTopLevelDeclInObjCContainer() && 00773 D->getAccess() == AS_none && 00774 !D->isModulePrivate() && 00775 !needsAnonymousDeclarationNumber(D) && 00776 D->getDeclName().getNameKind() == DeclarationName::Identifier && 00777 !D->hasExtInfo() && 00778 D->getFirstDecl() == D->getMostRecentDecl() && 00779 D->getInitStyle() == VarDecl::CInit && 00780 D->getInit() == nullptr && 00781 !isa<ParmVarDecl>(D) && 00782 !isa<VarTemplateSpecializationDecl>(D) && 00783 !D->isConstexpr() && 00784 !D->isInitCapture() && 00785 !D->isPreviousDeclInSameBlockScope() && 00786 !D->getMemberSpecializationInfo()) 00787 AbbrevToUse = Writer.getDeclVarAbbrev(); 00788 00789 Code = serialization::DECL_VAR; 00790 } 00791 00792 void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) { 00793 VisitVarDecl(D); 00794 Code = serialization::DECL_IMPLICIT_PARAM; 00795 } 00796 00797 void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { 00798 VisitVarDecl(D); 00799 Record.push_back(D->isObjCMethodParameter()); 00800 Record.push_back(D->getFunctionScopeDepth()); 00801 Record.push_back(D->getFunctionScopeIndex()); 00802 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding 00803 Record.push_back(D->isKNRPromoted()); 00804 Record.push_back(D->hasInheritedDefaultArg()); 00805 Record.push_back(D->hasUninstantiatedDefaultArg()); 00806 if (D->hasUninstantiatedDefaultArg()) 00807 Writer.AddStmt(D->getUninstantiatedDefaultArg()); 00808 Code = serialization::DECL_PARM_VAR; 00809 00810 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl 00811 00812 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here 00813 // we dynamically check for the properties that we optimize for, but don't 00814 // know are true of all PARM_VAR_DECLs. 00815 if (!D->hasAttrs() && 00816 !D->hasExtInfo() && 00817 !D->isImplicit() && 00818 !D->isUsed(false) && 00819 !D->isInvalidDecl() && 00820 !D->isReferenced() && 00821 D->getAccess() == AS_none && 00822 !D->isModulePrivate() && 00823 D->getStorageClass() == 0 && 00824 D->getInitStyle() == VarDecl::CInit && // Can params have anything else? 00825 D->getFunctionScopeDepth() == 0 && 00826 D->getObjCDeclQualifier() == 0 && 00827 !D->isKNRPromoted() && 00828 !D->hasInheritedDefaultArg() && 00829 D->getInit() == nullptr && 00830 !D->hasUninstantiatedDefaultArg()) // No default expr. 00831 AbbrevToUse = Writer.getDeclParmVarAbbrev(); 00832 00833 // Check things we know are true of *every* PARM_VAR_DECL, which is more than 00834 // just us assuming it. 00835 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS"); 00836 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private"); 00837 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var"); 00838 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl"); 00839 assert(!D->isStaticDataMember() && 00840 "PARM_VAR_DECL can't be static data member"); 00841 } 00842 00843 void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { 00844 VisitDecl(D); 00845 Writer.AddStmt(D->getAsmString()); 00846 Writer.AddSourceLocation(D->getRParenLoc(), Record); 00847 Code = serialization::DECL_FILE_SCOPE_ASM; 00848 } 00849 00850 void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) { 00851 VisitDecl(D); 00852 Code = serialization::DECL_EMPTY; 00853 } 00854 00855 void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) { 00856 VisitDecl(D); 00857 Writer.AddStmt(D->getBody()); 00858 Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record); 00859 Record.push_back(D->param_size()); 00860 for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end(); 00861 P != PEnd; ++P) 00862 Writer.AddDeclRef(*P, Record); 00863 Record.push_back(D->isVariadic()); 00864 Record.push_back(D->blockMissingReturnType()); 00865 Record.push_back(D->isConversionFromLambda()); 00866 Record.push_back(D->capturesCXXThis()); 00867 Record.push_back(D->getNumCaptures()); 00868 for (const auto &capture : D->captures()) { 00869 Writer.AddDeclRef(capture.getVariable(), Record); 00870 00871 unsigned flags = 0; 00872 if (capture.isByRef()) flags |= 1; 00873 if (capture.isNested()) flags |= 2; 00874 if (capture.hasCopyExpr()) flags |= 4; 00875 Record.push_back(flags); 00876 00877 if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr()); 00878 } 00879 00880 Code = serialization::DECL_BLOCK; 00881 } 00882 00883 void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) { 00884 Record.push_back(CD->getNumParams()); 00885 VisitDecl(CD); 00886 Record.push_back(CD->getContextParamPosition()); 00887 Record.push_back(CD->isNothrow() ? 1 : 0); 00888 // Body is stored by VisitCapturedStmt. 00889 for (unsigned I = 0; I < CD->getNumParams(); ++I) 00890 Writer.AddDeclRef(CD->getParam(I), Record); 00891 Code = serialization::DECL_CAPTURED; 00892 } 00893 00894 void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { 00895 VisitDecl(D); 00896 Record.push_back(D->getLanguage()); 00897 Writer.AddSourceLocation(D->getExternLoc(), Record); 00898 Writer.AddSourceLocation(D->getRBraceLoc(), Record); 00899 Code = serialization::DECL_LINKAGE_SPEC; 00900 } 00901 00902 void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) { 00903 VisitNamedDecl(D); 00904 Writer.AddSourceLocation(D->getLocStart(), Record); 00905 Code = serialization::DECL_LABEL; 00906 } 00907 00908 00909 void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { 00910 VisitRedeclarable(D); 00911 VisitNamedDecl(D); 00912 Record.push_back(D->isInline()); 00913 Writer.AddSourceLocation(D->getLocStart(), Record); 00914 Writer.AddSourceLocation(D->getRBraceLoc(), Record); 00915 00916 if (D->isOriginalNamespace()) 00917 Writer.AddDeclRef(D->getAnonymousNamespace(), Record); 00918 Code = serialization::DECL_NAMESPACE; 00919 00920 if (Writer.hasChain() && !D->isOriginalNamespace() && 00921 D->getOriginalNamespace()->isFromASTFile()) { 00922 NamespaceDecl *NS = D->getOriginalNamespace(); 00923 Writer.AddUpdatedDeclContext(NS); 00924 00925 // Make sure all visible decls are written. They will be recorded later. 00926 if (StoredDeclsMap *Map = NS->buildLookup()) { 00927 for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); 00928 D != DEnd; ++D) { 00929 DeclContext::lookup_result R = D->second.getLookupResult(); 00930 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; 00931 ++I) 00932 Writer.GetDeclRef(*I); 00933 } 00934 } 00935 } 00936 00937 if (Writer.hasChain() && D->isAnonymousNamespace() && 00938 D == D->getMostRecentDecl()) { 00939 // This is a most recent reopening of the anonymous namespace. If its parent 00940 // is in a previous PCH (or is the TU), mark that parent for update, because 00941 // the original namespace always points to the latest re-opening of its 00942 // anonymous namespace. 00943 Decl *Parent = cast<Decl>( 00944 D->getParent()->getRedeclContext()->getPrimaryContext()); 00945 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) { 00946 Writer.DeclUpdates[Parent].push_back( 00947 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D)); 00948 } 00949 } 00950 } 00951 00952 void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { 00953 VisitRedeclarable(D); 00954 VisitNamedDecl(D); 00955 Writer.AddSourceLocation(D->getNamespaceLoc(), Record); 00956 Writer.AddSourceLocation(D->getTargetNameLoc(), Record); 00957 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record); 00958 Writer.AddDeclRef(D->getNamespace(), Record); 00959 Code = serialization::DECL_NAMESPACE_ALIAS; 00960 } 00961 00962 void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) { 00963 VisitNamedDecl(D); 00964 Writer.AddSourceLocation(D->getUsingLoc(), Record); 00965 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record); 00966 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record); 00967 Writer.AddDeclRef(D->FirstUsingShadow.getPointer(), Record); 00968 Record.push_back(D->hasTypename()); 00969 Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record); 00970 Code = serialization::DECL_USING; 00971 } 00972 00973 void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { 00974 VisitRedeclarable(D); 00975 VisitNamedDecl(D); 00976 Writer.AddDeclRef(D->getTargetDecl(), Record); 00977 Writer.AddDeclRef(D->UsingOrNextShadow, Record); 00978 Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record); 00979 Code = serialization::DECL_USING_SHADOW; 00980 } 00981 00982 void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { 00983 VisitNamedDecl(D); 00984 Writer.AddSourceLocation(D->getUsingLoc(), Record); 00985 Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record); 00986 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record); 00987 Writer.AddDeclRef(D->getNominatedNamespace(), Record); 00988 Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record); 00989 Code = serialization::DECL_USING_DIRECTIVE; 00990 } 00991 00992 void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { 00993 VisitValueDecl(D); 00994 Writer.AddSourceLocation(D->getUsingLoc(), Record); 00995 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record); 00996 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record); 00997 Code = serialization::DECL_UNRESOLVED_USING_VALUE; 00998 } 00999 01000 void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( 01001 UnresolvedUsingTypenameDecl *D) { 01002 VisitTypeDecl(D); 01003 Writer.AddSourceLocation(D->getTypenameLoc(), Record); 01004 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record); 01005 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME; 01006 } 01007 01008 void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { 01009 VisitRecordDecl(D); 01010 01011 enum { 01012 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization 01013 }; 01014 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) { 01015 Record.push_back(CXXRecTemplate); 01016 Writer.AddDeclRef(TemplD, Record); 01017 } else if (MemberSpecializationInfo *MSInfo 01018 = D->getMemberSpecializationInfo()) { 01019 Record.push_back(CXXRecMemberSpecialization); 01020 Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record); 01021 Record.push_back(MSInfo->getTemplateSpecializationKind()); 01022 Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record); 01023 } else { 01024 Record.push_back(CXXRecNotTemplate); 01025 } 01026 01027 Record.push_back(D->isThisDeclarationADefinition()); 01028 if (D->isThisDeclarationADefinition()) 01029 Writer.AddCXXDefinitionData(D, Record); 01030 01031 // Store (what we currently believe to be) the key function to avoid 01032 // deserializing every method so we can compute it. 01033 if (D->IsCompleteDefinition) 01034 Writer.AddDeclRef(Context.getCurrentKeyFunction(D), Record); 01035 01036 Code = serialization::DECL_CXX_RECORD; 01037 } 01038 01039 void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { 01040 VisitFunctionDecl(D); 01041 if (D->isCanonicalDecl()) { 01042 Record.push_back(D->size_overridden_methods()); 01043 for (CXXMethodDecl::method_iterator 01044 I = D->begin_overridden_methods(), E = D->end_overridden_methods(); 01045 I != E; ++I) 01046 Writer.AddDeclRef(*I, Record); 01047 } else { 01048 // We only need to record overridden methods once for the canonical decl. 01049 Record.push_back(0); 01050 } 01051 01052 if (D->getFirstDecl() == D->getMostRecentDecl() && 01053 !D->isInvalidDecl() && 01054 !D->hasAttrs() && 01055 !D->isTopLevelDeclInObjCContainer() && 01056 D->getDeclName().getNameKind() == DeclarationName::Identifier && 01057 !D->hasExtInfo() && 01058 !D->hasInheritedPrototype() && 01059 D->hasWrittenPrototype()) 01060 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(); 01061 01062 Code = serialization::DECL_CXX_METHOD; 01063 } 01064 01065 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { 01066 VisitCXXMethodDecl(D); 01067 01068 Writer.AddDeclRef(D->getInheritedConstructor(), Record); 01069 Record.push_back(D->IsExplicitSpecified); 01070 Writer.AddCXXCtorInitializers(D->CtorInitializers, D->NumCtorInitializers, 01071 Record); 01072 01073 Code = serialization::DECL_CXX_CONSTRUCTOR; 01074 } 01075 01076 void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { 01077 VisitCXXMethodDecl(D); 01078 01079 Writer.AddDeclRef(D->OperatorDelete, Record); 01080 01081 Code = serialization::DECL_CXX_DESTRUCTOR; 01082 } 01083 01084 void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { 01085 VisitCXXMethodDecl(D); 01086 Record.push_back(D->IsExplicitSpecified); 01087 Code = serialization::DECL_CXX_CONVERSION; 01088 } 01089 01090 void ASTDeclWriter::VisitImportDecl(ImportDecl *D) { 01091 VisitDecl(D); 01092 Record.push_back(Writer.getSubmoduleID(D->getImportedModule())); 01093 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs(); 01094 Record.push_back(!IdentifierLocs.empty()); 01095 if (IdentifierLocs.empty()) { 01096 Writer.AddSourceLocation(D->getLocEnd(), Record); 01097 Record.push_back(1); 01098 } else { 01099 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I) 01100 Writer.AddSourceLocation(IdentifierLocs[I], Record); 01101 Record.push_back(IdentifierLocs.size()); 01102 } 01103 // Note: the number of source locations must always be the last element in 01104 // the record. 01105 Code = serialization::DECL_IMPORT; 01106 } 01107 01108 void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) { 01109 VisitDecl(D); 01110 Writer.AddSourceLocation(D->getColonLoc(), Record); 01111 Code = serialization::DECL_ACCESS_SPEC; 01112 } 01113 01114 void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) { 01115 // Record the number of friend type template parameter lists here 01116 // so as to simplify memory allocation during deserialization. 01117 Record.push_back(D->NumTPLists); 01118 VisitDecl(D); 01119 bool hasFriendDecl = D->Friend.is<NamedDecl*>(); 01120 Record.push_back(hasFriendDecl); 01121 if (hasFriendDecl) 01122 Writer.AddDeclRef(D->getFriendDecl(), Record); 01123 else 01124 Writer.AddTypeSourceInfo(D->getFriendType(), Record); 01125 for (unsigned i = 0; i < D->NumTPLists; ++i) 01126 Writer.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i), 01127 Record); 01128 Writer.AddDeclRef(D->getNextFriend(), Record); 01129 Record.push_back(D->UnsupportedFriend); 01130 Writer.AddSourceLocation(D->FriendLoc, Record); 01131 Code = serialization::DECL_FRIEND; 01132 } 01133 01134 void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { 01135 VisitDecl(D); 01136 Record.push_back(D->getNumTemplateParameters()); 01137 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i) 01138 Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record); 01139 Record.push_back(D->getFriendDecl() != nullptr); 01140 if (D->getFriendDecl()) 01141 Writer.AddDeclRef(D->getFriendDecl(), Record); 01142 else 01143 Writer.AddTypeSourceInfo(D->getFriendType(), Record); 01144 Writer.AddSourceLocation(D->getFriendLoc(), Record); 01145 Code = serialization::DECL_FRIEND_TEMPLATE; 01146 } 01147 01148 void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) { 01149 VisitNamedDecl(D); 01150 01151 Writer.AddDeclRef(D->getTemplatedDecl(), Record); 01152 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record); 01153 } 01154 01155 void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { 01156 VisitRedeclarable(D); 01157 01158 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that 01159 // getCommonPtr() can be used while this is still initializing. 01160 if (D->isFirstDecl()) { 01161 // This declaration owns the 'common' pointer, so serialize that data now. 01162 Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record); 01163 if (D->getInstantiatedFromMemberTemplate()) 01164 Record.push_back(D->isMemberSpecialization()); 01165 } 01166 01167 VisitTemplateDecl(D); 01168 Record.push_back(D->getIdentifierNamespace()); 01169 } 01170 01171 void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) { 01172 VisitRedeclarableTemplateDecl(D); 01173 01174 if (D->isFirstDecl()) { 01175 typedef llvm::FoldingSetVector<ClassTemplateSpecializationDecl> CTSDSetTy; 01176 CTSDSetTy &CTSDSet = D->getSpecializations(); 01177 Record.push_back(CTSDSet.size()); 01178 for (CTSDSetTy::iterator I=CTSDSet.begin(), E = CTSDSet.end(); I!=E; ++I) { 01179 assert(I->isCanonicalDecl() && "Expected only canonical decls in set"); 01180 Writer.AddDeclRef(&*I, Record); 01181 } 01182 01183 typedef llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> 01184 CTPSDSetTy; 01185 CTPSDSetTy &CTPSDSet = D->getPartialSpecializations(); 01186 Record.push_back(CTPSDSet.size()); 01187 for (CTPSDSetTy::iterator I=CTPSDSet.begin(), E=CTPSDSet.end(); I!=E; ++I) { 01188 assert(I->isCanonicalDecl() && "Expected only canonical decls in set"); 01189 Writer.AddDeclRef(&*I, Record); 01190 } 01191 } 01192 Code = serialization::DECL_CLASS_TEMPLATE; 01193 } 01194 01195 void ASTDeclWriter::VisitClassTemplateSpecializationDecl( 01196 ClassTemplateSpecializationDecl *D) { 01197 VisitCXXRecordDecl(D); 01198 01199 llvm::PointerUnion<ClassTemplateDecl *, 01200 ClassTemplatePartialSpecializationDecl *> InstFrom 01201 = D->getSpecializedTemplateOrPartial(); 01202 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) { 01203 Writer.AddDeclRef(InstFromD, Record); 01204 } else { 01205 Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(), 01206 Record); 01207 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record); 01208 } 01209 01210 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record); 01211 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record); 01212 Record.push_back(D->getSpecializationKind()); 01213 Record.push_back(D->isCanonicalDecl()); 01214 01215 if (D->isCanonicalDecl()) { 01216 // When reading, we'll add it to the folding set of the following template. 01217 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record); 01218 } 01219 01220 // Explicit info. 01221 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record); 01222 if (D->getTypeAsWritten()) { 01223 Writer.AddSourceLocation(D->getExternLoc(), Record); 01224 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record); 01225 } 01226 01227 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION; 01228 } 01229 01230 void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl( 01231 ClassTemplatePartialSpecializationDecl *D) { 01232 VisitClassTemplateSpecializationDecl(D); 01233 01234 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record); 01235 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record); 01236 01237 // These are read/set from/to the first declaration. 01238 if (D->getPreviousDecl() == nullptr) { 01239 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record); 01240 Record.push_back(D->isMemberSpecialization()); 01241 } 01242 01243 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION; 01244 } 01245 01246 void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) { 01247 VisitRedeclarableTemplateDecl(D); 01248 01249 if (D->isFirstDecl()) { 01250 typedef llvm::FoldingSetVector<VarTemplateSpecializationDecl> VTSDSetTy; 01251 VTSDSetTy &VTSDSet = D->getSpecializations(); 01252 Record.push_back(VTSDSet.size()); 01253 for (VTSDSetTy::iterator I = VTSDSet.begin(), E = VTSDSet.end(); I != E; 01254 ++I) { 01255 assert(I->isCanonicalDecl() && "Expected only canonical decls in set"); 01256 Writer.AddDeclRef(&*I, Record); 01257 } 01258 01259 typedef llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> 01260 VTPSDSetTy; 01261 VTPSDSetTy &VTPSDSet = D->getPartialSpecializations(); 01262 Record.push_back(VTPSDSet.size()); 01263 for (VTPSDSetTy::iterator I = VTPSDSet.begin(), E = VTPSDSet.end(); I != E; 01264 ++I) { 01265 assert(I->isCanonicalDecl() && "Expected only canonical decls in set"); 01266 Writer.AddDeclRef(&*I, Record); 01267 } 01268 } 01269 Code = serialization::DECL_VAR_TEMPLATE; 01270 } 01271 01272 void ASTDeclWriter::VisitVarTemplateSpecializationDecl( 01273 VarTemplateSpecializationDecl *D) { 01274 VisitVarDecl(D); 01275 01276 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> 01277 InstFrom = D->getSpecializedTemplateOrPartial(); 01278 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) { 01279 Writer.AddDeclRef(InstFromD, Record); 01280 } else { 01281 Writer.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>(), 01282 Record); 01283 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record); 01284 } 01285 01286 // Explicit info. 01287 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record); 01288 if (D->getTypeAsWritten()) { 01289 Writer.AddSourceLocation(D->getExternLoc(), Record); 01290 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record); 01291 } 01292 01293 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record); 01294 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record); 01295 Record.push_back(D->getSpecializationKind()); 01296 Record.push_back(D->isCanonicalDecl()); 01297 01298 if (D->isCanonicalDecl()) { 01299 // When reading, we'll add it to the folding set of the following template. 01300 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record); 01301 } 01302 01303 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION; 01304 } 01305 01306 void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl( 01307 VarTemplatePartialSpecializationDecl *D) { 01308 VisitVarTemplateSpecializationDecl(D); 01309 01310 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record); 01311 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record); 01312 01313 // These are read/set from/to the first declaration. 01314 if (D->getPreviousDecl() == nullptr) { 01315 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record); 01316 Record.push_back(D->isMemberSpecialization()); 01317 } 01318 01319 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION; 01320 } 01321 01322 void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl( 01323 ClassScopeFunctionSpecializationDecl *D) { 01324 VisitDecl(D); 01325 Writer.AddDeclRef(D->getSpecialization(), Record); 01326 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION; 01327 } 01328 01329 01330 void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { 01331 VisitRedeclarableTemplateDecl(D); 01332 01333 if (D->isFirstDecl()) { 01334 // This FunctionTemplateDecl owns the CommonPtr; write it. 01335 01336 // Write the function specialization declarations. 01337 Record.push_back(D->getSpecializations().size()); 01338 for (llvm::FoldingSetVector<FunctionTemplateSpecializationInfo>::iterator 01339 I = D->getSpecializations().begin(), 01340 E = D->getSpecializations().end() ; I != E; ++I) { 01341 assert(I->Function->isCanonicalDecl() && 01342 "Expected only canonical decls in set"); 01343 Writer.AddDeclRef(I->Function, Record); 01344 } 01345 } 01346 Code = serialization::DECL_FUNCTION_TEMPLATE; 01347 } 01348 01349 void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { 01350 VisitTypeDecl(D); 01351 01352 Record.push_back(D->wasDeclaredWithTypename()); 01353 Record.push_back(D->defaultArgumentWasInherited()); 01354 Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record); 01355 01356 Code = serialization::DECL_TEMPLATE_TYPE_PARM; 01357 } 01358 01359 void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { 01360 // For an expanded parameter pack, record the number of expansion types here 01361 // so that it's easier for deserialization to allocate the right amount of 01362 // memory. 01363 if (D->isExpandedParameterPack()) 01364 Record.push_back(D->getNumExpansionTypes()); 01365 01366 VisitDeclaratorDecl(D); 01367 // TemplateParmPosition. 01368 Record.push_back(D->getDepth()); 01369 Record.push_back(D->getPosition()); 01370 01371 if (D->isExpandedParameterPack()) { 01372 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { 01373 Writer.AddTypeRef(D->getExpansionType(I), Record); 01374 Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record); 01375 } 01376 01377 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK; 01378 } else { 01379 // Rest of NonTypeTemplateParmDecl. 01380 Record.push_back(D->isParameterPack()); 01381 Record.push_back(D->getDefaultArgument() != nullptr); 01382 if (D->getDefaultArgument()) { 01383 Writer.AddStmt(D->getDefaultArgument()); 01384 Record.push_back(D->defaultArgumentWasInherited()); 01385 } 01386 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM; 01387 } 01388 } 01389 01390 void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { 01391 // For an expanded parameter pack, record the number of expansion types here 01392 // so that it's easier for deserialization to allocate the right amount of 01393 // memory. 01394 if (D->isExpandedParameterPack()) 01395 Record.push_back(D->getNumExpansionTemplateParameters()); 01396 01397 VisitTemplateDecl(D); 01398 // TemplateParmPosition. 01399 Record.push_back(D->getDepth()); 01400 Record.push_back(D->getPosition()); 01401 01402 if (D->isExpandedParameterPack()) { 01403 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); 01404 I != N; ++I) 01405 Writer.AddTemplateParameterList(D->getExpansionTemplateParameters(I), 01406 Record); 01407 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK; 01408 } else { 01409 // Rest of TemplateTemplateParmDecl. 01410 Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record); 01411 Record.push_back(D->defaultArgumentWasInherited()); 01412 Record.push_back(D->isParameterPack()); 01413 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM; 01414 } 01415 } 01416 01417 void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { 01418 VisitRedeclarableTemplateDecl(D); 01419 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE; 01420 } 01421 01422 void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) { 01423 VisitDecl(D); 01424 Writer.AddStmt(D->getAssertExpr()); 01425 Record.push_back(D->isFailed()); 01426 Writer.AddStmt(D->getMessage()); 01427 Writer.AddSourceLocation(D->getRParenLoc(), Record); 01428 Code = serialization::DECL_STATIC_ASSERT; 01429 } 01430 01431 /// \brief Emit the DeclContext part of a declaration context decl. 01432 /// 01433 /// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL 01434 /// block for this declaration context is stored. May be 0 to indicate 01435 /// that there are no declarations stored within this context. 01436 /// 01437 /// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE 01438 /// block for this declaration context is stored. May be 0 to indicate 01439 /// that there are no declarations visible from this context. Note 01440 /// that this value will not be emitted for non-primary declaration 01441 /// contexts. 01442 void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, 01443 uint64_t VisibleOffset) { 01444 Record.push_back(LexicalOffset); 01445 Record.push_back(VisibleOffset); 01446 } 01447 01448 template <typename T> 01449 void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) { 01450 T *First = D->getFirstDecl(); 01451 if (First->getMostRecentDecl() != First) { 01452 assert(isRedeclarableDeclKind(static_cast<T *>(D)->getKind()) && 01453 "Not considered redeclarable?"); 01454 01455 // There is more than one declaration of this entity, so we will need to 01456 // write a redeclaration chain. 01457 Writer.AddDeclRef(First, Record); 01458 Writer.Redeclarations.insert(First); 01459 01460 // Make sure that we serialize both the previous and the most-recent 01461 // declarations, which (transitively) ensures that all declarations in the 01462 // chain get serialized. 01463 (void)Writer.GetDeclRef(D->getPreviousDecl()); 01464 (void)Writer.GetDeclRef(First->getMostRecentDecl()); 01465 } else { 01466 // We use the sentinel value 0 to indicate an only declaration. 01467 Record.push_back(0); 01468 } 01469 01470 } 01471 01472 void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { 01473 Record.push_back(D->varlist_size()); 01474 VisitDecl(D); 01475 for (auto *I : D->varlists()) 01476 Writer.AddStmt(I); 01477 Code = serialization::DECL_OMP_THREADPRIVATE; 01478 } 01479 01480 //===----------------------------------------------------------------------===// 01481 // ASTWriter Implementation 01482 //===----------------------------------------------------------------------===// 01483 01484 void ASTWriter::WriteDeclAbbrevs() { 01485 using namespace llvm; 01486 01487 BitCodeAbbrev *Abv; 01488 01489 // Abbreviation for DECL_FIELD 01490 Abv = new BitCodeAbbrev(); 01491 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD)); 01492 // Decl 01493 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01494 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01495 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 01496 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01497 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 01498 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 01499 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 01500 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 01501 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier 01502 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 01503 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01504 // NamedDecl 01505 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 01506 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 01507 // ValueDecl 01508 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01509 // DeclaratorDecl 01510 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 01511 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 01512 // FieldDecl 01513 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable 01514 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth 01515 // Type Source Info 01516 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); 01517 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 01518 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 01519 DeclFieldAbbrev = Stream.EmitAbbrev(Abv); 01520 01521 // Abbreviation for DECL_OBJC_IVAR 01522 Abv = new BitCodeAbbrev(); 01523 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR)); 01524 // Decl 01525 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01526 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01527 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 01528 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01529 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 01530 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 01531 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 01532 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 01533 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier 01534 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 01535 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01536 // NamedDecl 01537 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 01538 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 01539 // ValueDecl 01540 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01541 // DeclaratorDecl 01542 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 01543 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 01544 // FieldDecl 01545 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable 01546 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth 01547 // ObjC Ivar 01548 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl 01549 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize 01550 // Type Source Info 01551 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); 01552 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 01553 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 01554 DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv); 01555 01556 // Abbreviation for DECL_ENUM 01557 Abv = new BitCodeAbbrev(); 01558 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM)); 01559 // Redeclarable 01560 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 01561 // Decl 01562 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01563 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01564 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 01565 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01566 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 01567 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 01568 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 01569 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 01570 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 01571 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 01572 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01573 // NamedDecl 01574 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 01575 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 01576 // TypeDecl 01577 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location 01578 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref 01579 // TagDecl 01580 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace 01581 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind 01582 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition 01583 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator 01584 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding 01585 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired 01586 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation 01587 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind 01588 // EnumDecl 01589 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef 01590 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType 01591 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType 01592 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits 01593 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits 01594 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped 01595 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag 01596 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed 01597 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum 01598 // DC 01599 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset 01600 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset 01601 DeclEnumAbbrev = Stream.EmitAbbrev(Abv); 01602 01603 // Abbreviation for DECL_RECORD 01604 Abv = new BitCodeAbbrev(); 01605 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD)); 01606 // Redeclarable 01607 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 01608 // Decl 01609 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01610 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01611 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 01612 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01613 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 01614 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 01615 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 01616 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 01617 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 01618 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 01619 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01620 // NamedDecl 01621 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 01622 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 01623 // TypeDecl 01624 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location 01625 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref 01626 // TagDecl 01627 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace 01628 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind 01629 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition 01630 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator 01631 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding 01632 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired 01633 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation 01634 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind 01635 // RecordDecl 01636 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember 01637 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion 01638 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember 01639 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember 01640 // DC 01641 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset 01642 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset 01643 DeclRecordAbbrev = Stream.EmitAbbrev(Abv); 01644 01645 // Abbreviation for DECL_PARM_VAR 01646 Abv = new BitCodeAbbrev(); 01647 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR)); 01648 // Redeclarable 01649 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 01650 // Decl 01651 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01652 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01653 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 01654 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01655 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 01656 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 01657 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 01658 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 01659 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 01660 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 01661 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01662 // NamedDecl 01663 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 01664 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 01665 // ValueDecl 01666 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01667 // DeclaratorDecl 01668 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 01669 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 01670 // VarDecl 01671 Abv->Add(BitCodeAbbrevOp(0)); // StorageClass 01672 Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec 01673 Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer 01674 Abv->Add(BitCodeAbbrevOp(0)); // isExceptionVariable 01675 Abv->Add(BitCodeAbbrevOp(0)); // isNRVOVariable 01676 Abv->Add(BitCodeAbbrevOp(0)); // isCXXForRangeDecl 01677 Abv->Add(BitCodeAbbrevOp(0)); // isARCPseudoStrong 01678 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr 01679 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture 01680 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope 01681 Abv->Add(BitCodeAbbrevOp(0)); // Linkage 01682 Abv->Add(BitCodeAbbrevOp(0)); // HasInit 01683 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo 01684 // ParmVarDecl 01685 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter 01686 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth 01687 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex 01688 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier 01689 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted 01690 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg 01691 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg 01692 // Type Source Info 01693 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); 01694 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 01695 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 01696 DeclParmVarAbbrev = Stream.EmitAbbrev(Abv); 01697 01698 // Abbreviation for DECL_TYPEDEF 01699 Abv = new BitCodeAbbrev(); 01700 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF)); 01701 // Redeclarable 01702 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 01703 // Decl 01704 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01705 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01706 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 01707 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01708 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 01709 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed 01710 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced 01711 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 01712 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier 01713 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 01714 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01715 // NamedDecl 01716 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 01717 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 01718 // TypeDecl 01719 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location 01720 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref 01721 // TypedefDecl 01722 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 01723 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 01724 DeclTypedefAbbrev = Stream.EmitAbbrev(Abv); 01725 01726 // Abbreviation for DECL_VAR 01727 Abv = new BitCodeAbbrev(); 01728 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR)); 01729 // Redeclarable 01730 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration 01731 // Decl 01732 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01733 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01734 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl 01735 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01736 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit 01737 Abv->Add(BitCodeAbbrevOp(0)); // isUsed 01738 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced 01739 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer 01740 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier 01741 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate 01742 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01743 // NamedDecl 01744 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier 01745 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name 01746 // ValueDecl 01747 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01748 // DeclaratorDecl 01749 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc 01750 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo 01751 // VarDecl 01752 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass 01753 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec 01754 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer 01755 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable 01756 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable 01757 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl 01758 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong 01759 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr 01760 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture 01761 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope 01762 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage 01763 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit 01764 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo 01765 // Type Source Info 01766 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); 01767 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 01768 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc 01769 DeclVarAbbrev = Stream.EmitAbbrev(Abv); 01770 01771 // Abbreviation for DECL_CXX_METHOD 01772 Abv = new BitCodeAbbrev(); 01773 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD)); 01774 // RedeclarableDecl 01775 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl 01776 // Decl 01777 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext 01778 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext 01779 Abv->Add(BitCodeAbbrevOp(0)); // Invalid 01780 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs 01781 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit 01782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used 01783 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced 01784 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer 01785 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access 01786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate 01787 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID 01788 // NamedDecl 01789 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind 01790 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier 01791 // ValueDecl 01792 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01793 // DeclaratorDecl 01794 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart 01795 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo 01796 // FunctionDecl 01797 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS 01798 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass 01799 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline 01800 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified 01801 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten 01802 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure 01803 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto 01804 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto 01805 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // DeletedAsWritten 01806 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial 01807 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted 01808 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted 01809 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero 01810 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr 01811 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody 01812 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed 01813 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage 01814 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd 01815 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind 01816 // This Array slurps the rest of the record. Fortunately we want to encode 01817 // (nearly) all the remaining (variable number of) fields in the same way. 01818 // 01819 // This is the function template information if any, then 01820 // NumParams and Params[] from FunctionDecl, and 01821 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl. 01822 // 01823 // Add an AbbrevOp for 'size then elements' and use it here. 01824 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); 01825 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); 01826 DeclCXXMethodAbbrev = Stream.EmitAbbrev(Abv); 01827 01828 // Abbreviation for EXPR_DECL_REF 01829 Abv = new BitCodeAbbrev(); 01830 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF)); 01831 //Stmt 01832 //Expr 01833 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01834 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 01835 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 01836 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 01837 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 01838 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 01839 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 01840 //DeclRefExpr 01841 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier 01842 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound 01843 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs 01844 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates 01845 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //RefersToEnclosingLocal 01846 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef 01847 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location 01848 DeclRefExprAbbrev = Stream.EmitAbbrev(Abv); 01849 01850 // Abbreviation for EXPR_INTEGER_LITERAL 01851 Abv = new BitCodeAbbrev(); 01852 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL)); 01853 //Stmt 01854 //Expr 01855 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01856 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 01857 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 01858 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 01859 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 01860 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 01861 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 01862 //Integer Literal 01863 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location 01864 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width 01865 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value 01866 IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv); 01867 01868 // Abbreviation for EXPR_CHARACTER_LITERAL 01869 Abv = new BitCodeAbbrev(); 01870 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL)); 01871 //Stmt 01872 //Expr 01873 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01874 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 01875 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 01876 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 01877 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 01878 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 01879 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 01880 //Character Literal 01881 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue 01882 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location 01883 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getKind 01884 CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv); 01885 01886 // Abbreviation for EXPR_IMPLICIT_CAST 01887 Abv = new BitCodeAbbrev(); 01888 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST)); 01889 // Stmt 01890 // Expr 01891 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type 01892 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent 01893 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent 01894 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent 01895 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack 01896 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind 01897 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind 01898 // CastExpr 01899 Abv->Add(BitCodeAbbrevOp(0)); // PathSize 01900 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind 01901 // ImplicitCastExpr 01902 ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abv); 01903 01904 Abv = new BitCodeAbbrev(); 01905 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL)); 01906 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 01907 DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv); 01908 01909 Abv = new BitCodeAbbrev(); 01910 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE)); 01911 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); 01912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); 01913 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv); 01914 } 01915 01916 /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by 01917 /// consumers of the AST. 01918 /// 01919 /// Such decls will always be deserialized from the AST file, so we would like 01920 /// this to be as restrictive as possible. Currently the predicate is driven by 01921 /// code generation requirements, if other clients have a different notion of 01922 /// what is "required" then we may have to consider an alternate scheme where 01923 /// clients can iterate over the top-level decls and get information on them, 01924 /// without necessary deserializing them. We could explicitly require such 01925 /// clients to use a separate API call to "realize" the decl. This should be 01926 /// relatively painless since they would presumably only do it for top-level 01927 /// decls. 01928 static bool isRequiredDecl(const Decl *D, ASTContext &Context) { 01929 // An ObjCMethodDecl is never considered as "required" because its 01930 // implementation container always is. 01931 01932 // File scoped assembly or obj-c implementation must be seen. ImportDecl is 01933 // used by codegen to determine the set of imported modules to search for 01934 // inputs for automatic linking. 01935 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D) || isa<ImportDecl>(D)) 01936 return true; 01937 01938 return Context.DeclMustBeEmitted(D); 01939 } 01940 01941 void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { 01942 // Switch case IDs are per Decl. 01943 ClearSwitchCaseIDs(); 01944 01945 RecordData Record; 01946 ASTDeclWriter W(*this, Context, Record); 01947 01948 // Determine the ID for this declaration. 01949 serialization::DeclID ID; 01950 if (D->isFromASTFile()) 01951 ID = getDeclID(D); 01952 else { 01953 serialization::DeclID &IDR = DeclIDs[D]; 01954 if (IDR == 0) 01955 IDR = NextDeclID++; 01956 01957 ID= IDR; 01958 } 01959 01960 bool isReplacingADecl = ID < FirstDeclID; 01961 01962 // If this declaration is also a DeclContext, write blocks for the 01963 // declarations that lexically stored inside its context and those 01964 // declarations that are visible from its context. These blocks 01965 // are written before the declaration itself so that we can put 01966 // their offsets into the record for the declaration. 01967 uint64_t LexicalOffset = 0; 01968 uint64_t VisibleOffset = 0; 01969 DeclContext *DC = dyn_cast<DeclContext>(D); 01970 if (DC) { 01971 if (isReplacingADecl) { 01972 // It is replacing a decl from a chained PCH; make sure that the 01973 // DeclContext is fully loaded. 01974 if (DC->hasExternalLexicalStorage()) 01975 DC->LoadLexicalDeclsFromExternalStorage(); 01976 if (DC->hasExternalVisibleStorage()) 01977 Chain->completeVisibleDeclsMap(DC); 01978 } 01979 LexicalOffset = WriteDeclContextLexicalBlock(Context, DC); 01980 VisibleOffset = WriteDeclContextVisibleBlock(Context, DC); 01981 } 01982 01983 if (isReplacingADecl) { 01984 // We're replacing a decl in a previous file. 01985 ReplacedDecls.push_back(ReplacedDeclInfo(ID, Stream.GetCurrentBitNo(), 01986 D->getLocation())); 01987 } else { 01988 unsigned Index = ID - FirstDeclID; 01989 01990 // Record the offset for this declaration 01991 SourceLocation Loc = D->getLocation(); 01992 if (DeclOffsets.size() == Index) 01993 DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo())); 01994 else if (DeclOffsets.size() < Index) { 01995 DeclOffsets.resize(Index+1); 01996 DeclOffsets[Index].setLocation(Loc); 01997 DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo(); 01998 } 01999 02000 SourceManager &SM = Context.getSourceManager(); 02001 if (Loc.isValid() && SM.isLocalSourceLocation(Loc)) 02002 associateDeclWithFile(D, ID); 02003 } 02004 02005 // Build and emit a record for this declaration 02006 Record.clear(); 02007 W.Code = (serialization::DeclCode)0; 02008 W.AbbrevToUse = 0; 02009 W.Visit(D); 02010 if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset); 02011 02012 if (!W.Code) 02013 llvm::report_fatal_error(StringRef("unexpected declaration kind '") + 02014 D->getDeclKindName() + "'"); 02015 Stream.EmitRecord(W.Code, Record, W.AbbrevToUse); 02016 02017 // Flush any expressions that were written as part of this declaration. 02018 FlushStmts(); 02019 02020 // Flush C++ base specifiers, if there are any. 02021 FlushCXXBaseSpecifiers(); 02022 02023 // Note declarations that should be deserialized eagerly so that we can add 02024 // them to a record in the AST file later. 02025 if (isRequiredDecl(D, Context)) 02026 EagerlyDeserializedDecls.push_back(ID); 02027 } 02028 02029 void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD, 02030 RecordData &Record) { 02031 ClearSwitchCaseIDs(); 02032 02033 ASTDeclWriter W(*this, FD->getASTContext(), Record); 02034 W.AddFunctionDefinition(FD); 02035 }