/// <summary> /// Returns a string describing the signature of <c>method</c>: return type, method name, /// argument types and names (param names are not really part of the method signature, but /// it's nice to know them anyway). /// </summary> public static string MethodSignature(Method method) { StringBuilder signature = new StringBuilder(); if (CciHelper.IsStatic(method)) { signature.Append("static "); } if (CciHelper.IsAbstract(method)) { signature.Append("abstract "); } else if (CciHelper.IsVirtual(method)) { signature.Append("virtual "); } signature.Append(method.ReturnType.FullName) .Append(" ") .Append(method.DeclaringType.FullName).Append(".").Append(method.Name) .Append("("); for (int i = 0, n = (method.Parameters != null)?method.Parameters.Count:0; i < n; i++) { Parameter p = method.Parameters[i]; if (i != 0) { signature.Append(", "); } signature.Append(p.Type.FullName).Append(" ").Append(p.Name); } signature.Append(")"); return(signature.ToString()); }
// deals with the special case of a pop statement private Statement treat_pop_stat(ExpressionStatement expr_stat) { Statement new_stat = expr_stat; if (CciHelper.IsPopStatement(expr_stat)) { // real pop statement! new_stat = PopStatTransformer(expr_stat, depth); decrement_depth(); } else { // expr followed by a pop that removes the result of the expr // the stack depth remains unchanged: +1-1 = 0. // WARNING: if Herman changes his stuff, this might break ... UnaryExpression unexpr = (UnaryExpression)expr_stat.Expression; System.Diagnostics.Debug.Assert(unexpr != null, "Expected non-null expression in expression statement."); Expression unarg = (Expression)Visit(unexpr.Operand); System.Diagnostics.Debug.Assert(unarg != null, "Visit must return non-null if passed non-null"); unexpr.Operand = unarg; new_stat = PopExprTransformer(expr_stat, depth); } return(new_stat); }
private static string ExpressionStatementToString(ExpressionStatement stat) { if (CciHelper.IsPopStatement(stat)) { return("POP_STAT"); } Expression expr = stat.Expression; System.Diagnostics.Debug.Assert(expr != null, "ExpressionStatement should not have null expression here."); return(expression2str(expr)); }
public bool ConsistentByDefault(Method m) { if (m.ApplyDefaultContract) { return(true); } if (CciHelper.IsConstructor(m)) { return(false); } return(true); }
/// <summary> /// Returns null, if result of Join is the same as atMerge. /// </summary> public static ExposureState Join(ExposureState atMerge, ExposureState incoming, CfgBlock joinPoint) { bool unchanged; IEGraph merged = atMerge.egraph.Join(incoming.egraph, joinPoint, out unchanged); TypeNode currentException = (atMerge.currentException != null)? ((incoming.currentException != null)? CciHelper.LeastCommonAncestor(atMerge.currentException, incoming.currentException) : null) : null; if (atMerge.currentException != currentException || !unchanged) { return(new ExposureState(merged, currentException, atMerge.typeSystem)); } return(null); }
public override void InitMethod(Method method, IEnumerable parameters, Label lb) { base.InitMethod(method, parameters, lb); if (this.Parameters != null) { foreach (Parameter p in this.Parameters) { if (this.MethodRequiresExposable(method, p)) { AssumeConsistent(p); } else { AssumeNonConsistent(p); } } } if (CciHelper.IsConstructor(Method)) { exposedNodes.AddRange(Values(Method.ThisParameter)); } }
public static bool IsDeclaredAccessingGlobals(Method m) { if (WorstCase) { return(true); } bool res = true; AttributeNode attr = m.GetAttribute(SystemTypes.GlobalAccessAttribute); if (attr != null) { Microsoft.Contracts.GlobalAccessAttribute readAttr = (Microsoft.Contracts.GlobalAccessAttribute)attr.GetRuntimeAttribute(); if (readAttr != null) { res = readAttr.Value; } } else { if (IsAssumedConfinedMethod(m)) { return(false); } // We assume thet constructor are not writing globals if (CciHelper.IsConstructor(m)) { res = false; } //if (m.DeclaringType != null && CciHelper.IsInterface(m.DeclaringType) // && m.DeclaringType.FullName.StartsWith("System.Collections")) // return false; } return(res); }
private bool HasToExpose() { bool res = /*!inExposedBlock &&*/ !CciHelper.IsConstructor(this.Method); return(res); }
public override Statement VisitExpressionStatement(ExpressionStatement expr_stat) { Expression expr = expr_stat.Expression; System.Diagnostics.Debug.Assert(expr != null, "Expression statement with null expression not expected"); // special cases: pop and dup. if (expr.NodeType == NodeType.Pop) { return(treat_pop_stat(expr_stat)); } if (expr.NodeType == NodeType.Dup) { depth++; return(DupTransformer(expr_stat, depth - 1)); } // recursively explore the expression of this statement expr_stat.Expression = expr = (Expression)Visit(expr); // the [transformed] statement to be returned from this method // by default, it's the original statement. Statement new_stat = expr_stat; switch (expr.NodeType) { case NodeType.Jmp: // TODO: what's this? throw new NotImplementedException("NodeType.Jmp in StackDepthVisitor"); case NodeType.Calli: case NodeType.Call: case NodeType.Callvirt: case NodeType.MethodCall: Member bm = ((MemberBinding)((MethodCall)expr).Callee).BoundMember; if (bm is Method) { Method callee = (Method)bm; TypeNode ret_type = callee.ReturnType; if (!CciHelper.IsVoid(ret_type)) { new_stat = PushExprTransformer(expr_stat, depth); // the called method pushed its non-void result on the evaluation stack depth++; } } else if (bm is FunctionPointer) { FunctionPointer callee = (FunctionPointer)bm; TypeNode ret_type = callee.ReturnType; if (!CciHelper.IsVoid(ret_type)) { new_stat = PushExprTransformer(expr_stat, depth); // the called method pushed its non-void result on the evaluation stack depth++; } } else { throw new NotImplementedException("StackDepthVisitor: Call case: bound member is " + bm.GetType().Name); } break; case NodeType.Initblk: case NodeType.Cpblk: // Unfortunately, Herman's ternary expressions are not expressions: the reader uses them // to model Cpblk and Initblk. As these "expressions" don't push anything on the stack, // they we don't do anything for them. break; default: new_stat = PushExprTransformer(expr_stat, depth); // the value of the expression was pushed on the stack depth++; break; } return(new_stat); }