Added basic source locations to Elaborated and DependentName types.

llvm-svn: 103770
This commit is contained in:
Abramo Bagnara 2010-05-14 14:14:23 +00:00
parent 148e876ac2
commit e9f4d6ed7d
6 changed files with 183 additions and 34 deletions

View File

@ -269,6 +269,16 @@ public:
return TypeClass::classof(Ty); return TypeClass::classof(Ty);
} }
static bool classof(const TypeLoc *TL) {
return Derived::classofType(TL->getTypePtr());
}
static bool classof(const UnqualTypeLoc *TL) {
return Derived::classofType(TL->getTypePtr());
}
static bool classof(const Derived *TL) {
return true;
}
TypeLoc getNextTypeLoc() const { TypeLoc getNextTypeLoc() const {
return getNextTypeLoc(asDerived()->getInnerType()); return getNextTypeLoc(asDerived()->getInnerType());
} }
@ -1231,18 +1241,75 @@ class DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
DecltypeType> { DecltypeType> {
}; };
// FIXME: locations for the nested name specifier; at the very least, // FIXME: locations for the nested name specifier should be put in
// a SourceRange. // NestedNameSpecifier
class ElaboratedTypeLoc : struct ElaboratedLocInfo {
public InheritingConcreteTypeLoc<TypeSpecTypeLoc, SourceLocation KeywordLoc;
ElaboratedTypeLoc,
ElaboratedType> {
}; };
// FIXME: locations for the typename keyword and nested name specifier. class ElaboratedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
class DependentNameTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, ElaboratedTypeLoc,
DependentNameTypeLoc, ElaboratedType,
DependentNameType> { ElaboratedLocInfo> {
public:
SourceLocation getKeywordLoc() const {
return this->getLocalData()->KeywordLoc;
}
void setKeywordLoc(SourceLocation Loc) {
this->getLocalData()->KeywordLoc = Loc;
}
SourceRange getSourceRange() const {
return SourceRange(getKeywordLoc(), getKeywordLoc());
}
void initializeLocal(SourceLocation Loc) {
setKeywordLoc(Loc);
}
TypeLoc getNamedTypeLoc() const {
return getInnerTypeLoc();
}
QualType getInnerType() const {
return getTypePtr()->getNamedType();
}
};
// FIXME: locations for the nested name specifier should be put in
// NestedNameSpecifier
struct DependentNameLocInfo {
SourceLocation KeywordLoc;
SourceLocation NameLoc;
};
class DependentNameTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
DependentNameTypeLoc,
DependentNameType,
DependentNameLocInfo> {
public:
SourceLocation getKeywordLoc() const {
return this->getLocalData()->KeywordLoc;
}
void setKeywordLoc(SourceLocation Loc) {
this->getLocalData()->KeywordLoc = Loc;
}
SourceLocation getNameLoc() const {
return this->getLocalData()->NameLoc;
}
void setNameLoc(SourceLocation Loc) {
this->getLocalData()->NameLoc = Loc;
}
SourceRange getSourceRange() const {
return SourceRange(getKeywordLoc(), getNameLoc());
}
void initializeLocal(SourceLocation Loc) {
setKeywordLoc(Loc);
setNameLoc(Loc);
}
}; };
} }

View File

@ -2354,12 +2354,13 @@ void TypeLocReader::VisitTemplateSpecializationTypeLoc(
Record, Idx)); Record, Idx));
} }
void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
} }
void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
} }
void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
TL.setKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
} }
void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {

View File

@ -396,12 +396,13 @@ void TypeLocWriter::VisitTemplateSpecializationTypeLoc(
Writer.AddTemplateArgumentLoc(TL.getArgLoc(i), Record); Writer.AddTemplateArgumentLoc(TL.getArgLoc(i), Record);
} }
void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
Writer.AddSourceLocation(TL.getNameLoc(), Record); Writer.AddSourceLocation(TL.getKeywordLoc(), Record);
} }
void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
Writer.AddSourceLocation(TL.getNameLoc(), Record); Writer.AddSourceLocation(TL.getNameLoc(), Record);
} }
void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
Writer.AddSourceLocation(TL.getKeywordLoc(), Record);
Writer.AddSourceLocation(TL.getNameLoc(), Record); Writer.AddSourceLocation(TL.getNameLoc(), Record);
} }
void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {

View File

@ -5184,16 +5184,18 @@ Sema::ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
static void FillTypeLoc(DependentNameTypeLoc TL, static void FillTypeLoc(DependentNameTypeLoc TL,
SourceLocation TypenameLoc, SourceLocation TypenameLoc,
SourceRange QualifierRange) { SourceRange QualifierRange,
// FIXME: typename, qualifier range SourceLocation NameLoc) {
TL.setNameLoc(TypenameLoc); // FIXME: qualifier range
TL.setKeywordLoc(TypenameLoc);
TL.setNameLoc(NameLoc);
} }
static void FillTypeLoc(ElaboratedTypeLoc TL, static void FillTypeLoc(ElaboratedTypeLoc TL,
SourceLocation TypenameLoc, SourceLocation TypenameLoc,
SourceRange QualifierRange) { SourceRange QualifierRange) {
// FIXME: typename, qualifier range // FIXME: qualifier range and inner locations.
TL.setNameLoc(TypenameLoc); TL.setKeywordLoc(TypenameLoc);
} }
Sema::TypeResult Sema::TypeResult
@ -5213,7 +5215,7 @@ Sema::ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS,
if (isa<DependentNameType>(T)) { if (isa<DependentNameType>(T)) {
DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc()); DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc());
// FIXME: fill inner type loc // FIXME: fill inner type loc
FillTypeLoc(TL, TypenameLoc, SS.getRange()); FillTypeLoc(TL, TypenameLoc, SS.getRange(), IdLoc);
} else { } else {
ElaboratedTypeLoc TL = cast<ElaboratedTypeLoc>(TSI->getTypeLoc()); ElaboratedTypeLoc TL = cast<ElaboratedTypeLoc>(TSI->getTypeLoc());
// FIXME: fill inner type loc // FIXME: fill inner type loc
@ -5249,7 +5251,7 @@ Sema::ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS,
TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T); TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T);
DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc()); DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc());
// FIXME: fill inner type loc // FIXME: fill inner type loc
FillTypeLoc(TL, TypenameLoc, SS.getRange()); FillTypeLoc(TL, TypenameLoc, SS.getRange(), TemplateLoc);
return CreateLocInfoType(T, TSI).getAsOpaquePtr(); return CreateLocInfoType(T, TSI).getAsOpaquePtr();
} }
@ -5426,13 +5428,41 @@ CurrentInstantiationRebuilder::TransformDependentNameType(TypeLocBuilder &TLB,
} else } else
Result = getDerived().RebuildDependentNameType(T->getKeyword(), Result = getDerived().RebuildDependentNameType(T->getKeyword(),
NNS, T->getIdentifier(), NNS, T->getIdentifier(),
SourceRange(TL.getNameLoc())); TL.getSourceRange());
if (Result.isNull()) if (Result.isNull())
return QualType(); return QualType();
DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
NewTL.setNameLoc(TL.getNameLoc()); QualType NamedT = ElabT->getNamedType();
if (isa<TypedefType>(NamedT)) {
TypedefTypeLoc NamedTLoc = TLB.push<TypedefTypeLoc>(NamedT);
NamedTLoc.setNameLoc(TL.getNameLoc());
}
else if (isa<RecordType>(NamedT)) {
RecordTypeLoc NamedTLoc = TLB.push<RecordTypeLoc>(NamedT);
NamedTLoc.setNameLoc(TL.getNameLoc());
}
else if (isa<EnumType>(NamedT)) {
EnumTypeLoc NamedTLoc = TLB.push<EnumTypeLoc>(NamedT);
NamedTLoc.setNameLoc(TL.getNameLoc());
}
else if (isa<TemplateSpecializationType>(NamedT)) {
TemplateSpecializationTypeLoc NamedTLoc
= TLB.push<TemplateSpecializationTypeLoc>(NamedT);
// FIXME: fill locations
NamedTLoc.initializeLocal(SourceLocation());
}
else
llvm_unreachable("Unexpected type");
ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
NewTL.setKeywordLoc(TL.getKeywordLoc());
}
else {
DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
NewTL.setKeywordLoc(TL.getKeywordLoc());
NewTL.setNameLoc(TL.getNameLoc());
}
return Result; return Result;
} }

View File

@ -1455,9 +1455,15 @@ namespace {
return; return;
} }
TemplateSpecializationTypeLoc OldTL = TypeLoc OldTL = TInfo->getTypeLoc();
cast<TemplateSpecializationTypeLoc>(TInfo->getTypeLoc()); if (TInfo->getType()->getAs<ElaboratedType>()) {
TL.copy(OldTL); ElaboratedTypeLoc ElabTL = cast<ElaboratedTypeLoc>(OldTL);
TemplateSpecializationTypeLoc NamedTL =
cast<TemplateSpecializationTypeLoc>(ElabTL.getNamedTypeLoc());
TL.copy(NamedTL);
}
else
TL.copy(cast<TemplateSpecializationTypeLoc>(OldTL));
} }
void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
assert(DS.getTypeSpecType() == DeclSpec::TST_typeofExpr); assert(DS.getTypeSpecType() == DeclSpec::TST_typeofExpr);
@ -1488,6 +1494,23 @@ namespace {
TL.setBuiltinLoc(DS.getTypeSpecWidthLoc()); TL.setBuiltinLoc(DS.getTypeSpecWidthLoc());
} }
} }
void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
ElaboratedTypeKeyword Keyword
= TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType());
TL.setKeywordLoc(Keyword != ETK_None
? DS.getTypeSpecTypeLoc()
: SourceLocation());
Visit(TL.getNextTypeLoc().getUnqualifiedLoc());
}
void VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
ElaboratedTypeKeyword Keyword
= TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType());
TL.setKeywordLoc(Keyword != ETK_None
? DS.getTypeSpecTypeLoc()
: SourceLocation());
TL.setNameLoc(DS.getTypeSpecTypeLoc());
}
void VisitTypeLoc(TypeLoc TL) { void VisitTypeLoc(TypeLoc TL) {
// FIXME: add other typespec types and change this to an assert. // FIXME: add other typespec types and change this to an assert.
TL.initialize(DS.getTypeSpecTypeLoc()); TL.initialize(DS.getTypeSpecTypeLoc());

View File

@ -3247,22 +3247,22 @@ QualType
TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
ElaboratedTypeLoc TL, ElaboratedTypeLoc TL,
QualType ObjectType) { QualType ObjectType) {
QualType Named = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
if (Named.isNull())
return QualType();
ElaboratedType *T = TL.getTypePtr(); ElaboratedType *T = TL.getTypePtr();
NestedNameSpecifier *NNS = 0; NestedNameSpecifier *NNS = 0;
// NOTE: the qualifier in an ElaboratedType is optional. // NOTE: the qualifier in an ElaboratedType is optional.
if (T->getQualifier() != 0) { if (T->getQualifier() != 0) {
NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
SourceRange(), /* FIXME */ SourceRange(),
ObjectType); ObjectType);
if (!NNS) if (!NNS)
return QualType(); return QualType();
} }
QualType Named = getDerived().TransformType(T->getNamedType());
if (Named.isNull())
return QualType();
QualType Result = TL.getType(); QualType Result = TL.getType();
if (getDerived().AlwaysRebuild() || if (getDerived().AlwaysRebuild() ||
NNS != T->getQualifier() || NNS != T->getQualifier() ||
@ -3273,7 +3273,7 @@ TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
} }
ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
NewTL.setNameLoc(TL.getNameLoc()); NewTL.setKeywordLoc(TL.getKeywordLoc());
return Result; return Result;
} }
@ -3315,9 +3315,36 @@ QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
if (Result.isNull()) if (Result.isNull())
return QualType(); return QualType();
DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
NewTL.setNameLoc(TL.getNameLoc()); QualType NamedT = ElabT->getNamedType();
if (isa<TypedefType>(NamedT)) {
TypedefTypeLoc NamedTLoc = TLB.push<TypedefTypeLoc>(NamedT);
NamedTLoc.setNameLoc(TL.getNameLoc());
}
else if (isa<RecordType>(NamedT)) {
RecordTypeLoc NamedTLoc = TLB.push<RecordTypeLoc>(NamedT);
NamedTLoc.setNameLoc(TL.getNameLoc());
}
else if (isa<EnumType>(NamedT)) {
EnumTypeLoc NamedTLoc = TLB.push<EnumTypeLoc>(NamedT);
NamedTLoc.setNameLoc(TL.getNameLoc());
}
else if (isa<TemplateSpecializationType>(NamedT)) {
TemplateSpecializationTypeLoc NamedTLoc
= TLB.push<TemplateSpecializationTypeLoc>(NamedT);
// FIXME: fill locations
NamedTLoc.initializeLocal(SourceLocation());
}
else
llvm_unreachable("Unexpected type");
ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
NewTL.setKeywordLoc(TL.getKeywordLoc());
}
else {
DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
NewTL.setKeywordLoc(TL.getKeywordLoc());
NewTL.setNameLoc(TL.getNameLoc());
}
return Result; return Result;
} }