diff options
author | Chimrod <> | 2023-11-06 15:07:28 +0100 |
---|---|---|
committer | Chimrod <> | 2023-11-06 15:09:06 +0100 |
commit | 5acc63c0653b363d3d6dc9217e0a29d7e44cbcaa (patch) | |
tree | 1bd8b5349b6c63081ea92686f03c7c101001deec /lib/syntax/nested_strings.ml | |
parent | 1128450d0b52c09e78d64df5737b8a034b3e230c (diff) |
In the string expression simplification, only report the strings converted into strings
Diffstat (limited to 'lib/syntax/nested_strings.ml')
-rw-r--r-- | lib/syntax/nested_strings.ml | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/lib/syntax/nested_strings.ml b/lib/syntax/nested_strings.ml index 16ec4ac..c7b0b83 100644 --- a/lib/syntax/nested_strings.ml +++ b/lib/syntax/nested_strings.ml @@ -5,10 +5,11 @@ let description = "Check for unnecessary use of expression encoded in string" let active = ref true module Expression : S.Expression with type t' = Report.t list = struct - type t = Report.t list - type t' = t + type t = Report.t list * Type_of.Expression.t + type t' = Report.t list - let v : t -> t' = Fun.id + let get_type t = Type_of.Expression.v t |> Type_of.get_type + let v : t -> t' = Stdlib.fst (** Identify the expressions reprented as string. That’s here that the report are added. @@ -16,28 +17,48 @@ module Expression : S.Expression with type t' = Report.t list = struct All the rest of the module only push thoses warning to the top level. *) let literal : S.pos -> t T.literal list -> t = fun pos content -> + let type_of = + List.map content ~f:(function + | T.Text _ as text -> text + | T.Expression expr -> T.Expression (List.map ~f:snd expr)) + |> Type_of.Expression.literal pos + in + match content with - | [ T.Expression expr; T.Text "" ] -> - ignore expr; - let msg = Report.debug pos "This expression can be simplified" in - [ msg ] - | _ -> [] + | [ T.Expression [ (_, t') ]; T.Text "" ] -> ( + match get_type t' with + | Type_of.Helper.Integer -> ([], type_of) + | _ -> + let msg = Report.debug pos "This expression can be simplified" in + ([ msg ], type_of)) + | _ -> ([], type_of) let ident : (S.pos, t) S.variable -> t = fun { pos; name : string; index : t option } -> - ignore pos; - ignore name; - match index with None -> [] | Some v -> v + match index with + | None -> + let type_ = Type_of.Expression.ident { pos; name; index = None } in + ([], type_) + | Some (v, t') -> + let type_ = Type_of.Expression.ident { pos; name; index = Some t' } in + (v, type_) - let integer : S.pos -> string -> t = fun _ _ -> [] + let integer : S.pos -> string -> t = + fun pos t -> ([], Type_of.Expression.integer pos t) let function_ : S.pos -> T.function_ -> t list -> t = - fun _ _ expressions -> List.concat expressions + fun pos f expressions -> + let r, t = List.split expressions in + + let type_of = Type_of.Expression.function_ pos f t in + (List.concat r, type_of) - let uoperator : S.pos -> T.uoperator -> t -> t = fun _ _ expr1 -> expr1 + let uoperator : S.pos -> T.uoperator -> t -> t = + fun pos op (r, expr1) -> (r, Type_of.Expression.uoperator pos op expr1) let boperator : S.pos -> T.boperator -> t -> t -> t = - fun _ _ expr1 expr2 -> expr1 @ expr2 + fun pos op (r1, expr1) (r2, expr2) -> + (r1 @ r2, Type_of.Expression.boperator pos op expr1 expr2) end module Instruction : |