@@ -40,8 +40,8 @@ def self.interval(conditions)
4040 # 分解して境界に寄与させる。分解できない連言子は寄与しない(保守的に広く扱う。
4141 # 恒偽の証明は Scope#never? が連言子単位で別途行う)
4242 def self . bounds ( conditions )
43- sinces = [ ]
44- untils = [ ]
43+ sinces = [ ] #: Array[bound]
44+ untils = [ ] #: Array[bound]
4545 conditions . each do |c |
4646 case c . kind
4747 when :since then sinces << [ Gem ::Version . new ( c . version ) , c . version ]
@@ -60,7 +60,7 @@ def self.bounds(conditions)
6060 # <= や否定(#@else 反転)は正確に表現できないので分解しない
6161 def self . if_bounds ( expr )
6262 return [ ] if expr . lstrip . start_with? ( '!' )
63- bounds = [ ]
63+ bounds = [ ] #: Array[[Symbol, String?]]
6464 expr . split ( /\b and\b / ) . each do |c |
6565 case c
6666 when /version\s *<\s *"([\d .]+)"/ then bounds << [ :until , $1]
@@ -142,7 +142,7 @@ def never_conjunct?(conjunct)
142142 def gate ( conditions )
143143 return nil unless cover? ( conditions )
144144 lo , hi = IncludeGraph . bounds ( conditions )
145- gate = { }
145+ gate = { } #: IncludeGraph::gate
146146 gate [ :since ] = lo [ 1 ] if lo && lo [ 0 ] > @lo
147147 gate [ :until ] = hi [ 1 ] if hi && hi [ 0 ] < @hi
148148 gate
@@ -199,7 +199,7 @@ def grouping_include_sites
199199 # LIBRARIES 内の版ゲート(fiber: until 3.1 等)をスコープ適用して付与する。
200200 # スコープ外のライブラリ(cmath/scanf/sync 等)は含まない。
201201 def library_front_matter_map ( scope )
202- result = { }
202+ result = { } #: Hash[String, Hash[String, String]]
203203 @library_gates . each do |name , gate |
204204 root = "#{ name } .rd"
205205 scoped = scope . gate ( gate )
@@ -227,7 +227,7 @@ def library_front_matter_map(scope)
227227 # - 同一ライブラリ内の複数 include サイトは、いずれかが有効なら
228228 # エンティティが存在するため、ゲートは区間の hull(弱い方)を取る
229229 def front_matter_map ( scope )
230- result = { }
230+ result = { } #: Hash[String, front_matter]
231231 groupings . each do |path , ms |
232232 covered = ms . select { |m | scope . cover? ( m . conditions ) }
233233 next if covered . empty?
@@ -264,16 +264,16 @@ def hull(gates)
264264 return { } if gates . any? ( &:empty? )
265265 sinces = gates . map { |g | g [ :since ] }
266266 untils = gates . map { |g | g [ :until ] }
267- result = { }
267+ result = { } #: gate
268268 result [ :since ] = sinces . min_by { |v | Gem ::Version . new ( v ) } if sinces . all?
269269 result [ :until ] = untils . max_by { |v | Gem ::Version . new ( v ) } if untils . all?
270270 result
271271 end
272272
273273 # LIBRARIES を版ゲート付きで読む。 [[name, [Condition]], ...]
274274 def read_libraries
275- entries = { }
276- stack = [ ]
275+ entries = { } #: Hash[String, Array[Condition]]
276+ stack = [ ] #: Array[Condition]
277277 File . foreach ( File . join ( @src_root , 'LIBRARIES' ) ) do |line |
278278 line = line . chomp
279279 if line . start_with? ( '#@#' ) || apply_directive ( stack , line )
@@ -292,7 +292,7 @@ def apply_directive(stack, line)
292292 case line
293293 when /\A \# @since\s +(\S +)/ then stack . push ( Condition . new ( :since , $1) )
294294 when /\A \# @until\s +(\S +)/ then stack . push ( Condition . new ( :until , $1) )
295- when /\A \# @if\s *(.*)/ then stack . push ( Condition . new ( :if , $1 . strip ) )
295+ when /\A \# @if\s *(.*)/ then stack . push ( Condition . new ( :if , ( $1 || raise ) . strip ) )
296296 when /\A \# @samplecode\b / then stack . push ( Condition . new ( :samplecode , nil ) )
297297 when /\A \# @else\b / then ( cond = stack . pop ) && stack . push ( invert ( cond ) )
298298 when /\A \# @end\b / then stack . pop
@@ -313,12 +313,12 @@ def invert(cond)
313313 # relpath のファイル内の #@include を条件スタック付きで走査する。
314314 # base_conditions は LIBRARIES ゲート+ここまでの include 経路の条件。
315315 def walk ( relpath , library , base_conditions , path_stack )
316- stack = [ ]
316+ stack = [ ] #: Array[Condition]
317317 File . foreach ( File . join ( @src_root , relpath ) ) do |line |
318318 line = line . chomp
319319 if line =~ /\A \# @include\s *\( (.*?)\) /
320320 conditions = ( base_conditions + stack ) . reject { |c | c . kind == :samplecode }
321- add_include ( relpath , $1, library , conditions , path_stack )
321+ add_include ( relpath , $1 || raise , library , conditions , path_stack )
322322 else
323323 apply_directive ( stack , line )
324324 end
0 commit comments