本文整理汇总了C++中Sema类的典型用法代码示例。如果您正苦于以下问题:C++ Sema类的具体用法?C++ Sema怎么用?C++ Sema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shouldProceed
bool shouldProceed(void *S, void *T) {
using namespace clang;
Sema *Sem = (Sema *)S;
DiagnosticsEngine& Diag = Sem->getDiagnostics();
cling::Transaction* Trans = (cling::Transaction*)T;
// Here we will cheat a bit and assume that the warning came from the last
// stmt, which will be in the 90% of the cases.
CompoundStmt* CS = cast<CompoundStmt>(Trans->getWrapperFD()->getBody());
// Skip the NullStmts.
SourceLocation Loc = CS->getLocStart();
for(CompoundStmt::const_reverse_body_iterator I = CS->body_rbegin(),
E = CS->body_rend(); I != E; ++I)
if (!isa<NullStmt>(*I)) {
Loc = (*I)->getLocStart();
break;
}
Diag.Report(Loc, diag::warn_null_ptr_deref);
if (isatty(fileno(stdin))) {
int input = getchar();
getchar();
if (input == 'y' || input == 'Y')
return false;
}
return true;
}
示例2: IsKnownEmitted
// Do we know that we will eventually codegen the given function?
static bool IsKnownEmitted(Sema &S, FunctionDecl *FD) {
// Templates are emitted when they're instantiated.
if (FD->isDependentContext())
return false;
// When compiling for device, host functions are never emitted. Similarly,
// when compiling for host, device and global functions are never emitted.
// (Technically, we do emit a host-side stub for global functions, but this
// doesn't count for our purposes here.)
Sema::CUDAFunctionTarget T = S.IdentifyCUDATarget(FD);
if (S.getLangOpts().CUDAIsDevice && T == Sema::CFT_Host)
return false;
if (!S.getLangOpts().CUDAIsDevice &&
(T == Sema::CFT_Device || T == Sema::CFT_Global))
return false;
// Check whether this function is externally visible -- if so, it's
// known-emitted.
//
// We have to check the GVA linkage of the function's *definition* -- if we
// only have a declaration, we don't know whether or not the function will be
// emitted, because (say) the definition could include "inline".
FunctionDecl *Def = FD->getDefinition();
if (Def &&
!isDiscardableGVALinkage(S.getASTContext().GetGVALinkageForFunction(Def)))
return true;
// Otherwise, the function is known-emitted if it's in our set of
// known-emitted functions.
return S.DeviceKnownEmittedFns.count(FD) > 0;
}
示例3: buildOperatorCoawaitCall
/// Build a call to 'operator co_await' if there is a suitable operator for
/// the given expression.
static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, Scope *S,
SourceLocation Loc, Expr *E) {
UnresolvedSet<16> Functions;
SemaRef.LookupOverloadedOperatorName(OO_Coawait, S, E->getType(), QualType(),
Functions);
return SemaRef.CreateOverloadedUnaryOp(Loc, UO_Coawait, Functions, E);
}
示例4: VisitCompoundStmt
bool VisitCompoundStmt(CompoundStmt* CS) {
for(CompoundStmt::body_iterator I = CS->body_begin(), E = CS->body_end();
I != E; ++I) {
if (!isa<BinaryOperator>(*I))
continue;
const BinaryOperator* BinOp = cast<BinaryOperator>(*I);
if (isAutoCandidate(BinOp)) {
ASTContext& C = m_Sema->getASTContext();
VarDecl* VD
= cast<VarDecl>(cast<DeclRefExpr>(BinOp->getLHS())->getDecl());
TypeSourceInfo* ResTSI = 0;
TypeSourceInfo* TrivialTSI
= C.getTrivialTypeSourceInfo(VD->getType());
Expr* RHS = BinOp->getRHS();
m_Sema->DeduceAutoType(TrivialTSI, RHS, ResTSI);
VD->setTypeSourceInfo(ResTSI);
VD->setType(ResTSI->getType());
VD->setInit(RHS);
Sema::DeclGroupPtrTy VDPtrTy = m_Sema->ConvertDeclToDeclGroup(VD);
// Transform the AST into a "sane" state. Replace the binary operator
// with decl stmt, because the binop semantically is a decl with init.
StmtResult DS = m_Sema->ActOnDeclStmt(VDPtrTy, BinOp->getLocStart(),
BinOp->getLocEnd());
assert(!DS.isInvalid() && "Invalid DeclStmt.");
*I = DS.take();
}
}
return true; // returning false will abort the in-depth traversal.
}
示例5: HandleMSP430InterruptAttr
static void HandleMSP430InterruptAttr(Decl *d,
const AttributeList &Attr, Sema &S) {
if (Attr.getNumArgs() != 1) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
<< Attr.getName() << 1;
return;
}
if (!Attr.isArgExpr(0)) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) << Attr.getName()
<< AANT_ArgumentIntegerConstant;
return;
}
// FIXME: Check for decl - it should be void ()(void).
Expr *NumParamsExpr = Attr.getArgAsExpr(0);
llvm::APSInt NumParams(32);
if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context)) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
<< Attr.getName() << AANT_ArgumentIntegerConstant
<< NumParamsExpr->getSourceRange();
return;
}
unsigned Num = NumParams.getLimitedValue(255);
if ((Num & 1) || Num > 30) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
<< "interrupt" << (int)NumParams.getSExtValue()
<< NumParamsExpr->getSourceRange();
return;
}
d->addAttr(::new (S.Context) MSP430InterruptAttr(Attr.getLoc(), S.Context, Num));
d->addAttr(::new (S.Context) UsedAttr(Attr.getLoc(), S.Context));
}
示例6: isValidCoroutineContext
static bool isValidCoroutineContext(Sema &S, SourceLocation Loc,
StringRef Keyword) {
// 'co_await' and 'co_yield' are not permitted in unevaluated operands.
if (S.isUnevaluatedContext()) {
S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
return false;
}
// Any other usage must be within a function.
auto *FD = dyn_cast<FunctionDecl>(S.CurContext);
if (!FD) {
S.Diag(Loc, isa<ObjCMethodDecl>(S.CurContext)
? diag::err_coroutine_objc_method
: diag::err_coroutine_outside_function) << Keyword;
return false;
}
// An enumeration for mapping the diagnostic type to the correct diagnostic
// selection index.
enum InvalidFuncDiag {
DiagCtor = 0,
DiagDtor,
DiagCopyAssign,
DiagMoveAssign,
DiagMain,
DiagConstexpr,
DiagAutoRet,
DiagVarargs,
};
bool Diagnosed = false;
auto DiagInvalid = [&](InvalidFuncDiag ID) {
S.Diag(Loc, diag::err_coroutine_invalid_func_context) << ID << Keyword;
Diagnosed = true;
return false;
};
// Diagnose when a constructor, destructor, copy/move assignment operator,
// or the function 'main' are declared as a coroutine.
auto *MD = dyn_cast<CXXMethodDecl>(FD);
if (MD && isa<CXXConstructorDecl>(MD))
return DiagInvalid(DiagCtor);
else if (MD && isa<CXXDestructorDecl>(MD))
return DiagInvalid(DiagDtor);
else if (MD && MD->isCopyAssignmentOperator())
return DiagInvalid(DiagCopyAssign);
else if (MD && MD->isMoveAssignmentOperator())
return DiagInvalid(DiagMoveAssign);
else if (FD->isMain())
return DiagInvalid(DiagMain);
// Emit a diagnostics for each of the following conditions which is not met.
if (FD->isConstexpr())
DiagInvalid(DiagConstexpr);
if (FD->getReturnType()->isUndeducedType())
DiagInvalid(DiagAutoRet);
if (FD->isVariadic())
DiagInvalid(DiagVarargs);
return !Diagnosed;
}
示例7: HandleDLLImportAttr
static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
// Attribute can be applied only to functions or variables.
FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
if (!FD && !isa<VarDecl>(D)) {
// Apparently Visual C++ thinks it is okay to not emit a warning
// in this case, so only emit a warning when -fms-extensions is not
// specified.
if (!S.getLangOpts().MicrosoftExt)
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << 2 /*variable and function*/;
return;
}
// Currently, the dllimport attribute is ignored for inlined functions.
// Warning is emitted.
if (FD && FD->isInlineSpecified()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
return;
}
unsigned Index = Attr.getAttributeSpellingListIndex();
DLLImportAttr *NewAttr = S.mergeDLLImportAttr(D, Attr.getRange(), Index);
if (NewAttr)
D->addAttr(NewAttr);
}
示例8: EraseUnwantedCUDAMatchesImpl
static void EraseUnwantedCUDAMatchesImpl(Sema &S, const FunctionDecl *Caller,
llvm::SmallVectorImpl<T> &Matches,
FetchDeclFn FetchDecl) {
assert(S.getLangOpts().CUDATargetOverloads &&
"Should not be called w/o enabled target overloads.");
if (Matches.size() <= 1)
return;
// Find the best call preference among the functions in Matches.
Sema::CUDAFunctionPreference P, BestCFP = Sema::CFP_Never;
for (auto const &Match : Matches) {
P = S.IdentifyCUDAPreference(Caller, FetchDecl(Match));
if (P > BestCFP)
BestCFP = P;
}
// Erase all functions with lower priority.
for (unsigned I = 0, N = Matches.size(); I != N;)
if (S.IdentifyCUDAPreference(Caller, FetchDecl(Matches[I])) < BestCFP) {
Matches[I] = Matches[--N];
Matches.resize(N);
} else {
++I;
}
}
示例9: buildCoroutineHandle
static ExprResult buildCoroutineHandle(Sema &S, QualType PromiseType,
SourceLocation Loc) {
QualType CoroHandleType = lookupCoroutineHandleType(S, PromiseType, Loc);
if (CoroHandleType.isNull())
return ExprError();
DeclContext *LookupCtx = S.computeDeclContext(CoroHandleType);
LookupResult Found(S, &S.PP.getIdentifierTable().get("from_address"), Loc,
Sema::LookupOrdinaryName);
if (!S.LookupQualifiedName(Found, LookupCtx)) {
S.Diag(Loc, diag::err_coroutine_handle_missing_member)
<< "from_address";
return ExprError();
}
Expr *FramePtr =
buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_frame, {});
CXXScopeSpec SS;
ExprResult FromAddr =
S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false);
if (FromAddr.isInvalid())
return ExprError();
return S.ActOnCallExpr(nullptr, FromAddr.get(), Loc, FramePtr, Loc);
}
示例10: HandleX86ForceAlignArgPointerAttr
static void HandleX86ForceAlignArgPointerAttr(Decl *D,
const AttributeList& Attr,
Sema &S) {
// Check the attribute arguments.
if (Attr.getNumArgs() != 0) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
return;
}
// If we try to apply it to a function pointer, don't warn, but don't
// do anything, either. It doesn't matter anyway, because there's nothing
// special about calling a force_align_arg_pointer function.
ValueDecl *VD = dyn_cast<ValueDecl>(D);
if (VD && VD->getType()->isFunctionPointerType())
return;
// Also don't warn on function pointer typedefs.
TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D);
if (TD && (TD->getUnderlyingType()->isFunctionPointerType() ||
TD->getUnderlyingType()->isFunctionType()))
return;
// Attribute can only be applied to function types.
if (!isa<FunctionDecl>(D)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << /* function */0;
return;
}
D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr(Attr.getRange(),
S.Context));
}
示例11: HandleDLLExportAttr
static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 0) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
return;
}
// Attribute can be applied only to functions or variables.
FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
if (!FD && !isa<VarDecl>(D)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << 2 /*variable and function*/;
return;
}
// Currently, the dllexport attribute is ignored for inlined functions, unless
// the -fkeep-inline-functions flag has been used. Warning is emitted;
if (FD && FD->isInlineSpecified()) {
// FIXME: ... unless the -fkeep-inline-functions flag has been used.
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllexport";
return;
}
unsigned Index = Attr.getAttributeSpellingListIndex();
DLLExportAttr *NewAttr = S.mergeDLLExportAttr(D, Attr.getRange(), Index);
if (NewAttr)
D->addAttr(NewAttr);
}
示例12: CheckNakedParmReference
static bool CheckNakedParmReference(Expr *E, Sema &S) {
FunctionDecl *Func = dyn_cast<FunctionDecl>(S.CurContext);
if (!Func)
return false;
if (!Func->hasAttr<NakedAttr>())
return false;
SmallVector<Expr*, 4> WorkList;
WorkList.push_back(E);
while (WorkList.size()) {
Expr *E = WorkList.pop_back_val();
if (isa<CXXThisExpr>(E)) {
S.Diag(E->getLocStart(), diag::err_asm_naked_this_ref);
S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
return true;
}
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
if (isa<ParmVarDecl>(DRE->getDecl())) {
S.Diag(DRE->getLocStart(), diag::err_asm_naked_parm_ref);
S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
return true;
}
}
for (Stmt *Child : E->children()) {
if (Expr *E = dyn_cast_or_null<Expr>(Child))
WorkList.push_back(E);
}
}
return false;
}
示例13: HandleDLLExportAttr
static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 0) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
return;
}
// Attribute can be applied only to functions or variables.
if (isa<VarDecl>(D)) {
D->addAttr(::new (S.Context) DLLExportAttr(Attr.getLoc(), S.Context));
return;
}
FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
if (!FD) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << 2 /*variable and function*/;
return;
}
// Currently, the dllexport attribute is ignored for inlined functions, unless
// the -fkeep-inline-functions flag has been used. Warning is emitted;
if (FD->isInlineSpecified()) {
// FIXME: ... unless the -fkeep-inline-functions flag has been used.
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllexport";
return;
}
D->addAttr(::new (S.Context) DLLExportAttr(Attr.getLoc(), S.Context));
}
示例14: HandleAddressSpaceTypeAttribute
/// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
/// specified type. The attribute contains 1 argument, the id of the address
/// space for the type.
static void HandleAddressSpaceTypeAttribute(QualType &Type,
const AttributeList &Attr, Sema &S){
// If this type is already address space qualified, reject it.
// Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers
// for two or more different address spaces."
if (Type.getAddressSpace()) {
S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
return;
}
// Check the attribute arguments.
if (Attr.getNumArgs() != 1) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
return;
}
Expr *ASArgExpr = static_cast<Expr *>(Attr.getArg(0));
llvm::APSInt addrSpace(32);
if (!ASArgExpr->isIntegerConstantExpr(addrSpace, S.Context)) {
S.Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int)
<< ASArgExpr->getSourceRange();
return;
}
unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue());
Type = S.Context.getAddrSpaceQualType(Type, ASIdx);
}
示例15: HandleObjCGCTypeAttribute
/// HandleObjCGCTypeAttribute - Process an objc's gc attribute on the
/// specified type. The attribute contains 1 argument, weak or strong.
static void HandleObjCGCTypeAttribute(QualType &Type,
const AttributeList &Attr, Sema &S) {
if (Type.getObjCGCAttr() != QualType::GCNone) {
S.Diag(Attr.getLoc(), diag::err_attribute_multiple_objc_gc);
return;
}
// Check the attribute arguments.
if (!Attr.getParameterName()) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string)
<< "objc_gc" << 1;
return;
}
QualType::GCAttrTypes GCAttr;
if (Attr.getNumArgs() != 0) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
return;
}
if (Attr.getParameterName()->isStr("weak"))
GCAttr = QualType::Weak;
else if (Attr.getParameterName()->isStr("strong"))
GCAttr = QualType::Strong;
else {
S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)
<< "objc_gc" << Attr.getParameterName();
return;
}
Type = S.Context.getObjCGCQualType(Type, GCAttr);
}