diff options
| author | John McCall <rjmccall@apple.com> | 2010-06-11 00:33:02 +0000 | 
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-06-11 00:33:02 +0000 | 
| commit | c392f37ae81d99a29c95dafb964e52492f2e0f37 (patch) | |
| tree | 256ac4ce11a58388766a1dd709d81551395e8efa /clang/lib/Sema/SemaTemplate.cpp | |
| parent | d85248be7abb5c707ea1b3457a0692f240b40dda (diff) | |
| download | bcm5719-llvm-c392f37ae81d99a29c95dafb964e52492f2e0f37.tar.gz bcm5719-llvm-c392f37ae81d99a29c95dafb964e52492f2e0f37.zip | |
Split DependentNameType into two types.  DependentNameType represents the
case of an elaborated-type-specifier like 'typename A<T>::foo', and
DependentTemplateSpecializationType represents the case of an
elaborated-type-specifier like 'typename A<T>::template B<T>'.  The TypeLoc
representation of a DependentTST conveniently exactly matches that of an
ElaboratedType wrapping a TST.
Kill off the explicit rebuild methods for RebuildInCurrentInstantiation;
the standard implementations work fine because the nested name specifier
is computable in the newly-entered context.
llvm-svn: 105801
Diffstat (limited to 'clang/lib/Sema/SemaTemplate.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 106 | 
1 files changed, 22 insertions, 84 deletions
| diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 2f18711e246..5208f28ca69 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -5288,15 +5288,31 @@ Sema::ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS,      return CreateLocInfoType(T, TSI).getAsOpaquePtr();    } -  T = Context.getDependentNameType(ETK_Typename, NNS, -                                   cast<TemplateSpecializationType>(T)); +  // TODO: it's really silly that we make a template specialization +  // type earlier only to drop it again here. +  TemplateSpecializationType *TST = cast<TemplateSpecializationType>(T); +  DependentTemplateName *DTN = +    TST->getTemplateName().getAsDependentTemplateName(); +  assert(DTN && "dependent template has non-dependent name?"); +  T = Context.getDependentTemplateSpecializationType(ETK_Typename, NNS, +                                                     DTN->getIdentifier(), +                                                     TST->getNumArgs(), +                                                     TST->getArgs());    TypeSourceInfo *TSI = Context.CreateTypeSourceInfo(T); -  DependentNameTypeLoc TL = cast<DependentNameTypeLoc>(TSI->getTypeLoc()); +  DependentTemplateSpecializationTypeLoc TL = +    cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc()); +  if (InnerTSI) { +    TemplateSpecializationTypeLoc TSTL = +      cast<TemplateSpecializationTypeLoc>(InnerTSI->getTypeLoc()); +    TL.setLAngleLoc(TSTL.getLAngleLoc()); +    TL.setRAngleLoc(TSTL.getRAngleLoc()); +    for (unsigned I = 0, E = TST->getNumArgs(); I != E; ++I) +      TL.setArgLocInfo(I, TSTL.getArgLocInfo(I)); +  } else { +    TL.initializeLocal(SourceLocation()); +  }    TL.setKeywordLoc(TypenameLoc);    TL.setQualifierRange(SS.getRange()); - -  // FIXME: the inner type is a template here; remember its full source info -  TL.setNameLoc(InnerTSI ? InnerTSI->getTypeLoc().getBeginLoc() : TemplateLoc);    return CreateLocInfoType(T, TSI).getAsOpaquePtr();  } @@ -5425,87 +5441,9 @@ namespace {      Sema::OwningExprResult TransformExpr(Expr *E) {        return getSema().Owned(E->Retain());      } - -    /// \brief Transforms a typename type by determining whether the type now -    /// refers to a member of the current instantiation, and then -    /// type-checking and building an ElaboratedType (when possible). -    QualType TransformDependentNameType(TypeLocBuilder &TLB, -                                        DependentNameTypeLoc TL, -                                        QualType ObjectType);    };  } -QualType -CurrentInstantiationRebuilder::TransformDependentNameType(TypeLocBuilder &TLB, -                                                     DependentNameTypeLoc TL,  -                                                     QualType ObjectType) { -  DependentNameType *T = TL.getTypePtr(); - -  NestedNameSpecifier *NNS -    = TransformNestedNameSpecifier(T->getQualifier(), -                                   TL.getQualifierRange(), -                                   ObjectType); -  if (!NNS) -    return QualType(); - -  // If the nested-name-specifier did not change, and we cannot compute the -  // context corresponding to the nested-name-specifier, then this -  // typename type will not change; exit early. -  CXXScopeSpec SS; -  SS.setRange(TL.getQualifierRange()); -  SS.setScopeRep(NNS); - -  QualType Result; -  if (NNS == T->getQualifier() && getSema().computeDeclContext(SS) == 0) -    Result = QualType(T, 0); - -  // Rebuild the typename type, which will probably turn into a -  // ElaboratedType. -  else if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { -    QualType NewTemplateId -      = TransformType(QualType(TemplateId, 0)); -    if (NewTemplateId.isNull()) -      return QualType(); - -    if (NNS == T->getQualifier() && -        NewTemplateId == QualType(TemplateId, 0)) -      Result = QualType(T, 0); -    else -      Result = getDerived().RebuildDependentNameType(T->getKeyword(), -                                                     NNS, NewTemplateId); -  } else -    Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, -                                                   T->getIdentifier(), -                                                   TL.getKeywordLoc(), -                                                   TL.getQualifierRange(), -                                                   TL.getNameLoc()); - -  if (Result.isNull()) -    return QualType(); - -  if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { -    QualType NamedT = ElabT->getNamedType(); -    if (isa<TemplateSpecializationType>(NamedT)) { -      TemplateSpecializationTypeLoc NamedTLoc -        = TLB.push<TemplateSpecializationTypeLoc>(NamedT); -      // FIXME: fill locations -      NamedTLoc.initializeLocal(TL.getNameLoc()); -    } else { -      TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); -    } -    ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); -    NewTL.setKeywordLoc(TL.getKeywordLoc()); -    NewTL.setQualifierRange(TL.getQualifierRange()); -  } -  else { -    DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); -    NewTL.setKeywordLoc(TL.getKeywordLoc()); -    NewTL.setQualifierRange(TL.getQualifierRange()); -    NewTL.setNameLoc(TL.getNameLoc()); -  } -  return Result; -} -  /// \brief Rebuilds a type within the context of the current instantiation.  ///  /// The type \p T is part of the type of an out-of-line member definition of | 

