Changeset 8e4aa05 for tests/zombies/subrange.cfa
- Timestamp:
- Mar 4, 2021, 7:40:25 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 77d601f
- Parents:
- 342af53 (diff), a5040fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/zombies/subrange.cfa
r342af53 r8e4aa05 1 1 // A small context defining the notion of an ordered otype. (The standard 2 2 // library should probably contain a context for this purpose.) 3 trait ordered( otypeT) {3 trait ordered(T) { 4 4 int ?<?(T, T), ?<=?(T, T); 5 5 }; … … 7 7 // A subrange otype resembling an Ada subotype with a base otype and a range 8 8 // constraint. 9 otype subrange( otypebase_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;9 otype subrange(base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t; 10 10 11 11 // Note that subrange() can be applied to floating-point and pointer otypes, not … … 28 28 29 29 // Convenient access to subrange bounds, for instance for iteration: 30 forall ( otypeT, T low, T high)30 forall (T, T low, T high) 31 31 T lbound( subrange(T, low, high) v) { 32 32 return low; 33 33 } 34 34 35 forall ( otypeT, T low, T high)35 forall (T, T low, T high) 36 36 T hbound( subrange(T, low, high) v) { 37 37 return high; … … 44 44 // of exception handling here. Inlining allows the compiler to eliminate 45 45 // bounds checks. 46 forall ( otypeT | ordered(T), T low, T high)46 forall (T | ordered(T), T low, T high) 47 47 inline subrange(T, low, high) ?=?(subrange(T, low, high)* target, T source) { 48 48 if (low <= source && source <= high) *((T*)target) = source; … … 54 54 // compares range bounds so that the compiler can optimize checks away when the 55 55 // ranges are known to overlap. 56 forall ( otypeT | ordered(T), T t_low, T t_high, T s_low, T s_high)56 forall (T | ordered(T), T t_low, T t_high, T s_low, T s_high) 57 57 inline subrange(T, t_low, t_high) ?=?(subrange(T, t_low, t_high)* target, 58 58 subrange(T, s_low, s_high) source) {
Note:
See TracChangeset
for help on using the changeset viewer.