void ReplaceDependentName::handleOneElaboratedTypeLoc(
       const ElaboratedTypeLoc &TLoc)
{
  SourceLocation Loc = TLoc.getBeginLoc();
  if (Loc.isInvalid() || isInIncludedFile(Loc))
    return;

  const ElaboratedType *ET = TLoc.getTypePtr();
  if ((ET->getKeyword() != ETK_Typename) && (ET->getKeyword() != ETK_None))
    return;

  if (TLoc.getQualifierLoc().getBeginLoc().isInvalid())
    return;
  std::string Str = "";
  if (ValidInstanceNum == 8)
    TransAssert(ET);
  bool Typename = false;
  if (!getTypeString(ET->getNamedType(), Str, Typename))
    return;
  std::string TyStr = "";
  ET->getNamedType().getAsStringInternal(TyStr, Context->getPrintingPolicy());
  if (TyStr == Str)
    return;
  
  ValidInstanceNum++;
  if (ValidInstanceNum == TransformationCounter) {
    TheTyName = Str;
    NeedTypenameKeyword = Typename;
    TheLocBegin = getElaboratedTypeLocBegin(TLoc);
    TheNameLocEnd = TLoc.getEndLoc();
  }
}
SourceLocation ReplaceDependentName::getElaboratedTypeLocBegin(
                 const ElaboratedTypeLoc &TLoc)
{
  SourceLocation Loc = TLoc.getElaboratedKeywordLoc();
  if (Loc.isValid())
    return Loc;
  NestedNameSpecifierLoc SpecLoc = TLoc.getQualifierLoc();
  NestedNameSpecifierLoc Prefix = SpecLoc.getPrefix();

  while (Prefix.getBeginLoc().isValid()) {
    SpecLoc = Prefix;
    Prefix = Prefix.getPrefix();
  }
  Loc = SpecLoc.getBeginLoc();
  TransAssert(Loc.isValid() && "Failed to get ElaboratedTypeLoc!");
  return Loc;
}
Exemplo n.º 3
0
// Handle cases like:
// struct S {
//   typedef int Int;
// };
// S::Int g;
// where S::Int is referred as an ElaboratedType
bool ReplaceSimpleTypedefRewriteVisitor::VisitElaboratedTypeLoc(
       ElaboratedTypeLoc Loc)
{
  const ElaboratedType *ETy = dyn_cast<ElaboratedType>(Loc.getTypePtr());
  const Type *NamedTy = ETy->getNamedType().getTypePtr();
  const TypedefType *TdefTy = NamedTy->getAs<TypedefType>();
  if (!TdefTy)
    return true; 

  const TypedefDecl *TdefD = dyn_cast<TypedefDecl>(TdefTy->getDecl());
  if (!TdefD || (dyn_cast<TypedefDecl>(TdefD->getCanonicalDecl()) != 
                 ConsumerInstance->TheTypedefDecl)) {
    return true;
  }

  NestedNameSpecifierLoc QualifierLoc = Loc.getQualifierLoc();
  if (QualifierLoc && ConsumerInstance->IsScalarType) {
    ConsumerInstance->TheRewriter.RemoveText(QualifierLoc.getSourceRange());
  }
  return true;
}