Пример #1
0
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;
}
Пример #2
0
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;
}