Resolve merge conflicts & address review comments

This commit is contained in:
Daniil Kovalev
2025-11-10 19:16:54 +03:00
parent 72431dbd2d
commit f0bf57a269
13 changed files with 229 additions and 202 deletions

View File

@@ -29,15 +29,45 @@ public class Decl: CustomStringConvertible, Hashable {
// True if this declaration is imported from C/C++/ObjC.
public var hasClangNode: Bool { bridged.hasClangNode() }
public var declContext: DeclContext { bridgedDecl.declContext }
public var declContext: DeclContext {
if let decl = parent {
return decl as! DeclContext
}
return DeclContextObj(bridged: bridged.getDeclContext())
}
var bridgedDecl: BridgedDecl { BridgedDecl(raw: bridged.obj) }
public var bridgedDecl: BridgedDecl { BridgedDecl(raw: bridged.obj) }
public static func ==(lhs: Decl, rhs: Decl) -> Bool { lhs === rhs }
public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
}
public func setImplicit() { bridged.setImplicit() }
}
public protocol DeclContext {
var bridgedDeclContext: BridgedDeclContext { get }
}
extension DeclContext {
public var astContext: ASTContext { bridgedDeclContext.astContext }
}
fileprivate class DeclContextObj : DeclContext {
public var bridgedDeclContext: BridgedDeclContext
public init(bridged: BridgedDeclContext) { bridgedDeclContext = bridged }
}
public protocol GenericContext: Decl, DeclContext {}
extension GenericContext {
public func setGenericSignature(_ genericSignature: GenericSignature) {
bridged.GenericContext_setGenericSignature(genericSignature.bridged)
}
public var bridgedDeclContext: BridgedDeclContext { bridged.asGenericContext() }
}
public class ValueDecl: Decl {
@@ -45,13 +75,16 @@ public class ValueDecl: Decl {
final public var userFacingName: StringRef { StringRef(bridged: bridged.Value_getUserFacingName()) }
final public var baseIdentifier: Identifier { bridged.Value_getBaseIdentifier() }
final public var isObjC: Bool { bridged.Value_isObjC() }
final public func setAccess(_ accessLevel : AccessLevel) {
bridged.ValueDecl_setAccess(accessLevel)
}
}
public class TypeDecl: ValueDecl {
final public var name: StringRef { StringRef(bridged: bridged.Type_getName()) }
}
public class GenericTypeDecl: TypeDecl {
public class GenericTypeDecl: TypeDecl, GenericContext {
final public var isGenericAtAnyLevel: Bool { bridged.GenericType_isGenericAtAnyLevel() }
}
@@ -65,10 +98,34 @@ public class NominalTypeDecl: GenericTypeDecl {
public var declaredInterfaceType: Type {
Type(bridged: bridged.NominalType_getDeclaredInterfaceType())
}
public func add(member: Decl) {
bridged.NominalTypeDecl_addMember(member.bridged)
}
}
final public class EnumDecl: NominalTypeDecl {
public var hasRawType: Bool { bridged.Enum_hasRawType() }
public static func create(
_ astContext: ASTContext, declContext: DeclContext, enumKeywordLoc: SourceLoc?, name: String,
nameLoc: SourceLoc?, genericParamList: GenericParamList?, inheritedTypes: [Type],
genericWhereClause: TrailingWhereClause?, braceRange: SourceRange
) -> EnumDecl {
name.withCString { strPtr in
inheritedTypes.withBridgedArrayRef { types in
ASTBridging.BridgedEnumDecl.createParsed(
astContext, declContext: declContext.bridgedDeclContext,
enumKeywordLoc: enumKeywordLoc.bridgedLocation,
name: astContext.getIdentifier(BridgedStringRef(data: strPtr, count: name.count)),
nameLoc: nameLoc.bridgedLocation,
genericParamList: genericParamList.bridged,
inheritedTypes: types,
genericWhereClause: genericWhereClause.bridged,
braceRange: braceRange.bridged)
}
}.asDecl.declObj.getAs(EnumDecl.self)
}
}
final public class StructDecl: NominalTypeDecl {
@@ -93,7 +150,19 @@ final public class OpaqueTypeDecl: GenericTypeDecl {}
final public class TypeAliasDecl: GenericTypeDecl {}
final public class GenericTypeParamDecl: TypeDecl {}
final public class GenericTypeParamDecl: TypeDecl {
public static func create(
declContext: DeclContext,
name: Identifier,
depth: Int,
index: Int,
paramKind: GenericTypeParameterKind) -> GenericTypeParamDecl {
ASTBridging.BridgedGenericTypeParamDecl.createImplicit(
declContext: declContext.bridgedDeclContext,
name: name, depth: depth, index: index,
paramKind: paramKind).asDecl.declObj.getAs(GenericTypeParamDecl.self)
}
}
final public class AssociatedTypeDecl: TypeDecl {}
@@ -105,7 +174,15 @@ public class AbstractStorageDecl: ValueDecl {
public class VarDecl: AbstractStorageDecl {}
final public class ParamDecl: VarDecl {}
final public class ParamDecl: VarDecl {
public func cloneWithoutType() -> ParamDecl {
BridgedParamDecl(raw: bridged.obj).cloneWithoutType().asDecl.declObj.getAs(ParamDecl.self)
}
public func setInterfaceType(type: Type) {
BridgedParamDecl(raw: bridged.obj).setInterfaceType(type.bridged)
}
}
final public class SubscriptDecl: AbstractStorageDecl {}
@@ -127,8 +204,22 @@ final public class MacroDecl: ValueDecl {}
final public class EnumElementDecl: ValueDecl {
public var hasAssociatedValues: Bool { bridged.EnumElementDecl_hasAssociatedValues() }
public var parameterList: ParameterList { bridged.EnumElementDecl_getParameterList() }
public var parameterList: ParameterList { ParameterList(bridged: bridged.EnumElementDecl_getParameterList()) }
public var name: StringRef { StringRef(bridged: bridged.EnumElementDecl_getNameStr()) }
public static func create(
_ astContext: ASTContext, declContext: DeclContext,
name: Identifier, nameLoc: SourceLoc?,
parameterList: ParameterList?,
equalsLoc: SourceLoc?, rawValue: Expr?
) -> EnumElementDecl {
BridgedEnumElementDecl.createParsed(
astContext, declContext: declContext.bridgedDeclContext,
name: name, nameLoc: nameLoc.bridgedLocation,
parameterList: parameterList.bridged.bridged,
equalsLoc: equalsLoc.bridgedLocation,
rawValue: rawValue.bridged).asDecl.declObj.getAs(EnumElementDecl.self)
}
}
final public class ExtensionDecl: Decl {}
@@ -177,62 +268,83 @@ extension Optional where Wrapped == Decl {
}
}
public typealias AccessLevel = swift.AccessLevel
public typealias Identifier = swift.Identifier
public typealias GenericTypeParamKind = swift.GenericTypeParamKind
public typealias ASTContext = BridgedASTContext
public typealias DeclContext = BridgedDeclContext
public typealias Expr = BridgedExpr
public typealias ParameterList = BridgedParameterList
public typealias SourceFile = BridgedSourceFile
public typealias FileUnit = BridgedFileUnit
public typealias GenericParamList = BridgedGenericParamList
public class GenericParamList {
public var bridged: BridgedGenericParamList
public init(bridged: BridgedGenericParamList) { self.bridged = bridged }
}
public typealias TrailingWhereClause = BridgedTrailingWhereClause
public typealias BridgedParamDecl = ASTBridging.BridgedParamDecl
public class ParameterList : RandomAccessCollection {
public class Iterator : IteratorProtocol {
public typealias Element = ParamDecl
private var index : Int = 0
private let parameterList : ParameterList
init(parameterList : ParameterList) { self.parameterList = parameterList }
public func next() -> Element? {
if index < parameterList.bridged.size {
return parameterList.bridged.get(index).asDecl.declObj.getAs(ParamDecl.self)
}
return nil
}
}
public typealias Index = Int
public var startIndex: Index { 0 }
public var endIndex: Index { bridged.size }
public func index(after i: Index) -> Index { i + 1 }
public typealias BridgedGenericTypeParamDecl = ASTBridging.BridgedGenericTypeParamDecl
public typealias BridgedEnumDecl = ASTBridging.BridgedEnumDecl
public typealias BridgedEnumElementDecl = ASTBridging.BridgedEnumElementDecl
extension ParameterList {
public subscript(_ index: Int) -> BridgedParamDecl {
return get(index)
public func makeIterator() -> Iterator {
Self.Iterator(parameterList: self)
}
public static func createParsed(
_ astContext: ASTContext, leftParenLoc: SourceLoc?, parameters: [BridgedParamDecl],
public var bridged: BridgedParameterList
public init(bridged: BridgedParameterList) {
self.bridged = bridged
}
public subscript(_ index: Index) -> ParamDecl {
return bridged.get(index).asDecl.declObj.getAs(ParamDecl.self)
}
public static func create(
_ astContext: ASTContext, leftParenLoc: SourceLoc?, parameters: [ParamDecl],
rightParenLoc: SourceLoc?
) -> ParameterList {
parameters.withBridgedArrayRef {
ParameterList.createParsed(
ParameterList(bridged: parameters.map{BridgedParamDecl(raw: $0.bridged.obj)}.withBridgedArrayRef {
BridgedParameterList.createParsed(
astContext, leftParenLoc: leftParenLoc.bridgedLocation, parameters: $0,
rightParenLoc: rightParenLoc.bridgedLocation)
}
})
}
}
extension GenericParamList {
public static func createParsed(
_ astContext: ASTContext, leftAngleLoc: SourceLoc?, parameters: [BridgedGenericTypeParamDecl],
public static func create(
_ astContext: ASTContext, leftAngleLoc: SourceLoc?, parameters: [GenericTypeParamDecl],
genericWhereClause: TrailingWhereClause?,
rightAngleLoc: SourceLoc?
) -> GenericParamList {
return parameters.withBridgedArrayRef {
GenericParamList.createParsed(
let paramsNew = parameters.map{ ASTBridging.BridgedGenericTypeParamDecl(raw: $0.bridged.obj) }
return paramsNew.withBridgedArrayRef {
GenericParamList(bridged: BridgedGenericParamList.createParsed(
astContext, leftAngleLoc: leftAngleLoc.bridgedLocation, parameters: $0,
genericWhereClause: genericWhereClause.bridged, rightAngleLoc: rightAngleLoc.bridgedLocation
)
))
}
}
}
@@ -244,43 +356,6 @@ extension BridgedDecl {
public var decl: Decl { declObj.decl }
}
extension BridgedEnumDecl {
public static func createParsed(
_ astContext: ASTContext, declContext: DeclContext, enumKeywordLoc: SourceLoc?, name: String,
nameLoc: SourceLoc?, genericParamList: GenericParamList?, inheritedTypes: [Type],
genericWhereClause: TrailingWhereClause?, braceRange: SourceRange
) -> BridgedEnumDecl {
return name.withCString { strPtr in
inheritedTypes.withBridgedArrayRef { types in
BridgedEnumDecl.createParsed(
astContext, declContext: declContext,
enumKeywordLoc: enumKeywordLoc.bridgedLocation,
name: astContext.getIdentifier(BridgedStringRef(data: strPtr, count: name.count)),
nameLoc: nameLoc.bridgedLocation,
genericParamList: genericParamList.bridged,
inheritedTypes: types,
genericWhereClause: genericWhereClause.bridged,
braceRange: braceRange.bridged)
}
}
}
}
extension BridgedEnumElementDecl {
public static func createParsed(
_ astContext: ASTContext, declContext: DeclContext,
name: Identifier, nameLoc: SourceLoc?,
parameterList: ParameterList?,
equalsLoc: SourceLoc?, rawValue: Expr?
) -> BridgedEnumElementDecl {
BridgedEnumElementDecl.createParsed(
astContext, declContext: declContext,
name: name, nameLoc: nameLoc.bridgedLocation,
parameterList: parameterList.bridged,
equalsLoc: equalsLoc.bridgedLocation, rawValue: rawValue.bridged)
}
}
extension SourceFile {
public init?(bridged: BridgedNullableSourceFile) {
guard let raw = bridged.raw else {
@@ -294,13 +369,16 @@ extension FileUnit {
public var asSourceFile: SourceFile? { SourceFile(bridged: self.castToSourceFile()) }
}
extension BridgedParamDecl {
public func setInterfaceType(type: Type) {
self.setInterfaceType(type.bridged)
extension ParameterList? {
public var bridged: BridgedParameterList? {
if self == nil {
return nil
}
return self!.bridged
}
}
extension ParameterList? {
extension BridgedParameterList? {
public var bridged: BridgedNullableParameterList {
BridgedNullableParameterList(raw: self?.raw)
}
@@ -308,7 +386,7 @@ extension ParameterList? {
extension GenericParamList? {
public var bridged: BridgedNullableGenericParamList {
BridgedNullableGenericParamList(raw: self?.raw)
BridgedNullableGenericParamList(raw: self?.bridged.raw)
}
}

View File

@@ -67,7 +67,7 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
return Type(bridged: bridged.subst(substitutionMap.bridged))
}
public func mapTypeOutOfContext() -> Type {
public func mapOutOfContext() -> Type {
return Type(bridged: bridged.mapTypeOutOfContext())
}

View File

@@ -23,6 +23,13 @@ extension TypeProperties {
public func loweredType(in function: Function, maximallyAbstracted: Bool = false) -> Type {
function.bridged.getLoweredType(rawType.bridged, maximallyAbstracted).type.objectType
}
// Lowers the AST type to a SIL type - in a specific function.
// In contrast to `loweredType`, this takes `AbstractionPattern` constructed from `function`'s
// `SubstGenericSignature` into account when getting the lowered type.
public func loweredTypeWithAbstractionPattern(in function: Function) -> Type {
function.bridged.getLoweredTypeWithAbstractionPattern(rawType.canonical.bridged).type
}
}
extension CanonicalType {
@@ -36,10 +43,6 @@ extension CanonicalType {
precondition(isBox)
return BoxFieldsArray(boxType: self, function: function)
}
public func loweredType(in function: Function) -> Type {
function.bridged.getLoweredType(bridged).type
}
}
extension Decl {

View File

@@ -36,6 +36,8 @@ public struct DeclRef: CustomStringConvertible, NoReflectionChildren {
public func calleesAreStaticallyKnowable(_ context: some Context) -> Bool {
context._bridged.calleesAreStaticallyKnowable(bridged)
}
public var sourceFile: SourceFile? { SourceFile(bridged: bridged.getSourceFile()) }
}
extension DeclRef: DiagnosticArgument {

View File

@@ -26,7 +26,9 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
return Location(bridged: bridged.getLocation())
}
public var sourceFile: SourceFile? { SourceFile(bridged: bridged.getSourceFile()) }
public var declRef: DeclRef { DeclRef(bridged: bridged.getDeclRef()) }
public var sourceFile: SourceFile? { declRef.sourceFile }
final public var description: String {
return String(taking: bridged.getDebugDescription())

View File

@@ -195,22 +195,6 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
return EnumCases(enumType: self, function: function)
}
public func getEnumCase(in function: Function, at index: Int) -> EnumCase? {
guard let enumCases = getEnumCases(in: function) else {
return nil
}
var enumCaseIndex = 0
for enumCase in enumCases {
if index == enumCaseIndex {
return enumCase
}
enumCaseIndex += 1
}
return nil
}
public func getIndexOfEnumCase(withName name: String) -> Int? {
let idx = name._withBridgedStringRef {
bridged.getCaseIdxOfEnumType($0)
@@ -241,8 +225,8 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
return false
}
public func mapTypeOutOfContext(in function: Function) -> Type {
rawType.mapTypeOutOfContext().canonical.loweredType(in: function)
public func mapOutOfContext(in function: Function) -> Type {
rawType.mapOutOfContext().canonical.loweredType(in: function)
}
}
@@ -325,6 +309,22 @@ public struct EnumCases : CollectionLikeSequence, IteratorProtocol {
}
return nil
}
// Note: this has O(n) complexity where n is number of enum cases
public subscript(_ index: Int) -> EnumCase? {
var iterator = enumType.bridged.getFirstEnumCaseIterator()
var currentIndex = 0
while currentIndex != index && !enumType.bridged.isEndCaseIterator(iterator) {
iterator = iterator.getNext()
currentIndex += 1
}
if currentIndex == index && !enumType.bridged.isEndCaseIterator(iterator) {
return EnumCase(enumElementDecl: enumType.bridged.getEnumElementDecl(iterator).getAs(EnumElementDecl.self),
payload: enumType.bridged.getEnumCasePayload(iterator, function.bridged).typeOrNil,
index: caseIndex)
}
return nil
}
}
public struct TupleElementArray : RandomAccessCollection, FormattedLikeArray {

View File

@@ -321,6 +321,9 @@ struct BridgedDeclObj {
BRIDGED_INLINE swift::SourceLoc getLoc() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj getModuleContext() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getParent() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclContext getDeclContext() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclContext asGenericContext() const;
BRIDGED_INLINE void setImplicit() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef Type_getName() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef Value_getUserFacingName() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE swift::SourceLoc Value_getNameLoc() const;
@@ -347,6 +350,9 @@ struct BridgedDeclObj {
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef
EnumElementDecl_getNameStr() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef AccessorDecl_getKindName() const;
BRIDGED_INLINE void GenericContext_setGenericSignature(BridgedGenericSignature genericSignature) const;
BRIDGED_INLINE void ValueDecl_setAccess(swift::AccessLevel accessLevel) const;
BRIDGED_INLINE void NominalTypeDecl_addMember(BridgedDeclObj member) const;
};
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedASTNodeKind : uint8_t {
@@ -399,14 +405,6 @@ public:
#define ABSTRACT_DECL(Id, Parent) DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"
// Declare `.asValueDecl` on each BridgedXXXDecl type that's also a
// ValueDecl.
#define DECL(Id, Parent)
#define VALUE_DECL(Id, Parent) \
SWIFT_NAME("getter:Bridged" #Id "Decl.asValueDecl(self:)") \
BridgedValueDecl Bridged##Id##Decl_asValueDecl(Bridged##Id##Decl decl);
#include "swift/AST/DeclNodes.def"
// Declare `.asNominalTypeDecl` on each BridgedXXXDecl type that's also a
// NominalTypeDecl.
#define DECL(Id, Parent)
@@ -425,16 +423,6 @@ public:
#define ABSTRACT_CONTEXT_DECL(Id, Parent) CONTEXT_DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"
// Declare `.asGenericContext` on each BridgedXXXDecl type that's also a
// GenericContext.
#define DECL(Id, Parent)
#define GENERIC_DECL(Id, Parent) \
SWIFT_NAME("getter:Bridged" #Id "Decl.asGenericContext(self:)") \
BridgedGenericContext Bridged##Id##Decl_asGenericContext( \
Bridged##Id##Decl decl);
#define ITERABLE_GENERIC_DECL(Id, Parent) GENERIC_DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"
// Declare `.asStmt` on each BridgedXXXStmt type, which upcasts a wrapper for
// a Stmt subclass to a BridgedStmt.
#define STMT(Id, Parent) \
@@ -1348,9 +1336,6 @@ SWIFT_NAME("BridgedDecl.forEachDeclToHoist(self:_:)")
void BridgedDecl_forEachDeclToHoist(BridgedDecl decl,
BridgedSwiftClosure closure);
SWIFT_NAME("getter:BridgedDecl.declContext(self:)")
BridgedDeclContext BridgedDecl_getDeclContext(BridgedDecl decl);
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedStaticSpelling {
BridgedStaticSpellingNone,
BridgedStaticSpellingStatic,
@@ -1428,13 +1413,8 @@ BRIDGED_INLINE void
BridgedParamDecl_setSpecifier(BridgedParamDecl cDecl,
BridgedParamSpecifier cSpecifier);
SWIFT_NAME("BridgedDecl.setImplicit(self:)")
BRIDGED_INLINE void BridgedDecl_setImplicit(BridgedDecl cDecl);
SWIFT_NAME("BridgedGenericContext.setGenericSignature(self:_:)")
BRIDGED_INLINE void
BridgedGenericContext_setGenericSignature(BridgedGenericContext cDecl,
BridgedGenericSignature cGenSig);
SWIFT_NAME("BridgedParamDecl.setImplicit(self:)")
BRIDGED_INLINE void BridgedParamDecl_setImplicit(BridgedParamDecl cDecl);
SWIFT_NAME("BridgedConstructorDecl.setParsedBody(self:_:)")
void BridgedConstructorDecl_setParsedBody(BridgedConstructorDecl decl,
@@ -1689,10 +1669,6 @@ void BridgedTopLevelCodeDecl_dump(BridgedTopLevelCodeDecl decl);
SWIFT_NAME("BridgedDecl.dump(self:)")
void BridgedDecl_dump(BridgedDecl decl);
SWIFT_NAME("BridgedValueDecl.setAccess(self:_:)")
void BridgedValueDecl_setAccess(BridgedValueDecl decl,
swift::AccessLevel accessLevel);
//===----------------------------------------------------------------------===//
// MARK: AbstractStorageDecl
//===----------------------------------------------------------------------===//
@@ -1742,11 +1718,6 @@ SWIFT_NAME("BridgedNominalTypeDecl.getSourceLocation(self:)")
BRIDGED_INLINE swift::SourceLoc
BridgedNominalTypeDecl_getSourceLocation(BridgedNominalTypeDecl decl);
SWIFT_NAME("BridgedNominalTypeDecl.addMember(self:_:)")
BRIDGED_INLINE void
BridgedNominalTypeDecl_addMember(BridgedNominalTypeDecl cDecl,
BridgedDecl member);
//===----------------------------------------------------------------------===//
// MARK: SubscriptDecl
//===----------------------------------------------------------------------===//

View File

@@ -177,6 +177,18 @@ OptionalBridgedDeclObj BridgedDeclObj::getParent() const {
return {unbridged()->getDeclContext()->getAsDecl()};
}
BridgedDeclContext BridgedDeclObj::getDeclContext() const {
return {unbridged()->getDeclContext()};
}
BridgedDeclContext BridgedDeclObj::asGenericContext() const {
return {static_cast<swift::DeclContext *>(getAs<swift::GenericContext>())};
}
void BridgedDeclObj::setImplicit() const {
unbridged()->setImplicit();
}
BridgedStringRef BridgedDeclObj::Type_getName() const {
return getAs<swift::TypeDecl>()->getName().str();
}
@@ -264,6 +276,18 @@ BridgedASTType BridgedDeclObj::NominalType_getDeclaredInterfaceType() const {
getAs<swift::NominalTypeDecl>()->getDeclaredInterfaceType().getPointer()};
}
void BridgedDeclObj::GenericContext_setGenericSignature(BridgedGenericSignature genericSignature) const {
getAs<swift::GenericContext>()->setGenericSignature(genericSignature.unbridged());
}
void BridgedDeclObj::ValueDecl_setAccess(swift::AccessLevel accessLevel) const {
getAs<swift::ValueDecl>()->setAccess(accessLevel);
}
void BridgedDeclObj::NominalTypeDecl_addMember(BridgedDeclObj member) const {
getAs<swift::NominalTypeDecl>()->addMember(member.unbridged());
}
//===----------------------------------------------------------------------===//
// MARK: BridgedASTNode
//===----------------------------------------------------------------------===//
@@ -387,24 +411,10 @@ void BridgedParamDecl_setSpecifier(BridgedParamDecl cDecl,
cDecl.unbridged()->setSpecifier(unbridge(cSpecifier));
}
void BridgedDecl_setImplicit(BridgedDecl cDecl) {
void BridgedParamDecl_setImplicit(BridgedParamDecl cDecl) {
cDecl.unbridged()->setImplicit();
}
void BridgedGenericContext_setGenericSignature(
BridgedGenericContext cDecl, BridgedGenericSignature cGenSig) {
cDecl.unbridged()->setGenericSignature(cGenSig.unbridged());
}
//===----------------------------------------------------------------------===//
// MARK: BridgedNominalTypeDecl
//===----------------------------------------------------------------------===//
void BridgedNominalTypeDecl_addMember(BridgedNominalTypeDecl cDecl,
BridgedDecl member) {
cDecl.unbridged()->addMember(member.unbridged());
}
//===----------------------------------------------------------------------===//
// MARK: BridgedSubscriptDecl
//===----------------------------------------------------------------------===//

View File

@@ -258,6 +258,7 @@ BridgedYieldInfoArray SILFunctionType_getYields(BridgedCanType);
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLifetimeDependenceInfoArray
SILFunctionType_getLifetimeDependencies(BridgedCanType);
struct BridgedType {
void * _Nullable opaqueValue;
@@ -532,8 +533,6 @@ struct BridgedFunction {
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
BridgedOwnedString getDebugDescription() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getLocation() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedNullableSourceFile
getSourceFile() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedArrayRef getFilesForModule() const;
BRIDGED_INLINE bool isAccessor() const;
BRIDGED_INLINE bool isInitializer() const;
@@ -586,7 +585,7 @@ struct BridgedFunction {
BRIDGED_INLINE bool isResilientNominalDecl(BridgedDeclObj decl) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getLoweredType(BridgedASTType type, bool maximallyAbstracted) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType
getLoweredType(BridgedCanType type) const;
getLoweredTypeWithAbstractionPattern(BridgedCanType type) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getLoweredType(BridgedType type) const;
BRIDGED_INLINE BridgedLinkage getLinkage() const;
BRIDGED_INLINE void setLinkage(BridgedLinkage linkage) const;
@@ -845,8 +844,6 @@ struct BridgedInstruction {
BRIDGED_INLINE void RefElementAddrInst_setImmutable(bool isImmutable) const;
BRIDGED_INLINE bool RefTailAddrInst_isImmutable() const;
BRIDGED_INLINE SwiftInt PartialApplyInst_numArguments() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap
PartialApplyInst_getSubstitutionMap() const;
BRIDGED_INLINE SwiftInt ApplyInst_numArguments() const;
BRIDGED_INLINE bool ApplyInst_getNonThrowing() const;
BRIDGED_INLINE bool ApplyInst_getNonAsync() const;
@@ -1002,7 +999,6 @@ struct BridgedArgument {
BRIDGED_INLINE void setReborrow(bool reborrow) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getDecl() const;
BRIDGED_INLINE void copyFlags(BridgedArgument fromArgument) const;
BRIDGED_INLINE BridgedValue::Ownership getOwnership() const;
};
struct OptionalBridgedArgument {
@@ -1080,6 +1076,7 @@ struct BridgedDeclRef {
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getLocation() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj getDecl() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDiagnosticArgument asDiagnosticArgument() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedNullableSourceFile getSourceFile() const;
};
struct BridgedVTableEntry {

View File

@@ -675,11 +675,6 @@ void BridgedArgument::copyFlags(BridgedArgument fromArgument) const {
fArg->copyFlags(static_cast<swift::SILFunctionArgument *>(fromArgument.getArgument()));
}
BridgedValue::Ownership BridgedArgument::getOwnership() const {
swift::ValueBase *val = getArgument();
return BridgedValue{SwiftObject{val}}.getOwnership();
}
swift::SILArgument * _Nullable OptionalBridgedArgument::unbridged() const {
if (!obj)
return nullptr;
@@ -758,10 +753,6 @@ BridgedLocation BridgedFunction::getLocation() const {
return {swift::SILDebugLocation(getFunction()->getLocation(), getFunction()->getDebugScope())};
}
BridgedNullableSourceFile BridgedFunction::getSourceFile() const {
return {getFunction()->getSourceFile()};
}
BridgedArrayRef BridgedFunction::getFilesForModule() const {
return getFunction()->getModule().getSwiftModule()->getFiles();
}
@@ -1000,7 +991,7 @@ BridgedType BridgedFunction::getLoweredType(BridgedASTType type, bool maximallyA
return BridgedType(getFunction()->getLoweredType(type.type));
}
BridgedType BridgedFunction::getLoweredType(BridgedCanType type) const {
BridgedType BridgedFunction::getLoweredTypeWithAbstractionPattern(BridgedCanType type) const {
swift::Lowering::AbstractionPattern pattern(
getFunction()->getLoweredFunctionType()->getSubstGenericSignature(),
type.unbridged());
@@ -1183,12 +1174,6 @@ bool BridgedInstruction::isIdenticalTo(BridgedInstruction inst) const {
return unbridged()->isIdenticalTo(inst.unbridged());
}
BridgedSubstitutionMap
BridgedInstruction::PartialApplyInst_getSubstitutionMap() const {
auto *pai = llvm::cast<swift::PartialApplyInst>(unbridged());
return {pai->getSubstitutionMap()};
}
SwiftInt BridgedInstruction::MultipleValueInstruction_getNumResults() const {
return getAs<swift::MultipleValueInstruction>()->getNumResults();
}
@@ -2113,6 +2098,14 @@ BridgedDiagnosticArgument BridgedDeclRef::asDiagnosticArgument() const {
return swift::DiagnosticArgument(unbridged().getDecl()->getName());
}
BridgedNullableSourceFile BridgedDeclRef::getSourceFile() const {
swift::SILDeclRef declRef = unbridged();
if (!declRef)
return nullptr;
return {declRef.getInnermostDeclContext()->getParentSourceFile()};
}
//===----------------------------------------------------------------------===//
// BridgedVTable
//===----------------------------------------------------------------------===//

View File

@@ -95,15 +95,6 @@ BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(BridgedASTContext cContext,
#define ABSTRACT_DECL(Id, Parent) DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"
// Define `.asValueDecl` on each BridgedXXXDecl type that's also a
// ValueDecl.
#define DECL(Id, Parent)
#define VALUE_DECL(Id, Parent) \
BridgedValueDecl Bridged##Id##Decl_asValueDecl(Bridged##Id##Decl decl) { \
return static_cast<ValueDecl *>(decl.unbridged()); \
}
#include "swift/AST/DeclNodes.def"
// Define `.asNominalTypeDecl` on each BridgedXXXDecl type that's also a
// NominalTypeDecl.
#define DECL(Id, Parent)
@@ -124,17 +115,6 @@ BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(BridgedASTContext cContext,
#define ABSTRACT_CONTEXT_DECL(Id, Parent) CONTEXT_DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"
// Define `.asGenericContext` on each BridgedXXXDecl type that's also a
// GenericContext.
#define DECL(Id, Parent)
#define GENERIC_DECL(Id, Parent) \
BridgedGenericContext Bridged##Id##Decl_asGenericContext( \
Bridged##Id##Decl decl) { \
return static_cast<GenericContext *>(decl.unbridged()); \
}
#define ITERABLE_GENERIC_DECL(Id, Parent) GENERIC_DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"
static StaticSpellingKind unbridged(BridgedStaticSpelling kind) {
return static_cast<StaticSpellingKind>(kind);
}
@@ -152,15 +132,6 @@ void BridgedDecl_forEachDeclToHoist(BridgedDecl cDecl,
});
}
BridgedDeclContext BridgedDecl_getDeclContext(BridgedDecl decl) {
return decl.unbridged()->getDeclContext();
}
void BridgedValueDecl_setAccess(BridgedValueDecl decl,
swift::AccessLevel accessLevel) {
decl.unbridged()->setAccess(accessLevel);
}
BridgedAccessorDecl BridgedAccessorDecl_createParsed(
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
swift::AccessorKind Kind, BridgedAbstractStorageDecl cStorage,

View File

@@ -1067,7 +1067,7 @@ void IterableDeclContext::addMember(Decl *member, Decl *hint, bool insertAtHead)
case IterableDeclContextKind::NominalTypeDecl: {
auto nominal = cast<NominalTypeDecl>(this);
nominal->addedMember(member);
assert(member->getDeclContext() == nominal &&
assert(member->getDeclContext() == static_cast<DeclContext *>(nominal) &&
"Added member to the wrong context");
break;
}

View File

@@ -370,7 +370,7 @@ extension ASTGenVisitor {
defaultValueInitContext: nil
)
param.setSpecifier(.default)
param.asDecl.setImplicit()
param.setImplicit()
params.append(param)
}
}