-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ASTGen] Generate AvailableAttr #79125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
swiftlang/swift-syntax#2954 |
2 similar comments
swiftlang/swift-syntax#2954 |
swiftlang/swift-syntax#2954 |
9333a24
to
b8c8b20
Compare
b8c8b20
to
6a0fda6
Compare
swiftlang/swift-syntax#2954 |
6a0fda6
to
cf62f3d
Compare
* Move `AvailabilitySpec` handling logic to AST, so they can be shared between libParse and ASTGen * Requestify '-define-availability' arguments parsing and parse them with 'SwiftParser' according to the 'ParserASTGen' feature flag * Implement 'AvailableAttr' generation in ASTGen
cf62f3d
to
df2ada3
Compare
swiftlang/swift-syntax#2954 |
const void *_Nullable BridgedArrayRef_data(const BridgedArrayRef arr); | ||
|
||
SWIFT_NAME("getter:BridgedArrayRef.count(self:)") | ||
BRIDGED_INLINE SwiftInt BridgedArrayRef_count(BridgedArrayRef arr); | ||
BRIDGED_INLINE SwiftInt BridgedArrayRef_count(const BridgedArrayRef arr); | ||
|
||
SWIFT_NAME("getter:BridgedArrayRef.isEmpty(self:)") | ||
BRIDGED_INLINE bool BridgedArrayRef_isEmpty(const BridgedArrayRef arr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The const
s on the parameters don't do anything, right?
const void *_Nullable BridgedArrayRef_data(const BridgedArrayRef arr) { | ||
return arr.Data; | ||
} | ||
|
||
SwiftInt BridgedArrayRef_count(BridgedArrayRef arr) { | ||
SwiftInt BridgedArrayRef_count(const BridgedArrayRef arr) { | ||
return static_cast<SwiftInt>(arr.Length); | ||
} | ||
|
||
bool BridgedArrayRef_isEmpty(const BridgedArrayRef arr) { | ||
return arr.Length == 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment, although these do prevent mutating the variable itself, but that's not too helpful
@@ -0,0 +1,426 @@ | |||
//===--- Attrs.swift ------------------------------------------------------===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//===--- Attrs.swift ------------------------------------------------------===// | |
//===--- Availability.swift -----------------------------------------------===// |
let atLoc = self.generateSourceLoc(node.atSign) | ||
let range = self.generateAttrSourceRange(node) | ||
let specs = self.generateAvailabilitySpecList( | ||
args: node.arguments!.cast(AvailabilityArgumentListSyntax.self), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth passing through the args so you don't have to do this again?
} | ||
|
||
func generateAvailableAttrExtended(attribute node: AttributeSyntax) -> BridgedAvailableAttr? { | ||
var args = node.arguments!.cast(AvailabilityArgumentListSyntax.self)[...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
var renamed: BridgedStringRef? = nil | ||
|
||
func generateVersion(arg: AvailabilityLabeledArgumentSyntax, into target: inout VersionAndRange?) { | ||
guard let versionSytnax = arg.value.as(VersionTupleSyntax.self) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guard let versionSytnax = arg.value.as(VersionTupleSyntax.self) else { | |
guard let versionSyntax = arg.value.as(VersionTupleSyntax.self) else { |
|
||
extension BridgedArrayRef { | ||
public func withElements<T, R>(ofType ty: T.Type, _ c: (UnsafeBufferPointer<T>) -> R) -> R { | ||
let start = data?.bindMemory(to: ty, capacity: count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should probably either use withMemoryRebound(to:)
or assumingMemoryBound(to:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I'd go with assumingMemoryBound
. I copied this from SwiftCompilerSources, so I will change both in followups.
/// Parse the '-define-availability' arguments. | ||
class AvailabilityMacroArgumentsRequest | ||
: public SimpleRequest<AvailabilityMacroArgumentsRequest, | ||
AvailabilityMacroMap *(ASTContext *), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should hand back a const
pointer
AvailabilityMacroMap *(ASTContext *), | |
const AvailabilityMacroMap *(ASTContext *), |
|
||
BridgedAvailabilityMacroMap | ||
BridgedASTContext_getAvailabilityMacroMap(BridgedASTContext cContext) { | ||
return const_cast<AvailabilityMacroMap *>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if BridgedAvailabilityMacroMap
could store a const pointer, maybe we should define it manually instead of using AST_BRIDGING_WRAPPER
? Or maybe we could add a const variant of that macro
Thanks @hamishknight ! I will address your comments in followups |
AvailabilitySpec
handling logic to AST, so they can be shared between libParse and ASTGen-define-availability
arguments parsing and parse them withSwiftParser
according to theParserASTGen
feature flagAvailableAttr
generation in ASTGen