本文整理汇总了C++中TypeLoc类的典型用法代码示例。如果您正苦于以下问题:C++ TypeLoc类的具体用法?C++ TypeLoc怎么用?C++ TypeLoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TypeLoc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TransAssert
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.getBeginLoc();
TransAssert(LocStart.isValid() && "Invalid Location!");
ConsumerInstance->TheRewriter.ReplaceText(
LocStart, CXXRD->getNameAsString().size(), Name);
}
return true;
}
示例2: while
SourceLocation TypeLoc::getEndLoc() const {
TypeLoc Cur = *this;
TypeLoc Last;
while (true) {
switch (Cur.getTypeLocClass()) {
default:
if (!Last)
Last = Cur;
return Last.getLocalSourceRange().getEnd();
case Paren:
case ConstantArray:
case DependentSizedArray:
case IncompleteArray:
case VariableArray:
case FunctionProto:
case FunctionNoProto:
Last = Cur;
break;
case Pointer:
case BlockPointer:
case MemberPointer:
case LValueReference:
case RValueReference:
case PackExpansion:
if (!Last)
Last = Cur;
break;
case Qualified:
case Elaborated:
break;
}
Cur = Cur.getNextTypeLoc();
}
}
示例3: isEnumRawType
static bool isEnumRawType(const Decl* D, TypeLoc TL) {
assert (TL.getType());
if (auto ED = dyn_cast<EnumDecl>(D)) {
return ED->hasRawType() && ED->getRawType()->isEqual(TL.getType());
}
return false;
}
示例4: isNonVoidReturnFunction
bool ReturnVoid::isNonVoidReturnFunction(FunctionDecl *FD)
{
// Avoid duplications
if (std::find(ValidFuncDecls.begin(),
ValidFuncDecls.end(), FD) !=
ValidFuncDecls.end())
return false;
// this function happen to have a library function, e.g. strcpy,
// then the type source info won't be available, let's try to
// get one from the one which is in the source
if (!FD->getTypeSourceInfo()) {
const FunctionDecl *FirstFD = FD->getFirstDeclaration();
FD = NULL;
for (FunctionDecl::redecl_iterator I = FirstFD->redecls_begin(),
E = FirstFD->redecls_end(); I != E; ++I) {
if ((*I)->getTypeSourceInfo()) {
FD = (*I);
break;
}
}
if (!FD)
return false;
}
TypeLoc TLoc = FD->getTypeSourceInfo()->getTypeLoc();
SourceLocation SLoc = TLoc.getBeginLoc();
if (SLoc.isInvalid())
return false;
QualType RVType = FD->getResultType();
return !(RVType.getTypePtr()->isVoidType());
}
示例5: assert
TemplateArgumentLoc
Sema::getTemplateArgumentPackExpansionPattern(
TemplateArgumentLoc OrigLoc,
SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
const TemplateArgument &Argument = OrigLoc.getArgument();
assert(Argument.isPackExpansion());
switch (Argument.getKind()) {
case TemplateArgument::Type: {
// FIXME: We shouldn't ever have to worry about missing
// type-source info!
TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
if (!ExpansionTSInfo)
ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
Ellipsis);
PackExpansionTypeLoc Expansion =
ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
Ellipsis = Expansion.getEllipsisLoc();
TypeLoc Pattern = Expansion.getPatternLoc();
NumExpansions = Expansion.getTypePtr()->getNumExpansions();
// We need to copy the TypeLoc because TemplateArgumentLocs store a
// TypeSourceInfo.
// FIXME: Find some way to avoid the copy?
TypeLocBuilder TLB;
TLB.pushFullCopy(Pattern);
TypeSourceInfo *PatternTSInfo =
TLB.getTypeSourceInfo(Context, Pattern.getType());
return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
PatternTSInfo);
}
case TemplateArgument::Expression: {
PackExpansionExpr *Expansion
= cast<PackExpansionExpr>(Argument.getAsExpr());
Expr *Pattern = Expansion->getPattern();
Ellipsis = Expansion->getEllipsisLoc();
NumExpansions = Expansion->getNumExpansions();
return TemplateArgumentLoc(Pattern, Pattern);
}
case TemplateArgument::TemplateExpansion:
Ellipsis = OrigLoc.getTemplateEllipsisLoc();
NumExpansions = Argument.getNumTemplateExpansions();
return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
OrigLoc.getTemplateQualifierLoc(),
OrigLoc.getTemplateNameLoc());
case TemplateArgument::Declaration:
case TemplateArgument::NullPtr:
case TemplateArgument::Template:
case TemplateArgument::Integral:
case TemplateArgument::Pack:
case TemplateArgument::Null:
return TemplateArgumentLoc();
}
llvm_unreachable("Invalid TemplateArgument Kind!");
}
示例6: processLambdaExpr
void RedundantVoidArgCheck::processLambdaExpr(
const MatchFinder::MatchResult &Result, const LambdaExpr *Lambda) {
if (Lambda->getLambdaClass()->getLambdaCallOperator()->getNumParams() == 0 &&
Lambda->hasExplicitParameters()) {
SourceManager *SM = Result.SourceManager;
TypeLoc TL = Lambda->getLambdaClass()->getLambdaTypeInfo()->getTypeLoc();
removeVoidArgumentTokens(Result,
{SM->getSpellingLoc(TL.getBeginLoc()),
SM->getSpellingLoc(TL.getEndLoc())},
"lambda expression");
}
}
示例7: extendedTypeIsPrivate
static bool extendedTypeIsPrivate(TypeLoc inheritedType) {
if (!inheritedType.getType())
return true;
SmallVector<ProtocolDecl *, 2> protocols;
if (!inheritedType.getType()->isAnyExistentialType(protocols)) {
// Be conservative. We don't know how to deal with other extended types.
return false;
}
return std::all_of(protocols.begin(), protocols.end(), declIsPrivate);
}
示例8: revertDependentTypeLoc
static void revertDependentTypeLoc(TypeLoc &tl) {
// If there's no type representation, there's nothing to revert.
if (!tl.getTypeRepr())
return;
// Don't revert an error type; we've already complained.
if (tl.wasValidated() && tl.isError())
return;
// Make sure we validate the type again.
tl.setType(Type());
}
示例9: VisitValueDecl
void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
VisitValueDecl(DD);
QualType InfoTy = Reader.GetType(Record[Idx++]);
if (InfoTy.isNull())
return;
DeclaratorInfo *DInfo = Reader.getContext()->CreateDeclaratorInfo(InfoTy);
TypeLocReader TLR(Reader, Record, Idx);
for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
TLR.Visit(TL);
DD->setDeclaratorInfo(DInfo);
}
示例10: Extend
void NestedNameSpecifierLocBuilder::Extend(ASTContext &Context,
SourceLocation TemplateKWLoc,
TypeLoc TL,
SourceLocation ColonColonLoc) {
Representation = NestedNameSpecifier::Create(Context, Representation,
TemplateKWLoc.isValid(),
TL.getTypePtr());
// Push source-location info into the buffer.
SavePointer(TL.getOpaqueData(), Buffer, BufferSize, BufferCapacity);
SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
}
示例11: diag
void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("Ctor");
const auto *ParamDecl = Result.Nodes.getNodeAs<ParmVarDecl>("Param");
const auto *Initializer =
Result.Nodes.getNodeAs<CXXCtorInitializer>("Initializer");
SourceManager &SM = *Result.SourceManager;
// If the parameter is used or anything other than the copy, do not apply
// the changes.
if (!paramReferredExactlyOnce(Ctor, ParamDecl))
return;
// If the parameter is trivial to copy, don't move it. Moving a trivivally
// copyable type will cause a problem with misc-move-const-arg
if (ParamDecl->getType().isTriviallyCopyableType(*Result.Context))
return;
auto Diag = diag(ParamDecl->getLocStart(), "pass by value and use std::move");
// Iterate over all declarations of the constructor.
for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
auto ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
auto RefTL = ParamTL.getAs<ReferenceTypeLoc>();
// Do not replace if it is already a value, skip.
if (RefTL.isNull())
continue;
TypeLoc ValueTL = RefTL.getPointeeLoc();
auto TypeRange = CharSourceRange::getTokenRange(ParmDecl->getLocStart(),
ParamTL.getLocEnd());
std::string ValueStr =
Lexer::getSourceText(
CharSourceRange::getTokenRange(ValueTL.getSourceRange()), SM,
Result.Context->getLangOpts())
.str();
ValueStr += ' ';
Diag << FixItHint::CreateReplacement(TypeRange, ValueStr);
}
// Use std::move in the initialization list.
Diag << FixItHint::CreateInsertion(Initializer->getRParenLoc(), ")")
<< FixItHint::CreateInsertion(
Initializer->getLParenLoc().getLocWithOffset(1), "std::move(");
if (auto IncludeFixit = Inserter->CreateIncludeInsertion(
Result.SourceManager->getFileID(Initializer->getSourceLocation()),
"utility",
/*IsAngled=*/true)) {
Diag << *IncludeFixit;
}
}
示例12: TransAssert
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;
}
示例13: while
SourceLocation TypeLoc::getEndLoc() const {
TypeLoc Cur = *this;
while (true) {
switch (Cur.getTypeLocClass()) {
default:
break;
case Qualified:
case Elaborated:
Cur = Cur.getNextTypeLoc();
continue;
}
break;
}
return Cur.getLocalSourceRange().getEnd();
}
示例14: run
virtual void run(const MatchFinder::MatchResult &Result) {
auto *d = Result.Nodes.getNodeAs<CXXConstructorDecl>("stuff");
if (d) {
if (d->getNumCtorInitializers() > 0) {
const CXXCtorInitializer *firstinit = *d->init_begin();
if (!firstinit->isWritten()) {
llvm::errs() << "firstinit not written; skipping\n";
return;
}
if (firstinit->isBaseInitializer()) {
TypeLoc basetypeloc = firstinit->getBaseClassLoc();
llvm::errs() << "firstinit as base loc: "
<< basetypeloc.getBeginLoc().printToString(
*Result.SourceManager) << "\n";
}
SourceLocation initloc = firstinit->getSourceLocation();
llvm::errs() << "firstinit loc: "
<< initloc.printToString(*Result.SourceManager) << "\n";
SourceRange initrange = firstinit->getSourceRange();
llvm::errs() << "firstinit range from "
<< initrange.getBegin().printToString(
*Result.SourceManager) << "\n";
llvm::errs() << "firstinit range to "
<< initrange.getEnd().printToString(
*Result.SourceManager) << "\n";
SourceLocation start = firstinit->getLParenLoc();
llvm::errs() << "firstinit start: "
<< start.printToString(*Result.SourceManager) << "\n";
Token tok_id = GetTokenBeforeLocation(start, *Result.Context);
llvm::errs() << " tok_id: "
<< tok_id.getLocation().printToString(
*Result.SourceManager) << "\n";
Token tok_colon =
GetTokenBeforeLocation(tok_id.getLocation(), *Result.Context);
llvm::errs() << " tok_colon: "
<< tok_colon.getLocation().printToString(
*Result.SourceManager) << "\n";
const CXXCtorInitializer *lastinit = *d->init_rbegin();
SourceLocation end = lastinit->getRParenLoc();
llvm::errs() << "lastinit end: "
<< end.printToString(*Result.SourceManager) << "\n";
//init->getInit()->dump();
}
}
}
示例15: switch
void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
ObjCContainerDecl *CDecl,
ObjCMethodDecl *OM) {
ObjCInstanceTypeFamily OIT_Family =
Selector::getInstTypeMethodFamily(OM->getSelector());
if (OIT_Family == OIT_None)
return;
// TODO. Many more to come
switch (OIT_Family) {
case OIT_Array:
break;
case OIT_Dictionary:
break;
default:
return;
}
if (!OM->getResultType()->isObjCIdType())
return;
ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
if (!IDecl) {
if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
IDecl = CatDecl->getClassInterface();
else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
IDecl = ImpDecl->getClassInterface();
}
if (!IDecl)
return;
if (OIT_Family == OIT_Array &&
!IDecl->lookupInheritedClass(&Ctx.Idents.get("NSArray")))
return;
else if (OIT_Family == OIT_Dictionary &&
!IDecl->lookupInheritedClass(&Ctx.Idents.get("NSDictionary")))
return;
TypeSourceInfo *TSInfo = OM->getResultTypeSourceInfo();
TypeLoc TL = TSInfo->getTypeLoc();
SourceRange R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
edit::Commit commit(*Editor);
std::string ClassString = "instancetype";
commit.replace(R, ClassString);
Editor->commit(commit);
}