-
Notifications
You must be signed in to change notification settings - Fork 11
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
Availability attribute support #51
base: master
Are you sure you want to change the base?
Conversation
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/syntax.jl b/src/syntax.jl
index 0fc0adb..7e5a075 100644
--- a/src/syntax.jl
+++ b/src/syntax.jl
@@ -263,8 +263,8 @@ Attempt to contruct an Objective-C object or property that is
not available in the current macOS version.
"""
struct UnavailableError <: Exception
- symbol::Symbol
- minver::VersionNumber
+ symbol::Symbol
+ minver::VersionNumber
end
Base.showerror(io::IO, e::UnavailableError) = print(io, "UnavailableError: `", e.symbol, "` was introduced in macOS v", e.minver)
@@ -303,7 +303,7 @@ macro objcwrapper(ex...)
# parse kwargs
comparison = nothing
immutable = nothing
- availability = nothing
+ availability = nothing
for kw in kwargs
if kw isa Expr && kw.head == :(=)
kw, value = kw.args
@@ -313,9 +313,9 @@ macro objcwrapper(ex...)
elseif kw == :immutable
value isa Bool || wrappererror("immutable keyword argument must be a literal boolean")
immutable = value
- elseif kw == :availability
- Meta.isexpr(value, :macrocall) && value.args[1] == Symbol("@v_str") || wrappererror("availability keyword argument must be a `v_str` statement")
- availability = macroexpand(__module__, value; recursive=false)
+ elseif kw == :availability
+ Meta.isexpr(value, :macrocall) && value.args[1] == Symbol("@v_str") || wrappererror("availability keyword argument must be a `v_str` statement")
+ availability = macroexpand(__module__, value; recursive = false)
else
wrappererror("unrecognized keyword argument: $kw")
end
@@ -325,7 +325,7 @@ macro objcwrapper(ex...)
end
immutable = something(immutable, true)
comparison = something(comparison, !immutable)
- availability = something(availability, v"0")
+ availability = something(availability, v"0")
# parse class definition
if Meta.isexpr(def, :(<:))
@@ -366,9 +366,9 @@ macro objcwrapper(ex...)
# add a pseudo constructor to the abstract type that also checks for nil pointers.
function $name(ptr::id)
- @static if !Sys.isapple() || ObjectiveC.macos_version() < $availability
- throw($UnavailableError(Symbol($name), $availability))
- end
+ @static if !Sys.isapple() || ObjectiveC.macos_version() < $availability
+ throw($UnavailableError(Symbol($name), $availability))
+ end
ptr == nil && throw(UndefRefError())
$instance(ptr)
@@ -527,7 +527,7 @@ macro objcproperties(typ, ex)
getproperty_ex = objcm(__module__, :([object::id{$(esc(typ))} $getterproperty]::$srcTyp))
getproperty_ex = quote
@static if !Sys.isapple() || ObjectiveC.macos_version() < $availability
- throw($UnavailableError(Symbol($(esc(typ)),".",field), $availability))
+ throw($UnavailableError(Symbol($(esc(typ)), ".", field), $availability))
end
value = $(Expr(:var"hygienic-scope", getproperty_ex, @__MODULE__, __source__))
end |
0e5fb25
to
6badbb7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #51 +/- ##
==========================================
+ Coverage 71.91% 76.64% +4.73%
==========================================
Files 10 12 +2
Lines 769 942 +173
==========================================
+ Hits 553 722 +169
- Misses 216 220 +4 ☔ View full report in Codecov by Sentry. |
What about making this more generic than only checking against the macOS version, taking an arbitrary bool instead? Is there precedent for, say, platform-dependent attributes? If so, what about: availability = is_macos(v"15")
availability = (Sys.ARCH == :aarch64) |
I don't think there is precedence for this, I tried to have it behave like the clang attribute, and the only platform that supports both it and Julia is macOS. I'm not opposed to it, but this would leave the need for code in the
|
Did not mean to close |
The TOML could always use a more specific
I wonder if we could symbolize the condition:
That said, I'm totally fine with mimicking Clang and providing something more specific. I'd then mimic it somewhat closer though, also including the platform and introduced/deprecated/obsolete. Just spitballing, but what about: # in ObjectiveC.jl:
struct macOS
# ...
macOS(introduced::VersionNumber, deprecated=nothing, obsolete=nothing) = ...
end
# in user code
@objcwrapper availability = macOS(v"14") Foo <: Object
@objcwrapper availability = [macOS(introduced=v"14", deprecated=v"15")] Bar <: Object
|
#50