本文整理汇总了C++中NamedDecl类的典型用法代码示例。如果您正苦于以下问题:C++ NamedDecl类的具体用法?C++ NamedDecl怎么用?C++ NamedDecl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NamedDecl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
FriendUnion Friend,
SourceLocation FriendL,
ArrayRef<TemplateParameterList*> FriendTypeTPLists) {
#ifndef NDEBUG
if (Friend.is<NamedDecl*>()) {
NamedDecl *D = Friend.get<NamedDecl*>();
assert(isa<FunctionDecl>(D) ||
isa<CXXRecordDecl>(D) ||
isa<FunctionTemplateDecl>(D) ||
isa<ClassTemplateDecl>(D));
// As a temporary hack, we permit template instantiation to point
// to the original declaration when instantiating members.
assert(D->getFriendObjectKind() ||
(cast<CXXRecordDecl>(DC)->getTemplateSpecializationKind()));
// These template parameters are for friend types only.
assert(FriendTypeTPLists.size() == 0);
}
#endif
std::size_t Size = sizeof(FriendDecl)
+ FriendTypeTPLists.size() * sizeof(TemplateParameterList*);
void *Mem = C.Allocate(Size);
FriendDecl *FD = new (Mem) FriendDecl(DC, L, Friend, FriendL,
FriendTypeTPLists);
cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
return FD;
}
示例2: checkUndefinedInternals
/// checkUndefinedInternals - Check for undefined objects with internal linkage.
static void checkUndefinedInternals(Sema &S) {
if (S.UndefinedInternals.empty()) return;
// Collect all the still-undefined entities with internal linkage.
SmallVector<UndefinedInternal, 16> undefined;
for (llvm::MapVector<NamedDecl*,SourceLocation>::iterator
i = S.UndefinedInternals.begin(), e = S.UndefinedInternals.end();
i != e; ++i) {
NamedDecl *decl = i->first;
// Ignore attributes that have become invalid.
if (decl->isInvalidDecl()) continue;
// If we found out that the decl is external, don't warn.
if (decl->getLinkage() == ExternalLinkage) continue;
// __attribute__((weakref)) is basically a definition.
if (decl->hasAttr<WeakRefAttr>()) continue;
if (FunctionDecl *fn = dyn_cast<FunctionDecl>(decl)) {
if (fn->isPure() || fn->hasBody())
continue;
} else {
if (cast<VarDecl>(decl)->hasDefinition() != VarDecl::DeclarationOnly)
continue;
}
S.Diag(decl->getLocation(), diag::warn_undefined_internal)
<< isa<VarDecl>(decl) << decl;
S.Diag(i->second, diag::note_used_here);
}
}
示例3: 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;
}
示例4: TemplateLoc
TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
NamedDecl **Params, unsigned NumParams,
SourceLocation RAngleLoc)
: TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
NumParams(NumParams), ContainsUnexpandedParameterPack(false) {
assert(this->NumParams == NumParams && "Too many template parameters");
for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
NamedDecl *P = Params[Idx];
begin()[Idx] = P;
if (!P->isTemplateParameterPack()) {
if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
if (NTTP->getType()->containsUnexpandedParameterPack())
ContainsUnexpandedParameterPack = true;
if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
ContainsUnexpandedParameterPack = true;
// FIXME: If a default argument contains an unexpanded parameter pack, the
// template parameter list does too.
}
}
}
示例5: getUndefinedButUsed
/// Obtains a sorted list of functions that are undefined but ODR-used.
void Sema::getUndefinedButUsed(
SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined) {
for (llvm::DenseMap<NamedDecl *, SourceLocation>::iterator
I = UndefinedButUsed.begin(), E = UndefinedButUsed.end();
I != E; ++I) {
NamedDecl *ND = I->first;
// Ignore attributes that have become invalid.
if (ND->isInvalidDecl()) continue;
// __attribute__((weakref)) is basically a definition.
if (ND->hasAttr<WeakRefAttr>()) continue;
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
if (FD->isDefined())
continue;
if (FD->hasExternalLinkage() &&
!FD->getMostRecentDecl()->isInlined())
continue;
} else {
if (cast<VarDecl>(ND)->hasDefinition() != VarDecl::DeclarationOnly)
continue;
if (ND->hasExternalLinkage())
continue;
}
Undefined.push_back(std::make_pair(ND, I->second));
}
// Sort (in order of use site) so that we're not dependent on the iteration
// order through an llvm::DenseMap.
std::sort(Undefined.begin(), Undefined.end(),
SortUndefinedButUsed(Context.getSourceManager()));
}
示例6: assert
/// Look up the std::nothrow object.
static Expr *buildStdNoThrowDeclRef(Sema &S, SourceLocation Loc) {
NamespaceDecl *Std = S.getStdNamespace();
assert(Std && "Should already be diagnosed");
LookupResult Result(S, &S.PP.getIdentifierTable().get("nothrow"), Loc,
Sema::LookupOrdinaryName);
if (!S.LookupQualifiedName(Result, Std)) {
// FIXME: <experimental/coroutine> should have been included already.
// If we require it to include <new> then this diagnostic is no longer
// needed.
S.Diag(Loc, diag::err_implicit_coroutine_std_nothrow_type_not_found);
return nullptr;
}
// FIXME: Mark the variable as ODR used. This currently does not work
// likely due to the scope at in which this function is called.
auto *VD = Result.getAsSingle<VarDecl>();
if (!VD) {
Result.suppressDiagnostics();
// We found something weird. Complain about the first thing we found.
NamedDecl *Found = *Result.begin();
S.Diag(Found->getLocation(), diag::err_malformed_std_nothrow);
return nullptr;
}
ExprResult DR = S.BuildDeclRefExpr(VD, VD->getType(), VK_LValue, Loc);
if (DR.isInvalid())
return nullptr;
return DR.get();
}
示例7: ClassifyMemberExpr
static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E) {
if (E->getType() == Ctx.UnknownAnyTy)
return (isa<FunctionDecl>(E->getMemberDecl())
? Cl::CL_PRValue : Cl::CL_LValue);
// Handle C first, it's easier.
if (!Ctx.getLangOpts().CPlusPlus) {
// C99 6.5.2.3p3
// For dot access, the expression is an lvalue if the first part is. For
// arrow access, it always is an lvalue.
if (E->isArrow())
return Cl::CL_LValue;
// ObjC property accesses are not lvalues, but get special treatment.
Expr *Base = E->getBase()->IgnoreParens();
if (isa<ObjCPropertyRefExpr>(Base))
return Cl::CL_SubObjCPropertySetting;
return ClassifyInternal(Ctx, Base);
}
NamedDecl *Member = E->getMemberDecl();
// C++ [expr.ref]p3: E1->E2 is converted to the equivalent form (*(E1)).E2.
// C++ [expr.ref]p4: If E2 is declared to have type "reference to T", then
// E1.E2 is an lvalue.
if (ValueDecl *Value = dyn_cast<ValueDecl>(Member))
if (Value->getType()->isReferenceType())
return Cl::CL_LValue;
// Otherwise, one of the following rules applies.
// -- If E2 is a static member [...] then E1.E2 is an lvalue.
if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord())
return Cl::CL_LValue;
// -- If E2 is a non-static data member [...]. If E1 is an lvalue, then
// E1.E2 is an lvalue; if E1 is an xvalue, then E1.E2 is an xvalue;
// otherwise, it is a prvalue.
if (isa<FieldDecl>(Member)) {
// *E1 is an lvalue
if (E->isArrow())
return Cl::CL_LValue;
Expr *Base = E->getBase()->IgnoreParenImpCasts();
if (isa<ObjCPropertyRefExpr>(Base))
return Cl::CL_SubObjCPropertySetting;
return ClassifyInternal(Ctx, E->getBase());
}
// -- If E2 is a [...] member function, [...]
// -- If it refers to a static member function [...], then E1.E2 is an
// lvalue; [...]
// -- Otherwise [...] E1.E2 is a prvalue.
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member))
return Method->isStatic() ? Cl::CL_LValue : Cl::CL_MemberFunction;
// -- If E2 is a member enumerator [...], the expression E1.E2 is a prvalue.
// So is everything else we haven't handled yet.
return Cl::CL_PRValue;
}
示例8: LookupDecl
void EvaluateTSynthesizer::Transform() {
if (!getTransaction()->getCompilationOpts().DynamicScoping)
return;
// include the DynamicLookup specific builtins
if (!m_EvalDecl) {
TemplateDecl* D
= cast_or_null<TemplateDecl>(m_Interpreter->LookupDecl("cling").
LookupDecl("runtime").
LookupDecl("internal").
LookupDecl("EvaluateT").
getSingleDecl());
assert(D && "Cannot find EvaluateT TemplateDecl!\n");
m_EvalDecl = dyn_cast<FunctionDecl>(D->getTemplatedDecl());
assert (m_EvalDecl && "The Eval function not found!");
}
if (m_NoRange.isInvalid()) {
NamespaceDecl* NSD = utils::Lookup::Namespace(m_Sema, "cling");
NSD = utils::Lookup::Namespace(m_Sema, "runtime", NSD);
NSD = utils::Lookup::Namespace(m_Sema, "internal", NSD);
DeclarationName Name
= &m_Context->Idents.get(
"InterpreterGeneratedCodeDiagnosticsMaybeIncorrect");
LookupResult R(*m_Sema, Name, SourceLocation(), Sema::LookupOrdinaryName,
Sema::ForRedeclaration);
m_Sema->LookupQualifiedName(R, NSD);
assert(!R.empty() && "Cannot find PrintValue(...)");
NamedDecl* ND = R.getFoundDecl();
m_NoRange = ND->getSourceRange();
m_NoSLoc = m_NoRange.getBegin();
m_NoELoc = m_NoRange.getEnd();
}
for (Transaction::const_iterator I = getTransaction()->decls_begin(),
E = getTransaction()->decls_end(); I != E; ++I)
for (DeclGroupRef::const_iterator J = (*I).begin(),
JE = (*I).end(); J != JE; ++J)
if (ShouldVisit(*J) && (*J)->hasBody()) {
if (FunctionDecl* FD = dyn_cast<FunctionDecl>(*J)) {
// Set the decl context, which is needed by Evaluate.
m_CurDeclContext = FD->getDeclContext();
ASTNodeInfo NewBody = Visit((*J)->getBody());
FD->setBody(NewBody.getAsSingleNode());
}
assert ((!isa<BlockDecl>(*J) || !isa<ObjCMethodDecl>(*J))
&& "Not implemented yet!");
}
//TODO: Check for error before returning.
}
示例9: extractFromReturnStmt
void RedundantLocalVariableRule::apply(CXCursor& node, CXCursor& parentNode, ViolationSet& violationSet) {
Stmt *stmt = CursorHelper::getStmt(node);
Stmt *parentStmt = CursorHelper::getStmt(parentNode);
if (stmt && parentStmt) {
NamedDecl *returnDeclRef = extractFromReturnStmt(stmt);
NamedDecl *namedDecl = extractFromDeclStmt(parentStmt);
if (returnDeclRef && namedDecl && returnDeclRef->getName().equals(namedDecl->getName())) {
Violation violation(node, this);
violationSet.addViolation(violation);
}
}
}
示例10: assert
void IdentifierResolver::iterator::incrementSlowCase() {
NamedDecl *D = **this;
void *InfoPtr = D->getDeclName().getFETokenInfo<void>();
assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
BaseIter I = getIterator();
if (I != Info->decls_begin())
*this = iterator(I-1);
else // No more decls.
*this = iterator();
}
示例11: R
/// \brief Called when an expression computing the size of a parameter pack
/// is parsed.
///
/// \code
/// template<typename ...Types> struct count {
/// static const unsigned value = sizeof...(Types);
/// };
/// \endcode
///
//
/// \param OpLoc The location of the "sizeof" keyword.
/// \param Name The name of the parameter pack whose size will be determined.
/// \param NameLoc The source location of the name of the parameter pack.
/// \param RParenLoc The location of the closing parentheses.
ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S,
SourceLocation OpLoc,
IdentifierInfo &Name,
SourceLocation NameLoc,
SourceLocation RParenLoc) {
// C++0x [expr.sizeof]p5:
// The identifier in a sizeof... expression shall name a parameter pack.
LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
LookupName(R, S);
NamedDecl *ParameterPack = 0;
ParameterPackValidatorCCC Validator;
switch (R.getResultKind()) {
case LookupResult::Found:
ParameterPack = R.getFoundDecl();
break;
case LookupResult::NotFound:
case LookupResult::NotFoundInCurrentInstantiation:
if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(),
R.getLookupKind(), S, 0,
Validator)) {
std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOpts()));
ParameterPack = Corrected.getCorrectionDecl();
Diag(NameLoc, diag::err_sizeof_pack_no_pack_name_suggest)
<< &Name << CorrectedQuotedStr
<< FixItHint::CreateReplacement(
NameLoc, Corrected.getAsString(getLangOpts()));
Diag(ParameterPack->getLocation(), diag::note_parameter_pack_here)
<< CorrectedQuotedStr;
}
case LookupResult::FoundOverloaded:
case LookupResult::FoundUnresolvedValue:
break;
case LookupResult::Ambiguous:
DiagnoseAmbiguousLookup(R);
return ExprError();
}
if (!ParameterPack || !ParameterPack->isParameterPack()) {
Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
<< &Name;
return ExprError();
}
MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
return new (Context) SizeOfPackExpr(Context.getSizeType(), OpLoc,
ParameterPack, NameLoc, RParenLoc);
}
示例12: VisitOMPThreadPrivateDecl
void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
Out << "#pragma omp threadprivate";
if (!D->varlist_empty()) {
for (OMPThreadPrivateDecl::varlist_iterator I = D->varlist_begin(),
E = D->varlist_end();
I != E; ++I) {
Out << (I == D->varlist_begin() ? '(' : ',');
NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
ND->printQualifiedName(Out);
}
Out << ")";
}
}
示例13: DiagnoseBadAccess
static void DiagnoseBadAccess(Sema &S, SourceLocation Loc,
const EffectiveContext &EC,
AccessTarget &Entity) {
const CXXRecordDecl *NamingClass = Entity.getNamingClass();
const CXXRecordDecl *DeclaringClass = Entity.getDeclaringClass();
NamedDecl *D = (Entity.isMemberAccess() ? Entity.getTargetDecl() : 0);
S.Diag(Loc, Entity.getDiag())
<< (Entity.getAccess() == AS_protected)
<< (D ? D->getDeclName() : DeclarationName())
<< S.Context.getTypeDeclType(NamingClass)
<< S.Context.getTypeDeclType(DeclaringClass);
DiagnoseAccessPath(S, EC, Entity);
}
示例14: matchesNodeUnqualified
bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl &Node) const {
assert(UseUnqualifiedMatch);
if (Node.getIdentifier()) {
// Simple name.
return Name == Node.getName();
}
if (Node.getDeclName()) {
// Name needs to be constructed.
llvm::SmallString<128> NodeName;
llvm::raw_svector_ostream OS(NodeName);
Node.printName(OS);
return Name == OS.str();
}
return false;
}
示例15: assert
// With -fcuda-host-device-constexpr, an unattributed constexpr function is
// treated as implicitly __host__ __device__, unless:
// * it is a variadic function (device-side variadic functions are not
// allowed), or
// * a __device__ function with this signature was already declared, in which
// case in which case we output an error, unless the __device__ decl is in a
// system header, in which case we leave the constexpr function unattributed.
//
// In addition, all function decls are treated as __host__ __device__ when
// ForceCUDAHostDeviceDepth > 0 (corresponding to code within a
// #pragma clang force_cuda_host_device_begin/end
// pair).
void Sema::maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *NewD,
const LookupResult &Previous) {
assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
if (ForceCUDAHostDeviceDepth > 0) {
if (!NewD->hasAttr<CUDAHostAttr>())
NewD->addAttr(CUDAHostAttr::CreateImplicit(Context));
if (!NewD->hasAttr<CUDADeviceAttr>())
NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context));
return;
}
if (!getLangOpts().CUDAHostDeviceConstexpr || !NewD->isConstexpr() ||
NewD->isVariadic() || NewD->hasAttr<CUDAHostAttr>() ||
NewD->hasAttr<CUDADeviceAttr>() || NewD->hasAttr<CUDAGlobalAttr>())
return;
// Is D a __device__ function with the same signature as NewD, ignoring CUDA
// attributes?
auto IsMatchingDeviceFn = [&](NamedDecl *D) {
if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(D))
D = Using->getTargetDecl();
FunctionDecl *OldD = D->getAsFunction();
return OldD && OldD->hasAttr<CUDADeviceAttr>() &&
!OldD->hasAttr<CUDAHostAttr>() &&
!IsOverload(NewD, OldD, /* UseMemberUsingDeclRules = */ false,
/* ConsiderCudaAttrs = */ false);
};
auto It = llvm::find_if(Previous, IsMatchingDeviceFn);
if (It != Previous.end()) {
// We found a __device__ function with the same name and signature as NewD
// (ignoring CUDA attrs). This is an error unless that function is defined
// in a system header, in which case we simply return without making NewD
// host+device.
NamedDecl *Match = *It;
if (!getSourceManager().isInSystemHeader(Match->getLocation())) {
Diag(NewD->getLocation(),
diag::err_cuda_unattributed_constexpr_cannot_overload_device)
<< NewD->getName();
Diag(Match->getLocation(),
diag::note_cuda_conflicting_device_function_declared_here);
}
return;
}
NewD->addAttr(CUDAHostAttr::CreateImplicit(Context));
NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context));
}