///
/// \returns true if an error occurred (e.g., because one of the parameter
/// types is incomplete), false otherwise.
- bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S);
+ std::string getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const;
/// \brief Emit the encoded type for the method declaration \p Decl into
/// \p S.
///
/// \returns true if an error occurred (e.g., because one of the parameter
/// types is incomplete), false otherwise.
- bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S,
- bool Extended = false)
- const;
+ std::string getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
+ bool Extended = false) const;
/// \brief Return the encoded type for this block declaration.
std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
/// this method declaration. If non-NULL, Container must be either
/// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
/// only be NULL when getting encodings for protocol properties.
- void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
- const Decl *Container,
- std::string &S) const;
+ std::string getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
+ const Decl *Container) const;
bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
ObjCProtocolDecl *rProto) const;
return S;
}
-bool ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl,
- std::string& S) {
+std::string
+ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const {
+ std::string S;
// Encode result type.
getObjCEncodingForType(Decl->getReturnType(), S);
CharUnits ParmOffset;
if (sz.isZero())
continue;
- assert (sz.isPositive() &&
- "getObjCEncodingForFunctionDecl - Incomplete param type");
+ assert(sz.isPositive() &&
+ "getObjCEncodingForFunctionDecl - Incomplete param type");
ParmOffset += sz;
}
S += charUnitsToString(ParmOffset);
ParmOffset += getObjCEncodingTypeSize(PType);
}
- return false;
+ return S;
}
/// getObjCEncodingForMethodParameter - Return the encoded type for a single
/// getObjCEncodingForMethodDecl - Return the encoded type for this method
/// declaration.
-bool ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
- std::string& S,
- bool Extended) const {
+std::string ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
+ bool Extended) const {
// FIXME: This is not very efficient.
// Encode return type.
+ std::string S;
getObjCEncodingForMethodParameter(Decl->getObjCDeclQualifier(),
Decl->getReturnType(), S, Extended);
// Compute size of all parameters.
ParmOffset += getObjCEncodingTypeSize(PType);
}
- return false;
+ return S;
}
ObjCPropertyImplDecl *
/// kPropertyNonAtomic = 'N' // property non-atomic
/// };
/// @endcode
-void ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
- const Decl *Container,
- std::string& S) const {
+std::string
+ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
+ const Decl *Container) const {
// Collect information from the property implementation decl(s).
bool Dynamic = false;
ObjCPropertyImplDecl *SynthesizePID = nullptr;
}
// FIXME: This is not very efficient.
- S = "T";
+ std::string S = "T";
// Encode result type.
// GCC has some special rules regarding encoding of properties which
}
// FIXME: OBJCGC: weak & strong
+ return S;
}
/// getLegacyIntegralTypeEncoding -
if ((R.getKind() == ObjCRuntime::GNUstep) &&
(R.getVersion() >= VersionTuple(1, 6))) {
std::string NameAndAttributes;
- std::string TypeStr;
- CGM.getContext().getObjCEncodingForPropertyDecl(PD, Container, TypeStr);
+ std::string TypeStr =
+ CGM.getContext().getObjCEncodingForPropertyDecl(PD, Container);
NameAndAttributes += '\0';
NameAndAttributes += TypeStr.length() + 3;
NameAndAttributes += TypeStr;
llvm::Value *CGObjCGNU::GetSelector(CodeGenFunction &CGF,
const ObjCMethodDecl *Method) {
- std::string SelTypes;
- CGM.getContext().getObjCEncodingForMethodDecl(Method, SelTypes);
+ std::string SelTypes = CGM.getContext().getObjCEncodingForMethodDecl(Method);
return GetSelector(CGF, Method->getSelector(), SelTypes);
}
SmallVector<llvm::Constant*, 16> OptionalInstanceMethodNames;
SmallVector<llvm::Constant*, 16> OptionalInstanceMethodTypes;
for (const auto *I : PD->instance_methods()) {
- std::string TypeStr;
- Context.getObjCEncodingForMethodDecl(I, TypeStr);
+ std::string TypeStr = Context.getObjCEncodingForMethodDecl(I);
if (I->getImplementationControl() == ObjCMethodDecl::Optional) {
OptionalInstanceMethodNames.push_back(
MakeConstantString(I->getSelector().getAsString()));
SmallVector<llvm::Constant*, 16> OptionalClassMethodNames;
SmallVector<llvm::Constant*, 16> OptionalClassMethodTypes;
for (const auto *I : PD->class_methods()) {
- std::string TypeStr;
- Context.getObjCEncodingForMethodDecl(I,TypeStr);
+ std::string TypeStr = Context.getObjCEncodingForMethodDecl(I);
if (I->getImplementationControl() == ObjCMethodDecl::Optional) {
OptionalClassMethodNames.push_back(
MakeConstantString(I->getSelector().getAsString()));
PushPropertyAttributes(fields, property);
if (ObjCMethodDecl *getter = property->getGetterMethodDecl()) {
- std::string typeStr;
- Context.getObjCEncodingForMethodDecl(getter, typeStr);
+ std::string typeStr = Context.getObjCEncodingForMethodDecl(getter);
llvm::Constant *typeEncoding = MakeConstantString(typeStr);
InstanceMethodTypes.push_back(typeEncoding);
fields.add(MakeConstantString(getter->getSelector().getAsString()));
fields.add(NULLPtr);
}
if (ObjCMethodDecl *setter = property->getSetterMethodDecl()) {
- std::string typeStr;
- Context.getObjCEncodingForMethodDecl(setter, typeStr);
+ std::string typeStr = Context.getObjCEncodingForMethodDecl(setter);
llvm::Constant *typeEncoding = MakeConstantString(typeStr);
InstanceMethodTypes.push_back(typeEncoding);
fields.add(MakeConstantString(setter->getSelector().getAsString()));
SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
for (const auto *I : OCD->instance_methods()) {
InstanceMethodSels.push_back(I->getSelector());
- std::string TypeStr;
- CGM.getContext().getObjCEncodingForMethodDecl(I,TypeStr);
+ std::string TypeStr = CGM.getContext().getObjCEncodingForMethodDecl(I);
InstanceMethodTypes.push_back(MakeConstantString(TypeStr));
}
SmallVector<llvm::Constant*, 16> ClassMethodTypes;
for (const auto *I : OCD->class_methods()) {
ClassMethodSels.push_back(I->getSelector());
- std::string TypeStr;
- CGM.getContext().getObjCEncodingForMethodDecl(I,TypeStr);
+ std::string TypeStr = CGM.getContext().getObjCEncodingForMethodDecl(I);
ClassMethodTypes.push_back(MakeConstantString(TypeStr));
}
fields.add(MakePropertyEncodingString(property, OID));
PushPropertyAttributes(fields, property, isSynthesized, isDynamic);
if (ObjCMethodDecl *getter = property->getGetterMethodDecl()) {
- std::string TypeStr;
- Context.getObjCEncodingForMethodDecl(getter,TypeStr);
+ std::string TypeStr = Context.getObjCEncodingForMethodDecl(getter);
llvm::Constant *TypeEncoding = MakeConstantString(TypeStr);
if (isSynthesized) {
InstanceMethodTypes.push_back(TypeEncoding);
fields.add(NULLPtr);
}
if (ObjCMethodDecl *setter = property->getSetterMethodDecl()) {
- std::string TypeStr;
- Context.getObjCEncodingForMethodDecl(setter,TypeStr);
+ std::string TypeStr = Context.getObjCEncodingForMethodDecl(setter);
llvm::Constant *TypeEncoding = MakeConstantString(TypeStr);
if (isSynthesized) {
InstanceMethodTypes.push_back(TypeEncoding);
SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
for (const auto *I : OID->instance_methods()) {
InstanceMethodSels.push_back(I->getSelector());
- std::string TypeStr;
- Context.getObjCEncodingForMethodDecl(I,TypeStr);
+ std::string TypeStr = Context.getObjCEncodingForMethodDecl(I);
InstanceMethodTypes.push_back(MakeConstantString(TypeStr));
}
SmallVector<llvm::Constant*, 16> ClassMethodTypes;
for (const auto *I : OID->class_methods()) {
ClassMethodSels.push_back(I->getSelector());
- std::string TypeStr;
- Context.getObjCEncodingForMethodDecl(I,TypeStr);
+ std::string TypeStr = Context.getObjCEncodingForMethodDecl(I);
ClassMethodTypes.push_back(MakeConstantString(TypeStr));
}
// Collect the names of referenced protocols
std::vector<llvm::Constant*> MethodTypesExt, OptMethodTypesExt;
for (const auto *MD : PD->instance_methods()) {
llvm::Constant *C = GetMethodDescriptionConstant(MD);
- if (!C)
- return GetOrEmitProtocolRef(PD);
if (MD->getImplementationControl() == ObjCMethodDecl::Optional) {
OptInstanceMethods.push_back(C);
for (const auto *MD : PD->class_methods()) {
llvm::Constant *C = GetMethodDescriptionConstant(MD);
- if (!C)
- return GetOrEmitProtocolRef(PD);
if (MD->getImplementationControl() == ObjCMethodDecl::Optional) {
OptClassMethods.push_back(C);
ObjCTypes.SelectorPtrTy),
GetMethodVarType(MD)
};
- if (!Desc[1])
- return nullptr;
return llvm::ConstantStruct::get(ObjCTypes.MethodDescriptionTy,
Desc);
llvm::Constant *CGObjCCommonMac::GetMethodVarType(const ObjCMethodDecl *D,
bool Extended) {
- std::string TypeStr;
- if (CGM.getContext().getObjCEncodingForMethodDecl(D, TypeStr, Extended))
- return nullptr;
+ std::string TypeStr =
+ CGM.getContext().getObjCEncodingForMethodDecl(D, Extended);
llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr];
if (!Entry)
llvm::Constant *
CGObjCCommonMac::GetPropertyTypeString(const ObjCPropertyDecl *PD,
const Decl *Container) {
- std::string TypeStr;
- CGM.getContext().getObjCEncodingForPropertyDecl(PD, Container, TypeStr);
+ std::string TypeStr =
+ CGM.getContext().getObjCEncodingForPropertyDecl(PD, Container);
return GetPropertyName(&CGM.getContext().Idents.get(TypeStr));
}
std::vector<llvm::Constant*> MethodTypesExt, OptMethodTypesExt;
for (const auto *MD : PD->instance_methods()) {
llvm::Constant *C = GetMethodDescriptionConstant(MD);
- if (!C)
- return GetOrEmitProtocolRef(PD);
if (MD->getImplementationControl() == ObjCMethodDecl::Optional) {
OptInstanceMethods.push_back(C);
for (const auto *MD : PD->class_methods()) {
llvm::Constant *C = GetMethodDescriptionConstant(MD);
- if (!C)
- return GetOrEmitProtocolRef(PD);
if (MD->getImplementationControl() == ObjCMethodDecl::Optional) {
OptClassMethods.push_back(C);
llvm::ConstantExpr::getBitCast(GetMethodVarName(MD->getSelector()),
ObjCTypes.SelectorPtrTy);
Desc[1] = GetMethodVarType(MD);
- if (!Desc[1])
- return nullptr;
// Protocol methods have no implementation. So, this entry is always NULL.
Desc[2] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
Result += "\t{(struct objc_selector *)\"";
Result += (MD)->getSelector().getAsString(); Result += "\"";
Result += ", ";
- std::string MethodTypeString;
- Context->getObjCEncodingForMethodDecl(MD, MethodTypeString);
+ std::string MethodTypeString = Context->getObjCEncodingForMethodDecl(MD);
Result += "\""; Result += MethodTypeString; Result += "\"";
Result += ", ";
if (!MethodImpl)
else
Result += "\t{\"";
Result += PropDecl->getName(); Result += "\",";
- std::string PropertyTypeString, QuotePropertyTypeString;
- Context->getObjCEncodingForPropertyDecl(PropDecl, Container, PropertyTypeString);
+ std::string PropertyTypeString =
+ Context->getObjCEncodingForPropertyDecl(PropDecl, Container);
+ std::string QuotePropertyTypeString;
RewriteObj.QuoteDoublequotes(PropertyTypeString, QuotePropertyTypeString);
Result += "\""; Result += QuotePropertyTypeString; Result += "\"";
if (i == e-1)
Result += "{\n";
for (unsigned i = 0, e = Methods.size(); i < e; i++) {
ObjCMethodDecl *MD = Methods[i];
- std::string MethodTypeString, QuoteMethodTypeString;
- Context->getObjCEncodingForMethodDecl(MD, MethodTypeString, true);
+ std::string MethodTypeString =
+ Context->getObjCEncodingForMethodDecl(MD, true);
+ std::string QuoteMethodTypeString;
RewriteObj.QuoteDoublequotes(MethodTypeString, QuoteMethodTypeString);
Result += "\t\""; Result += QuoteMethodTypeString; Result += "\"";
if (i == e-1)
else
Result += "\t ,{(struct objc_selector *)\"";
Result += (*I)->getSelector().getAsString();
- std::string MethodTypeString;
- Context->getObjCEncodingForMethodDecl((*I), MethodTypeString);
+ std::string MethodTypeString = Context->getObjCEncodingForMethodDecl(*I);
Result += "\", \"";
Result += MethodTypeString;
Result += "\"}\n";
else
Result += "\t ,{(struct objc_selector *)\"";
Result += (*I)->getSelector().getAsString();
- std::string MethodTypeString;
- Context->getObjCEncodingForMethodDecl((*I), MethodTypeString);
+ std::string MethodTypeString = Context->getObjCEncodingForMethodDecl(*I);
Result += "\", \"";
Result += MethodTypeString;
Result += "\"}\n";
Result += "\t,{{(SEL)\"";
Result += (*MethodBegin)->getSelector().getAsString();
- std::string MethodTypeString;
- Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString);
+ std::string MethodTypeString =
+ Context->getObjCEncodingForMethodDecl(*MethodBegin);
Result += "\", \"";
Result += MethodTypeString;
Result += "\", (void *)";
for (++MethodBegin; MethodBegin != MethodEnd; ++MethodBegin) {
Result += "\t ,{(SEL)\"";
Result += (*MethodBegin)->getSelector().getAsString();
- std::string MethodTypeString;
- Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString);
+ std::string MethodTypeString =
+ Context->getObjCEncodingForMethodDecl(*MethodBegin);
Result += "\", \"";
Result += MethodTypeString;
Result += "\", (void *)";
std::string encoding;
if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
- if (Ctx.getObjCEncodingForMethodDecl(OMD, encoding))
- return cxstring::createRef("?");
+ encoding = Ctx.getObjCEncodingForMethodDecl(OMD);
} else if (const ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D))
- Ctx.getObjCEncodingForPropertyDecl(OPD, nullptr, encoding);
+ encoding = Ctx.getObjCEncodingForPropertyDecl(OPD, nullptr);
else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
- Ctx.getObjCEncodingForFunctionDecl(FD, encoding);
+ encoding = Ctx.getObjCEncodingForFunctionDecl(FD);
else {
QualType Ty;
if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))