public static bool getSourceInfo(Cmd cmd, out string file, out int line, out int column, out bool keepCmd) { file = null; line = -1; column = -1; keepCmd = true; var acmd = cmd as PredicateCmd; if (acmd == null) { return(false); } var attr = BoogieUtil.getAttr("sourceloc", acmd.Attributes); if (attr != null && attr.Count == 3) { file = attr[0] as string; var tt = attr[1] as LiteralExpr; if (tt != null && (tt.Val is Microsoft.Basetypes.BigNum)) { line = ((Microsoft.Basetypes.BigNum)(tt.Val)).ToInt; } tt = attr[2] as LiteralExpr; if (tt != null && (tt.Val is Microsoft.Basetypes.BigNum)) { column = ((Microsoft.Basetypes.BigNum)(tt.Val)).ToInt; } } else { file = QKeyValue.FindStringAttribute(acmd.Attributes, "sourceFile"); if (file == null) { file = QKeyValue.FindStringAttribute(acmd.Attributes, "sourcefile"); } line = QKeyValue.FindIntAttribute(acmd.Attributes, "sourceLine", -1); if (line == -1) { line = QKeyValue.FindIntAttribute(acmd.Attributes, "sourceline", -1); } } if (file == null || line == -1) { return(false); } if (acmd.Expr is LiteralExpr && (acmd.Expr as LiteralExpr).IsTrue) { keepCmd = false; } return(true); }
public void VisitImplementation(Implementation impl) { // callee -> id var cnt = new Dictionary <string, int>(); foreach (var block in impl.Blocks) { var callcnt = 0; for (int i = 0; i < block.Cmds.Count; i++) { var cc = block.Cmds[i] as CallCmd; if (cc == null) { continue; } if (!cnt.ContainsKey(cc.callee)) { cnt[cc.callee] = 0; } var uniqueId = useGlobalCounter ? counter : cnt[cc.callee]; var attr = new List <object>(); attr.Add(new LiteralExpr(Token.NoToken, Microsoft.BaseTypes.BigNum.FromInt(uniqueId))); cc.Attributes = BoogieUtil.removeAttr("si_old_unique_call", cc.Attributes); var oldAttr = BoogieUtil.getAttr("si_unique_call", cc.Attributes); if (oldAttr != null) { cc.Attributes = BoogieUtil.removeAttr("si_unique_call", cc.Attributes); var newattr = new QKeyValue(Token.NoToken, "si_old_unique_call", oldAttr, null); if (cc.Attributes == null) { cc.Attributes = newattr; } else { cc.Attributes.AddLast(newattr); } } cc.Attributes = new QKeyValue(Token.NoToken, "si_unique_call", attr, cc.Attributes); callIdToLocation.Add(Tuple.Create(impl.Name, cc.callee, uniqueId), Tuple.Create(block.Label, callcnt)); cnt[cc.callee]++; callcnt++; counter++; } } }
public static bool MatchSig(Implementation toMatch, DeclWithFormals dwf, Program boogieProgram, out QKeyValue toMatchAnyParamsAttributes, out int anyParamsPosition, out QKeyValue toMatchAnyParamsAttributesOut, out int anyParamsPositionOut, out Dictionary <Declaration, Expr> paramSubstitution) { toMatchAnyParamsAttributes = null; anyParamsPosition = int.MaxValue; toMatchAnyParamsAttributesOut = null; anyParamsPositionOut = int.MaxValue; paramSubstitution = new Dictionary <Declaration, Expr>(); if (!ExprMatchVisitor.AreAttributesASubset(toMatch.Attributes, dwf.Attributes)) { return(false); } // match procedure name if (BoogieUtil.checkAttrExists(ExprMatchVisitor.BoogieKeyWords.AnyProcedure, toMatch.Attributes)) { //do nothing } else if (BoogieUtil.checkAttrExists(ExprMatchVisitor.BoogieKeyWords.NameMatches, toMatch.Attributes)) { var nmAttrParams = BoogieUtil.getAttr(ExprMatchVisitor.BoogieKeyWords.NameMatches, toMatch.Attributes); var regex = nmAttrParams.First().ToString(); var m = Regex.Match(dwf.Name, regex); if (m.Success) { //do nothing } else { return(false); } } else if (toMatch.Name != dwf.Name) { return(false); } // if the procedure name is matched, it may still be that we are looking only for stubs if (BoogieUtil.checkAttrExists(ExprMatchVisitor.BoogieKeyWords.NoImplementation, toMatch.Attributes)) { foreach (var i in boogieProgram.Implementations) { if (i.Name == dwf.Name) { return(false); } } } if (!MatchParams(ref toMatchAnyParamsAttributes, ref anyParamsPosition, paramSubstitution, toMatch.InParams, toMatch.Proc.InParams, dwf.InParams)) { return(false); } if (!MatchParams(ref toMatchAnyParamsAttributesOut, ref anyParamsPositionOut, paramSubstitution, toMatch.OutParams, toMatch.Proc.OutParams, dwf.OutParams)) { return(false); } return(true); }
public static bool MatchSig(Implementation toMatch, DeclWithFormals dwf, Program boogieProgram, out QKeyValue toMatchAnyParamsAttributes, out int anyParamsPosition, out QKeyValue toMatchAnyParamsAttributesOut, out int anyParamsPositionOut, out Dictionary <Declaration, Expr> paramSubstitution, bool matchPtrs) { toMatchAnyParamsAttributes = null; anyParamsPosition = int.MaxValue; toMatchAnyParamsAttributesOut = null; anyParamsPositionOut = int.MaxValue; paramSubstitution = new Dictionary <Declaration, Expr>(); if (!ExprMatchVisitor.AreAttributesASubset(toMatch.Attributes, dwf.Attributes)) { return(false); } // match procedure name // Positive filters: AnyProcedure, NameMatches, ByName if (BoogieUtil.checkAttrExists(ExprMatchVisitor.BoogieKeyWords.AnyProcedure, toMatch.Attributes)) { //do nothing } else if (BoogieUtil.checkAttrExists(ExprMatchVisitor.BoogieKeyWords.NameMatches, toMatch.Attributes)) { var nmAttrParams = BoogieUtil.getAttr(ExprMatchVisitor.BoogieKeyWords.NameMatches, toMatch.Attributes); Debug.Assert(nmAttrParams.Count() == 1, "Expecting exactly one #NameMatches attribute, found " + nmAttrParams.Count()); var regex = nmAttrParams.First().ToString(); var m = Regex.Match(dwf.Name, regex); if (m.Success) { //do nothing } else { return(false); } } else if (toMatch.Name != dwf.Name) { return(false); } //Negative filter: NameNotMatches (can be multiple of them) if (BoogieUtil.checkAttrExists(ExprMatchVisitor.BoogieKeyWords.NameNotMatches, toMatch.Attributes)) { //get the params from multiple matching key var getAttrRepeated = new Func <QKeyValue, string, IList <IList <object> > >((attr, name) => { var ret = new List <IList <object> >(); for (; attr != null; attr = attr.Next) { if (attr.Key == name) { ret.Add(attr.Params); } } return(ret); }); var nmAttrParams = getAttrRepeated(toMatch.Attributes, ExprMatchVisitor.BoogieKeyWords.NameNotMatches); foreach (var nm in nmAttrParams) { if (Regex.Match(dwf.Name, nm.First().ToString()).Success) { return(false); } } } // if the procedure name is matched, it may still be that we are looking only for stubs if (BoogieUtil.checkAttrExists(ExprMatchVisitor.BoogieKeyWords.NoImplementation, toMatch.Attributes)) { foreach (var i in boogieProgram.Implementations) { if (i.Name == dwf.Name) { return(false); } } } Procedure dwfProc = null; if (dwf is Implementation) { dwfProc = ((Implementation)dwf).Proc; } else if (dwf is Procedure) { dwfProc = (Procedure)dwf; } if (!MatchParams(ref toMatchAnyParamsAttributes, ref anyParamsPosition, paramSubstitution, toMatch.InParams, toMatch.Proc.InParams, dwf.InParams, dwfProc.InParams, matchPtrs)) { return(false); } if (!MatchParams(ref toMatchAnyParamsAttributesOut, ref anyParamsPositionOut, paramSubstitution, toMatch.OutParams, toMatch.Proc.OutParams, dwf.OutParams, dwfProc.OutParams, matchPtrs)) { return(false); } return(true); }