]> gitweb.factorcode.org Git - factor.git/commitdiff
"deprecated" declaration, "deprecation" vocab to track deprecations in the error log
authorJoe Groff <arcata@gmail.com>
Thu, 20 Aug 2009 20:10:42 +0000 (15:10 -0500)
committerJoe Groff <arcata@gmail.com>
Thu, 20 Aug 2009 20:10:42 +0000 (15:10 -0500)
basis/deprecation/authors.txt [new file with mode: 0644]
basis/deprecation/deprecation.factor [new file with mode: 0644]
basis/deprecation/summary.txt [new file with mode: 0644]
basis/see/see.factor
basis/ui/tools/error-list/icons/deprecation-note.tiff [new file with mode: 0644]
core/bootstrap/syntax.factor
core/syntax/syntax-docs.factor
core/syntax/syntax.factor
core/words/words-docs.factor
core/words/words.factor

diff --git a/basis/deprecation/authors.txt b/basis/deprecation/authors.txt
new file mode 100644 (file)
index 0000000..f13c9c1
--- /dev/null
@@ -0,0 +1 @@
+Joe Groff
diff --git a/basis/deprecation/deprecation.factor b/basis/deprecation/deprecation.factor
new file mode 100644 (file)
index 0000000..4774ba7
--- /dev/null
@@ -0,0 +1,72 @@
+! (c)2009 Joe Groff bsd license
+USING: accessors arrays assocs compiler.units
+debugger io kernel namespaces prettyprint sequences
+source-files.errors summary tools.crossref.private
+tools.errors words ;
+IN: deprecation
+
+SYMBOL: +deprecation-note+
+SYMBOL: deprecation-notes
+
+deprecation-notes [ H{ } clone ] initialize
+
+TUPLE: deprecation-note < source-file-error ;
+
+M: deprecation-note error-type drop +deprecation-note+ ;
+
+TUPLE: deprecated-usages asset usages ;
+
+: :deprecations ( -- )
+    deprecation-notes get-global values errors. ;
+
+T{ error-type
+    { type +deprecation-note+ }
+    { word ":deprecations" }
+    { plural "deprecated word usages" }
+    { icon "vocab:ui/tools/error-list/icons/deprecation-note.tiff" }
+    { quot [ deprecation-notes get values ] }
+    { forget-quot [ deprecation-notes get delete-at ] }
+} define-error-type
+
+: <deprecation-note> ( error word -- deprecation-note )
+    \ deprecation-note <definition-error> ;
+
+: deprecation-note ( word usages -- )
+    [ deprecated-usages boa ]
+    [ drop <deprecation-note> ]
+    [ drop deprecation-notes get-global set-at ] 2tri ;
+
+: clear-deprecation-note ( word -- )
+    deprecation-notes get-global delete-at ;
+
+: check-deprecations ( word -- )
+    dup "forgotten" word-prop
+    [ clear-deprecation-note ] [
+        dup def>> [ deprecated? ] filter
+        [ clear-deprecation-note ] [ >array deprecation-note ] if-empty
+    ] if ;
+
+M: deprecated-usages summary
+    drop "Deprecated words used" ;
+
+M: deprecated-usages error.
+    "The definition of " write
+    dup asset>> pprint
+    " uses these deprecated words:" write nl
+    usages>> [ "    " write pprint nl ] each ;
+
+SINGLETON: deprecation-observer
+
+: initialize-deprecation-notes ( -- )
+    get-crossref [ drop deprecated? ] assoc-filter
+    values [ keys [ check-deprecations ] each ] each ;
+
+M: deprecation-observer definitions-changed
+    drop keys [ word? ] filter
+    dup [ deprecated? ] filter empty?
+    [ [ check-deprecations ] each ]
+    [ drop initialize-deprecation-notes ] if ;
+
+\ deprecation-observer add-definition-observer
+
+initialize-deprecation-notes
diff --git a/basis/deprecation/summary.txt b/basis/deprecation/summary.txt
new file mode 100644 (file)
index 0000000..513938d
--- /dev/null
@@ -0,0 +1 @@
+Tracking usage of deprecated words
index 206bdbb9065ef0aaf5d1f938707dbb315153af92..1b3bd4bfb5a18767bd5e88d559f30dcc6f8ca9d4 100644 (file)
@@ -101,6 +101,7 @@ M: object declarations. drop ;
 M: word declarations.
     {
         POSTPONE: delimiter
+        POSTPONE: deprecated
         POSTPONE: inline
         POSTPONE: recursive
         POSTPONE: foldable
@@ -229,4 +230,4 @@ PRIVATE>
     ] { } make prune ;
 
 : see-methods ( word -- )
-    methods see-all nl ;
\ No newline at end of file
+    methods see-all nl ;
diff --git a/basis/ui/tools/error-list/icons/deprecation-note.tiff b/basis/ui/tools/error-list/icons/deprecation-note.tiff
new file mode 100644 (file)
index 0000000..1eef0ef
Binary files /dev/null and b/basis/ui/tools/error-list/icons/deprecation-note.tiff differ
index f5182a02100b548208c4e4355870680eee642b51..906b73934e9b26a1a2137e6b8faab200baee3e10 100644 (file)
@@ -67,6 +67,7 @@ IN: bootstrap.syntax
     "M\\"
     "]"
     "delimiter"
+    "deprecated"
     "f"
     "flushable"
     "foldable"
index 70905ceda95b5132c363b8d0def2f45345c836de..320387e50666087daeaf28a9423747cc3e892d44 100644 (file)
@@ -191,6 +191,10 @@ HELP: delimiter
 { $syntax ": foo ... ; delimiter" }
 { $description "Declares the most recently defined word as a delimiter. Delimiters are words which are only ever valid as the end of a nested block to be read by " { $link parse-until } ". An unpaired occurrence of a delimiter is a parse error." } ;
 
+HELP: deprecated
+{ $syntax ": foo ... ; deprecated" }
+{ $description "Declares the most recently defined word as deprecated. If the " { $vocab-link "deprecation" } " vocabulary is loaded, usages of deprecated words will be noted as they are made." } ;
+
 HELP: SYNTAX:
 { $syntax "SYNTAX: foo ... ;" }
 { $description "Defines a parsing word." }
index 7b9a0d36efc93512d32d466f3318dbbbcb2616e6..f01f90c027dae0c7a7419d1113a926ac0f32b21a 100644 (file)
@@ -111,6 +111,7 @@ IN: bootstrap.syntax
     "foldable" [ word make-foldable ] define-core-syntax
     "flushable" [ word make-flushable ] define-core-syntax
     "delimiter" [ word t "delimiter" set-word-prop ] define-core-syntax
+    "deprecated" [ word make-deprecated ] define-core-syntax
 
     "SYNTAX:" [
         CREATE-WORD parse-definition define-syntax
index 806d09bf9ecc6e926eb2ddc1f683afb3076e43c9..b756c0b681a8ed631de701a3cb98c66890e5051a 100644 (file)
@@ -294,6 +294,16 @@ HELP: delimiter?
 { $description "Tests if an object is a delimiter word declared by " { $link POSTPONE: delimiter } "." }
 { $notes "Outputs " { $link f } " if the object is not a word." } ;
 
+HELP: deprecated?
+{ $values { "obj" object } { "?" "a boolean" } }
+{ $description "Tests if an object is " { $link POSTPONE: deprecated } "." }
+{ $notes "Outputs " { $link f } " if the object is not a word." } ;
+
+HELP: make-deprecated
+{ $values { "word" word } }
+{ $description "Declares a word as " { $link POSTPONE: deprecated } "." }
+{ $side-effects "word" } ;
+
 HELP: make-flushable
 { $values { "word" word } }
 { $description "Declares a word as " { $link POSTPONE: flushable } "." }
index 19a2ce551d0ee9263d65b3798e09139154c9ddcf..df5bc84edef5cd8a6a7bdc3cb46626f01cc09023 100755 (executable)
@@ -123,6 +123,9 @@ M: word subwords drop f ;
 : define-declared ( word def effect -- )
     [ nip swap set-stack-effect ] [ drop define ] 3bi ;
 
+: make-deprecated ( word -- )
+    t "deprecated" set-word-prop ;
+
 : make-inline ( word -- )
     dup inline? [ drop ] [
         [ t "inline" set-word-prop ]
@@ -148,7 +151,7 @@ M: word reset-word
     {
         "unannotated-def" "parsing" "inline" "recursive"
         "foldable" "flushable" "reading" "writing" "reader"
-        "writer" "delimiter"
+        "writer" "delimiter" "deprecated"
     } reset-props ;
 
 : reset-generic ( word -- )
@@ -200,6 +203,9 @@ M: parsing-word definer drop \ SYNTAX: \ ; ;
 : delimiter? ( obj -- ? )
     dup word? [ "delimiter" word-prop ] [ drop f ] if ;
 
+: deprecated? ( obj -- ? )
+    dup word? [ "deprecated" word-prop ] [ drop f ] if ;
+
 ! Definition protocol
 M: word where "loc" word-prop ;
 
@@ -217,4 +223,4 @@ M: word hashcode*
 
 M: word literalize <wrapper> ;
 
-INSTANCE: word definition
\ No newline at end of file
+INSTANCE: word definition