@@ -35,16 +35,39 @@ let is_bs_attribute txt =
35
35
36
36
let used_attributes : Parsetree.attribute Hash_set_poly.t = Hash_set_poly. create 16
37
37
38
+ let dump_attribute fmt = (fun ( (sloc : string Asttypes.loc ),payload ) ->
39
+ Format. fprintf fmt " @[%s %a@]" sloc.txt (Printast. payload 0 ) payload
40
+ )
41
+
42
+ let dump_used_attributes fmt =
43
+ Format. fprintf fmt " Used attributes Listing Start:@." ;
44
+ Hash_set_poly. iter (fun attr -> dump_attribute fmt attr) used_attributes;
45
+ Format. fprintf fmt " Used attributes Listing End:@."
46
+
47
+
38
48
let mark_used_bs_attribute (x : Parsetree.attribute ) =
39
49
Hash_set_poly. add used_attributes x
40
50
41
- let warn_unused_attributes attrs =
51
+ let dummy_unused_attribute : Warnings.t = (Bs_unused_attribute " " )
52
+
53
+
54
+
55
+ let warn_unused_attribute
56
+ (({txt; loc} , _ ) as attr : Parsetree. attribute ) =
57
+ if is_bs_attribute txt &&
58
+ not (Hash_set_poly. mem used_attributes attr) then
59
+ begin
60
+ #if BS_DEBUG then (* COMMENT*)
61
+ dump_used_attributes Format. err_formatter;
62
+ dump_attribute Format. err_formatter attr ;
63
+ #end
64
+ Location. prerr_warning loc (Bs_unused_attribute txt)
65
+ end
66
+
67
+ let warn_unused_attributes (attrs : Parsetree.attributes ) =
42
68
if attrs <> [] then
43
- List. iter (fun (({txt; loc} , _ ) as a : Parsetree. attribute ) ->
44
- if is_bs_attribute txt &&
45
- not (Hash_set_poly. mem used_attributes a) then
46
- Location. prerr_warning loc (Warnings. Bs_unused_attribute txt)
47
- ) attrs
69
+ Ext_list. iter attrs warn_unused_attribute
70
+
48
71
#if OCAML_VERSION =~ " >4.03.0" then
49
72
type iterator = Ast_iterator .iterator
50
73
let default_iterator = Ast_iterator. default_iterator
@@ -57,13 +80,7 @@ let default_iterator = Bs_ast_iterator.default_iterator
57
80
let emit_external_warnings : iterator =
58
81
{
59
82
default_iterator with
60
- attribute = (fun _ a ->
61
- match a with
62
- | {txt ; loc} , _ ->
63
- if is_bs_attribute txt &&
64
- not (Hash_set_poly. mem used_attributes a) then
65
- Location. prerr_warning loc (Bs_unused_attribute txt)
66
- );
83
+ attribute = (fun _ attr -> warn_unused_attribute attr);
67
84
expr = (fun self a ->
68
85
match a.Parsetree. pexp_desc with
69
86
| Pexp_constant (
@@ -97,3 +114,11 @@ let emit_external_warnings : iterator=
97
114
default_iterator.value_description self v
98
115
)
99
116
}
117
+
118
+ let emit_external_warnings_on_structure (stru : Parsetree.structure ) =
119
+ if Warnings. is_active dummy_unused_attribute then
120
+ emit_external_warnings.structure emit_external_warnings stru
121
+
122
+ let emit_external_warnings_on_signature (sigi : Parsetree.signature ) =
123
+ if Warnings. is_active dummy_unused_attribute then
124
+ emit_external_warnings.signature emit_external_warnings sigi
0 commit comments