private ValInfo Visit(NotNode node) { ValInfo val = Visit(node.Operand as dynamic); if (val.isConst) { object obj = !(dynamic)val.val; ReplaceNode(node.Parent, node.ChildIndex, obj, val.type); return(new ValInfo(obj, val.type, true)); } return(new ValInfo()); }
private ValInfo Visit(CastNode node) { ValInfo val = Visit(node.Expression); var type = node.Type as SimpleType; if (val == null) { return(null); } if (val.isConst && type != null) { object obj = null; switch (type.SType) { case SimpleTypeEnum.Bool: obj = (bool)val.val; break; case SimpleTypeEnum.Byte: obj = (byte)val.val; break; case SimpleTypeEnum.Char: obj = (char)val.val; break; case SimpleTypeEnum.Int: obj = (int)val.val; break; case SimpleTypeEnum.Float: obj = (float)val.val; break; case SimpleTypeEnum.Double: obj = (double)val.val; break; default: throw new ArgumentOutOfRangeException(); } return(new ValInfo(obj, type.SType, true)); } return(new ValInfo()); }
private ValInfo Visit(MinusNode node) { if (!node.isUnary) { return(BinaryOperator(node, (x, y) => x - y)); } ValInfo va = Visit(node.LeftOperand as dynamic); if (va.isConst) { object obj = -(dynamic)va.val; ReplaceNode(node.Parent, node.ChildIndex, obj, va.type); return(new ValInfo(obj, va.type, true)); } return(new ValInfo()); }
private ValInfo BinaryOperator(BinaryOperator node, Func <dynamic, dynamic, object> func) { ValInfo lV = Visit(node.LeftOperand as dynamic); ValInfo rV = Visit(node.RightOperand as dynamic); if (lV == null || rV == null) { return(null); } if (lV.isConst && rV.isConst && lV.type == rV.type) { object val = func(lV.val, rV.val); ReplaceNode(node.Parent, node.ChildIndex, val, lV.type); return(new ValInfo(val, rV.type, true)); } return(new ValInfo()); }