]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/deprecation/deprecation.factor
change add-init-hook to add-startup-hook, new add-shutdown-hook word
[factor.git] / basis / tools / deprecation / deprecation.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: accessors arrays assocs combinators.short-circuit
3 compiler.units debugger init io
4 io.streams.null kernel namespaces prettyprint sequences
5 source-files.errors summary tools.crossref
6 tools.crossref.private tools.errors words ;
7 IN: tools.deprecation
8
9 SYMBOL: +deprecation-note+
10 SYMBOL: deprecation-notes
11
12 deprecation-notes [ H{ } clone ] initialize
13
14 TUPLE: deprecation-note < source-file-error ;
15
16 M: deprecation-note error-type drop +deprecation-note+ ;
17
18 TUPLE: deprecated-usages asset usages ;
19
20 : :deprecations ( -- )
21     deprecation-notes get-global values errors. ;
22
23 T{ error-type
24     { type +deprecation-note+ }
25     { word ":deprecations" }
26     { plural "deprecated word usages" }
27     { icon "vocab:ui/tools/error-list/icons/deprecation-note.tiff" }
28     { quot [ deprecation-notes get values ] }
29     { forget-quot [ deprecation-notes get delete-at ] }
30 } define-error-type
31
32 : <deprecation-note> ( error word -- deprecation-note )
33     \ deprecation-note <definition-error> ;
34
35 : deprecation-note ( word usages -- )
36     [ deprecated-usages boa ]
37     [ drop <deprecation-note> ]
38     [ drop deprecation-notes get-global set-at ] 2tri ;
39
40 : clear-deprecation-note ( word -- )
41     deprecation-notes get-global delete-at ;
42
43 : check-deprecations ( usage -- )
44     dup word? [
45         dup { [ "forgotten" word-prop ] [ deprecated? ] } 1||
46         [ clear-deprecation-note ] [
47             dup def>> uses [ deprecated? ] filter
48             [ clear-deprecation-note ] [ >array deprecation-note ] if-empty
49         ] if
50     ] [ drop ] if ;
51
52 M: deprecated-usages summary
53     drop "Deprecated words used" ;
54
55 M: deprecated-usages error.
56     "The definition of " write
57     dup asset>> pprint
58     " uses these deprecated words:" write nl
59     usages>> [ "    " write pprint nl ] each ;
60
61 SINGLETON: deprecation-observer
62
63 : initialize-deprecation-notes ( -- )
64     [
65         get-crossref [ drop deprecated? ] assoc-filter
66         values [ keys [ check-deprecations ] each ] each
67     ] with-null-writer ;
68
69 M: deprecation-observer definitions-changed
70     drop keys [ word? ] filter
71     dup [ deprecated? ] filter empty?
72     [ [ check-deprecations ] each ]
73     [ drop initialize-deprecation-notes ] if ;
74
75 [ \ deprecation-observer add-definition-observer ] 
76 "tools.deprecation" add-startup-hook
77
78 initialize-deprecation-notes