1
3 package jminusminus;
4
5 import static jminusminus.CLConstants.*;
6
7
10 abstract class JComparisonExpression extends JBooleanBinaryExpression {
11
19 protected JComparisonExpression(int line, String operator, JExpression lhs, JExpression rhs) {
20 super(line, operator, lhs, rhs);
21 }
22
23
26 public JExpression analyze(Context context) {
27 lhs = (JExpression) lhs.analyze(context);
28 rhs = (JExpression) rhs.analyze(context);
29 lhs.type().mustMatchExpected(line(), Type.INT);
30 rhs.type().mustMatchExpected(line(), lhs.type());
31 type = Type.BOOLEAN;
32 return this;
33 }
34 }
35
36
39 class JGreaterThanOp extends JComparisonExpression {
40
47 public JGreaterThanOp(int line, JExpression lhs, JExpression rhs) {
48 super(line, ">", lhs, rhs);
49 }
50
51
54 public void codegen(CLEmitter output, String targetLabel, boolean onTrue) {
55 lhs.codegen(output);
56 rhs.codegen(output);
57 output.addBranchInstruction(onTrue ? IF_ICMPGT : IF_ICMPLE, targetLabel);
58 }
59 }
60
61
64 class JLessEqualOp extends JComparisonExpression {
65
66
73 public JLessEqualOp(int line, JExpression lhs, JExpression rhs) {
74 super(line, "<=", lhs, rhs);
75 }
76
77
80 public void codegen(CLEmitter output, String targetLabel, boolean onTrue) {
81 lhs.codegen(output);
82 rhs.codegen(output);
83 output.addBranchInstruction(onTrue ? IF_ICMPLE : IF_ICMPGT, targetLabel);
84 }
85 }
86
87
90 class JGreaterEqualOp extends JComparisonExpression {
91
92
99 public JGreaterEqualOp(int line, JExpression lhs, JExpression rhs) {
100 super(line, ">=", lhs, rhs);
101 }
102
103
106 public void codegen(CLEmitter output, String targetLabel, boolean onTrue) {
107 }
109 }
110
111
114 class JLessThanOp extends JComparisonExpression {
115
122 public JLessThanOp(int line, JExpression lhs, JExpression rhs) {
123 super(line, "<", lhs, rhs);
124 }
125
126
129 public void codegen(CLEmitter output, String targetLabel, boolean onTrue) {
130 }
132 }