From 6554dd6f8e5b1faafbda33b853a3de08ffd0ff6e Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Sat, 28 Mar 2020 18:02:11 +0100 Subject: Add location to transform functions. --- cparser/Bitfields.ml | 8 ++++---- cparser/StructPassing.ml | 12 ++++++------ cparser/Transform.ml | 24 ++++++++++++------------ cparser/Transform.mli | 12 ++++++------ 4 files changed, 28 insertions(+), 28 deletions(-) (limited to 'cparser') diff --git a/cparser/Bitfields.ml b/cparser/Bitfields.ml index 696a9a8d..efb82b01 100644 --- a/cparser/Bitfields.ml +++ b/cparser/Bitfields.ml @@ -189,7 +189,7 @@ let rec transf_union_members env id count = function { fld_name = carrier; fld_typ = carrier_typ; fld_bitfield = None; fld_anonymous = false;} :: transf_union_members env id (count + 1) ms) -let transf_composite env su id attr ml = +let transf_composite env loc su id attr ml = if List.for_all (fun f -> f.fld_bitfield = None) ml then (attr, ml) else begin @@ -550,7 +550,7 @@ and transf_init env i = (* Declarations *) -let transf_decl env (sto, id, ty, init_opt) = +let transf_decl env loc (sto, id, ty, init_opt) = (sto, id, ty, match init_opt with None -> None | Some i -> Some(transf_init env i)) @@ -559,12 +559,12 @@ let transf_decl env (sto, id, ty, init_opt) = let transf_stmt env s = Transform.stmt ~expr:(fun loc env ctx e -> transf_exp env ctx e) - ~decl:transf_decl + ~decl:(fun env (sto, id, ty, init_opt) -> transf_decl env s.sloc (sto, id, ty, init_opt)) env s (* Functions *) -let transf_fundef env f = +let transf_fundef env loc f = Transform.fundef transf_stmt env f (* Programs *) diff --git a/cparser/StructPassing.ml b/cparser/StructPassing.ml index 5c6454f0..222da367 100644 --- a/cparser/StructPassing.ml +++ b/cparser/StructPassing.ml @@ -424,7 +424,7 @@ and transf_init env = function (* Declarations *) -let transf_decl env (sto, id, ty, init) = +let transf_decl env loc (sto, id, ty, init) = (sto, id, transf_type env ty, match init with None -> None | Some i -> Some (transf_init env i)) @@ -494,7 +494,7 @@ let rec transf_stmt s = | Sblock sl -> {s with sdesc = Sblock(List.map transf_stmt sl)} | Sdecl d -> - {s with sdesc = Sdecl(transf_decl env d)} + {s with sdesc = Sdecl(transf_decl env s.sloc d)} | Sasm(attr, template, outputs, inputs, clob) -> {s with sdesc = Sasm(attr, template, List.map transf_asm_operand outputs, @@ -540,13 +540,13 @@ let rec transf_funparams loc env params = actions, IdentMap.add x (ereinterpret tx' y) subst) -let transf_fundef env f = +let transf_fundef env loc f = reset_temps(); let ret = transf_type env f.fd_ret in let (params, actions, subst) = transf_funparams f.fd_body.sloc env f.fd_params in let locals = - List.map (fun d -> transf_decl env (subst_decl subst d)) f.fd_locals in + List.map (fun d -> transf_decl env loc (subst_decl subst d)) f.fd_locals in let (attr1, ret1, params1, body1) = match classify_return env f.fd_ret with | Ret_scalar -> @@ -577,7 +577,7 @@ let transf_fundef env f = (* Composites *) -let transf_composite env su id attr fl = +let transf_composite env loc su id attr fl = (attr, List.map (fun f -> {f with fld_typ = transf_type env f.fld_typ}) fl) (* Entry point *) @@ -595,5 +595,5 @@ let program p = ~decl:transf_decl ~fundef:transf_fundef ~composite:transf_composite - ~typedef:(fun env id ty -> transf_type env ty) + ~typedef:(fun env loc id ty -> transf_type env ty) p diff --git a/cparser/Transform.ml b/cparser/Transform.ml index 349a3155..6774a9b6 100644 --- a/cparser/Transform.ml +++ b/cparser/Transform.ml @@ -191,12 +191,12 @@ let fundef trstmt env f = (* Generic transformation of a program *) let program - ?(decl = fun env d -> d) - ?(fundef = fun env fd -> fd) - ?(composite = fun env su id attr fl -> (attr, fl)) - ?(typedef = fun env id ty -> ty) - ?(enum = fun env id attr members -> (attr, members)) - ?(pragma = fun env s -> s) + ?(decl = fun env loc d -> d) + ?(fundef = fun env loc fd -> fd) + ?(composite = fun env loc su id attr fl -> (attr, fl)) + ?(typedef = fun env loc id ty -> ty) + ?(enum = fun env loc id attr members -> (attr, members)) + ?(pragma = fun env loc s -> s) p = let rec transf_globdecls env accu = function @@ -205,25 +205,25 @@ let program let (desc', env') = match g.gdesc with | Gdecl((sto, id, ty, init) as d) -> - (Gdecl(decl env d), Env.add_ident env id sto ty) + (Gdecl(decl env g.gloc d), Env.add_ident env id sto ty) | Gfundef f -> - (Gfundef(fundef env f), + (Gfundef(fundef env g.gloc f), Env.add_ident env f.fd_name f.fd_storage (fundef_typ f)) | Gcompositedecl(su, id, attr) -> (Gcompositedecl(su, id, attr), Env.add_composite env id (composite_info_decl su attr)) | Gcompositedef(su, id, attr, fl) -> - let (attr', fl') = composite env su id attr fl in + let (attr', fl') = composite env g.gloc su id attr fl in (Gcompositedef(su, id, attr', fl'), Env.add_composite env id (composite_info_def env su attr fl)) | Gtypedef(id, ty) -> - (Gtypedef(id, typedef env id ty), Env.add_typedef env id ty) + (Gtypedef(id, typedef env g.gloc id ty), Env.add_typedef env id ty) | Genumdef(id, attr, members) -> - let (attr', members') = enum env id attr members in + let (attr', members') = enum env g.gloc id attr members in (Genumdef(id, attr', members'), Env.add_enum env id {ei_members = members; ei_attr = attr}) | Gpragma s -> - (Gpragma(pragma env s), env) + (Gpragma(pragma env g.gloc s), env) in transf_globdecls env' ({g with gdesc = desc'} :: accu) gl diff --git a/cparser/Transform.mli b/cparser/Transform.mli index dbd8e575..220b7944 100644 --- a/cparser/Transform.mli +++ b/cparser/Transform.mli @@ -62,14 +62,14 @@ val fundef : (Env.t -> C.stmt -> C.stmt) -> Env.t -> C.fundef -> C.fundef (** Generic transformation of a program *) val program : - ?decl:(Env.t -> C.decl -> C.decl) -> - ?fundef:(Env.t -> C.fundef -> C.fundef) -> - ?composite:(Env.t -> C.struct_or_union -> + ?decl:(Env.t -> C.location -> C.decl -> C.decl) -> + ?fundef:(Env.t -> C.location -> C.fundef -> C.fundef) -> + ?composite:(Env.t -> C.location -> C.struct_or_union -> C.ident -> C.attributes -> C.field list -> C.attributes * C.field list) -> - ?typedef:(Env.t -> C.ident -> C.typ -> C.typ) -> - ?enum:(Env.t -> C.ident -> C.attributes -> C.enumerator list -> + ?typedef:(Env.t -> C.location -> C.ident -> C.typ -> C.typ) -> + ?enum:(Env.t -> C.location -> C.ident -> C.attributes -> C.enumerator list -> C.attributes * C.enumerator list) -> - ?pragma:(Env.t -> string -> string) -> + ?pragma:(Env.t -> C.location -> string -> string) -> C.program -> C.program -- cgit