Jeremy Schonfeld 6110fbf96f
(112909324) Add descriptions to Predicate
* (112909324) Add debug descriptions to Predicate

* Fix build errors
2023-11-14 13:44:59 -05:00

186 lines
6.2 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions {
public struct IntDivision<
LHS : PredicateExpression,
RHS : PredicateExpression
> : PredicateExpression
where
LHS.Output == RHS.Output,
LHS.Output : BinaryInteger
{
public typealias Output = LHS.Output
public let lhs: LHS
public let rhs: RHS
public init(lhs: LHS, rhs: RHS) {
self.lhs = lhs
self.rhs = rhs
}
public func evaluate(_ bindings: PredicateBindings) throws -> Output {
let a = try lhs.evaluate(bindings)
let b = try rhs.evaluate(bindings)
return a / b
}
}
public struct IntRemainder<
LHS : PredicateExpression,
RHS : PredicateExpression
> : PredicateExpression
where
LHS.Output == RHS.Output,
LHS.Output : BinaryInteger
{
public typealias Output = LHS.Output
public let lhs: LHS
public let rhs: RHS
public init(lhs: LHS, rhs: RHS) {
self.lhs = lhs
self.rhs = rhs
}
public func evaluate(_ bindings: PredicateBindings) throws -> Output {
let a = try lhs.evaluate(bindings)
let b = try rhs.evaluate(bindings)
return a % b
}
}
public struct FloatDivision<
LHS : PredicateExpression,
RHS : PredicateExpression
> : PredicateExpression
where
LHS.Output == RHS.Output,
LHS.Output : FloatingPoint
{
public typealias Output = LHS.Output
public let lhs: LHS
public let rhs: RHS
public init(lhs: LHS, rhs: RHS) {
self.lhs = lhs
self.rhs = rhs
}
public func evaluate(_ bindings: PredicateBindings) throws -> Output {
let a = try lhs.evaluate(bindings)
let b = try rhs.evaluate(bindings)
return a / b
}
}
public static func build_Division<LHS, RHS>(lhs: LHS, rhs: RHS) -> IntDivision<LHS, RHS> {
IntDivision(lhs: lhs, rhs: rhs)
}
public static func build_Division<LHS, RHS>(lhs: LHS, rhs: RHS) -> FloatDivision<LHS, RHS> {
FloatDivision(lhs: lhs, rhs: rhs)
}
public static func build_Remainder<LHS, RHS>(lhs: LHS, rhs: RHS) -> IntRemainder<LHS, RHS> {
IntRemainder(lhs: lhs, rhs: rhs)
}
}
@available(FoundationPreview 0.3, *)
extension PredicateExpressions.FloatDivision : CustomStringConvertible {
public var description: String {
"FloatDivision(lhs: \(lhs), rhs: \(rhs))"
}
}
@available(FoundationPreview 0.3, *)
extension PredicateExpressions.IntDivision : CustomStringConvertible {
public var description: String {
"IntDivision(lhs: \(lhs), rhs: \(rhs))"
}
}
@available(FoundationPreview 0.3, *)
extension PredicateExpressions.IntRemainder : CustomStringConvertible {
public var description: String {
"IntRemainder(lhs: \(lhs), rhs: \(rhs))"
}
}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.FloatDivision : StandardPredicateExpression where LHS : StandardPredicateExpression, RHS : StandardPredicateExpression {}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.IntRemainder : StandardPredicateExpression where LHS : StandardPredicateExpression, RHS : StandardPredicateExpression {}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.IntDivision : StandardPredicateExpression where LHS : StandardPredicateExpression, RHS : StandardPredicateExpression {}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.FloatDivision : Codable where LHS : Codable, RHS : Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(lhs)
try container.encode(rhs)
}
public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
lhs = try container.decode(LHS.self)
rhs = try container.decode(RHS.self)
}
}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.IntRemainder : Codable where LHS : Codable, RHS : Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(lhs)
try container.encode(rhs)
}
public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
lhs = try container.decode(LHS.self)
rhs = try container.decode(RHS.self)
}
}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.IntDivision : Codable where LHS : Codable, RHS : Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(lhs)
try container.encode(rhs)
}
public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
lhs = try container.decode(LHS.self)
rhs = try container.decode(RHS.self)
}
}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.FloatDivision : Sendable where LHS : Sendable, RHS : Sendable {}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.IntRemainder : Sendable where LHS : Sendable, RHS : Sendable {}
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
extension PredicateExpressions.IntDivision : Sendable where LHS : Sendable, RHS : Sendable {}