public override void ExitRelationalExpression(CParser.RelationalExpressionContext context) { if (context.relationalExpression() != null) { int contextLength = context.GetText().Length; int lhsLength = context.relationalExpression().GetText().Length; int rhsLength = context.shiftExpression().GetText().Length; string operation = context.GetText().Substring(lhsLength, contextLength - (lhsLength + rhsLength)); if (operation == "<") { //relationalExpression '<' shiftExpression SafeCall(context, CExpression.LessThanOperator); } else if (operation == ">") { //relationalExpression '>' shiftExpression SafeCall(context, CExpression.GreaterThanOperator); } else if (operation == "<=") { //relationalExpression '<=' shiftExpression SafeCall(context, CExpression.LessThanOrEqualOperator); } else if (operation == ">=") { //relationalExpression '>=' shiftExpression SafeCall(context, CExpression.GreaterThanOrEqualOperator); } } }
protected ObjectDef EmitRelationalExpression(CParser.RelationalExpressionContext relationalExpression) { ObjectDef returnObjectDef = null; if (relationalExpression.shiftExpression() != null) { returnObjectDef = EmitShiftExpression(relationalExpression.shiftExpression()); } if (relationalExpression.shiftExpression() != null && relationalExpression.relationalExpression() != null) { var relationalObj = EmitRelationalExpression(relationalExpression.relationalExpression()); if (relationalExpression.Less() != null) { relationalObj.Load(); returnObjectDef.Load(); _generatorIL.Emit(OpCodes.Clt); } else if (relationalExpression.LessEqual() != null) { ObjectDef less; ObjectDef equal; relationalObj.Load(); returnObjectDef.Load(); _generatorIL.Emit(OpCodes.Clt); less = LocalObjectDef.AllocateLocal(typeof(int)); returnObjectDef.Load(); relationalObj.Load(); _generatorIL.Emit(OpCodes.Ceq); equal = LocalObjectDef.AllocateLocal(typeof(int)); less.Load(); equal.Load(); _generatorIL.Emit(OpCodes.Or); } else if (relationalExpression.Greater() != null) { relationalObj.Load(); returnObjectDef.Load(); _generatorIL.Emit(OpCodes.Cgt); } else if (relationalExpression.GreaterEqual() != null) { ObjectDef greater; ObjectDef equal; relationalObj.Load(); returnObjectDef.Load(); _generatorIL.Emit(OpCodes.Cgt); greater = LocalObjectDef.AllocateLocal(typeof(int)); relationalObj.Load(); returnObjectDef.Load(); _generatorIL.Emit(OpCodes.Ceq); equal = LocalObjectDef.AllocateLocal(typeof(int)); greater.Load(); equal.Load(); _generatorIL.Emit(OpCodes.Or); } returnObjectDef = LocalObjectDef.AllocateLocal(typeof(int)); } return(returnObjectDef); }