1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs combinators.short-circuit
4 compiler.units debugger init io io.streams.null kernel
5 namespaces prettyprint sequences sets source-files.errors
6 summary tools.crossref tools.crossref.private tools.errors
10 SYMBOL: +deprecation-note+
11 SYMBOL: deprecation-notes
13 deprecation-notes [ H{ } clone ] initialize
15 TUPLE: deprecation-note < source-file-error ;
17 M: deprecation-note error-type drop +deprecation-note+ ;
19 TUPLE: deprecated-usages asset usages ;
21 : :deprecations ( -- )
22 deprecation-notes get-global values errors. ;
25 { type +deprecation-note+ }
26 { word ":deprecations" }
27 { plural "deprecated word usages" }
28 { icon "vocab:ui/tools/error-list/icons/deprecation-note.png" }
29 { quot [ deprecation-notes get values ] }
30 { forget-quot [ deprecation-notes get delete-at ] }
34 : <deprecation-note> ( error word -- deprecation-note )
35 deprecation-note new-source-file-error ;
37 : store-deprecation-note ( word usages -- )
38 over [ deprecated-usages boa ] dip
39 [ <deprecation-note> ]
40 [ deprecation-notes get-global set-at ] bi ;
42 : clear-deprecation-note ( word -- )
43 deprecation-notes get-global delete-at ;
45 : check-deprecations ( usage -- )
47 dup { [ "forgotten" word-prop ] [ deprecated? ] } 1||
48 [ clear-deprecation-note ] [
49 dup def>> uses [ deprecated? ] filter
50 [ clear-deprecation-note ]
51 [ store-deprecation-note ] if-empty
55 M: deprecated-usages summary
56 drop "Deprecated words used" ;
58 M: deprecated-usages error.
59 "The definition of " write
61 " uses these deprecated words:" write nl
62 usages>> [ " " write pprint nl ] each ;
64 SINGLETON: deprecation-observer
66 : initialize-deprecation-notes ( -- )
68 get-crossref [ drop deprecated? ] assoc-filter
69 values [ members [ check-deprecations ] each ] each
72 M: deprecation-observer definitions-changed
74 dup [ deprecated? ] none?
75 [ [ check-deprecations ] each ]
76 [ drop initialize-deprecation-notes ] if ;
78 [ deprecation-observer add-definition-observer ]
79 "tools.deprecation" add-startup-hook
81 initialize-deprecation-notes