Example #1
0
        private Expression VariableOperation(Variable left, Variable right)
        {
            Expression res;

            //When left exponent is lesser than right exponent. 2x^2/3x^4 -> 2/3x^2
            if (((left.Exponent < right.Exponent) as Boolean).@bool)
            {
                var symbol = right.Clone();

                (symbol as Variable).Exponent = (right.Exponent - left.Exponent) as Real;
                res = new Div(left.Prefix, symbol);
            }
            //When left exponent is greater than right exponent. 2x^4/3x^2 -> 2x^2/3
            else if (((left.Exponent > right.Exponent) as Boolean).@bool)
            {
                var symbol = right.Clone();

                (symbol as Variable).Exponent = (left.Exponent - right.Exponent) as Real;
                res = new Div(symbol, right.Prefix);
            }
            //When left exponent equals right exponent. 6x^3/3x^3 -> 6/3 -> 2
            else
            {
                res = left.Prefix / right.Prefix;
            }

            return(res);
        }
 public ObjectActionProperties Clone()
 {
     return(new ObjectActionProperties(Variable.Clone(), _variablesRepository, _objectsRepository)
     {
         Actions = Actions.ToList()
     });
 }
 public override void ReplaceRegisterUsage(int oldIndex, int newIndex)
 {
     if (Index.Index == oldIndex)
     {
         Index = Index.Clone(newIndex);
     }
 }
Example #4
0
        public void Add(Variable var)
        {
            if(var == null)
            {
                throw new ParseException("Valid  variable", "null variable");
            }

            if(var.Name == null)
            {
                throw new ParseException("Valid  variable", "null named variable");
            }

            if(var.Name.Length == 0)
            {
                throw new ParseException("Valid variable", "non named variable");
            }

            if(!VarIsArray(var))
            {
                if((var as VariableItem).Value.Type == HVMType.Unknown)
                {
                    throw new ParseException("Variable of known type",
                        string.Format("Variable of unknown type: {0}", var.Name));
                }
            }

            if(_symbols.ContainsKey(var.Name))
            {
                throw new ParseException("Unique variable", string.Format("Variable added to lexical scope twice: {0}", var.Name));
            }

            _symbols[var.Name]=var.Clone();
        }
        public VariableEditorPicker(AutoSplitEnv env, Variable variable = null)
        {
            InitializeComponent();

            _env           = env;
            EditedVariable = variable?.Clone(_env);

            var dictionary = env.VariableTypes.Keys
                             .Except(env.HiddenVariables)
                             .Where(t => env.VariableTypes[t] != null)
                             .ToDictionary(t =>
            {
                var tName = t.Name;
                if (tName.Contains("`"))
                {
                    tName = tName.Remove(tName.IndexOf("`"));
                }
                return(tName);
            });

            cbVarTypes.DataSource            = new BindingSource(dictionary.OrderBy(p => p.Key), null);
            cbVarTypes.DisplayMember         = "Key";
            cbVarTypes.ValueMember           = "Value";
            cbVarTypes.SelectedValueChanged += cbVarTypes_SelectedValueChanged;
            cbVarTypes.SelectedItem          = dictionary.First(p => p.Value == env.DefaultVariableType);
        }
Example #6
0
        public void CloneDependentVariable()
        {
            var x = new Variable <int>("x")
            {
                Values = { 1, 2, 3 }
            };
            var y = new Variable <int>("y")
            {
                Arguments = { x }
            };

            // TODO: would be nice to call above as: var y = = new Variable<int>("y") { Arguments = { x } };

            var clonedY = (IVariable <int>)y.Clone();

            // check argument
            Assert.AreEqual(y.Name, clonedY.Name);
            Assert.AreNotEqual(y, clonedY);
            Assert.AreNotEqual(y.Store, clonedY.Store);
            Assert.AreEqual(y.Values.Count, clonedY.Values.Count);

            // check argument
            var clonedX = (IVariable <int>)clonedY.Arguments[0];

            Assert.AreEqual(x.Name, clonedX.Name);
            Assert.AreNotEqual(x, clonedX);
            Assert.AreNotEqual(x.Store, clonedX.Store);
            Assert.AreEqual(x.Values.Count, clonedX.Values.Count);
            Assert.IsTrue(x.Values.SequenceEqual(clonedX.Values));
            Assert.AreEqual(y.Arguments[0].Values[0], clonedY.Arguments[0].Values[0]);
        }
 public override void ReplaceRegisterUsage(int oldIndex, int newIndex)
 {
     if (Variable.Index == oldIndex)
     {
         Variable = Variable.Clone(newIndex);
     }
 }
Example #8
0
        public void Clone()
        {
            var x = new Variable <int>("x")
            {
                Values            = { 1, 2, 3 },
                Unit              = new Unit("distance", "m"),
                ExtrapolationType = ExtrapolationType.Constant,
                InterpolationType = InterpolationType.Linear
            };

            var clone = (IVariable <int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
            .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
            Assert.AreEqual(x.ExtrapolationType, clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);
            Assert.AreNotSame(x.Unit, clone.Unit);
            Assert.AreEqual(x.Unit.Name, clone.Unit.Name);
            Assert.AreEqual(x.Unit.Symbol, clone.Unit.Symbol);
        }
Example #9
0
 public override void ReplaceRegisterUsage(int oldIndex, int newIndex)
 {
     if (Array.Index == oldIndex)
     {
         Array = Array.Clone(newIndex);
     }
 }
Example #10
0
 public override void ReplaceRegisterUsage(int oldIndex, int newIndex)
 {
     if (Result.Index == oldIndex)
     {
         Result = Result.Clone(newIndex);
     }
 }
Example #11
0
 public override void ReplaceRegisterUsage(int oldIndex, int newIndex)
 {
     if (Src.Index == oldIndex)
     {
         Src = Src.Clone(newIndex);
     }
 }
Example #12
0
        public void Clone()
        {
            var x = new Variable<int>("x")
                {
                    Values = {1, 2, 3},
                    Unit = new Unit("distance", "m"),
                    ExtrapolationType = ExtrapolationType.Constant,
                    InterpolationType = InterpolationType.Linear
                };

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
            Assert.AreEqual(x.ExtrapolationType, clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);
            Assert.AreNotSame(x.Unit, clone.Unit);
            Assert.AreEqual(x.Unit.Name, clone.Unit.Name);
            Assert.AreEqual(x.Unit.Symbol, clone.Unit.Symbol);
        }
Example #13
0
        public override Variable VisitVariable(Variable node)
        {
            var ret = (Variable)node.Clone();

            ret.TypedIdent = VisitTypedIdent(ret.TypedIdent);
            return(ret);
        }
 public override void ReplaceRegisterUsage(int oldIndex, int newIndex)
 {
     base.ReplaceRegisterUsage(oldIndex, newIndex);
     if (Operand.Index == oldIndex)
     {
         Operand = Operand.Clone(newIndex);
     }
 }
Example #15
0
 public override void ReplaceRegisterUsage(int oldIndex, int newIndex)
 {
     base.ReplaceRegisterUsage(oldIndex, newIndex);
     if (Source.Index == oldIndex)
     {
         Source = Source.Clone(newIndex);
     }
 }
Example #16
0
        //Multipies Variable's exponent with a real, and returns Variable.
        private Variable VariableOperation(Variable left, Real right)
        {
            Variable res = left.Clone() as Variable;

            res.Exponent = (left.Exponent * right) as Real;

            return(res);
        }
Example #17
0
        public LayerBase Clone()
        {
            var clone = (LayerBase)Activator.CreateInstance(this.GetType(), new object[] { false });

            clone.Block    = Block;
            clone.Variable = Variable.Clone();
            return(clone);
        }
Example #18
0
        //Returns two Variables added together. 2x+3x -> 5x
        private Expression VariableOperation(Variable left, Variable right)
        {
            var res = left.Clone();

            (res as Variable).Prefix = (left.Prefix + right.Prefix) as Real;

            return(res);
        }
Example #19
0
        //Mul Variables prefixs, and Add Variables exponents, and return a new Variable.
        private Expression SameVariableOperation(Variable left, Variable right)
        {
            var res = left.Clone() as Variable;

            res.Prefix   = (left.Prefix * right.Prefix) as Real;
            res.Exponent = (left.Exponent + right.Exponent) as Real;

            return(res);
        }
Example #20
0
        /// <summary>
        /// Analyzes the specified expression.
        /// </summary>
        /// <param name="exp">The expression.</param>
        /// <returns>
        /// The result of analysis.
        /// </returns>
        public override IExpression Analyze(Variable exp)
        {
            if (exp.Equals(Variable))
            {
                return(new Number(1));
            }

            return(exp.Clone());
        }
        public override Statement Clone()
        {
            BlockStatement clonedBody = Body != null?body.Clone() as BlockStatement : null;

            ForEachStatement result = new ForEachStatement(Variable.Clone() as VariableDeclarationExpression, Collection.Clone(), clonedBody, mappedConditionInstructions, mappedFinallyInstructions);

            CopyParentAndLabel(result);
            return(result);
        }
Example #22
0
        protected override IEnumerable <IEnumerable <Interruption> > InnerExecute(Return.ReturnSetter me)
        {
            // Step1: prepare new frame
            Variable oldNameSpace       = Mediator.Instance.ExecutingNameSpace;
            string   functionName       = ChildID[0].GetCode();
            Variable templateStructure  = Mediator.Instance.ExecutingNameSpace.Get("@function_" + functionName) as Variable;
            Variable newNameSpaceParent = templateStructure.Parent;
            Variable callStructure      = templateStructure.Clone() as Variable;
            BaseNode actualParams       = ChildID[1];

            string[] paramIndex = callStructure.CurrentLevelGet("@index") as string[];
            int      id         = 0;

            foreach (BaseNode actualParam in actualParams.ChildID)
            {
                Return rhs = new Return();
                yield return(actualParam.Execute(rhs));

                callStructure.Reassign(paramIndex[id++], rhs.Object);
            }

            // Step2: stash old frame, change name space
            Variable newNameSpace = callStructure;
            Variable stashed      = null;

            if (newNameSpaceParent.CurrentLevelContainsKey(functionName))
            {
                // Stash the old stuff
                stashed = newNameSpaceParent.CurrentLevelGet(functionName) as Variable;
                newNameSpaceParent.CurrentLevelEraseKey(functionName);
            }
            newNameSpaceParent.RegisterObject(functionName, callStructure);
            Mediator.Instance.ExecutingNameSpace = callStructure;

            // Step3: Execute the procedure
            BaseNode callNode = callStructure.CurrentLevelGet("@address") as BaseNode;

            yield return(callNode.Execute());

            object returnValue = Type == "function_call" ?
                                 callStructure.CurrentLevelGet("@return") : null;

            // Step4: Clean, recover the old frame and old name space
            newNameSpaceParent.CurrentLevelEraseKey(functionName);
            if (!(stashed is null))
            {
                newNameSpaceParent.RegisterObject(functionName, stashed);
            }
            Mediator.Instance.ExecutingNameSpace = oldNameSpace;

            if (Type == "function_call")
            {
                me.Return(returnValue);
            }
            yield break;
        }
Example #23
0
        //x^z * y^z -> (x*y)^z
        private Expression DifferentVariableOperation(Variable left, Variable right)
        {
            var newLeft  = left.Clone();
            var newRight = right.Clone();

            (newLeft as Variable).Exponent  = new Integer(1);
            (newRight as Variable).Exponent = new Integer(1);

            return(new Mul(left.Prefix * right.Prefix, new Exp(new Mul(newLeft, newRight), left.Exponent)));
        }
Example #24
0
 public void BeginEdit()
 {
     if (inEdit)
     {
         return;
     }
     inEdit              = true;
     bakVariable         = variable.Clone() as Variable;
     bakResponseTypeCode = response.TypeCode;
 }
Example #25
0
        public void TestClone()
        {
            byte[]          domainValues   = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            Domain <byte>   domain         = new Domain <byte>(domainValues.ToList());
            Variable <byte> variable       = new Variable <byte>(1, domain, "V");
            Variable <byte> variableCloned = variable.Clone();

            variable.domain.values.Remove(3);
            Assert.AreNotEqual(variable.domain.values.Count, variableCloned.domain.values.Count);
            Assert.AreEqual(variable, variableCloned);
            Assert.AreEqual(variable.domain.values.Count + 1, variableCloned.domain.values.Count);
        }
Example #26
0
            private IExpression SubstituteVariableToExpr(IExpression baseExpression, Variable x, IExpression y)
            {
                if (y == null)
                {
                    return(baseExpression.Clone());
                }
                var rv = baseExpression.Clone();
                Dictionary <Variable, int> closing = new Dictionary <Variable, int>();

                rv = _substituteVariableToExpr(rv, (Variable)x.Clone(), y, closing);
                return(rv);
            }
Example #27
0
        public void CloneUsingStore()
        {
            var x = new Variable<int>("x") { Values = { 1, 2, 3 } };

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
        }
Example #28
0
File: Utils.cs Project: yuedeji/esh
            public override Variable VisitVariable(Variable node)
            {
                if (node.Name.StartsWith(_prefix))
                {
                    return(node);
                }
                var result = node.Clone() as Variable;

                if (result == null)
                {
                    return(node);
                }
                result.Name = _prefix + result.Name;
                return(result);
            }
Example #29
0
        public void CloneUsingStore()
        {
            var x = new Variable <int>("x")
            {
                Values = { 1, 2, 3 }
            };

            var clone = (IVariable <int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
            .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
        }
Example #30
0
        public void Clone()
        {
            var x = new Variable<int>("x") { Values = {1, 2, 3} };
            x.ExtrapolationType = ApproximationType.Constant;
            x.InterpolationType = ApproximationType.Linear;

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)
            
            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] {1, 2, 3});
            Assert.AreEqual(x.ExtrapolationType,clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);

        }
Example #31
0
        public override void ValidateSemantic()
        {
            var typeOfDeclaretion = Type.ValidateSemantic();

            foreach (var expressionNode in InitValues)

            {
                if (expressionNode.ValidateSemantic() != typeOfDeclaretion)
                {
                    throw new SemanticException($"Error: Row {expressionNode.NodePosition.Row} Colum:{expressionNode.NodePosition.Column} los elementos del arreglo deben ser igual que el tipo declarado");
                }
            }
            var variableClone = (IdVariable)Variable.Clone();

            Context.StackOfContext.Stack.Peek().RegisterType(Variable.Value, Type.ValidateSemantic(), variableClone.Accesors?.Count ?? 0);
            Context.StackOfContext.Stack.Peek().InformatioNVariable.Add(Variable.Value, new InforamtionVariable()
            {
                Lenght = Variable.Accesors?.Count ?? 0
            });
            Context.StackOfContext.Stack.Peek().ValuesOfArrays.Add(Variable.Value, new List <Value>());
        }
        public VariableEditor(AutoSplitEnv env, Type varType, Variable source)
        {
            InitializeComponent();

            _env           = env;
            EditedVariable = source?.Clone(env);

            var typeName = varType.Name.IndexOf("`") != -1
                                ? varType.Name.Remove(varType.Name.IndexOf("`"))
                                : varType.Name;

            Text = typeName + " Editor";

            _editor          = (VariableControl)Activator.CreateInstance(_env.GetEditor(varType), env, source);
            _editor.Dock     = DockStyle.Fill;
            _editor.Margin   = new Padding(_editor.Margin.Left, _editor.Margin.Top, _editor.Margin.Right, 0);
            _editor.TabIndex = 0;
            tlpMain.Controls.Add(_editor);
            tlpMain.SetRow(_editor, 0);
            tlpMain.SetColumn(_editor, 0);
        }
Example #33
0
        public void Clone()
        {
            var x = new Variable <int>("x")
            {
                Values = { 1, 2, 3 }
            };

            x.ExtrapolationType = ApproximationType.Constant;
            x.InterpolationType = ApproximationType.Linear;

            var clone = (IVariable <int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
            .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
            Assert.AreEqual(x.ExtrapolationType, clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);
        }
Example #34
0
        public void Update(Variable var)
        {
            if(var == null)
            {
                throw new ParseException("Valid  variable", "null variable");
            }

            if(var.Name == null)
            {
                throw new ParseException("Valid  variable", "null named variable");
            }

            if(var.Name.Length == 0)
            {
                throw new ParseException("Valid variable", "non named variable");
            }

            if(var.Type == HVMType.Unknown)
            {
                throw new ParseException("Variable of known type",
                    string.Format("Variable of unknown type: {0}", var.Name));
            }

            LexicalScope ls = GetContainingLexicalScope(var.Name);
            if(ls != null)
            {
                ls._symbols[var.Name]=var.Clone();
            }
        }
        private void AddPredicatedEqualityCandidateInvariant(IRegion region, string loopPredicate, Variable v)
        {
            var inv = Expr.Imp(
                Expr.And(
                    new IdentifierExpr(Token.NoToken, new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, loopPredicate + "$1", Microsoft.Boogie.Type.Int))),
                    new IdentifierExpr(Token.NoToken, new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, loopPredicate + "$2", Microsoft.Boogie.Type.Int)))),
                Expr.Eq(
                    new IdentifierExpr(Token.NoToken, new VariableDualiser(1, verifier, impl.Name).VisitVariable(v.Clone() as Variable)),
                    new IdentifierExpr(Token.NoToken, new VariableDualiser(2, verifier, impl.Name).VisitVariable(v.Clone() as Variable))));

            verifier.AddCandidateInvariant(region, inv, "predicatedEquality");
        }
Example #36
0
        public void CloneDependentVariable()
        {
            var x = new Variable<int>("x") {Values = {1, 2, 3}};
            var y = new Variable<int>("y") {Arguments = {x}};

            // TODO: would be nice to call above as: var y = = new Variable<int>("y") { Arguments = { x } };
            
            var clonedY = (IVariable<int>)y.Clone();

            // check argument
            Assert.AreEqual(y.Name, clonedY.Name);
            Assert.AreNotEqual(y, clonedY);
            Assert.AreNotEqual(y.Store, clonedY.Store);
            Assert.AreEqual(y.Values.Count, clonedY.Values.Count);

            // check argument
            var clonedX = (IVariable<int>)clonedY.Arguments[0];
            Assert.AreEqual(x.Name, clonedX.Name);
            Assert.AreNotEqual(x, clonedX);
            Assert.AreNotEqual(x.Store, clonedX.Store);
            Assert.AreEqual(x.Values.Count, clonedX.Values.Count);
            Assert.IsTrue(x.Values.SequenceEqual(clonedX.Values));
            Assert.AreEqual(y.Arguments[0].Values[0],clonedY.Arguments[0].Values[0]);
        }