Lines Matching +full:loc +full:- +full:code
1 //===------ SemaSwift.cpp ------ Swift language-specific routines ---------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
28 if (const auto *PrevSNA = D->getAttr<SwiftNameAttr>()) { in mergeNameAttr()
29 if (PrevSNA->getName() != Name && !PrevSNA->isImplicit()) { in mergeNameAttr()
30 Diag(PrevSNA->getLocation(), diag::err_attributes_are_not_compatible) in mergeNameAttr()
32 << (PrevSNA->isRegularKeywordAttribute() || in mergeNameAttr()
37 D->dropAttr<SwiftNameAttr>(); in mergeNameAttr()
42 /// Pointer-like types in the default address space.
44 if (!Ty->hasPointerRepresentation()) in isValidSwiftContextType()
45 return Ty->isDependentType(); in isValidSwiftContextType()
46 return Ty->getPointeeType().getAddressSpace() == LangAS::Default; in isValidSwiftContextType()
51 if (const auto *PtrType = Ty->getAs<PointerType>()) { in isValidSwiftIndirectResultType()
52 Ty = PtrType->getPointeeType(); in isValidSwiftIndirectResultType()
53 } else if (const auto *RefType = Ty->getAs<ReferenceType>()) { in isValidSwiftIndirectResultType()
54 Ty = RefType->getPointeeType(); in isValidSwiftIndirectResultType()
56 return Ty->isDependentType(); in isValidSwiftIndirectResultType()
63 if (const auto *PtrType = Ty->getAs<PointerType>()) { in isValidSwiftErrorResultType()
64 Ty = PtrType->getPointeeType(); in isValidSwiftErrorResultType()
65 } else if (const auto *RefType = Ty->getAs<ReferenceType>()) { in isValidSwiftErrorResultType()
66 Ty = RefType->getPointeeType(); in isValidSwiftErrorResultType()
68 return Ty->isDependentType(); in isValidSwiftErrorResultType()
82 D->addAttr(::new (getASTContext()) SwiftAttrAttr(getASTContext(), AL, Str)); in handleAttrAttr()
94 if (const auto *Other = D->getAttr<SwiftBridgeAttr>()) { in handleBridge()
95 if (Other->getSwiftType() != BT) in handleBridge()
100 D->addAttr(::new (getASTContext()) SwiftBridgeAttr(getASTContext(), AL, BT)); in handleBridge()
104 const auto *PT = QT->getAs<PointerType>(); in isErrorParameter()
108 QualType Pointee = PT->getPointeeType(); in isErrorParameter()
111 if (const auto *OPT = Pointee->getAs<ObjCObjectPointerType>()) in isErrorParameter()
112 if (const auto *ID = OPT->getInterfaceDecl()) in isErrorParameter()
113 if (ID->getIdentifier() == S.ObjC().getNSErrorIdent()) in isErrorParameter()
117 if (const auto *PT = Pointee->getAs<PointerType>()) in isErrorParameter()
118 if (const auto *RT = PT->getPointeeType()->getAs<RecordType>()) in isErrorParameter()
119 if (S.ObjC().isCFError(RT->getDecl())) in isErrorParameter()
126 auto hasErrorParameter = [](Sema &S, Decl *D, const ParsedAttr &AL) -> bool { in handleError()
137 auto hasPointerResult = [](Sema &S, Decl *D, const ParsedAttr &AL) -> bool { in handleError()
138 // - C, ObjC, and block pointers are definitely okay. in handleError()
139 // - References are definitely not okay. in handleError()
140 // - nullptr_t is weird, but acceptable. in handleError()
142 if (RT->hasPointerRepresentation() && !RT->isReferenceType()) in handleError()
146 << AL << AL.getArgAsIdent(0)->Ident->getName() << isa<ObjCMethodDecl>(D) in handleError()
151 auto hasIntegerResult = [](Sema &S, Decl *D, const ParsedAttr &AL) -> bool { in handleError()
153 if (RT->isIntegralType(S.Context)) in handleError()
157 << AL << AL.getArgAsIdent(0)->Ident->getName() << isa<ObjCMethodDecl>(D) in handleError()
162 if (D->isInvalidDecl()) in handleError()
165 IdentifierLoc *Loc = AL.getArgAsIdent(0); in handleError() local
167 if (!SwiftErrorAttr::ConvertStrToConventionKind(Loc->Ident->getName(), in handleError()
170 << AL << Loc->Ident; in handleError()
196 D->addAttr(::new (getASTContext()) in handleError()
203 if (AsyncAttr->getKind() == SwiftAsyncAttr::None) { in checkSwiftAsyncErrorBlock()
204 if (ErrorAttr->getConvention() != SwiftAsyncErrorAttr::None) { in checkSwiftAsyncErrorBlock()
205 S.Diag(AsyncAttr->getLocation(), in checkSwiftAsyncErrorBlock()
213 D, AsyncAttr->getCompletionHandlerIndex().getASTIndex()); in checkSwiftAsyncErrorBlock()
215 // double-check it here. in checkSwiftAsyncErrorBlock()
216 const auto *FuncTy = HandlerParam->getType() in checkSwiftAsyncErrorBlock()
217 ->castAs<BlockPointerType>() in checkSwiftAsyncErrorBlock()
218 ->getPointeeType() in checkSwiftAsyncErrorBlock()
219 ->getAs<FunctionProtoType>(); in checkSwiftAsyncErrorBlock()
222 BlockParams = FuncTy->getParamTypes(); in checkSwiftAsyncErrorBlock()
224 switch (ErrorAttr->getConvention()) { in checkSwiftAsyncErrorBlock()
227 uint32_t ParamIdx = ErrorAttr->getHandlerParamIdx(); in checkSwiftAsyncErrorBlock()
229 S.Diag(ErrorAttr->getLocation(), in checkSwiftAsyncErrorBlock()
234 QualType ErrorParam = BlockParams[ParamIdx - 1]; in checkSwiftAsyncErrorBlock()
235 if (!ErrorParam->isIntegralType(S.Context)) { in checkSwiftAsyncErrorBlock()
237 ErrorAttr->getConvention() == SwiftAsyncErrorAttr::ZeroArgument in checkSwiftAsyncErrorBlock()
240 S.Diag(ErrorAttr->getLocation(), diag::err_swift_async_error_non_integral) in checkSwiftAsyncErrorBlock()
250 if (const auto *ObjCPtrTy = Param->getAs<ObjCObjectPointerType>()) { in checkSwiftAsyncErrorBlock()
251 if (const auto *ID = ObjCPtrTy->getInterfaceDecl()) { in checkSwiftAsyncErrorBlock()
252 if (ID->getIdentifier() == S.ObjC().getNSErrorIdent()) { in checkSwiftAsyncErrorBlock()
259 if (const auto *PtrTy = Param->getAs<PointerType>()) { in checkSwiftAsyncErrorBlock()
260 if (const auto *RT = PtrTy->getPointeeType()->getAs<RecordType>()) { in checkSwiftAsyncErrorBlock()
261 if (S.ObjC().isCFError(RT->getDecl())) { in checkSwiftAsyncErrorBlock()
270 S.Diag(ErrorAttr->getLocation(), in checkSwiftAsyncErrorBlock()
285 if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind(IDLoc->Ident->getName(), in handleAsyncError()
288 << AL << IDLoc->Ident; in handleAsyncError()
314 D->addAttr(ErrorAttr); in handleAsyncError()
316 if (auto *AsyncAttr = D->getAttr<SwiftAsyncAttr>()) in handleAsyncError()
321 // <code>init(foo:bar:baz:)</code> or <code>controllerForName(_:)</code>, and
323 // single-arg initializer.
327 // <code>context.identifier</code> name.
329 SourceLocation Loc, StringRef Name, in validateSwiftFunctionName() argument
343 S.Diag(Loc, diag::warn_attr_swift_name_function) << AL; in validateSwiftFunctionName()
359 S.Diag(Loc, diag::warn_attr_swift_name_invalid_identifier) in validateSwiftFunctionName()
367 S.Diag(Loc, diag::warn_attr_swift_name_invalid_identifier) in validateSwiftFunctionName()
375 S.Diag(Loc, diag::warn_attr_swift_name_subscript_invalid_parameter) in validateSwiftFunctionName()
381 S.Diag(Loc, diag::warn_attr_swift_name_missing_parameters) << AL; in validateSwiftFunctionName()
391 S.Diag(Loc, diag::warn_attr_swift_name_subscript_invalid_parameter) in validateSwiftFunctionName()
397 S.Diag(Loc, diag::warn_attr_swift_name_setter_parameters) << AL; in validateSwiftFunctionName()
405 S.Diag(Loc, diag::warn_attr_swift_name_function) << AL; in validateSwiftFunctionName()
417 S.Diag(Loc, diag::warn_attr_swift_name_invalid_identifier) in validateSwiftFunctionName()
427 S.Diag(Loc, diag::warn_attr_swift_name_multiple_selfs) << AL; in validateSwiftFunctionName()
448 S.Diag(Loc, diag::warn_attr_swift_name_subscript_invalid_parameter) in validateSwiftFunctionName()
472 S.Diag(Loc, ParamDiag) << AL; in validateSwiftFunctionName()
480 S.Diag(Loc, diag::warn_attr_swift_name_subscript_setter_no_newValue) in validateSwiftFunctionName()
485 S.Diag(Loc, in validateSwiftFunctionName()
493 S.Diag(Loc, diag::warn_attr_swift_name_subscript_getter_newValue) in validateSwiftFunctionName()
501 S.Diag(Loc, ParamDiag) << AL; in validateSwiftFunctionName()
510 bool SemaSwift::DiagnoseName(Decl *D, StringRef Name, SourceLocation Loc, in DiagnoseName() argument
517 ParamCount = Method->getSelector().getNumArgs(); in DiagnoseName()
518 Params = Method->parameters().slice(0, ParamCount); in DiagnoseName()
522 ParamCount = F->getNumParams(); in DiagnoseName()
523 Params = F->parameters(); in DiagnoseName()
525 if (!F->hasWrittenPrototype()) { in DiagnoseName()
526 Diag(Loc, diag::warn_attribute_wrong_decl_type) in DiagnoseName()
536 Diag(Loc, diag::warn_attr_swift_name_decl_missing_params) in DiagnoseName()
540 ParamCount -= 1; in DiagnoseName()
545 if (!validateSwiftFunctionName(SemaRef, AL, Loc, Name, SwiftParamCount, in DiagnoseName()
555 // We have fewer Swift parameters than Objective-C parameters, but that in DiagnoseName()
559 llvm::count_if(Params, [](const ParmVarDecl *Param) -> bool { in DiagnoseName()
560 QualType ParamTy = Param->getType(); in DiagnoseName()
561 if (ParamTy->isReferenceType() || ParamTy->isPointerType()) in DiagnoseName()
562 return !ParamTy->getPointeeType().isConstQualified(); in DiagnoseName()
570 Diag(Loc, diag::warn_attr_swift_name_num_params) in DiagnoseName()
587 Diag(Loc, diag::warn_attr_swift_name_invalid_identifier) in DiagnoseName()
593 Diag(Loc, diag::warn_attr_swift_name_invalid_identifier) in DiagnoseName()
598 Diag(Loc, diag::warn_attr_swift_name_decl_kind) << AL; in DiagnoseName()
606 SourceLocation Loc; in handleName() local
607 if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Name, &Loc)) in handleName()
610 if (!DiagnoseName(D, Name, Loc, AL, /*IsAsync=*/false)) in handleName()
613 D->addAttr(::new (getASTContext()) SwiftNameAttr(getASTContext(), AL, Name)); in handleName()
618 SourceLocation Loc; in handleAsyncName() local
619 if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Name, &Loc)) in handleAsyncName()
622 if (!DiagnoseName(D, Name, Loc, AL, /*IsAsync=*/true)) in handleAsyncName()
625 D->addAttr(::new (getASTContext()) in handleAsyncName()
641 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; in handleNewType()
642 if (!SwiftNewTypeAttr::ConvertStrToNewtypeKind(II->getName(), Kind)) { in handleNewType()
653 D->addAttr(::new (getASTContext()) in handleNewType()
665 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; in handleAsyncAttr()
666 if (!SwiftAsyncAttr::ConvertStrToKind(II->getName(), Kind)) { in handleAsyncAttr()
677 // Non-none swift_async requires a completion handler index argument. in handleAsyncAttr()
687 QualType CompletionBlockType = CompletionBlock->getType(); in handleAsyncAttr()
688 if (!CompletionBlockType->isBlockPointerType()) { in handleAsyncAttr()
689 Diag(CompletionBlock->getLocation(), diag::err_swift_async_bad_block_type) in handleAsyncAttr()
690 << CompletionBlock->getType(); in handleAsyncAttr()
694 CompletionBlockType->castAs<BlockPointerType>()->getPointeeType(); in handleAsyncAttr()
695 if (!BlockTy->castAs<FunctionType>()->getReturnType()->isVoidType()) { in handleAsyncAttr()
696 Diag(CompletionBlock->getLocation(), diag::err_swift_async_bad_block_type) in handleAsyncAttr()
697 << CompletionBlock->getType(); in handleAsyncAttr()
704 D->addAttr(AsyncAttr); in handleAsyncAttr()
706 if (auto *ErrorAttr = D->getAttr<SwiftAsyncErrorAttr>()) in handleAsyncAttr()
713 QualType type = cast<ParmVarDecl>(D)->getType(); in AddParameterABIAttr()
715 if (auto existingAttr = D->getAttr<ParameterABIAttr>()) { in AddParameterABIAttr()
716 if (existingAttr->getABI() != abi) { in AddParameterABIAttr()
720 existingAttr->isRegularKeywordAttribute()); in AddParameterABIAttr()
721 Diag(existingAttr->getLocation(), diag::note_conflicting_attribute); in AddParameterABIAttr()
735 D->addAttr(::new (Context) SwiftContextAttr(Context, CI)); in AddParameterABIAttr()
743 D->addAttr(::new (Context) SwiftAsyncContextAttr(Context, CI)); in AddParameterABIAttr()
751 D->addAttr(::new (Context) SwiftErrorResultAttr(Context, CI)); in AddParameterABIAttr()
759 D->addAttr(::new (Context) SwiftIndirectResultAttr(Context, CI)); in AddParameterABIAttr()