clang 22.0.0git
SemaAPINotes.cpp File Reference
#include "CheckExprLifetime.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/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.

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 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)
 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)
 Processes all versions of versioned API notes.
static std::optional< api_notes::ContextUnwindNamespaceContext (DeclContext *DC, api_notes::APINotesManager &APINotes)
static std::optional< api_notes::ContextUnwindTagContext (TagDecl *DC, api_notes::APINotesManager &APINotes)

Macro Definition Documentation

◆ ATTR

#define ATTR ( X)
Value:
template <> struct AttrKindFor<X##Attr> { \
static const attr::Kind value = attr::X; \
};
#define X(type, name)
Definition Value.h:97
Attr - This represents one attribute.
Definition Attr.h:44

Definition at line 129 of file SemaAPINotes.cpp.

Function Documentation

◆ applyAPINotesType()

void applyAPINotesType ( Sema & S,
Decl * decl,
StringRef typeString,
VersionedInfoMetadata metadata )
static

◆ applyNullability()

void applyNullability ( Sema & S,
Decl * decl,
NullabilityKind nullability,
VersionedInfoMetadata metadata )
static

◆ ASTAllocateString()

StringRef ASTAllocateString ( ASTContext & Ctx,
StringRef String )
static

Copy a string into ASTContext-allocated memory.

Definition at line 112 of file SemaAPINotes.cpp.

References clang::ASTContext::Allocate(), and memcpy().

Referenced by ProcessAPINotes().

◆ checkAPINotesReplacementType()

bool checkAPINotesReplacementType ( Sema & S,
SourceLocation Loc,
QualType OrigType,
QualType ReplacementType )
static

Check that the replacement type provided by API notes is reasonable.

This is a very weak form of ABI check.

Definition at line 374 of file SemaAPINotes.cpp.

References clang::Sema::Context, clang::SemaBase::Diag(), and clang::ASTContext::getTypeSize().

Referenced by clang::Sema::ApplyAPINotesType(), and ProcessAPINotes().

◆ getPlaceholderAttrInfo()

◆ handleAPINotedRetainCountAttribute()

template<typename A>
void handleAPINotedRetainCountAttribute ( Sema & S,
Decl * D,
bool ShouldAddAttribute,
VersionedInfoMetadata Metadata )
static

◆ handleAPINotedRetainCountConvention()

◆ isIndirectPointerType()

bool isIndirectPointerType ( QualType Type)
static

◆ maybeAttachUnversionedSwiftName()

template<typename SpecificInfo>
void maybeAttachUnversionedSwiftName ( Sema & S,
Decl * D,
const api_notes::APINotesReader::VersionedInfo< SpecificInfo > Info )
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 854 of file SemaAPINotes.cpp.

References clang::api_notes::APINotesReader::VersionedInfo< T >::getSelected(), and clang::Decl::hasAttr().

Referenced by ProcessVersionedAPINotes().

◆ ProcessAPINotes() [1/16]

◆ ProcessAPINotes() [2/16]

◆ ProcessAPINotes() [3/16]

◆ ProcessAPINotes() [4/16]

void ProcessAPINotes ( Sema & S,
Decl * D,
const api_notes::VariableInfo & Info,
VersionedInfoMetadata Metadata )
static

◆ ProcessAPINotes() [5/16]

void ProcessAPINotes ( Sema & S,
EnumConstantDecl * D,
const api_notes::EnumConstantInfo & Info,
VersionedInfoMetadata Metadata )
static

Process API notes for an enumerator.

Definition at line 684 of file SemaAPINotes.cpp.

References ProcessAPINotes().

◆ ProcessAPINotes() [6/16]

void ProcessAPINotes ( Sema & S,
FieldDecl * D,
const api_notes::FieldInfo & Info,
VersionedInfoMetadata metadata )
static

Process API notes for a C field.

Definition at line 526 of file SemaAPINotes.cpp.

References ProcessAPINotes().

◆ ProcessAPINotes() [7/16]

void ProcessAPINotes ( Sema & S,
FunctionDecl * D,
const api_notes::GlobalFunctionInfo & Info,
VersionedInfoMetadata Metadata )
static

Process API notes for a global function.

Definition at line 675 of file SemaAPINotes.cpp.

References ProcessAPINotes().

◆ ProcessAPINotes() [8/16]

void ProcessAPINotes ( Sema & S,
FunctionOrMethod AnyFunc,
const api_notes::FunctionInfo & Info,
VersionedInfoMetadata Metadata )
static

◆ ProcessAPINotes() [9/16]

void ProcessAPINotes ( Sema & S,
ObjCContainerDecl * D,
const api_notes::ContextInfo & Info,
VersionedInfoMetadata Metadata )
static

Process API notes for an Objective-C class or protocol.

Definition at line 812 of file SemaAPINotes.cpp.

References ProcessAPINotes().

◆ ProcessAPINotes() [10/16]

void ProcessAPINotes ( Sema & S,
ObjCInterfaceDecl * D,
const api_notes::ContextInfo & Info,
VersionedInfoMetadata Metadata )
static

◆ ProcessAPINotes() [11/16]

void ProcessAPINotes ( Sema & S,
ObjCMethodDecl * D,
const api_notes::ObjCMethodInfo & Info,
VersionedInfoMetadata Metadata )
static

◆ ProcessAPINotes() [12/16]

void ProcessAPINotes ( Sema & S,
ObjCPropertyDecl * D,
const api_notes::ObjCPropertyInfo & Info,
VersionedInfoMetadata Metadata )
static

Process API notes for an Objective-C property.

Definition at line 535 of file SemaAPINotes.cpp.

References clang::Sema::Context, getPlaceholderAttrInfo(), clang::api_notes::ObjCPropertyInfo::getSwiftImportAsAccessors(), and ProcessAPINotes().

◆ ProcessAPINotes() [13/16]

◆ ProcessAPINotes() [14/16]

◆ ProcessAPINotes() [15/16]

void ProcessAPINotes ( Sema & S,
TypedefNameDecl * D,
const api_notes::TypedefInfo & Info,
VersionedInfoMetadata Metadata )
static

◆ ProcessAPINotes() [16/16]

void ProcessAPINotes ( Sema & S,
VarDecl * D,
const api_notes::GlobalVariableInfo & Info,
VersionedInfoMetadata metadata )
static

Process API notes for a global variable.

Definition at line 517 of file SemaAPINotes.cpp.

References ProcessAPINotes().

◆ ProcessVersionedAPINotes()

template<typename SpecificDecl, typename SpecificInfo>
void ProcessVersionedAPINotes ( Sema & S,
SpecificDecl * D,
const api_notes::APINotesReader::VersionedInfo< SpecificInfo > Info )
static

Processes all versions of versioned API notes.

Just dispatches to the various ProcessAPINotes functions in this file.

Definition at line 892 of file SemaAPINotes.cpp.

References clang::Sema::captureSwiftVersionIndependentAPINotes(), clang::api_notes::APINotesReader::VersionedInfo< T >::getSelected(), maybeAttachUnversionedSwiftName(), ProcessAPINotes(), and clang::api_notes::APINotesReader::VersionedInfo< T >::size().

Referenced by clang::Sema::ProcessAPINotes().

◆ UnwindNamespaceContext()

std::optional< api_notes::Context > UnwindNamespaceContext ( DeclContext * DC,
api_notes::APINotesManager & APINotes )
static

◆ UnwindTagContext()