本文整理汇总了C++中ObjCInterfaceDecl::getNameAsString方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjCInterfaceDecl::getNameAsString方法的具体用法?C++ ObjCInterfaceDecl::getNameAsString怎么用?C++ ObjCInterfaceDecl::getNameAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjCInterfaceDecl
的用法示例。
在下文中一共展示了ObjCInterfaceDecl::getNameAsString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: VisitObjCMessageExpr
bool VisitObjCMessageExpr(ObjCMessageExpr *objCMsgExpr)
{
ObjCInterfaceDecl *objCInterfaceDecl = objCMsgExpr->getReceiverInterface();
if (objCInterfaceDecl && objCInterfaceDecl->getNameAsString() == "NSNumber" &&
objCMsgExpr->getNumArgs() == 1 && canSimplify(objCMsgExpr))
{
addViolation(objCMsgExpr, this);
}
return true;
}
示例3: 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());
}
}
示例4: PrintObjCInterfaceDecl
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...
}
示例5: 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";
}
示例6: VisitObjCMessageExpr
bool VisitObjCMessageExpr(ObjCMessageExpr *objCMsgExpr)
{
string selectorString = objCMsgExpr->getSelector().getAsString();
vector<string> selectorStrings;
selectorStrings.push_back("raise");
selectorStrings.push_back("raise:format:");
selectorStrings.push_back("raise:format:arguments:");
bool isRaiseMethod = vectorContains<string>(selectorString, selectorStrings);
ObjCInterfaceDecl *objCInterfaceDecl = objCMsgExpr->getReceiverInterface();
bool isNSExceptionClass = objCInterfaceDecl &&
objCInterfaceDecl->getNameAsString() == "NSException";
if (isRaiseMethod && isNSExceptionClass)
{
_raisers->push_back(objCMsgExpr);
}
return true;
}
示例7: CreateType
/// CreateType - get objective-c interface type.
llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
llvm::DICompileUnit Unit) {
ObjCInterfaceDecl *Decl = Ty->getDecl();
unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
SourceManager &SM = M->getContext().getSourceManager();
// Get overall information about the record type for the debug info.
std::string Name = Decl->getNameAsString();
llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation());
unsigned Line = SM.getInstantiationLineNumber(Decl->getLocation());
// To handle recursive interface, we
// first generate a debug descriptor for the struct as a forward declaration.
// Then (if it is a definition) we go through and get debug info for all of
// its members. Finally, we create a descriptor for the complete type (which
// may refer to the forward decl if the struct is recursive) and replace all
// uses of the forward declaration with the final definition.
llvm::DIType FwdDecl =
DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0,
llvm::DIType(), llvm::DIArray());
// If this is just a forward declaration, return it.
if (Decl->isForwardDecl())
return FwdDecl;
// Otherwise, insert it into the TypeCache so that recursive uses will find
// it.
TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl;
// Convert all the elements.
llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
ObjCInterfaceDecl *SClass = Decl->getSuperClass();
if (SClass) {
llvm::DIType SClassTy =
getOrCreateType(M->getContext().getObjCInterfaceType(SClass), Unit);
llvm::DIType InhTag =
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance,
Unit, "", Unit, 0, 0, 0,
0 /* offset */, 0, SClassTy);
EltTys.push_back(InhTag);
}
const ASTRecordLayout &RL = M->getContext().getASTObjCInterfaceLayout(Decl);
unsigned FieldNo = 0;
for (ObjCInterfaceDecl::ivar_iterator I = Decl->ivar_begin(),
E = Decl->ivar_end(); I != E; ++I, ++FieldNo) {
ObjCIvarDecl *Field = *I;
llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
std::string FieldName = Field->getNameAsString();
// Get the location for the field.
SourceLocation FieldDefLoc = Field->getLocation();
llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
unsigned FieldLine = SM.getInstantiationLineNumber(FieldDefLoc);
QualType FType = Field->getType();
uint64_t FieldSize = 0;
unsigned FieldAlign = 0;
if (!FType->isIncompleteArrayType()) {
// Bit size, align and offset of the type.
FieldSize = M->getContext().getTypeSize(FType);
Expr *BitWidth = Field->getBitWidth();
if (BitWidth)
FieldSize =
BitWidth->getIntegerConstantExprValue(M->getContext()).getZExtValue();
FieldAlign = M->getContext().getTypeAlign(FType);
}
uint64_t FieldOffset = RL.getFieldOffset(FieldNo);
unsigned Flags = 0;
if (Field->getAccessControl() == ObjCIvarDecl::Protected)
Flags = llvm::DIType::FlagProtected;
else if (Field->getAccessControl() == ObjCIvarDecl::Private)
Flags = llvm::DIType::FlagPrivate;
// Create a DW_TAG_member node to remember the offset of this field in the
// struct. FIXME: This is an absolutely insane way to capture this
// information. When we gut debug info, this should be fixed.
FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
FieldName, FieldDefUnit,
FieldLine, FieldSize, FieldAlign,
FieldOffset, Flags, FieldTy);
EltTys.push_back(FieldTy);
}
llvm::DIArray Elements =
DebugFactory.GetOrCreateArray(&EltTys[0], EltTys.size());
// Bit size, align and offset of the type.
//.........这里部分代码省略.........