forked from swiftlang/swift-corelibs-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSExpression.swift
141 lines (121 loc) · 11.1 KB
/
NSExpression.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
// Expressions are the core of the predicate implementation. When expressionValueWithObject: is called, the expression is evaluated, and a value returned which can then be handled by an operator. Expressions can be anything from constants to method invocations. Scalars should be wrapped in appropriate NSValue classes.
extension NSExpression {
public enum ExpressionType : UInt {
case constantValue // Expression that always returns the same value
case evaluatedObject // Expression that always returns the parameter object itself
case variable // Expression that always returns whatever is stored at 'variable' in the bindings dictionary
case keyPath // Expression that returns something that can be used as a key path
case function // Expression that returns the result of evaluating a symbol
case unionSet // Expression that returns the result of doing a unionSet: on two expressions that evaluate to flat collections (arrays or sets)
case intersectSet // Expression that returns the result of doing an intersectSet: on two expressions that evaluate to flat collections (arrays or sets)
case minusSet // Expression that returns the result of doing a minusSet: on two expressions that evaluate to flat collections (arrays or sets)
case subquery
case aggregate
case anyKey
case block
case conditional
}
}
open class NSExpression : NSObject, NSSecureCoding, NSCopying {
public static var supportsSecureCoding: Bool {
return true
}
public required init?(coder aDecoder: NSCoder) {
NSUnimplemented()
}
open func encode(with aCoder: NSCoder) {
NSUnimplemented()
}
open override func copy() -> Any {
return copy(with: nil)
}
open func copy(with zone: NSZone? = nil) -> Any {
NSUnimplemented()
}
public /*not inherited*/ init(format expressionFormat: String, argumentArray arguments: [Any]) { NSUnimplemented() }
public /*not inherited*/ init(format expressionFormat: String, arguments argList: CVaListPointer) { NSUnimplemented() }
public /*not inherited*/ init(forConstantValue obj: Any?) { NSUnimplemented() } // Expression that returns a constant value
open class func expressionForEvaluatedObject() -> NSExpression { NSUnimplemented() } // Expression that returns the object being evaluated
public /*not inherited*/ init(forVariable string: String) { NSUnimplemented() } // Expression that pulls a value from the variable bindings dictionary
public /*not inherited*/ init(forKeyPath keyPath: String) { NSUnimplemented() } // Expression that invokes valueForKeyPath with keyPath
public /*not inherited*/ init(forFunction name: String, arguments parameters: [Any]) { NSUnimplemented() } // Expression that invokes one of the predefined functions. Will throw immediately if the selector is bad; will throw at runtime if the parameters are incorrect.
// Predefined functions are:
// name parameter array contents returns
//-------------------------------------------------------------------------------------------------------------------------------------
// sum: NSExpression instances representing numbers NSNumber
// count: NSExpression instances representing numbers NSNumber
// min: NSExpression instances representing numbers NSNumber
// max: NSExpression instances representing numbers NSNumber
// average: NSExpression instances representing numbers NSNumber
// median: NSExpression instances representing numbers NSNumber
// mode: NSExpression instances representing numbers NSArray (returned array will contain all occurrences of the mode)
// stddev: NSExpression instances representing numbers NSNumber
// add:to: NSExpression instances representing numbers NSNumber
// from:subtract: two NSExpression instances representing numbers NSNumber
// multiply:by: two NSExpression instances representing numbers NSNumber
// divide:by: two NSExpression instances representing numbers NSNumber
// modulus:by: two NSExpression instances representing numbers NSNumber
// sqrt: one NSExpression instance representing numbers NSNumber
// log: one NSExpression instance representing a number NSNumber
// ln: one NSExpression instance representing a number NSNumber
// raise:toPower: one NSExpression instance representing a number NSNumber
// exp: one NSExpression instance representing a number NSNumber
// floor: one NSExpression instance representing a number NSNumber
// ceiling: one NSExpression instance representing a number NSNumber
// abs: one NSExpression instance representing a number NSNumber
// trunc: one NSExpression instance representing a number NSNumber
// uppercase: one NSExpression instance representing a string NSString
// lowercase: one NSExpression instance representing a string NSString
// random none NSNumber (integer)
// randomn: one NSExpression instance representing a number NSNumber (integer) such that 0 <= rand < param
// now none [NSDate now]
// bitwiseAnd:with: two NSExpression instances representing numbers NSNumber (numbers will be treated as NSInteger)
// bitwiseOr:with: two NSExpression instances representing numbers NSNumber (numbers will be treated as NSInteger)
// bitwiseXor:with: two NSExpression instances representing numbers NSNumber (numbers will be treated as NSInteger)
// leftshift:by: two NSExpression instances representing numbers NSNumber (numbers will be treated as NSInteger)
// rightshift:by: two NSExpression instances representing numbers NSNumber (numbers will be treated as NSInteger)
// onesComplement: one NSExpression instance representing a numbers NSNumber (numbers will be treated as NSInteger)
// noindex: an NSExpression parameter (used by CoreData to indicate that an index should be dropped)
// distanceToLocation:fromLocation:
// two NSExpression instances representing CLLocations NSNumber
// length: an NSExpression instance representing a string NSNumber
public /*not inherited*/ init(forAggregate subexpressions: [Any]) { NSUnimplemented() } // Expression that returns a collection containing the results of other expressions
public /*not inherited*/ init(forUnionSet left: NSExpression, with right: NSExpression) { NSUnimplemented() } // return an expression that will return the union of the collections expressed by left and right
public /*not inherited*/ init(forIntersectSet left: NSExpression, with right: NSExpression) { NSUnimplemented() } // return an expression that will return the intersection of the collections expressed by left and right
public /*not inherited*/ init(forMinusSet left: NSExpression, with right: NSExpression) { NSUnimplemented() } // return an expression that will return the disjunction of the collections expressed by left and right
public /*not inherited*/ init(forSubquery expression: NSExpression, usingIteratorVariable variable: String, predicate: Any) { NSUnimplemented() } // Expression that filters a collection by storing elements in the collection in the variable variable and keeping the elements for which qualifer returns true; variable is used as a local variable, and will shadow any instances of variable in the bindings dictionary, the variable is removed or the old value replaced once evaluation completes
public /*not inherited*/ init(forFunction target: NSExpression, selectorName name: String, arguments parameters: [Any]?) { NSUnimplemented() } // Expression that invokes the selector on target with parameters. Will throw at runtime if target does not implement selector or if parameters are wrong.
open class func expressionForAnyKey() -> NSExpression { NSUnimplemented() }
public /*not inherited*/ init(block: @escaping (Any?, [Any], NSMutableDictionary?) -> Any, arguments: [NSExpression]?) { NSUnimplemented() } // Expression that invokes the block with the parameters; note that block expressions are not encodable or representable as parseable strings.
public /*not inherited*/ init(forConditional predicate: Any, trueExpression: NSExpression, falseExpression: NSExpression) { NSUnimplemented() } // Expression that will return the result of trueExpression or falseExpression depending on the value of predicate
public init(expressionType type: ExpressionType) { NSUnimplemented() }
// accessors for individual parameters - raise if not applicable
open var expressionType: ExpressionType { NSUnimplemented() }
open var constantValue: Any { NSUnimplemented() }
open var keyPath: String { NSUnimplemented() }
open var function: String { NSUnimplemented() }
open var variable: String { NSUnimplemented() }
/*@NSCopying*/ open var operand: NSExpression { NSUnimplemented() } // the object on which the selector will be invoked (the result of evaluating a key path or one of the defined functions)
open var arguments: [NSExpression]? { NSUnimplemented() } // array of expressions which will be passed as parameters during invocation of the selector on the operand of a function expression
open var collection: Any { NSUnimplemented() }
/*@NSCopying*/ open var predicate: NSPredicate { NSUnimplemented() }
/*@NSCopying*/ open var left: NSExpression { NSUnimplemented() } // expression which represents the left side of a set expression
/*@NSCopying*/ open var right: NSExpression { NSUnimplemented() } // expression which represents the right side of a set expression
/*@NSCopying*/ open var `true`: NSExpression { NSUnimplemented() } // expression which will be evaluated if a conditional expression's predicate evaluates to true
/*@NSCopying*/ open var `false`: NSExpression { NSUnimplemented() } // expression which will be evaluated if a conditional expression's predicate evaluates to false
open var expressionBlock: (Any?, [Any], NSMutableDictionary?) -> Any { NSUnimplemented() }
// evaluate the expression using the object and bindings- note that context is mutable here and can be used by expressions to store temporary state for one predicate evaluation
open func expressionValue(with object: Any?, context: NSMutableDictionary?) -> Any? { NSUnimplemented() }
open func allowEvaluation() { NSUnimplemented() } // Force an expression which was securely decoded to allow evaluation
}
extension NSExpression {
public convenience init(format expressionFormat: String, _ args: CVarArg...) { NSUnimplemented() }
}