Esempio n. 1
0
        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;
                SolvingFunctions.PushConstraints(descArray.ElementNode, ancArray.ElementNode);
                return(true);
            }

            if (ancestor is StateFun ancFun)
            {
                var descFun = (StateFun)descendant;
                if (descFun.ArgsCount != ancFun.ArgsCount)
                {
                    return(false);
                }
                PushFunTypeArgumentsConstraints(descFun, ancFun);
                return(true);
            }
            if (ancestor is StateStruct ancStruct)
            {
                return(TryMergeStructFields(ancStruct, (StateStruct)descendant));
            }
            return(false);
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
        public bool Apply(ICompositeState ancestor, ICompositeState descendant, TicNode ancestorNode, TicNode descendantNode)
        {
            if (ancestor is StateArray ancArray)
            {
                if (descendant is StateArray descArray)
                {
                    return(SolvingFunctions.Destruction(descArray.ElementNode, ancArray.ElementNode));
                }
                return(true);
            }

            if (ancestor is StateFun ancFun)
            {
                if (descendant is StateFun descFun)
                {
                    TraceLog.Write("f+f: ");
                    if (ancFun.ArgsCount == descFun.ArgsCount)
                    {
                        for (int i = 0; i < ancFun.ArgsCount; i++)
                        {
                            SolvingFunctions.Destruction(descFun.ArgNodes[i], ancFun.ArgNodes[i]);
                        }
                        SolvingFunctions.Destruction(ancFun.RetNode, descFun.RetNode);
                    }
                }
            }

            if (ancestor is StateStruct ancStruct)
            {
                if (descendant is StateStruct descStruct)
                {
                    foreach (var ancField in ancStruct.Fields)
                    {
                        var descFieldNode = descStruct.GetFieldOrNull(ancField.Key);
                        if (descFieldNode == null)
                        {
                            //todo!!
                            //throw new ImpossibleException(
                            //    $"Struct descendant '{descendantNode.Name}:{descendant}' of node '{ancestorNode.Name}:{ancestor}' miss field '{ancField.Key}'");
                            descendantNode.State = descStruct.With(ancField.Key, ancField.Value);
                        }
                        else
                        {
                            SolvingFunctions.Destruction(descFieldNode, ancField.Value);
                        }
                    }
                    ancestorNode.State = new StateRefTo(descendantNode);
                }
            }
            return(true);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.StateMachine == null))
     {
         IStateMachine stateMachineCasted = item.As <IStateMachine>();
         if ((stateMachineCasted != null))
         {
             this._parent.StateMachine = stateMachineCasted;
             return;
         }
     }
     if ((this._parent.CompositeStates == null))
     {
         ICompositeState compositeStatesCasted = item.As <ICompositeState>();
         if ((compositeStatesCasted != null))
         {
             this._parent.CompositeStates = compositeStatesCasted;
             return;
         }
     }
 }
Esempio n. 7
0
 public bool Apply(ICompositeState ancestor, StatePrimitive descendant, TicNode _, TicNode __)
 => false;
Esempio n. 8
0
 public bool Apply(StatePrimitive ancestor, ICompositeState descendant, TicNode _, TicNode __)
 => true;
Esempio n. 9
0
 public bool Apply(IStateCombination2dimensionalVisitor visitor, TicNode ancestorNode, TicNode descendantNode, ICompositeState ancestor)
 => visitor.Apply(ancestor, this, ancestorNode, descendantNode);
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
 public bool Apply(ConstrainsState ancestor, ICompositeState descendant, TicNode _, TicNode __) =>
 !ancestor.HasAncestor || ancestor.Ancestor.Equals(StatePrimitive.Any);
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 public bool Apply(ConstrainsState ancestor, ICompositeState descendant, TicNode ancestorNode, TicNode descendantNode)
 => ApplyAncestorConstrains(ancestorNode, ancestor, descendant);
Esempio n. 14
0
 public bool Apply(StatePrimitive ancestor, ICompositeState descendant, TicNode _, TicNode __)
 => descendant.CanBeImplicitlyConvertedTo(ancestor);