Skip to content

Commit 9cc9930

Browse files
committed
Sequence fixes; Added CollectionOfOne
1 parent 8621edf commit 9cc9930

File tree

9 files changed

+54
-159
lines changed

9 files changed

+54
-159
lines changed

Source/Array.swift

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public struct Array<T>
167167
//
168168
//
169169

170+
@Sequence
170171
public func GetSequence() -> ISequence<T> {
171172
return list
172173
}
@@ -708,38 +709,38 @@ public struct Array<T>
708709
}
709710
}
710711

711-
#if !COCOA
712-
public extension Swift.Array : ISequence<T> {
712+
//#if !COCOA
713+
//public extension Swift.Array : ISequence<T> {
713714

714-
#if JAVA
715-
public func iterator() -> Iterator<T>! {
716-
return list.iterator()
717-
}
718-
#endif
715+
//#if JAVA
716+
//public func iterator() -> Iterator<T>! {
717+
//return list.iterator()
718+
//}
719+
//#endif
719720

720-
#if ECHOES
721-
@Implements(typeOf(System.Collections.IEnumerable), "GetEnumerator")
722-
func GetEnumeratorNG() -> System.Collections.IEnumerator! {
723-
return list.GetEnumerator()
724-
}
721+
//#if ECHOES
722+
//@Implements(typeOf(System.Collections.IEnumerable), "GetEnumerator")
723+
//func GetEnumeratorNG() -> System.Collections.IEnumerator! {
724+
//return list.GetEnumerator()
725+
//}
725726

726-
public func GetEnumerator() -> IEnumerator<T>! {
727-
return list.GetEnumerator()
728-
}
729-
#endif
727+
//public func GetEnumerator() -> IEnumerator<T>! {
728+
//return list.GetEnumerator()
729+
//}
730+
//#endif
730731

731-
#if ISLAND
732-
@Implements(typeOf(IEnumerable), "GetEnumerator")
733-
func GetEnumeratorNG() -> IEnumerator! {
734-
return list.GetEnumerator()
735-
}
732+
//#if ISLAND
733+
//@Implements(typeOf(IEnumerable), "GetEnumerator")
734+
//func GetEnumeratorNG() -> IEnumerator! {
735+
//return list.GetEnumerator()
736+
//}
736737

737-
public func GetEnumerator() -> IEnumerator<T>! {
738-
return list.GetEnumerator()
739-
}
740-
#endif
741-
}
742-
#endif
738+
//public func GetEnumerator() -> IEnumerator<T>! {
739+
//return list.GetEnumerator()
740+
//}
741+
//#endif
742+
//}
743+
//#endif
743744

744745
//public extension Swift.Array where T : ICollection {
745746
////func joined() -> ISequence<T> { // FlattenCollection<Array<Element>> {

Source/Collections.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
//74077: Allow GetSequence() to actually be used to implement ISequence
3-
public struct CollectionOfOne<Element> : ICollectionType<Bit, Int, Element> {
3+
public struct CollectionOfOne<Element> /*ICollectionType<Bit, Int, Element>,*/ {
44
///*, ISequence<Int>*/ { // 74093: Silver: should not require explicit generic on interfaces in ancestor list
55

66
public typealias Index = Bit
@@ -31,11 +31,26 @@ public struct CollectionOfOne<Element> : ICollectionType<Bit, Int, Element> {
3131
//
3232

3333
public subscript(position: Index) -> Element {
34-
_precondition(position == .Zero, "Index out of range")
34+
precondition(position == .Zero, "Index out of range")
3535
return element
3636
}
3737

38+
@Sequence
3839
public func GetSequence() -> ISequence<Element> {
3940
__yield element
4041
}
42+
43+
#if TOFFEE && !TOFFEEV2
44+
//public func countByEnumeratingWithState(_ state: UnsafePointer<NSFastEnumerationState>, objects stackbuf: UnsafePointer<Element>, count len: NSUInteger) -> NSUInteger {
45+
46+
//if state.state > 0 {
47+
//return 0;
48+
//}
49+
50+
//state.itemsPtr = unsafeBitCast(element, Int);
51+
//state.state = 1;
52+
//state.mutationsPtr = unsafeBitCast(self, Int);
53+
//return 1;
54+
//}
55+
#endif
4156
}

Source/Dictionary.swift

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/
9494
//
9595
//
9696

97+
@Sequence
9798
public func GetSequence() -> ISequence<(Key, Value)> {
9899
return DictionaryHelper.Enumerate<Key, Value>(dictionary)
99100
}
@@ -384,55 +385,6 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/
384385
}
385386
}
386387

387-
#if !COCOA
388-
public extension Swift.Dictionary : ISequence<(Key,Value)> {
389-
390-
#if JAVA
391-
public func iterator() -> Iterator<(Key,Value)>! {
392-
for entry in dictionary.entrySet() {
393-
var item: (Key, Value) = (entry.Key, entry.Value)
394-
__yield item
395-
}
396-
}
397-
#endif
398-
399-
#if ECHOES
400-
@Implements(typeOf(System.Collections.IEnumerable), "GetEnumerator")
401-
func GetEnumeratorNG() -> System.Collections.IEnumerator! {
402-
for entry in dictionary {
403-
var item: (Key, Value) = (entry.Key, entry.Value)
404-
__yield item
405-
}
406-
}
407-
408-
func GetEnumerator() -> IEnumerator<(Key,Value)>! {
409-
for entry in dictionary {
410-
var item: (Key, Value) = (entry.Key, entry.Value)
411-
__yield item
412-
}
413-
}
414-
#endif
415-
416-
#if ISLAND
417-
418-
@Implements(typeOf(IEnumerable), "GetEnumerator")
419-
func GetEnumeratorNG() -> IEnumerator! {
420-
for entry in dictionary {
421-
var item: (Key, Value) = (entry.Key, entry.Value)
422-
__yield item
423-
}
424-
}
425-
426-
func GetEnumerator() -> IEnumerator<(Key,Value)>! {
427-
for entry in dictionary {
428-
var item: (Key, Value) = (entry.Key, entry.Value)
429-
__yield item
430-
}
431-
}
432-
#endif
433-
}
434-
#endif
435-
436388
public static class DictionaryHelper {
437389
#if JAVA
438390
public static func Enumerate<Key, Value>(_ val: PlatformDictionary<Key,Value>) -> ISequence<(Key, Value)> {

Source/Range.swift

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public class Range/*<Element: ForwardIndexType, Comparable>*/: CustomStringConve
211211
}
212212
}
213213

214+
@Sequence
214215
public func GetSequence() -> ISequence<Int64> {
215216
if reversed {
216217
if let upperBound = upperBound {
@@ -286,45 +287,4 @@ public class Range/*<Element: ForwardIndexType, Comparable>*/: CustomStringConve
286287
}
287288
#endif
288289

289-
}
290-
291-
//public extension Swift.Range : ISequence<Int64> {
292-
293-
//#if JAVA
294-
//public func iterator() -> Iterator<Int64>! {
295-
//return GetSequence()
296-
//}
297-
//#elseif ECHOES
298-
//@Implements(typeOf(System.Collections.IEnumerable), "GetEnumerator")
299-
//func GetEnumeratorNG() -> System.Collections.IEnumerator! {
300-
//return GetSequence()
301-
//}
302-
303-
//public func GetEnumerator() -> IEnumerator<Int64>! {
304-
//return GetSequence()
305-
//}
306-
//#elseif ISLAND
307-
//@Implements(typeOf(IEnumerable), "GetEnumerator")
308-
//func GetEnumeratorNG() -> IEnumerator! {
309-
//return GetSequence()
310-
//}
311-
312-
//public func GetEnumerator() -> IEnumerator<Int64>! {
313-
//return GetSequence()
314-
//}
315-
//#elseif TOFFEE
316-
//public func countByEnumeratingWithState(_ aState: UnsafePointer<NSFastEnumerationState>, objects stackbuf: UnsafePointer<T!>, count len: NSUInteger) -> NSUInteger
317-
//{
318-
//return GetSequence()
319-
//}
320-
//#endif
321-
//}
322-
//74138: Silver: constrained type extensions
323-
/*extension Range where Element == Int32 {
324-
#if COCOA
325-
public init(_ nativeRange: NSRange) {
326-
startIndex = nativeRange.location
327-
endIndex = nativeRange.location+nativeRange.length
328-
}
329-
#endif
330-
}*/
290+
}

Source/Sequence_Protocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public protocol Indexable {
1818

1919
public typealias ICollectionType = CollectionType
2020
public protocol CollectionType : Indexable {
21-
associatedtype SubSequence: Indexable, SequenceType<Index> = ISequence<Index>
21+
associatedtype SubSequence: Indexable, SequenceType<Element> = ISequence<Element>
2222
subscript(bounds: Range/*<Index>*/) -> SubSequence { get }
2323

2424
func `prefix`(upTo: Index) -> SubSequence

Source/Set.swift

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public struct Set<T> //:
100100
//
101101
//
102102

103+
@Sequence
103104
public func GetSequence() -> ISequence<T> {
104105
return _set
105106
}
@@ -483,37 +484,4 @@ public struct Set<T> //:
483484
return _set.description
484485
#endif
485486
}
486-
}
487-
488-
#if !COCOA
489-
public extension Swift.Set : ISequence<T> {
490-
491-
#if JAVA
492-
public func iterator() -> Iterator<T>! {
493-
return _set.iterator()
494-
}
495-
#endif
496-
497-
#if ECHOES
498-
@Implements(typeOf(System.Collections.IEnumerable), "GetEnumerator")
499-
func GetEnumeratorNG() -> System.Collections.IEnumerator! {
500-
return _set.GetEnumerator()
501-
}
502-
503-
public func GetEnumerator() -> IEnumerator<T>! {
504-
return _set.GetEnumerator()
505-
}
506-
#endif
507-
508-
#if ISLAND
509-
@Implements(typeOf(IEnumerable), "GetEnumerator")
510-
func GetEnumeratorNG() -> IEnumerator! {
511-
return _set.GetEnumerator()
512-
}
513-
514-
public func GetEnumerator() -> IEnumerator<T>! {
515-
return _set.GetEnumerator()
516-
}
517-
#endif
518-
}
519-
#endif
487+
}

Source/String.Views.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public extension SwiftString {
244244
return stringData[index*4] + stringData[index*4+1]<<8 + stringData[index*4+2]<<16 + stringData[index*4+3]<<24 // todo: check if order is correct
245245
}
246246

247+
@Sequence
247248
public func GetSequence() -> ISequence<UTF32Char> {
248249
for i in startIndex ..< endIndex {
249250
__yield self[i]

Source/Swift.Shared.elements

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build">
33
<PropertyGroup Label="Globals">
44
<ProjectGuid>7952073B-795C-4074-954D-212FE780D7D3</ProjectGuid>
5-
</PropertyGroup>
6-
<PropertyGroup>
75
<RootNamespace>Swift.Shared</RootNamespace>
86
</PropertyGroup>
97
<Import Project="Swift.Shared.projitems" Label="Shared" />

Source/Swift.Shared.projitems

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
<Compile Include="$(MSBuildThisFileDirectory)Integer_Extensions.swift">
4949
<VirtualFolder>Numbers and such</VirtualFolder>
5050
</Compile>
51-
<None Include="$(MSBuildThisFileDirectory)Collections.swift">
51+
<Compile Include="$(MSBuildThisFileDirectory)Collections.swift">
5252
<VirtualFolder>Collection Types</VirtualFolder>
53-
</None>
53+
</Compile>
5454
<Compile Include="$(MSBuildThisFileDirectory)Bit.swift">
5555
<VirtualFolder>Numbers and such</VirtualFolder>
5656
</Compile>

0 commit comments

Comments
 (0)