Example #1
0
 /// <summary>
 /// Sets up the command
 /// </summary>
 public override void Setup()
 {
     ILGenerator Generator = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Generator;
     if (RightHandSide.DataType.IsValueType 
         && !LeftHandSide.DataType.IsValueType)
     {
         RightHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Box(RightHandSide);
     }
     else if (!RightHandSide.DataType.IsValueType 
         && LeftHandSide.DataType.IsValueType)
     {
         RightHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.UnBox(RightHandSide, LeftHandSide.DataType);
     }
     else if (!RightHandSide.DataType.IsValueType 
         && !LeftHandSide.DataType.IsValueType
         && RightHandSide.DataType != LeftHandSide.DataType)
     {
         RightHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Cast(RightHandSide, LeftHandSide.DataType);
     }
     if (LeftHandSide is FieldBuilder || LeftHandSide is IPropertyBuilder)
         Generator.Emit(OpCodes.Ldarg_0);
     if (RightHandSide is FieldBuilder || RightHandSide is IPropertyBuilder)
         Generator.Emit(OpCodes.Ldarg_0);
     RightHandSide.Load(Generator);
     if (RightHandSide.DataType != LeftHandSide.DataType)
     {
         if (ConversionOpCodes.ContainsKey(LeftHandSide.DataType))
         {
             Generator.Emit(ConversionOpCodes[LeftHandSide.DataType]);
         }
     }
     LeftHandSide.Save(Generator);
 }
Example #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ObjectCallingOn">Object calling on</param>
 /// <param name="Method">Method builder</param>
 /// <param name="MethodCalling">Method calling on the object</param>
 /// <param name="Parameters">List of parameters to send in</param>
 public Call(IMethodBuilder Method, VariableBase ObjectCallingOn, MethodInfo MethodCalling, object[] Parameters)
     : base()
 {
     this.ObjectCallingOn = ObjectCallingOn;
     this.MethodCalling = MethodCalling;
     this.MethodCallingFrom = Method;
     if (MethodCalling.ReturnType != null && MethodCalling.ReturnType != typeof(void))
     {
         Result = Method.CreateLocal(MethodCalling.Name + "ReturnObject"+YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.ObjectCounter.ToString(), MethodCalling.ReturnType);
     }
     if (Parameters != null)
     {
         this.Parameters = new VariableBase[Parameters.Length];
         for (int x = 0; x < Parameters.Length; ++x)
         {
             if (Parameters[x] is VariableBase)
                 this.Parameters[x] = (VariableBase)Parameters[x];
             else
                 this.Parameters[x] = MethodCallingFrom.CreateConstant(Parameters[x]);
         }
     }
     else
     {
         this.Parameters = null;
     }
 }
Example #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="LeftHandSide">Left hand side</param>
 /// <param name="Value">Value to store</param>
 public Assign(VariableBase LeftHandSide, object Value)
     : base()
 {
     if (LeftHandSide == null)
         throw new ArgumentNullException("LeftHandSide");
     this.LeftHandSide = LeftHandSide;
     if (!(Value is VariableBase))
         this.RightHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(Value);
     else
         this.RightHandSide = (VariableBase)Value;
 }
Example #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="EndIfLabel">End if label (for this else if)</param>
 /// <param name="ComparisonType">Comparison type</param>
 /// <param name="LeftHandSide">Left hand side</param>
 /// <param name="RightHandSide">Right hand side</param>
 public ElseIf(Label EndIfLabel, Comparison ComparisonType, VariableBase LeftHandSide, VariableBase RightHandSide)
     : base()
 {
     this.EndIfLabel = EndIfLabel;
     if (LeftHandSide != null)
         this.LeftHandSide = LeftHandSide;
     else
         this.LeftHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null);
     if (RightHandSide != null)
         this.RightHandSide = RightHandSide;
     else
         this.RightHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null);
     this.ComparisonType = ComparisonType;
 }
Example #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ComparisonType">Comparison type</param>
 /// <param name="LeftHandSide">Left hand side</param>
 /// <param name="RightHandSide">Right hand side</param>
 public While(Comparison ComparisonType, VariableBase LeftHandSide, VariableBase RightHandSide)
     : base()
 {
     ILGenerator Generator = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Generator;
     this.StartWhileLabel = Generator.DefineLabel();
     this.EndWhileLabel = Generator.DefineLabel();
     if (LeftHandSide != null)
         this.LeftHandSide = LeftHandSide;
     else
         this.LeftHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null);
     if (RightHandSide != null)
         this.RightHandSide = RightHandSide;
     else
         this.RightHandSide = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null);
     this.ComparisonType = ComparisonType;
 }
Example #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ObjectCallingOn">Object calling on</param>
 /// <param name="Method">Method builder</param>
 /// <param name="MethodCalling">Method calling on the object</param>
 /// <param name="Parameters">List of parameters to send in</param>
 public Call(IMethodBuilder Method, VariableBase ObjectCallingOn, ConstructorInfo MethodCalling, object[] Parameters)
     : base()
 {
     this.ObjectCallingOn = ObjectCallingOn;
     this.ConstructorCalling = MethodCalling;
     this.MethodCallingFrom = Method;
     if (Parameters != null)
     {
         this.Parameters = new VariableBase[Parameters.Length];
         for (int x = 0; x < Parameters.Length; ++x)
         {
             if (Parameters[x] is VariableBase)
                 this.Parameters[x] = (VariableBase)Parameters[x];
             else
                 this.Parameters[x] = MethodCallingFrom.CreateConstant(Parameters[x]);
         }
     }
     else
     {
         this.Parameters = null;
     }
 }
Example #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Value">Value to cast</param>
 /// <param name="ValueType">Desired type to cast to</param>
 public Cast(VariableBase Value,Type ValueType)
     : base()
 {
     this.Value = Value;
     this.ValueType = ValueType;
 }
Example #8
0
 /// <summary>
 /// Throws an exception
 /// </summary>
 /// <param name="Exception">Exception to throw</param>
 public virtual void Throw(VariableBase Exception)
 {
     Throw TempCommand = new Throw(Exception);
     TempCommand.Setup();
     Commands.Add(TempCommand);
 }
Example #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Exception">Exception to throw</param>
 public Throw(VariableBase Exception)
 {
     this.Exception = Exception;
 }
Example #10
0
 /// <summary>
 /// Creates a while statement
 /// </summary>
 /// <param name="LeftHandSide">Left hand side variable</param>
 /// <param name="ComparisonType">Comparison type</param>
 /// <param name="RightHandSide">Right hand side variable</param>
 /// <returns>The while object</returns>
 public virtual While While(VariableBase LeftHandSide, Enums.Comparison ComparisonType, VariableBase RightHandSide)
 {
     SetCurrentMethod();
     While TempCommand = new While(ComparisonType, LeftHandSide, RightHandSide);
     TempCommand.Setup();
     Commands.Add(TempCommand);
     return TempCommand;
 }
Example #11
0
 /// <summary>
 /// Casts an object as a specific type
 /// </summary>
 /// <param name="Value">Value to cast</param>
 /// <param name="ValueType">Type to cast to</param>
 /// <returns>The resulting variable</returns>
 public virtual VariableBase Cast(VariableBase Value, Type ValueType)
 {
     Cast TempCommand = new Cast(Value, ValueType);
     TempCommand.Setup();
     Commands.Add(TempCommand);
     ++ObjectCounter;
     return TempCommand.Result;
 }
Example #12
0
 /// <summary>
 /// Creates an if statement
 /// </summary>
 /// <param name="LeftHandSide">Left hand side variable</param>
 /// <param name="ComparisonType">Comparison type</param>
 /// <param name="RightHandSide">Right hand side variable</param>
 /// <returns>The if object</returns>
 public virtual If If(VariableBase LeftHandSide, Enums.Comparison ComparisonType, VariableBase RightHandSide)
 {
     SetCurrentMethod();
     YunShop.Utilities.Reflection.Emit.Commands.If TempCommand = new If(ComparisonType, LeftHandSide, RightHandSide);
     TempCommand.Setup();
     Commands.Add(TempCommand);
     return TempCommand;
 }
Example #13
0
 /// <summary>
 /// Assigns a value to a variable
 /// </summary>
 /// <param name="LeftHandSide">Variable to assign to</param>
 /// <param name="Value">Value to assign</param>
 public virtual void Assign(VariableBase LeftHandSide, object Value)
 {
     SetCurrentMethod();
     Assign TempCommand = new Assign(LeftHandSide, Value);
     TempCommand.Setup();
     Commands.Add(TempCommand);
 }
Example #14
0
 /// <summary>
 /// Calls a constructor
 /// </summary>
 /// <param name="ObjectCallingOn">Object to call the constructor on</param>
 /// <param name="MethodCalling">Constructor to call</param>
 /// <param name="Parameters">Parameters to use</param>
 public virtual void Call(VariableBase ObjectCallingOn, ConstructorInfo MethodCalling, object[] Parameters)
 {
     SetCurrentMethod();
     Call TempCommand = new Call(this, ObjectCallingOn, MethodCalling, Parameters);
     TempCommand.Setup();
     Commands.Add(TempCommand);
     ++ObjectCounter;
 }
Example #15
0
 /// <summary>
 /// Calls a method
 /// </summary>
 /// <param name="ObjectCallingOn">Object to call the method on</param>
 /// <param name="MethodCalling">Method to call</param>
 /// <param name="Parameters">Parameters to use</param>
 /// <returns>The result of the method call</returns>
 public virtual VariableBase Call(VariableBase ObjectCallingOn, MethodInfo MethodCalling, object[] Parameters)
 {
     SetCurrentMethod();
     Call TempCommand = new Call(this, ObjectCallingOn, MethodCalling, Parameters);
     TempCommand.Setup();
     Commands.Add(TempCommand);
     ++ObjectCounter;
     return TempCommand.Result;
 }
Example #16
0
 /// <summary>
 /// Defines an else if statement
 /// </summary>
 /// <param name="ComparisonType">Comparison type</param>
 /// <param name="LeftHandSide">left hand side value</param>
 /// <param name="RightHandSide">right hand side value</param>
 public virtual void ElseIf(VariableBase LeftHandSide, Comparison ComparisonType, VariableBase RightHandSide)
 {
     ILGenerator Generator = YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Generator;
     Generator.Emit(OpCodes.Br, EndIfFinalLabel);
     Generator.MarkLabel(EndIfLabel);
     EndIfLabel = Generator.DefineLabel();
     YunShop.Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Commands.Add(new ElseIf(EndIfLabel, ComparisonType, LeftHandSide, RightHandSide));
 }