当前位置: 首页>>代码示例>>C++>>正文


C++ TemplateSpecializationTypeLoc类代码示例

本文整理汇总了C++中TemplateSpecializationTypeLoc的典型用法代码示例。如果您正苦于以下问题:C++ TemplateSpecializationTypeLoc类的具体用法?C++ TemplateSpecializationTypeLoc怎么用?C++ TemplateSpecializationTypeLoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TemplateSpecializationTypeLoc类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: VisitTemplateSpecializationTypeLoc

bool ClassTemplateToClassSpecializationTypeRewriteVisitor::
       VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc Loc)
{
  const TemplateSpecializationType *Ty = 
    dyn_cast<TemplateSpecializationType>(Loc.getTypePtr());
  TransAssert(Ty && "Invalid TemplateSpecializationType!");

  TemplateName TmplName = Ty->getTemplateName();
  if (!ConsumerInstance->referToTheTemplateDecl(TmplName))
    return true;

  SourceLocation TmplKeyLoc = Loc.getTemplateKeywordLoc();
  if (TmplKeyLoc.isValid())
    ConsumerInstance->TheRewriter.RemoveText(TmplKeyLoc, 8);

  // it's necessary to check the validity of locations, otherwise
  // we will get assertion errors...
  // note that some implicit typeloc has been visited by Clang, e.g.
  // template < typename > struct A { };
  // struct B:A < int > {
  //  B (  ) { }
  // };
  // base initializer A<int> is not presented in the code but visited,
  // so, we need to make sure locations are valid.
  SourceLocation LAngleLoc = Loc.getLAngleLoc();
  if (LAngleLoc.isInvalid())
    return true;
  SourceLocation RAngleLoc = Loc.getRAngleLoc();
  if (RAngleLoc.isInvalid())
    return true;
  ConsumerInstance->TheRewriter.RemoveText(SourceRange(LAngleLoc,
                                                       RAngleLoc));
  return true;
}
开发者ID:8l,项目名称:creduce,代码行数:34,代码来源:ClassTemplateToClass.cpp

示例2: markUsed

bool
UnnecessaryIncludeFinder::VisitTemplateSpecializationTypeLoc (
    TemplateSpecializationTypeLoc typeLoc)
{
  CXXRecordDecl* pCXXRecordDecl = typeLoc.getTypePtr()->getAsCXXRecordDecl();
  if (pCXXRecordDecl) {
    markUsed(pCXXRecordDecl->getLocation(), typeLoc.getTemplateNameLoc());
  }
  return true;
}
开发者ID:rpavlik,项目名称:find-unnecessary-includes,代码行数:10,代码来源:UnnecessaryIncludeFinder.cpp

示例3: handleTemplateSpecializationTypeLoc

void TemplateArgToInt::handleTemplateSpecializationTypeLoc(
       const TemplateSpecializationTypeLoc &TLoc)
{
  const Type *Ty = TLoc.getTypePtr();
  const TemplateSpecializationType *TST = 
    Ty->getAs<TemplateSpecializationType>();
  TemplateName TplName = TST->getTemplateName();
  const TemplateDecl *TplD = TplName.getAsTemplateDecl();

  TemplateParameterIdxSet *InvalidIdx = 
    DeclToParamIdx[dyn_cast<TemplateDecl>(TplD->getCanonicalDecl())];
  if (!InvalidIdx)
    return;
  for (unsigned I = 0; I < TLoc.getNumArgs(); ++I) {
    if (!InvalidIdx->count(I))
      handleOneTemplateArgumentLoc(TLoc.getArgLoc(I));
  }
}
开发者ID:vgvassilev,项目名称:creduce,代码行数:18,代码来源:TemplateArgToInt.cpp

示例4: VisitTemplateSpecializationTypeLoc

bool ClassTemplateToClassSpecializationTypeRewriteVisitor::
       VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc Loc)
{
  const TemplateSpecializationType *Ty = 
    dyn_cast<TemplateSpecializationType>(Loc.getTypePtr());
  TransAssert(Ty && "Invalid TemplateSpecializationType!");

  TemplateName TmplName = Ty->getTemplateName();
  if (!ConsumerInstance->referToTheTemplateDecl(TmplName))
    return true;

  SourceLocation TmplKeyLoc = Loc.getTemplateKeywordLoc();
  if (TmplKeyLoc.isValid())
    ConsumerInstance->TheRewriter.RemoveText(TmplKeyLoc, 8);

  ConsumerInstance->TheRewriter.RemoveText(SourceRange(Loc.getLAngleLoc(),
                                                       Loc.getRAngleLoc()));
  return true;
}
开发者ID:annulen,项目名称:creduce,代码行数:19,代码来源:ClassTemplateToClass.cpp

示例5: VisitTemplateSpecializationTypeLoc

bool ReduceClassTemplateParameterRewriteVisitor::
       VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc Loc)
{
  // Invalidation can be introduced by constructor's initialization list, e.g.:
  // template<typename T1, typename T2> class A { };
  // class B : public A<int, int> {
  //   int m;
  //   B(int x) : m(x) {}
  // };
  // In RecursiveASTVisitor.h, TraverseConstructorInitializer will visit the part
  // of initializing base class's, i.e. through base's default constructor 
  if (Loc.getBeginLoc().isInvalid())
    return true;
  const TemplateSpecializationType *Ty = 
    dyn_cast<TemplateSpecializationType>(Loc.getTypePtr());
  TransAssert(Ty && "Invalid TemplateSpecializationType!");

  TemplateName TmplName = Ty->getTemplateName();
  if (!ConsumerInstance->referToTheTemplateDecl(TmplName))
    return true;

  unsigned NumArgs = Loc.getNumArgs();
  // I would put a stronger assert here, i.e., 
  // " (ConsumerInstance->TheParameterIndex >= NumArgs) && 
  // ConsumerInstance->hasDefaultArg "
  // but sometimes ill-formed input could yield incomplete
  // info, e.g., for two template decls which refer to the same
  // template def, one decl could have a non-null default arg,
  // while another decl's default arg field could be null. 
  if (ConsumerInstance->TheParameterIndex >= NumArgs)
    return true;

  TransAssert((ConsumerInstance->TheParameterIndex < NumArgs) &&
              "TheParameterIndex cannot be greater than NumArgs!");
  TemplateArgumentLoc ArgLoc = Loc.getArgLoc(ConsumerInstance->TheParameterIndex);
  SourceRange Range = ArgLoc.getSourceRange();

  if (NumArgs == 1) {
    ConsumerInstance->TheRewriter.ReplaceText(SourceRange(Loc.getLAngleLoc(),
                                                          Loc.getRAngleLoc()),
                                              "<>");
  }
  else if ((ConsumerInstance->TheParameterIndex + 1) == NumArgs) {
    SourceLocation EndLoc = Loc.getRAngleLoc();
    EndLoc = EndLoc.getLocWithOffset(-1);
    ConsumerInstance->RewriteHelper->removeTextFromLeftAt(
                                       Range, ',', EndLoc);
  }
  else {
    ConsumerInstance->RewriteHelper->removeTextUntil(Range, ',');
  }
  return true;
}
开发者ID:oriceemple,项目名称:creduce,代码行数:53,代码来源:ReduceClassTemplateParameter.cpp

示例6: VisitTemplateSpecializationTypeLoc

bool RemoveNamespaceRewriteVisitor::VisitTemplateSpecializationTypeLoc(
       TemplateSpecializationTypeLoc TSPLoc)
{
  const Type *Ty = TSPLoc.getTypePtr();
  const TemplateSpecializationType *TST =
    dyn_cast<TemplateSpecializationType>(Ty);
  TransAssert(TST && "Bad TemplateSpecializationType!");

  TemplateName TplName = TST->getTemplateName();
  const TemplateDecl *TplD = TplName.getAsTemplateDecl();
  TransAssert(TplD && "Invalid TemplateDecl!");
  NamedDecl *ND = TplD->getTemplatedDecl();
  // in some cases, ND could be NULL, e.g., the
  // template template parameter code below:
  // template<template<class> class BBB>
  // struct AAA {
  //   template <class T>
  //   struct CCC {
  //     static BBB<T> a;
  //   };
  // };
  // where we don't know BBB
  if (!ND)
    return true;

  const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ND);
  if (!CXXRD)
    return true;

  std::string Name;
  if (ConsumerInstance->getNewName(CXXRD, Name)) {
    SourceLocation LocStart = TSPLoc.getTemplateNameLoc();
    ConsumerInstance->TheRewriter.ReplaceText(
      LocStart, CXXRD->getNameAsString().size(), Name);
  }

  return true;
}
开发者ID:csmith-project,项目名称:creduce,代码行数:38,代码来源:RemoveNamespace.cpp

示例7: TemplateArgs

bool Sema::ActOnCXXNestedNameSpecifier(Scope *S,
                                       SourceLocation TemplateLoc, 
                                       CXXScopeSpec &SS, 
                                       TemplateTy Template,
                                       SourceLocation TemplateNameLoc,
                                       SourceLocation LAngleLoc,
                                       ASTTemplateArgsPtr TemplateArgsIn,
                                       SourceLocation RAngleLoc,
                                       SourceLocation CCLoc,
                                       bool EnteringContext) {
  if (SS.isInvalid())
    return true;
  
  // Translate the parser's template argument list in our AST format.
  TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
  translateTemplateArguments(TemplateArgsIn, TemplateArgs);

  if (DependentTemplateName *DTN = Template.get().getAsDependentTemplateName()){
    // Handle a dependent template specialization for which we cannot resolve
    // the template name.
    assert(DTN->getQualifier()
             == static_cast<NestedNameSpecifier*>(SS.getScopeRep()));
    QualType T = Context.getDependentTemplateSpecializationType(ETK_None,
                                                          DTN->getQualifier(),
                                                          DTN->getIdentifier(),
                                                                TemplateArgs);
    
    // Create source-location information for this type.
    TypeLocBuilder Builder;
    DependentTemplateSpecializationTypeLoc SpecTL 
      = Builder.push<DependentTemplateSpecializationTypeLoc>(T);
    SpecTL.setLAngleLoc(LAngleLoc);
    SpecTL.setRAngleLoc(RAngleLoc);
    SpecTL.setKeywordLoc(SourceLocation());
    SpecTL.setNameLoc(TemplateNameLoc);
    SpecTL.setQualifierLoc(SS.getWithLocInContext(Context));
    for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
      SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
    
    SS.Extend(Context, TemplateLoc, Builder.getTypeLocInContext(Context, T), 
              CCLoc);
    return false;
  }
  
  
  if (Template.get().getAsOverloadedTemplate() ||
      isa<FunctionTemplateDecl>(Template.get().getAsTemplateDecl())) {
    SourceRange R(TemplateNameLoc, RAngleLoc);
    if (SS.getRange().isValid())
      R.setBegin(SS.getRange().getBegin());
      
    Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
      << Template.get() << R;
    NoteAllFoundTemplates(Template.get());
    return true;
  }
                                
  // We were able to resolve the template name to an actual template. 
  // Build an appropriate nested-name-specifier.
  QualType T = CheckTemplateIdType(Template.get(), TemplateNameLoc, 
                                   TemplateArgs);
  if (T.isNull())
    return true;

  // Alias template specializations can produce types which are not valid
  // nested name specifiers.
  if (!T->isDependentType() && !T->getAs<TagType>()) {
    Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
    NoteAllFoundTemplates(Template.get());
    return true;
  }

  // Provide source-location information for the template specialization 
  // type.
  TypeLocBuilder Builder;
  TemplateSpecializationTypeLoc SpecTL 
    = Builder.push<TemplateSpecializationTypeLoc>(T);
  
  SpecTL.setLAngleLoc(LAngleLoc);
  SpecTL.setRAngleLoc(RAngleLoc);
  SpecTL.setTemplateNameLoc(TemplateNameLoc);
  for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
    SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());


  SS.Extend(Context, TemplateLoc, Builder.getTypeLocInContext(Context, T), 
            CCLoc);
  return false;
}
开发者ID:Bootz,项目名称:multicore-opimization,代码行数:89,代码来源:SemaCXXScopeSpec.cpp

示例8: getRange

 virtual SourceRange getRange(const TypeLoc &Node) {
   TemplateSpecializationTypeLoc T =
       Node.getUnqualifiedLoc().castAs<TemplateSpecializationTypeLoc>();
   assert(!T.isNull());
   return SourceRange(T.getLAngleLoc(), T.getRAngleLoc());
 }
开发者ID:matbd,项目名称:clang,代码行数:6,代码来源:SourceLocationTest.cpp


注:本文中的TemplateSpecializationTypeLoc类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。