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."); } }
public override IConnection CreateConnection() { VariableConnection conn = new VariableConnection().SetProgram(ParentProgram) as VariableConnection; conn.Init(); return(conn); }
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); }