public override void Clone(JsNode node) { base.Clone(node); var node2 = (JsVariableDeclarationStatement)node; node2.Declaration = Declaration.Clone(); }
// special treatment for np.arange which is a "monster" private IEnumerable <Declaration> ExpandArange(Declaration decl) { // numpy.arange([start, ]stop, [step, ]dtype=None) var dtype = decl.Arguments.Last(); dtype.IsNullable = true; dtype.IsNamedArg = true; if (decl.Arguments.Any(a => a.Type == "number")) { foreach (var type in "byte short int long float double".Split()) { // start, stop var clone_decl = decl.Clone(); clone_decl.Arguments.ForEach(a => { if (a.Type == "number") { a.Type = type; } }); clone_decl.Arguments[0].IsNamedArg = false; clone_decl.Arguments[0].IsNullable = false; clone_decl.Arguments[0].DefaultValue = null; yield return(clone_decl); // [start=0] <-- remove start from arg list clone_decl = clone_decl.Clone(); // <---- clone from the clone, as it has the correct type clone_decl.Arguments.RemoveAt(0); yield return(clone_decl); } yield break; } }
private IEnumerable <Declaration> InferOverloads(Declaration decl) { // without args we don't need to consider possible overloads if (decl.Arguments.Count == 0) { yield return(decl); yield break; } // array_like if (decl.Arguments.Any(a => a.Type == "(array_like)")) { foreach (var type in "NDarray T[]".Split()) { var clone_decl = decl.Clone(); clone_decl.Arguments.ForEach(a => { if (a.Type == "array_like") { a.Type = type; } }); if (type == "T[]") { clone_decl.Generics = new string[] { "T" } } ; yield return(clone_decl); } yield break; } yield return(decl); }
protected virtual IEnumerable <Declaration> ExpandOverloads(Declaration decl) { // todo: let's hope there are not multiple expansions in one declaration, or else this will get complicated if (decl.Arguments.Any(a => a.Type == "(array_like)")) { foreach (var type in "NumSharp.NDArray T[]".Split()) { var clone_decl = decl.Clone(); clone_decl.Arguments.ForEach(a => { if (a.Type == "(array_like)") { a.Type = type; } }); if (type == "T[]") { clone_decl.Generics = new string[] { "T" } } ; yield return(clone_decl); } yield break; } yield return(decl); }
internal void DualiseKernel() { List <Declaration> NewTopLevelDeclarations = new List <Declaration>(); // This loop really does have to be a "for(i ...)" loop. The reason is // that dualisation may add additional functions to the program, which // get put into the program's top level declarations and also need to // be dualised. var decls = verifier.Program.TopLevelDeclarations.ToList(); for (int i = 0; i < UpdateDeclarationsAndCountTotal(decls); i++) { Declaration d = decls[i]; if (d is Axiom) { VariableDualiser vd1 = new VariableDualiser(1, null, null); VariableDualiser vd2 = new VariableDualiser(2, null, null); Axiom NewAxiom1 = vd1.VisitAxiom(d.Clone() as Axiom); Axiom NewAxiom2 = vd2.VisitAxiom(d.Clone() as Axiom); NewTopLevelDeclarations.Add(NewAxiom1); // Test whether dualisation had any effect by seeing whether the new // axioms are syntactically indistinguishable. If they are, then there // is no point adding the second axiom. if (!NewAxiom1.ToString().Equals(NewAxiom2.ToString())) { NewTopLevelDeclarations.Add(NewAxiom2); } continue; } if (d is Procedure) { DualiseProcedure(d as Procedure); NewTopLevelDeclarations.Add(d); continue; } if (d is Implementation) { DualiseImplementation(d as Implementation); NewTopLevelDeclarations.Add(d); continue; } if (d is Variable && ((d as Variable).IsMutable || GPUVerifier.IsThreadLocalIdConstant(d as Variable) || (GPUVerifier.IsGroupIdConstant(d as Variable) && !GPUVerifyVCGenCommandLineOptions.OnlyIntraGroupRaceChecking))) { var v = d as Variable; if (v.Name.Contains("_NOT_ACCESSED_") || v.Name.Contains("_ARRAY_OFFSET")) { NewTopLevelDeclarations.Add(v); continue; } if (QKeyValue.FindBoolAttribute(v.Attributes, "atomic_usedmap")) { NewTopLevelDeclarations.Add(v); continue; } if (verifier.KernelArrayInfo.GetGlobalArrays(true).Contains(v)) { NewTopLevelDeclarations.Add(v); continue; } if (verifier.KernelArrayInfo.GetGroupSharedArrays(true).Contains(v)) { if (!GPUVerifyVCGenCommandLineOptions.OnlyIntraGroupRaceChecking) { Variable newV = new GlobalVariable(Token.NoToken, new TypedIdent(Token.NoToken, v.Name, new MapType(Token.NoToken, new List <TypeVariable>(), new List <Microsoft.Boogie.Type> { Microsoft.Boogie.Type.GetBvType(1) }, v.TypedIdent.Type))); newV.Attributes = v.Attributes; NewTopLevelDeclarations.Add(newV); } else { NewTopLevelDeclarations.Add(v); } continue; } NewTopLevelDeclarations.Add(new VariableDualiser(1, null, null).VisitVariable((Variable)v.Clone())); if (!QKeyValue.FindBoolAttribute(v.Attributes, "race_checking")) { NewTopLevelDeclarations.Add(new VariableDualiser(2, null, null).VisitVariable((Variable)v.Clone())); } continue; } NewTopLevelDeclarations.Add(d); } verifier.Program.TopLevelDeclarations = NewTopLevelDeclarations; }
public override Declaration VisitDeclaration(Declaration node) { return(base.VisitDeclaration((Declaration)node.Clone())); }
public override Declaration VisitDeclaration(Declaration node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result <Declaration>() != null); return(base.VisitDeclaration((Declaration)node.Clone())); }
private IEnumerable <Declaration> InferOverloads(Declaration decl) { // without args we don't need to consider possible overloads if (decl.Arguments.Count == 0) { yield return(decl); yield break; } if (decl.Name == "arange") { foreach (var d in ExpandArange(decl)) { yield return(d); } yield break; } // array_like if (decl.Arguments.Any(a => a.Type == "array_like")) { foreach (var type in "NDarray T[]".Split()) { var clone_decl = decl.Clone(); clone_decl.Arguments.ForEach(a => { if (a.Type == "array_like") { a.Type = type; } }); if (type == "T[]") { clone_decl.Generics = new string[] { "T" }; if (clone_decl.Returns[0].Type == "NDarray") // TODO: this feels like a hack. make it more robust if necessary { clone_decl.Returns[0].Type = "NDarray<T>"; } } yield return(clone_decl); } yield break; } // number if (decl.Arguments.Any(a => a.Type == "number")) { foreach (var type in "byte short int long float double".Split()) { var clone_decl = decl.Clone(); clone_decl.Arguments.ForEach(a => { if (a.Type == "number") { a.Type = type; } }); yield return(clone_decl); } yield break; } if (decl.Name == "bmat") { decl.Arguments[0].Type = "string"; yield return(decl); var clone_decl = decl.Clone(); clone_decl.Arguments[0].Type = "T[]"; clone_decl.Generics = new [] { "T" }; clone_decl.Returns[0].Type = "matrix<T>"; yield return(clone_decl); yield break; } yield return(decl); }