CodeBinaryOperation.cs 926 B

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