123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149(**************************************************************************)(* *)(* This file is part of the Frama-C's Lannotate plug-in. *)(* *)(* Copyright (C) 2012-2025 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file LICENSE) *)(* *)(**************************************************************************)openCilopenCil_typesopenAst_constletaorOption:boolref=reffalseletrorOption:boolref=reffalseletcorOption:boolref=reffalseletabsOption:boolref=reffalseclassmutationVisitormk_label=object(self)inheritVisitor.frama_c_inplacevalmutableexprs=[]valmutablecurrloc=Cil_datatype.Location.unknownmethodprivatemakeLabelcondcategory=letle=mk_label~extra:[category]cond[]currlocinexprs<-exprs@[le]methodprivatemk_op_labelseloplexprexptywmopt=ifopt=truethenList.iter(funop->letnewExp=Exp_builder.mk(BinOp(op,lexp,rexp,ty))inletlabelExp=Exp_builder.mk(BinOp(Ne,newExp,e,ty))inself#makeLabellabelExpwm)lop;self#traitExplexp;self#traitExprexpmethodprivatetraitExpe=matche.enodewith|BinOp(LAnd,lexp,rexp,ty)->self#mk_op_labelse[LOr]lexprexpty"COR"!corOption|BinOp(LOr,lexp,rexp,ty)->self#mk_op_labelse[LAnd]lexprexpty"COR"!corOption|BinOp(Div,lexp,rexp,ty)->self#mk_op_labelse[Mult;PlusA;MinusA]lexprexpty"AOR"!aorOption|BinOp(Mult,lexp,rexp,ty)->self#mk_op_labelse[Div;PlusA;MinusA]lexprexpty"AOR"!aorOption|BinOp(PlusA,lexp,rexp,ty)->self#mk_op_labelse[Mult;Div;MinusA]lexprexpty"AOR"!aorOption|BinOp(MinusA,lexp,rexp,ty)->self#mk_op_labelse[Mult;Div;PlusA]lexprexpty"AOR"!aorOption|BinOp(Lt,lexp,rexp,ty)->self#mk_op_labelse[Le;Gt;Ge]lexprexpty"ROR"!rorOption|BinOp(Gt,lexp,rexp,ty)->self#mk_op_labelse[Lt;Le;Ge]lexprexpty"ROR"!rorOption|BinOp(Le,lexp,rexp,ty)->self#mk_op_labelse[Lt;Gt;Ge]lexprexpty"ROR"!rorOption|BinOp(Ge,lexp,rexp,ty)->self#mk_op_labelse[Lt;Le;Gt]lexprexpty"ROR"!rorOption|BinOp(Eq,lexp,rexp,ty)->self#mk_op_labelse[Ne]lexprexpty"ROR"!rorOption|BinOp(Ne,lexp,rexp,ty)->self#mk_op_labelse[Eq]lexprexpty"ROR"!rorOption|BinOp(Shiftlt,lexp,rexp,ty)->self#mk_op_labelse[Shiftrt]lexprexpty"AOR"!aorOption|BinOp(Shiftrt,lexp,rexp,ty)->self#mk_op_labelse[Shiftlt]lexprexpty"AOR"!aorOption|BinOp(_op,lexp,rexp,_ty)->self#traitExplexp;self#traitExprexp|UnOp(Neg,exp,ty)->if!aorOption=truethenbeginletlabelExp=Exp_builder.mk(BinOp(Ne,exp,e,ty))inself#makeLabellabelExp"AOR"end;self#traitExpexp|UnOp(_op,exp,_ty)->self#traitExpexp|Lval(_l)->if!absOption=truethenbeginletzeroExp=Exp_builder.mk(Const(CInt64(Integer.of_int(0),IInt,None)))inletlabelExp=Exp_builder.mk(BinOp(Lt,e,zeroExp,Cil_const.intType))inself#makeLabellabelExp"ABS"end|_->()method!vfuncf=ifAnnotators.shouldInstrumentFunf.svarthenDoChildrenelseSkipChildrenmethod!vstmt_auxstmt=beginmatchstmt.skindwith|Instr(Set(_l,e,loc))->currloc<-loc;self#traitExpe|If(e,_l,_ll,loc)->currloc<-loc;self#traitExpe|Return(e,loc)->beginmatchewith|Someexp->currloc<-loc;self#traitExpexp|_->()end|Switch(e,_l,_ll,loc)->currloc<-loc;self#traitExpe|_->()end;letstmtExprsLabels=exprsinexprs<-[];DoChildrenPost(funstmt->matchstmtExprsLabelswith|[]->stmt|_->stmt.skind<-Block(Cil.mkBlock(stmtExprsLabels@[Stmt_builder.mkstmt.skind]));stmt)endmoduleWM=Annotators.RegisterWithExtraTags(structletname="WM"lethelp="Weak Mutation"letapplymk_labelast=Visitor.visitFramacFileSameGlobals(newmutationVisitormk_label:>Visitor.frama_c_inplace)astend)