protected virtual Expression Visit(ComparrisonExp compExp) { var leftExp = compExp.LeftNode; var rightExp = compExp.RightNode; if (!(leftExp is GetFieldExp)) { throw new Exception(); } if (!(rightExp is ConstExp) && !(rightExp is GetFieldExp)) { throw new Exception(); } var leftAccess = new AccessInfo(); Visit((GetFieldExp)leftExp, new Stack <Tuple <string, Type> >(), leftAccess); Expression right = null; Tuple <Type, object> constInfo = null; if (rightExp is ConstExp) { constInfo = Visit((ConstExp)rightExp); //类型校验 if (constInfo.Item1 != leftAccess.FieldType) { throw new Exception(); } right = Expression.Constant(constInfo.Item2); } if (rightExp is GetFieldExp) { AccessInfo rightAccess = new AccessInfo(); Visit((GetFieldExp)rightExp, new Stack <Tuple <string, Type> >(), rightAccess); if (leftAccess.FieldType != rightAccess.FieldType) { throw new Exception(); } //todo 暂时不支持对比表达式右边是取字段或者字段操作 throw new Exception(); } var creator = OpDic[compExp.BaseToken.OpType]; return(creator(leftAccess.exp, right)); }
protected override void Visit(ComparrisonExp compExp) { base.Visit(compExp); var exp = temp.Pop(); var leftAccess = accessInfo; if (exp.GetType() == typeof(ConstantExpression)) { if (((ConstantExpression)exp).Type != leftAccess.FieldType) { throw new Exception(); } } else { //todo 暂时不支持对比表达式右边是取字段或者字段操作 throw new Exception(); } var creator = OpDic[compExp.BaseToken.OpType]; creator(leftAccess.exp, exp); }
protected virtual void Visit(ComparrisonExp compExp) { var leftExp = compExp.LeftNode; var rightExp = compExp.RightNode; if (!(leftExp is GetFieldExp)) { throw new Exception(); } if (!(rightExp is ConstExp) && !(rightExp is GetFieldExp)) { throw new Exception(); } Visit((GetFieldExp)leftExp); if (rightExp is ConstExp) { Visit((ConstExp)rightExp); } if (rightExp is GetFieldExp) { Visit((GetFieldExp)rightExp); } }