本文整理汇总了C++中ParmVarDecl::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ ParmVarDecl::getType方法的具体用法?C++ ParmVarDecl::getType怎么用?C++ ParmVarDecl::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParmVarDecl
的用法示例。
在下文中一共展示了ParmVarDecl::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckParmVarDecls
//---------------------------------------------------------------------------
void TransformWCR::CheckParmVarDecls(FunctionDecl *FD, StmtVector &Body,
StmtVector &WCR) {
// If some function parameters are modified in the function body,
// they should be saved in some temporal variables.
for (unsigned i = 0, e = FD->getNumParams(); i < e; ++i) {
ParmVarDecl *PD = FD->getParamDecl(i);
if (PD->isModified()) {
SourceLocation SL;
// T __cl_parm_PD;
VarDecl *VD = NewVarDeclForParameter(PD);
VD->setInit(NULL);
Body.push_back(NewDeclStmt(VD));
// __cl_parm_PD = PD;
DeclRefExpr *Init_LHS = new (ASTCtx) DeclRefExpr(VD, VD->getType(),
VK_RValue, SL);
DeclRefExpr *Init_RHS = new (ASTCtx) DeclRefExpr(PD, PD->getType(),
VK_RValue, SL);
Expr *InitExpr = new (ASTCtx) BinaryOperator(Init_LHS, Init_RHS,
BO_Assign, PD->getType(), VK_RValue, OK_Ordinary, SL);
Body.push_back(InitExpr);
// PD = __cl_parm_PD;
DeclRefExpr *LHS = new (ASTCtx) DeclRefExpr(PD, PD->getType(),
VK_RValue, SL);
DeclRefExpr *RHS = new (ASTCtx) DeclRefExpr(VD, VD->getType(),
VK_RValue, SL);
Expr *RestoreExpr = new (ASTCtx) BinaryOperator(LHS, RHS, BO_Assign,
PD->getType(), VK_RValue, OK_Ordinary, SL);
WCR.push_back(RestoreExpr);
}
}
}
示例2: isInterestingSecondMethod
static bool isInterestingSecondMethod(CXXMethodDecl *method)
{
if (!method)
return false;
if (method->getParent()->getNameAsString() != "QString")
return false;
static const vector<string> list = { "compare", "contains", "count", "startsWith", "endsWith", "indexOf",
"isEmpty", "isNull", "lastIndexOf", "length", "size", "toDouble", "toInt",
"toUInt", "toULong", "toULongLong", "toUShort", "toUcs4"};
const bool isInList = std::find(list.cbegin(), list.cend(), method->getNameAsString()) != list.cend();
if (!isInList)
return false;
if (method->getNumParams() > 0) {
// Check any argument is a QRegExp or QRegularExpression
ParmVarDecl *firstParam = method->getParamDecl(0);
if (firstParam) {
const string paramSig = firstParam->getType().getAsString();
if (paramSig == "const class QRegExp &" || paramSig == "class QRegExp &" || paramSig == "const class QRegularExpression &")
return false;
}
}
return true;
}
示例3: PrintObjCMethodDecl
void DeclPrinter::PrintObjCMethodDecl(ObjCMethodDecl *OMD) {
if (OMD->isInstance())
Out << "\n- ";
else
Out << "\n+ ";
if (!OMD->getResultType().isNull())
Out << '(' << OMD->getResultType().getAsString() << ") ";
// FIXME: just print original selector name!
Out << OMD->getSelector().getName();
for (int i = 0; i < OMD->getNumParams(); i++) {
ParmVarDecl *PDecl = OMD->getParamDecl(i);
// FIXME: selector is missing here!
Out << " :(" << PDecl->getType().getAsString() << ") " << PDecl->getName();
}
}
示例4: checkASTDecl
void edmChecker::checkASTDecl(const clang::CXXRecordDecl *RD, clang::ento::AnalysisManager& mgr,
clang::ento::BugReporter &BR) const {
const clang::SourceManager &SM = BR.getSourceManager();
clang::ento::PathDiagnosticLocation DLoc =clang::ento::PathDiagnosticLocation::createBegin( RD, SM );
if ( !m_exception.reportClass( DLoc, BR ) ) return;
// Check the class methods (member methods).
for (clang::CXXRecordDecl::method_iterator
I = RD->method_begin(), E = RD->method_end(); I != E; ++I)
{
if ( !llvm::isa<clang::CXXMethodDecl>((*I)) ) continue;
clang::CXXMethodDecl * MD = llvm::cast<clang::CXXMethodDecl>((*I));
if ( MD->getNameAsString() == "beginRun"
|| MD->getNameAsString() == "endRun"
|| MD->getNameAsString() == "beginLuminosityBlock"
|| MD->getNameAsString() == "endLuminosityBlock" )
{
// llvm::errs()<<MD->getQualifiedNameAsString()<<"\n";
for (auto J=RD->bases_begin(), F=RD->bases_end();J != F; ++J)
{
std::string name = J->getType()->castAs<RecordType>()->getDecl()->getQualifiedNameAsString();
// llvm::errs()<<RD->getQualifiedNameAsString()<<"\n";
// llvm::errs() << "inherits from " <<name<<"\n";
if (name=="edm::EDProducer" || name=="edm::EDFilter")
{
llvm::SmallString<100> buf;
llvm::raw_svector_ostream os(buf);
os << RD->getQualifiedNameAsString() << " inherits from edm::EDProducer or edm::EDFilter";
os << "\n";
llvm::errs()<<os.str();
CXXMethodDecl::param_iterator I = MD->param_begin();
ParmVarDecl * PVD = *(I);
QualType PQT = PVD->getType();
if ( PQT->isReferenceType() ) {
QualType RQT = PQT->getPointeeType();
if (RQT.isConstQualified()) continue;
}
clang::ento::PathDiagnosticLocation ELoc =clang::ento::PathDiagnosticLocation::createBegin( MD, SM );
clang::SourceLocation SL = MD->getLocStart();
BR.EmitBasicReport(MD, "Class Checker : inherits from edm::EDProducer or edm::EDFilter","optional",os.str(),ELoc,SL);
}
}
}
}
} //end of class
示例5: isArgOfFunc
static bool isArgOfFunc(T expr, FunctionDecl *fDecl, const VarDecl *varDecl, bool byRefOrPtrOnly)
{
unsigned int param = -1;
for (auto arg : expr->arguments()) {
++param;
DeclRefExpr *refExpr = dyn_cast<DeclRefExpr>(arg);
if (!refExpr) {
if (clazy_std::hasChildren(arg)) {
Stmt* firstChild = *(arg->child_begin()); // Can be null (bug #362236)
refExpr = firstChild ? dyn_cast<DeclRefExpr>(firstChild) : nullptr;
if (!refExpr)
continue;
} else {
continue;
}
}
if (refExpr->getDecl() != varDecl) // It's our variable ?
continue;
if (!byRefOrPtrOnly) {
// We found it
return true;
}
// It is, lets see if the callee takes our variable by const-ref
if (param >= fDecl->param_size())
continue;
ParmVarDecl *paramDecl = fDecl->getParamDecl(param);
if (!paramDecl)
continue;
QualType qt = paramDecl->getType();
const Type *t = qt.getTypePtrOrNull();
if (!t)
continue;
if ((t->isReferenceType() || t->isPointerType()) && !t->getPointeeType().isConstQualified())
return true; // function receives non-const ref, so our foreach variable cant be const-ref
}
return false;
}
示例6: isCandidateMethod
static bool isCandidateMethod(CXXMethodDecl *methodDecl)
{
if (!methodDecl)
return false;
CXXRecordDecl *classDecl = methodDecl->getParent();
if (!classDecl)
return false;
if (!clazy_std::equalsAny(methodDecl->getNameAsString(), { "append", "push_back", "push", "operator<<", "operator+=" }))
return false;
if (!QtUtils::isAReserveClass(classDecl))
return false;
// Catch cases like: QList<T>::append(const QList<T> &), which don't make sense to reserve.
// In this case, the parameter has the same type of the class
ParmVarDecl *parm = methodDecl->getParamDecl(0);
if (paramIsSameTypeAs(parm->getType().getTypePtrOrNull(), classDecl))
return false;
return true;
}
示例7: isInterestingFunction
static bool isInterestingFunction(FunctionDecl *func)
{
if (!func)
return false;
// The interesting function calls for the pointertoBool check are those having bool and also pointer arguments,
// which might get mixed
bool hasBoolArgument = false;
bool hasPointerArgument = false;
for (auto it = func->param_begin(), end = func->param_end(); it != end; ++it) {
ParmVarDecl *param = *it;
const Type *t = param->getType().getTypePtrOrNull();
hasBoolArgument |= (t && t->isBooleanType());
hasPointerArgument |= (t && t->isPointerType());
if (hasBoolArgument && hasPointerArgument)
return true;
}
return false;
}
示例8: containsUnexpandedParameterPacks
bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
const DeclSpec &DS = D.getDeclSpec();
switch (DS.getTypeSpecType()) {
case TST_typename:
case TST_typeofType:
case TST_underlyingType:
case TST_atomic: {
QualType T = DS.getRepAsType().get();
if (!T.isNull() && T->containsUnexpandedParameterPack())
return true;
break;
}
case TST_typeofExpr:
case TST_decltype:
if (DS.getRepAsExpr() &&
DS.getRepAsExpr()->containsUnexpandedParameterPack())
return true;
break;
case TST_unspecified:
case TST_void:
case TST_char:
case TST_wchar:
case TST_char16:
case TST_char32:
case TST_int:
case TST_int128:
case TST_half:
case TST_float:
case TST_double:
case TST_bool:
case TST_decimal32:
case TST_decimal64:
case TST_decimal128:
case TST_enum:
case TST_union:
case TST_struct:
case TST_interface:
case TST_class:
case TST_auto:
case TST_decltype_auto:
case TST_unknown_anytype:
case TST_error:
break;
}
for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
const DeclaratorChunk &Chunk = D.getTypeObject(I);
switch (Chunk.Kind) {
case DeclaratorChunk::Pointer:
case DeclaratorChunk::Reference:
case DeclaratorChunk::Paren:
case DeclaratorChunk::BlockPointer:
// These declarator chunks cannot contain any parameter packs.
break;
case DeclaratorChunk::Array:
if (Chunk.Arr.NumElts &&
Chunk.Arr.NumElts->containsUnexpandedParameterPack())
return true;
break;
case DeclaratorChunk::Function:
for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
QualType ParamTy = Param->getType();
assert(!ParamTy.isNull() && "Couldn't parse type?");
if (ParamTy->containsUnexpandedParameterPack()) return true;
}
if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
for (unsigned i = 0; i != Chunk.Fun.NumExceptions; ++i) {
if (Chunk.Fun.Exceptions[i]
.Ty.get()
->containsUnexpandedParameterPack())
return true;
}
} else if (Chunk.Fun.getExceptionSpecType() == EST_ComputedNoexcept &&
Chunk.Fun.NoexceptExpr->containsUnexpandedParameterPack())
return true;
if (Chunk.Fun.hasTrailingReturnType()) {
QualType T = Chunk.Fun.getTrailingReturnType().get();
if (!T.isNull() && T->containsUnexpandedParameterPack())
return true;
}
break;
case DeclaratorChunk::MemberPointer:
if (Chunk.Mem.Scope().getScopeRep() &&
Chunk.Mem.Scope().getScopeRep()->containsUnexpandedParameterPack())
return true;
break;
}
}
return false;
}
示例9: BuildBlockForLambdaConversion
ExprResult Sema::BuildBlockForLambdaConversion(SourceLocation CurrentLocation,
SourceLocation ConvLocation,
CXXConversionDecl *Conv,
Expr *Src) {
// Make sure that the lambda call operator is marked used.
CXXRecordDecl *Lambda = Conv->getParent();
CXXMethodDecl *CallOperator
= cast<CXXMethodDecl>(
*Lambda->lookup(
Context.DeclarationNames.getCXXOperatorName(OO_Call)).first);
CallOperator->setReferenced();
CallOperator->setUsed();
ExprResult Init = PerformCopyInitialization(
InitializedEntity::InitializeBlock(ConvLocation,
Src->getType(),
/*NRVO=*/false),
CurrentLocation, Src);
if (!Init.isInvalid())
Init = ActOnFinishFullExpr(Init.take());
if (Init.isInvalid())
return ExprError();
// Create the new block to be returned.
BlockDecl *Block = BlockDecl::Create(Context, CurContext, ConvLocation);
// Set the type information.
Block->setSignatureAsWritten(CallOperator->getTypeSourceInfo());
Block->setIsVariadic(CallOperator->isVariadic());
Block->setBlockMissingReturnType(false);
// Add parameters.
SmallVector<ParmVarDecl *, 4> BlockParams;
for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {
ParmVarDecl *From = CallOperator->getParamDecl(I);
BlockParams.push_back(ParmVarDecl::Create(Context, Block,
From->getLocStart(),
From->getLocation(),
From->getIdentifier(),
From->getType(),
From->getTypeSourceInfo(),
From->getStorageClass(),
From->getStorageClassAsWritten(),
/*DefaultArg=*/0));
}
Block->setParams(BlockParams);
Block->setIsConversionFromLambda(true);
// Add capture. The capture uses a fake variable, which doesn't correspond
// to any actual memory location. However, the initializer copy-initializes
// the lambda object.
TypeSourceInfo *CapVarTSI =
Context.getTrivialTypeSourceInfo(Src->getType());
VarDecl *CapVar = VarDecl::Create(Context, Block, ConvLocation,
ConvLocation, 0,
Src->getType(), CapVarTSI,
SC_None, SC_None);
BlockDecl::Capture Capture(/*Variable=*/CapVar, /*ByRef=*/false,
/*Nested=*/false, /*Copy=*/Init.take());
Block->setCaptures(Context, &Capture, &Capture + 1,
/*CapturesCXXThis=*/false);
// Add a fake function body to the block. IR generation is responsible
// for filling in the actual body, which cannot be expressed as an AST.
Block->setBody(new (Context) CompoundStmt(ConvLocation));
// Create the block literal expression.
Expr *BuildBlock = new (Context) BlockExpr(Block, Conv->getConversionType());
ExprCleanupObjects.push_back(Block);
ExprNeedsCleanups = true;
return BuildBlock;
}
示例10: addFunctionPointerConversion
/// \brief Add a lambda's conversion to function pointer, as described in
/// C++11 [expr.prim.lambda]p6.
static void addFunctionPointerConversion(Sema &S,
SourceRange IntroducerRange,
CXXRecordDecl *Class,
CXXMethodDecl *CallOperator) {
// Add the conversion to function pointer.
const FunctionProtoType *Proto
= CallOperator->getType()->getAs<FunctionProtoType>();
QualType FunctionPtrTy;
QualType FunctionTy;
{
FunctionProtoType::ExtProtoInfo ExtInfo = Proto->getExtProtoInfo();
ExtInfo.TypeQuals = 0;
FunctionTy = S.Context.getFunctionType(Proto->getResultType(),
Proto->arg_type_begin(),
Proto->getNumArgs(),
ExtInfo);
FunctionPtrTy = S.Context.getPointerType(FunctionTy);
}
FunctionProtoType::ExtProtoInfo ExtInfo;
ExtInfo.TypeQuals = Qualifiers::Const;
QualType ConvTy = S.Context.getFunctionType(FunctionPtrTy, 0, 0, ExtInfo);
SourceLocation Loc = IntroducerRange.getBegin();
DeclarationName Name
= S.Context.DeclarationNames.getCXXConversionFunctionName(
S.Context.getCanonicalType(FunctionPtrTy));
DeclarationNameLoc NameLoc;
NameLoc.NamedType.TInfo = S.Context.getTrivialTypeSourceInfo(FunctionPtrTy,
Loc);
CXXConversionDecl *Conversion
= CXXConversionDecl::Create(S.Context, Class, Loc,
DeclarationNameInfo(Name, Loc, NameLoc),
ConvTy,
S.Context.getTrivialTypeSourceInfo(ConvTy,
Loc),
/*isInline=*/false, /*isExplicit=*/false,
/*isConstexpr=*/false,
CallOperator->getBody()->getLocEnd());
Conversion->setAccess(AS_public);
Conversion->setImplicit(true);
Class->addDecl(Conversion);
// Add a non-static member function "__invoke" that will be the result of
// the conversion.
Name = &S.Context.Idents.get("__invoke");
CXXMethodDecl *Invoke
= CXXMethodDecl::Create(S.Context, Class, Loc,
DeclarationNameInfo(Name, Loc), FunctionTy,
CallOperator->getTypeSourceInfo(),
/*IsStatic=*/true, SC_Static, /*IsInline=*/true,
/*IsConstexpr=*/false,
CallOperator->getBody()->getLocEnd());
SmallVector<ParmVarDecl *, 4> InvokeParams;
for (unsigned I = 0, N = CallOperator->getNumParams(); I != N; ++I) {
ParmVarDecl *From = CallOperator->getParamDecl(I);
InvokeParams.push_back(ParmVarDecl::Create(S.Context, Invoke,
From->getLocStart(),
From->getLocation(),
From->getIdentifier(),
From->getType(),
From->getTypeSourceInfo(),
From->getStorageClass(),
From->getStorageClassAsWritten(),
/*DefaultArg=*/0));
}
Invoke->setParams(InvokeParams);
Invoke->setAccess(AS_private);
Invoke->setImplicit(true);
Class->addDecl(Invoke);
}
示例11: SourceLocation
llvm::Constant *
CodeGenFunction::GenerateCovariantThunk(llvm::Function *Fn,
GlobalDecl GD, bool Extern,
const CovariantThunkAdjustment &Adjustment) {
const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
QualType ResultType = FPT->getResultType();
FunctionArgList Args;
ImplicitParamDecl *ThisDecl =
ImplicitParamDecl::Create(getContext(), 0, SourceLocation(), 0,
MD->getThisType(getContext()));
Args.push_back(std::make_pair(ThisDecl, ThisDecl->getType()));
for (FunctionDecl::param_const_iterator i = MD->param_begin(),
e = MD->param_end();
i != e; ++i) {
ParmVarDecl *D = *i;
Args.push_back(std::make_pair(D, D->getType()));
}
IdentifierInfo *II
= &CGM.getContext().Idents.get("__thunk_named_foo_");
FunctionDecl *FD = FunctionDecl::Create(getContext(),
getContext().getTranslationUnitDecl(),
SourceLocation(), II, ResultType, 0,
Extern
? FunctionDecl::Extern
: FunctionDecl::Static,
false, true);
StartFunction(FD, ResultType, Fn, Args, SourceLocation());
// generate body
const llvm::Type *Ty =
CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
FPT->isVariadic());
llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty);
CallArgList CallArgs;
bool ShouldAdjustReturnPointer = true;
QualType ArgType = MD->getThisType(getContext());
llvm::Value *Arg = Builder.CreateLoad(LocalDeclMap[ThisDecl], "this");
if (!Adjustment.ThisAdjustment.isEmpty()) {
// Do the this adjustment.
const llvm::Type *OrigTy = Callee->getType();
Arg = DynamicTypeAdjust(Arg, Adjustment.ThisAdjustment);
if (!Adjustment.ReturnAdjustment.isEmpty()) {
const CovariantThunkAdjustment &ReturnAdjustment =
CovariantThunkAdjustment(ThunkAdjustment(),
Adjustment.ReturnAdjustment);
Callee = CGM.BuildCovariantThunk(GD, Extern, ReturnAdjustment);
Callee = Builder.CreateBitCast(Callee, OrigTy);
ShouldAdjustReturnPointer = false;
}
}
CallArgs.push_back(std::make_pair(RValue::get(Arg), ArgType));
for (FunctionDecl::param_const_iterator i = MD->param_begin(),
e = MD->param_end();
i != e; ++i) {
ParmVarDecl *D = *i;
QualType ArgType = D->getType();
// llvm::Value *Arg = CGF.GetAddrOfLocalVar(Dst);
Expr *Arg = new (getContext()) DeclRefExpr(D, ArgType.getNonReferenceType(),
SourceLocation());
CallArgs.push_back(std::make_pair(EmitCallArg(Arg, ArgType), ArgType));
}
RValue RV = EmitCall(CGM.getTypes().getFunctionInfo(ResultType, CallArgs,
FPT->getCallConv(),
FPT->getNoReturnAttr()),
Callee, ReturnValueSlot(), CallArgs, MD);
if (ShouldAdjustReturnPointer && !Adjustment.ReturnAdjustment.isEmpty()) {
bool CanBeZero = !(ResultType->isReferenceType()
// FIXME: attr nonnull can't be zero either
/* || ResultType->hasAttr<NonNullAttr>() */ );
// Do the return result adjustment.
if (CanBeZero) {
llvm::BasicBlock *NonZeroBlock = createBasicBlock();
llvm::BasicBlock *ZeroBlock = createBasicBlock();
llvm::BasicBlock *ContBlock = createBasicBlock();
const llvm::Type *Ty = RV.getScalarVal()->getType();
llvm::Value *Zero = llvm::Constant::getNullValue(Ty);
Builder.CreateCondBr(Builder.CreateICmpNE(RV.getScalarVal(), Zero),
NonZeroBlock, ZeroBlock);
EmitBlock(NonZeroBlock);
llvm::Value *NZ =
DynamicTypeAdjust(RV.getScalarVal(), Adjustment.ReturnAdjustment);
EmitBranch(ContBlock);
EmitBlock(ZeroBlock);
llvm::Value *Z = RV.getScalarVal();
EmitBlock(ContBlock);
llvm::PHINode *RVOrZero = Builder.CreatePHI(Ty);
RVOrZero->reserveOperandSpace(2);
RVOrZero->addIncoming(NZ, NonZeroBlock);
//.........这里部分代码省略.........
示例12: ExprError
/// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an
/// objective C interface. This is a property reference expression.
ExprResult Sema::
HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
Expr *BaseExpr, DeclarationName MemberName,
SourceLocation MemberLoc,
SourceLocation SuperLoc, QualType SuperType,
bool Super) {
const ObjCInterfaceType *IFaceT = OPT->getInterfaceType();
ObjCInterfaceDecl *IFace = IFaceT->getDecl();
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
if (IFace->isForwardDecl()) {
Diag(MemberLoc, diag::err_property_not_found_forward_class)
<< MemberName << QualType(OPT, 0);
Diag(IFace->getLocation(), diag::note_forward_class);
return ExprError();
}
// Search for a declared property first.
if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration(Member)) {
// Check whether we can reference this property.
if (DiagnoseUseOfDecl(PD, MemberLoc))
return ExprError();
QualType ResTy = PD->getType();
Selector Sel = PP.getSelectorTable().getNullarySelector(Member);
ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel);
if (DiagnosePropertyAccessorMismatch(PD, Getter, MemberLoc))
ResTy = Getter->getResultType();
if (Super)
return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
VK_LValue, OK_ObjCProperty,
MemberLoc,
SuperLoc, SuperType));
else
return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
VK_LValue, OK_ObjCProperty,
MemberLoc, BaseExpr));
}
// Check protocols on qualified interfaces.
for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(),
E = OPT->qual_end(); I != E; ++I)
if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Member)) {
// Check whether we can reference this property.
if (DiagnoseUseOfDecl(PD, MemberLoc))
return ExprError();
if (Super)
return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
VK_LValue,
OK_ObjCProperty,
MemberLoc,
SuperLoc, SuperType));
else
return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
VK_LValue,
OK_ObjCProperty,
MemberLoc,
BaseExpr));
}
// If that failed, look for an "implicit" property by seeing if the nullary
// selector is implemented.
// FIXME: The logic for looking up nullary and unary selectors should be
// shared with the code in ActOnInstanceMessage.
Selector Sel = PP.getSelectorTable().getNullarySelector(Member);
ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel);
// May be founf in property's qualified list.
if (!Getter)
Getter = LookupMethodInQualifiedType(Sel, OPT, true);
// If this reference is in an @implementation, check for 'private' methods.
if (!Getter)
Getter = IFace->lookupPrivateMethod(Sel);
// Look through local category implementations associated with the class.
if (!Getter)
Getter = IFace->getCategoryInstanceMethod(Sel);
if (Getter) {
// Check if we can reference this property.
if (DiagnoseUseOfDecl(Getter, MemberLoc))
return ExprError();
}
// If we found a getter then this may be a valid dot-reference, we
// will look for the matching setter, in case it is needed.
Selector SetterSel =
SelectorTable::constructSetterName(PP.getIdentifierTable(),
PP.getSelectorTable(), Member);
ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(SetterSel);
// May be founf in property's qualified list.
if (!Setter)
Setter = LookupMethodInQualifiedType(SetterSel, OPT, true);
if (!Setter) {
// If this reference is in an @implementation, also check for 'private'
// methods.
Setter = IFace->lookupPrivateMethod(SetterSel);
}
//.........这里部分代码省略.........
示例13: CheckMessageArgumentTypes
bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
Selector Sel, ObjCMethodDecl *Method,
bool isClassMessage,
SourceLocation lbrac, SourceLocation rbrac,
QualType &ReturnType, ExprValueKind &VK) {
if (!Method) {
// Apply default argument promotion as for (C99 6.5.2.2p6).
for (unsigned i = 0; i != NumArgs; i++) {
if (Args[i]->isTypeDependent())
continue;
DefaultArgumentPromotion(Args[i]);
}
unsigned DiagID = isClassMessage ? diag::warn_class_method_not_found :
diag::warn_inst_method_not_found;
Diag(lbrac, DiagID)
<< Sel << isClassMessage << SourceRange(lbrac, rbrac);
ReturnType = Context.getObjCIdType();
VK = VK_RValue;
return false;
}
ReturnType = Method->getSendResultType();
VK = Expr::getValueKindForType(Method->getResultType());
unsigned NumNamedArgs = Sel.getNumArgs();
// Method might have more arguments than selector indicates. This is due
// to addition of c-style arguments in method.
if (Method->param_size() > Sel.getNumArgs())
NumNamedArgs = Method->param_size();
// FIXME. This need be cleaned up.
if (NumArgs < NumNamedArgs) {
Diag(lbrac, diag::err_typecheck_call_too_few_args)
<< 2 << NumNamedArgs << NumArgs;
return false;
}
bool IsError = false;
for (unsigned i = 0; i < NumNamedArgs; i++) {
// We can't do any type-checking on a type-dependent argument.
if (Args[i]->isTypeDependent())
continue;
Expr *argExpr = Args[i];
ParmVarDecl *Param = Method->param_begin()[i];
assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
if (RequireCompleteType(argExpr->getSourceRange().getBegin(),
Param->getType(),
PDiag(diag::err_call_incomplete_argument)
<< argExpr->getSourceRange()))
return true;
InitializedEntity Entity = InitializedEntity::InitializeParameter(Context,
Param);
ExprResult ArgE = PerformCopyInitialization(Entity, lbrac, Owned(argExpr));
if (ArgE.isInvalid())
IsError = true;
else
Args[i] = ArgE.takeAs<Expr>();
}
// Promote additional arguments to variadic methods.
if (Method->isVariadic()) {
for (unsigned i = NumNamedArgs; i < NumArgs; ++i) {
if (Args[i]->isTypeDependent())
continue;
IsError |= DefaultVariadicArgumentPromotion(Args[i], VariadicMethod, 0);
}
} else {
// Check for extra arguments to non-variadic methods.
if (NumArgs != NumNamedArgs) {
Diag(Args[NumNamedArgs]->getLocStart(),
diag::err_typecheck_call_too_many_args)
<< 2 /*method*/ << NumNamedArgs << NumArgs
<< Method->getSourceRange()
<< SourceRange(Args[NumNamedArgs]->getLocStart(),
Args[NumArgs-1]->getLocEnd());
}
}
DiagnoseSentinelCalls(Method, lbrac, Args, NumArgs);
return IsError;
}
示例14: GetTypeForDeclarator
/// GetTypeForDeclarator - Convert the type for the specified
/// declarator to Type instances. Skip the outermost Skip type
/// objects.
QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip) {
bool OmittedReturnType = false;
if (D.getContext() == Declarator::BlockLiteralContext
&& Skip == 0
&& !D.getDeclSpec().hasTypeSpecifier()
&& (D.getNumTypeObjects() == 0
|| (D.getNumTypeObjects() == 1
&& D.getTypeObject(0).Kind == DeclaratorChunk::Function)))
OmittedReturnType = true;
// long long is a C99 feature.
if (!getLangOptions().C99 && !getLangOptions().CPlusPlus0x &&
D.getDeclSpec().getTypeSpecWidth() == DeclSpec::TSW_longlong)
Diag(D.getDeclSpec().getTypeSpecWidthLoc(), diag::ext_longlong);
// Determine the type of the declarator. Not all forms of declarator
// have a type.
QualType T;
switch (D.getKind()) {
case Declarator::DK_Abstract:
case Declarator::DK_Normal:
case Declarator::DK_Operator: {
const DeclSpec& DS = D.getDeclSpec();
if (OmittedReturnType)
// We default to a dependent type initially. Can be modified by
// the first return statement.
T = Context.DependentTy;
else {
T = ConvertDeclSpecToType(DS);
if (T.isNull())
return T;
}
break;
}
case Declarator::DK_Constructor:
case Declarator::DK_Destructor:
case Declarator::DK_Conversion:
// Constructors and destructors don't have return types. Use
// "void" instead. Conversion operators will check their return
// types separately.
T = Context.VoidTy;
break;
}
// The name we're declaring, if any.
DeclarationName Name;
if (D.getIdentifier())
Name = D.getIdentifier();
// Walk the DeclTypeInfo, building the recursive type as we go.
// DeclTypeInfos are ordered from the identifier out, which is
// opposite of what we want :).
for (unsigned i = Skip, e = D.getNumTypeObjects(); i != e; ++i) {
DeclaratorChunk &DeclType = D.getTypeObject(e-i-1+Skip);
switch (DeclType.Kind) {
default: assert(0 && "Unknown decltype!");
case DeclaratorChunk::BlockPointer:
// If blocks are disabled, emit an error.
if (!LangOpts.Blocks)
Diag(DeclType.Loc, diag::err_blocks_disable);
if (DeclType.Cls.TypeQuals)
Diag(D.getIdentifierLoc(), diag::err_qualified_block_pointer_type);
if (!T.getTypePtr()->isFunctionType())
Diag(D.getIdentifierLoc(), diag::err_nonfunction_block_type);
else
T = Context.getBlockPointerType(T);
break;
case DeclaratorChunk::Pointer:
T = BuildPointerType(T, DeclType.Ptr.TypeQuals, DeclType.Loc, Name);
break;
case DeclaratorChunk::Reference:
T = BuildReferenceType(T, DeclType.Ref.LValueRef,
DeclType.Ref.HasRestrict ? QualType::Restrict : 0,
DeclType.Loc, Name);
break;
case DeclaratorChunk::Array: {
DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
Expr *ArraySize = static_cast<Expr*>(ATI.NumElts);
ArrayType::ArraySizeModifier ASM;
if (ATI.isStar)
ASM = ArrayType::Star;
else if (ATI.hasStatic)
ASM = ArrayType::Static;
else
ASM = ArrayType::Normal;
T = BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals, DeclType.Loc, Name);
break;
}
case DeclaratorChunk::Function: {
// If the function declarator has a prototype (i.e. it is not () and
// does not have a K&R-style identifier list), then the arguments are part
// of the type, otherwise the argument list is ().
const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
//.........这里部分代码省略.........
示例15: emitDeviceStubBodyNew
// CUDA 9.0+ uses new way to launch kernels. Parameters are packed in a local
// array and kernels are launched using cudaLaunchKernel().
void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
FunctionArgList &Args) {
// Build the shadow stack entry at the very start of the function.
// Calculate amount of space we will need for all arguments. If we have no
// args, allocate a single pointer so we still have a valid pointer to the
// argument array that we can pass to runtime, even if it will be unused.
Address KernelArgs = CGF.CreateTempAlloca(
VoidPtrTy, CharUnits::fromQuantity(16), "kernel_args",
llvm::ConstantInt::get(SizeTy, std::max<size_t>(1, Args.size())));
// Store pointers to the arguments in a locally allocated launch_args.
for (unsigned i = 0; i < Args.size(); ++i) {
llvm::Value* VarPtr = CGF.GetAddrOfLocalVar(Args[i]).getPointer();
llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, VoidPtrTy);
CGF.Builder.CreateDefaultAlignedStore(
VoidVarPtr, CGF.Builder.CreateConstGEP1_32(KernelArgs.getPointer(), i));
}
llvm::BasicBlock *EndBlock = CGF.createBasicBlock("setup.end");
// Lookup cudaLaunchKernel function.
// cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim, dim3 blockDim,
// void **args, size_t sharedMem,
// cudaStream_t stream);
TranslationUnitDecl *TUDecl = CGM.getContext().getTranslationUnitDecl();
DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl);
IdentifierInfo &cudaLaunchKernelII =
CGM.getContext().Idents.get("cudaLaunchKernel");
FunctionDecl *cudaLaunchKernelFD = nullptr;
for (const auto &Result : DC->lookup(&cudaLaunchKernelII)) {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(Result))
cudaLaunchKernelFD = FD;
}
if (cudaLaunchKernelFD == nullptr) {
CGM.Error(CGF.CurFuncDecl->getLocation(),
"Can't find declaration for cudaLaunchKernel()");
return;
}
// Create temporary dim3 grid_dim, block_dim.
ParmVarDecl *GridDimParam = cudaLaunchKernelFD->getParamDecl(1);
QualType Dim3Ty = GridDimParam->getType();
Address GridDim =
CGF.CreateMemTemp(Dim3Ty, CharUnits::fromQuantity(8), "grid_dim");
Address BlockDim =
CGF.CreateMemTemp(Dim3Ty, CharUnits::fromQuantity(8), "block_dim");
Address ShmemSize =
CGF.CreateTempAlloca(SizeTy, CGM.getSizeAlign(), "shmem_size");
Address Stream =
CGF.CreateTempAlloca(VoidPtrTy, CGM.getPointerAlign(), "stream");
llvm::FunctionCallee cudaPopConfigFn = CGM.CreateRuntimeFunction(
llvm::FunctionType::get(IntTy,
{/*gridDim=*/GridDim.getType(),
/*blockDim=*/BlockDim.getType(),
/*ShmemSize=*/ShmemSize.getType(),
/*Stream=*/Stream.getType()},
/*isVarArg=*/false),
"__cudaPopCallConfiguration");
CGF.EmitRuntimeCallOrInvoke(cudaPopConfigFn,
{GridDim.getPointer(), BlockDim.getPointer(),
ShmemSize.getPointer(), Stream.getPointer()});
// Emit the call to cudaLaunch
llvm::Value *Kernel = CGF.Builder.CreatePointerCast(CGF.CurFn, VoidPtrTy);
CallArgList LaunchKernelArgs;
LaunchKernelArgs.add(RValue::get(Kernel),
cudaLaunchKernelFD->getParamDecl(0)->getType());
LaunchKernelArgs.add(RValue::getAggregate(GridDim), Dim3Ty);
LaunchKernelArgs.add(RValue::getAggregate(BlockDim), Dim3Ty);
LaunchKernelArgs.add(RValue::get(KernelArgs.getPointer()),
cudaLaunchKernelFD->getParamDecl(3)->getType());
LaunchKernelArgs.add(RValue::get(CGF.Builder.CreateLoad(ShmemSize)),
cudaLaunchKernelFD->getParamDecl(4)->getType());
LaunchKernelArgs.add(RValue::get(CGF.Builder.CreateLoad(Stream)),
cudaLaunchKernelFD->getParamDecl(5)->getType());
QualType QT = cudaLaunchKernelFD->getType();
QualType CQT = QT.getCanonicalType();
llvm::Type *Ty = CGM.getTypes().ConvertType(CQT);
llvm::FunctionType *FTy = dyn_cast<llvm::FunctionType>(Ty);
const CGFunctionInfo &FI =
CGM.getTypes().arrangeFunctionDeclaration(cudaLaunchKernelFD);
llvm::FunctionCallee cudaLaunchKernelFn =
CGM.CreateRuntimeFunction(FTy, "cudaLaunchKernel");
CGF.EmitCall(FI, CGCallee::forDirect(cudaLaunchKernelFn), ReturnValueSlot(),
LaunchKernelArgs);
CGF.EmitBranch(EndBlock);
CGF.EmitBlock(EndBlock);
}