Пример #1
0
        public Variable UnaryOperation(Variable variable, VariableOperationType op)
        {
            Debug.Assert(variable.Type == this);

            if ((this.UnaryOperationFuncs?.ContainsKey(op)).GetValueOrDefault())
            {
                var retVariable = this.UnaryOperationFuncs[op](variable);

                // add connection
                var newCon = new VariableConnection()
                {
                    OperationType = op
                };
                newCon.InVariables.Add(variable);
                newCon.OutVariables.Add(retVariable);

                retVariable.ParentConnections.Add(newCon);

                // note: retVariable might be unused. The calculation of unused variables MUST be done, but the result will be cleared out later

                return(retVariable);
            }
            else
            {
                throw new Exception($"Type \"{this.TypeCodeName}\" doesn't support \"{op.ToString()}\" operation.");
            }
        }
Пример #2
0
        public override IConnection CreateConnection()
        {
            VariableConnection conn = new VariableConnection().SetProgram(ParentProgram) as VariableConnection;

            conn.Init();
            return(conn);
        }
Пример #3
0
        public Variable ExplicitConvert(Variable variable, NType targetType)
        {
            Debug.Assert(variable.Type == this);
            var retVariable = this.ExplicitConvertFunc(variable, targetType);

            if (Object.ReferenceEquals(retVariable, variable))
            {
                return(retVariable);
            }

            // add connection
            var newCon = new VariableConnection()
            {
                OperationType = VariableOperationType.TypeCast_Trim
            };

            newCon.InVariables.Add(variable);
            newCon.OutVariables.Add(retVariable);

            retVariable.ParentConnections.Add(newCon);

            return(retVariable);
        }