]> granicus.if.org Git - clang/commitdiff
Eliminate the last remains of TemplateSpecializationTypes with
authorDouglas Gregor <dgregor@apple.com>
Mon, 28 Feb 2011 17:23:35 +0000 (17:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 28 Feb 2011 17:23:35 +0000 (17:23 +0000)
dependent template names. There is still a lot of redundant code in
TreeTransform to cope with TemplateSpecializationTypes, which I'll
remove in stages.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126656 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Type.cpp
lib/AST/TypePrinter.cpp
lib/Sema/SemaTemplate.cpp
lib/Sema/TreeTransform.h

index d1136adbab2aa7b206d3895a6a9680d3cc4b14a9..cde865f5b9f18e4e3b5d16df0cca2dd049ada950 100644 (file)
@@ -1357,10 +1357,11 @@ TemplateSpecializationType(TemplateName T,
                            unsigned NumArgs, QualType Canon)
   : Type(TemplateSpecialization,
          Canon.isNull()? QualType(this, 0) : Canon,
-         T.isDependent(), false,
-         T.containsUnexpandedParameterPack()),
+         T.isDependent(), false, T.containsUnexpandedParameterPack()),
     Template(T), NumArgs(NumArgs) 
 {
+  assert(!T.getAsDependentTemplateName() && 
+         "Use DependentTemplateSpecializationType for dependent template-name");
   assert((!Canon.isNull() ||
           T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) &&
          "No canonical type for non-dependent class template specialization");
index 139073987a0ea233cfbbd55180146c88e783ef32..4e966083bb2d9dde4c81556b30ba1f43ca156b7b 100644 (file)
@@ -737,7 +737,8 @@ void TypePrinter::printDependentTemplateSpecialization(
     if (T->getKeyword() != ETK_None)
       OS << " ";
     
-    T->getQualifier()->print(OS, Policy);    
+    if (T->getQualifier())
+      T->getQualifier()->print(OS, Policy);    
     OS << T->getIdentifier()->getName();
     OS << TemplateSpecializationType::PrintTemplateArgumentList(
                                                             T->getArgs(),
index 625944d797f6b06e42191f5ef5a5872f3fd4211c..cbfd7b09394843dd9f23edf982edf0eceeb4ffc3 100644 (file)
@@ -1756,6 +1756,26 @@ Sema::ActOnTemplateIdType(TemplateTy TemplateD, SourceLocation TemplateLoc,
   TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
   translateTemplateArguments(TemplateArgsIn, TemplateArgs);
 
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
+    QualType T = Context.getDependentTemplateSpecializationType(ETK_None,
+                                                           DTN->getQualifier(), 
+                                                           DTN->getIdentifier(), 
+                                                                TemplateArgs);
+    
+    // Build type-source information.    
+    TypeLocBuilder TLB;
+    DependentTemplateSpecializationTypeLoc SpecTL
+      = TLB.push<DependentTemplateSpecializationTypeLoc>(T);
+    SpecTL.setKeywordLoc(SourceLocation()); // FIXME: 'template' location
+    SpecTL.setNameLoc(TemplateLoc);
+    SpecTL.setLAngleLoc(LAngleLoc);
+    SpecTL.setRAngleLoc(RAngleLoc);
+    SpecTL.setQualifierRange(TemplateLoc); // FIXME: nested-name-specifier loc
+    for (unsigned I = 0, N = SpecTL.getNumArgs(); I != N; ++I)
+      SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
+    return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T));
+  }
+  
   QualType Result = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs);
   TemplateArgsIn.release();
 
index fa4637a27e8a85d8775c551cf3a2e9effeaee071..8f875fbef0203cfa6e9b63709b4a1b0f5f340617 100644 (file)
@@ -488,6 +488,11 @@ public:
                                       TemplateSpecializationTypeLoc TL,
                                       TemplateName Template);
 
+  QualType 
+  TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
+                                      DependentTemplateSpecializationTypeLoc TL,
+                                               TemplateName Template);
+
   QualType 
   TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
                                       DependentTemplateSpecializationTypeLoc TL,
@@ -754,11 +759,10 @@ public:
       getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
     if (T.isNull()) return QualType();
 
-    if (Keyword == ETK_None)
+    if (Keyword == ETK_None && Qualifier == 0)
       return T;
     
-    // NOTE: NNS is already recorded in template specialization type T.
-    return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
+    return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T);
   }
 
   /// \brief Build a new typename type that refers to an identifier.
@@ -3240,8 +3244,18 @@ TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
     DependentTemplateSpecializationTypeLoc TL
       = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
 
-    Result = getDerived()
-      .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
+    TemplateName Template
+      = SemaRef.Context.getDependentTemplateName(
+                                                TL.getTypePtr()->getQualifier(),
+                                              TL.getTypePtr()->getIdentifier());
+    
+    Template = getDerived().TransformTemplateName(Template, ObjectType, 
+                                                  UnqualLookup);
+    if (Template.isNull())
+      return 0;
+
+    Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
+                                                                     Template);
   } else {
     // Nothing special needs to be done for these.
     Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
@@ -3293,9 +3307,19 @@ TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
     DependentTemplateSpecializationTypeLoc SpecTL
       = cast<DependentTemplateSpecializationTypeLoc>(TL);
     
+    TemplateName Template
+    = SemaRef.Context.getDependentTemplateName(
+                                         SpecTL.getTypePtr()->getQualifier(),
+                                         SpecTL.getTypePtr()->getIdentifier());
+    
+    Template = getDerived().TransformTemplateName(Template, ObjectType, 
+                                                  UnqualLookup);
+    if (Template.isNull())
+      return TypeLoc();
+    
     Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 
-                                                                       SpecTL, 
-                                                             SS.getScopeRep());
+                                                                       SpecTL,
+                                                                     Template);
   } else {
     // Nothing special needs to be done for these.
     Result = getDerived().TransformType(TLB, TL);
@@ -4365,6 +4389,62 @@ QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
   return Result;
 }
 
+template <typename Derived>
+QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
+                                     TypeLocBuilder &TLB,
+                                     DependentTemplateSpecializationTypeLoc TL,
+                                     TemplateName Template) {
+  TemplateArgumentListInfo NewTemplateArgs;
+  NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
+  NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
+  typedef TemplateArgumentLocContainerIterator<
+            DependentTemplateSpecializationTypeLoc> ArgIterator;
+  if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 
+                                              ArgIterator(TL, TL.getNumArgs()),
+                                              NewTemplateArgs))
+    return QualType();
+  
+  // FIXME: maybe don't rebuild if all the template arguments are the same.
+  
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
+    QualType Result
+      = getSema().Context.getDependentTemplateSpecializationType(
+                                                TL.getTypePtr()->getKeyword(),
+                                                         DTN->getQualifier(),
+                                                         DTN->getIdentifier(),
+                                                               NewTemplateArgs);
+   
+    DependentTemplateSpecializationTypeLoc NewTL
+      = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
+    NewTL.setKeywordLoc(TL.getKeywordLoc());
+    NewTL.setQualifierRange(TL.getQualifierRange());
+    NewTL.setNameLoc(TL.getNameLoc());
+    NewTL.setLAngleLoc(TL.getLAngleLoc());
+    NewTL.setRAngleLoc(TL.getRAngleLoc());
+    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
+      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
+    return Result;
+  }
+      
+  QualType Result 
+    = getDerived().RebuildTemplateSpecializationType(Template,
+                                                     TL.getNameLoc(),
+                                                     NewTemplateArgs);
+  
+  if (!Result.isNull()) {
+    /// FIXME: Wrap this in an elaborated-type-specifier?
+    TemplateSpecializationTypeLoc NewTL
+      = TLB.push<TemplateSpecializationTypeLoc>(Result);
+    NewTL.setTemplateNameLoc(TL.getNameLoc());
+    NewTL.setLAngleLoc(TL.getLAngleLoc());
+    NewTL.setRAngleLoc(TL.getRAngleLoc());
+    for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
+      NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
+  }
+  
+  return Result;
+}
+
 template<typename Derived>
 QualType
 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
@@ -4502,12 +4582,14 @@ QualType TreeTransform<Derived>::
                                  DependentTemplateSpecializationTypeLoc TL) {
   const DependentTemplateSpecializationType *T = TL.getTypePtr();
 
-  NestedNameSpecifier *NNS
-    = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
-                                                TL.getQualifierRange());
-  if (!NNS)
-    return QualType();
-
+  NestedNameSpecifier *NNS = 0;
+  if (T->getQualifier()) {
+    NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
+                                                    TL.getQualifierRange());
+    if (!NNS)
+      return QualType();
+  }
+            
   return getDerived()
            .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
 }