public override Values.Value ReadValue(RunScope scope) { if (_whereExp != null) { _whereExp.ReadValue(scope); } if (_aggExp != null) { return(_aggExp.ReadValue(scope)); } else if (_name == "count") { return(Value.CreateUnknownFromDataType(DataType.Int)); } else { return(base.ReadValue(scope)); } }
public override void Simplify(RunScope scope) { if (Parent == null) { throw new InvalidOperationException("Conditional operator must have a parent."); } var leftScope = scope.Clone(); var leftNode = Parent.GetLeftSibling(leftScope, this); scope.Merge(leftScope); if (leftNode == null) { ReportError(_opSpan, CAError.CA0007, "?"); // Operator '{0}' expects value on left. Parent.ReplaceWithResult(Value.Void, ResultSource.Conditional1, this); } else { var leftValue = leftNode.ReadValue(leftScope); if (leftValue.IsVoid) { leftNode.ReportError(_opSpan, CAError.CA0007, "?"); // Operator '{0}' expects value on left. } Value result = null; if (leftValue.IsTrue) { if (_trueExp != null) { result = _trueExp.ReadValue(scope); } else { result = Value.Void; } } else if (leftValue.IsFalse) { if (_falseExp != null) { result = _falseExp.ReadValue(scope); } else { result = Value.Void; } } else { if (_trueExp != null) { result = _trueExp.ReadValue(scope); } if (_falseExp != null) { var value = _falseExp.ReadValue(scope); if (result == null) { result = value; } } if (result == null) { result = Value.Void; } } Parent.ReplaceWithResult(result, leftNode, this); } }