namespace {
class ASTDeclContextNameLookupTrait {
ASTReader &Reader;
-
+ ASTReader::PerFileData &F;
+
public:
/// \brief Pair of begin/end iterators for DeclIDs.
typedef std::pair<DeclID *, DeclID *> data_type;
typedef DeclarationName external_key_type;
typedef DeclNameKey internal_key_type;
- explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { }
+ explicit ASTDeclContextNameLookupTrait(ASTReader &Reader,
+ ASTReader::PerFileData &F)
+ : Reader(Reader), F(F) { }
static bool EqualKey(const internal_key_type& a,
const internal_key_type& b) {
case DeclarationName::CXXConstructorName:
return Context->DeclarationNames.getCXXConstructorName(
- Context->getCanonicalType(Reader.GetType(Key.Data)));
+ Context->getCanonicalType(Reader.getLocalType(F, Key.Data)));
case DeclarationName::CXXDestructorName:
return Context->DeclarationNames.getCXXDestructorName(
- Context->getCanonicalType(Reader.GetType(Key.Data)));
+ Context->getCanonicalType(Reader.getLocalType(F, Key.Data)));
case DeclarationName::CXXConversionFunctionName:
return Context->DeclarationNames.getCXXConversionFunctionName(
- Context->getCanonicalType(Reader.GetType(Key.Data)));
+ Context->getCanonicalType(Reader.getLocalType(F, Key.Data)));
case DeclarationName::CXXOperatorName:
return Context->DeclarationNames.getCXXOperatorName(
= ASTDeclContextNameLookupTable::Create(
(const unsigned char *)Blob + Record[0],
(const unsigned char *)Blob,
- ASTDeclContextNameLookupTrait(*this));
+ ASTDeclContextNameLookupTrait(*this, *Info.F));
} else {
Info.NameLookupTableData = 0;
}
void *Table = ASTDeclContextNameLookupTable::Create(
(const unsigned char *)BlobStart + Record[1],
(const unsigned char *)BlobStart,
- ASTDeclContextNameLookupTrait(*this));
+ ASTDeclContextNameLookupTrait(*this, F));
if (ID == 1 && Context) { // Is it the TU?
DeclContextInfo Info = {
&F, Table, /* No lexical inforamtion */ 0, 0
break;
case SPECIAL_TYPES:
- // Optimization for the first block
- if (SpecialTypes.empty())
- SpecialTypes.swap(Record);
- else
- SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end());
+ for (unsigned I = 0, N = Record.size(); I != N; ++I)
+ SpecialTypes.push_back(getGlobalTypeID(F, Record[I]));
break;
case STATISTICS:
/// routine actually reads the record corresponding to the type at the given
/// location. It is a helper routine for GetType, which deals with reading type
/// IDs.
-QualType ASTReader::ReadTypeRecord(unsigned Index) {
+QualType ASTReader::readTypeRecord(unsigned Index) {
RecordLocation Loc = TypeCursorForIndex(Index);
llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
// Note that we are loading a type record.
Deserializing AType(this);
+ unsigned Idx = 0;
DeclsCursor.JumpToBit(Loc.Offset);
RecordData Record;
unsigned Code = DeclsCursor.ReadCode();
Error("Incorrect encoding of extended qualifier type");
return QualType();
}
- QualType Base = GetType(Record[0]);
- Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]);
+ QualType Base = readType(*Loc.F, Record, Idx);
+ Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]);
return Context->getQualifiedType(Base, Quals);
}
Error("Incorrect encoding of complex type");
return QualType();
}
- QualType ElemType = GetType(Record[0]);
+ QualType ElemType = readType(*Loc.F, Record, Idx);
return Context->getComplexType(ElemType);
}
Error("Incorrect encoding of pointer type");
return QualType();
}
- QualType PointeeType = GetType(Record[0]);
+ QualType PointeeType = readType(*Loc.F, Record, Idx);
return Context->getPointerType(PointeeType);
}
Error("Incorrect encoding of block pointer type");
return QualType();
}
- QualType PointeeType = GetType(Record[0]);
+ QualType PointeeType = readType(*Loc.F, Record, Idx);
return Context->getBlockPointerType(PointeeType);
}
Error("Incorrect encoding of lvalue reference type");
return QualType();
}
- QualType PointeeType = GetType(Record[0]);
+ QualType PointeeType = readType(*Loc.F, Record, Idx);
return Context->getLValueReferenceType(PointeeType, Record[1]);
}
Error("Incorrect encoding of rvalue reference type");
return QualType();
}
- QualType PointeeType = GetType(Record[0]);
+ QualType PointeeType = readType(*Loc.F, Record, Idx);
return Context->getRValueReferenceType(PointeeType);
}
Error("Incorrect encoding of member pointer type");
return QualType();
}
- QualType PointeeType = GetType(Record[0]);
- QualType ClassType = GetType(Record[1]);
+ QualType PointeeType = readType(*Loc.F, Record, Idx);
+ QualType ClassType = readType(*Loc.F, Record, Idx);
if (PointeeType.isNull() || ClassType.isNull())
return QualType();
}
case TYPE_CONSTANT_ARRAY: {
- QualType ElementType = GetType(Record[0]);
+ QualType ElementType = readType(*Loc.F, Record, Idx);
ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
unsigned IndexTypeQuals = Record[2];
unsigned Idx = 3;
}
case TYPE_INCOMPLETE_ARRAY: {
- QualType ElementType = GetType(Record[0]);
+ QualType ElementType = readType(*Loc.F, Record, Idx);
ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
unsigned IndexTypeQuals = Record[2];
return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals);
}
case TYPE_VARIABLE_ARRAY: {
- QualType ElementType = GetType(Record[0]);
+ QualType ElementType = readType(*Loc.F, Record, Idx);
ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
unsigned IndexTypeQuals = Record[2];
SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]);
return QualType();
}
- QualType ElementType = GetType(Record[0]);
+ QualType ElementType = readType(*Loc.F, Record, Idx);
unsigned NumElements = Record[1];
unsigned VecKind = Record[2];
return Context->getVectorType(ElementType, NumElements,
return QualType();
}
- QualType ElementType = GetType(Record[0]);
+ QualType ElementType = readType(*Loc.F, Record, Idx);
unsigned NumElements = Record[1];
return Context->getExtVectorType(ElementType, NumElements);
}
Error("incorrect encoding of no-proto function type");
return QualType();
}
- QualType ResultType = GetType(Record[0]);
+ 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);
}
case TYPE_FUNCTION_PROTO: {
- QualType ResultType = GetType(Record[0]);
+ QualType ResultType = readType(*Loc.F, Record, Idx);
FunctionProtoType::ExtProtoInfo EPI;
EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1],
unsigned NumParams = Record[Idx++];
llvm::SmallVector<QualType, 16> ParamTypes;
for (unsigned I = 0; I != NumParams; ++I)
- ParamTypes.push_back(GetType(Record[Idx++]));
+ ParamTypes.push_back(readType(*Loc.F, Record, Idx));
EPI.Variadic = Record[Idx++];
EPI.TypeQuals = Record[Idx++];
EPI.NumExceptions = Record[Idx++];
llvm::SmallVector<QualType, 2> Exceptions;
for (unsigned I = 0; I != EPI.NumExceptions; ++I)
- Exceptions.push_back(GetType(Record[Idx++]));
+ Exceptions.push_back(readType(*Loc.F, Record, Idx));
EPI.Exceptions = Exceptions.data();
} else if (EST == EST_ComputedNoexcept) {
EPI.NoexceptExpr = ReadExpr(*Loc.F);
}
unsigned Idx = 0;
TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx);
- QualType Canonical = GetType(Record[1]);
+ QualType Canonical = readType(*Loc.F, Record, Idx);
if (!Canonical.isNull())
Canonical = Context->getCanonicalType(Canonical);
return Context->getTypedefType(Decl, Canonical);
Error("incorrect encoding of typeof(type) in AST file");
return QualType();
}
- QualType UnderlyingType = GetType(Record[0]);
+ QualType UnderlyingType = readType(*Loc.F, Record, Idx);
return Context->getTypeOfType(UnderlyingType);
}
return Context->getDecltypeType(ReadExpr(*Loc.F));
case TYPE_UNARY_TRANSFORM: {
- QualType BaseType = GetType(Record[0]);
- QualType UnderlyingType = GetType(Record[1]);
+ 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);
}
case TYPE_AUTO:
- return Context->getAutoType(GetType(Record[0]));
+ return Context->getAutoType(readType(*Loc.F, Record, Idx));
case TYPE_RECORD: {
if (Record.size() != 2) {
Error("incorrect encoding of attributed type");
return QualType();
}
- QualType modifiedType = GetType(Record[0]);
- QualType equivalentType = GetType(Record[1]);
+ 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);
}
Error("incorrect encoding of paren type");
return QualType();
}
- QualType InnerType = GetType(Record[0]);
+ QualType InnerType = readType(*Loc.F, Record, Idx);
return Context->getParenType(InnerType);
}
Error("incorrect encoding of pack expansion type");
return QualType();
}
- QualType Pattern = GetType(Record[0]);
+ QualType Pattern = readType(*Loc.F, Record, Idx);
if (Pattern.isNull())
return QualType();
llvm::Optional<unsigned> NumExpansions;
unsigned Idx = 0;
ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
- QualType NamedType = GetType(Record[Idx++]);
+ QualType NamedType = readType(*Loc.F, Record, Idx);
return Context->getElaboratedType(Keyword, NNS, NamedType);
}
case TYPE_OBJC_OBJECT: {
unsigned Idx = 0;
- QualType Base = GetType(Record[Idx++]);
+ QualType Base = readType(*Loc.F, Record, Idx);
unsigned NumProtos = Record[Idx++];
llvm::SmallVector<ObjCProtocolDecl*, 4> Protos;
for (unsigned I = 0; I != NumProtos; ++I)
case TYPE_OBJC_OBJECT_POINTER: {
unsigned Idx = 0;
- QualType Pointee = GetType(Record[Idx++]);
+ QualType Pointee = readType(*Loc.F, Record, Idx);
return Context->getObjCObjectPointerType(Pointee);
}
case TYPE_SUBST_TEMPLATE_TYPE_PARM: {
unsigned Idx = 0;
- QualType Parm = GetType(Record[Idx++]);
- QualType Replacement = GetType(Record[Idx++]);
+ QualType Parm = readType(*Loc.F, Record, Idx);
+ QualType Replacement = readType(*Loc.F, Record, Idx);
return
Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm),
Replacement);
case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: {
unsigned Idx = 0;
- QualType Parm = GetType(Record[Idx++]);
+ QualType Parm = readType(*Loc.F, Record, Idx);
TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx);
return Context->getSubstTemplateTypeParmPackType(
cast<TemplateTypeParmType>(Parm),
}
case TYPE_INJECTED_CLASS_NAME: {
- unsigned Idx = 0;
CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx);
- QualType TST = GetType(Record[1]); // probably derivable
+ QualType TST = readType(*Loc.F, Record, Idx); // probably derivable
// FIXME: ASTContext::getInjectedClassNameType is not currently suitable
// for AST reading, too much interdependencies.
return
ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++];
NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx);
const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx);
- QualType Canon = GetType(Record[Idx++]);
+ QualType Canon = readType(*Loc.F, Record, Idx);
if (!Canon.isNull())
Canon = Context->getCanonicalType(Canon);
return Context->getDependentNameType(Keyword, NNS, Name, Canon);
unsigned Idx = 0;
// ArrayType
- QualType ElementType = GetType(Record[Idx++]);
+ QualType ElementType = readType(*Loc.F, Record, Idx);
ArrayType::ArraySizeModifier ASM
= (ArrayType::ArraySizeModifier)Record[Idx++];
unsigned IndexTypeQuals = Record[Idx++];
TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx);
llvm::SmallVector<TemplateArgument, 8> Args;
ReadTemplateArgumentList(Args, *Loc.F, Record, Idx);
- QualType Underlying = GetType(Record[Idx++]);
+ QualType Underlying = readType(*Loc.F, Record, Idx);
QualType T;
if (Underlying.isNull())
T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(),
TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F,
const RecordData &Record,
unsigned &Idx) {
- QualType InfoTy = GetType(Record[Idx++]);
+ QualType InfoTy = readType(F, Record, Idx);
if (InfoTy.isNull())
return 0;
Index -= NUM_PREDEF_TYPE_IDS;
assert(Index < TypesLoaded.size() && "Type index out-of-range");
if (TypesLoaded[Index].isNull()) {
- TypesLoaded[Index] = ReadTypeRecord(Index);
+ TypesLoaded[Index] = readTypeRecord(Index);
if (TypesLoaded[Index].isNull())
return QualType();
return TypesLoaded[Index].withFastQualifiers(FastQuals);
}
+QualType ASTReader::getLocalType(PerFileData &F, unsigned LocalID) {
+ return GetType(getGlobalTypeID(F, LocalID));
+}
+
+serialization::TypeID
+ASTReader::getGlobalTypeID(PerFileData &F, unsigned LocalID) const {
+ // FIXME: Map from local type ID to global type ID.
+ return LocalID;
+}
+
TypeID ASTReader::GetTypeID(QualType T) const {
return MakeTypeID(T,
std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this));
}
DeclarationName
-ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) {
+ASTReader::ReadDeclarationName(PerFileData &F,
+ const RecordData &Record, unsigned &Idx) {
DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++];
switch (Kind) {
case DeclarationName::Identifier:
case DeclarationName::CXXConstructorName:
return Context->DeclarationNames.getCXXConstructorName(
- Context->getCanonicalType(GetType(Record[Idx++])));
+ Context->getCanonicalType(readType(F, Record, Idx)));
case DeclarationName::CXXDestructorName:
return Context->DeclarationNames.getCXXDestructorName(
- Context->getCanonicalType(GetType(Record[Idx++])));
+ Context->getCanonicalType(readType(F, Record, Idx)));
case DeclarationName::CXXConversionFunctionName:
return Context->DeclarationNames.getCXXConversionFunctionName(
- Context->getCanonicalType(GetType(Record[Idx++])));
+ Context->getCanonicalType(readType(F, Record, Idx)));
case DeclarationName::CXXOperatorName:
return Context->DeclarationNames.getCXXOperatorName(
void ASTReader::ReadDeclarationNameInfo(PerFileData &F,
DeclarationNameInfo &NameInfo,
const RecordData &Record, unsigned &Idx) {
- NameInfo.setName(ReadDeclarationName(Record, Idx));
+ NameInfo.setName(ReadDeclarationName(F, Record, Idx));
NameInfo.setLoc(ReadSourceLocation(F, Record, Idx));
DeclarationNameLoc DNLoc;
ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx);
case TemplateArgument::Null:
return TemplateArgument();
case TemplateArgument::Type:
- return TemplateArgument(GetType(Record[Idx++]));
+ return TemplateArgument(readType(F, Record, Idx));
case TemplateArgument::Declaration:
return TemplateArgument(ReadDecl(F, Record, Idx));
case TemplateArgument::Integral: {
llvm::APSInt Value = ReadAPSInt(Record, Idx);
- QualType T = GetType(Record[Idx++]);
+ QualType T = readType(F, Record, Idx);
return TemplateArgument(Value, T);
}
case TemplateArgument::Template:
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate: {
- const Type *T = GetType(Record[Idx++]).getTypePtrOrNull();
+ const Type *T = readType(F, Record, Idx).getTypePtrOrNull();
if (!T)
return 0;