bool AnyTypeContainsUnfixedParameter(IEnumerable <IType> types) { OccursInVisitor o = new OccursInVisitor(this); foreach (var type in types) { type.AcceptVisitor(o); } for (int i = 0; i < typeParameters.Length; i++) { if (!typeParameters[i].IsFixed && o.Occurs[i]) { return(true); } } return(false); }
// C# 4.0 spec: §7.5.2.5 Dependance void CalculateDependencyMatrix() { int n = typeParameters.Length; dependencyMatrix = new bool[n, n]; for (int k = 0; k < arguments.Length; k++) { OccursInVisitor input = new OccursInVisitor(this); OccursInVisitor output = new OccursInVisitor(this); foreach (var type in InputTypes(arguments[k], parameterTypes[k])) { type.AcceptVisitor(input); } foreach (var type in OutputTypes(arguments[k], parameterTypes[k])) { type.AcceptVisitor(output); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dependencyMatrix[i, j] |= input.Occurs[j] && output.Occurs[i]; } } } // calculate transitive closure using Warshall's algorithm: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (dependencyMatrix[i, j]) { for (int k = 0; k < n; k++) { if (dependencyMatrix[j, k]) { dependencyMatrix[i, k] = true; } } } } } }
bool AnyTypeContainsUnfixedParameter(IEnumerable<IType> types) { OccursInVisitor o = new OccursInVisitor(this); foreach (var type in types) { type.AcceptVisitor(o); } for (int i = 0; i < typeParameters.Length; i++) { if (!typeParameters[i].IsFixed && o.Occurs[i]) return true; } return false; }
// C# 4.0 spec: §7.5.2.5 Dependance void CalculateDependencyMatrix() { int n = typeParameters.Length; dependencyMatrix = new bool[n, n]; for (int k = 0; k < arguments.Length; k++) { OccursInVisitor input = new OccursInVisitor(this); OccursInVisitor output = new OccursInVisitor(this); foreach (var type in InputTypes(arguments[k], parameterTypes[k])) { type.AcceptVisitor(input); } foreach (var type in OutputTypes(arguments[k], parameterTypes[k])) { type.AcceptVisitor(output); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dependencyMatrix[i, j] |= input.Occurs[j] && output.Occurs[i]; } } } // calculate transitive closure using Warshall's algorithm: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (dependencyMatrix[i, j]) { for (int k = 0; k < n; k++) { if (dependencyMatrix[j, k]) dependencyMatrix[i, k] = true; } } } } }
private static void InjectCode(Implementation impl, int anyParamsPosition, QKeyValue anyParamsAttributes, int anyParamsPositionOut, QKeyValue anyParamsAttributesOut, Implementation procSig, InsertAtBeginningRule rule, Dictionary <Declaration, Expr> paramSubstitution) { //TODO handle anyParams in the OutParam case var doesAnyParamOccurInRhs = false; if (anyParamsPosition != int.MaxValue) { var anyParam = procSig.InParams[anyParamsPosition]; var oiv = new OccursInVisitor(anyParam); oiv.VisitCmdSeq(rule.ProcedureToMatchToInsertion[procSig]); doesAnyParamOccurInRhs = oiv.Success; } if (doesAnyParamOccurInRhs) { for (int i = anyParamsPosition; i < impl.InParams.Count; i++) { var p = impl.InParams[i]; // If attributes for the ##anyparams in the toMatch are given, we only insert code for those parameters of impl // with matching (subset) attributes // we look both in the implementation's and the procedure declaration's signature if (anyParamsAttributes == null || ExprMatchVisitor.AreAttributesASubset(anyParamsAttributes, impl.Proc.InParams[i].Attributes)) { if (!procSig.InParams[anyParamsPosition].TypedIdent.Type.Equals(p.TypedIdent.Type)) { continue; //skip parameters that don't match type } var id = new IdentifierExpr(Token.NoToken, p.Name, p.TypedIdent.Type, true); var substitution = new Dictionary <Declaration, Expr> { { procSig.InParams[anyParamsPosition], id } }; foreach (var kvp in paramSubstitution) { substitution.Add(kvp.Key, kvp.Value); } var sv = new SubstitionVisitor(substitution); var newCmds = sv.VisitCmdSeq(rule.ProcedureToMatchToInsertion[procSig]); if (impl.Blocks.Count > 0 && !QKeyValue.FindBoolAttribute(procSig.Attributes, ExprMatchVisitor.BoogieKeyWords.ReplaceImplementation)) { impl.Blocks.Insert(0, BoogieAstFactory.MkBlock(newCmds, BoogieAstFactory.MkGotoCmd(impl.Blocks.First().Label))); } else { impl.Blocks = new List <Block>(); impl.Blocks.Add( BoogieAstFactory.MkBlock(newCmds)); } } } } else { var sv = new SubstitionVisitor(paramSubstitution); var newCmds = sv.VisitCmdSeq(rule.ProcedureToMatchToInsertion[procSig]); if (impl.Blocks.Count > 0 && !QKeyValue.FindBoolAttribute(procSig.Attributes, ExprMatchVisitor.BoogieKeyWords.ReplaceImplementation)) { impl.Blocks.Insert(0, BoogieAstFactory.MkBlock(newCmds, BoogieAstFactory.MkGotoCmd(impl.Blocks.First().Label))); } else { impl.Blocks = new List <Block>(); impl.Blocks.Add( BoogieAstFactory.MkBlock(newCmds)); } } }