@@ -45,12 +45,11 @@ class struct(object):
45
45
return 'struct ( % r) ' % self . __dict__
46
46
47
47
binaryArithmetic = [
48
- struct ( operator= '+ ', name= 'add', llvmName= 'add', kind= '+ ') ,
49
- struct ( operator= '- ', name= 'subtract', llvmName= 'sub', kind= '- ') ,
50
- struct ( operator= '* ', name= 'multiply', llvmName= 'mul', kind= '* ') ,
51
- struct ( operator= '/', name='divideBy', llvmName='div', kind='/ ') ,
52
- struct (
53
- operator= '% ', name= 'remainderWhenDividedBy', llvmName= 'rem', kind= '/ ')
48
+ struct ( operator= '+ ', name= 'adding', mutatingName= 'add', firstArg= '', llvmName= 'add', kind= '+ ') ,
49
+ struct ( operator= '- ', name= 'subtracting', mutatingName= 'subtract', firstArg= '', llvmName= 'sub', kind= '- ') ,
50
+ struct ( operator= '* ', name= 'multiplied', mutatingName= 'multiply', firstArg= 'by', llvmName= 'mul', kind= '* ') ,
51
+ struct ( operator= '/', name='divided', mutatingName='divide', firstArg='by', llvmName='div', kind='/ ') ,
52
+ struct ( operator= '% ', name= 'remainder', mutatingName= 'formRemainder', firstArg= 'dividingBy', llvmName= 'rem', kind= '/ ')
54
53
]
55
54
56
55
@@ -133,18 +132,19 @@ public protocol Arithmetic {
133
132
// defaulted using an InPlace counterpart, but can be used as an
134
133
// optimization hook
135
134
@warn_unused_result
136
- func ${ x. name } ( rhs: Self) - > Self
135
+ func ${ x. name } ( $ { x . firstArg } rhs: Self) - > Self
137
136
138
137
// implementation hook
139
- mutating func ${ x. name } InPlace ( rhs: Self)
138
+ mutating func ${ x. mutatingName } ( $ { x . firstArg } rhs: Self)
140
139
% end
141
140
}
142
141
143
142
extension Arithmetic {
144
143
% for x in binaryArithmetic:
145
- public func ${ x. name} ( rhs: Self) - > Self {
144
+ % callLabel = x. firstArg + ': ' if x. firstArg else ''
145
+ public func ${ x. name} ( ${ x. firstArg} rhs: Self) - > Self {
146
146
var lhs = self
147
- lhs . ${ x. name } InPlace ( rhs)
147
+ lhs . ${ x. mutatingName } ( $ { callLabel } rhs)
148
148
return lhs
149
149
}
150
150
% end
@@ -161,15 +161,16 @@ extension SignedArithmetic {
161
161
}
162
162
163
163
% for x in binaryArithmetic:
164
+ % callLabel = x. firstArg + ': ' if x. firstArg else ''
164
165
@_transparent
165
166
@warn_unused_result
166
167
public func ${ x. operator} < T: Arithmetic> ( lhs: T, rhs: T) - > T {
167
- return lhs . ${ x. name} ( rhs)
168
+ return lhs . ${ x. name} ( $ { callLabel } rhs)
168
169
}
169
170
170
171
@_transparent
171
172
public func ${ x. operator} = < T: Arithmetic> ( lhs: inout T, rhs: T) {
172
- lhs . ${ x. name } InPlace ( rhs)
173
+ lhs . ${ x. mutatingName } ( $ { callLabel } rhs)
173
174
}
174
175
% end
175
176
@@ -366,7 +367,7 @@ comment = '''
366
367
${ comment}
367
368
@warn_unused_result
368
369
func ${ x. name} WithOverflow(
369
- rhs: Self
370
+ $ { x . firstArg } rhs: Self
370
371
) -> ( partialValue: Self, overflow: ArithmeticOverflow)
371
372
% end
372
373
@@ -491,9 +492,10 @@ extension FixedWidthInteger {
491
492
}
492
493
493
494
% for x in binaryArithmetic:
495
+ % callLabel = x. firstArg + ': ' if x. firstArg else ''
494
496
@_transparent
495
- public mutating func ${ x. name } InPlace ( rhs: Self) {
496
- let ( result, overflow) = self . ${ x. name} WithOverflow( rhs)
497
+ public mutating func ${ x. mutating Name } ( $ { x . firstArg } rhs: Self) {
498
+ let ( result, overflow) = self . ${ x. name} WithOverflow( $ { callLabel } rhs)
497
499
_assertCond( overflow == . none, " overflow in ${x.name} " )
498
500
self = result
499
501
}
@@ -506,7 +508,7 @@ extension FixedWidthInteger {
506
508
@warn_unused_result
507
509
@_transparent
508
510
public func unsafe${ capitalize ( x. name) } ( rhs: Self) - > Self {
509
- let ( result, overflow) = self . ${ x. name} WithOverflow( rhs)
511
+ let ( result, overflow) = self . ${ x. name} WithOverflow( $ { callLabel } rhs)
510
512
511
513
if ( overflow != . none) {
512
514
if ( _isDebugAssertConfiguration ( ) ) {
@@ -555,10 +557,11 @@ extension FixedWidthInteger {
555
557
}
556
558
557
559
% for x in binaryArithmetic:
560
+ % callLabel = x. firstArg + ': ' if x. firstArg else ''
558
561
% if x. kind != '/ ':
559
562
@warn_unused_result
560
563
public func & ${ x. operator} < T: FixedWidthInteger> ( lhs: T, rhs: T) - > T {
561
- return lhs . ${ x. name} WithOverflow( rhs) . partialValue
564
+ return lhs . ${ x. name} WithOverflow( $ { callLabel } rhs) . partialValue
562
565
}
563
566
% end
564
567
% end
@@ -703,13 +706,14 @@ public struct ${Self}
703
706
}
704
707
705
708
% for x in binaryArithmetic:
709
+ % callLabel = x. firstArg + ': ' if x. firstArg else ''
706
710
/// Return a pair consisting of `self` ${x.operator} `rhs`,
707
711
/// truncated to fit if necessary, and a flag indicating whether an
708
712
/// arithmetic overflow occurred.
709
713
@warn_unused_result
710
714
@_transparent
711
715
public func ${ x. name} WithOverflow(
712
- rhs: ${ Self}
716
+ $ { x . firstArg } rhs: ${ Self}
713
717
) - > ( partialValue: ${ Self} , overflow: ArithmeticOverflow) {
714
718
715
719
% if x. kind == '/ ':
0 commit comments