|
clang 24.0.0git
|
#include "SemaAPINotesInternal.h"#include "TypeLocBuilder.h"#include "clang/APINotes/APINotesReader.h"#include "clang/APINotes/Types.h"#include "clang/AST/Decl.h"#include "clang/AST/DeclCXX.h"#include "clang/AST/DeclObjC.h"#include "clang/AST/TypeLoc.h"#include "clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h"#include "clang/Basic/SourceLocation.h"#include "clang/Lex/Lexer.h"#include "clang/Sema/SemaObjC.h"#include "clang/Sema/SemaSwift.h"#include <stack>#include "clang/Basic/AttrList.inc"Go to the source code of this file.
Classes | |
| struct | clang::APINotesParameterSelector |
| struct | clang::APINotesParameterSelectorCandidates |
Namespaces | |
| namespace | clang |
| Top level wrappers for InstallAPI frontend operations. | |
Macros | |
| #define | ATTR(X) |
Functions | |
| static bool | isIndirectPointerType (QualType Type) |
| Determine whether this is a multi-level pointer type. | |
| static void | applyAPINotesType (Sema &S, Decl *decl, StringRef typeString, VersionedInfoMetadata metadata) |
| static void | applyNullability (Sema &S, Decl *decl, NullabilityKind nullability, VersionedInfoMetadata metadata) |
| Apply nullability to the given declaration. | |
| static StringRef | ASTAllocateString (ASTContext &Ctx, StringRef String) |
| Copy a string into ASTContext-allocated memory. | |
| static AttributeCommonInfo | getPlaceholderAttrInfo () |
| template<typename A> | |
| static void | handleAPINotedRetainCountAttribute (Sema &S, Decl *D, bool ShouldAddAttribute, VersionedInfoMetadata Metadata) |
| static void | handleAPINotedRetainCountConvention (Sema &S, Decl *D, VersionedInfoMetadata Metadata, std::optional< api_notes::RetainCountConventionKind > Convention) |
| static void | addSwiftAttrIfAbsent (Sema &S, Decl *D, StringRef Attribute) |
Add a 'swift_attr' unless D already carries that exact annotation. | |
| static void | ProcessAPINotes (Sema &S, Decl *D, const api_notes::CommonEntityInfo &Info, VersionedInfoMetadata Metadata) |
| static void | ProcessAPINotes (Sema &S, Decl *D, const api_notes::CommonTypeInfo &Info, VersionedInfoMetadata Metadata) |
| static bool | checkAPINotesReplacementType (Sema &S, SourceLocation Loc, QualType OrigType, QualType ReplacementType) |
| Check that the replacement type provided by API notes is reasonable. | |
| static void | ProcessAPINotes (Sema &S, Decl *D, const api_notes::VariableInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for a variable or property. | |
| static void | ProcessAPINotes (Sema &S, ParmVarDecl *D, const api_notes::ParamInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for a parameter. | |
| static void | ProcessAPINotes (Sema &S, VarDecl *D, const api_notes::GlobalVariableInfo &Info, VersionedInfoMetadata metadata) |
| Process API notes for a global variable. | |
| static void | ProcessAPINotes (Sema &S, FieldDecl *D, const api_notes::FieldInfo &Info, VersionedInfoMetadata metadata) |
| Process API notes for a C field. | |
| static void | ProcessAPINotes (Sema &S, ObjCPropertyDecl *D, const api_notes::ObjCPropertyInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for an Objective-C property. | |
| static void | ProcessAPINotes (Sema &S, FunctionOrMethod AnyFunc, const api_notes::FunctionInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for a function or method. | |
| static void | ProcessAPINotes (Sema &S, CXXMethodDecl *Method, const api_notes::CXXMethodInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for a C++ method. | |
| static void | ProcessAPINotes (Sema &S, FunctionDecl *D, const api_notes::GlobalFunctionInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for a global function. | |
| static void | ProcessAPINotes (Sema &S, EnumConstantDecl *D, const api_notes::EnumConstantInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for an enumerator. | |
| static void | ProcessAPINotes (Sema &S, ObjCMethodDecl *D, const api_notes::ObjCMethodInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for an Objective-C method. | |
| static void | ProcessAPINotes (Sema &S, TagDecl *D, const api_notes::TagInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for a tag. | |
| static void | ProcessAPINotes (Sema &S, TypedefNameDecl *D, const api_notes::TypedefInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for a typedef. | |
| static void | ProcessAPINotes (Sema &S, ObjCContainerDecl *D, const api_notes::ContextInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for an Objective-C class or protocol. | |
| static void | ProcessAPINotes (Sema &S, ObjCInterfaceDecl *D, const api_notes::ContextInfo &Info, VersionedInfoMetadata Metadata) |
| Process API notes for an Objective-C class. | |
| template<typename SpecificInfo> | |
| static void | maybeAttachUnversionedSwiftName (Sema &S, Decl *D, const api_notes::APINotesReader::VersionedInfo< SpecificInfo > Info, unsigned SliceGroup) |
If we're applying API notes with an active, non-default version, and the versioned API notes have a SwiftName but the declaration normally wouldn't have one, add a removal attribute to make it clear that the new SwiftName attribute only applies to the active version of D, not to all versions. | |
| template<typename SpecificDecl, typename SpecificInfo> | |
| static void | ProcessVersionedAPINotes (Sema &S, SpecificDecl *D, const api_notes::APINotesReader::VersionedInfo< SpecificInfo > Info, unsigned SliceGroup) |
| Processes all versions of versioned API notes. | |
| static std::optional< api_notes::Context > | UnwindNamespaceContext (DeclContext *DC, api_notes::APINotesManager &APINotes) |
| static std::optional< api_notes::Context > | UnwindTagContext (TagDecl *DC, api_notes::APINotesManager &APINotes) |
| static PrintingPolicy | getAPINotesParameterSelectorPrintingPolicy (const ASTContext &Context) |
| static std::string | getAPINotesParameterSelectorSpelling (QualType ParamType, const ASTContext &Context, const PrintingPolicy &Policy, bool Desugar) |
| static std::optional< APINotesParameterSelectorCandidates > | getAPINotesParameterSelectorCandidates (const Sema &S, const FunctionDecl *FD) |
| static APINotesSelectorDiagnosticReaderState & | getAPINotesSelectorDiagnosticState (Sema &S, api_notes::APINotesReader *Reader) |
| template<typename SpecificInfo, typename SpecificDecl> | |
| static void | processExactAPINotes (Sema &S, SpecificDecl *D, const APINotesParameterSelectorCandidates &ParameterSelectorCandidates, llvm::function_ref< api_notes::APINotesReader::VersionedInfo< SpecificInfo >(ArrayRef< std::string >)> LookupExact, unsigned SliceGroup) |
| Apply the first exact selector entry found. | |
| #define ATTR | ( | X | ) |
Definition at line 136 of file SemaAPINotes.cpp.
Add a 'swift_attr' unless D already carries that exact annotation.
Definition at line 258 of file SemaAPINotes.cpp.
References clang::Decl::addAttr(), clang::Sema::Context, and clang::Decl::specific_attrs().
Referenced by ProcessAPINotes(), ProcessAPINotes(), and ProcessAPINotes().
|
static |
Definition at line 61 of file SemaAPINotes.cpp.
References clang::Sema::ApplyAPINotesType(), clang::Sema::captureSwiftVersionIndependentAPINotes(), clang::Sema::Context, and clang::ast_matchers::decl.
Referenced by ProcessAPINotes().
|
static |
Apply nullability to the given declaration.
Definition at line 83 of file SemaAPINotes.cpp.
References clang::Sema::ApplyNullability(), clang::Sema::captureSwiftVersionIndependentAPINotes(), clang::Sema::Context, clang::ast_matchers::decl, clang::NonNull, clang::Nullable, clang::NullableResult, and clang::Unspecified.
Referenced by ProcessAPINotes(), and ProcessAPINotes().
|
static |
Copy a string into ASTContext-allocated memory.
Definition at line 119 of file SemaAPINotes.cpp.
References clang::ASTContext::Allocate(), and memcpy().
Referenced by ProcessAPINotes().
|
static |
Check that the replacement type provided by API notes is reasonable.
This is a very weak form of ABI check.
Definition at line 390 of file SemaAPINotes.cpp.
References clang::Sema::Context, clang::SemaBase::Diag(), and clang::ASTContext::getTypeSize().
Referenced by clang::Sema::ApplyAPINotesType(), and ProcessAPINotes().
|
static |
Definition at line 1071 of file SemaAPINotes.cpp.
References clang::Sema::Context, clang::APINotesParameterSelectorCandidates::Desugared, getAPINotesParameterSelectorPrintingPolicy(), getAPINotesParameterSelectorSpelling(), clang::Type::getAs(), clang::ValueDecl::getType(), clang::APINotesParameterSelector::Parameters, and clang::APINotesParameterSelectorCandidates::Source.
Referenced by clang::Sema::ProcessAPINotes().
|
static |
Definition at line 1042 of file SemaAPINotes.cpp.
References clang::PrintingPolicy::IncludeNewlines, clang::PrintingPolicy::SplitTemplateClosers, and clang::PrintingPolicy::SuppressScope.
Referenced by getAPINotesParameterSelectorCandidates().
|
static |
Definition at line 1057 of file SemaAPINotes.cpp.
References clang::QualType::getAsString(), clang::QualType::getDesugaredType(), clang::QualType::removeLocalConst(), clang::QualType::removeLocalVolatile(), and clang::QualType::stripNullability().
Referenced by getAPINotesParameterSelectorCandidates().
|
static |
Definition at line 1112 of file SemaAPINotes.cpp.
References clang::Sema::APINotesSelectorDiagnostics.
Referenced by clang::Sema::ProcessAPINotes().
|
static |
Definition at line 125 of file SemaAPINotes.cpp.
References clang::AttributeCommonInfo::AS_GNU, and clang::AttributeCommonInfo::UnknownAttribute.
Referenced by handleAPINotedRetainCountAttribute(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), and ProcessAPINotes().
|
static |
Definition at line 204 of file SemaAPINotes.cpp.
References clang::Decl::attrs(), clang::Sema::Context, getPlaceholderAttrInfo(), and Next.
Referenced by handleAPINotedRetainCountConvention().
|
static |
Definition at line 223 of file SemaAPINotes.cpp.
References clang::api_notes::CFReturnsNotRetained, clang::api_notes::CFReturnsRetained, handleAPINotedRetainCountAttribute(), clang::isa(), clang::api_notes::None, clang::api_notes::NSReturnsNotRetained, and clang::api_notes::NSReturnsRetained.
Referenced by ProcessAPINotes(), and ProcessAPINotes().
Determine whether this is a multi-level pointer type.
Definition at line 52 of file SemaAPINotes.cpp.
References clang::Type::getPointeeType(), clang::Type::isAnyPointerType(), clang::Type::isMemberPointerType(), clang::QualType::isNull(), and clang::Type::isObjCObjectPointerType().
Referenced by clang::Sema::ApplyNullability().
|
static |
If we're applying API notes with an active, non-default version, and the versioned API notes have a SwiftName but the declaration normally wouldn't have one, add a removal attribute to make it clear that the new SwiftName attribute only applies to the active version of D, not to all versions.
This must be run before processing API notes for D, because otherwise any existing SwiftName attribute will have been packaged up in a SwiftVersionedAdditionAttr.
Definition at line 880 of file SemaAPINotes.cpp.
References clang::api_notes::APINotesReader::VersionedInfo< T >::getSelected(), and clang::Decl::hasAttr().
Referenced by ProcessVersionedAPINotes().
|
static |
Process API notes for a C++ method.
Definition at line 682 of file SemaAPINotes.cpp.
References clang::Sema::Context, clang::ASTContext::getAttributedType(), getPlaceholderAttrInfo(), clang::TypeLocBuilder::getTypeSourceInfo(), clang::lifetimes::implicitObjectParamIsLifetimeBound(), ProcessAPINotes(), clang::TypeLocBuilder::push(), clang::TypeLocBuilder::pushFullCopy(), clang::AttributedTypeLoc::setAttr(), and clang::api_notes::CXXMethodInfo::This.
|
static |
Definition at line 266 of file SemaAPINotes.cpp.
References clang::Addition, clang::Sema::AP_Explicit, ASTAllocateString(), clang::Decl::attrs(), clang::Sema::Context, clang::IdentifierTable::get(), getPlaceholderAttrInfo(), clang::api_notes::CommonEntityInfo::getSwiftSafety(), clang::ASTContext::Idents, clang::api_notes::CommonEntityInfo::isSwiftPrivate(), clang::api_notes::Safe, clang::api_notes::CommonEntityInfo::Unavailable, clang::api_notes::CommonEntityInfo::UnavailableInSwift, clang::api_notes::CommonEntityInfo::UnavailableMsg, and clang::api_notes::Unspecified.
Referenced by clang::Sema::ActOnAliasDeclaration(), clang::Sema::ActOnStartNamespaceDef(), clang::Sema::ActOnUsingDirective(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), ProcessAPINotes(), and ProcessVersionedAPINotes().
|
static |
Definition at line 357 of file SemaAPINotes.cpp.
References addSwiftAttrIfAbsent(), clang::api_notes::CommonTypeInfo::getNSErrorDomain(), clang::api_notes::CommonTypeInfo::getSwiftBridge(), clang::api_notes::CommonTypeInfo::getSwiftConformance(), and ProcessAPINotes().
|
static |
Process API notes for a variable or property.
Definition at line 497 of file SemaAPINotes.cpp.
References applyAPINotesType(), applyNullability(), clang::api_notes::VariableInfo::getNullability(), clang::api_notes::VariableInfo::getType(), and ProcessAPINotes().
|
static |
Process API notes for an enumerator.
Definition at line 713 of file SemaAPINotes.cpp.
References ProcessAPINotes().
|
static |
Process API notes for a C field.
Definition at line 548 of file SemaAPINotes.cpp.
References ProcessAPINotes().
|
static |
Process API notes for a global function.
Definition at line 704 of file SemaAPINotes.cpp.
References ProcessAPINotes().
|
static |
Process API notes for a function or method.
Definition at line 578 of file SemaAPINotes.cpp.
References addSwiftAttrIfAbsent(), applyNullability(), clang::cast(), clang::Type::castAs(), checkAPINotesReplacementType(), clang::Sema::Context, clang::Type::getAs(), clang::QualType::getAsOpaquePtr(), clang::Sema::getASTContext(), clang::Decl::getAttr(), clang::ASTContext::getFunctionNoProtoType(), clang::ASTContext::getFunctionType(), clang::Decl::getLocation(), clang::FunctionDecl::getNumParams(), clang::FunctionDecl::getParamDecl(), clang::api_notes::FunctionInfo::getParamTypeInfo(), getPlaceholderAttrInfo(), clang::api_notes::FunctionInfo::getRetainCountConvention(), clang::FunctionDecl::getReturnType(), clang::ObjCMethodDecl::getReturnType(), clang::api_notes::FunctionInfo::getReturnTypeInfo(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::ValueDecl::getType(), clang::Sema::GetTypeFromParser(), handleAPINotedRetainCountConvention(), clang::QualType::isNull(), clang::api_notes::FunctionInfo::NullabilityAudited, clang::ObjCMethodDecl::param_begin(), clang::ObjCMethodDecl::param_size(), clang::FunctionDecl::parameters(), clang::api_notes::FunctionInfo::Params, clang::Sema::ParseTypeFromStringCallback, ProcessAPINotes(), clang::api_notes::FunctionInfo::ResultType, clang::ObjCMethodDecl::setReturnType(), clang::ObjCMethodDecl::setReturnTypeSourceInfo(), clang::ValueDecl::setType(), clang::api_notes::FunctionInfo::SwiftReturnOwnership, and clang::api_notes::FunctionInfo::UnsafeBufferUsage.
|
static |
Process API notes for an Objective-C class or protocol.
Definition at line 838 of file SemaAPINotes.cpp.
References ProcessAPINotes().
|
static |
Process API notes for an Objective-C class.
Definition at line 847 of file SemaAPINotes.cpp.
References clang::Sema::Context, getPlaceholderAttrInfo(), clang::api_notes::ContextInfo::getSwiftImportAsNonGeneric(), clang::api_notes::ContextInfo::getSwiftObjCMembers(), and ProcessAPINotes().
|
static |
Process API notes for an Objective-C method.
Definition at line 722 of file SemaAPINotes.cpp.
References clang::Sema::Context, clang::api_notes::ObjCMethodInfo::DesignatedInit, clang::ObjCMethodDecl::getClassInterface(), getPlaceholderAttrInfo(), and ProcessAPINotes().
|
static |
Process API notes for an Objective-C property.
Definition at line 557 of file SemaAPINotes.cpp.
References clang::Sema::Context, getPlaceholderAttrInfo(), clang::api_notes::ObjCPropertyInfo::getSwiftImportAsAccessors(), and ProcessAPINotes().
|
static |
Process API notes for a parameter.
Definition at line 513 of file SemaAPINotes.cpp.
References clang::Sema::Context, getPlaceholderAttrInfo(), clang::api_notes::ParamInfo::getRetainCountConvention(), handleAPINotedRetainCountConvention(), clang::api_notes::ParamInfo::isLifetimebound(), clang::api_notes::ParamInfo::isNoEscape(), and ProcessAPINotes().
|
static |
Process API notes for a tag.
Definition at line 743 of file SemaAPINotes.cpp.
References addSwiftAttrIfAbsent(), clang::Sema::Context, clang::api_notes::TagInfo::EnumExtensibility, getPlaceholderAttrInfo(), clang::api_notes::TagInfo::isFlagEnum(), clang::api_notes::TagInfo::isSwiftCopyable(), clang::api_notes::TagInfo::isSwiftEscapable(), kind, ProcessAPINotes(), clang::api_notes::TagInfo::SwiftDefaultOwnership, clang::api_notes::TagInfo::SwiftDestroyOp, clang::api_notes::TagInfo::SwiftImportAs, clang::api_notes::TagInfo::SwiftReleaseOp, and clang::api_notes::TagInfo::SwiftRetainOp.
|
static |
Process API notes for a typedef.
Definition at line 801 of file SemaAPINotes.cpp.
References clang::AttributeCommonInfo::AS_GNU, clang::Sema::Context, ProcessAPINotes(), and clang::api_notes::TypedefInfo::SwiftWrapper.
|
static |
Process API notes for a global variable.
Definition at line 539 of file SemaAPINotes.cpp.
References ProcessAPINotes().
|
static |
Apply the first exact selector entry found.
This preserves source-spelling precedence over the desugared fallback and avoids applying multiple exact entries for the same declaration.
| SliceGroup | Which group the slices from LookupExact form. This lookup runs its own version selection, so it is a group distinct from the broad lookup beside it even though both read the same reader. |
Definition at line 1141 of file SemaAPINotes.cpp.
References clang::APINotesParameterSelectorCandidates::Desugared, ProcessVersionedAPINotes(), and clang::APINotesParameterSelectorCandidates::Source.
Referenced by clang::Sema::ProcessAPINotes().
|
static |
Processes all versions of versioned API notes.
Just dispatches to the various ProcessAPINotes functions in this file.
| SliceGroup | Which group the slices in Info form. Selection runs independently per group, so this has to travel with every slice. |
Definition at line 923 of file SemaAPINotes.cpp.
References clang::Sema::captureSwiftVersionIndependentAPINotes(), clang::Sema::Context, clang::api_notes::APINotesReader::VersionedInfo< T >::getSelected(), maybeAttachUnversionedSwiftName(), ProcessAPINotes(), and clang::api_notes::APINotesReader::VersionedInfo< T >::size().
Referenced by clang::Sema::ProcessAPINotes(), and processExactAPINotes().
|
static |
Definition at line 965 of file SemaAPINotes.cpp.
References clang::api_notes::APINotesManager::findAPINotes(), and clang::api_notes::Namespace.
Referenced by clang::Sema::ProcessAPINotes(), and UnwindTagContext().
|
static |
Definition at line 996 of file SemaAPINotes.cpp.
References clang::api_notes::APINotesManager::findAPINotes(), clang::Decl::getLocation(), clang::api_notes::Tag, and UnwindNamespaceContext().
Referenced by clang::Sema::ProcessAPINotes().