-
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
Indentation consistency #58
Conversation
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/blocks.jl b/src/blocks.jl
index 83149ba..42a3ee5 100644
--- a/src/blocks.jl
+++ b/src/blocks.jl
@@ -82,8 +82,10 @@ function JuliaBlock(trampoline, callable)
copy_cb = @cfunction(julia_block_copy, Nothing, (Ptr{JuliaBlock}, Ptr{JuliaBlock}))
dispose_cb = @cfunction(julia_block_dispose, Nothing, (Ptr{JuliaBlock},))
- julia_block_descriptor[] = JuliaBlockDescriptor(0, sizeof(JuliaBlock),
- copy_cb, dispose_cb)
+ julia_block_descriptor[] = JuliaBlockDescriptor(
+ 0, sizeof(JuliaBlock),
+ copy_cb, dispose_cb
+ )
julia_block_descriptor_initialized[] = true
end
@@ -184,8 +186,10 @@ function JuliaAsyncBlock(cond)
# lazily create a descriptor (these sometimes don't precompile properly)
if !julia_async_block_descriptor_initialized[]
# simple cfunctions, so don't need to be rooted
- julia_async_block_descriptor[] = JuliaAsyncBlockDescriptor(0, sizeof(JuliaAsyncBlock),
- C_NULL, C_NULL)
+ julia_async_block_descriptor[] = JuliaAsyncBlockDescriptor(
+ 0, sizeof(JuliaAsyncBlock),
+ C_NULL, C_NULL
+ )
julia_async_block_descriptor_initialized[] = true
end
diff --git a/src/classes.jl b/src/classes.jl
index a84abfd..50b32ee 100644
--- a/src/classes.jl
+++ b/src/classes.jl
@@ -2,39 +2,49 @@
# resurrecting it, please look at the repository at commit 22118319da.
function allocclass(name, super)
- ptr = ccall(:objc_allocateClassPair, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cchar}, Csize_t),
- super, name, 0)
+ ptr = ccall(
+ :objc_allocateClassPair, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cchar}, Csize_t),
+ super, name, 0
+ )
ptr == C_NULL && error("Couldn't allocate class $name")
return Class(ptr)
end
function register(class::Class)
- ccall(:objc_registerClassPair, Cvoid, (Ptr{Cvoid},),
- class)
+ ccall(
+ :objc_registerClassPair, Cvoid, (Ptr{Cvoid},),
+ class
+ )
return class
end
createclass(name, super) = allocclass(name, super) |> register
getmethod(class::Class, sel::Selector) =
- ccall(:class_getInstanceMethod, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}),
- class, sel)
+ ccall(
+ :class_getInstanceMethod, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}),
+ class, sel
+)
methodtypeenc(method::Ptr) =
- ccall(:method_getTypeEncoding, Ptr{Cchar}, (Ptr{Cvoid},),
- method) |> unsafe_string
+ ccall(
+ :method_getTypeEncoding, Ptr{Cchar}, (Ptr{Cvoid},),
+ method
+) |> unsafe_string
methodtypeenc(class::Class, sel::Selector) = methodtypeenc(getmethod(class, sel))
methodtype(args...) = methodtypeenc(args...) |> parseencoding
replacemethod(class::Class, sel::Selector, imp::Ptr{Cvoid}, types::String) =
- ccall(:class_replaceMethod, Bool, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cchar}),
- class, sel, imp, types)
+ ccall(
+ :class_replaceMethod, Bool, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cchar}),
+ class, sel, imp, types
+)
function setmethod(class::Class, sel::Selector, imp::Ptr{Cvoid}, types::String)
meth = getmethod(class, sel)
meth ≠ C_NULL && methodtype(meth) != parseencoding(types) &&
error("New method $(name(sel)) of $class must match $(methodtype(meth))")
- replacemethod(class, sel, imp, types)
+ return replacemethod(class, sel, imp, types)
end
diff --git a/src/foundation.jl b/src/foundation.jl
index aa72eff..25fe6da 100644
--- a/src/foundation.jl
+++ b/src/foundation.jl
@@ -34,7 +34,7 @@ export NSObject, retain, release, autorelease, is_kind_of
end
function Base.show(io::IO, ::MIME"text/plain", obj::NSObject)
- if get(io, :compact, false)
+ return if get(io, :compact, false)
print(io, String(obj.description))
else
print(io, String(obj.debugDescription))
@@ -50,11 +50,11 @@ retain(obj::NSObject) = @objc [obj::id{NSObject} retain]::Cvoid
ObjectiveC.class(obj::NSObject) = @objc [obj::id{NSObject} class]::Class
function is_kind_of(obj::NSObject, class::Class)
- @objc [obj::id{NSObject} isKindOfClass:class::Class]::Bool
+ return @objc [obj::id{NSObject} isKindOfClass:class::Class]::Bool
end
function Base.:(==)(obj1::NSObject, obj2::NSObject)
- @objc [obj1::id{NSObject} isEqual:obj2::id{NSObject}]::Bool
+ return @objc [obj1::id{NSObject} isEqual:obj2::id{NSObject}]::Bool
end
@@ -134,7 +134,7 @@ end
Base.isnan(dec::NSDecimal) = dec.length == 0 && dec.isNegative
function Base.show(io::IO, dec::NSDecimal)
- if isnan(dec)
+ return if isnan(dec)
print(io, "NaN")
else
print(io, "NSDecimal(", dec.mantissa, "e", dec.exponent, ")")
@@ -185,7 +185,7 @@ const NSNumberTypes = [
let
unique_number_types = Set{Type}(map(first, NSNumberTypes))
for T in unique_number_types
- i = findfirst(x->x[1] == T, NSNumberTypes)
+ i = findfirst(x -> x[1] == T, NSNumberTypes)
method = NSNumberTypes[i][2]
@eval NSNumber(x::$T) = NSNumber(@objc [NSNumber $method:x::$T]::id{NSNumber})
@eval Base.convert(::Type{NSNumber}, x::$T) = NSNumber(x)
@@ -308,7 +308,7 @@ end
Base.length(arr::NSArray) = Int(arr.count)
function Base.getindex(arr::NSArray, i::Int)
@boundscheck 1 <= i <= length(arr) || throw(BoundsError(arr, i))
- @objc [arr::id{NSArray} objectAtIndex:(i-1)::NSUInteger]::id{Object}
+ return @objc [arr::id{NSArray} objectAtIndex:(i - 1)::NSUInteger]::id{Object}
end
Base.iterate(arr::NSArray, i::Int=1) = i > length(arr) ? nothing : (arr[i], i+1)
@@ -318,7 +318,7 @@ Base.:(==)(a1::NSArray, a2::NSArray) =
# conversion to typed Julia array
function Base.convert(::Type{Vector{T}}, arr::NSArray) where {T}
- [reinterpret(T, arr[i]) for i in 1:length(arr)]
+ return [reinterpret(T, arr[i]) for i in 1:length(arr)]
end
Vector{T}(arr::NSArray) where {T} = convert(Vector{T}, arr)
@@ -357,8 +357,12 @@ end
# conversion to typed Julia dictionary
function Base.convert(::Type{Dict{K,V}}, dict::NSDictionary) where {K,V}
- Dict{K,V}(zip(map(Base.Fix1(reinterpret, K), keys(dict)),
- map(Base.Fix1(reinterpret, V), values(dict))))
+ return Dict{K, V}(
+ zip(
+ map(Base.Fix1(reinterpret, K), keys(dict)),
+ map(Base.Fix1(reinterpret, V), values(dict))
+ )
+ )
end
Dict{K,V}(dict::NSDictionary) where {K,V} = convert(Dict{K,V}, dict)
@@ -379,16 +383,20 @@ end
# TODO: userInfo
function NSError(domain, code)
- err = @objc [NSError errorWithDomain:domain::id{NSString}
- code:code::NSInteger
- userInfo:nil::id{NSDictionary}]::id{NSError}
+ err = @objc [
+ NSError errorWithDomain:domain::id{NSString}
+ code:code::NSInteger
+ userInfo:nil::id{NSDictionary}
+ ]::id{NSError}
return NSError(err)
end
function NSError(domain, code, userInfo)
- err = @objc [NSError errorWithDomain:domain::id{NSString}
- code:code::NSInteger
- userInfo:userInfo::id{NSDictionary}]::id{NSError}
+ err = @objc [
+ NSError errorWithDomain:domain::id{NSString}
+ code:code::NSInteger
+ userInfo:userInfo::id{NSDictionary}
+ ]::id{NSError}
return NSError(err)
end
@@ -400,7 +408,7 @@ function Base.showerror(io::IO, err::NSError)
end
recovery_options = err.localizedRecoveryOptions
- if recovery_options !== nothing
+ return if recovery_options !== nothing
print(io, "\nRecovery Options:")
for option in recovery_options
print(io, "\n - $(option)")
@@ -431,12 +439,12 @@ export NSBundle, load_framework
function NSBundle(path::Union{String,NSString})
ptr = @objc [NSBundle bundleWithPath:path::id{NSString}]::id{NSBundle}
ptr == nil && error("Couldn't find bundle '$path'")
- NSBundle(ptr)
+ return NSBundle(ptr)
end
function load(bundle::NSBundle)
loaded = @objc [bundle::id{NSBundle} load]::Bool
- loaded || error("Couldn't load bundle")
+ return loaded || error("Couldn't load bundle")
end
load_framework(name) = load(NSBundle("/System/Library/Frameworks/$name.framework"))
@@ -462,7 +470,7 @@ export NSURL, NSFileURL
@autoproperty parameterString::id{NSString}
@autoproperty password::id{NSString}
@autoproperty path::id{NSString}
- @autoproperty pathComponents::id{NSArray} type=Vector{NSString}
+ @autoproperty pathComponents::id{NSArray} type = Vector{NSString}
@autoproperty pathExtension::id{NSString}
@autoproperty port::id{NSNumber}
@autoproperty query::id{NSString}
@@ -479,15 +487,15 @@ export NSURL, NSFileURL
end
function NSURL(str::Union{String,NSString})
- NSURL(@objc [NSURL URLWithString:str::id{NSString}]::id{NSURL})
+ return NSURL(@objc [NSURL URLWithString:str::id{NSString}]::id{NSURL})
end
function NSFileURL(path::Union{String,NSString})
- NSURL(@objc [NSURL fileURLWithPath:path::id{NSString}]::id{NSURL})
+ return NSURL(@objc [NSURL fileURLWithPath:path::id{NSString}]::id{NSURL})
end
function Base.:(==)(a::NSURL, b::NSURL)
- @objc [a::id{NSURL} isEqual:b::id{NSURL}]::Bool
+ return @objc [a::id{NSURL} isEqual:b::id{NSURL}]::Bool
end
@@ -536,7 +544,7 @@ function NSAutoreleasePool()
@objc [obj::id{NSAutoreleasePool} init]::id{NSAutoreleasePool}
# NOTE: we don't register a finalizer, as it's better to drain the pool,
# and it's not allowed to both drain and release.
- obj
+ return obj
end
drain(pool::NSAutoreleasePool) = @objc [pool::id{NSAutoreleasePool} drain]::Cvoid
@@ -561,7 +569,7 @@ See also: [`@autoreleasepool`](@ref)
function NSAutoreleasePool(f::Base.Callable)
# we cannot switch between multiple autorelease pools, so ensure only one is ever active.
# XXX: support multiple pools, as long as they run on separate threads?
- Base.@lock NSAutoreleaseLock begin
+ return Base.@lock NSAutoreleaseLock begin
# autorelease pools are thread-bound, so ensure we don't migrate to another thread
task = current_task()
sticky = task.sticky
@@ -582,7 +590,7 @@ const NSAutoreleaseLock = ReentrantLock()
function NSUnsafeAutoreleasePool(f::Base.Callable)
pool = NSAutoreleasePool()
- try
+ return try
f()
finally
drain(pool)
@@ -603,7 +611,7 @@ See also: [`NSAutoreleasePool`](@ref)
"""
macro autoreleasepool(ex...)
code = ex[end]
- kwargs = ex[1:end-1]
+ kwargs = ex[1:(end - 1)]
# extract keyword arguments that are handled by this macro
unsafe = false
@@ -622,8 +630,8 @@ macro autoreleasepool(ex...)
end
f = unsafe ? NSUnsafeAutoreleasePool : NSAutoreleasePool
- if Meta.isexpr(code, :(=)) &&
- (Meta.isexpr(code.args[1], :call) || Meta.isexpr(code.args[1], :where))
+ return if Meta.isexpr(code, :(=)) &&
+ (Meta.isexpr(code.args[1], :call) || Meta.isexpr(code.args[1], :where))
# function definition, short form
sig, body = code.args
@assert Meta.isexpr(body, :block)
diff --git a/src/methods.jl b/src/methods.jl
index beadf57..bc05ce4 100644
--- a/src/methods.jl
+++ b/src/methods.jl
@@ -1,8 +1,10 @@
export signature
method(class::Class, sel::Selector) =
- ccall(:class_getInstanceMethod, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}),
- class, sel)
+ ccall(
+ :class_getInstanceMethod, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}),
+ class, sel
+)
method(obj::Object, sel::Selector) =
method(class(obj), sel)
@@ -11,8 +13,10 @@ types(m::Ptr) =
ccall(:method_getTypeEncoding, Ptr{Cchar}, (Ptr{Cvoid},), m) |> unsafe_string
implementation(m::Ptr) =
- ccall(:method_getImplementation, Ptr{Cvoid}, (Ptr{Cvoid},),
- m)
+ ccall(
+ :method_getImplementation, Ptr{Cvoid}, (Ptr{Cvoid},),
+ m
+)
# From https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html
const typeencodings = Dict('c' => Cchar,
@@ -72,7 +76,7 @@ signature(m::Ptr) = m |> types |> parseencoding
function signature(class::Class, sel::Selector)
m = method(class, sel)
m == C_NULL && error("$class doesn't respond to $sel")
- signature(m)
+ return signature(m)
end
signature(obj::Object, sel::Selector) =
diff --git a/src/primitives.jl b/src/primitives.jl
index c64a56e..ad62fc5 100644
--- a/src/primitives.jl
+++ b/src/primitives.jl
@@ -17,18 +17,18 @@ end
Base.unsafe_convert(::Type{Ptr{Cvoid}}, sel::Selector) = sel.ptr
function Selector(name)
- Selector(ccall(:sel_registerName, Ptr{Cvoid}, (Ptr{Cchar},), name))
+ return Selector(ccall(:sel_registerName, Ptr{Cvoid}, (Ptr{Cchar},), name))
end
macro sel_str(name)
- Selector(name)
+ return Selector(name)
end
name(sel::Selector) = selname(sel.ptr)
function Base.show(io::IO, sel::Selector)
print(io, "sel")
- show(io, string(name(sel)))
+ return show(io, string(name(sel)))
end
@@ -52,31 +52,37 @@ end
classexists(name) = classptr(name) ≠ C_NULL
name(class::Class) =
- ccall(:class_getName, Ptr{Cchar}, (Ptr{Cvoid},),
- class) |> unsafe_string |> Symbol
+ ccall(
+ :class_getName, Ptr{Cchar}, (Ptr{Cvoid},),
+ class
+) |> unsafe_string |> Symbol
ismeta(class::Class) = ccall(:class_isMetaClass, Bool, (Ptr{Cvoid},), class)
function Base.supertype(class::Class)
- ptr = ccall(:class_getSuperclass, Ptr{Cvoid}, (Ptr{Cvoid},),
- class.ptr)
+ ptr = ccall(
+ :class_getSuperclass, Ptr{Cvoid}, (Ptr{Cvoid},),
+ class.ptr
+ )
ptr == C_NULL && return nothing
- Class(ptr)
+ return Class(ptr)
end
function Base.show(io::IO, class::Class)
ismeta(class) && print(io, "^")
- print(io, name(class))
+ return print(io, name(class))
end
function Base.methods(class::Class)
count = Cuint[0]
- meths = ccall(:class_copyMethodList, Ptr{Ptr{Cvoid}}, (Ptr{Cvoid}, Ptr{Cuint}),
- class, count)
- meths′ = [unsafe_load(meths, i) for i = 1:count[1]]
+ meths = ccall(
+ :class_copyMethodList, Ptr{Ptr{Cvoid}}, (Ptr{Cvoid}, Ptr{Cuint}),
+ class, count
+ )
+ meths′ = [unsafe_load(meths, i) for i in 1:count[1]]
Libc.free(meths)
meths = [ccall(:method_getName, Ptr{Cvoid}, (Ptr{Cvoid},), meth) for meth in meths′]
- return map(meth->selname(meth), meths)
+ return map(meth -> selname(meth), meths)
end
@@ -100,11 +106,13 @@ end
protoexists(name) = protoptr(name) ≠ C_NULL
name(proto::Protocol) =
- ccall(:protocol_getName, Ptr{Cchar}, (Ptr{Cvoid},),
- proto) |> unsafe_string |> Symbol
+ ccall(
+ :protocol_getName, Ptr{Cchar}, (Ptr{Cvoid},),
+ proto
+) |> unsafe_string |> Symbol
function Base.show(io::IO, proto::Protocol)
- print(io, name(proto))
+ return print(io, name(proto))
end
@@ -134,7 +142,7 @@ function Base.convert(::Type{id{T}}, x::id{U}) where {T,U}
x == nil && return Base.bitcast(id{T}, nil)
# otherwise, types must match (i.e., only allow converting to a supertype)
U <: T || throw(ArgumentError("Cannot convert id{$U} to id{$T}"))
- Base.bitcast(id{T}, x)
+ return Base.bitcast(id{T}, x)
end
# conversion to integer
diff --git a/src/syntax.jl b/src/syntax.jl
index 029b7eb..4458ea4 100644
--- a/src/syntax.jl
+++ b/src/syntax.jl
@@ -8,7 +8,7 @@ callerror(msg) = error("""ObjectiveC call: $msg
# convert a vcat to a hcat so that we can split the @objc expressions into multiple lines
function flatvcat(ex::Expr)
- any(ex->Meta.isexpr(ex, :row), ex.args) || return ex
+ any(ex -> Meta.isexpr(ex, :row), ex.args) || return ex
flat = Expr(:hcat)
for row in ex.args
Meta.isexpr(row, :row) ?
@@ -108,14 +108,14 @@ end
# argument renderers, for tracing functionality
render(io, obj) = Core.print(io, repr(obj))
function render(io, ptr::id{T}) where T
- Core.print(io, "(id<", String(T.name.name), ">)0x", string(UInt(ptr), base=16, pad = Sys.WORD_SIZE>>2))
+ return Core.print(io, "(id<", String(T.name.name), ">)0x", string(UInt(ptr), base = 16, pad = Sys.WORD_SIZE >> 2))
end
function render(io, ptr::Ptr{T}) where T
- Core.print(io, "(", String(T.name.name), "*)0x", string(UInt(ptr), base=16, pad = Sys.WORD_SIZE>>2))
+ return Core.print(io, "(", String(T.name.name), "*)0x", string(UInt(ptr), base = 16, pad = Sys.WORD_SIZE >> 2))
end
## mimic ccall's conversion
function render_c_arg(io, obj, typ)
- GC.@preserve obj begin
+ return GC.@preserve obj begin
ptr = Base.unsafe_convert(typ, Base.cconvert(typ, obj))
render(io, ptr)
end
@@ -154,14 +154,18 @@ function make_gcsafe(ex)
end
# emit a gcsafe ccall
- append!(code.args, (quote
- GC.@preserve $(vars...) begin
- gc_state = ccall(:jl_gc_safe_enter, Int8, ())
- ret = ccall($target, $rettyp, ($(argtypes...),), $(converted...))
- ccall(:jl_gc_safe_leave, Cvoid, (Int8,), gc_state)
- ret
- end
- end).args)
+ append!(
+ code.args, (
+ quote
+ GC.@preserve $(vars...) begin
+ gc_state = ccall(:jl_gc_safe_enter, Int8, ())
+ ret = ccall($target, $rettyp, ($(argtypes...),), $(converted...))
+ ccall(:jl_gc_safe_leave, Cvoid, (Int8,), gc_state)
+ ret
+ end
+ end
+ ).args
+ )
return code
end
@@ -252,7 +256,7 @@ end
# TODO: support availability
macro objc(ex)
- objcm(__module__, ex)
+ return objcm(__module__, ex)
end
# Wrapper Classes
@@ -285,7 +289,7 @@ keyword arguments:
"""
macro objcwrapper(ex...)
def = ex[end]
- kwargs = ex[1:end-1]
+ kwargs = ex[1:(end - 1)]
# parse kwargs
comparison = nothing
@@ -357,7 +361,7 @@ macro objcwrapper(ex...)
end
ptr == nil && throw(UndefRefError())
- $instance(ptr)
+ return $instance(ptr)
end
end
@@ -371,7 +375,7 @@ macro objcwrapper(ex...)
end
end
- esc(ex)
+ return esc(ex)
end
Base.pointer(obj::Object) = obj.ptr
@@ -581,7 +585,7 @@ macro objcproperties(typ, ex)
return properties
end
function Base.propertynames(::$(esc(typ)))
- $ObjectiveC.objc_propertynames($(esc(typ)))
+ return $ObjectiveC.objc_propertynames($(esc(typ)))
end
end
@@ -602,9 +606,13 @@ macro objcproperties(typ, ex)
end
# finally, call our parent's `getproperty`
- final = :(@inline invoke(getproperty,
- Tuple{supertype($(esc(typ))), Symbol},
- object, field))
+ final = :(
+ @inline invoke(
+ getproperty,
+ Tuple{supertype($(esc(typ))), Symbol},
+ object, field
+ )
+ )
push!(current.args, final)
getproperties_ex = quote
# XXX: force const-prop on field, without inlining everything?
@@ -631,9 +639,13 @@ macro objcproperties(typ, ex)
end
# finally, call our parent's `setproperty!`
- final = :(@inline invoke(setproperty!,
- Tuple{supertype($(esc(typ))), Symbol, Any},
- object, field, value))
+ final = :(
+ @inline invoke(
+ setproperty!,
+ Tuple{supertype($(esc(typ))), Symbol, Any},
+ object, field, value
+ )
+ )
push!(current.args, final)
setproperties_ex = quote
# XXX: force const-prop on field, without inlining everything? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #58 +/- ##
==========================================
+ Coverage 71.91% 77.73% +5.82%
==========================================
Files 10 13 +3
Lines 769 988 +219
==========================================
+ Hits 553 768 +215
- Misses 216 220 +4 ☔ View full report in Codecov by Sentry. |
Error is #53 |
Use 4 spaces for indentation instead of sometimes 2 and sometimes 4.
Same as JuliaGPU/Metal.jl#545 but for this repo.
Ideally not squashed so that only the second commit ("Indentation fixes") gets added to the .git-blame-ignore-revs file that I'll add once this is merged