本文整理汇总了C++中TypeLoc::getLocStart方法的典型用法代码示例。如果您正苦于以下问题:C++ TypeLoc::getLocStart方法的具体用法?C++ TypeLoc::getLocStart怎么用?C++ TypeLoc::getLocStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeLoc
的用法示例。
在下文中一共展示了TypeLoc::getLocStart方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VisitClassTemplatePartialSpecializationDecl
bool RemoveNamespaceRewriteVisitor::VisitClassTemplatePartialSpecializationDecl(
ClassTemplatePartialSpecializationDecl *D)
{
const Type *Ty = D->getInjectedSpecializationType().getTypePtr();
TransAssert(Ty && "Bad TypePtr!");
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();
TransAssert(ND && "Invalid NamedDecl!");
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ND);
TransAssert(CXXRD && "Invalid CXXRecordDecl!");
std::string Name;
if (ConsumerInstance->getNewName(CXXRD, Name)) {
const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
if (!TyInfo)
return true;
TypeLoc TyLoc = TyInfo->getTypeLoc();
SourceLocation LocStart = TyLoc.getLocStart();
TransAssert(LocStart.isValid() && "Invalid Location!");
ConsumerInstance->TheRewriter.ReplaceText(
LocStart, CXXRD->getNameAsString().size(), Name);
}
return true;
}
示例2: getVarDeclTypeLocBegin
SourceLocation RewriteUtils::getVarDeclTypeLocBegin(const VarDecl *VD)
{
TypeLoc VarTypeLoc = VD->getTypeSourceInfo()->getTypeLoc();
TypeLoc NextTL = VarTypeLoc.getNextTypeLoc();
while (!NextTL.isNull()) {
VarTypeLoc = NextTL;
NextTL = NextTL.getNextTypeLoc();
}
return VarTypeLoc.getLocStart();
}
示例3: VisitElaboratedTypeLoc
bool EmptyStructToIntRewriteVisitor::VisitElaboratedTypeLoc(
ElaboratedTypeLoc Loc)
{
const ElaboratedType *ETy = dyn_cast<ElaboratedType>(Loc.getTypePtr());
const Type *NamedTy = ETy->getNamedType().getTypePtr();
const RecordType *RDTy = NamedTy->getAs<RecordType>();
if (!RDTy)
return true;
const RecordDecl *RD = RDTy->getDecl();
TransAssert(RD && "NULL RecordDecl!");
if (RD->getCanonicalDecl() != ConsumerInstance->TheRecordDecl) {
return true;
}
SourceLocation StartLoc = Loc.getLocStart();
if (StartLoc.isInvalid())
return true;
TypeLoc TyLoc = Loc.getNamedTypeLoc();
SourceLocation EndLoc = TyLoc.getLocStart();
if (EndLoc.isInvalid())
return true;
EndLoc = EndLoc.getLocWithOffset(-1);
const char *StartBuf =
ConsumerInstance->SrcManager->getCharacterData(StartLoc);
const char *EndBuf = ConsumerInstance->SrcManager->getCharacterData(EndLoc);
ConsumerInstance->Rewritten = true;
// It's possible, e.g.,
// struct S1 {
// struct { } S;
// };
// Clang will translate struct { } S to
// struct {
// };
// struct <anonymous struct ...> S;
// the last declaration is injected by clang.
// We need to omit it.
if (StartBuf > EndBuf) {
SourceLocation KeywordLoc = Loc.getElaboratedKeywordLoc();
const llvm::StringRef Keyword =
TypeWithKeyword::getKeywordName(ETy->getKeyword());
ConsumerInstance->TheRewriter.ReplaceText(KeywordLoc,
Keyword.size(), "int");
return true;
}
ConsumerInstance->TheRewriter.RemoveText(SourceRange(StartLoc, EndLoc));
return true;
}