aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp2
-rw-r--r--lib/AST/TypeLoc.cpp40
-rw-r--r--lib/Sema/SemaTemplate.cpp6
-rw-r--r--lib/Sema/SemaType.cpp14
-rw-r--r--lib/Sema/TreeTransform.h6
5 files changed, 54 insertions, 14 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 043d56a98d..1622d3cfa4 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1127,7 +1127,7 @@ TypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T,
TypeSourceInfo *ASTContext::getTrivialTypeSourceInfo(QualType T,
SourceLocation L) const {
TypeSourceInfo *DI = CreateTypeSourceInfo(T);
- DI->getTypeLoc().initialize(L);
+ DI->getTypeLoc().initialize(const_cast<ASTContext &>(*this), L);
return DI;
}
diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp
index 08fe267b1d..0680acb1c5 100644
--- a/lib/AST/TypeLoc.cpp
+++ b/lib/AST/TypeLoc.cpp
@@ -77,14 +77,15 @@ TypeLoc TypeLoc::getNextTypeLocImpl(TypeLoc TL) {
/// \brief Initializes a type location, and all of its children
/// recursively, as if the entire tree had been written in the
/// given location.
-void TypeLoc::initializeImpl(TypeLoc TL, SourceLocation Loc) {
+void TypeLoc::initializeImpl(ASTContext &Context, TypeLoc TL,
+ SourceLocation Loc) {
while (true) {
switch (TL.getTypeLocClass()) {
#define ABSTRACT_TYPELOC(CLASS, PARENT)
#define TYPELOC(CLASS, PARENT) \
case CLASS: { \
CLASS##TypeLoc TLCasted = cast<CLASS##TypeLoc>(TL); \
- TLCasted.initializeLocal(Loc); \
+ TLCasted.initializeLocal(Context, Loc); \
TL = TLCasted.getNextTypeLoc(); \
if (!TL) return; \
continue; \
@@ -229,3 +230,38 @@ TypeLoc TypeLoc::IgnoreParensImpl(TypeLoc TL) {
TL = PTL->getInnerLoc();
return TL;
}
+
+void TemplateSpecializationTypeLoc::initializeArgLocs(ASTContext &Context,
+ unsigned NumArgs,
+ const TemplateArgument *Args,
+ TemplateArgumentLocInfo *ArgInfos,
+ SourceLocation Loc) {
+ for (unsigned i = 0, e = NumArgs; i != e; ++i) {
+ switch (Args[i].getKind()) {
+ case TemplateArgument::Null:
+ case TemplateArgument::Declaration:
+ case TemplateArgument::Integral:
+ case TemplateArgument::Pack:
+ case TemplateArgument::Expression:
+ // FIXME: Can we do better for declarations and integral values?
+ ArgInfos[i] = TemplateArgumentLocInfo();
+ break;
+
+ case TemplateArgument::Type:
+ ArgInfos[i] = TemplateArgumentLocInfo(
+ Context.getTrivialTypeSourceInfo(Args[i].getAsType(),
+ Loc));
+ break;
+
+ case TemplateArgument::Template:
+ ArgInfos[i] = TemplateArgumentLocInfo(SourceRange(Loc), Loc,
+ SourceLocation());
+ break;
+
+ case TemplateArgument::TemplateExpansion:
+ ArgInfos[i] = TemplateArgumentLocInfo(SourceRange(Loc), Loc, Loc);
+ break;
+ }
+ }
+}
+
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 2d2c3ea672..78f8d5e05a 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -5901,7 +5901,8 @@ Sema::ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
if (InnerTSI)
Builder.pushFullCopy(InnerTSI->getTypeLoc());
else
- Builder.push<TemplateSpecializationTypeLoc>(T).initialize(TemplateLoc);
+ Builder.push<TemplateSpecializationTypeLoc>(T).initialize(Context,
+ TemplateLoc);
/* Note: NNS already embedded in template specialization type T. */
T = Context.getElaboratedType(ETK_Typename, /*NNS=*/0, T);
@@ -5937,7 +5938,8 @@ Sema::ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
for (unsigned I = 0, E = TST->getNumArgs(); I != E; ++I)
TL.setArgLocInfo(I, TSTL.getArgLocInfo(I));
} else {
- TL.initializeLocal(SourceLocation());
+ // FIXME: Poor source-location information here.
+ TL.initializeLocal(Context, TemplateLoc);
}
TL.setKeywordLoc(TypenameLoc);
TL.setQualifierRange(SS.getRange());
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 40d3734836..c8f7545602 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1972,10 +1972,12 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
namespace {
class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> {
+ ASTContext &Context;
const DeclSpec &DS;
public:
- TypeSpecLocFiller(const DeclSpec &DS) : DS(DS) {}
+ TypeSpecLocFiller(ASTContext &Context, const DeclSpec &DS)
+ : Context(Context), DS(DS) {}
void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
Visit(TL.getUnqualifiedLoc());
@@ -1990,7 +1992,7 @@ namespace {
// Handle the base type, which might not have been written explicitly.
if (DS.getTypeSpecType() == DeclSpec::TST_unspecified) {
TL.setHasBaseTypeAsWritten(false);
- TL.getBaseLoc().initialize(SourceLocation());
+ TL.getBaseLoc().initialize(Context, SourceLocation());
} else {
TL.setHasBaseTypeAsWritten(true);
Visit(TL.getBaseLoc());
@@ -2021,7 +2023,7 @@ namespace {
// If we got no declarator info from previous Sema routines,
// just fill with the typespec loc.
if (!TInfo) {
- TL.initialize(DS.getTypeSpecTypeLoc());
+ TL.initialize(Context, DS.getTypeSpecTypeLoc());
return;
}
@@ -2114,7 +2116,7 @@ namespace {
return;
}
}
- TL.initializeLocal(SourceLocation());
+ TL.initializeLocal(Context, SourceLocation());
TL.setKeywordLoc(Keyword != ETK_None
? DS.getTypeSpecTypeLoc()
: SourceLocation());
@@ -2126,7 +2128,7 @@ namespace {
void VisitTypeLoc(TypeLoc TL) {
// FIXME: add other typespec types and change this to an assert.
- TL.initialize(DS.getTypeSpecTypeLoc());
+ TL.initialize(Context, DS.getTypeSpecTypeLoc());
}
};
@@ -2231,7 +2233,7 @@ Sema::GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
assert(TL.getFullDataSize() == CurrTL.getFullDataSize());
memcpy(CurrTL.getOpaqueData(), TL.getOpaqueData(), TL.getFullDataSize());
} else {
- TypeSpecLocFiller(D.getDeclSpec()).Visit(CurrTL);
+ TypeSpecLocFiller(Context, D.getDeclSpec()).Visit(CurrTL);
}
return TInfo;
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 654bf90e87..04c45b8da7 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -2980,8 +2980,8 @@ QualType TreeTransform<Derived>::TransformType(QualType T) {
// Temporary workaround. All of these transformations should
// eventually turn into transformations on TypeLocs.
- TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
- DI->getTypeLoc().initialize(getDerived().getBaseLocation());
+ TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
+ getDerived().getBaseLocation());
TypeSourceInfo *NewDI = getDerived().TransformType(DI);
@@ -3073,7 +3073,7 @@ TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
return T;
TypeSourceInfo *TSI =
- SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
+ SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
UnqualLookup, Prefix);