public bool Apply(ICompositeState ancestor, ConstrainsState descendant, TicNode ancestorNode, TicNode descendantNode) { if (ancestor is StateArray ancArray) { var result = SolvingFunctions.TransformToArrayOrNull(descendantNode.Name, descendant); if (result == null) { return(false); } result.ElementNode.AddAncestor(ancArray.ElementNode); descendantNode.State = result; descendantNode.RemoveAncestor(ancestorNode); } else if (ancestor is StateFun ancFun) { var result = SolvingFunctions.TransformToFunOrNull( descendantNode.Name, descendant, ancFun); if (result == null) { return(false); } result.RetNode.AddAncestor(ancFun.RetNode); for (int i = 0; i < result.ArgsCount; i++) { result.ArgNodes[i].AddAncestor(ancFun.ArgNodes[i]); } descendantNode.State = result; descendantNode.RemoveAncestor(ancestorNode); } else if (ancestor is StateStruct ancStruct) { var result = SolvingFunctions.TransformToStructOrNull(descendant, ancStruct); if (result == null) { return(false); } //todo Зачем это тут, если и так структура ссылается на оригинальные поля? /*foreach (var ancField in ancStruct.Fields) * { * var descField = result.GetFieldOrNull(ancField.Key); * if (descField != ancField.Value) * { * descField.AddAncestor(ancField.Value); * } * }*/ descendantNode.State = result; //descendantNode.RemoveAncestor(ancestorNode); } return(true); }
public bool Apply(ConstrainsState ancestor, ConstrainsState descendant, TicNode ancestorNode, TicNode descendantNode) { var result = ancestor.MergeOrNull(descendant); if (result == null) { return(false); } if (result is StatePrimitive) { descendantNode.State = ancestorNode.State = result; return(true); } if (ancestorNode.Type == TicNodeType.TypeVariable || descendantNode.Type != TicNodeType.TypeVariable) { ancestorNode.State = result; descendantNode.State = new StateRefTo(ancestorNode); } else { descendantNode.State = result; ancestorNode.State = new StateRefTo(descendantNode); } descendantNode.RemoveAncestor(ancestorNode); return(true); }
public bool Apply(ICompositeState ancestor, ConstrainsState descendant, TicNode ancestorNode, TicNode descendantNode) { if (descendant.Fits(ancestor)) { descendantNode.State = new StateRefTo(ancestorNode); descendantNode.RemoveAncestor(ancestorNode); } return(true); }
public bool Apply(ConstrainsState ancestor, ICompositeState descendant, TicNode ancestorNode, TicNode descendantNode) { //todo Check all nonrefchildren of constrains? if (ancestor.Fits(descendant)) { ancestorNode.State = new StateRefTo(descendantNode); descendantNode.RemoveAncestor(ancestorNode); } return(true); }
public bool Apply( ICompositeState ancestor, ConstrainsState descendant, TicNode ancestorNode, TicNode descendantNode) { // if ancestor is composite type then descendant HAS to have same composite type // y:int[] = a:[..] # 'a' has to be an array if (ancestor is StateArray ancArray) { var result = SolvingFunctions.TransformToArrayOrNull(descendantNode.Name, descendant); if (result == null) { return(false); } if (result.ElementNode == ancArray.ElementNode) { descendantNode.RemoveAncestor(ancestorNode); return(true); } result.ElementNode.AddAncestor(ancArray.ElementNode); descendantNode.State = result; descendantNode.RemoveAncestor(ancestorNode); SolvingFunctions.PushConstraints(result.ElementNode, ancArray.ElementNode); return(true); } // y:f(x) = a:[..] # 'a' has to be a functional variable if (ancestor is StateFun ancFun) { var descFun = SolvingFunctions.TransformToFunOrNull(descendantNode.Name, descendant, ancFun); if (descFun == null) { return(false); } if (!descendantNode.State.Equals(descFun)) { descendantNode.State = descFun; PushFunTypeArgumentsConstraints(descFun, ancFun); } return(true); } // y:user = a:[..] # 'a' has to be a struct, that converts to type of 'user' if (ancestor is StateStruct ancStruct) { var descStruct = SolvingFunctions.TransformToStructOrNull(descendant, ancStruct); if (descStruct == null) { return(false); } if (descendantNode.State.Equals(descStruct)) { descendantNode.RemoveAncestor(ancestorNode); return(true); } descendantNode.State = descStruct; if (TryMergeStructFields(ancStruct, descStruct)) { descendantNode.RemoveAncestor(ancestorNode); return(true); } } return(false); }
public bool Apply(ICompositeState ancestor, ICompositeState descendant, TicNode ancestorNode, TicNode descendantNode) { if (ancestor.GetType() != descendant.GetType()) { return(false); } if (ancestor is StateArray ancArray) { var descArray = (StateArray)descendant; if (descArray.ElementNode != ancArray.ElementNode) { descArray.ElementNode.AddAncestor(ancArray.ElementNode); } descendantNode.RemoveAncestor(ancestorNode); } else if (ancestor is StateFun ancFun) { var descFun = (StateFun)descendant; if (descFun.ArgsCount != ancFun.ArgsCount) { return(false); } descFun.RetNode.AddAncestor(ancFun.RetNode); for (int i = 0; i < descFun.ArgsCount; i++) { ancFun.ArgNodes[i].AddAncestor(descFun.ArgNodes[i]); } descendantNode.RemoveAncestor(ancestorNode); } else if (ancestor is StateStruct ancStruct) { var descStruct = (StateStruct)descendant; // desc node has to have all ancestors fields that has exast same type as desc type // (implicit field convertion is not allowed) foreach (var ancField in ancStruct.Fields) { var descField = descStruct.GetFieldOrNull(ancField.Key); if (descField == null) { descendantNode.State = descStruct.With(ancField.Key, ancField.Value); } else { SolvingFunctions.MergeInplace(ancField.Value, descField); if (ancField.Value.State is StateRefTo) { ancestorNode.State = ancestor.GetNonReferenced(); } if (descField.State is StateRefTo) { descendantNode.State = descendant.GetNonReferenced(); } } } // descendantNode.RemoveAncestor(ancestorNode); } else { throw new NotSupportedException($"Composite type {ancestor.GetType().Name} is not supported"); } return(true); }