本文整理汇总了C++中ObjCInterfaceDecl类的典型用法代码示例。如果您正苦于以下问题:C++ ObjCInterfaceDecl类的具体用法?C++ ObjCInterfaceDecl怎么用?C++ ObjCInterfaceDecl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjCInterfaceDecl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shouldRunOnFunctionOrMethod
// FIXME: A callback should disable checkers at the start of functions.
static bool shouldRunOnFunctionOrMethod(const NamedDecl *ND) {
if (!ND)
return false;
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ND);
if (!MD)
return false;
if (!isInitializationMethod(MD))
return false;
// self = [super init] applies only to NSObject subclasses.
// For instance, NSProxy doesn't implement -init.
ASTContext &Ctx = MD->getASTContext();
IdentifierInfo* NSObjectII = &Ctx.Idents.get("NSObject");
ObjCInterfaceDecl *ID = MD->getClassInterface()->getSuperClass();
for ( ; ID ; ID = ID->getSuperClass()) {
IdentifierInfo *II = ID->getIdentifier();
if (II == NSObjectII)
break;
}
if (!ID)
return false;
return true;
}
示例2: VisitObjCMessageExpr
bool VisitObjCMessageExpr(ObjCMessageExpr *objCMsgExpr)
{
ObjCInterfaceDecl *objCInterfaceDecl = objCMsgExpr->getReceiverInterface();
string selectorString = objCMsgExpr->getSelector().getAsString();
vector<string> arraySelectors;
arraySelectors.push_back("array");
arraySelectors.push_back("arrayWithObject:");
arraySelectors.push_back("arrayWithObjects:count:");
arraySelectors.push_back("arrayWithObjects:");
vector<string> dictionarySelectors;
dictionarySelectors.push_back("dictionary");
dictionarySelectors.push_back("dictionaryWithObject:forKey:");
dictionarySelectors.push_back("dictionaryWithObjects:forKeys:count:");
dictionarySelectors.push_back("dictionaryWithObjectsAndKeys:");
dictionarySelectors.push_back("dictionaryWithObjects:forKeys:");
if (objCInterfaceDecl &&
((objCInterfaceDecl->getNameAsString() == "NSArray" &&
vectorContains<string>(selectorString, arraySelectors)) ||
(objCInterfaceDecl->getNameAsString() == "NSDictionary" &&
vectorContains<string>(selectorString, dictionarySelectors))))
{
addViolation(objCMsgExpr, this);
}
return true;
}
示例3: while
bool trans::canApplyWeak(ASTContext &Ctx, QualType type,
bool AllowOnUnknownClass) {
if (!Ctx.getLangOptions().ObjCRuntimeHasWeak)
return false;
QualType T = type;
if (T.isNull())
return false;
while (const PointerType *ptr = T->getAs<PointerType>())
T = ptr->getPointeeType();
if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
if (!AllowOnUnknownClass && (!Class || Class->getName() == "NSObject"))
return false; // id/NSObject is not safe for weak.
if (!AllowOnUnknownClass && Class->isForwardDecl())
return false; // forward classes are not verifiable, therefore not safe.
if (Class->isArcWeakrefUnavailable())
return false;
if (isClassInWeakBlacklist(Class))
return false;
}
return true;
}
示例4: LoadExternalDefinition
ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
ObjCInterfaceDecl *&clsDeclared) {
// FIXME: Should make sure no callers ever do this.
if (!hasDefinition())
return 0;
if (data().ExternallyCompleted)
LoadExternalDefinition();
ObjCInterfaceDecl* ClassDecl = this;
while (ClassDecl != NULL) {
if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
clsDeclared = ClassDecl;
return I;
}
for (const ObjCCategoryDecl *CDecl = ClassDecl->getFirstClassExtension();
CDecl; CDecl = CDecl->getNextClassExtension()) {
if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) {
clsDeclared = ClassDecl;
return I;
}
}
ClassDecl = ClassDecl->getSuperClass();
}
return NULL;
}
示例5: PrintObjCImplementationDecl
void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) {
std::string I = OID->getName();
ObjCInterfaceDecl *SID = OID->getSuperClass();
if (SID)
Out << "@implementation " << I << " : " << SID->getName();
else
Out << "@implementation " << I;
for (ObjCImplementationDecl::instmeth_iterator I = OID->instmeth_begin(),
E = OID->instmeth_end(); I != E; ++I) {
ObjCMethodDecl *OMD = *I;
PrintObjCMethodDecl(OMD);
if (OMD->getBody()) {
Out << ' ';
OMD->getBody()->printPretty(Out);
Out << '\n';
}
}
for (ObjCImplementationDecl::classmeth_iterator I = OID->classmeth_begin(),
E = OID->classmeth_end(); I != E; ++I) {
ObjCMethodDecl *OMD = *I;
PrintObjCMethodDecl(OMD);
if (OMD->getBody()) {
Out << ' ';
OMD->getBody()->printPretty(Out);
Out << '\n';
}
}
Out << "@end\n";
}
示例6: while
/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
/// class whose name is passed as argument. If it is not one of the super classes
/// the it returns NULL.
ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
const IdentifierInfo*ICName) {
ObjCInterfaceDecl* ClassDecl = this;
while (ClassDecl != NULL) {
if (ClassDecl->getIdentifier() == ICName)
return ClassDecl;
ClassDecl = ClassDecl->getSuperClass();
}
return NULL;
}
示例7: _objc_getClass
void CGObjCJit::GenerateClass(const ObjCImplementationDecl *ClassDecl) {
if (isUsable) {
const char* ClassName = ClassDecl->getIdentifier()->getNameStart();
void* Superclass = 0;
ObjCInterfaceDecl *superClassDecl =
ClassDecl->getClassInterface()->getSuperClass();
if (superClassDecl) {
const char* superClassName =
superClassDecl->getIdentifier()->getNameStart();
Superclass = _objc_getClass(superClassName);
}
void *theClass =
_objc_allocateClassPair(Superclass, ClassName, 0); // TODO: always zero?
// Add methods
AddMethodsToClass(theClass);
// Add interface ivars
const ObjCInterfaceDecl *classInterfaceDecl = ClassDecl->getClassInterface();
AddIvarsToClass(theClass,
classInterfaceDecl->ivar_begin(),
classInterfaceDecl->ivar_end());
// Add implementation ivars
AddIvarsToClass(theClass,
ClassDecl->ivar_begin(),
ClassDecl->ivar_end());
// Add protocols
ObjCInterfaceDecl::protocol_iterator protocol =
classInterfaceDecl->protocol_begin();
const ObjCInterfaceDecl::protocol_iterator protocol_end =
classInterfaceDecl->protocol_end();
while (protocol != protocol_end) {
void *theProtocol = 0;
// Search "locally" first, then from runtime
llvm::StringMap<void*>::iterator proto_local =
DefinedProtocols.find((*protocol)->getName());
if (proto_local != DefinedProtocols.end()) {
theProtocol = proto_local->second;
} else {
theProtocol = _objc_getProtocol((*protocol)->getNameAsString().c_str());
}
_class_addProtocol(theClass, theProtocol);
protocol++;
}
// Finalize class (adding methods later, at runtime, in init function)
_objc_registerClassPair(theClass);
}
}
示例8: VisitObjCMessageExpr
bool VisitObjCMessageExpr(ObjCMessageExpr *objCMsgExpr)
{
ObjCInterfaceDecl *objCInterfaceDecl = objCMsgExpr->getReceiverInterface();
if (objCInterfaceDecl && objCInterfaceDecl->getNameAsString() == "NSNumber" &&
objCMsgExpr->getNumArgs() == 1 && canSimplify(objCMsgExpr))
{
addViolation(objCMsgExpr, this);
}
return true;
}
示例9: CheckObjCUnusedIvar
void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) {
ObjCInterfaceDecl* ID = D->getClassInterface();
IvarUsageMap M;
ASTContext &Ctx = BR.getContext();
// Iterate over the ivars.
for (ObjCInterfaceDecl::ivar_iterator I=ID->ivar_begin(), E=ID->ivar_end();
I!=E; ++I) {
ObjCIvarDecl* ID = *I;
// Ignore ivars that aren't private.
if (ID->getAccessControl() != ObjCIvarDecl::Private)
continue;
// Skip IB Outlets.
if (ID->getAttr<IBOutletAttr>())
continue;
M[ID] = Unused;
}
if (M.empty())
return;
// Now scan the methods for accesses.
for (ObjCImplementationDecl::instmeth_iterator I = D->instmeth_begin(Ctx),
E = D->instmeth_end(Ctx); I!=E; ++I)
Scan(M, (*I)->getBody(Ctx));
// Scan for @synthesized property methods that act as setters/getters
// to an ivar.
for (ObjCImplementationDecl::propimpl_iterator I = D->propimpl_begin(Ctx),
E = D->propimpl_end(Ctx); I!=E; ++I)
Scan(M, *I);
// Find ivars that are unused.
for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
if (I->second == Unused) {
std::ostringstream os;
os << "Instance variable '" << I->first->getNameAsString()
<< "' in class '" << ID->getNameAsString()
<< "' is never used by the methods in its @implementation "
"(although it may be used by category methods).";
BR.EmitBasicReport("Unused instance variable", "Optimization",
os.str().c_str(), I->first->getLocation());
}
}
示例10: switch
void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
switch (D->getKind()) {
default:
llvm_unreachable("Invalid ObjC container.");
case Decl::ObjCInterface:
case Decl::ObjCImplementation:
GenObjCClass(D->getName());
break;
case Decl::ObjCCategory: {
ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
ObjCInterfaceDecl *ID = CD->getClassInterface();
if (!ID) {
// Handle invalid code where the @interface might not
// have been specified.
// FIXME: We should be able to generate this USR even if the
// @interface isn't available.
IgnoreResults = true;
return;
}
// Specially handle class extensions, which are anonymous categories.
// We want to mangle in the location to uniquely distinguish them.
if (CD->IsClassExtension()) {
Out << "objc(ext)" << ID->getName() << '@';
GenLoc(CD);
}
else
GenObjCCategory(ID->getName(), CD->getName());
break;
}
case Decl::ObjCCategoryImpl: {
ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
ObjCInterfaceDecl *ID = CD->getClassInterface();
if (!ID) {
// Handle invalid code where the @interface might not
// have been specified.
// FIXME: We should be able to generate this USR even if the
// @interface isn't available.
IgnoreResults = true;
return;
}
GenObjCCategory(ID->getName(), CD->getName());
break;
}
case Decl::ObjCProtocol:
GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
break;
}
}
示例11: PrintObjCPropertyDecl
void DeclPrinter::PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
std::string I = OID->getNameAsString();
ObjCInterfaceDecl *SID = OID->getSuperClass();
if (SID)
Out << "@interface " << I << " : " << SID->getNameAsString();
else
Out << "@interface " << I;
// Protocols?
const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
if (!Protocols.empty()) {
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
E = Protocols.end(); I != E; ++I)
Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getNameAsString();
}
if (!Protocols.empty())
Out << ">";
Out << '\n';
if (OID->ivar_size() > 0) {
Out << '{';
for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
E = OID->ivar_end(); I != E; ++I) {
Out << '\t' << (*I)->getType().getAsString()
<< ' ' << (*I)->getNameAsString() << ";\n";
}
Out << "}\n";
}
// FIXME: Should not use a NULL DeclContext!
ASTContext *Context = 0;
for (ObjCInterfaceDecl::prop_iterator I = OID->prop_begin(*Context),
E = OID->prop_end(*Context); I != E; ++I)
PrintObjCPropertyDecl(*I);
bool eol_needed = false;
for (ObjCInterfaceDecl::classmeth_iterator I = OID->classmeth_begin(*Context),
E = OID->classmeth_end(*Context); I != E; ++I)
eol_needed = true, PrintObjCMethodDecl(*I);
for (ObjCInterfaceDecl::instmeth_iterator I = OID->instmeth_begin(*Context),
E = OID->instmeth_end(*Context); I != E; ++I)
eol_needed = true, PrintObjCMethodDecl(*I);
Out << (eol_needed ? "\[email protected]\n" : "@end\n");
// FIXME: implement the rest...
}
示例12: tryCaptureObjCSelf
ExprResult Sema::ActOnSuperMessage(Scope *S,
SourceLocation SuperLoc,
Selector Sel,
SourceLocation LBracLoc,
SourceLocation SelectorLoc,
SourceLocation RBracLoc,
MultiExprArg Args) {
// Determine whether we are inside a method or not.
ObjCMethodDecl *Method = tryCaptureObjCSelf();
if (!Method) {
Diag(SuperLoc, diag::err_invalid_receiver_to_message_super);
return ExprError();
}
ObjCInterfaceDecl *Class = Method->getClassInterface();
if (!Class) {
Diag(SuperLoc, diag::error_no_super_class_message)
<< Method->getDeclName();
return ExprError();
}
ObjCInterfaceDecl *Super = Class->getSuperClass();
if (!Super) {
// The current class does not have a superclass.
Diag(SuperLoc, diag::error_root_class_cannot_use_super)
<< Class->getIdentifier();
return ExprError();
}
// We are in a method whose class has a superclass, so 'super'
// is acting as a keyword.
if (Method->isInstanceMethod()) {
// Since we are in an instance method, this is an instance
// message to the superclass instance.
QualType SuperTy = Context.getObjCInterfaceType(Super);
SuperTy = Context.getObjCObjectPointerType(SuperTy);
return BuildInstanceMessage(0, SuperTy, SuperLoc,
Sel, /*Method=*/0,
LBracLoc, SelectorLoc, RBracLoc, move(Args));
}
// Since we are in a class method, this is a class message to
// the superclass.
return BuildClassMessage(/*ReceiverTypeInfo=*/0,
Context.getObjCInterfaceType(Super),
SuperLoc, Sel, /*Method=*/0,
LBracLoc, SelectorLoc, RBracLoc, move(Args));
}
示例13: rewriteToObjCProperty
static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const ObjCMethodDecl *Setter,
const NSAPI &NS, edit::Commit &commit) {
ASTContext &Context = NS.getASTContext();
std::string PropertyString = "@property";
const ParmVarDecl *argDecl = *Setter->param_begin();
QualType ArgType = Context.getCanonicalType(argDecl->getType());
Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
if (ArgType->isObjCRetainableType() &&
propertyLifetime == Qualifiers::OCL_Strong) {
if (const ObjCObjectPointerType *ObjPtrTy =
ArgType->getAs<ObjCObjectPointerType>()) {
ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
if (IDecl &&
IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
PropertyString += "(copy)";
}
}
else if (propertyLifetime == Qualifiers::OCL_Weak)
// TODO. More precise determination of 'weak' attribute requires
// looking into setter's implementation for backing weak ivar.
PropertyString += "(weak)";
else
PropertyString += "(unsafe_unretained)";
// strip off any ARC lifetime qualifier.
QualType CanResultTy = Context.getCanonicalType(Getter->getResultType());
if (CanResultTy.getQualifiers().hasObjCLifetime()) {
Qualifiers Qs = CanResultTy.getQualifiers();
Qs.removeObjCLifetime();
CanResultTy = Context.getQualifiedType(CanResultTy.getUnqualifiedType(), Qs);
}
PropertyString += " ";
PropertyString += CanResultTy.getAsString(Context.getPrintingPolicy());
PropertyString += " ";
PropertyString += Getter->getNameAsString();
commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(),
Getter->getDeclaratorEndLoc()),
PropertyString);
SourceLocation EndLoc = Setter->getDeclaratorEndLoc();
// Get location past ';'
EndLoc = EndLoc.getLocWithOffset(1);
commit.remove(CharSourceRange::getCharRange(Setter->getLocStart(), EndLoc));
return true;
}
示例14: 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);
}
示例15: PrintObjCImplementationDecl
void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) {
std::string I = OID->getNameAsString();
ObjCInterfaceDecl *SID = OID->getSuperClass();
if (SID)
Out << "@implementation " << I << " : " << SID->getNameAsString();
else
Out << "@implementation " << I;
// FIXME: Don't use a NULL context
ASTContext *Context = 0;
for (ObjCImplementationDecl::instmeth_iterator
I = OID->instmeth_begin(*Context),
E = OID->instmeth_end(*Context);
I != E; ++I) {
ObjCMethodDecl *OMD = *I;
PrintObjCMethodDecl(OMD);
if (OMD->getBody()) {
Out << ' ';
OMD->getBody()->printPretty(Out);
Out << '\n';
}
}
for (ObjCImplementationDecl::classmeth_iterator
I = OID->classmeth_begin(*Context),
E = OID->classmeth_end(*Context);
I != E; ++I) {
ObjCMethodDecl *OMD = *I;
PrintObjCMethodDecl(OMD);
if (OMD->getBody()) {
Out << ' ';
OMD->getBody()->printPretty(Out);
Out << '\n';
}
}
for (ObjCImplementationDecl::propimpl_iterator
I = OID->propimpl_begin(*Context),
E = OID->propimpl_end(*Context); I != E; ++I)
PrintObjCPropertyImplDecl(*I);
Out << "@end\n";
}