本文整理汇总了C++中NestedNameSpecifierLoc类的典型用法代码示例。如果您正苦于以下问题:C++ NestedNameSpecifierLoc类的具体用法?C++ NestedNameSpecifierLoc怎么用?C++ NestedNameSpecifierLoc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NestedNameSpecifierLoc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Expr
// DependentScopeDeclRefExpr
DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *Args)
: Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
true, true,
(NameInfo.isInstantiationDependent() ||
(QualifierLoc &&
QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
(NameInfo.containsUnexpandedParameterPack() ||
(QualifierLoc &&
QualifierLoc.getNestedNameSpecifier()
->containsUnexpandedParameterPack()))),
QualifierLoc(QualifierLoc), NameInfo(NameInfo),
HasExplicitTemplateArgs(Args != 0)
{
if (Args) {
bool Dependent = true;
bool InstantiationDependent = true;
bool ContainsUnexpandedParameterPack
= ExprBits.ContainsUnexpandedParameterPack;
reinterpret_cast<ASTTemplateArgumentListInfo*>(this+1)
->initializeFrom(*Args, Dependent, InstantiationDependent,
ContainsUnexpandedParameterPack);
ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
}
}
示例2: TransAssert
bool RemoveNamespaceRewriteVisitor::VisitUsingDecl(UsingDecl *D)
{
if (ConsumerInstance->isForUsingNamedDecls)
return true;
if (ConsumerInstance->UselessUsingDecls.count(D)) {
ConsumerInstance->RewriteHelper->removeDecl(D);
return true;
}
// check if this UsingDecl refers to the namespaced being removed
NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
TransAssert(QualifierLoc && "Bad QualifierLoc!");
NestedNameSpecifierLoc PrefixLoc = QualifierLoc.getPrefix();
const NestedNameSpecifier *NNS = D->getQualifier();
TransAssert(NNS && "Bad NameSpecifier!");
if (ConsumerInstance->isTheNamespaceSpecifier(NNS) &&
(!PrefixLoc || ConsumerInstance->isGlobalNamespace(PrefixLoc))) {
ConsumerInstance->RewriteHelper->removeDecl(D);
SkipTraverseNestedNameSpecifier = true;
}
return true;
}
示例3: TraverseNestedNameSpecifierLoc
bool RemoveNamespaceRewriteVisitor::VisitNamespaceAliasDecl(
NamespaceAliasDecl *D)
{
if (ConsumerInstance->isForUsingNamedDecls)
return true;
const NamespaceDecl *CanonicalND =
D->getNamespace()->getCanonicalDecl();
if (D->getQualifier()) {
TraverseNestedNameSpecifierLoc(D->getQualifierLoc());
if (CanonicalND == ConsumerInstance->TheNamespaceDecl) {
NestedNameSpecifierLoc QualLoc = D->getQualifierLoc();
SourceLocation QualEndLoc = QualLoc.getEndLoc();
SourceLocation DeclEndLoc = D->getSourceRange().getEnd();
ConsumerInstance->TheRewriter.RemoveText(
SourceRange(QualEndLoc, DeclEndLoc));
}
}
else {
if (CanonicalND == ConsumerInstance->TheNamespaceDecl)
ConsumerInstance->RewriteHelper->removeDecl(D);
}
return true;
}
示例4: getQualifierAsString
void RewriteUtils::getQualifierAsString(NestedNameSpecifierLoc Loc,
std::string &Str)
{
SourceLocation StartLoc = Loc.getBeginLoc();
TransAssert(StartLoc.isValid() && "Bad StartLoc for NestedNameSpecifier!");
SourceRange Range = Loc.getSourceRange();
int Len = TheRewriter->getRangeSize(Range);
const char *StartBuf = SrcManager->getCharacterData(StartLoc);
Str.assign(StartBuf, Len);
}
示例5: SourceRange
SourceRange NestedNameSpecifierLoc::getSourceRange() const {
if (!Qualifier)
return SourceRange();
NestedNameSpecifierLoc First = *this;
while (NestedNameSpecifierLoc Prefix = First.getPrefix())
First = Prefix;
return SourceRange(First.getLocalSourceRange().getBegin(),
getLocalSourceRange().getEnd());
}
示例6: TransAssert
bool RewriteUtils::removeSpecifier(NestedNameSpecifierLoc Loc)
{
SourceRange LocRange = Loc.getLocalSourceRange();
TransAssert((TheRewriter->getRangeSize(LocRange) != -1) &&
"Bad NestedNameSpecifierLoc Range!");
return !(TheRewriter->RemoveText(LocRange));
}
示例7: handleOneUsingShadowDecl
// A using declaration in the removed namespace could cause
// name conflict, e.g.,
// namespace NS1 {
// void foo(void) {}
// }
// namespace NS2 {
// using NS1::foo;
// void bar() { ... foo(); ... }
// }
// void foo() {...}
// void func() {... foo(); ...}
// if we remove NS2, then foo() in func() will become ambiguous.
// In this case, we need to replace the first invocation of foo()
// with NS1::foo()
void RemoveNamespace::handleOneUsingShadowDecl(const UsingShadowDecl *UD,
const DeclContext *ParentCtx)
{
const NamedDecl *ND = UD->getTargetDecl();
if (!hasNameConflict(ND, ParentCtx))
return;
std::string NewName;
const UsingDecl *D = UD->getUsingDecl();
NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
NestedNameSpecifier *NNS = QualifierLoc.getNestedNameSpecifier();
// QualifierLoc could be ::foo, whose PrefixLoc is invalid, e.g.,
// void foo();
// namespace NS2 {
// using ::foo;
// void bar () { foo(); }
// }
if (NNS->getKind() != NestedNameSpecifier::Global) {
// NestedNameSpecifierLoc PrefixLoc = QualifierLoc.getPrefix();
RewriteHelper->getQualifierAsString(QualifierLoc, NewName);
}
if ( const TemplateDecl *TD = dyn_cast<TemplateDecl>(ND) ) {
ND = TD->getTemplatedDecl();
}
// NewName += "::";
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
if (FD && FD->isOverloadedOperator()) {
const char *Op = clang::getOperatorSpelling(FD->getOverloadedOperator());
std::string OpStr(Op);
NewName += ("operator::" + OpStr);
}
else {
const IdentifierInfo *IdInfo = ND->getIdentifier();
TransAssert(IdInfo && "Invalid IdentifierInfo!");
NewName += IdInfo->getName();
}
UsingNamedDeclToNewName[ND] = NewName;
// the tied UsingDecl becomes useless, and hence it's removable
UselessUsingDecls.insert(D);
}
示例8: Adopt
void NestedNameSpecifierLocBuilder::Adopt(NestedNameSpecifierLoc Other) {
if (BufferCapacity)
free(Buffer);
if (!Other) {
Representation = 0;
BufferSize = 0;
return;
}
// Rather than copying the data (which is wasteful), "adopt" the
// pointer (which points into the ASTContext) but set the capacity to zero to
// indicate that we don't own it.
Representation = Other.getNestedNameSpecifier();
Buffer = static_cast<char *>(Other.getOpaqueData());
BufferSize = Other.getDataLength();
BufferCapacity = 0;
}
示例9: Adopt
void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) {
if (!Other) {
Range = SourceRange();
Builder.Clear();
return;
}
Range = Other.getSourceRange();
Builder.Adopt(Other);
}
示例10: VisitElaboratedTypeLoc
// 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;
}
示例11: VisitCallExpr
bool VisitCallExpr(CallExpr *E) {
llvm::errs() << "I see a CallExpr\n";
E->dump();
Expr *callee = E->getCallee();
if (ImplicitCastExpr *ica = llvm::dyn_cast<ImplicitCastExpr>(callee)) {
callee = ica->getSubExpr();
}
if (DeclRefExpr *dref = llvm::dyn_cast<DeclRefExpr>(callee)) {
llvm::errs() << "declref:\n";
dref->dump();
NamedDecl *d = dref->getFoundDecl();
ASTContext &Context = d->getASTContext();
SourceManager &SM = Context.getSourceManager();
if (dref->hasQualifier()) {
llvm::errs() << " has qualifier in name.\n";
NestedNameSpecifierLoc lc = dref->getQualifierLoc();
llvm::errs() << " begin loc: " << lc.getBeginLoc().printToString(SM)
<< "\n";
llvm::errs() << " end loc: " << lc.getEndLoc().printToString(SM)
<< "\n";
}
if (UsingShadowDecl *sh = llvm::dyn_cast<UsingShadowDecl>(d)) {
NamedDecl *td = sh->getTargetDecl();
FoundRealDecl(td);
//d->dump();
} else {
FoundRealDecl(d);
//d->dump();
}
} else if (UnresolvedLookupExpr *ule = dyn_cast<UnresolvedLookupExpr>(callee)) {
llvm::errs() << "unresolved\n";
ASTContext* Context;
SourceManager* SM;
for (const auto *d : ule->decls()) {
FoundRealDecl(d);
Context = &d->getASTContext();
SM = &Context->getSourceManager();
}
llvm::errs() << " begin loc: " << ule->getLocStart().printToString(*SM)
<< "\n";
llvm::errs() << " end loc: " << ule->getLocEnd().printToString(*SM)
<< "\n";
NestedNameSpecifierLoc ll = ule->getQualifierLoc();
llvm::errs() << " nested begin loc: "
<< ll.getBeginLoc().printToString(*SM) << "\n";
llvm::errs() << " nested end loc: "
<< ll.getEndLoc().printToString(*SM) << "\n";
}
return true;
}
示例12: indexNestedNameSpecifierLoc
void IndexingContext::indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
const NamedDecl *Parent,
const DeclContext *DC) {
if (!NNS)
return;
if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
indexNestedNameSpecifierLoc(Prefix, Parent, DC);
if (!DC)
DC = Parent->getLexicalDeclContext();
SourceLocation Loc = NNS.getSourceRange().getBegin();
switch (NNS.getNestedNameSpecifier()->getKind()) {
case NestedNameSpecifier::Identifier:
case NestedNameSpecifier::Global:
case NestedNameSpecifier::Super:
break;
case NestedNameSpecifier::Namespace:
handleReference(NNS.getNestedNameSpecifier()->getAsNamespace(),
Loc, Parent, DC, SymbolRoleSet());
break;
case NestedNameSpecifier::NamespaceAlias:
handleReference(NNS.getNestedNameSpecifier()->getAsNamespaceAlias(),
Loc, Parent, DC, SymbolRoleSet());
break;
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate:
indexTypeLoc(NNS.getTypeLoc(), Parent, DC);
break;
}
}
示例13: getSpecifierAsString
void RewriteUtils::getSpecifierAsString(NestedNameSpecifierLoc Loc,
std::string &Str)
{
SourceLocation StartLoc = Loc.getBeginLoc();
TransAssert(StartLoc.isValid() && "Bad StartLoc for NestedNameSpecifier!");
const char *StartBuf = SrcManager->getCharacterData(StartLoc);
const char *OrigBuf = StartBuf;
unsigned int Len = 0;
while (!isspace(*StartBuf) && (*StartBuf != ':')) {
StartBuf++;
Len++;
}
Str.assign(OrigBuf, Len);
}
示例14: getElaboratedTypeLocBegin
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;
}
示例15: processQualifierLoc
// fix the "B" part of names like A::B::C if B is our target
void TypeRenameTransform::processQualifierLoc(NestedNameSpecifierLoc NNSL,
bool forceRewriteMacro)
{
while (NNSL) {
auto NNS = NNSL.getNestedNameSpecifier();
auto NNSK = NNS->getKind();
if (NNSK == NestedNameSpecifier::TypeSpec ||
NNSK == NestedNameSpecifier::TypeSpecWithTemplate) {
processTypeLoc(NNSL.getTypeLoc(), forceRewriteMacro);
}
else if (NNSK == NestedNameSpecifier::Namespace) {
std::string newName;
if (nameMatches(NNS->getAsNamespace(), newName, true)) {
renameLocation(NNSL.getLocalBeginLoc(), newName);
}
processTypeLoc(NNSL.getTypeLoc(), forceRewriteMacro);
}
else if (NNSK == NestedNameSpecifier::NamespaceAlias) {
std::string newName;
if (nameMatches(NNS->getAsNamespaceAlias(), newName, true)) {
renameLocation(NNSL.getLocalBeginLoc(), newName);
}
processTypeLoc(NNSL.getTypeLoc(), forceRewriteMacro);
}
// else {
// auto srcrange = NNSL.getSourceRange();
// llvm::errs() << indent()
// << "==> ??? (" << ii << ") "
// << " range=[" << range(srcrange)
// << "\n";
// break;
// }
NNSL = NNSL.getPrefix();
}
}