diff options
author | Chimrod <> | 2025-07-19 11:18:24 +0200 |
---|---|---|
committer | Chimrod <> | 2025-08-01 14:12:14 +0200 |
commit | 3046fb0d0c1ceac2c6a6ca9456e9e05671e0cef9 (patch) | |
tree | 8ba2700e541a6753499ceac54ced4f1d02a3b625 /lib/checks/nested_strings.ml | |
parent | 406b7b79cd375b071f92ddee9cee14a98dc91281 (diff) |
Diffstat (limited to 'lib/checks/nested_strings.ml')
-rw-r--r-- | lib/checks/nested_strings.ml | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/lib/checks/nested_strings.ml b/lib/checks/nested_strings.ml index 51c5258..d4a7947 100644 --- a/lib/checks/nested_strings.ml +++ b/lib/checks/nested_strings.ml @@ -7,80 +7,77 @@ let identifier = "escaped_string" let description = "Check for unnecessary use of expression encoded in string" let is_global = false let active = ref true +let depends = [ Get_type.ex ] +type ex = Qsp_syntax.Identifier.t type context = unit let initialize = Fun.id let finalize () = [] -module Expression = Compose.TypeBuilder.Make (struct - type t = Report.t list +module Expression = struct + type t = { type_of : Get_type.Expression.t; report : Report.t list } type t' = Report.t list - let v : Get_type.t Lazy.t * t -> t' = snd + let v : t -> t' = fun t -> t.report (** Identify the expressions reprented as string. That’s here that the report are added. All the rest of the module only push thoses warning to the top level. *) let literal : - S.pos -> (Get_type.t Lazy.t * t) T.literal list -> Get_type.t Lazy.t -> t - = - fun pos content _type_of -> + ctx:Qsp_syntax.S.extract_context -> S.pos -> t T.literal list -> t = + fun ~ctx pos content -> + let type_of = Option.get (ctx.f Get_type.expression_id) in match content with - | [ T.Expression (t', _); T.Text "" ] -> ( - match Get_type.get_type (Lazy.force t') with - | Get_type.Integer -> [] + | [ T.Expression t; T.Text "" ] -> ( + match Get_type.Expression.get_type t.type_of with + | Get_type.Integer -> { type_of; report = [] } | _ -> let msg = Report.debug pos "This expression can be simplified" in - [ msg ]) - | _ -> [] + { type_of; report = [ msg ] }) + | _ -> { type_of; report = [] } - let ident : - (S.pos, Get_type.t Lazy.t * t) S.variable -> Get_type.t Lazy.t -> t = - fun variable _type_of -> - match variable.index with None -> [] | Some (_, t) -> t + let ident : ctx:Qsp_syntax.S.extract_context -> (S.pos, t) S.variable -> t = + fun ~ctx variable -> + let type_of = Option.get (ctx.f Get_type.expression_id) in + match variable.index with None -> { type_of; report = [] } | Some t -> t - let integer : S.pos -> string -> Get_type.t Lazy.t -> t = - fun pos t _type_of -> + let integer : ctx:Qsp_syntax.S.extract_context -> S.pos -> string -> t = + fun ~ctx pos t -> ignore pos; ignore t; - [] + let type_of = Option.get (ctx.f Get_type.expression_id) in + { type_of; report = [] } let function_ : - S.pos -> - T.function_ -> - (Get_type.t Lazy.t * t) list -> - Get_type.t Lazy.t -> - t = - fun pos f expressions _type_of -> + ctx:Qsp_syntax.S.extract_context -> S.pos -> T.function_ -> t list -> t = + fun ~ctx pos f expressions -> + let type_of = Option.get (ctx.f Get_type.expression_id) in ignore pos; ignore f; let exprs = List.fold_left ~init:[] expressions ~f:(fun acc el -> - List.rev_append (snd el) acc) + List.rev_append el.report acc) in - exprs + { type_of; report = exprs } let uoperator : - S.pos -> T.uoperator -> Get_type.t Lazy.t * t -> Get_type.t Lazy.t -> t = - fun pos op r _type_of -> + ctx:Qsp_syntax.S.extract_context -> S.pos -> T.uoperator -> t -> t = + fun ~ctx pos op r -> + let type_of = Option.get (ctx.f Get_type.expression_id) in ignore op; ignore pos; - snd r + { r with type_of } let boperator : - S.pos -> - T.boperator -> - Get_type.t Lazy.t * t -> - Get_type.t Lazy.t * t -> - Get_type.t Lazy.t -> - t = - fun pos op (_, r1) (_, r2) _type_of -> + ctx:Qsp_syntax.S.extract_context -> S.pos -> T.boperator -> t -> t -> t = + fun ~ctx pos op r1 r2 -> + let type_of = Option.get (ctx.f Get_type.expression_id) in ignore pos; ignore op; - r1 @ r2 -end) + { type_of; report = r1.report @ r2.report } +end module Instruction : S.Instruction with type t' = Report.t list and type expression = Expression.t' = |