public void AddToUnit(Object obj, string unit_name)
 {
     SLT.Object finded = this.Vars[unit_name].Find(o => (o.Name == obj.Name));
     if (finded != null)
     {
         finded.SetValue(obj.GetValue());
     }
     else
     {
         this.Vars[unit_name].Add(obj);
     }
 }
Exemple #2
0
 public Object AddSingletonObject(Object o)
 {
     SLT.Object finded = this.Cells.Find(c => ((c.Name == o.Name) && (c.Unit == o.Unit)));
     if (finded != null)
     {
         finded.SetValue(o.GetValue());
         return(finded);
     }
     o.ID = this.ID_Object_Counter;
     this.Cells.Add(o);
     this.ID_Object_Counter++;
     return(o);
 }
Exemple #3
0
        int ExecuteAction(Action action)
        {
            string unit_name = action.ParentOperator.ParentSubprogram.Unit.Name;
            string label;
            string unit;
            bool   islast;

            switch (action.Name)
            {
            case ActionName.Assign:
                Phrase     var_ph = (Phrase)action.Parameters[0];
                SLT.Object var    = this.GetObject(var_ph);

                Phrase value_ph = (Phrase)action.Parameters[1];
                object value_obj;    // = ConvertValueToObject(value_ph);
                if (value_ph.PhType == PhraseType.Initiator_Word)
                {
                    //пассивизация инициатора
                    value_obj = GetObjectFromLink(value_ph).ID;
                }
                else
                {
                    value_obj = ConvertValueToObject(value_ph);
                }
                var.SetValue(value_obj);
                break;

            case ActionName.Create:
                string var_name   = (string)action.Parameters[0];
                Phrase vartype_ph = (Phrase)action.Parameters[1];

                SLT.Object new_obj = new SLT.Scalar("", "");    //заглушка

                //для скаляра
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.ScalarVarType_Word))
                {
                    new_obj = new SLT.Scalar(var_name, unit_name);
                }
                //для вектора
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.VectorVarType_Word))
                {
                    Phrase description_line_ph = vartype_ph.Value.Find(ph => ph.PhType == PhraseType.DescriptionLine);
                    new_obj = new SLT.Vector(var_name, unit_name, this.ParentModel.Analyzer.CreateObjectsFromDesciptionLine(description_line_ph, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name));
                }
                //для ссылки
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.LinkVarType_Word))
                {
                    new_obj = new SLT.Link(var_name, unit_name);
                }
                //для макроса
                if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.MacroVarType_Word))
                {
                }
                //this.ParentModel.O_Cont.CreateObject(new_obj,this.INITIATOR.NextOperator.ParentSubprogram SUBPROGRAM.Unit.Name);
                this.ParentModel.O_Cont.CreateObject(new_obj, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name);

                //list.Add(new_obj);
                break;

            case ActionName.Delete:
                string deleted_name = Convert.ToString(action.Parameters[0]);
                if (deleted_name == "True")
                {
                    int deleted_id = this.INITIATOR.ID_of_MemoryCell;
                    this.ParentModel.O_Cont.IT.Delete(deleted_id);
                }
                else
                {
                    //Objects.Object del_obj= this.ParentModel.O_Cont.GetObjectByName(deleted_name,this.SUBPROGRAM.Unit.Name);
                    SLT.Object del_obj = this.ParentModel.O_Cont.GetObjectByName(deleted_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name);
                    //if (del_obj.Unit == this.SUBPROGRAM.Unit.Name)
                    if (del_obj.Unit == this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name)
                    {
                        this.ParentModel.O_Cont.DeleteObjectByID(del_obj.ID);
                    }
                }
                break;

            case ActionName.Terminate:
                string terminated_name = Convert.ToString(action.Parameters[0]);
                int    terminated_id   = this.INITIATOR.ID_of_MemoryCell;
                this.ParentModel.O_Cont.DeleteInitiatorByID(terminated_id);
                break;

            case ActionName.Write_to_CT:
                Phrase condition;
                if (typeof(bool) == action.Parameters[0].GetType())
                {
                    if ((bool)action.Parameters[0])
                    {
                        condition = new Phrase(PhraseType.True);
                    }
                    else
                    {
                        condition = new Phrase(PhraseType.False);
                    }
                }
                else
                {
                    condition = (Phrase)action.Parameters[0];
                }
                string link_name       = Convert.ToString(action.Parameters[1]);
                bool   to_the_begining = (bool)action.Parameters[2];
                label  = (string)action.Parameters[3];
                unit   = (string)action.Parameters[4];
                islast = (bool)action.Parameters[5];

                Initiator  init;
                Subprogram subp;
                try
                {
                    subp = this.ParentModel.ST_Cont.FindSubprogramByLabelAndUnit(label, unit);
                }
                catch (RunTimeError e)
                {
                    throw new RunTimeError(e);
                }

                if (link_name == "True")
                {
                    init = this.INITIATOR;
                }
                else
                {
                    //init = this.ParentModel.O_Cont.ActivateFromLink(link_name, this.SUBPROGRAM.Unit.Name);
                    init = this.ParentModel.O_Cont.ActivateFromLink(link_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name);
                }
                //init.NextOperator = subp;
                init.NextOperator = subp.Operators[0];

                if (to_the_begining)
                {
                    this.TC_Cont.InsertConditionRecord(condition, init, subp, islast);
                }
                else
                {
                    this.TC_Cont.AddConditionRecord(condition, init, subp, islast);
                }
                break;

            case ActionName.Write_to_FTT:
                Phrase time_exp = (Phrase)action.Parameters[0];
                double time     = Convert.ToDouble(this.ComputeArithmeticExpression(time_exp));
                label  = (string)action.Parameters[3];
                unit   = (string)action.Parameters[4];
                islast = (bool)action.Parameters[5];

                init = this.INITIATOR;
                subp = this.ParentModel.ST_Cont.FindSubprogramByLabelAndUnit(label, unit);
                this.TC_Cont.AddTimeRecord(time, init, subp, islast);
                break;
            }
            return(1);
        }