CodeBinaryOperation.cs 955 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // created on 28/08/2004 at 17:30
  2. #if !FULL_AOT_RUNTIME
  3. using System;
  4. using System.Reflection;
  5. using System.Reflection.Emit;
  6. namespace Mono.CodeGeneration
  7. {
  8. public abstract class CodeBinaryOperation: CodeConditionExpression
  9. {
  10. protected CodeExpression exp1;
  11. protected CodeExpression exp2;
  12. protected Type t1;
  13. protected Type t2;
  14. string symbol;
  15. public CodeBinaryOperation (CodeExpression exp1, CodeExpression exp2, string symbol)
  16. {
  17. this.symbol = symbol;
  18. this.exp1 = exp1;
  19. this.exp2 = exp2;
  20. t1 = exp1.GetResultType ();
  21. t2 = exp2.GetResultType ();
  22. if (!t1.IsPrimitive || !t2.IsPrimitive || (t1 != t2)) {
  23. throw new InvalidOperationException ("Operator " + GetType().Name + " cannot be applied to operands of type '" + t1.Name + " and " + t2.Name);
  24. }
  25. }
  26. public override void PrintCode (CodeWriter cp)
  27. {
  28. exp1.PrintCode (cp);
  29. cp.Write (" " + symbol + " ");
  30. exp2.PrintCode (cp);
  31. }
  32. }
  33. }
  34. #endif