Lines Matching +full:suppress +full:- +full:preamble
1 //===-- RewriteModernObjC.cpp - Playground for the code rewriter ----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
77 std::string Preamble; member in __anonc09f721f0111::RewriteModernObjC
111 /* Misc. containers needed for meta-data rewrite. */
119 /// DefinedNonLazyClasses - List of defined "non-lazy" classes.
122 /// DefinedNonLazyCategories - List of defined "non-lazy" categories.
194 if (!Class->isThisDeclarationADefinition()) { in HandleTopLevelDecl()
205 if (!Proto->isThisDeclarationADefinition()) { in HandleTopLevelDecl()
216 if (FDecl->isThisDeclarationADefinition() && in HandleTopLevelDecl()
218 !FDecl->isTopLevelDeclInObjCContainer()) { in HandleTopLevelDecl()
231 if (isTopLevelBlockPointerType(TD->getUnderlyingType())) in HandleTopLevelDeclInObjCContainer()
233 else if (TD->getUnderlyingType()->isFunctionPointerType()) in HandleTopLevelDeclInObjCContainer()
234 CheckFunctionPointerDecl(TD->getUnderlyingType(), TD); in HandleTopLevelDeclInObjCContainer()
252 ReplaceStmtWithRange(Old, New, Old->getSourceRange()); in ReplaceStmt()
256 assert(Old != nullptr && New != nullptr && "Expected non-null Stmt's"); in ReplaceStmtWithRange()
267 if (Size == -1) { in ReplaceStmtWithRange()
268 Diags.Report(Context->getFullLoc(Old->getBeginLoc()), RewriteFailedDiag) in ReplaceStmtWithRange()
269 << Old->getSourceRange(); in ReplaceStmtWithRange()
275 New->printPretty(S, nullptr, PrintingPolicy(LangOpts)); in ReplaceStmtWithRange()
284 Diags.Report(Context->getFullLoc(Old->getBeginLoc()), RewriteFailedDiag) in ReplaceStmtWithRange()
285 << Old->getSourceRange(); in ReplaceStmtWithRange()
295 Diags.Report(Context->getFullLoc(Loc), RewriteFailedDiag); in InsertText()
305 Diags.Report(Context->getFullLoc(Start), RewriteFailedDiag); in ReplaceText()
498 // canonical type. We only care if the top-level type is a closure pointer.
503 /// convertBlockPointerToFunctionPointer - Converts a block-pointer type
508 const auto *BPT = T->castAs<BlockPointerType>(); in convertBlockPointerToFunctionPointer()
509 T = Context->getPointerType(BPT->getPointeeType()); in convertBlockPointerToFunctionPointer()
523 if (T->isObjCQualifiedIdType()) { in convertToUnqualifiedObjCType()
525 T = isConst ? Context->getObjCIdType().withConst() in convertToUnqualifiedObjCType()
526 : Context->getObjCIdType(); in convertToUnqualifiedObjCType()
528 else if (T->isObjCQualifiedClassType()) in convertToUnqualifiedObjCType()
529 T = Context->getObjCClassType(); in convertToUnqualifiedObjCType()
530 else if (T->isObjCObjectPointerType() && in convertToUnqualifiedObjCType()
531 T->getPointeeType()->isObjCQualifiedInterfaceType()) { in convertToUnqualifiedObjCType()
533 T->getAsObjCInterfacePointerType()) { in convertToUnqualifiedObjCType()
534 const ObjCInterfaceType *IFaceT = OBJPT->getInterfaceType(); in convertToUnqualifiedObjCType()
536 T = Context->getPointerType(T); in convertToUnqualifiedObjCType()
546 QualType OCT = Context->getCanonicalType(T).getUnqualifiedType(); in isObjCType()
548 if (OCT == Context->getCanonicalType(Context->getObjCIdType()) || in isObjCType()
549 OCT == Context->getCanonicalType(Context->getObjCClassType())) in isObjCType()
552 if (const PointerType *PT = OCT->getAs<PointerType>()) { in isObjCType()
553 if (isa<ObjCInterfaceType>(PT->getPointeeType()) || in isObjCType()
554 PT->getPointeeType()->isObjCQualifiedIdType()) in isObjCType()
577 if (result == Context->getObjCInstanceType()) in getSimpleFunctionType()
578 result = Context->getObjCIdType(); in getSimpleFunctionType()
581 return Context->getFunctionType(result, args, fpi); in getSimpleFunctionType()
587 TypeSourceInfo *TInfo = Ctx->getTrivialTypeSourceInfo(Ty, SourceLocation()); in NoTypeInfoCStyleCastExpr()
594 const IdentifierInfo *II = &Context->Idents.get("load"); in ImplementationIsNonLazy()
595 Selector LoadSel = Context->Selectors.getSelector(0, &II); in ImplementationIsNonLazy()
596 return OD->getClassMethod(LoadSel) != nullptr; in ImplementationIsNonLazy()
600 QualType StrType = Context->getConstantArrayType( in getStringLiteral()
601 Context->CharTy, llvm::APInt(32, Str.size() + 1), nullptr, in getStringLiteral()
613 for (const auto &I : fproto->param_types()) in RewriteBlocksInFunctionProtoType()
623 const PointerType *PT = funcType->getAs<PointerType>(); in CheckFunctionPointerDecl()
625 RewriteBlocksInFunctionProtoType(PT->getPointeeType(), ND); in CheckFunctionPointerDecl()
651 "rewriting sub-expression within a macro (may not be correct)"); in RewriteModernObjC()
659 "rewriter doesn't support user-specified control flow semantics " in RewriteModernObjC()
674 SM = &Context->getSourceManager(); in InitializeCommon()
675 TUDecl = Context->getTranslationUnitDecl(); in InitializeCommon()
704 MainFileID = SM->getMainFileID(); in InitializeCommon()
705 llvm::MemoryBufferRef MainBuf = SM->getBufferOrFake(MainFileID); in InitializeCommon()
709 Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts()); in InitializeCommon()
712 //===----------------------------------------------------------------------===//
714 //===----------------------------------------------------------------------===//
723 SourceLocation Loc = D->getLocation(); in HandleTopLevelSingleDecl()
724 Loc = SM->getExpansionLoc(Loc); in HandleTopLevelSingleDecl()
729 // Look for built-in declarations that we need to refer during the rewrite. in HandleTopLevelSingleDecl()
734 if (FVD->getName() == "_NSConstantStringClassReference") { in HandleTopLevelSingleDecl()
741 if (PD->isThisDeclarationADefinition()) in HandleTopLevelSingleDecl()
745 for (DeclContext::decl_iterator DI = LSD->decls_begin(), in HandleTopLevelSingleDecl()
746 DIEnd = LSD->decls_end(); in HandleTopLevelSingleDecl()
749 if (!IFace->isThisDeclarationADefinition()) { in HandleTopLevelSingleDecl()
751 SourceLocation StartLoc = IFace->getBeginLoc(); in HandleTopLevelSingleDecl()
754 !cast<ObjCInterfaceDecl>(*DI)->isThisDeclarationADefinition() && in HandleTopLevelSingleDecl()
755 StartLoc == (*DI)->getBeginLoc()) in HandleTopLevelSingleDecl()
774 if (!Proto->isThisDeclarationADefinition()) { in HandleTopLevelSingleDecl()
776 SourceLocation StartLoc = Proto->getBeginLoc(); in HandleTopLevelSingleDecl()
779 !cast<ObjCProtocolDecl>(*DI)->isThisDeclarationADefinition() && in HandleTopLevelSingleDecl()
780 StartLoc == (*DI)->getBeginLoc()) in HandleTopLevelSingleDecl()
797 if (SM->isWrittenInMainFile(Loc)) in HandleTopLevelSingleDecl()
801 //===----------------------------------------------------------------------===//
802 // Syntactic (non-AST) Rewriting Code
803 //===----------------------------------------------------------------------===//
806 SourceLocation LocStart = SM->getLocForStartOfFile(MainFileID); in RewriteInclude()
807 StringRef MainBuf = SM->getBufferData(MainFileID); in RewriteInclude()
823 LocStart.getLocWithOffset(BufPtr-MainBufStart); in RewriteInclude()
834 Result += IDecl->getName(); in WriteInternalIvarName()
836 Result += IvarDecl->getName(); in WriteInternalIvarName()
841 const ObjCInterfaceDecl *ClassDecl = D->getContainingInterface(); in getIvarAccessString()
845 if (D->isBitField()) in getIvarAccessString()
851 QualType IvarT = D->getType(); in getIvarAccessString()
852 if (D->isBitField()) in getIvarAccessString()
855 if (!IvarT->getAs<TypedefType>() && IvarT->isRecordType()) { in getIvarAccessString()
856 RecordDecl *RD = IvarT->castAs<RecordType>()->getDecl(); in getIvarAccessString()
857 RD = RD->getDefinition(); in getIvarAccessString()
858 if (RD && !RD->getDeclName().getAsIdentifierInfo()) { in getIvarAccessString()
859 // decltype(((Foo_IMPL*)0)->bar) * in getIvarAccessString()
860 auto *CDecl = cast<ObjCContainerDecl>(D->getDeclContext()); in getIvarAccessString()
863 CDecl = CatDecl->getClassInterface(); in getIvarAccessString()
864 std::string RecName = std::string(CDecl->getName()); in getIvarAccessString()
868 &Context->Idents.get(RecName)); in getIvarAccessString()
869 QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD)); in getIvarAccessString()
871 static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); in getIvarAccessString()
874 Context->UnsignedIntTy, SourceLocation()); in getIvarAccessString()
880 &Context->Idents.get(D->getNameAsString()), in getIvarAccessString()
885 *Context, PE, true, FD, FD->getType(), VK_LValue, OK_Ordinary); in getIvarAccessString()
886 IvarT = Context->getDecltypeType(ME, ME->getType()); in getIvarAccessString()
890 QualType castT = Context->getPointerType(IvarT); in getIvarAccessString()
891 std::string TypeString(castT.getAsString(Context->getPrintingPolicy())); in getIvarAccessString()
899 if (D->isBitField()) { in getIvarAccessString()
901 S += D->getNameAsString(); in getIvarAccessString()
907 /// mustSynthesizeSetterGetterMethod - returns true if setter or getter has not
912 auto *OMD = IMP->getInstanceMethod(getter ? PD->getGetterName() in mustSynthesizeSetterGetterMethod()
913 : PD->getSetterName()); in mustSynthesizeSetterGetterMethod()
914 return !OMD || OMD->isSynthesizedAccessorStub(); in mustSynthesizeSetterGetterMethod()
924 if (PID->getBeginLoc().isValid()) { in RewritePropertyImplDecl()
925 SourceLocation startLoc = PID->getBeginLoc(); in RewritePropertyImplDecl()
927 const char *startBuf = SM->getCharacterData(startLoc); in RewritePropertyImplDecl()
931 startGetterSetterLoc = startLoc.getLocWithOffset(semiBuf-startBuf+1); in RewritePropertyImplDecl()
933 startGetterSetterLoc = IMD ? IMD->getEndLoc() : CID->getEndLoc(); in RewritePropertyImplDecl()
935 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) in RewritePropertyImplDecl()
939 ObjCPropertyDecl *PD = PID->getPropertyDecl(); in RewritePropertyImplDecl()
940 ObjCIvarDecl *OID = PID->getPropertyIvarDecl(); in RewritePropertyImplDecl()
943 unsigned Attributes = PD->getPropertyAttributes(); in RewritePropertyImplDecl()
956 RewriteObjCMethodDecl(OID->getContainingInterface(), in RewritePropertyImplDecl()
957 PID->getGetterMethodDecl(), Getr); in RewritePropertyImplDecl()
960 // See objc-act.c:objc_synthesize_new_getter() for details. in RewritePropertyImplDecl()
965 RewriteTypeIntoString(PID->getGetterMethodDecl()->getReturnType(), Getr, in RewritePropertyImplDecl()
974 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { in RewritePropertyImplDecl()
977 FT->getParamType(i).getAsString(Context->getPrintingPolicy()); in RewritePropertyImplDecl()
980 if (FT->isVariadic()) { in RewritePropertyImplDecl()
981 if (FT->getNumParams()) in RewritePropertyImplDecl()
1001 if (PD->isReadOnly() || in RewritePropertyImplDecl()
1016 RewriteObjCMethodDecl(OID->getContainingInterface(), in RewritePropertyImplDecl()
1017 PID->getSetterMethodDecl(), Setr); in RewritePropertyImplDecl()
1020 // See objc-act.c:objc_synthesize_new_setter() for details. in RewritePropertyImplDecl()
1025 Setr += PD->getName(); in RewritePropertyImplDecl()
1038 Setr += PD->getName(); in RewritePropertyImplDecl()
1047 typedefString += ForwardDecl->getNameAsString(); in RewriteOneForwardClassDecl()
1050 typedefString += ForwardDecl->getNameAsString(); in RewriteOneForwardClassDecl()
1053 typedefString += ForwardDecl->getNameAsString(); in RewriteOneForwardClassDecl()
1056 typedefString += ForwardDecl->getNameAsString(); in RewriteOneForwardClassDecl()
1062 SourceLocation startLoc = ClassDecl->getBeginLoc(); in RewriteForwardClassEpilogue()
1063 const char *startBuf = SM->getCharacterData(startLoc); in RewriteForwardClassEpilogue()
1066 ReplaceText(startLoc, semiPtr-startBuf+1, typedefString); in RewriteForwardClassEpilogue()
1078 typedefString += ForwardDecl->getNameAsString(); in RewriteForwardClassDecl()
1097 typedefString += ForwardDecl->getNameAsString(); in RewriteForwardClassDecl()
1108 if (Method->isImplicit()) in RewriteMethodDeclaration()
1110 SourceLocation LocStart = Method->getBeginLoc(); in RewriteMethodDeclaration()
1111 SourceLocation LocEnd = Method->getEndLoc(); in RewriteMethodDeclaration()
1113 if (SM->getExpansionLineNumber(LocEnd) > in RewriteMethodDeclaration()
1114 SM->getExpansionLineNumber(LocStart)) { in RewriteMethodDeclaration()
1123 SourceLocation Loc = prop->getAtLoc(); in RewriteProperty()
1130 SourceLocation LocStart = CatDecl->getBeginLoc(); in RewriteCategoryDecl()
1133 if (CatDecl->getIvarRBraceLoc().isValid()) { in RewriteCategoryDecl()
1135 ReplaceText(CatDecl->getIvarRBraceLoc(), 1, "**/ "); in RewriteCategoryDecl()
1141 for (auto *I : CatDecl->instance_properties()) in RewriteCategoryDecl()
1144 for (auto *I : CatDecl->instance_methods()) in RewriteCategoryDecl()
1146 for (auto *I : CatDecl->class_methods()) in RewriteCategoryDecl()
1150 ReplaceText(CatDecl->getAtEndRange().getBegin(), in RewriteCategoryDecl()
1155 SourceLocation LocStart = PDecl->getBeginLoc(); in RewriteProtocolDecl()
1156 assert(PDecl->isThisDeclarationADefinition()); in RewriteProtocolDecl()
1161 for (auto *I : PDecl->instance_methods()) in RewriteProtocolDecl()
1163 for (auto *I : PDecl->class_methods()) in RewriteProtocolDecl()
1165 for (auto *I : PDecl->instance_properties()) in RewriteProtocolDecl()
1169 SourceLocation LocEnd = PDecl->getAtEndRange().getBegin(); in RewriteProtocolDecl()
1173 const char *startBuf = SM->getCharacterData(LocStart); in RewriteProtocolDecl()
1174 const char *endBuf = SM->getCharacterData(LocEnd); in RewriteProtocolDecl()
1177 SourceLocation OptionalLoc = LocStart.getLocWithOffset(p-startBuf); in RewriteProtocolDecl()
1182 SourceLocation OptionalLoc = LocStart.getLocWithOffset(p-startBuf); in RewriteProtocolDecl()
1190 SourceLocation LocStart = (*D.begin())->getBeginLoc(); in RewriteForwardProtocolDecl()
1199 SourceLocation LocStart = DG[0]->getBeginLoc(); in RewriteForwardProtocolDecl()
1208 if (T->isObjCQualifiedIdType()) in RewriteTypeIntoString()
1210 else if (T->isFunctionPointerType() || in RewriteTypeIntoString()
1211 T->isBlockPointerType()) { in RewriteTypeIntoString()
1212 // needs special handling, since pointer-to-functions have special in RewriteTypeIntoString()
1216 if (const PointerType* PT = retType->getAs<PointerType>()) in RewriteTypeIntoString()
1217 PointeeTy = PT->getPointeeType(); in RewriteTypeIntoString()
1218 else if (const BlockPointerType *BPT = retType->getAs<BlockPointerType>()) in RewriteTypeIntoString()
1219 PointeeTy = BPT->getPointeeType(); in RewriteTypeIntoString()
1220 if ((FPRetType = PointeeTy->getAs<FunctionType>())) { in RewriteTypeIntoString()
1222 FPRetType->getReturnType().getAsString(Context->getPrintingPolicy()); in RewriteTypeIntoString()
1226 ResultStr += T.getAsString(Context->getPrintingPolicy()); in RewriteTypeIntoString()
1235 RewriteTypeIntoString(OMD->getReturnType(), ResultStr, FPRetType); in RewriteObjCMethodDecl()
1241 if (OMD->isInstanceMethod()) in RewriteObjCMethodDecl()
1246 NameStr += IDecl->getNameAsString(); in RewriteObjCMethodDecl()
1250 dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext())) { in RewriteObjCMethodDecl()
1251 NameStr += CID->getNameAsString(); in RewriteObjCMethodDecl()
1256 std::string selString = OMD->getSelector().getAsString(); in RewriteObjCMethodDecl()
1271 if (OMD->isInstanceMethod()) { in RewriteObjCMethodDecl()
1272 QualType selfTy = Context->getObjCInterfaceType(IDecl); in RewriteObjCMethodDecl()
1273 selfTy = Context->getPointerType(selfTy); in RewriteObjCMethodDecl()
1279 ResultStr += IDecl->getNameAsString(); in RewriteObjCMethodDecl()
1283 ResultStr += Context->getObjCClassType().getAsString( in RewriteObjCMethodDecl()
1284 Context->getPrintingPolicy()); in RewriteObjCMethodDecl()
1287 ResultStr += Context->getObjCSelType().getAsString(Context->getPrintingPolicy()); in RewriteObjCMethodDecl()
1291 for (const auto *PDecl : OMD->parameters()) { in RewriteObjCMethodDecl()
1293 if (PDecl->getType()->isObjCQualifiedIdType()) { in RewriteObjCMethodDecl()
1295 ResultStr += PDecl->getNameAsString(); in RewriteObjCMethodDecl()
1297 std::string Name = PDecl->getNameAsString(); in RewriteObjCMethodDecl()
1298 QualType QT = PDecl->getType(); in RewriteObjCMethodDecl()
1301 QT.getAsStringInternal(Name, Context->getPrintingPolicy()); in RewriteObjCMethodDecl()
1305 if (OMD->isVariadic()) in RewriteObjCMethodDecl()
1315 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { in RewriteObjCMethodDecl()
1318 FT->getParamType(i).getAsString(Context->getPrintingPolicy()); in RewriteObjCMethodDecl()
1321 if (FT->isVariadic()) { in RewriteObjCMethodDecl()
1322 if (FT->getNumParams()) in RewriteObjCMethodDecl()
1339 if (IMD->getIvarRBraceLoc().isValid()) { in RewriteImplementationDecl()
1340 ReplaceText(IMD->getBeginLoc(), 1, "/** "); in RewriteImplementationDecl()
1341 ReplaceText(IMD->getIvarRBraceLoc(), 1, "**/ "); in RewriteImplementationDecl()
1344 InsertText(IMD->getBeginLoc(), "// "); in RewriteImplementationDecl()
1348 InsertText(CID->getBeginLoc(), "// "); in RewriteImplementationDecl()
1350 for (auto *OMD : IMD ? IMD->instance_methods() : CID->instance_methods()) { in RewriteImplementationDecl()
1351 if (!OMD->getBody()) in RewriteImplementationDecl()
1354 RewriteObjCMethodDecl(OMD->getClassInterface(), OMD, ResultStr); in RewriteImplementationDecl()
1355 SourceLocation LocStart = OMD->getBeginLoc(); in RewriteImplementationDecl()
1356 SourceLocation LocEnd = OMD->getCompoundBody()->getBeginLoc(); in RewriteImplementationDecl()
1358 const char *startBuf = SM->getCharacterData(LocStart); in RewriteImplementationDecl()
1359 const char *endBuf = SM->getCharacterData(LocEnd); in RewriteImplementationDecl()
1360 ReplaceText(LocStart, endBuf-startBuf, ResultStr); in RewriteImplementationDecl()
1363 for (auto *OMD : IMD ? IMD->class_methods() : CID->class_methods()) { in RewriteImplementationDecl()
1364 if (!OMD->getBody()) in RewriteImplementationDecl()
1367 RewriteObjCMethodDecl(OMD->getClassInterface(), OMD, ResultStr); in RewriteImplementationDecl()
1368 SourceLocation LocStart = OMD->getBeginLoc(); in RewriteImplementationDecl()
1369 SourceLocation LocEnd = OMD->getCompoundBody()->getBeginLoc(); in RewriteImplementationDecl()
1371 const char *startBuf = SM->getCharacterData(LocStart); in RewriteImplementationDecl()
1372 const char *endBuf = SM->getCharacterData(LocEnd); in RewriteImplementationDecl()
1373 ReplaceText(LocStart, endBuf-startBuf, ResultStr); in RewriteImplementationDecl()
1375 for (auto *I : IMD ? IMD->property_impls() : CID->property_impls()) in RewriteImplementationDecl()
1378 InsertText(IMD ? IMD->getEndLoc() : CID->getEndLoc(), "// "); in RewriteImplementationDecl()
1386 ObjCInterfaceDecl *SuperClass = ClassDecl->getSuperClass(); in RewriteInterfaceDecl()
1389 SuperClass = SuperClass->getSuperClass(); in RewriteInterfaceDecl()
1392 if (!ObjCWrittenInterfaces.count(ClassDecl->getCanonicalDecl())) { in RewriteInterfaceDecl()
1393 // we haven't seen a forward decl - generate a typedef. in RewriteInterfaceDecl()
1399 ObjCWrittenInterfaces.insert(ClassDecl->getCanonicalDecl()); in RewriteInterfaceDecl()
1401 for (auto *I : ClassDecl->instance_properties()) in RewriteInterfaceDecl()
1403 for (auto *I : ClassDecl->instance_methods()) in RewriteInterfaceDecl()
1405 for (auto *I : ClassDecl->class_methods()) in RewriteInterfaceDecl()
1409 ReplaceText(ClassDecl->getAtEndRange().getBegin(), strlen("@end"), in RewriteInterfaceDecl()
1415 SourceRange OldRange = PseudoOp->getSourceRange(); in RewritePropertyOrImplicitSetter()
1420 cast<ObjCMessageExpr>(PseudoOp->getSemanticExpr( in RewritePropertyOrImplicitSetter()
1421 PseudoOp->getNumSemanticExprs() - 1)); in RewritePropertyOrImplicitSetter()
1424 // we need to suppress rewriting the sub-statements. in RewritePropertyOrImplicitSetter()
1432 if (OldMsg->getReceiverKind() == ObjCMessageExpr::Instance) { in RewritePropertyOrImplicitSetter()
1433 Base = OldMsg->getInstanceReceiver(); in RewritePropertyOrImplicitSetter()
1434 Base = cast<OpaqueValueExpr>(Base)->getSourceExpr(); in RewritePropertyOrImplicitSetter()
1438 unsigned numArgs = OldMsg->getNumArgs(); in RewritePropertyOrImplicitSetter()
1440 Expr *Arg = OldMsg->getArg(i); in RewritePropertyOrImplicitSetter()
1442 Arg = cast<OpaqueValueExpr>(Arg)->getSourceExpr(); in RewritePropertyOrImplicitSetter()
1450 OldMsg->getSelectorLocs(SelLocs); in RewritePropertyOrImplicitSetter()
1453 switch (OldMsg->getReceiverKind()) { in RewritePropertyOrImplicitSetter()
1455 NewMsg = ObjCMessageExpr::Create(*Context, OldMsg->getType(), in RewritePropertyOrImplicitSetter()
1456 OldMsg->getValueKind(), in RewritePropertyOrImplicitSetter()
1457 OldMsg->getLeftLoc(), in RewritePropertyOrImplicitSetter()
1458 OldMsg->getClassReceiverTypeInfo(), in RewritePropertyOrImplicitSetter()
1459 OldMsg->getSelector(), in RewritePropertyOrImplicitSetter()
1461 OldMsg->getMethodDecl(), in RewritePropertyOrImplicitSetter()
1463 OldMsg->getRightLoc(), in RewritePropertyOrImplicitSetter()
1464 OldMsg->isImplicit()); in RewritePropertyOrImplicitSetter()
1468 NewMsg = ObjCMessageExpr::Create(*Context, OldMsg->getType(), in RewritePropertyOrImplicitSetter()
1469 OldMsg->getValueKind(), in RewritePropertyOrImplicitSetter()
1470 OldMsg->getLeftLoc(), in RewritePropertyOrImplicitSetter()
1472 OldMsg->getSelector(), in RewritePropertyOrImplicitSetter()
1474 OldMsg->getMethodDecl(), in RewritePropertyOrImplicitSetter()
1476 OldMsg->getRightLoc(), in RewritePropertyOrImplicitSetter()
1477 OldMsg->isImplicit()); in RewritePropertyOrImplicitSetter()
1482 NewMsg = ObjCMessageExpr::Create(*Context, OldMsg->getType(), in RewritePropertyOrImplicitSetter()
1483 OldMsg->getValueKind(), in RewritePropertyOrImplicitSetter()
1484 OldMsg->getLeftLoc(), in RewritePropertyOrImplicitSetter()
1485 OldMsg->getSuperLoc(), in RewritePropertyOrImplicitSetter()
1486 OldMsg->getReceiverKind() == ObjCMessageExpr::SuperInstance, in RewritePropertyOrImplicitSetter()
1487 OldMsg->getSuperType(), in RewritePropertyOrImplicitSetter()
1488 OldMsg->getSelector(), in RewritePropertyOrImplicitSetter()
1490 OldMsg->getMethodDecl(), in RewritePropertyOrImplicitSetter()
1492 OldMsg->getRightLoc(), in RewritePropertyOrImplicitSetter()
1493 OldMsg->isImplicit()); in RewritePropertyOrImplicitSetter()
1503 SourceRange OldRange = PseudoOp->getSourceRange(); in RewritePropertyOrImplicitGetter()
1508 cast<ObjCMessageExpr>(PseudoOp->getResultExpr()->IgnoreImplicit()); in RewritePropertyOrImplicitGetter()
1511 // we need to suppress rewriting the sub-statements. in RewritePropertyOrImplicitGetter()
1517 if (OldMsg->getReceiverKind() == ObjCMessageExpr::Instance) { in RewritePropertyOrImplicitGetter()
1518 Base = OldMsg->getInstanceReceiver(); in RewritePropertyOrImplicitGetter()
1519 Base = cast<OpaqueValueExpr>(Base)->getSourceExpr(); in RewritePropertyOrImplicitGetter()
1522 unsigned numArgs = OldMsg->getNumArgs(); in RewritePropertyOrImplicitGetter()
1524 Expr *Arg = OldMsg->getArg(i); in RewritePropertyOrImplicitGetter()
1526 Arg = cast<OpaqueValueExpr>(Arg)->getSourceExpr(); in RewritePropertyOrImplicitGetter()
1536 switch (OldMsg->getReceiverKind()) { in RewritePropertyOrImplicitGetter()
1538 NewMsg = ObjCMessageExpr::Create(*Context, OldMsg->getType(), in RewritePropertyOrImplicitGetter()
1539 OldMsg->getValueKind(), in RewritePropertyOrImplicitGetter()
1540 OldMsg->getLeftLoc(), in RewritePropertyOrImplicitGetter()
1541 OldMsg->getClassReceiverTypeInfo(), in RewritePropertyOrImplicitGetter()
1542 OldMsg->getSelector(), in RewritePropertyOrImplicitGetter()
1544 OldMsg->getMethodDecl(), in RewritePropertyOrImplicitGetter()
1546 OldMsg->getRightLoc(), in RewritePropertyOrImplicitGetter()
1547 OldMsg->isImplicit()); in RewritePropertyOrImplicitGetter()
1551 NewMsg = ObjCMessageExpr::Create(*Context, OldMsg->getType(), in RewritePropertyOrImplicitGetter()
1552 OldMsg->getValueKind(), in RewritePropertyOrImplicitGetter()
1553 OldMsg->getLeftLoc(), in RewritePropertyOrImplicitGetter()
1555 OldMsg->getSelector(), in RewritePropertyOrImplicitGetter()
1557 OldMsg->getMethodDecl(), in RewritePropertyOrImplicitGetter()
1559 OldMsg->getRightLoc(), in RewritePropertyOrImplicitGetter()
1560 OldMsg->isImplicit()); in RewritePropertyOrImplicitGetter()
1565 NewMsg = ObjCMessageExpr::Create(*Context, OldMsg->getType(), in RewritePropertyOrImplicitGetter()
1566 OldMsg->getValueKind(), in RewritePropertyOrImplicitGetter()
1567 OldMsg->getLeftLoc(), in RewritePropertyOrImplicitGetter()
1568 OldMsg->getSuperLoc(), in RewritePropertyOrImplicitGetter()
1569 OldMsg->getReceiverKind() == ObjCMessageExpr::SuperInstance, in RewritePropertyOrImplicitGetter()
1570 OldMsg->getSuperType(), in RewritePropertyOrImplicitGetter()
1571 OldMsg->getSelector(), in RewritePropertyOrImplicitGetter()
1573 OldMsg->getMethodDecl(), in RewritePropertyOrImplicitGetter()
1575 OldMsg->getRightLoc(), in RewritePropertyOrImplicitGetter()
1576 OldMsg->isImplicit()); in RewritePropertyOrImplicitGetter()
1585 /// SynthCountByEnumWithState - To print:
1605 /// RewriteBreakStmt - Rewrite for a break-stmt inside an ObjC2's foreach
1614 SourceLocation startLoc = S->getBeginLoc(); in RewriteBreakStmt()
1627 PresumedLoc PLoc = SM->getPresumedLoc(Loc); in ConvertSourceLocationToLineDirective()
1635 /// RewriteContinueStmt - Rewrite for a continue-stmt inside an ObjC2's foreach
1644 SourceLocation startLoc = S->getBeginLoc(); in RewriteContinueStmt()
1652 /// RewriteObjCForCollectionStmt - Rewriter for ObjC2's foreach statement.
1686 assert(!Stmts.empty() && "ObjCForCollectionStmt - Statement stack empty"); in RewriteObjCForCollectionStmt()
1690 "ObjCForCollectionStmt - Label No stack empty"); in RewriteObjCForCollectionStmt()
1692 SourceLocation startLoc = S->getBeginLoc(); in RewriteObjCForCollectionStmt()
1693 const char *startBuf = SM->getCharacterData(startLoc); in RewriteObjCForCollectionStmt()
1698 SourceLocation ForEachLoc = S->getForLoc(); in RewriteObjCForCollectionStmt()
1701 if (DeclStmt *DS = dyn_cast<DeclStmt>(S->getElement())) { in RewriteObjCForCollectionStmt()
1703 NamedDecl* D = cast<NamedDecl>(DS->getSingleDecl()); in RewriteObjCForCollectionStmt()
1704 QualType ElementType = cast<ValueDecl>(D)->getType(); in RewriteObjCForCollectionStmt()
1705 if (ElementType->isObjCQualifiedIdType() || in RewriteObjCForCollectionStmt()
1706 ElementType->isObjCQualifiedInterfaceType()) in RewriteObjCForCollectionStmt()
1710 elementTypeAsString = ElementType.getAsString(Context->getPrintingPolicy()); in RewriteObjCForCollectionStmt()
1713 elementName = D->getName(); in RewriteObjCForCollectionStmt()
1718 DeclRefExpr *DR = cast<DeclRefExpr>(S->getElement()); in RewriteObjCForCollectionStmt()
1719 elementName = DR->getDecl()->getName(); in RewriteObjCForCollectionStmt()
1720 ValueDecl *VD = DR->getDecl(); in RewriteObjCForCollectionStmt()
1721 if (VD->getType()->isObjCQualifiedIdType() || in RewriteObjCForCollectionStmt()
1722 VD->getType()->isObjCQualifiedInterfaceType()) in RewriteObjCForCollectionStmt()
1726 elementTypeAsString = VD->getType().getAsString(Context->getPrintingPolicy()); in RewriteObjCForCollectionStmt()
1749 ReplaceText(startLoc, startCollectionBuf - startBuf, buf); in RewriteObjCForCollectionStmt()
1751 SourceLocation rightParenLoc = S->getRParenLoc(); in RewriteObjCForCollectionStmt()
1752 const char *rparenBuf = SM->getCharacterData(rightParenLoc); in RewriteObjCForCollectionStmt()
1753 SourceLocation lparenLoc = startLoc.getLocWithOffset(rparenBuf-startBuf); in RewriteObjCForCollectionStmt()
1828 // FIXME: If this should support Obj-C++, support CXXTryStmt in RewriteObjCForCollectionStmt()
1829 if (isa<CompoundStmt>(S->getBody())) { in RewriteObjCForCollectionStmt()
1840 const char *stmtBuf = SM->getCharacterData(OrigEnd); in RewriteObjCForCollectionStmt()
1843 SourceLocation endBodyLoc = OrigEnd.getLocWithOffset(semiBuf-stmtBuf+1); in RewriteObjCForCollectionStmt()
1858 /// RewriteObjCSynchronizedStmt -
1866 SourceLocation startLoc = S->getBeginLoc(); in RewriteObjCSynchronizedStmt()
1867 const char *startBuf = SM->getCharacterData(startLoc); in RewriteObjCSynchronizedStmt()
1872 SourceLocation SynchLoc = S->getAtSynchronizedLoc(); in RewriteObjCSynchronizedStmt()
1878 ReplaceText(startLoc, lparenBuf-startBuf+1, buf); in RewriteObjCSynchronizedStmt()
1886 // We can't use S->getSynchExpr()->getEndLoc() to find the end location, since in RewriteObjCSynchronizedStmt()
1889 SourceLocation RParenExprLoc = S->getSynchBody()->getBeginLoc(); in RewriteObjCSynchronizedStmt()
1890 const char *RParenExprLocBuf = SM->getCharacterData(RParenExprLoc); in RewriteObjCSynchronizedStmt()
1891 while (*RParenExprLocBuf != ')') RParenExprLocBuf--; in RewriteObjCSynchronizedStmt()
1892 RParenExprLoc = startLoc.getLocWithOffset(RParenExprLocBuf-startBuf); in RewriteObjCSynchronizedStmt()
1894 SourceLocation LBranceLoc = S->getSynchBody()->getBeginLoc(); in RewriteObjCSynchronizedStmt()
1895 const char *LBraceLocBuf = SM->getCharacterData(LBranceLoc); in RewriteObjCSynchronizedStmt()
1897 ReplaceText(RParenExprLoc, (LBraceLocBuf - SM->getCharacterData(RParenExprLoc) + 1), buf); in RewriteObjCSynchronizedStmt()
1899 SourceLocation startRBraceLoc = S->getSynchBody()->getEndLoc(); in RewriteObjCSynchronizedStmt()
1900 assert((*SM->getCharacterData(startRBraceLoc) == '}') && in RewriteObjCSynchronizedStmt()
1916 for (Stmt *SubStmt : S->children()) in WarnAboutReturnGotoStmts()
1921 Diags.Report(Context->getFullLoc(S->getBeginLoc()), in WarnAboutReturnGotoStmts()
1927 SourceLocation startLoc = S->getAtLoc(); in RewriteObjCAutoreleasePoolStmt()
1929 ReplaceText(S->getSubStmt()->getBeginLoc(), 1, in RewriteObjCAutoreleasePoolStmt()
1936 ObjCAtFinallyStmt *finalStmt = S->getFinallyStmt(); in RewriteObjCTryStmt()
1937 bool noCatch = S->getNumCatchStmts() == 0; in RewriteObjCTryStmt()
1939 SourceLocation TryLocation = S->getAtTryLoc(); in RewriteObjCTryStmt()
1950 SourceLocation startLoc = S->getBeginLoc(); in RewriteObjCTryStmt()
1951 const char *startBuf = SM->getCharacterData(startLoc); in RewriteObjCTryStmt()
1957 // @try -> try in RewriteObjCTryStmt()
1960 for (ObjCAtCatchStmt *Catch : S->catch_stmts()) { in RewriteObjCTryStmt()
1961 VarDecl *catchDecl = Catch->getCatchParamDecl(); in RewriteObjCTryStmt()
1963 startLoc = Catch->getBeginLoc(); in RewriteObjCTryStmt()
1966 QualType t = catchDecl->getType(); in RewriteObjCTryStmt()
1968 t->getAs<ObjCObjectPointerType>()) { in RewriteObjCTryStmt()
1970 ObjCInterfaceDecl *IDecl = Ptr->getObjectType()->getInterface(); in RewriteObjCTryStmt()
1973 ConvertSourceLocationToLineDirective(Catch->getBeginLoc(), Result); in RewriteObjCTryStmt()
1975 startBuf = SM->getCharacterData(startLoc); in RewriteObjCTryStmt()
1977 SourceLocation rParenLoc = Catch->getRParenLoc(); in RewriteObjCTryStmt()
1978 const char *rParenBuf = SM->getCharacterData(rParenLoc); in RewriteObjCTryStmt()
1981 Result += "catch (_objc_exc_"; Result += IDecl->getNameAsString(); in RewriteObjCTryStmt()
1982 Result += " *_"; Result += catchDecl->getNameAsString(); in RewriteObjCTryStmt()
1984 ReplaceText(startLoc, rParenBuf-startBuf+1, Result); in RewriteObjCTryStmt()
1988 Result += IDecl->getNameAsString(); in RewriteObjCTryStmt()
1989 Result += " *"; Result += catchDecl->getNameAsString(); in RewriteObjCTryStmt()
1990 Result += " = ("; Result += IDecl->getNameAsString(); Result += "*)"; in RewriteObjCTryStmt()
1991 Result += "_"; Result += catchDecl->getNameAsString(); in RewriteObjCTryStmt()
1994 SourceLocation lBraceLoc = Catch->getCatchBody()->getBeginLoc(); in RewriteObjCTryStmt()
2001 // @catch -> catch in RewriteObjCTryStmt()
2007 SourceLocation FinallyLoc = finalStmt->getBeginLoc(); in RewriteObjCTryStmt()
2019 SourceLocation startFinalLoc = finalStmt->getBeginLoc(); in RewriteObjCTryStmt()
2021 Stmt *body = finalStmt->getFinallyBody(); in RewriteObjCTryStmt()
2022 SourceLocation startFinalBodyLoc = body->getBeginLoc(); in RewriteObjCTryStmt()
2027 SourceLocation endFinalBodyLoc = body->getEndLoc(); in RewriteObjCTryStmt()
2030 WarnAboutReturnGotoStmts(S->getTryBody()); in RewriteObjCTryStmt()
2041 SourceLocation startLoc = S->getBeginLoc(); in RewriteObjCThrowStmt()
2042 const char *startBuf = SM->getCharacterData(startLoc); in RewriteObjCThrowStmt()
2048 if (S->getThrowExpr()) in RewriteObjCThrowStmt()
2056 ReplaceText(startLoc, wBuf-startBuf+1, buf); in RewriteObjCThrowStmt()
2058 SourceLocation endLoc = S->getEndLoc(); in RewriteObjCThrowStmt()
2059 const char *endBuf = SM->getCharacterData(endLoc); in RewriteObjCThrowStmt()
2062 SourceLocation semiLoc = startLoc.getLocWithOffset(semiBuf-startBuf); in RewriteObjCThrowStmt()
2063 if (S->getThrowExpr()) in RewriteObjCThrowStmt()
2071 Context->getObjCEncodingForType(Exp->getEncodedType(), StrEncoding); in RewriteAtEncode()
2086 SelExprs.push_back(getStringLiteral(Exp->getSelector().getAsString())); in RewriteAtSelector()
2100 QualType msgSendType = FD->getType(); in SynthesizeCallToFunctionDecl()
2107 QualType pToFunc = Context->getPointerType(msgSendType); in SynthesizeCallToFunctionDecl()
2112 const auto *FT = msgSendType->castAs<FunctionType>(); in SynthesizeCallToFunctionDecl()
2114 CallExpr::Create(*Context, ICE, Args, FT->getCallResultType(*Context), in SynthesizeCallToFunctionDecl()
2142 angle--; in scanToNextArgument()
2145 assert(angle == 0 && "scanToNextArgument - bad protocol type syntax"); in scanToNextArgument()
2149 if (T->isObjCQualifiedIdType()) in needToScanForQualifiers()
2151 if (const PointerType *PT = T->getAs<PointerType>()) { in needToScanForQualifiers()
2152 if (PT->getPointeeType()->isObjCQualifiedIdType()) in needToScanForQualifiers()
2155 if (T->isObjCObjectPointerType()) { in needToScanForQualifiers()
2156 T = T->getPointeeType(); in needToScanForQualifiers()
2157 return T->isObjCQualifiedInterfaceType(); in needToScanForQualifiers()
2159 if (T->isArrayType()) { in needToScanForQualifiers()
2160 QualType ElemTy = Context->getBaseElementType(T); in needToScanForQualifiers()
2167 QualType Type = E->getType(); in RewriteObjCQualifiedInterfaceTypes()
2172 Loc = ECE->getLParenLoc(); in RewriteObjCQualifiedInterfaceTypes()
2173 EndLoc = ECE->getRParenLoc(); in RewriteObjCQualifiedInterfaceTypes()
2175 Loc = E->getBeginLoc(); in RewriteObjCQualifiedInterfaceTypes()
2176 EndLoc = E->getEndLoc(); in RewriteObjCQualifiedInterfaceTypes()
2182 const char *startBuf = SM->getCharacterData(Loc); in RewriteObjCQualifiedInterfaceTypes()
2183 const char *endBuf = SM->getCharacterData(EndLoc); in RewriteObjCQualifiedInterfaceTypes()
2187 SourceLocation LessLoc = Loc.getLocWithOffset(startRef-startBuf); in RewriteObjCQualifiedInterfaceTypes()
2188 SourceLocation GreaterLoc = Loc.getLocWithOffset(endRef-startBuf+1); in RewriteObjCQualifiedInterfaceTypes()
2201 Loc = VD->getLocation(); in RewriteObjCQualifiedInterfaceTypes()
2202 Type = VD->getType(); in RewriteObjCQualifiedInterfaceTypes()
2205 Loc = FD->getLocation(); in RewriteObjCQualifiedInterfaceTypes()
2208 const FunctionType *funcType = FD->getType()->getAs<FunctionType>(); in RewriteObjCQualifiedInterfaceTypes()
2213 Type = proto->getReturnType(); in RewriteObjCQualifiedInterfaceTypes()
2216 Loc = FD->getLocation(); in RewriteObjCQualifiedInterfaceTypes()
2217 Type = FD->getType(); in RewriteObjCQualifiedInterfaceTypes()
2220 Loc = TD->getLocation(); in RewriteObjCQualifiedInterfaceTypes()
2221 Type = TD->getUnderlyingType(); in RewriteObjCQualifiedInterfaceTypes()
2229 const char *endBuf = SM->getCharacterData(Loc); in RewriteObjCQualifiedInterfaceTypes()
2232 startBuf--; // scan backward (from the decl location) for return type. in RewriteObjCQualifiedInterfaceTypes()
2236 SourceLocation LessLoc = Loc.getLocWithOffset(startRef-endBuf); in RewriteObjCQualifiedInterfaceTypes()
2237 SourceLocation GreaterLoc = Loc.getLocWithOffset(endRef-endBuf+1); in RewriteObjCQualifiedInterfaceTypes()
2246 const char *startBuf = SM->getCharacterData(Loc); in RewriteObjCQualifiedInterfaceTypes()
2248 for (unsigned i = 0; i < proto->getNumParams(); i++) { in RewriteObjCQualifiedInterfaceTypes()
2249 if (needToScanForQualifiers(proto->getParamType(i))) { in RewriteObjCQualifiedInterfaceTypes()
2259 Loc.getLocWithOffset(startRef-startFuncBuf); in RewriteObjCQualifiedInterfaceTypes()
2261 Loc.getLocWithOffset(endRef-startFuncBuf+1); in RewriteObjCQualifiedInterfaceTypes()
2279 QualType QT = ND->getType(); in RewriteTypeOfDecl()
2280 const Type* TypePtr = QT->getAs<Type>(); in RewriteTypeOfDecl()
2285 QT = TypeOfExprTypePtr->getUnderlyingExpr()->getType(); in RewriteTypeOfDecl()
2286 TypePtr = QT->getAs<Type>(); in RewriteTypeOfDecl()
2290 std::string TypeAsString(QT.getAsString(Context->getPrintingPolicy())); in RewriteTypeOfDecl()
2291 SourceLocation DeclLoc = ND->getTypeSpecStartLoc(); in RewriteTypeOfDecl()
2292 const char *startBuf = SM->getCharacterData(DeclLoc); in RewriteTypeOfDecl()
2293 if (ND->getInit()) { in RewriteTypeOfDecl()
2294 std::string Name(ND->getNameAsString()); in RewriteTypeOfDecl()
2296 Expr *E = ND->getInit(); in RewriteTypeOfDecl()
2299 startLoc = ECE->getLParenLoc(); in RewriteTypeOfDecl()
2301 startLoc = E->getBeginLoc(); in RewriteTypeOfDecl()
2302 startLoc = SM->getExpansionLoc(startLoc); in RewriteTypeOfDecl()
2303 const char *endBuf = SM->getCharacterData(startLoc); in RewriteTypeOfDecl()
2304 ReplaceText(DeclLoc, endBuf-startBuf-1, TypeAsString); in RewriteTypeOfDecl()
2307 SourceLocation X = ND->getEndLoc(); in RewriteTypeOfDecl()
2308 X = SM->getExpansionLoc(X); in RewriteTypeOfDecl()
2309 const char *endBuf = SM->getCharacterData(X); in RewriteTypeOfDecl()
2310 ReplaceText(DeclLoc, endBuf-startBuf-1, TypeAsString); in RewriteTypeOfDecl()
2314 // SynthSelGetUidFunctionDecl - SEL sel_registerName(const char *str);
2316 IdentifierInfo *SelGetUidIdent = &Context->Idents.get("sel_registerName"); in SynthSelGetUidFunctionDecl()
2318 ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); in SynthSelGetUidFunctionDecl()
2320 getSimpleFunctionType(Context->getObjCSelType(), ArgTys); in SynthSelGetUidFunctionDecl()
2330 if (FD->getIdentifier() && in RewriteFunctionDecl()
2331 FD->getName() == "sel_registerName") { in RewriteFunctionDecl()
2339 std::string TypeString(Type.getAsString(Context->getPrintingPolicy())); in RewriteBlockPointerType()
2354 QualType Type = VD->getType(); in RewriteBlockPointerTypeVariable()
2355 std::string TypeString(Type.getAsString(Context->getPrintingPolicy())); in RewriteBlockPointerTypeVariable()
2366 paren--; in RewriteBlockPointerTypeVariable()
2371 Str += VD->getNameAsString(); in RewriteBlockPointerTypeVariable()
2382 SourceLocation FunLocStart = FD->getTypeSpecStartLoc(); in RewriteBlockLiteralFunctionDecl()
2383 const FunctionType *funcType = FD->getType()->getAs<FunctionType>(); in RewriteBlockLiteralFunctionDecl()
2387 QualType Type = proto->getReturnType(); in RewriteBlockLiteralFunctionDecl()
2388 std::string FdStr = Type.getAsString(Context->getPrintingPolicy()); in RewriteBlockLiteralFunctionDecl()
2390 FdStr += FD->getName(); in RewriteBlockLiteralFunctionDecl()
2392 unsigned numArgs = proto->getNumParams(); in RewriteBlockLiteralFunctionDecl()
2394 QualType ArgType = proto->getParamType(i); in RewriteBlockLiteralFunctionDecl()
2399 if (FD->isVariadic()) { in RewriteBlockLiteralFunctionDecl()
2407 // SynthSuperConstructorFunctionDecl - id __rw_objc_super(id obj, id super);
2411 IdentifierInfo *msgSendIdent = &Context->Idents.get("__rw_objc_super"); in SynthSuperConstructorFunctionDecl()
2413 QualType argT = Context->getObjCIdType(); in SynthSuperConstructorFunctionDecl()
2417 QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), in SynthSuperConstructorFunctionDecl()
2426 // SynthMsgSendFunctionDecl - id objc_msgSend(id self, SEL op, ...);
2428 IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSend"); in SynthMsgSendFunctionDecl()
2430 QualType argT = Context->getObjCIdType(); in SynthMsgSendFunctionDecl()
2433 argT = Context->getObjCSelType(); in SynthMsgSendFunctionDecl()
2436 QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), in SynthMsgSendFunctionDecl()
2445 // SynthMsgSendSuperFunctionDecl - id objc_msgSendSuper(void);
2447 IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSendSuper"); in SynthMsgSendSuperFunctionDecl()
2449 ArgTys.push_back(Context->VoidTy); in SynthMsgSendSuperFunctionDecl()
2450 QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), in SynthMsgSendSuperFunctionDecl()
2459 // SynthMsgSendStretFunctionDecl - id objc_msgSend_stret(id self, SEL op, ...);
2461 IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSend_stret"); in SynthMsgSendStretFunctionDecl()
2463 QualType argT = Context->getObjCIdType(); in SynthMsgSendStretFunctionDecl()
2466 argT = Context->getObjCSelType(); in SynthMsgSendStretFunctionDecl()
2469 QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), in SynthMsgSendStretFunctionDecl()
2478 // SynthMsgSendSuperStretFunctionDecl -
2482 &Context->Idents.get("objc_msgSendSuper_stret"); in SynthMsgSendSuperStretFunctionDecl()
2484 ArgTys.push_back(Context->VoidTy); in SynthMsgSendSuperStretFunctionDecl()
2485 QualType msgSendType = getSimpleFunctionType(Context->getObjCIdType(), in SynthMsgSendSuperStretFunctionDecl()
2495 // SynthMsgSendFpretFunctionDecl - double objc_msgSend_fpret(id self, SEL op, ...);
2497 IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSend_fpret"); in SynthMsgSendFpretFunctionDecl()
2499 QualType argT = Context->getObjCIdType(); in SynthMsgSendFpretFunctionDecl()
2502 argT = Context->getObjCSelType(); in SynthMsgSendFpretFunctionDecl()
2505 QualType msgSendType = getSimpleFunctionType(Context->DoubleTy, in SynthMsgSendFpretFunctionDecl()
2514 // SynthGetClassFunctionDecl - Class objc_getClass(const char *name);
2516 IdentifierInfo *getClassIdent = &Context->Idents.get("objc_getClass"); in SynthGetClassFunctionDecl()
2518 ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); in SynthGetClassFunctionDecl()
2519 QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(), in SynthGetClassFunctionDecl()
2528 // SynthGetSuperClassFunctionDecl - Class class_getSuperclass(Class cls);
2531 &Context->Idents.get("class_getSuperclass"); in SynthGetSuperClassFunctionDecl()
2533 ArgTys.push_back(Context->getObjCClassType()); in SynthGetSuperClassFunctionDecl()
2534 QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(), in SynthGetSuperClassFunctionDecl()
2544 // SynthGetMetaClassFunctionDecl - Class objc_getMetaClass(const char *name);
2546 IdentifierInfo *getClassIdent = &Context->Idents.get("objc_getMetaClass"); in SynthGetMetaClassFunctionDecl()
2548 ArgTys.push_back(Context->getPointerType(Context->CharTy.withConst())); in SynthGetMetaClassFunctionDecl()
2549 QualType getClassType = getSimpleFunctionType(Context->getObjCClassType(), in SynthGetMetaClassFunctionDecl()
2559 assert (Exp != nullptr && "Expected non-null ObjCStringLiteral"); in RewriteObjCStringLiteral()
2568 // replace any non-alphanumeric characters with '_'. in RewriteObjCStringLiteral()
2576 Preamble += "static __NSConstantStringImpl " + S; in RewriteObjCStringLiteral()
2577 …Preamble += " __attribute__ ((section (\"__DATA, __cfstring\"))) = {__CFConstantStringClassReferen… in RewriteObjCStringLiteral()
2578 Preamble += "0x000007c8,"; // utf8_str in RewriteObjCStringLiteral()
2582 Exp->getString()->printPretty(prettyBuf, nullptr, PrintingPolicy(LangOpts)); in RewriteObjCStringLiteral()
2583 Preamble += prettyBufS; in RewriteObjCStringLiteral()
2584 Preamble += ","; in RewriteObjCStringLiteral()
2585 Preamble += utostr(Exp->getString()->getByteLength()) + "};\n"; in RewriteObjCStringLiteral()
2588 SourceLocation(), &Context->Idents.get(S), in RewriteObjCStringLiteral()
2594 Context->getPointerType(DRE->getType()), VK_PRValue, OK_Ordinary, in RewriteObjCStringLiteral()
2597 CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Exp->getType(), in RewriteObjCStringLiteral()
2606 static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); in RewriteObjCBoolLiteralExpr()
2609 llvm::APInt(IntSize, Exp->getValue()), in RewriteObjCBoolLiteralExpr()
2610 Context->IntTy, Exp->getLocation()); in RewriteObjCBoolLiteralExpr()
2611 CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->ObjCBuiltinBoolTy, in RewriteObjCBoolLiteralExpr()
2613 ParenExpr *PE = new (Context) ParenExpr(Exp->getLocation(), Exp->getExprLoc(), in RewriteObjCBoolLiteralExpr()
2630 SourceLocation StartLoc = Exp->getBeginLoc(); in RewriteObjCBoxedExpr()
2631 SourceLocation EndLoc = Exp->getEndLoc(); in RewriteObjCBoxedExpr()
2638 ObjCMethodDecl *BoxingMethod = Exp->getBoxingMethod(); in RewriteObjCBoxedExpr()
2639 ObjCInterfaceDecl *BoxingClass = BoxingMethod->getClassInterface(); in RewriteObjCBoxedExpr()
2641 IdentifierInfo *clsName = BoxingClass->getIdentifier(); in RewriteObjCBoxedExpr()
2642 ClsExprs.push_back(getStringLiteral(clsName->getName())); in RewriteObjCBoxedExpr()
2651 getStringLiteral(BoxingMethod->getSelector().getAsString())); in RewriteObjCBoxedExpr()
2656 // User provided sub-expression is the 3rd, and last, argument. in RewriteObjCBoxedExpr()
2657 Expr *subExpr = Exp->getSubExpr(); in RewriteObjCBoxedExpr()
2659 QualType type = ICE->getType(); in RewriteObjCBoxedExpr()
2660 const Expr *SubExpr = ICE->IgnoreParenImpCasts(); in RewriteObjCBoxedExpr()
2662 if (SubExpr->getType()->isIntegralType(*Context) && type->isBooleanType()) in RewriteObjCBoxedExpr()
2669 ArgTypes.push_back(Context->getObjCClassType()); in RewriteObjCBoxedExpr()
2670 ArgTypes.push_back(Context->getObjCSelType()); in RewriteObjCBoxedExpr()
2671 for (const auto PI : BoxingMethod->parameters()) in RewriteObjCBoxedExpr()
2672 ArgTypes.push_back(PI->getType()); in RewriteObjCBoxedExpr()
2674 QualType returnType = Exp->getType(); in RewriteObjCBoxedExpr()
2676 QualType msgSendType = MsgSendFlavor->getType(); in RewriteObjCBoxedExpr()
2683 Context, Context->getPointerType(Context->VoidTy), CK_BitCast, DRE); in RewriteObjCBoxedExpr()
2687 getSimpleFunctionType(returnType, ArgTypes, BoxingMethod->isVariadic()); in RewriteObjCBoxedExpr()
2688 castType = Context->getPointerType(castType); in RewriteObjCBoxedExpr()
2695 auto *FT = msgSendType->castAs<FunctionType>(); in RewriteObjCBoxedExpr()
2696 CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), in RewriteObjCBoxedExpr()
2713 SourceLocation StartLoc = Exp->getBeginLoc(); in RewriteObjCArrayLiteralExpr()
2714 SourceLocation EndLoc = Exp->getEndLoc(); in RewriteObjCArrayLiteralExpr()
2717 QualType IntQT = Context->IntTy; in RewriteObjCArrayLiteralExpr()
2719 getSimpleFunctionType(Context->VoidTy, IntQT, true); in RewriteObjCArrayLiteralExpr()
2726 unsigned NumElements = Exp->getNumElements(); in RewriteObjCArrayLiteralExpr()
2728 static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); in RewriteObjCArrayLiteralExpr()
2731 Context->UnsignedIntTy, SourceLocation()); in RewriteObjCArrayLiteralExpr()
2734 InitExprs.push_back(Exp->getElement(i)); in RewriteObjCArrayLiteralExpr()
2741 &Context->Idents.get("arr"), in RewriteObjCArrayLiteralExpr()
2742 Context->getPointerType(Context->VoidPtrTy), in RewriteObjCArrayLiteralExpr()
2747 ARRFD->getType(), VK_LValue, OK_Ordinary); in RewriteObjCArrayLiteralExpr()
2748 QualType ConstIdT = Context->getObjCIdType().withConst(); in RewriteObjCArrayLiteralExpr()
2751 Context->getPointerType(ConstIdT), in RewriteObjCArrayLiteralExpr()
2758 QualType expType = Exp->getType(); in RewriteObjCArrayLiteralExpr()
2762 expType->getPointeeType()->castAs<ObjCObjectType>()->getInterface(); in RewriteObjCArrayLiteralExpr()
2764 IdentifierInfo *clsName = Class->getIdentifier(); in RewriteObjCArrayLiteralExpr()
2765 ClsExprs.push_back(getStringLiteral(clsName->getName())); in RewriteObjCArrayLiteralExpr()
2773 ObjCMethodDecl *ArrayMethod = Exp->getArrayWithObjectsMethod(); in RewriteObjCArrayLiteralExpr()
2775 getStringLiteral(ArrayMethod->getSelector().getAsString())); in RewriteObjCArrayLiteralExpr()
2786 Context->UnsignedIntTy, SourceLocation()); in RewriteObjCArrayLiteralExpr()
2790 ArgTypes.push_back(Context->getObjCClassType()); in RewriteObjCArrayLiteralExpr()
2791 ArgTypes.push_back(Context->getObjCSelType()); in RewriteObjCArrayLiteralExpr()
2792 for (const auto *PI : ArrayMethod->parameters()) in RewriteObjCArrayLiteralExpr()
2793 ArgTypes.push_back(PI->getType()); in RewriteObjCArrayLiteralExpr()
2795 QualType returnType = Exp->getType(); in RewriteObjCArrayLiteralExpr()
2797 QualType msgSendType = MsgSendFlavor->getType(); in RewriteObjCArrayLiteralExpr()
2804 Context, Context->getPointerType(Context->VoidTy), CK_BitCast, DRE); in RewriteObjCArrayLiteralExpr()
2808 getSimpleFunctionType(returnType, ArgTypes, ArrayMethod->isVariadic()); in RewriteObjCArrayLiteralExpr()
2809 castType = Context->getPointerType(castType); in RewriteObjCArrayLiteralExpr()
2816 const FunctionType *FT = msgSendType->castAs<FunctionType>(); in RewriteObjCArrayLiteralExpr()
2817 CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), in RewriteObjCArrayLiteralExpr()
2834 SourceLocation StartLoc = Exp->getBeginLoc(); in RewriteObjCDictionaryLiteralExpr()
2835 SourceLocation EndLoc = Exp->getEndLoc(); in RewriteObjCDictionaryLiteralExpr()
2838 QualType IntQT = Context->IntTy; in RewriteObjCDictionaryLiteralExpr()
2840 getSimpleFunctionType(Context->VoidTy, IntQT, true); in RewriteObjCDictionaryLiteralExpr()
2849 unsigned NumElements = Exp->getNumElements(); in RewriteObjCDictionaryLiteralExpr()
2851 static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); in RewriteObjCDictionaryLiteralExpr()
2854 Context->UnsignedIntTy, SourceLocation()); in RewriteObjCDictionaryLiteralExpr()
2858 ObjCDictionaryElement Element = Exp->getKeyValueElement(i); in RewriteObjCDictionaryLiteralExpr()
2870 &Context->Idents.get("arr"), in RewriteObjCDictionaryLiteralExpr()
2871 Context->getPointerType(Context->VoidPtrTy), in RewriteObjCDictionaryLiteralExpr()
2876 ARRFD->getType(), VK_LValue, OK_Ordinary); in RewriteObjCDictionaryLiteralExpr()
2877 QualType ConstIdT = Context->getObjCIdType().withConst(); in RewriteObjCDictionaryLiteralExpr()
2880 Context->getPointerType(ConstIdT), in RewriteObjCDictionaryLiteralExpr()
2890 ARRFD->getType(), VK_LValue, OK_Ordinary); in RewriteObjCDictionaryLiteralExpr()
2894 Context->getPointerType(ConstIdT), in RewriteObjCDictionaryLiteralExpr()
2901 QualType expType = Exp->getType(); in RewriteObjCDictionaryLiteralExpr()
2905 expType->getPointeeType()->castAs<ObjCObjectType>()->getInterface(); in RewriteObjCDictionaryLiteralExpr()
2907 IdentifierInfo *clsName = Class->getIdentifier(); in RewriteObjCDictionaryLiteralExpr()
2908 ClsExprs.push_back(getStringLiteral(clsName->getName())); in RewriteObjCDictionaryLiteralExpr()
2916 ObjCMethodDecl *DictMethod = Exp->getDictWithObjectsMethod(); in RewriteObjCDictionaryLiteralExpr()
2917 SelExprs.push_back(getStringLiteral(DictMethod->getSelector().getAsString())); in RewriteObjCDictionaryLiteralExpr()
2931 Context->UnsignedIntTy, SourceLocation()); in RewriteObjCDictionaryLiteralExpr()
2935 ArgTypes.push_back(Context->getObjCClassType()); in RewriteObjCDictionaryLiteralExpr()
2936 ArgTypes.push_back(Context->getObjCSelType()); in RewriteObjCDictionaryLiteralExpr()
2937 for (const auto *PI : DictMethod->parameters()) { in RewriteObjCDictionaryLiteralExpr()
2938 QualType T = PI->getType(); in RewriteObjCDictionaryLiteralExpr()
2939 if (const PointerType* PT = T->getAs<PointerType>()) { in RewriteObjCDictionaryLiteralExpr()
2940 QualType PointeeTy = PT->getPointeeType(); in RewriteObjCDictionaryLiteralExpr()
2942 T = Context->getPointerType(PointeeTy); in RewriteObjCDictionaryLiteralExpr()
2947 QualType returnType = Exp->getType(); in RewriteObjCDictionaryLiteralExpr()
2949 QualType msgSendType = MsgSendFlavor->getType(); in RewriteObjCDictionaryLiteralExpr()
2956 Context, Context->getPointerType(Context->VoidTy), CK_BitCast, DRE); in RewriteObjCDictionaryLiteralExpr()
2960 getSimpleFunctionType(returnType, ArgTypes, DictMethod->isVariadic()); in RewriteObjCDictionaryLiteralExpr()
2961 castType = Context->getPointerType(castType); in RewriteObjCDictionaryLiteralExpr()
2968 const FunctionType *FT = msgSendType->castAs<FunctionType>(); in RewriteObjCDictionaryLiteralExpr()
2969 CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), in RewriteObjCDictionaryLiteralExpr()
2982 SourceLocation(), &Context->Idents.get("__rw_objc_super")); in getSuperStructType()
2986 FieldTypes[0] = Context->getObjCIdType(); in getSuperStructType()
2988 FieldTypes[1] = Context->getObjCIdType(); in getSuperStructType()
2992 SuperStructDecl->addDecl(FieldDecl::Create(*Context, SuperStructDecl, in getSuperStructType()
3001 SuperStructDecl->completeDefinition(); in getSuperStructType()
3003 return Context->getTagDeclType(SuperStructDecl); in getSuperStructType()
3010 SourceLocation(), &Context->Idents.get("__NSConstantStringImpl")); in getConstantStringStructType()
3014 FieldTypes[0] = Context->getObjCIdType(); in getConstantStringStructType()
3016 FieldTypes[1] = Context->IntTy; in getConstantStringStructType()
3018 FieldTypes[2] = Context->getPointerType(Context->CharTy); in getConstantStringStructType()
3020 FieldTypes[3] = Context->LongTy; in getConstantStringStructType()
3024 ConstantStringDecl->addDecl(FieldDecl::Create(*Context, in getConstantStringStructType()
3034 ConstantStringDecl->completeDefinition(); in getConstantStringStructType()
3036 return Context->getTagDeclType(ConstantStringDecl); in getConstantStringStructType()
3039 /// getFunctionSourceLocation - returns start location of a function
3044 if (FD->isExternC() && !FD->isMain()) { in getFunctionSourceLocation()
3045 const DeclContext *DC = FD->getDeclContext(); in getFunctionSourceLocation()
3048 if (!LSD->getRBraceLoc().isValid()) in getFunctionSourceLocation()
3049 return LSD->getExternLoc(); in getFunctionSourceLocation()
3051 if (FD->getStorageClass() != SC_None) in getFunctionSourceLocation()
3053 return FD->getTypeSpecStartLoc(); in getFunctionSourceLocation()
3058 SourceLocation Location = D->getLocation(); in RewriteLineDirective()
3062 PresumedLoc PLoc = SM->getPresumedLoc(Location); in RewriteLineDirective()
3070 Location = D->getBeginLoc(); in RewriteLineDirective()
3072 if (FD->isExternC() && !FD->isMain()) { in RewriteLineDirective()
3073 const DeclContext *DC = FD->getDeclContext(); in RewriteLineDirective()
3076 if (!LSD->getRBraceLoc().isValid()) in RewriteLineDirective()
3077 Location = LSD->getExternLoc(); in RewriteLineDirective()
3084 /// SynthMsgSendStretCallExpr - This routine translates message expression
3087 /// MsgSendStretFlavor - function declaration objc_msgSend_stret(...)
3088 /// msgSendType - function type of objc_msgSend_stret(...)
3089 /// returnType - Result type of the method being synthesized.
3090 /// ArgTypes - type of the arguments passed to objc_msgSend_stret, starting with receiver type.
3091 /// MsgExprs - list of argument expressions being passed to objc_msgSend_stret,
3093 /// Method - Method being rewritten.
3101 returnType, ArgTypes, Method ? Method->isVariadic() : false); in SynthMsgSendStretCallExpr()
3102 QualType castType = Context->getPointerType(FuncType); in SynthMsgSendStretCallExpr()
3116 ArgTypes[i].getAsStringInternal(ArgName, Context->getPrintingPolicy()); in SynthMsgSendStretCallExpr()
3122 MsgExprs[i]->getType().getAsStringInternal(ArgName, in SynthMsgSendStretCallExpr()
3123 Context->getPrintingPolicy()); in SynthMsgSendStretCallExpr()
3129 str += returnType.getAsString(Context->getPrintingPolicy()); str += ");\n"; in SynthMsgSendStretCallExpr()
3133 str += "\t s = (("; str += castType.getAsString(Context->getPrintingPolicy()); in SynthMsgSendStretCallExpr()
3148 str += "\t s = (("; str += castType.getAsString(Context->getPrintingPolicy()); in SynthMsgSendStretCallExpr()
3160 str += "\t"; str += returnType.getAsString(Context->getPrintingPolicy()); in SynthMsgSendStretCallExpr()
3167 assert(CurMethodDef && "SynthMsgSendStretCallExpr - CurMethodDef is null"); in SynthMsgSendStretCallExpr()
3168 FunLocStart = CurMethodDef->getBeginLoc(); in SynthMsgSendStretCallExpr()
3175 IdentifierInfo *ID = &Context->Idents.get(name); in SynthMsgSendStretCallExpr()
3187 &Context->Idents.get("s"), in SynthMsgSendStretCallExpr()
3192 *Context, STCE, false, FieldD, FieldD->getType(), VK_LValue, OK_Ordinary); in SynthMsgSendStretCallExpr()
3223 if (ObjCMethodDecl *mDecl = Exp->getMethodDecl()) { in SynthMessageExpr()
3224 QualType resultType = mDecl->getReturnType(); in SynthMessageExpr()
3225 if (resultType->isRecordType()) in SynthMessageExpr()
3227 else if (resultType->isRealFloatingType()) in SynthMessageExpr()
3233 switch (Exp->getReceiverKind()) { in SynthMessageExpr()
3240 ObjCInterfaceDecl *ClassDecl = CurMethodDef->getClassInterface(); in SynthMessageExpr()
3246 Context, Context->getObjCIdType(), CK_BitCast, in SynthMessageExpr()
3247 new (Context) DeclRefExpr(*Context, CurMethodDef->getSelfDecl(), false, in SynthMessageExpr()
3248 Context->getObjCIdType(), VK_PRValue, in SynthMessageExpr()
3253 ClsExprs.push_back(getStringLiteral(ClassDecl->getIdentifier()->getName())); in SynthMessageExpr()
3263 // To turn off a warning, type-cast to 'id' in SynthMessageExpr()
3266 Context->getObjCIdType(), in SynthMessageExpr()
3289 Context->getPointerType(SuperRep->getType()), VK_PRValue, OK_Ordinary, in SynthMessageExpr()
3292 Context->getPointerType(superType), in SynthMessageExpr()
3300 = Context->getTrivialTypeSourceInfo(superType); in SynthMessageExpr()
3307 Context->getPointerType(SuperRep->getType()), VK_PRValue, OK_Ordinary, in SynthMessageExpr()
3317 = Exp->getClassReceiver()->castAs<ObjCObjectType>()->getInterface(); in SynthMessageExpr()
3318 IdentifierInfo *clsName = Class->getIdentifier(); in SynthMessageExpr()
3319 ClsExprs.push_back(getStringLiteral(clsName->getName())); in SynthMessageExpr()
3323 Context->getObjCIdType(), in SynthMessageExpr()
3334 ObjCInterfaceDecl *ClassDecl = CurMethodDef->getClassInterface(); in SynthMessageExpr()
3338 Context, Context->getObjCIdType(), CK_BitCast, in SynthMessageExpr()
3339 new (Context) DeclRefExpr(*Context, CurMethodDef->getSelfDecl(), false, in SynthMessageExpr()
3340 Context->getObjCIdType(), VK_PRValue, in SynthMessageExpr()
3345 ClsExprs.push_back(getStringLiteral(ClassDecl->getIdentifier()->getName())); in SynthMessageExpr()
3355 // To turn off a warning, type-cast to 'id' in SynthMessageExpr()
3358 NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), in SynthMessageExpr()
3381 Context->getPointerType(SuperRep->getType()), VK_PRValue, OK_Ordinary, in SynthMessageExpr()
3384 Context->getPointerType(superType), in SynthMessageExpr()
3392 = Context->getTrivialTypeSourceInfo(superType); in SynthMessageExpr()
3401 // Remove all type-casts because it may contain objc-style types; e.g. in SynthMessageExpr()
3403 Expr *recExpr = Exp->getInstanceReceiver(); in SynthMessageExpr()
3405 recExpr = CE->getSubExpr(); in SynthMessageExpr()
3406 CastKind CK = recExpr->getType()->isObjCObjectPointerType() in SynthMessageExpr()
3407 ? CK_BitCast : recExpr->getType()->isBlockPointerType() in SynthMessageExpr()
3411 recExpr = NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), in SynthMessageExpr()
3420 SelExprs.push_back(getStringLiteral(Exp->getSelector().getAsString())); in SynthMessageExpr()
3426 for (unsigned i = 0; i < Exp->getNumArgs(); i++) { in SynthMessageExpr()
3427 Expr *userExpr = Exp->getArg(i); in SynthMessageExpr()
3428 // Make all implicit casts explicit...ICE comes in handy:-) in SynthMessageExpr()
3431 QualType type = ICE->getType(); in SynthMessageExpr()
3433 type = Context->getObjCIdType(); in SynthMessageExpr()
3436 const Expr *SubExpr = ICE->IgnoreParenImpCasts(); in SynthMessageExpr()
3438 if (SubExpr->getType()->isIntegralType(*Context) && in SynthMessageExpr()
3439 type->isBooleanType()) { in SynthMessageExpr()
3441 } else if (type->isObjCObjectPointerType()) { in SynthMessageExpr()
3442 if (SubExpr->getType()->isBlockPointerType()) { in SynthMessageExpr()
3444 } else if (SubExpr->getType()->isPointerType()) { in SynthMessageExpr()
3457 if (CE->getType()->isObjCQualifiedIdType()) { in SynthMessageExpr()
3459 userExpr = CE->getSubExpr(); in SynthMessageExpr()
3461 if (userExpr->getType()->isIntegralType(*Context)) { in SynthMessageExpr()
3463 } else if (userExpr->getType()->isBlockPointerType()) { in SynthMessageExpr()
3465 } else if (userExpr->getType()->isPointerType()) { in SynthMessageExpr()
3470 userExpr = NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), in SynthMessageExpr()
3478 //Exp->setArg(i, 0); in SynthMessageExpr()
3487 ArgTypes.push_back(Context->getPointerType(getSuperStructType())); in SynthMessageExpr()
3489 ArgTypes.push_back(Context->getObjCIdType()); in SynthMessageExpr()
3490 ArgTypes.push_back(Context->getObjCSelType()); in SynthMessageExpr()
3491 if (ObjCMethodDecl *OMD = Exp->getMethodDecl()) { in SynthMessageExpr()
3493 for (const auto *PI : OMD->parameters()) { in SynthMessageExpr()
3494 QualType t = PI->getType()->isObjCQualifiedIdType() in SynthMessageExpr()
3495 ? Context->getObjCIdType() in SynthMessageExpr()
3496 : PI->getType(); in SynthMessageExpr()
3501 returnType = Exp->getType(); in SynthMessageExpr()
3505 returnType = Context->getObjCIdType(); in SynthMessageExpr()
3508 QualType msgSendType = MsgSendFlavor->getType(); in SynthMessageExpr()
3516 // xx.m:13: warning: function called through a non-compatible type in SynthMessageExpr()
3519 Context->getPointerType(Context->VoidTy), in SynthMessageExpr()
3524 const ObjCMethodDecl *MD = Exp->getMethodDecl(); in SynthMessageExpr()
3526 getSimpleFunctionType(returnType, ArgTypes, MD ? MD->isVariadic() : true); in SynthMessageExpr()
3527 castType = Context->getPointerType(castType); in SynthMessageExpr()
3534 const FunctionType *FT = msgSendType->castAs<FunctionType>(); in SynthMessageExpr()
3535 CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), in SynthMessageExpr()
3547 Exp->getMethodDecl()); in SynthMessageExpr()
3556 SynthMessageExpr(Exp, Exp->getBeginLoc(), Exp->getEndLoc()); in RewriteMessageExpr()
3569 = Context->getTrivialTypeSourceInfo(Context->getObjCIdType()); in getProtocolType()
3572 &Context->Idents.get("Protocol"), in getProtocolType()
3575 return Context->getTypeDeclType(ProtocolTypeDecl); in getProtocolType()
3578 /// RewriteObjCProtocolExpr - Rewrite a protocol expression into
3584 Exp->getProtocol()->getNameAsString(); in RewriteObjCProtocolExpr()
3585 IdentifierInfo *ID = &Context->Idents.get(Name); in RewriteObjCProtocolExpr()
3592 Context, Context->getPointerType(DRE->getType()), CK_BitCast, DRE); in RewriteObjCProtocolExpr()
3594 ProtocolExprDecls.insert(Exp->getProtocol()->getCanonicalDecl()); in RewriteObjCProtocolExpr()
3599 /// IsTagDefinedInsideClass - This routine checks that a named tagged type
3600 /// is defined inside an objective-c class. If so, it returns true.
3608 RD = RD->getDefinition(); in IsTagDefinedInsideClass()
3609 if (!RD || !RD->getDeclName().getAsIdentifierInfo()) in IsTagDefinedInsideClass()
3612 TagLocation = RD->getLocation(); in IsTagDefinedInsideClass()
3613 return Context->getSourceManager().isBeforeInTranslationUnit( in IsTagDefinedInsideClass()
3614 IDecl->getLocation(), TagLocation); in IsTagDefinedInsideClass()
3617 if (!ED || !ED->getDeclName().getAsIdentifierInfo()) in IsTagDefinedInsideClass()
3620 TagLocation = ED->getLocation(); in IsTagDefinedInsideClass()
3621 return Context->getSourceManager().isBeforeInTranslationUnit( in IsTagDefinedInsideClass()
3622 IDecl->getLocation(), TagLocation); in IsTagDefinedInsideClass()
3627 /// RewriteObjCFieldDeclType - This routine rewrites a type into the buffer.
3631 if (Type->getAs<TypedefType>()) { in RewriteObjCFieldDeclType()
3636 if (Type->isArrayType()) { in RewriteObjCFieldDeclType()
3637 QualType ElemTy = Context->getBaseElementType(Type); in RewriteObjCFieldDeclType()
3640 else if (Type->isRecordType()) { in RewriteObjCFieldDeclType()
3641 RecordDecl *RD = Type->castAs<RecordType>()->getDecl(); in RewriteObjCFieldDeclType()
3642 if (RD->isCompleteDefinition()) { in RewriteObjCFieldDeclType()
3643 if (RD->isStruct()) in RewriteObjCFieldDeclType()
3645 else if (RD->isUnion()) in RewriteObjCFieldDeclType()
3650 Result += RD->getName(); in RewriteObjCFieldDeclType()
3657 for (auto *FD : RD->fields()) in RewriteObjCFieldDeclType()
3663 else if (Type->isEnumeralType()) { in RewriteObjCFieldDeclType()
3664 EnumDecl *ED = Type->castAs<EnumType>()->getDecl(); in RewriteObjCFieldDeclType()
3665 if (ED->isCompleteDefinition()) { in RewriteObjCFieldDeclType()
3667 Result += ED->getName(); in RewriteObjCFieldDeclType()
3675 for (const auto *EC : ED->enumerators()) { in RewriteObjCFieldDeclType()
3676 Result += "\t"; Result += EC->getName(); Result += " = "; in RewriteObjCFieldDeclType()
3677 Result += toString(EC->getInitVal(), 10); in RewriteObjCFieldDeclType()
3691 /// RewriteObjCFieldDecl - This routine rewrites a field into the buffer.
3695 QualType Type = fieldDecl->getType(); in RewriteObjCFieldDecl()
3696 std::string Name = fieldDecl->getNameAsString(); in RewriteObjCFieldDecl()
3700 Type.getAsStringInternal(Name, Context->getPrintingPolicy()); in RewriteObjCFieldDecl()
3702 if (fieldDecl->isBitField()) { in RewriteObjCFieldDecl()
3703 Result += " : "; Result += utostr(fieldDecl->getBitWidthValue(*Context)); in RewriteObjCFieldDecl()
3705 else if (EleboratedType && Type->isArrayType()) { in RewriteObjCFieldDecl()
3706 const ArrayType *AT = Context->getAsArrayType(Type); in RewriteObjCFieldDecl()
3710 llvm::APInt Dim = CAT->getSize(); in RewriteObjCFieldDecl()
3714 AT = Context->getAsArrayType(AT->getElementType()); in RewriteObjCFieldDecl()
3721 /// RewriteLocallyDefinedNamedAggregates - This routine rewrites locally defined
3725 QualType Type = fieldDecl->getType(); in RewriteLocallyDefinedNamedAggregates()
3726 if (Type->getAs<TypedefType>()) in RewriteLocallyDefinedNamedAggregates()
3728 if (Type->isArrayType()) in RewriteLocallyDefinedNamedAggregates()
3729 Type = Context->getBaseElementType(Type); in RewriteLocallyDefinedNamedAggregates()
3731 auto *IDecl = dyn_cast<ObjCContainerDecl>(fieldDecl->getDeclContext()); in RewriteLocallyDefinedNamedAggregates()
3734 if (Type->isRecordType()) { in RewriteLocallyDefinedNamedAggregates()
3735 TD = Type->castAs<RecordType>()->getDecl(); in RewriteLocallyDefinedNamedAggregates()
3737 else if (Type->isEnumeralType()) { in RewriteLocallyDefinedNamedAggregates()
3738 TD = Type->castAs<EnumType>()->getDecl(); in RewriteLocallyDefinedNamedAggregates()
3756 const ObjCInterfaceDecl *CDecl = IV->getContainingInterface(); in ObjCIvarBitfieldGroupNo()
3762 for (const ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); in ObjCIvarBitfieldGroupNo()
3763 IVD; IVD = IVD->getNextIvar()) in ObjCIvarBitfieldGroupNo()
3767 if (IVars[i]->isBitField()) { in ObjCIvarBitfieldGroupNo()
3769 while (i < e && IVars[i]->isBitField()) in ObjCIvarBitfieldGroupNo()
3772 --i; in ObjCIvarBitfieldGroupNo()
3785 *Context, TagTypeKind::Struct, Context->getTranslationUnitDecl(), in SynthesizeBitfieldGroupStructType()
3786 SourceLocation(), SourceLocation(), &Context->Idents.get(StructTagName)); in SynthesizeBitfieldGroupStructType()
3789 RD->addDecl(FieldDecl::Create(*Context, RD, SourceLocation(), SourceLocation(), in SynthesizeBitfieldGroupStructType()
3790 &Context->Idents.get(Ivar->getName()), in SynthesizeBitfieldGroupStructType()
3791 Ivar->getType(), in SynthesizeBitfieldGroupStructType()
3792 nullptr, /*Expr *BW */Ivar->getBitWidth(), in SynthesizeBitfieldGroupStructType()
3795 RD->completeDefinition(); in SynthesizeBitfieldGroupStructType()
3796 return Context->getTagDeclType(RD); in SynthesizeBitfieldGroupStructType()
3800 const ObjCInterfaceDecl *CDecl = IV->getContainingInterface(); in GetGroupRecordTypeForObjCIvarBitfield()
3807 for (const ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); in GetGroupRecordTypeForObjCIvarBitfield()
3808 IVD; IVD = IVD->getNextIvar()) { in GetGroupRecordTypeForObjCIvarBitfield()
3809 if (IVD->isBitField()) in GetGroupRecordTypeForObjCIvarBitfield()
3833 /// ObjCIvarBitfieldGroupDecl - Names field decl. for ivar bitfield group.
3837 const ObjCInterfaceDecl *CDecl = IV->getContainingInterface(); in ObjCIvarBitfieldGroupDecl()
3838 Result += CDecl->getName(); in ObjCIvarBitfieldGroupDecl()
3844 /// ObjCIvarBitfieldGroupType - Names struct type for ivar bitfield group.
3849 const ObjCInterfaceDecl *CDecl = IV->getContainingInterface(); in ObjCIvarBitfieldGroupType()
3850 Result += CDecl->getName(); in ObjCIvarBitfieldGroupType()
3856 /// ObjCIvarBitfieldGroupOffset - Names symbol for ivar bitfield group field offset.
3866 while ((IX < ENDIX) && VEC[IX]->isBitField()) \
3869 --IX; \
3872 /// RewriteObjCInternalStruct - Rewrite one internal struct corresponding to
3873 /// an objective-c class with ivars.
3877 assert(CDecl->getName() != "" && in RewriteObjCInternalStruct()
3879 ObjCInterfaceDecl *RCDecl = CDecl->getSuperClass(); in RewriteObjCInternalStruct()
3881 for (ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); in RewriteObjCInternalStruct()
3882 IVD; IVD = IVD->getNextIvar()) in RewriteObjCInternalStruct()
3885 SourceLocation LocStart = CDecl->getBeginLoc(); in RewriteObjCInternalStruct()
3886 SourceLocation LocEnd = CDecl->getEndOfDefinitionLoc(); in RewriteObjCInternalStruct()
3888 const char *startBuf = SM->getCharacterData(LocStart); in RewriteObjCInternalStruct()
3889 const char *endBuf = SM->getCharacterData(LocEnd); in RewriteObjCInternalStruct()
3893 if ((!CDecl->isThisDeclarationADefinition() || IVars.size() == 0) && in RewriteObjCInternalStruct()
3896 ReplaceText(LocStart, endBuf-startBuf, Result); in RewriteObjCInternalStruct()
3902 // struct/unions in objective-c classes. in RewriteObjCInternalStruct()
3909 if (IVars[i]->isBitField()) { in RewriteObjCInternalStruct()
3919 Result += CDecl->getNameAsString(); in RewriteObjCInternalStruct()
3923 Result += "\tstruct "; Result += RCDecl->getNameAsString(); in RewriteObjCInternalStruct()
3924 Result += "_IMPL "; Result += RCDecl->getNameAsString(); in RewriteObjCInternalStruct()
3929 if (IVars[i]->isBitField()) { in RewriteObjCInternalStruct()
3943 ReplaceText(LocStart, endBuf-startBuf, Result); in RewriteObjCInternalStruct()
3946 llvm_unreachable("struct already synthesize- RewriteObjCInternalStruct"); in RewriteObjCInternalStruct()
3949 /// RewriteIvarOffsetSymbols - Rewrite ivar offset symbols of those ivars which
3962 const ObjCInterfaceDecl *IDecl = IvarDecl->getContainingInterface(); in RewriteIvarOffsetSymbols()
3964 if (IvarDecl->isBitField()) { in RewriteIvarOffsetSymbols()
3974 IvarDecl->getAccessControl() != ObjCIvarDecl::Private && in RewriteIvarOffsetSymbols()
3975 IvarDecl->getAccessControl() != ObjCIvarDecl::Package) in RewriteIvarOffsetSymbols()
3979 if (IvarDecl->isBitField()) { in RewriteIvarOffsetSymbols()
3989 //===----------------------------------------------------------------------===//
3991 //===----------------------------------------------------------------------===//
3993 /// RewriteImplementations - This routine rewrites all method implementations
3994 /// and emits meta-data.
4003 ObjCInterfaceDecl *CDecl = OIMP->getClassInterface(); in RewriteImplementations()
4004 if (CDecl->isImplicitInterfaceDecl()) in RewriteImplementations()
4012 ObjCInterfaceDecl *CDecl = CIMP->getClassInterface(); in RewriteImplementations()
4013 if (CDecl->isImplicitInterfaceDecl()) in RewriteImplementations()
4033 return (Var->isFunctionOrMethodVarDecl() && !Var->hasLocalStorage()); in HasLocalVariableExternalStorage()
4040 const FunctionType *AFT = CE->getFunctionType(); in SynthesizeBlockFunc()
4041 QualType RT = AFT->getReturnType(); in SynthesizeBlockFunc()
4043 SourceLocation BlockLoc = CE->getExprLoc(); in SynthesizeBlockFunc()
4047 S += "static " + RT.getAsString(Context->getPrintingPolicy()) + " __" + in SynthesizeBlockFunc()
4050 BlockDecl *BD = CE->getBlockDecl(); in SynthesizeBlockFunc()
4053 // No user-supplied arguments. Still need to pass in a pointer to the in SynthesizeBlockFunc()
4056 } else if (BD->param_empty()) { in SynthesizeBlockFunc()
4065 for (BlockDecl::param_iterator AI = BD->param_begin(), in SynthesizeBlockFunc()
4066 E = BD->param_end(); AI != E; ++AI) { in SynthesizeBlockFunc()
4067 if (AI != BD->param_begin()) S += ", "; in SynthesizeBlockFunc()
4068 ParamStr = (*AI)->getNameAsString(); in SynthesizeBlockFunc()
4069 QualType QT = (*AI)->getType(); in SynthesizeBlockFunc()
4071 QT.getAsStringInternal(ParamStr, Context->getPrintingPolicy()); in SynthesizeBlockFunc()
4074 if (FT->isVariadic()) { in SynthesizeBlockFunc()
4075 if (!BD->param_empty()) S += ", "; in SynthesizeBlockFunc()
4087 std::string Name = (*I)->getNameAsString(); in SynthesizeBlockFunc()
4092 S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by ref\n"; in SynthesizeBlockFunc()
4108 if (isTopLevelBlockPointerType((*I)->getType())) { in SynthesizeBlockFunc()
4111 RewriteBlockPointerType(S, (*I)->getType()); in SynthesizeBlockFunc()
4113 S += "__cself->" + (*I)->getNameAsString() + "; // bound by copy\n"; in SynthesizeBlockFunc()
4116 std::string Name = (*I)->getNameAsString(); in SynthesizeBlockFunc()
4117 QualType QT = (*I)->getType(); in SynthesizeBlockFunc()
4119 QT = Context->getPointerType(QT); in SynthesizeBlockFunc()
4120 QT.getAsStringInternal(Name, Context->getPrintingPolicy()); in SynthesizeBlockFunc()
4121 S += Name + " = __cself->" + in SynthesizeBlockFunc()
4122 (*I)->getNameAsString() + "; // bound by copy\n"; in SynthesizeBlockFunc()
4144 S += "_Block_object_assign((void*)&dst->"; in SynthesizeBlockHelperFuncs()
4145 S += VD->getNameAsString(); in SynthesizeBlockHelperFuncs()
4146 S += ", (void*)src->"; in SynthesizeBlockHelperFuncs()
4147 S += VD->getNameAsString(); in SynthesizeBlockHelperFuncs()
4150 else if (VD->getType()->isBlockPointerType()) in SynthesizeBlockHelperFuncs()
4163 S += "_Block_object_dispose((void*)src->"; in SynthesizeBlockHelperFuncs()
4164 S += VD->getNameAsString(); in SynthesizeBlockHelperFuncs()
4167 else if (VD->getType()->isBlockPointerType()) in SynthesizeBlockHelperFuncs()
4195 std::string FieldName = (*I)->getNameAsString(); in SynthesizeBlockImpl()
4207 if (isTopLevelBlockPointerType((*I)->getType())) { in SynthesizeBlockImpl()
4211 QualType QT = (*I)->getType(); in SynthesizeBlockImpl()
4213 QT = Context->getPointerType(QT); in SynthesizeBlockImpl()
4214 QT.getAsStringInternal(FieldName, Context->getPrintingPolicy()); in SynthesizeBlockImpl()
4215 QT.getAsStringInternal(ArgName, Context->getPrintingPolicy()); in SynthesizeBlockImpl()
4224 std::string FieldName = (*I)->getNameAsString(); in SynthesizeBlockImpl()
4242 std::string Name = (*I)->getNameAsString(); in SynthesizeBlockImpl()
4249 if (isTopLevelBlockPointerType((*I)->getType())) in SynthesizeBlockImpl()
4257 std::string Name = (*I)->getNameAsString(); in SynthesizeBlockImpl()
4264 Constructor += Name + "(_" + Name + "->__forwarding)"; in SynthesizeBlockImpl()
4323 GlobalVarDecl->getStorageClass() == SC_Static && in SynthesizeBlockLiterals()
4324 GlobalVarDecl->getType().getCVRQualifiers()); in SynthesizeBlockLiterals()
4327 SC += GlobalVarDecl->getNameAsString(); in SynthesizeBlockLiterals()
4335 // Need to copy-in the inner copied-in variables not actually used in this in SynthesizeBlockLiterals()
4339 ValueDecl *VD = Exp->getDecl(); in SynthesizeBlockLiterals()
4341 if (!VD->hasAttr<BlocksAttr>()) { in SynthesizeBlockLiterals()
4356 if (VD->getType()->isObjCObjectPointerType() || in SynthesizeBlockLiterals()
4357 VD->getType()->isBlockPointerType()) in SynthesizeBlockLiterals()
4391 if (GlobalVarDecl->getStorageClass() == SC_Static) in SynthesizeBlockLiterals()
4393 if (GlobalVarDecl->getType().isConstQualified()) in SynthesizeBlockLiterals()
4395 if (GlobalVarDecl->getType().isVolatileQualified()) in SynthesizeBlockLiterals()
4397 if (GlobalVarDecl->getType().isRestrictQualified()) in SynthesizeBlockLiterals()
4408 Tag += utostr(Blocks.size()-1); in SynthesizeBlockLiterals()
4414 GlobalConstructionExp->printPretty(constructorExprBuf, nullptr, in SynthesizeBlockLiterals()
4431 : FD->getTypeSpecStartLoc(); in InsertBlockLiteralsWithinFunction()
4432 StringRef FuncName = FD->getName(); in InsertBlockLiteralsWithinFunction()
4439 ObjCInterfaceDecl *IFace = MD->getClassInterface(); in BuildUniqueMethodName()
4440 Name = std::string(IFace->getName()); in BuildUniqueMethodName()
4441 Name += "__" + MD->getSelector().getAsString(); in BuildUniqueMethodName()
4450 // SourceLocation FunLocStart = MD->getBeginLoc(); in InsertBlockLiteralsWithinMethod()
4451 SourceLocation FunLocStart = MD->getBeginLoc(); in InsertBlockLiteralsWithinMethod()
4458 for (Stmt *SubStmt : S->children()) in GetBlockDeclRefExprs()
4461 GetBlockDeclRefExprs(CBE->getBody()); in GetBlockDeclRefExprs()
4467 if (DRE->refersToEnclosingVariableOrCapture() || in GetBlockDeclRefExprs()
4468 HasLocalVariableExternalStorage(DRE->getDecl())) in GetBlockDeclRefExprs()
4476 for (Stmt *SubStmt : S->children()) in GetInnerBlockDeclRefExprs()
4479 InnerContexts.insert(cast<DeclContext>(CBE->getBlockDecl())); in GetInnerBlockDeclRefExprs()
4480 GetInnerBlockDeclRefExprs(CBE->getBody(), in GetInnerBlockDeclRefExprs()
4489 if (DRE->refersToEnclosingVariableOrCapture() || in GetInnerBlockDeclRefExprs()
4490 HasLocalVariableExternalStorage(DRE->getDecl())) { in GetInnerBlockDeclRefExprs()
4491 if (!InnerContexts.count(DRE->getDecl()->getDeclContext())) in GetInnerBlockDeclRefExprs()
4493 if (VarDecl *Var = cast<VarDecl>(DRE->getDecl())) in GetInnerBlockDeclRefExprs()
4494 if (Var->isFunctionOrMethodVarDecl()) in GetInnerBlockDeclRefExprs()
4500 /// convertObjCTypeToCStyleType - This routine converts such objc types
4506 if (T->isFunctionPointerType()) { in convertObjCTypeToCStyleType()
4508 if (const PointerType* PT = T->getAs<PointerType>()) { in convertObjCTypeToCStyleType()
4509 PointeeTy = PT->getPointeeType(); in convertObjCTypeToCStyleType()
4510 if (const FunctionType *FT = PointeeTy->getAs<FunctionType>()) { in convertObjCTypeToCStyleType()
4512 T = Context->getPointerType(T); in convertObjCTypeToCStyleType()
4521 /// convertFunctionTypeOfBlocks - This routine converts a function type
4530 QualType Res = FT->getReturnType(); in convertFunctionTypeOfBlocks()
4534 for (auto &I : FTP->param_types()) { in convertFunctionTypeOfBlocks()
4554 CPT = DRE->getType()->getAs<BlockPointerType>(); in SynthesizeBlockCall()
4556 CPT = MExpr->getType()->getAs<BlockPointerType>(); in SynthesizeBlockCall()
4559 return SynthesizeBlockCall(Exp, PRE->getSubExpr()); in SynthesizeBlockCall()
4562 CPT = IEXPR->getType()->getAs<BlockPointerType>(); in SynthesizeBlockCall()
4565 Expr *LHSExp = CEXPR->getLHS(); in SynthesizeBlockCall()
4567 Expr *RHSExp = CEXPR->getRHS(); in SynthesizeBlockCall()
4569 Expr *CONDExp = CEXPR->getCond(); in SynthesizeBlockCall()
4572 cast<Expr>(RHSStmt), Exp->getType(), VK_PRValue, OK_Ordinary); in SynthesizeBlockCall()
4575 CPT = IRE->getType()->getAs<BlockPointerType>(); in SynthesizeBlockCall()
4578 CPT = POE->getType()->castAs<BlockPointerType>(); in SynthesizeBlockCall()
4583 const FunctionType *FT = CPT->getPointeeType()->getAs<FunctionType>(); in SynthesizeBlockCall()
4590 &Context->Idents.get("__block_impl")); in SynthesizeBlockCall()
4591 QualType PtrBlock = Context->getPointerType(Context->getTagDeclType(RD)); in SynthesizeBlockCall()
4599 for (auto &I : FTP->param_types()) { in SynthesizeBlockCall()
4608 QualType PtrToFuncCastType = getSimpleFunctionType(Exp->getType(), ArgTypes); in SynthesizeBlockCall()
4610 PtrToFuncCastType = Context->getPointerType(PtrToFuncCastType); in SynthesizeBlockCall()
4618 //PE->dump(); in SynthesizeBlockCall()
4622 &Context->Idents.get("FuncPtr"), in SynthesizeBlockCall()
4623 Context->VoidPtrTy, nullptr, in SynthesizeBlockCall()
4627 *Context, PE, true, FD, FD->getType(), VK_LValue, OK_Ordinary); in SynthesizeBlockCall()
4637 for (CallExpr::arg_iterator I = Exp->arg_begin(), in SynthesizeBlockCall()
4638 E = Exp->arg_end(); I != E; ++I) { in SynthesizeBlockCall()
4642 CallExpr::Create(*Context, PE, BlkExprs, Exp->getType(), VK_PRValue, in SynthesizeBlockCall()
4661 // Rewrite the byref variable into BYREFVAR->__forwarding->BYREFVAR in RewriteBlockDeclRefExpr()
4663 ValueDecl *VD = DeclRefExp->getDecl(); in RewriteBlockDeclRefExpr()
4664 bool isArrow = DeclRefExp->refersToEnclosingVariableOrCapture() || in RewriteBlockDeclRefExpr()
4665 HasLocalVariableExternalStorage(DeclRefExp->getDecl()); in RewriteBlockDeclRefExpr()
4669 &Context->Idents.get("__forwarding"), in RewriteBlockDeclRefExpr()
4670 Context->VoidPtrTy, nullptr, in RewriteBlockDeclRefExpr()
4674 *Context, DeclRefExp, isArrow, FD, FD->getType(), VK_LValue, OK_Ordinary); in RewriteBlockDeclRefExpr()
4676 StringRef Name = VD->getName(); in RewriteBlockDeclRefExpr()
4678 &Context->Idents.get(Name), in RewriteBlockDeclRefExpr()
4679 Context->VoidPtrTy, nullptr, in RewriteBlockDeclRefExpr()
4682 ME = MemberExpr::CreateImplicit(*Context, ME, true, FD, DeclRefExp->getType(), in RewriteBlockDeclRefExpr()
4686 ParenExpr *PE = new (Context) ParenExpr(DeclRefExp->getExprLoc(), in RewriteBlockDeclRefExpr()
4687 DeclRefExp->getExprLoc(), in RewriteBlockDeclRefExpr()
4697 ValueDecl *VD = DRE->getDecl(); in RewriteLocalVariableExternalStorage()
4702 const_cast<ASTContext &>(*Context), DRE, UO_Deref, DRE->getType(), in RewriteLocalVariableExternalStorage()
4703 VK_LValue, OK_Ordinary, DRE->getLocation(), false, FPOptionsOverride()); in RewriteLocalVariableExternalStorage()
4712 SourceLocation LocStart = CE->getLParenLoc(); in RewriteCastExpr()
4713 SourceLocation LocEnd = CE->getRParenLoc(); in RewriteCastExpr()
4722 const char *startBuf = SM->getCharacterData(LocStart); in RewriteCastExpr()
4723 const char *endBuf = SM->getCharacterData(LocEnd); in RewriteCastExpr()
4724 QualType QT = CE->getType(); in RewriteCastExpr()
4725 const Type* TypePtr = QT->getAs<Type>(); in RewriteCastExpr()
4728 QT = TypeOfExprTypePtr->getUnderlyingExpr()->getType(); in RewriteCastExpr()
4732 ReplaceText(LocStart, endBuf-startBuf+1, TypeAsString); in RewriteCastExpr()
4742 LocStart = LocStart.getLocWithOffset(argPtr-startBuf); in RewriteCastExpr()
4750 CastKind CastKind = IC->getCastKind(); in RewriteImplicitCastObjCExpr()
4755 QualType QT = IC->getType(); in RewriteImplicitCastObjCExpr()
4757 std::string TypeString(QT.getAsString(Context->getPrintingPolicy())); in RewriteImplicitCastObjCExpr()
4761 InsertText(IC->getSubExpr()->getBeginLoc(), Str); in RewriteImplicitCastObjCExpr()
4765 SourceLocation DeclLoc = FD->getLocation(); in RewriteBlockPointerFunctionArgs()
4769 const char *startBuf = SM->getCharacterData(DeclLoc); in RewriteBlockPointerFunctionArgs()
4776 DeclLoc = DeclLoc.getLocWithOffset(startArgList-startBuf); in RewriteBlockPointerFunctionArgs()
4785 DeclLoc = DeclLoc.getLocWithOffset(argPtr-startArgList); in RewriteBlockPointerFunctionArgs()
4792 parenCount--; in RewriteBlockPointerFunctionArgs()
4800 const PointerType *PT = QT->getAs<PointerType>(); in PointerTypeTakesAnyBlockArguments()
4802 FTP = PT->getPointeeType()->getAs<FunctionProtoType>(); in PointerTypeTakesAnyBlockArguments()
4804 const BlockPointerType *BPT = QT->getAs<BlockPointerType>(); in PointerTypeTakesAnyBlockArguments()
4806 FTP = BPT->getPointeeType()->getAs<FunctionProtoType>(); in PointerTypeTakesAnyBlockArguments()
4809 for (const auto &I : FTP->param_types()) in PointerTypeTakesAnyBlockArguments()
4818 const PointerType *PT = QT->getAs<PointerType>(); in PointerTypeTakesAnyObjCQualifiedType()
4820 FTP = PT->getPointeeType()->getAs<FunctionProtoType>(); in PointerTypeTakesAnyObjCQualifiedType()
4822 const BlockPointerType *BPT = QT->getAs<BlockPointerType>(); in PointerTypeTakesAnyObjCQualifiedType()
4824 FTP = BPT->getPointeeType()->getAs<FunctionProtoType>(); in PointerTypeTakesAnyObjCQualifiedType()
4827 for (const auto &I : FTP->param_types()) { in PointerTypeTakesAnyObjCQualifiedType()
4828 if (I->isObjCQualifiedIdType()) in PointerTypeTakesAnyObjCQualifiedType()
4830 if (I->isObjCObjectPointerType() && in PointerTypeTakesAnyObjCQualifiedType()
4831 I->getPointeeType()->isObjCQualifiedInterfaceType()) in PointerTypeTakesAnyObjCQualifiedType()
4851 case ')': parenCount--; break; in GetExtentOfArgList()
4866 SourceLocation DeclLoc = ND->getLocation(); in RewriteBlockPointerDecl()
4869 DeclT = VD->getType(); in RewriteBlockPointerDecl()
4871 DeclT = TDD->getUnderlyingType(); in RewriteBlockPointerDecl()
4873 DeclT = FD->getType(); in RewriteBlockPointerDecl()
4877 const char *startBuf = SM->getCharacterData(DeclLoc); in RewriteBlockPointerDecl()
4881 startBuf--; in RewriteBlockPointerDecl()
4882 SourceLocation Start = DeclLoc.getLocWithOffset(startBuf-endBuf); in RewriteBlockPointerDecl()
4905 DeclLoc = ND->getLocation(); in RewriteBlockPointerDecl()
4906 startBuf = SM->getCharacterData(DeclLoc); in RewriteBlockPointerDecl()
4934 /// SynthesizeByrefCopyDestroyHelper - This routine synthesizes:
4937 /// _Block_object_assign (&_dest->object, _src->object,
4940 /// _Block_object_assign(&_dest->object, _src->object,
4946 /// _Block_object_dispose(_src->object,
4949 /// _Block_object_dispose(_src->object,
4967 static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); in SynthesizeByrefCopyDestroyHelper()
4969 static_cast<unsigned>(Context->getTypeSize(Context->VoidPtrTy)); in SynthesizeByrefCopyDestroyHelper()
4971 unsigned offset = (VoidPtrSize*4 + IntSize + IntSize)/Context->getCharWidth(); in SynthesizeByrefCopyDestroyHelper()
4991 /// RewriteByRefVar - For each __block typex ND variable this routine transforms
5006 /// ND=initializer-if-any};
5013 SourceLocation DeclLoc = ND->getTypeSpecStartLoc(); in RewriteByRefVar()
5017 DeclLoc = ND->getLocation(); in RewriteByRefVar()
5018 const char *startBuf = SM->getCharacterData(DeclLoc); in RewriteByRefVar()
5019 SourceLocation X = ND->getEndLoc(); in RewriteByRefVar()
5020 X = SM->getExpansionLoc(X); in RewriteByRefVar()
5021 const char *endBuf = SM->getCharacterData(X); in RewriteByRefVar()
5022 std::string Name(ND->getNameAsString()); in RewriteByRefVar()
5033 QualType Ty = ND->getType(); in RewriteByRefVar()
5034 bool HasCopyAndDispose = Context->BlockRequiresCopying(Ty, ND); in RewriteByRefVar()
5042 T.getAsStringInternal(Name, Context->getPrintingPolicy()); in RewriteByRefVar()
5051 assert(CurMethodDef && "RewriteByRefVar - CurMethodDef is null"); in RewriteByRefVar()
5052 FunLocStart = CurMethodDef->getBeginLoc(); in RewriteByRefVar()
5062 QualType Ty = ND->getType(); in RewriteByRefVar()
5064 if (Ty->isBlockPointerType()) in RewriteByRefVar()
5070 Preamble += HF; in RewriteByRefVar()
5075 // initializer-if-any}; in RewriteByRefVar()
5076 bool hasInit = (ND->getInit() != nullptr); in RewriteByRefVar()
5080 if (CXXConstructExpr *CExp = dyn_cast<CXXConstructExpr>(ND->getInit())) { in RewriteByRefVar()
5081 CXXConstructorDecl *CXXDecl = CExp->getConstructor(); in RewriteByRefVar()
5082 if (CXXDecl && CXXDecl->isDefaultConstructor()) in RewriteByRefVar()
5089 Name = ND->getNameAsString(); in RewriteByRefVar()
5113 DeclLoc = ND->getLocation(); in RewriteByRefVar()
5114 const char *startDeclBuf = SM->getCharacterData(DeclLoc); in RewriteByRefVar()
5117 commaBuf--; in RewriteByRefVar()
5119 DeclLoc = DeclLoc.getLocWithOffset(commaBuf - startDeclBuf); in RewriteByRefVar()
5128 if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) in RewriteByRefVar()
5130 ReplaceText(DeclLoc, endBuf-startBuf+nameSize, ByrefType); in RewriteByRefVar()
5135 Expr *E = ND->getInit(); in RewriteByRefVar()
5137 startLoc = ECE->getLParenLoc(); in RewriteByRefVar()
5139 startLoc = E->getBeginLoc(); in RewriteByRefVar()
5140 startLoc = SM->getExpansionLoc(startLoc); in RewriteByRefVar()
5141 endBuf = SM->getCharacterData(startLoc); in RewriteByRefVar()
5142 ReplaceText(DeclLoc, endBuf-startBuf, ByrefType); in RewriteByRefVar()
5145 const char *startInitializerBuf = SM->getCharacterData(startLoc); in RewriteByRefVar()
5150 startLoc.getLocWithOffset(separatorBuf-startInitializerBuf); in RewriteByRefVar()
5158 GetBlockDeclRefExprs(Exp->getBody()); in CollectBlockDeclRefInfo()
5162 if (!BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>()) { in CollectBlockDeclRefInfo()
5163 if (!BlockByCopyDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) { in CollectBlockDeclRefInfo()
5164 BlockByCopyDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()); in CollectBlockDeclRefInfo()
5165 BlockByCopyDecls.push_back(BlockDeclRefs[i]->getDecl()); in CollectBlockDeclRefInfo()
5170 if (BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>()) { in CollectBlockDeclRefInfo()
5171 if (!BlockByRefDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) { in CollectBlockDeclRefInfo()
5172 BlockByRefDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()); in CollectBlockDeclRefInfo()
5173 BlockByRefDecls.push_back(BlockDeclRefs[i]->getDecl()); in CollectBlockDeclRefInfo()
5178 if (BlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>() || in CollectBlockDeclRefInfo()
5179 BlockDeclRefs[i]->getType()->isObjCObjectPointerType() || in CollectBlockDeclRefInfo()
5180 BlockDeclRefs[i]->getType()->isBlockPointerType()) in CollectBlockDeclRefInfo()
5181 ImportedBlockDecls.insert(BlockDeclRefs[i]->getDecl()); in CollectBlockDeclRefInfo()
5186 IdentifierInfo *ID = &Context->Idents.get(name); in SynthBlockInitFunctionDecl()
5187 QualType FType = Context->getFunctionNoProtoType(Context->VoidPtrTy); in SynthBlockInitFunctionDecl()
5195 const BlockDecl *block = Exp->getBlockDecl(); in SynthBlockInitExpr()
5206 ValueDecl *VD = Exp->getDecl(); in SynthBlockInitExpr()
5207 if (!VD->hasAttr<BlocksAttr>() && !BlockByCopyDeclsPtrSet.count(VD)) { in SynthBlockInitExpr()
5208 // We need to save the copied-in variables in nested in SynthBlockInitExpr()
5216 if (VD->hasAttr<BlocksAttr>() && !BlockByRefDeclsPtrSet.count(VD)) { in SynthBlockInitExpr()
5225 if (InnerBlockDeclRefs[i]->getDecl()->hasAttr<BlocksAttr>() || in SynthBlockInitExpr()
5226 InnerBlockDeclRefs[i]->getType()->isObjCObjectPointerType() || in SynthBlockInitExpr()
5227 InnerBlockDeclRefs[i]->getType()->isBlockPointerType()) in SynthBlockInitExpr()
5228 ImportedBlockDecls.insert(InnerBlockDeclRefs[i]->getDecl()); in SynthBlockInitExpr()
5235 FuncName = CurFunctionDef->getNameAsString(); in SynthBlockInitExpr()
5239 FuncName = std::string(GlobalVarDecl->getNameAsString()); in SynthBlockInitExpr()
5242 block->getDeclContext()->getRedeclContext()->isFileContext(); in SynthBlockInitExpr()
5245 Diags.Report(block->getLocation(), GlobalBlockRewriteFailedDiag); in SynthBlockInitExpr()
5249 std::string BlockNumber = utostr(Blocks.size()-1); in SynthBlockInitExpr()
5254 QualType BFT = convertFunctionTypeOfBlocks(Exp->getFunctionType()); in SynthBlockInitExpr()
5255 QualType FType = Context->getPointerType(BFT); in SynthBlockInitExpr()
5278 *Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); in SynthBlockInitExpr()
5279 CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, in SynthBlockInitExpr()
5288 &Context->Idents.get(DescData), Context->VoidPtrTy, nullptr, SC_Static); in SynthBlockInitExpr()
5291 new (Context) DeclRefExpr(*Context, NewVD, false, Context->VoidPtrTy, in SynthBlockInitExpr()
5293 UO_AddrOf, Context->getPointerType(Context->VoidPtrTy), VK_PRValue, in SynthBlockInitExpr()
5303 if (isObjCType((*I)->getType())) { in SynthBlockInitExpr()
5305 FD = SynthBlockInitFunctionDecl((*I)->getName()); in SynthBlockInitExpr()
5306 Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), in SynthBlockInitExpr()
5309 QualType QT = (*I)->getType(); in SynthBlockInitExpr()
5310 QT = Context->getPointerType(QT); in SynthBlockInitExpr()
5316 } else if (isTopLevelBlockPointerType((*I)->getType())) { in SynthBlockInitExpr()
5317 FD = SynthBlockInitFunctionDecl((*I)->getName()); in SynthBlockInitExpr()
5318 Arg = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), in SynthBlockInitExpr()
5320 Exp = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, in SynthBlockInitExpr()
5323 FD = SynthBlockInitFunctionDecl((*I)->getName()); in SynthBlockInitExpr()
5324 Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), in SynthBlockInitExpr()
5327 QualType QT = (*I)->getType(); in SynthBlockInitExpr()
5328 QT = Context->getPointerType(QT); in SynthBlockInitExpr()
5342 std::string Name(ND->getNameAsString()); in SynthBlockInitExpr()
5345 IdentifierInfo *II = &Context->Idents.get(RecName.c_str() in SynthBlockInitExpr()
5351 QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); in SynthBlockInitExpr()
5353 FD = SynthBlockInitFunctionDecl((*I)->getName()); in SynthBlockInitExpr()
5354 Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), in SynthBlockInitExpr()
5357 for (const auto &CI : block->captures()) { in SynthBlockInitExpr()
5361 "SynthBlockInitExpr - captured block variable is not byref"); in SynthBlockInitExpr()
5371 Context->getPointerType(Exp->getType()), VK_PRValue, OK_Ordinary, in SynthBlockInitExpr()
5381 static_cast<unsigned>(Context->getTypeSize(Context->IntTy)); in SynthBlockInitExpr()
5383 Context->IntTy, SourceLocation()); in SynthBlockInitExpr()
5391 "SynthBlockInitExpr - GlobalConstructionExp must be null"); in SynthBlockInitExpr()
5398 Context->getPointerType(NewRep->getType()), VK_PRValue, OK_Ordinary, in SynthBlockInitExpr()
5418 return CS->getElement() == DS; in IsDeclStmtInForeachHeader()
5422 //===----------------------------------------------------------------------===//
5424 //===----------------------------------------------------------------------===//
5435 // Pseudo-object operations and ivar references need special in RewriteFunctionBodyOrGlobalInitializer()
5438 if (isa<BinaryOperator>(PseudoOp->getSyntacticForm())) { in RewriteFunctionBodyOrGlobalInitializer()
5447 S = cast<OpaqueValueExpr>(S)->getSourceExpr(); in RewriteFunctionBodyOrGlobalInitializer()
5449 SourceRange OrigStmtRange = S->getSourceRange(); in RewriteFunctionBodyOrGlobalInitializer()
5452 for (Stmt *&childStmt : S->children()) in RewriteFunctionBodyOrGlobalInitializer()
5463 InnerContexts.insert(BE->getBlockDecl()); in RewriteFunctionBodyOrGlobalInitializer()
5465 GetInnerBlockDeclRefExprs(BE->getBody(), in RewriteFunctionBodyOrGlobalInitializer()
5469 CurrentBody = BE->getBody(); in RewriteFunctionBodyOrGlobalInitializer()
5471 // block literal on rhs of a property-dot-sytax assignment in RewriteFunctionBodyOrGlobalInitializer()
5478 RewriteFunctionBodyOrGlobalInitializer(BE->getBody()); in RewriteFunctionBodyOrGlobalInitializer()
5484 std::string Str = Rewrite.getRewrittenText(BE->getSourceRange()); in RewriteFunctionBodyOrGlobalInitializer()
5489 //blockTranscribed->dump(); in RewriteFunctionBodyOrGlobalInitializer()
5519 SourceLocation startLoc = MessExpr->getBeginLoc(); in RewriteFunctionBodyOrGlobalInitializer()
5520 SourceLocation endLoc = MessExpr->getEndLoc(); in RewriteFunctionBodyOrGlobalInitializer()
5522 const char *startBuf = SM->getCharacterData(startLoc); in RewriteFunctionBodyOrGlobalInitializer()
5523 const char *endBuf = SM->getCharacterData(endLoc); in RewriteFunctionBodyOrGlobalInitializer()
5527 messString.append(startBuf, endBuf-startBuf+1); in RewriteFunctionBodyOrGlobalInitializer()
5570 // FIXME: What we're doing here is modifying the type-specifier that in RewriteFunctionBodyOrGlobalInitializer()
5572 // a separate type-specifier that we can rewrite. in RewriteFunctionBodyOrGlobalInitializer()
5580 RewriteObjCQualifiedInterfaceTypes(*DS->decl_begin()); in RewriteFunctionBodyOrGlobalInitializer()
5583 for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end(); in RewriteFunctionBodyOrGlobalInitializer()
5587 if (isTopLevelBlockPointerType(ND->getType())) in RewriteFunctionBodyOrGlobalInitializer()
5589 else if (ND->getType()->isFunctionPointerType()) in RewriteFunctionBodyOrGlobalInitializer()
5590 CheckFunctionPointerDecl(ND->getType(), ND); in RewriteFunctionBodyOrGlobalInitializer()
5592 if (VD->hasAttr<BlocksAttr>()) { in RewriteFunctionBodyOrGlobalInitializer()
5597 RewriteByRefVar(VD, (DI == DS->decl_begin()), ((DI+1) == DE)); in RewriteFunctionBodyOrGlobalInitializer()
5604 if (isTopLevelBlockPointerType(TD->getUnderlyingType())) in RewriteFunctionBodyOrGlobalInitializer()
5606 else if (TD->getUnderlyingType()->isFunctionPointerType()) in RewriteFunctionBodyOrGlobalInitializer()
5607 CheckFunctionPointerDecl(TD->getUnderlyingType(), TD); in RewriteFunctionBodyOrGlobalInitializer()
5625 ValueDecl *VD = DRE->getDecl(); in RewriteFunctionBodyOrGlobalInitializer()
5626 if (VD->hasAttr<BlocksAttr>()) in RewriteFunctionBodyOrGlobalInitializer()
5633 if (CE->getCallee()->getType()->isBlockPointerType()) { in RewriteFunctionBodyOrGlobalInitializer()
5634 Stmt *BlockCall = SynthesizeBlockCall(CE, CE->getCallee()); in RewriteFunctionBodyOrGlobalInitializer()
5648 CastExpr *Replacement = new (Context) CastExpr(ICE->getType(), in RewriteFunctionBodyOrGlobalInitializer()
5649 ICE->getSubExpr(), in RewriteFunctionBodyOrGlobalInitializer()
5654 Replacement->printPretty(Buf); in RewriteFunctionBodyOrGlobalInitializer()
5658 InsertText(ICE->getSubExpr()->getBeginLoc(), Str); in RewriteFunctionBodyOrGlobalInitializer()
5668 for (auto *FD : RD->fields()) { in RewriteRecordBody()
5669 if (isTopLevelBlockPointerType(FD->getType())) in RewriteRecordBody()
5671 if (FD->getType()->isObjCQualifiedIdType() || in RewriteRecordBody()
5672 FD->getType()->isObjCQualifiedInterfaceType()) in RewriteRecordBody()
5677 /// HandleDeclInMainFile - This is called for each top-level decl defined in the
5680 switch (D->getKind()) { in HandleDeclInMainFile()
5683 if (FD->isOverloadedOperator()) in HandleDeclInMainFile()
5689 RewriteBlocksInFunctionProtoType(FD->getType(), FD); in HandleDeclInMainFile()
5691 if (!FD->isThisDeclarationADefinition()) in HandleDeclInMainFile()
5694 // FIXME: If this should support Obj-C++, support CXXTryStmt in HandleDeclInMainFile()
5695 if (CompoundStmt *Body = dyn_cast_or_null<CompoundStmt>(FD->getBody())) { in HandleDeclInMainFile()
5700 FD->setBody(Body); in HandleDeclInMainFile()
5716 if (CompoundStmt *Body = MD->getCompoundBody()) { in HandleDeclInMainFile()
5721 MD->setBody(Body); in HandleDeclInMainFile()
5746 if (isTopLevelBlockPointerType(VD->getType())) in HandleDeclInMainFile()
5748 else if (VD->getType()->isFunctionPointerType()) { in HandleDeclInMainFile()
5749 CheckFunctionPointerDecl(VD->getType(), VD); in HandleDeclInMainFile()
5750 if (VD->getInit()) { in HandleDeclInMainFile()
5751 if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) { in HandleDeclInMainFile()
5755 } else if (VD->getType()->isRecordType()) { in HandleDeclInMainFile()
5756 RecordDecl *RD = VD->getType()->castAs<RecordType>()->getDecl(); in HandleDeclInMainFile()
5757 if (RD->isCompleteDefinition()) in HandleDeclInMainFile()
5760 if (VD->getInit()) { in HandleDeclInMainFile()
5762 CurrentBody = VD->getInit(); in HandleDeclInMainFile()
5763 RewriteFunctionBodyOrGlobalInitializer(VD->getInit()); in HandleDeclInMainFile()
5769 SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(), VD->getName()); in HandleDeclInMainFile()
5773 if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) { in HandleDeclInMainFile()
5782 if (isTopLevelBlockPointerType(TD->getUnderlyingType())) in HandleDeclInMainFile()
5784 else if (TD->getUnderlyingType()->isFunctionPointerType()) in HandleDeclInMainFile()
5785 CheckFunctionPointerDecl(TD->getUnderlyingType(), TD); in HandleDeclInMainFile()
5794 if (RD->isCompleteDefinition()) in HandleDeclInMainFile()
5804 /// Write_ProtocolExprReferencedMetadata - This routine writer out the
5810 // Also output .objc_protorefs$B section and its meta-data. in Write_ProtocolExprReferencedMetadata()
5811 if (Context->getLangOpts().MicrosoftExt) in Write_ProtocolExprReferencedMetadata()
5815 Result += PDecl->getNameAsString(); in Write_ProtocolExprReferencedMetadata()
5817 Result += "_OBJC_PROTOCOL_"; Result += PDecl->getNameAsString(); in Write_ProtocolExprReferencedMetadata()
5838 RewriteObjCProtocolMetaData(ProtDecl, Preamble); in HandleTranslationUnit()
5839 Write_ProtocolExprReferencedMetadata(Context, ProtDecl, Preamble); in HandleTranslationUnit()
5842 InsertText(SM->getLocForStartOfFile(MainFileID), Preamble, false); in HandleTranslationUnit()
5861 *OutFile << std::string(RewriteBuf->begin(), RewriteBuf->end()); in HandleTranslationUnit()
5868 // Rewrite Objective-c meta data* in HandleTranslationUnit()
5880 OutFile->flush(); in HandleTranslationUnit()
5886 Preamble += "#ifndef __OBJC2__\n"; in Initialize()
5887 Preamble += "#define __OBJC2__\n"; in Initialize()
5888 Preamble += "#endif\n"; in Initialize()
5893 Preamble = "#pragma once\n"; in Initialize()
5894 Preamble += "struct objc_selector; struct objc_class;\n"; in Initialize()
5895 Preamble += "struct __rw_objc_super { \n\tstruct objc_object *object; "; in Initialize()
5896 Preamble += "\n\tstruct objc_object *superClass; "; in Initialize()
5898 Preamble += "\n\t__rw_objc_super(struct objc_object *o, struct objc_object *s) "; in Initialize()
5899 Preamble += ": object(o), superClass(s) {} "; in Initialize()
5900 Preamble += "\n};\n"; in Initialize()
5905 Preamble += "\n#pragma section(\".objc_classlist$B\", long, read, write)\n"; in Initialize()
5906 Preamble += "#pragma section(\".objc_catlist$B\", long, read, write)\n"; in Initialize()
5907 Preamble += "#pragma section(\".objc_imageinfo$B\", long, read, write)\n"; in Initialize()
5908 Preamble += "#pragma section(\".objc_nlclslist$B\", long, read, write)\n"; in Initialize()
5909 Preamble += "#pragma section(\".objc_nlcatlist$B\", long, read, write)\n"; in Initialize()
5911 Preamble += "#pragma section(\".cat_cls_meth$B\", long, read, write)\n"; in Initialize()
5912 Preamble += "#pragma section(\".inst_meth$B\", long, read, write)\n"; in Initialize()
5913 Preamble += "#pragma section(\".cls_meth$B\", long, read, write)\n"; in Initialize()
5914 Preamble += "#pragma section(\".objc_ivar$B\", long, read, write)\n"; in Initialize()
5918 Preamble += "#pragma section(\".objc_selrefs$B\", long, read, write)\n"; in Initialize()
5919 Preamble += "#pragma section(\".objc_classrefs$B\", long, read, write)\n"; in Initialize()
5920 Preamble += "#pragma section(\".objc_superrefs$B\", long, read, write)\n"; in Initialize()
5923 Preamble += "#ifndef _REWRITER_typedef_Protocol\n"; in Initialize()
5924 Preamble += "typedef struct objc_object Protocol;\n"; in Initialize()
5925 Preamble += "#define _REWRITER_typedef_Protocol\n"; in Initialize()
5926 Preamble += "#endif\n"; in Initialize()
5928 Preamble += "#define __OBJC_RW_DLLIMPORT extern \"C\" __declspec(dllimport)\n"; in Initialize()
5929 Preamble += "#define __OBJC_RW_STATICIMPORT extern \"C\"\n"; in Initialize()
5932 Preamble += "#define __OBJC_RW_DLLIMPORT extern\n"; in Initialize()
5934 Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSend(void);\n"; in Initialize()
5935 Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSendSuper(void);\n"; in Initialize()
5936 Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSend_stret(void);\n"; in Initialize()
5937 Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSendSuper_stret(void);\n"; in Initialize()
5938 Preamble += "__OBJC_RW_DLLIMPORT void objc_msgSend_fpret(void);\n"; in Initialize()
5940 Preamble += "__OBJC_RW_DLLIMPORT struct objc_class *objc_getClass"; in Initialize()
5941 Preamble += "(const char *);\n"; in Initialize()
5942 Preamble += "__OBJC_RW_DLLIMPORT struct objc_class *class_getSuperclass"; in Initialize()
5943 Preamble += "(struct objc_class *);\n"; in Initialize()
5944 Preamble += "__OBJC_RW_DLLIMPORT struct objc_class *objc_getMetaClass"; in Initialize()
5945 Preamble += "(const char *);\n"; in Initialize()
5946 Preamble += "__OBJC_RW_DLLIMPORT void objc_exception_throw( struct objc_object *);\n"; in Initialize()
5948 Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_enter( struct objc_object *);\n"; in Initialize()
5949 Preamble += "__OBJC_RW_DLLIMPORT int objc_sync_exit( struct objc_object *);\n"; in Initialize()
5950 Preamble += "__OBJC_RW_DLLIMPORT Protocol *objc_getProtocol(const char *);\n"; in Initialize()
5951 Preamble += "#ifdef _WIN64\n"; in Initialize()
5952 Preamble += "typedef unsigned long long _WIN_NSUInteger;\n"; in Initialize()
5953 Preamble += "#else\n"; in Initialize()
5954 Preamble += "typedef unsigned int _WIN_NSUInteger;\n"; in Initialize()
5955 Preamble += "#endif\n"; in Initialize()
5956 Preamble += "#ifndef __FASTENUMERATIONSTATE\n"; in Initialize()
5957 Preamble += "struct __objcFastEnumerationState {\n\t"; in Initialize()
5958 Preamble += "unsigned long state;\n\t"; in Initialize()
5959 Preamble += "void **itemsPtr;\n\t"; in Initialize()
5960 Preamble += "unsigned long *mutationsPtr;\n\t"; in Initialize()
5961 Preamble += "unsigned long extra[5];\n};\n"; in Initialize()
5962 Preamble += "__OBJC_RW_DLLIMPORT void objc_enumerationMutation(struct objc_object *);\n"; in Initialize()
5963 Preamble += "#define __FASTENUMERATIONSTATE\n"; in Initialize()
5964 Preamble += "#endif\n"; in Initialize()
5965 Preamble += "#ifndef __NSCONSTANTSTRINGIMPL\n"; in Initialize()
5966 Preamble += "struct __NSConstantStringImpl {\n"; in Initialize()
5967 Preamble += " int *isa;\n"; in Initialize()
5968 Preamble += " int flags;\n"; in Initialize()
5969 Preamble += " char *str;\n"; in Initialize()
5970 Preamble += "#if _WIN64\n"; in Initialize()
5971 Preamble += " long long length;\n"; in Initialize()
5972 Preamble += "#else\n"; in Initialize()
5973 Preamble += " long length;\n"; in Initialize()
5974 Preamble += "#endif\n"; in Initialize()
5975 Preamble += "};\n"; in Initialize()
5976 Preamble += "#ifdef CF_EXPORT_CONSTANT_STRING\n"; in Initialize()
5977 Preamble += "extern \"C\" __declspec(dllexport) int __CFConstantStringClassReference[];\n"; in Initialize()
5978 Preamble += "#else\n"; in Initialize()
5979 Preamble += "__OBJC_RW_DLLIMPORT int __CFConstantStringClassReference[];\n"; in Initialize()
5980 Preamble += "#endif\n"; in Initialize()
5981 Preamble += "#define __NSCONSTANTSTRINGIMPL\n"; in Initialize()
5982 Preamble += "#endif\n"; in Initialize()
5983 // Blocks preamble. in Initialize()
5984 Preamble += "#ifndef BLOCK_IMPL\n"; in Initialize()
5985 Preamble += "#define BLOCK_IMPL\n"; in Initialize()
5986 Preamble += "struct __block_impl {\n"; in Initialize()
5987 Preamble += " void *isa;\n"; in Initialize()
5988 Preamble += " int Flags;\n"; in Initialize()
5989 Preamble += " int Reserved;\n"; in Initialize()
5990 Preamble += " void *FuncPtr;\n"; in Initialize()
5991 Preamble += "};\n"; in Initialize()
5992 Preamble += "// Runtime copy/destroy helper functions (from Block_private.h)\n"; in Initialize()
5993 Preamble += "#ifdef __OBJC_EXPORT_BLOCKS\n"; in Initialize()
5994 Preamble += "extern \"C\" __declspec(dllexport) " in Initialize()
5996 …Preamble += "extern \"C\" __declspec(dllexport) void _Block_object_dispose(const void *, const int… in Initialize()
5997 Preamble += "extern \"C\" __declspec(dllexport) void *_NSConcreteGlobalBlock[32];\n"; in Initialize()
5998 Preamble += "extern \"C\" __declspec(dllexport) void *_NSConcreteStackBlock[32];\n"; in Initialize()
5999 Preamble += "#else\n"; in Initialize()
6000 Preamble += "__OBJC_RW_DLLIMPORT void _Block_object_assign(void *, const void *, const int);\n"; in Initialize()
6001 Preamble += "__OBJC_RW_DLLIMPORT void _Block_object_dispose(const void *, const int);\n"; in Initialize()
6002 Preamble += "__OBJC_RW_DLLIMPORT void *_NSConcreteGlobalBlock[32];\n"; in Initialize()
6003 Preamble += "__OBJC_RW_DLLIMPORT void *_NSConcreteStackBlock[32];\n"; in Initialize()
6004 Preamble += "#endif\n"; in Initialize()
6005 Preamble += "#endif\n"; in Initialize()
6007 Preamble += "#undef __OBJC_RW_DLLIMPORT\n"; in Initialize()
6008 Preamble += "#undef __OBJC_RW_STATICIMPORT\n"; in Initialize()
6009 Preamble += "#ifndef KEEP_ATTRIBUTES\n"; // We use this for clang tests. in Initialize()
6010 Preamble += "#define __attribute__(X)\n"; in Initialize()
6011 Preamble += "#endif\n"; in Initialize()
6012 Preamble += "#ifndef __weak\n"; in Initialize()
6013 Preamble += "#define __weak\n"; in Initialize()
6014 Preamble += "#endif\n"; in Initialize()
6015 Preamble += "#ifndef __block\n"; in Initialize()
6016 Preamble += "#define __block\n"; in Initialize()
6017 Preamble += "#endif\n"; in Initialize()
6020 Preamble += "#define __block\n"; in Initialize()
6021 Preamble += "#define __weak\n"; in Initialize()
6024 // Declarations required for modern objective-c array and dictionary literals. in Initialize()
6025 Preamble += "\n#include <stdarg.h>\n"; in Initialize()
6026 Preamble += "struct __NSContainer_literal {\n"; in Initialize()
6027 Preamble += " void * *arr;\n"; in Initialize()
6028 Preamble += " __NSContainer_literal (unsigned int count, ...) {\n"; in Initialize()
6029 Preamble += "\tva_list marker;\n"; in Initialize()
6030 Preamble += "\tva_start(marker, count);\n"; in Initialize()
6031 Preamble += "\tarr = new void *[count];\n"; in Initialize()
6032 Preamble += "\tfor (unsigned i = 0; i < count; i++)\n"; in Initialize()
6033 Preamble += "\t arr[i] = va_arg(marker, void *);\n"; in Initialize()
6034 Preamble += "\tva_end( marker );\n"; in Initialize()
6035 Preamble += " };\n"; in Initialize()
6036 Preamble += " ~__NSContainer_literal() {\n"; in Initialize()
6037 Preamble += "\tdelete[] arr;\n"; in Initialize()
6038 Preamble += " }\n"; in Initialize()
6039 Preamble += "};\n"; in Initialize()
6042 Preamble += "extern \"C\" __declspec(dllimport) void * objc_autoreleasePoolPush(void);\n"; in Initialize()
6043 Preamble += "extern \"C\" __declspec(dllimport) void objc_autoreleasePoolPop(void *);\n\n"; in Initialize()
6044 Preamble += "struct __AtAutoreleasePool {\n"; in Initialize()
6045 Preamble += " __AtAutoreleasePool() {atautoreleasepoolobj = objc_autoreleasePoolPush();}\n"; in Initialize()
6046 Preamble += " ~__AtAutoreleasePool() {objc_autoreleasePoolPop(atautoreleasepoolobj);}\n"; in Initialize()
6047 Preamble += " void * atautoreleasepoolobj;\n"; in Initialize()
6048 Preamble += "};\n"; in Initialize()
6052 Preamble += "\n#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)\n"; in Initialize()
6055 /// RewriteIvarOffsetComputation - This routine synthesizes computation of
6060 Result += ivar->getContainingInterface()->getNameAsString(); in RewriteIvarOffsetComputation()
6064 if (ivar->isBitField()) in RewriteIvarOffsetComputation()
6067 Result += ivar->getNameAsString(); in RewriteIvarOffsetComputation()
6071 /// WriteModernMetadataDeclarations - Writes out metadata declarations for modern ABI.
6161 /// MessageRefTy - LLVM for:
6167 /// SuperMessageRefTy - LLVM for:
6217 const llvm::Triple &Triple(Context->getTargetInfo().getTriple()); in WriteModernMetadataDeclarations()
6304 Result += SuperPD->getNameAsString(); in Write_protocol_list_initializer()
6305 if (i == e-1) in Write_protocol_list_initializer()
6333 Result += (MD)->getSelector().getAsString(); Result += "\""; in Write_method_list_t_initializer()
6335 std::string MethodTypeString = Context->getObjCEncodingForMethodDecl(MD); in Write_method_list_t_initializer()
6344 if (i == e-1) in Write_method_list_t_initializer()
6373 Result += PropDecl->getName(); Result += "\","; in Write_prop_list_t_initializer()
6375 Context->getObjCEncodingForPropertyDecl(PropDecl, Container); in Write_prop_list_t_initializer()
6379 if (i == e-1) in Write_prop_list_t_initializer()
6396 /// (Obsolete) ARC-specific: this class has a .release_ivars method
6398 /// class was compiled with -fobjc-arr
6420 const llvm::Triple &Triple(Context->getTargetInfo().getTriple()); in Write__class_ro_t_initializer()
6472 bool rootClass = (!CDecl->getSuperClass()); in Write_class_t()
6477 RootClass = CDecl->getSuperClass(); in Write_class_t()
6478 while (RootClass->getSuperClass()) { in Write_class_t()
6479 RootClass = RootClass->getSuperClass(); in Write_class_t()
6487 if (CDecl->getImplementation()) in Write_class_t()
6493 Result += CDecl->getNameAsString(); in Write_class_t()
6498 ObjCInterfaceDecl *SuperClass = CDecl->getSuperClass(); in Write_class_t()
6501 if (SuperClass->getImplementation()) in Write_class_t()
6508 Result += SuperClass->getNameAsString(); in Write_class_t()
6513 if (RootClass->getImplementation()) in Write_class_t()
6520 Result += RootClass->getNameAsString(); in Write_class_t()
6526 Result += VarName; Result += CDecl->getNameAsString(); in Write_class_t()
6532 Result += RootClass->getNameAsString(); in Write_class_t()
6535 Result += CDecl->getSuperClass()->getNameAsString(); in Write_class_t()
6540 Result += CDecl->getNameAsString(); in Write_class_t()
6542 Result += "0, // &OBJC_CLASS_$_"; Result += CDecl->getNameAsString(); in Write_class_t()
6548 Result += CDecl->getNameAsString(); in Write_class_t()
6552 Result += CDecl->getSuperClass()->getNameAsString(); in Write_class_t()
6564 Result += CDecl->getNameAsString(); in Write_class_t()
6567 // Add static function to initialize some of the meta-data fields. in Write_class_t()
6573 rootClass ? CDecl : CDecl->getSuperClass(); in Write_class_t()
6576 Result += CDecl->getNameAsString(); in Write_class_t()
6578 Result += "\tOBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); in Write_class_t()
6580 Result += RootClass->getNameAsString(); Result += ";\n"; in Write_class_t()
6582 Result += "\tOBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); in Write_class_t()
6589 Result += SuperClass->getNameAsString(); Result += ";\n"; in Write_class_t()
6591 Result += "\tOBJC_METACLASS_$_"; Result += CDecl->getNameAsString(); in Write_class_t()
6594 Result += "\tOBJC_CLASS_$_"; Result += CDecl->getNameAsString(); in Write_class_t()
6596 Result += CDecl->getNameAsString(); Result += ";\n"; in Write_class_t()
6599 Result += "\tOBJC_CLASS_$_"; Result += CDecl->getNameAsString(); in Write_class_t()
6601 Result += SuperClass->getNameAsString(); Result += ";\n"; in Write_class_t()
6604 Result += "\tOBJC_CLASS_$_"; Result += CDecl->getNameAsString(); in Write_class_t()
6617 StringRef CatName = CatDecl->getName(); in Write_category_t()
6618 StringRef ClassName = ClassDecl->getName(); in Write_category_t()
6623 if (ClassDecl->getImplementation()) in Write_category_t()
6679 Result += ClassDecl->getNameAsString(); in Write_category_t()
6684 Result += ClassDecl->getNameAsString(); in Write_category_t()
6706 Context->getObjCEncodingForMethodDecl(MD, true); in Write__extendedMethodTypes_initializer()
6710 if (i == e-1) in Write__extendedMethodTypes_initializer()
6726 if (Ivar->getAccessControl() == ObjCIvarDecl::Private || in Write_IvarOffsetVar()
6727 Ivar->getAccessControl() == ObjCIvarDecl::Package || in Write_IvarOffsetVar()
6728 Class->getVisibility() == HiddenVisibility) in Write_IvarOffsetVar()
6737 if (Context->getLangOpts().MicrosoftExt) in Write_IvarOffsetVar()
6740 if (!Context->getLangOpts().MicrosoftExt || in Write_IvarOffsetVar()
6741 IvarDecl->getAccessControl() == ObjCIvarDecl::Private || in Write_IvarOffsetVar()
6742 IvarDecl->getAccessControl() == ObjCIvarDecl::Package) in Write_IvarOffsetVar()
6746 if (Ivars[i]->isBitField()) in Write_IvarOffsetVar()
6754 if (Ivars[i]->isBitField()) { in Write_IvarOffsetVar()
6773 if (OriginalIvars[i]->isBitField()) { in Write__ivar_list_t_initializer()
6785 Result += CDecl->getNameAsString(); in Write__ivar_list_t_initializer()
6796 if (Ivars[i]->isBitField()) in Write__ivar_list_t_initializer()
6803 if (Ivars[i]->isBitField()) in Write__ivar_list_t_initializer()
6806 Result += IvarDecl->getName(); in Write__ivar_list_t_initializer()
6809 QualType IVQT = IvarDecl->getType(); in Write__ivar_list_t_initializer()
6810 if (IvarDecl->isBitField()) in Write__ivar_list_t_initializer()
6814 Context->getObjCEncodingForType(IVQT, IvarTypeString, in Write__ivar_list_t_initializer()
6821 unsigned Align = Context->getTypeAlign(IVQT)/8; in Write__ivar_list_t_initializer()
6824 CharUnits Size = Context->getTypeSizeInChars(IVQT); in Write__ivar_list_t_initializer()
6826 if (i == e-1) in Write__ivar_list_t_initializer()
6835 /// RewriteObjCProtocolMetaData - Rewrite protocols meta-data.
6840 if (ObjCSynthesizedProtocols.count(PDecl->getCanonicalDecl())) in RewriteObjCProtocolMetaData()
6844 if (ObjCProtocolDecl *Def = PDecl->getDefinition()) in RewriteObjCProtocolMetaData()
6848 for (auto *I : PDecl->protocols()) in RewriteObjCProtocolMetaData()
6854 for (auto *MD : PDecl->instance_methods()) { in RewriteObjCProtocolMetaData()
6855 if (MD->getImplementationControl() == ObjCImplementationControl::Optional) { in RewriteObjCProtocolMetaData()
6862 for (auto *MD : PDecl->class_methods()) { in RewriteObjCProtocolMetaData()
6863 if (MD->getImplementationControl() == ObjCImplementationControl::Optional) { in RewriteObjCProtocolMetaData()
6882 PDecl->getNameAsString()); in RewriteObjCProtocolMetaData()
6884 SmallVector<ObjCProtocolDecl *, 8> SuperProtocols(PDecl->protocols()); in RewriteObjCProtocolMetaData()
6887 PDecl->getNameAsString()); in RewriteObjCProtocolMetaData()
6891 PDecl->getNameAsString(), false); in RewriteObjCProtocolMetaData()
6895 PDecl->getNameAsString(), false); in RewriteObjCProtocolMetaData()
6899 PDecl->getNameAsString(), false); in RewriteObjCProtocolMetaData()
6903 PDecl->getNameAsString(), false); in RewriteObjCProtocolMetaData()
6907 PDecl->instance_properties()); in RewriteObjCProtocolMetaData()
6911 PDecl->getNameAsString()); in RewriteObjCProtocolMetaData()
6918 Result += PDecl->getNameAsString(); in RewriteObjCProtocolMetaData()
6921 Result += "\t\""; Result += PDecl->getNameAsString(); Result += "\",\n"; in RewriteObjCProtocolMetaData()
6924 Result += PDecl->getNameAsString(); Result += ",\n"; in RewriteObjCProtocolMetaData()
6930 Result += PDecl->getNameAsString(); Result += ",\n"; in RewriteObjCProtocolMetaData()
6937 Result += PDecl->getNameAsString(); Result += ",\n"; in RewriteObjCProtocolMetaData()
6944 Result += PDecl->getNameAsString(); Result += ",\n"; in RewriteObjCProtocolMetaData()
6951 Result += PDecl->getNameAsString(); Result += ",\n"; in RewriteObjCProtocolMetaData()
6958 Result += PDecl->getNameAsString(); Result += ",\n"; in RewriteObjCProtocolMetaData()
6968 Result += PDecl->getNameAsString(); in RewriteObjCProtocolMetaData()
6977 Result += "_OBJC_LABEL_PROTOCOL_$_"; Result += PDecl->getNameAsString(); in RewriteObjCProtocolMetaData()
6978 Result += " = &_OBJC_PROTOCOL_"; Result += PDecl->getNameAsString(); in RewriteObjCProtocolMetaData()
6982 if (!ObjCSynthesizedProtocols.insert(PDecl->getCanonicalDecl()).second) in RewriteObjCProtocolMetaData()
6986 /// hasObjCExceptionAttribute - Return true if this class or any super
6991 if (OID->hasAttr<ObjCExceptionAttr>()) in hasObjCExceptionAttribute()
6993 if (const ObjCInterfaceDecl *Super = OID->getSuperClass()) in hasObjCExceptionAttribute()
7000 ObjCInterfaceDecl *CDecl = IDecl->getClassInterface(); in RewriteObjCClassMetaData()
7003 if (CDecl->isImplicitInterfaceDecl()) in RewriteObjCClassMetaData()
7010 for (ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); in RewriteObjCClassMetaData()
7011 IVD; IVD = IVD->getNextIvar()) { in RewriteObjCClassMetaData()
7012 // Ignore unnamed bit-fields. in RewriteObjCClassMetaData()
7013 if (!IVD->getDeclName()) in RewriteObjCClassMetaData()
7023 SmallVector<ObjCMethodDecl *, 32> InstanceMethods(IDecl->instance_methods()); in RewriteObjCClassMetaData()
7027 for (const auto *Prop : IDecl->property_impls()) { in RewriteObjCClassMetaData()
7028 if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) in RewriteObjCClassMetaData()
7030 if (!Prop->getPropertyIvarDecl()) in RewriteObjCClassMetaData()
7032 ObjCPropertyDecl *PD = Prop->getPropertyDecl(); in RewriteObjCClassMetaData()
7035 if (ObjCMethodDecl *Getter = Prop->getGetterMethodDecl()) in RewriteObjCClassMetaData()
7038 if (PD->isReadOnly()) in RewriteObjCClassMetaData()
7040 if (ObjCMethodDecl *Setter = Prop->getSetterMethodDecl()) in RewriteObjCClassMetaData()
7047 IDecl->getNameAsString(), true); in RewriteObjCClassMetaData()
7049 SmallVector<ObjCMethodDecl *, 32> ClassMethods(IDecl->class_methods()); in RewriteObjCClassMetaData()
7053 IDecl->getNameAsString(), true); in RewriteObjCClassMetaData()
7058 const ObjCList<ObjCProtocolDecl> &Protocols = CDecl->getReferencedProtocols(); in RewriteObjCClassMetaData()
7071 IDecl->getNameAsString()); in RewriteObjCClassMetaData()
7075 CDecl->instance_properties()); in RewriteObjCClassMetaData()
7079 CDecl->getNameAsString()); in RewriteObjCClassMetaData()
7081 // Data for initializing _class_ro_t metaclass meta-data in RewriteObjCClassMetaData()
7086 bool classIsHidden = CDecl->getVisibility() == HiddenVisibility; in RewriteObjCClassMetaData()
7090 if (!CDecl->getSuperClass()) in RewriteObjCClassMetaData()
7102 CDecl->getNameAsString()); in RewriteObjCClassMetaData()
7104 // Data for initializing _class_ro_t meta-data in RewriteObjCClassMetaData()
7112 if (!CDecl->getSuperClass()) in RewriteObjCClassMetaData()
7124 InstanceSize += CDecl->getNameAsString(); in RewriteObjCClassMetaData()
7127 ObjCIvarDecl *IVD = CDecl->all_declared_ivar_begin(); in RewriteObjCClassMetaData()
7141 CDecl->getNameAsString()); in RewriteObjCClassMetaData()
7164 ObjCInterfaceDecl *CDecl = IDecl->getClassInterface(); in RewriteClassSetupInitHook()
7166 Result += CDecl->getName(); Result += ",\n"; in RewriteClassSetupInitHook()
7197 Result += ClassImplementation[i]->getNameAsString(); in RewriteMetaDataIntoBuffer()
7207 Result += "\t&OBJC_CLASS_$_"; Result += DefinedNonLazyClasses[i]->getNameAsString(); in RewriteMetaDataIntoBuffer()
7225 CategoryImplementation[i]->getClassInterface()->getNameAsString(); in RewriteMetaDataIntoBuffer()
7227 Result += CategoryImplementation[i]->getNameAsString(); in RewriteMetaDataIntoBuffer()
7240 DefinedNonLazyCategories[i]->getClassInterface()->getNameAsString(); in RewriteMetaDataIntoBuffer()
7242 Result += DefinedNonLazyCategories[i]->getNameAsString(); in RewriteMetaDataIntoBuffer()
7258 /// RewriteObjCCategoryImplDecl - Rewrite metadata for each category
7263 ObjCInterfaceDecl *ClassDecl = IDecl->getClassInterface(); in RewriteObjCCategoryImplDecl()
7266 = ClassDecl->FindCategoryDeclaration(IDecl->getIdentifier()); in RewriteObjCCategoryImplDecl()
7268 std::string FullCategoryName = ClassDecl->getNameAsString(); in RewriteObjCCategoryImplDecl()
7270 FullCategoryName += CDecl->getNameAsString(); in RewriteObjCCategoryImplDecl()
7273 SmallVector<ObjCMethodDecl *, 32> InstanceMethods(IDecl->instance_methods()); in RewriteObjCCategoryImplDecl()
7277 for (const auto *Prop : IDecl->property_impls()) { in RewriteObjCCategoryImplDecl()
7278 if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) in RewriteObjCCategoryImplDecl()
7280 if (!Prop->getPropertyIvarDecl()) in RewriteObjCCategoryImplDecl()
7282 ObjCPropertyDecl *PD = Prop->getPropertyDecl(); in RewriteObjCCategoryImplDecl()
7285 if (ObjCMethodDecl *Getter = Prop->getGetterMethodDecl()) in RewriteObjCCategoryImplDecl()
7287 if (PD->isReadOnly()) in RewriteObjCCategoryImplDecl()
7289 if (ObjCMethodDecl *Setter = Prop->getSetterMethodDecl()) in RewriteObjCCategoryImplDecl()
7297 SmallVector<ObjCMethodDecl *, 32> ClassMethods(IDecl->class_methods()); in RewriteObjCCategoryImplDecl()
7305 SmallVector<ObjCProtocolDecl *, 8> RefedProtocols(CDecl->protocols()); in RewriteObjCCategoryImplDecl()
7306 for (auto *I : CDecl->protocols()) in RewriteObjCCategoryImplDecl()
7318 CDecl->instance_properties()); in RewriteObjCCategoryImplDecl()
7332 // Determine if this category is also "non-lazy". in RewriteObjCCategoryImplDecl()
7346 ObjCCategoryDecl *CatDecl= IDecl->getCategoryDecl(); in RewriteCategorySetupInitHook()
7347 ObjCInterfaceDecl *ClassDecl = IDecl->getClassInterface(); in RewriteCategorySetupInitHook()
7349 Result += ClassDecl->getName(); in RewriteCategorySetupInitHook()
7351 Result += CatDecl->getName(); in RewriteCategorySetupInitHook()
7357 // RewriteObjCMethodsMetaData - Rewrite methods metadata for instance or
7416 Result += (*MethodBegin)->getSelector().getAsString().c_str(); in RewriteObjCMethodsMetaData()
7418 Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString); in RewriteObjCMethodsMetaData()
7426 Result += (*MethodBegin)->getSelector().getAsString().c_str(); in RewriteObjCMethodsMetaData()
7428 Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString); in RewriteObjCMethodsMetaData()
7439 SourceRange OldRange = IV->getSourceRange(); in RewriteObjCIvarRefExpr()
7440 Expr *BaseExpr = IV->getBase(); in RewriteObjCIvarRefExpr()
7446 IV->setBase(BaseExpr); in RewriteObjCIvarRefExpr()
7449 ObjCIvarDecl *D = IV->getDecl(); in RewriteObjCIvarRefExpr()
7453 if (BaseExpr->getType()->isObjCObjectPointerType()) { in RewriteObjCIvarRefExpr()
7455 dyn_cast<ObjCInterfaceType>(BaseExpr->getType()->getPointeeType()); in RewriteObjCIvarRefExpr()
7456 assert(iFaceDecl && "RewriteObjCIvarRefExpr - iFaceDecl is null"); in RewriteObjCIvarRefExpr()
7459 iFaceDecl->getDecl()->lookupInstanceVariable(D->getIdentifier(), in RewriteObjCIvarRefExpr()
7465 if (D->isBitField()) in RewriteObjCIvarRefExpr()
7474 Context->getPointerType(Context->CharTy), in RewriteObjCIvarRefExpr()
7478 SourceLocation(), &Context->Idents.get(IvarOffsetName), in RewriteObjCIvarRefExpr()
7479 Context->UnsignedLongTy, nullptr, in RewriteObjCIvarRefExpr()
7482 DeclRefExpr(*Context, NewVD, false, Context->UnsignedLongTy, in RewriteObjCIvarRefExpr()
7486 Context->getPointerType(Context->CharTy), VK_PRValue, OK_Ordinary, in RewriteObjCIvarRefExpr()
7492 QualType IvarT = D->getType(); in RewriteObjCIvarRefExpr()
7493 if (D->isBitField()) in RewriteObjCIvarRefExpr()
7496 if (!IvarT->getAs<TypedefType>() && IvarT->isRecordType()) { in RewriteObjCIvarRefExpr()
7497 RecordDecl *RD = IvarT->castAs<RecordType>()->getDecl(); in RewriteObjCIvarRefExpr()
7498 RD = RD->getDefinition(); in RewriteObjCIvarRefExpr()
7499 if (RD && !RD->getDeclName().getAsIdentifierInfo()) { in RewriteObjCIvarRefExpr()
7500 // decltype(((Foo_IMPL*)0)->bar) * in RewriteObjCIvarRefExpr()
7501 auto *CDecl = cast<ObjCContainerDecl>(D->getDeclContext()); in RewriteObjCIvarRefExpr()
7504 CDecl = CatDecl->getClassInterface(); in RewriteObjCIvarRefExpr()
7505 std::string RecName = std::string(CDecl->getName()); in RewriteObjCIvarRefExpr()
7509 SourceLocation(), &Context->Idents.get(RecName)); in RewriteObjCIvarRefExpr()
7510 QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD)); in RewriteObjCIvarRefExpr()
7512 static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy)); in RewriteObjCIvarRefExpr()
7515 Context->UnsignedIntTy, SourceLocation()); in RewriteObjCIvarRefExpr()
7521 &Context->Idents.get(D->getNameAsString()), in RewriteObjCIvarRefExpr()
7526 *Context, PE, true, FD, FD->getType(), VK_LValue, OK_Ordinary); in RewriteObjCIvarRefExpr()
7527 IvarT = Context->getDecltypeType(ME, ME->getType()); in RewriteObjCIvarRefExpr()
7531 QualType castT = Context->getPointerType(IvarT); in RewriteObjCIvarRefExpr()
7545 if (D->isBitField()) { in RewriteObjCIvarRefExpr()
7548 &Context->Idents.get(D->getNameAsString()), in RewriteObjCIvarRefExpr()
7549 D->getType(), nullptr, in RewriteObjCIvarRefExpr()
7550 /*BitWidth=*/D->getBitWidth(), in RewriteObjCIvarRefExpr()
7554 FD->getType(), VK_LValue, OK_Ordinary); in RewriteObjCIvarRefExpr()