diff options
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 8 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 354 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 162 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderStmt.cpp | 106 |
4 files changed, 298 insertions, 332 deletions
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index e7019f311d..4d38a666f7 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -233,7 +233,7 @@ private: Preprocessor *PP; /// \brief The AST context into which we'll read the AST files. - ASTContext *Context; + ASTContext &Context; /// \brief The AST consumer. ASTConsumer *Consumer; @@ -752,8 +752,8 @@ public: /// \brief Set the Preprocessor to use. void setPreprocessor(Preprocessor &pp); - /// \brief Sets and initializes the given Context. - void InitializeContext(ASTContext &Context); + /// \brief Initializes the ASTContext + void InitializeContext(); /// \brief Add in-memory (virtual file) buffer. void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) { @@ -1267,7 +1267,7 @@ public: } /// \brief Retrieve the AST context that this AST reader supplements. - ASTContext *getContext() { return Context; } + ASTContext &getContext() { return Context; } // \brief Contains declarations that were loaded before we have // access to a Sema object. diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 55dd213286..f0b06259a7 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -498,7 +498,7 @@ ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { ASTSelectorLookupTrait::internal_key_type ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { using namespace clang::io; - SelectorTable &SelTable = Reader.getContext()->Selectors; + SelectorTable &SelTable = Reader.getContext().Selectors; unsigned N = ReadUnalignedLE16(d); IdentifierInfo *FirstII = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); @@ -632,7 +632,6 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // Read all of the declarations visible at global scope with this // name. - if (Reader.getContext() == 0) return II; if (DataLen > 0) { SmallVector<uint32_t, 4> DeclIDs; for (; DataLen > 0; DataLen -= 4) @@ -706,7 +705,7 @@ ASTDeclContextNameLookupTrait::GetInternalKey( ASTDeclContextNameLookupTrait::external_key_type ASTDeclContextNameLookupTrait::GetExternalKey( const internal_key_type& Key) const { - ASTContext *Context = Reader.getContext(); + ASTContext &Context = Reader.getContext(); switch (Key.Kind) { case DeclarationName::Identifier: return DeclarationName((IdentifierInfo*)Key.Data); @@ -717,23 +716,23 @@ ASTDeclContextNameLookupTrait::GetExternalKey( return DeclarationName(Selector(Key.Data)); case DeclarationName::CXXConstructorName: - return Context->DeclarationNames.getCXXConstructorName( - Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); + return Context.DeclarationNames.getCXXConstructorName( + Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); case DeclarationName::CXXDestructorName: - return Context->DeclarationNames.getCXXDestructorName( - Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); + return Context.DeclarationNames.getCXXDestructorName( + Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); case DeclarationName::CXXConversionFunctionName: - return Context->DeclarationNames.getCXXConversionFunctionName( - Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); + return Context.DeclarationNames.getCXXConversionFunctionName( + Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); case DeclarationName::CXXOperatorName: - return Context->DeclarationNames.getCXXOperatorName( + return Context.DeclarationNames.getCXXOperatorName( (OverloadedOperatorKind)Key.Data); case DeclarationName::CXXLiteralOperatorName: - return Context->DeclarationNames.getCXXLiteralOperatorName( + return Context.DeclarationNames.getCXXLiteralOperatorName( (IdentifierInfo*)Key.Data); case DeclarationName::CXXUsingDirective: @@ -1934,14 +1933,12 @@ ASTReader::ReadASTBlock(Module &F) { } case TU_UPDATE_LEXICAL: { - DeclContext *TU = Context ? Context->getTranslationUnitDecl() : 0; + DeclContext *TU = Context.getTranslationUnitDecl(); DeclContextInfo &Info = F.DeclContextInfos[TU]; Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); Info.NumLexicalDecls = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); - if (TU) - TU->setHasExternalLexicalStorage(true); - + TU->setHasExternalLexicalStorage(true); break; } @@ -1952,8 +1949,8 @@ ASTReader::ReadASTBlock(Module &F) { (const unsigned char *)BlobStart + Record[Idx++], (const unsigned char *)BlobStart, ASTDeclContextNameLookupTrait(*this, F)); - if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID && Context) { // Is it the TU? - DeclContext *TU = Context->getTranslationUnitDecl(); + if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? + DeclContext *TU = Context.getTranslationUnitDecl(); F.DeclContextInfos[TU].NameLookupTableData = Table; TU->setHasExternalVisibleStorage(true); } else @@ -2635,8 +2632,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, } } - if (Context) - InitializeContext(*Context); + InitializeContext(); if (DeserializationListener) DeserializationListener->ReaderInitialized(this); @@ -2797,59 +2793,38 @@ void ASTReader::setPreprocessor(Preprocessor &pp) { PP->getHeaderSearchInfo().SetExternalSource(this); } -void ASTReader::InitializeContext(ASTContext &Ctx) { - Context = &Ctx; - assert(Context && "Passed null context!"); - +void ASTReader::InitializeContext() { assert(PP && "Forgot to set Preprocessor ?"); PP->getIdentifierTable().setExternalIdentifierLookup(this); PP->setExternalSource(this); - // If we have any update blocks for the TU waiting, we have to add - // them before we deserialize anything. - TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl(); - for (ModuleIterator M = ModuleMgr.begin(), MEnd = ModuleMgr.end(); - M != MEnd; ++M) { - Module::DeclContextInfosMap::iterator DCU - = (*M)->DeclContextInfos.find(0); - if (DCU != (*M)->DeclContextInfos.end()) { - // Insertion could invalidate map, so grab value first. - DeclContextInfo Info = DCU->second; - (*M)->DeclContextInfos.erase(DCU); - (*M)->DeclContextInfos[TU] = Info; - - if (Info.NumLexicalDecls) - TU->setHasExternalLexicalStorage(); - if (Info.NameLookupTableData) - TU->setHasExternalVisibleStorage(); - } - } - // If there's a listener, notify them that we "read" the translation unit. if (DeserializationListener) - DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); + DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, + Context.getTranslationUnitDecl()); // Make sure we load the declaration update records for the translation unit, // if there are any. - loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); + loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, + Context.getTranslationUnitDecl()); // FIXME: Find a better way to deal with collisions between these // built-in types. Right now, we just ignore the problem. // Load the special types. - if (Context->getBuiltinVaListType().isNull()) { - Context->setBuiltinVaListType( + if (Context.getBuiltinVaListType().isNull()) { + Context.setBuiltinVaListType( GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); } if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { - if (Context->ObjCProtoType.isNull()) - Context->ObjCProtoType = GetType(Proto); + if (Context.ObjCProtoType.isNull()) + Context.ObjCProtoType = GetType(Proto); } if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { - if (!Context->CFConstantStringTypeDecl) - Context->setCFConstantStringType(GetType(String)); + if (!Context.CFConstantStringTypeDecl) + Context.setCFConstantStringType(GetType(String)); } if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { @@ -2859,16 +2834,16 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { return; } - if (!Context->FILEDecl) { + if (!Context.FILEDecl) { if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) - Context->setFILEDecl(Typedef->getDecl()); + Context.setFILEDecl(Typedef->getDecl()); else { const TagType *Tag = FileType->getAs<TagType>(); if (!Tag) { Error("Invalid FILE type in AST file"); return; } - Context->setFILEDecl(Tag->getDecl()); + Context.setFILEDecl(Tag->getDecl()); } } } @@ -2880,16 +2855,16 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { return; } - if (!Context->jmp_bufDecl) { + if (!Context.jmp_bufDecl) { if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) - Context->setjmp_bufDecl(Typedef->getDecl()); + Context.setjmp_bufDecl(Typedef->getDecl()); else { const TagType *Tag = Jmp_bufType->getAs<TagType>(); if (!Tag) { Error("Invalid jmp_buf type in AST file"); return; } - Context->setjmp_bufDecl(Tag->getDecl()); + Context.setjmp_bufDecl(Tag->getDecl()); } } } @@ -2901,41 +2876,41 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { return; } - if (!Context->sigjmp_bufDecl) { + if (!Context.sigjmp_bufDecl) { if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) - Context->setsigjmp_bufDecl(Typedef->getDecl()); + Context.setsigjmp_bufDecl(Typedef->getDecl()); else { const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); assert(Tag && "Invalid sigjmp_buf type in AST file"); - Context->setsigjmp_bufDecl(Tag->getDecl()); + Context.setsigjmp_bufDecl(Tag->getDecl()); } } } if (unsigned ObjCIdRedef = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { - if (Context->ObjCIdRedefinitionType.isNull()) - Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); + if (Context.ObjCIdRedefinitionType.isNull()) + Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); } if (unsigned ObjCClassRedef = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { - if (Context->ObjCClassRedefinitionType.isNull()) - Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); + if (Context.ObjCClassRedefinitionType.isNull()) + Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); } if (unsigned ObjCSelRedef = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { - if (Context->ObjCSelRedefinitionType.isNull()) - Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); + if (Context.ObjCSelRedefinitionType.isNull()) + Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); } - ReadPragmaDiagnosticMappings(Context->getDiagnostics()); + ReadPragmaDiagnosticMappings(Context.getDiagnostics()); // If there were any CUDA special declarations, deserialize them. if (!CUDASpecialDeclRefs.empty()) { assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); - Context->setcudaConfigureCallDecl( + Context.setcudaConfigureCallDecl( cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); } } @@ -3271,7 +3246,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { } QualType Base = readType(*Loc.F, Record, Idx); Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); - return Context->getQualifiedType(Base, Quals); + return Context.getQualifiedType(Base, Quals); } case TYPE_COMPLEX: { @@ -3280,7 +3255,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { return QualType(); } QualType ElemType = readType(*Loc.F, Record, Idx); - return Context->getComplexType(ElemType); + return Context.getComplexType(ElemType); } case TYPE_POINTER: { @@ -3289,7 +3264,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { return QualType(); } QualType PointeeType = readType(*Loc.F, Record, Idx); - return Context->getPointerType(PointeeType); + return Context.getPointerType(PointeeType); } case TYPE_BLOCK_POINTER: { @@ -3298,7 +3273,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { return QualType(); } QualType PointeeType = readType(*Loc.F, Record, Idx); - return Context->getBlockPointerType(PointeeType); + return Context.getBlockPointerType(PointeeType); } case TYPE_LVALUE_REFERENCE: { @@ -3307,7 +3282,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { return QualType(); } QualType PointeeType = readType(*Loc.F, Record, Idx); - return Context->getLValueReferenceType(PointeeType, Record[1]); + return Context.getLValueReferenceType(PointeeType, Record[1]); } case TYPE_RVALUE_REFERENCE: { @@ -3316,7 +3291,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { return QualType(); } QualType PointeeType = readType(*Loc.F, Record, Idx); - return Context->getRValueReferenceType(PointeeType); + return Context.getRValueReferenceType(PointeeType); } case TYPE_MEMBER_POINTER: { @@ -3329,7 +3304,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { if (PointeeType.isNull() || ClassType.isNull()) return QualType(); - return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); + return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); } case TYPE_CONSTANT_ARRAY: { @@ -3338,7 +3313,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { unsigned IndexTypeQuals = Record[2]; unsigned Idx = 3; llvm::APInt Size = ReadAPInt(Record, Idx); - return Context->getConstantArrayType(ElementType, Size, + return Context.getConstantArrayType(ElementType, Size, ASM, IndexTypeQuals); } @@ -3346,7 +3321,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { QualType ElementType = readType(*Loc.F, Record, Idx); ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; unsigned IndexTypeQuals = Record[2]; - return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); + return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); } case TYPE_VARIABLE_ARRAY: { @@ -3355,7 +3330,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { unsigned IndexTypeQuals = Record[2]; SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); - return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), + return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), ASM, IndexTypeQuals, SourceRange(LBLoc, RBLoc)); } @@ -3369,7 +3344,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { QualType ElementType = readType(*Loc.F, Record, Idx); unsigned NumElements = Record[1]; unsigned VecKind = Record[2]; - return Context->getVectorType(ElementType, NumElements, + return Context.getVectorType(ElementType, NumElements, (VectorType::VectorKind)VecKind); } @@ -3381,7 +3356,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { QualType ElementType = readType(*Loc.F, Record, Idx); unsigned NumElements = Record[1]; - return Context->getExtVectorType(ElementType, NumElements); + return Context.getExtVectorType(ElementType, NumElements); } case TYPE_FUNCTION_NO_PROTO: { @@ -3392,7 +3367,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { QualType ResultType = readType(*Loc.F, Record, Idx); FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], (CallingConv)Record[4], Record[5]); - return Context->getFunctionNoProtoType(ResultType, Info); + return Context.getFunctionNoProtoType(ResultType, Info); } case TYPE_FUNCTION_PROTO: { @@ -3426,13 +3401,13 @@ QualType ASTReader::readTypeRecord(unsigned Index) { } else if (EST == EST_ComputedNoexcept) { EPI.NoexceptExpr = ReadExpr(*Loc.F); } - return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, + return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, EPI); } case TYPE_UNRESOLVED_USING: { unsigned Idx = 0; - return Context->getTypeDeclType( + return Context.getTypeDeclType( ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); } @@ -3445,12 +3420,12 @@ QualType ASTReader::readTypeRecord(unsigned Index) { TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); QualType Canonical = readType(*Loc.F, Record, Idx); if (!Canonical.isNull()) - Canonical = Context->getCanonicalType(Canonical); - return Context->getTypedefType(Decl, Canonical); + Canonical = Context.getCanonicalType(Canonical); + return Context.getTypedefType(Decl, Canonical); } case TYPE_TYPEOF_EXPR: - return Context->getTypeOfExprType(ReadExpr(*Loc.F)); + return Context.getTypeOfExprType(ReadExpr(*Loc.F)); case TYPE_TYPEOF: { if (Record.size() != 1) { @@ -3458,21 +3433,21 @@ QualType ASTReader::readTypeRecord(unsigned Index) { return QualType(); } QualType UnderlyingType = readType(*Loc.F, Record, Idx); - return Context->getTypeOfType(UnderlyingType); + return Context.getTypeOfType(UnderlyingType); } case TYPE_DECLTYPE: - return Context->getDecltypeType(ReadExpr(*Loc.F)); + return Context.getDecltypeType(ReadExpr(*Loc.F)); case TYPE_UNARY_TRANSFORM: { QualType BaseType = readType(*Loc.F, Record, Idx); QualType UnderlyingType = readType(*Loc.F, Record, Idx); UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; - return Context->getUnaryTransformType(BaseType, UnderlyingType, UKind); + return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); } case TYPE_AUTO: - return Context->getAutoType(readType(*Loc.F, Record, Idx)); + return Context.getAutoType(readType(*Loc.F, Record, Idx)); case TYPE_RECORD: { if (Record.size() != 2) { @@ -3482,7 +3457,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { unsigned Idx = 0; bool IsDependent = Record[Idx++]; QualType T - = Context->getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); + = Context.getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); return T; } @@ -3495,7 +3470,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { unsigned Idx = 0; bool IsDependent = Record[Idx++]; QualType T - = Context->getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); + = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); return T; } @@ -3508,7 +3483,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { QualType modifiedType = readType(*Loc.F, Record, Idx); QualType equivalentType = readType(*Loc.F, Record, Idx); AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); - return Context->getAttributedType(kind, modifiedType, equivalentType); + return Context.getAttributedType(kind, modifiedType, equivalentType); } case TYPE_PAREN: { @@ -3517,7 +3492,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { return QualType(); } QualType InnerType = readType(*Loc.F, Record, Idx); - return Context->getParenType(InnerType); + return Context.getParenType(InnerType); } case TYPE_PACK_EXPANSION: { @@ -3531,7 +3506,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { llvm::Optional<unsigned> NumExpansions; if (Record[1]) NumExpansions = Record[1] - 1; - return Context->getPackExpansionType(Pattern, NumExpansions); + return Context.getPackExpansionType(Pattern, NumExpansions); } case TYPE_ELABORATED: { @@ -3539,14 +3514,14 @@ QualType ASTReader::readTypeRecord(unsigned Index) { ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); QualType NamedType = readType(*Loc.F, Record, Idx); - return Context->getElaboratedType(Keyword, NNS, NamedType); + return Context.getElaboratedType(Keyword, NNS, NamedType); } case TYPE_OBJC_INTERFACE: { unsigned Idx = 0; ObjCInterfaceDecl *ItfD = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); - return Context->getObjCInterfaceType(ItfD); + return Context.getObjCInterfaceType(ItfD); } case TYPE_OBJC_OBJECT: { @@ -3556,13 +3531,13 @@ QualType ASTReader::readTypeRecord(unsigned Index) { SmallVector<ObjCProtocolDecl*, 4> Protos; for (unsigned I = 0; I != NumProtos; ++I) Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); - return Context->getObjCObjectType(Base, Protos.data(), NumProtos); + return Context.getObjCObjectType(Base, Protos.data(), NumProtos); } case TYPE_OBJC_OBJECT_POINTER: { unsigned Idx = 0; QualType Pointee = readType(*Loc.F, Record, Idx); - return Context->getObjCObjectPointerType(Pointee); + return Context.getObjCObjectPointerType(Pointee); } case TYPE_SUBST_TEMPLATE_TYPE_PARM: { @@ -3570,7 +3545,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { QualType Parm = readType(*Loc.F, Record, Idx); QualType Replacement = readType(*Loc.F, Record, Idx); return - Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), + Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), Replacement); } @@ -3578,7 +3553,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { unsigned Idx = 0; QualType Parm = readType(*Loc.F, Record, Idx); TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); - return Context->getSubstTemplateTypeParmPackType( + return Context.getSubstTemplateTypeParmPackType( cast<TemplateTypeParmType>(Parm), ArgPack); } @@ -3589,7 +3564,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { // FIXME: ASTContext::getInjectedClassNameType is not currently suitable // for AST reading, too much interdependencies. return - QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); + QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); } case TYPE_TEMPLATE_TYPE_PARM: { @@ -3599,7 +3574,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { bool Pack = Record[Idx++]; TemplateTypeParmDecl *D = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); - return Context->getTemplateTypeParmType(Depth, Index, Pack, D); + return Context.getTemplateTypeParmType(Depth, Index, Pack, D); } case TYPE_DEPENDENT_NAME: { @@ -3609,8 +3584,8 @@ QualType ASTReader::readTypeRecord(unsigned Index) { const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); QualType Canon = readType(*Loc.F, Record, Idx); if (!Canon.isNull()) - Canon = Context->getCanonicalType(Canon); - return Context->getDependentNameType(Keyword, NNS, Name, Canon); + Canon = Context.getCanonicalType(Canon); + return Context.getDependentNameType(Keyword, NNS, Name, Canon); } case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { @@ -3623,7 +3598,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { Args.reserve(NumArgs); while (NumArgs--) Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); - return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, + return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, Args.size(), Args.data()); } @@ -3640,7 +3615,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) { Expr *NumElts = ReadExpr(*Loc.F); SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); - return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, + return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, IndexTypeQuals, Brackets); } @@ -3653,10 +3628,10 @@ QualType ASTReader::readTypeRecord(unsigned Index) { QualType Underlying = readType(*Loc.F, Record, Idx); QualType T; if (Underlying.isNull()) - T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), + T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), Args.size()); else - T = Context->getTemplateSpecializationType(Name, Args.data(), + T = Context.getTemplateSpecializationType(Name, Args.data(), Args.size(), Underlying); const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); return T; @@ -3903,7 +3878,7 @@ TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, if (InfoTy.isNull()) return 0; - TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); + TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); TypeLocReader TLR(*this, F, Record, Idx); for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) TLR.Visit(TL); @@ -3918,45 +3893,45 @@ QualType ASTReader::GetType(TypeID ID) { QualType T; switch ((PredefinedTypeIDs)Index) { case PREDEF_TYPE_NULL_ID: return QualType(); - case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; - case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; + case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; + case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; case PREDEF_TYPE_CHAR_U_ID: case PREDEF_TYPE_CHAR_S_ID: // FIXME: Check that the signedness of CharTy is correct! - T = Context->CharTy; + T = Context.CharTy; break; - case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; - case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; - case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; - case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; - case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; - case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; - case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; - case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; - case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; - case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; - case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; - case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; - case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; - case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; - case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; - case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; - case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; - case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; - case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; - case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; - case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; - case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; - case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; - case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; - case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; - case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; - case PREDEF_TYPE_AUTO_DEDUCT: T = Context->getAutoDeductType(); break; + case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; + case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; + case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; + case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; + case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; + case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; + case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; + case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; + case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; + case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; + case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; + case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; + case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; + case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; + case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; + case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; + case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; + case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; + case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; + case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; + case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; + case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; + case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; + case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; + case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; + case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; + case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; case PREDEF_TYPE_AUTO_RREF_DEDUCT: - T = Context->getAutoRRefDeductType(); + T = Context.getAutoRRefDeductType(); break; } @@ -4077,7 +4052,7 @@ CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { unsigned Idx = 0; unsigned NumBases = Record[Idx++]; - void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); + void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; for (unsigned I = 0; I != NumBases; ++I) Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); @@ -4110,32 +4085,25 @@ Decl *ASTReader::GetDecl(DeclID ID) { return 0; case PREDEF_DECL_TRANSLATION_UNIT_ID: - assert(Context && "No context available?"); - return Context->getTranslationUnitDecl(); + return Context.getTranslationUnitDecl(); case PREDEF_DECL_OBJC_ID_ID: - assert(Context && "No context available?"); - return Context->getObjCIdDecl(); + return Context.getObjCIdDecl(); case PREDEF_DECL_OBJC_SEL_ID: - assert(Context && "No context available?"); - return Context->getObjCSelDecl(); + return Context.getObjCSelDecl(); case PREDEF_DECL_OBJC_CLASS_ID: - assert(Context && "No context available?"); - return Context->getObjCClassDecl(); + return Context.getObjCClassDecl(); case PREDEF_DECL_INT_128_ID: - assert(Context && "No context available?"); - return Context->getInt128Decl(); + return Context.getInt128Decl(); case PREDEF_DECL_UNSIGNED_INT_128_ID: - assert(Context && "No context available?"); - return Context->getUInt128Decl(); + return Context.getUInt128Decl(); case PREDEF_DECL_OBJC_INSTANCETYPE_ID: - assert(Context && "No context available?"); - return Context->getObjCInstanceTypeDecl(); + return Context.getObjCInstanceTypeDecl(); } return 0; @@ -4981,23 +4949,23 @@ ASTReader::ReadDeclarationName(Module &F, return DeclarationName(ReadSelector(F, Record, Idx)); case DeclarationName::CXXConstructorName: - return Context->DeclarationNames.getCXXConstructorName( - Context->getCanonicalType(readType(F, Record, Idx))); + return Context.DeclarationNames.getCXXConstructorName( + Context.getCanonicalType(readType(F, Record, Idx))); case DeclarationName::CXXDestructorName: - return Context->DeclarationNames.getCXXDestructorName( - Context->getCanonicalType(readType(F, Record, Idx))); + return Context.DeclarationNames.getCXXDestructorName( + Context.getCanonicalType(readType(F, Record, Idx))); case DeclarationName::CXXConversionFunctionName: - return Context->DeclarationNames.getCXXConversionFunctionName( - Context->getCanonicalType(readType(F, Record, Idx))); + return Context.DeclarationNames.getCXXConversionFunctionName( + Context.getCanonicalType(readType(F, Record, Idx))); case DeclarationName::CXXOperatorName: - return Context->DeclarationNames.getCXXOperatorName( + return Context.DeclarationNames.getCXXOperatorName( (OverloadedOperatorKind)Record[Idx++]); case DeclarationName::CXXLiteralOperatorName: - return Context->DeclarationNames.getCXXLiteralOperatorName( + return Context.DeclarationNames.getCXXLiteralOperatorName( GetIdentifierInfo(F, Record, Idx)); case DeclarationName::CXXUsingDirective: @@ -5056,7 +5024,7 @@ void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, unsigned NumTPLists = Record[Idx++]; Info.NumTemplParamLists = NumTPLists; if (NumTPLists) { - Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; + Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; for (unsigned i=0; i != NumTPLists; ++i) Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); } @@ -5076,23 +5044,23 @@ ASTReader::ReadTemplateName(Module &F, const RecordData &Record, while (size--) Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); - return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); + return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); } case TemplateName::QualifiedTemplate: { NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); bool hasTemplKeyword = Record[Idx++]; TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); - return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); + return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); } case TemplateName::DependentTemplate: { NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); if (Record[Idx++]) // isIdentifier - return Context->getDependentTemplateName(NNS, + return Context.getDependentTemplateName(NNS, GetIdentifierInfo(F, Record, Idx)); - return Context->getDependentTemplateName(NNS, + return Context.getDependentTemplateName(NNS, (OverloadedOperatorKind)Record[Idx++]); } @@ -5101,7 +5069,7 @@ ASTReader::ReadTemplateName(Module &F, const RecordData &Record, = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); if (!param) return TemplateName(); TemplateName replacement = ReadTemplateName(F, Record, Idx); - return Context->getSubstTemplateTemplateParm(param, replacement); + return Context.getSubstTemplateTemplateParm(param, replacement); } case TemplateName::SubstTemplateTemplateParmPack: { @@ -5114,7 +5082,7 @@ ASTReader::ReadTemplateName(Module &F, const RecordData &Record, if (ArgPack.getKind() != TemplateArgument::Pack) return TemplateName(); - return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); + return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); } } @@ -5151,7 +5119,7 @@ ASTReader::ReadTemplateArgument(Module &F, return TemplateArgument(ReadExpr(F)); case TemplateArgument::Pack: { unsigned NumArgs = Record[Idx++]; - TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; + TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; for (unsigned I = 0; I != NumArgs; ++I) Args[I] = ReadTemplateArgument(F, Record, Idx); return TemplateArgument(Args, NumArgs); @@ -5176,7 +5144,7 @@ ASTReader::ReadTemplateParameterList(Module &F, Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); TemplateParameterList* TemplateParams = - TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, + TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, Params.data(), Params.size(), RAngleLoc); return TemplateParams; } @@ -5225,10 +5193,8 @@ ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, CXXCtorInitializer **CtorInitializers = 0; unsigned NumInitializers = Record[Idx++]; if (NumInitializers) { - ASTContext &C = *getConte |