File tree Expand file tree Collapse file tree 7 files changed +49
-5
lines changed Expand file tree Collapse file tree 7 files changed +49
-5
lines changed Original file line number Diff line number Diff line change 22* .jl. * .cov
33* .jl.mem
44deps /deps.jl
5+ docs /build
Original file line number Diff line number Diff line change 1+ [deps ]
2+ Documenter = " e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
4+ [compat ]
5+ Documenter = " ~0.20"
Original file line number Diff line number Diff line change 1+ using Documenter, Classes
2+
3+ makedocs (
4+ modules = [Classes],
5+ sitename = " Classes.jl" ,
6+ pages = [
7+ " Home" => " index.md" ,
8+ ],
9+
10+ format = Documenter. HTML (prettyurls = get (ENV , " JULIA_NO_LOCAL_PRETTY_URLS" , nothing ) === nothing )
11+ )
12+
13+ deploydocs (
14+ repo = " github.com/rjplevin/Classes.jl.git" ,
15+ )
Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ using Classes
201201
202202 # Although Foo is immutable, subclasses might not be,
203203 # so it's still useful to define this method.
204- function Foo (self:: absclass (Foo) )
204+ function Foo (self:: AbstractFoo )
205205 self. foo = 0
206206 end
207207end
210210 bar:: Int
211211
212212 # Mutable classes can use this pattern
213- function Bar (self:: Union{Nothing, absclass(Bar) } = nothing )
213+ function Bar (self:: Union{Nothing, AbstractBar } = nothing )
214214 self = (self === nothing ? new () : self)
215215 superclass (Bar)(self)
216216 Bar (self, 0 )
Original file line number Diff line number Diff line change 6767# If a symbol is already a gensym, extract the symbol and re-gensym with it
6868regensym (s) = MacroTools. isgensym (s) ? gensym (Symbol (MacroTools. gensymname (s))) : gensym (s)
6969
70+ _cache = nothing
71+
7072# Return info about a class in a named tuple
7173function _class_info (:: Type{T} ) where {T <: AbstractClass }
74+ global _cache
75+ _cache === nothing && (_cache = Dict ())
76+ haskey (_cache, T) && return _cache[T]
77+
78+ # @info "_class_info($T)"
79+
7280 typ = (typeof (T) === UnionAll ? Base. unwrap_unionall (T) : T)
7381
7482 # note: must extract symbol from type to create required expression
@@ -79,7 +87,9 @@ function _class_info(::Type{T}) where {T <: AbstractClass}
7987 ivars = [_translate_ivar (d, iv) for iv in ivars] # translate types to use gensyms
8088 wheres = [_translate_where (d, w) for w in wheres]
8189
82- return (wheres= wheres, ivars= ivars, super= superclass (typ))
90+ result = (wheres= wheres, ivars= ivars, super= superclass (typ))
91+ _cache[T] = result
92+ return result
8393end
8494
8595"""
Original file line number Diff line number Diff line change 1+ abstract type A end
2+ struct B <: A
3+ i:: Int
4+ end
5+
6+ expr1 = :(struct Foo1 i:: B end )
7+
8+ class = B
9+ expr2 = :(struct Foo2 i:: $class end )
10+
11+ dump (expr1)
12+
13+ dump (expr2)
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ using Classes
1313
1414 # Although Foo is immutable, subclasses might not be,
1515 # so it's still useful to define this method.
16- function Foo (self:: absclass (Foo) )
16+ function Foo (self:: AbstractFoo )
1717 self. foo = 0
1818 end
1919end
2828 bar:: Int
2929
3030 # Mutable classes can use this pattern
31- function Bar (self:: Union{Nothing, absclass(Bar) } = nothing )
31+ function Bar (self:: Union{Nothing, AbstractBar } = nothing )
3232 self = (self === nothing ? new () : self)
3333 superclass (Bar)(self)
3434 Bar (self, 0 )
You can’t perform that action at this time.
0 commit comments