public void InferConstructor(IEnumerable <string> args, A.HandlerDecl h, Func <string, B.TypePlan> getTypePlan) { var cp = new B.ConstPlan(); foreach (string a in args) { cp.AddConstructorArguments(h, a, getTypePlan); } AddConstructor(cp); Console.WriteLine($"[A2B] Inferred constructor {cp.ToString(Name, Super)}"); }
internal void AddConstructorArguments(A.HandlerDecl h, string a, Func <string, B.TypePlan> getTypePlan) { A.Reaction c = h.GetContext(a); switch (c) { case A.PopAction pa: _args.Add(new Tuple <string, B.TypePlan>(a, getTypePlan(pa.Name))); break; case A.PopStarAction psa: _args.Add(new Tuple <string, B.TypePlan>(a, getTypePlan(psa.Name).Copy(true))); break; case A.PopHashAction pha: _args.Add(new Tuple <string, B.TypePlan>(a, getTypePlan(pha.Name).Copy(true))); break; case A.AwaitAction aa: _args.Add(new Tuple <string, B.TypePlan>(a, getTypePlan(aa.Name))); break; case A.AwaitStarAction asa: _args.Add(new Tuple <string, B.TypePlan>(a, getTypePlan(asa.Name).Copy(true))); break; case A.TearAction _: { int idx = -1; for (int i = 0; i < h.Context.Count; i++) { if (h.Context[i].LHS == a) { idx = i; break; } } idx--; // previous if (idx < 0) { Console.WriteLine($"the TEAR action must not be the first one"); } _args.Add(new Tuple <string, B.TypePlan>(a, getTypePlan(h.Context[idx].RHS.Name).FirstConstructor._args[0].Item2)); break; } case null when a == "this": _args.Add(new Tuple <string, B.TypePlan>(a, new B.TypePlan(B.SystemPlan.Unalias(h.LHS.NonTerminal)))); break; } }