Lines Matching +full:multi +full:- +full:attr

1 //===--- SemaAPINotes.cpp - API Notes Handling ----------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
42 /// Determine whether this is a multi-level pointer type.
44 QualType Pointee = Type->getPointeeType(); in isIndirectPointerType()
48 return Pointee->isAnyPointerType() || Pointee->isObjCObjectPointerType() || in isIndirectPointerType()
49 Pointee->isMemberPointerType(); in isIndirectPointerType()
60 NullabilityKind Nullability) -> std::optional<QualType> { in applyNullability()
62 S.CheckImplicitNullabilityTypeSpecifier(QT, Nullability, D->getLocation(), in applyNullability()
71 GetModified(D, Function->getReturnType(), Nullability)) { in applyNullability()
72 const FunctionType *FnType = Function->getType()->castAs<FunctionType>(); in applyNullability()
74 Function->setType(S.Context.getFunctionType( in applyNullability()
75 *Modified, proto->getParamTypes(), proto->getExtProtoInfo())); in applyNullability()
77 Function->setType( in applyNullability()
78 S.Context.getFunctionNoProtoType(*Modified, FnType->getExtInfo())); in applyNullability()
81 if (auto Modified = GetModified(D, Method->getReturnType(), Nullability)) { in applyNullability()
82 Method->setReturnType(*Modified); in applyNullability()
84 // Make it a context-sensitive keyword if we can. in applyNullability()
86 Method->setObjCDeclQualifier(Decl::ObjCDeclQualifier( in applyNullability()
87 Method->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); in applyNullability()
90 if (auto Modified = GetModified(D, Value->getType(), Nullability)) { in applyNullability()
91 Value->setType(*Modified); in applyNullability()
93 // Make it a context-sensitive keyword if we can. in applyNullability()
95 if (Parm->isObjCMethodParameter() && !isIndirectPointerType(*Modified)) in applyNullability()
96 Parm->setObjCDeclQualifier(Decl::ObjCDeclQualifier( in applyNullability()
97 Parm->getObjCDeclQualifier() | Decl::OBJC_TQ_CSNullability)); in applyNullability()
101 if (auto Modified = GetModified(D, Property->getType(), Nullability)) { in applyNullability()
102 Property->setType(*Modified, Property->getTypeSourceInfo()); in applyNullability()
106 Property->setPropertyAttributes( in applyNullability()
112 /// Copy a string into ASTContext-allocated memory.
130 #define ATTR(X) \ macro
131 template <> struct AttrKindFor<X##Attr> { \
132 static const attr::Kind value = attr::X; \
148 if (Existing != D->attr_end()) { in handleAPINotedAttribute()
150 // non-versioned attribute. in handleAPINotedAttribute()
154 D->getAttrs().erase(Existing); in handleAPINotedAttribute()
155 D->addAttr(Versioned); in handleAPINotedAttribute()
160 if (auto Attr = CreateAttr()) in handleAPINotedAttribute() local
161 D->addAttr(Attr); in handleAPINotedAttribute()
167 if (auto Attr = CreateAttr()) { in handleAPINotedAttribute() local
169 S.Context, Metadata.Version, Attr, in handleAPINotedAttribute()
171 D->addAttr(Versioned); in handleAPINotedAttribute()
180 D->addAttr(Versioned); in handleAPINotedAttribute()
190 return llvm::find_if(D->attrs(), in handleAPINotedAttribute()
191 [](const Attr *Next) { return isa<A>(Next); }); in handleAPINotedAttribute()
205 [](const Decl *D) -> Decl::attr_iterator { in handleAPINotedRetainCountAttribute()
206 return llvm::find_if(D->attrs(), [](const Attr *Next) -> bool { in handleAPINotedRetainCountAttribute()
278 return llvm::find_if(D->attrs(), [](const Attr *next) -> bool { in ProcessAPINotes()
280 if (const auto *II = AA->getPlatform()) in ProcessAPINotes()
281 return II->isStr("swift"); in ProcessAPINotes()
299 S, D, true, Metadata, [&]() -> SwiftNameAttr * { in ProcessAPINotes()
308 if (!S.Swift().DiagnoseName(D, Info.SwiftName, D->getLocation(), *SNA, in ProcessAPINotes()
325 S, D, !SwiftBridge->empty(), Metadata, [&] { in ProcessAPINotes()
335 S, D, !NSErrorDomain->empty(), Metadata, [&] { in ProcessAPINotes()
370 Info.getType(), "<API Notes>", D->getLocation()); in ProcessAPINotes()
374 S.Context.getTrivialTypeSourceInfo(Type, D->getLocation()); in ProcessAPINotes()
380 Type, D->getLocation(), TypeInfo); in ProcessAPINotes()
384 if (!checkAPINotesReplacementType(S, Var->getLocation(), Var->getType(), in ProcessAPINotes()
386 Var->setType(Type); in ProcessAPINotes()
387 Var->setTypeSourceInfo(TypeInfo); in ProcessAPINotes()
390 if (!checkAPINotesReplacementType(S, Property->getLocation(), in ProcessAPINotes()
391 Property->getType(), Type)) in ProcessAPINotes()
392 Property->setType(Type, TypeInfo); in ProcessAPINotes()
436 /// Process API notes for an Objective-C property.
477 unsigned NumParams = FD ? FD->getNumParams() : MD->param_size(); in ProcessAPINotes()
481 ParmVarDecl *Param = FD ? FD->getParamDecl(I) : MD->param_begin()[I]; in ProcessAPINotes()
482 QualType ParamTypeBefore = Param->getType(); in ProcessAPINotes()
491 if (ParamTypeBefore.getAsOpaquePtr() != Param->getType().getAsOpaquePtr()) in ProcessAPINotes()
500 Info.ResultType, "<API Notes>", D->getLocation()); in ProcessAPINotes()
505 if (!checkAPINotesReplacementType(S, D->getLocation(), in ProcessAPINotes()
506 MD->getReturnType(), ResultType)) { in ProcessAPINotes()
508 S.Context.getTrivialTypeSourceInfo(ResultType, D->getLocation()); in ProcessAPINotes()
509 MD->setReturnType(ResultType); in ProcessAPINotes()
510 MD->setReturnTypeSourceInfo(ResultTypeInfo); in ProcessAPINotes()
513 S, FD->getLocation(), FD->getReturnType(), ResultType)) { in ProcessAPINotes()
523 if (const auto *fnProtoType = FD->getType()->getAs<FunctionProtoType>()) { in ProcessAPINotes()
525 OverriddenResultType = fnProtoType->getReturnType(); in ProcessAPINotes()
528 for (auto Param : FD->parameters()) in ProcessAPINotes()
529 ParamTypes.push_back(Param->getType()); in ProcessAPINotes()
531 FD->setType(S.Context.getFunctionType(OverriddenResultType, ParamTypes, in ProcessAPINotes()
532 fnProtoType->getExtProtoInfo())); in ProcessAPINotes()
534 const auto *FnNoProtoType = FD->getType()->castAs<FunctionNoProtoType>(); in ProcessAPINotes()
535 FD->setType(S.Context.getFunctionNoProtoType( in ProcessAPINotes()
536 OverriddenResultType, FnNoProtoType->getExtInfo())); in ProcessAPINotes()
574 /// Process API notes for an Objective-C method.
582 if (ObjCInterfaceDecl *IFace = D->getClassInterface()) in ProcessAPINotes()
583 IFace->setHasDesignatedInitializers(); in ProcessAPINotes()
599 D->addAttr(SwiftAttrAttr::Create(S.Context, "import_" + ImportAs.value())); in ProcessAPINotes()
602 D->addAttr(SwiftAttrAttr::Create(S.Context, "retain:" + RetainOp.value())); in ProcessAPINotes()
605 D->addAttr( in ProcessAPINotes()
610 D->addAttr(SwiftAttrAttr::Create(S.Context, "~Copyable")); in ProcessAPINotes()
682 /// Process API notes for an Objective-C class or protocol.
691 /// Process API notes for an Objective-C class.
711 // Handle information common to Objective-C classes and protocols. in ProcessAPINotes()
716 /// If we're applying API notes with an active, non-default version, and the
728 if (D->hasAttr<SwiftNameAttr>()) in maybeAttachUnversionedSwiftName()
754 S, D, /*add*/ false, DummyFutureMetadata, []() -> SwiftNameAttr * { in maybeAttachUnversionedSwiftName()
793 [&](DeclContext *DC) -> std::optional<api_notes::Context> { in ProcessAPINotes()
796 APINotes.findAPINotes(NamespaceContext->getLocation())) { in ProcessAPINotes()
802 dyn_cast<NamespaceDecl>(CurrentNamespace->getParent())) { in ProcessAPINotes()
803 if (!CurrentNamespace->isInlineNamespace()) in ProcessAPINotes()
811 NamespaceID = Reader->lookupNamespaceID(CurrentNamespace->getName(), in ProcessAPINotes()
825 if (D->getDeclContext()->isFileContext() || in ProcessAPINotes()
826 D->getDeclContext()->isNamespace() || in ProcessAPINotes()
827 D->getDeclContext()->isExternCContext() || in ProcessAPINotes()
828 D->getDeclContext()->isExternCXXContext()) { in ProcessAPINotes()
830 GetNamespaceContext(D->getDeclContext()); in ProcessAPINotes()
833 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
835 Reader->lookupGlobalVariable(VD->getName(), APINotesContext); in ProcessAPINotes()
844 if (FD->getDeclName().isIdentifier()) { in ProcessAPINotes()
845 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
847 Reader->lookupGlobalFunction(FD->getName(), APINotesContext); in ProcessAPINotes()
855 // Objective-C classes. in ProcessAPINotes()
857 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
858 auto Info = Reader->lookupObjCClassInfo(Class->getName()); in ProcessAPINotes()
865 // Objective-C protocols. in ProcessAPINotes()
867 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
868 auto Info = Reader->lookupObjCProtocolInfo(Protocol->getName()); in ProcessAPINotes()
877 std::string LookupName = Tag->getName().str(); in ProcessAPINotes()
883 // NS/CF_OPTIONS when C++-Interop is enabled. in ProcessAPINotes()
885 LookupName.empty() && Tag->getOuterLocStart().isMacroID() in ProcessAPINotes()
887 Tag->getOuterLocStart(), in ProcessAPINotes()
888 Tag->getASTContext().getSourceManager(), LangOpts) in ProcessAPINotes()
896 clang::QualType T = llvm::cast<clang::EnumDecl>(Tag)->getIntegerType(); in ProcessAPINotes()
901 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
902 auto Info = Reader->lookupTag(LookupName, APINotesContext); in ProcessAPINotes()
911 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
912 auto Info = Reader->lookupTypedef(Typedef->getName(), APINotesContext); in ProcessAPINotes()
921 if (D->getDeclContext()->getRedeclContext()->isFileContext() || in ProcessAPINotes()
922 D->getDeclContext()->getRedeclContext()->isExternCContext()) { in ProcessAPINotes()
924 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
925 auto Info = Reader->lookupEnumConstant(EnumConstant->getName()); in ProcessAPINotes()
933 if (auto ObjCContainer = dyn_cast<ObjCContainerDecl>(D->getDeclContext())) { in ProcessAPINotes()
934 // Location function that looks up an Objective-C context. in ProcessAPINotes()
936 -> std::optional<api_notes::ContextID> { in ProcessAPINotes()
938 if (auto Found = Reader->lookupObjCProtocolID(Protocol->getName())) in ProcessAPINotes()
945 if (auto Cat = Impl->getCategoryDecl()) in ProcessAPINotes()
946 ObjCContainer = Cat->getClassInterface(); in ProcessAPINotes()
952 if (Category->getClassInterface()) in ProcessAPINotes()
953 ObjCContainer = Category->getClassInterface(); in ProcessAPINotes()
959 if (Impl->getClassInterface()) in ProcessAPINotes()
960 ObjCContainer = Impl->getClassInterface(); in ProcessAPINotes()
966 if (auto Found = Reader->lookupObjCClassID(Class->getName())) in ProcessAPINotes()
975 // Objective-C methods. in ProcessAPINotes()
977 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
980 Selector Sel = Method->getSelector(); in ProcessAPINotes()
993 auto Info = Reader->lookupObjCMethod(*Context, SelectorRef, in ProcessAPINotes()
994 Method->isInstanceMethod()); in ProcessAPINotes()
1000 // Objective-C properties. in ProcessAPINotes()
1002 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
1005 (Property->getPropertyAttributesAsWritten() & in ProcessAPINotes()
1007 auto Info = Reader->lookupObjCProperty(*Context, Property->getName(), in ProcessAPINotes()
1017 if (auto CXXRecord = dyn_cast<CXXRecordDecl>(D->getDeclContext())) { in ProcessAPINotes()
1019 -> std::optional<api_notes::ContextID> { in ProcessAPINotes()
1020 auto ParentContext = GetNamespaceContext(CXXRecord->getDeclContext()); in ProcessAPINotes()
1021 if (auto Found = Reader->lookupTagID(CXXRecord->getName(), ParentContext)) in ProcessAPINotes()
1028 for (auto Reader : APINotes.findAPINotes(D->getLocation())) { in ProcessAPINotes()
1030 auto Info = Reader->lookupCXXMethod(*Context, CXXMethod->getName()); in ProcessAPINotes()