1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798(**************************************************************************)(* *)(* SPDX-License-Identifier LGPL-2.1 *)(* Copyright (C) *)(* CEA (Commissariat à l'énergie atomique et aux énergies alternatives) *)(* *)(**************************************************************************)openCil_typesopenAst_constletunk_loc=Cil_datatype.Location.unknown(* Est-ce qu'on peut recup' la loc plus simplement? *)letget_fundec_locdec=letglob=Ast.def_or_last_decldec.svarinmatchglobwith|GFun(_,loc)->loc|_->unk_loc(** A visitor that adds a label at the start of each statement
i.e. :
-Start of a function
-Goto/Return
-Each block of a If
-In Loops
-After each C labels
*)letvisitormk_label=object(self)inheritVisitor.frama_c_inplacemethod!vfuncdec=ifAnnotators.shouldInstrumentFundec.svarthenletl=mk_label(Exp_builder.one())[](get_fundec_locdec)inCil.DoChildrenPost(funres->res.sbody.bstmts<-l::res.sbody.bstmts;res)elseCil.SkipChildrenmethod!vstmt_auxstmt=matchstmt.skindwith|Goto(_,loc)|Return(_,loc)->letl=mk_label(Exp_builder.one())[]locinstmt.skind<-Block(Cil.mkBlock[l;Stmt_builder.mkstmt.skind]);Cil.SkipChildren|If(e,b1,b2,loc)->letl1=mk_label(Exp_builder.one())[]locinletnb1=Cil.visitCilBlock(self:>Cil.cilVisitor)b1inletl2=mk_label(Exp_builder.one())[]locinletnb2=Cil.visitCilBlock(self:>Cil.cilVisitor)b2innb1.bstmts<-l1::nb1.bstmts;nb2.bstmts<-l2::nb2.bstmts;stmt.skind<-(If(e,nb1,nb2,loc));Cil.SkipChildren|Loop_->Cil.DoChildrenPost(funres->matchres.skindwith|Loop(ca,b,loc,s1,s2)->letlb=mk_label(Exp_builder.one())[]locinb.bstmts<-lb::b.bstmts;res.skind<-(Loop(ca,b,loc,s1,s2));res|_->assertfalse)|_->Cil.DoChildrenPost(funres->ifres.labels<>[]thenbeginletloc=matchList.hdstmt.labelswith|Label(_,l,_)|Case(_,l)|Defaultl->linletlb=mk_label(Exp_builder.one())[]locinres.skind<-beginmatchres.skindwith|Instr(Skip_)->lb.skind|_->Block(Cil.mkBlock[lb;Stmt_builder.mkres.skind]);end;resendelseres)endincludeAnnotators.Register(structletname="STMT"lethelp="Statement Coverage"letapplyfast=Visitor.visitFramacFileSameGlobals(visitorf)astend)