Ignore:
Timestamp:
Mar 4, 2021, 7:40:25 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/zombies/subrange.cfa

    r342af53 r8e4aa05  
    11// A small context defining the notion of an ordered otype.  (The standard
    22// library should probably contain a context for this purpose.)
    3 trait ordered(otype T) {
     3trait ordered(T) {
    44    int ?<?(T, T), ?<=?(T, T);
    55};
     
    77// A subrange otype resembling an Ada subotype with a base otype and a range
    88// constraint.
    9 otype subrange(otype base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;
     9otype subrange(base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;
    1010
    1111// Note that subrange() can be applied to floating-point and pointer otypes, not
     
    2828
    2929// Convenient access to subrange bounds, for instance for iteration:
    30 forall (otype T, T low, T high)
     30forall (T, T low, T high)
    3131T lbound( subrange(T, low, high) v) {
    3232    return low;
    3333}
    3434
    35 forall (otype T, T low, T high)
     35forall (T, T low, T high)
    3636T hbound( subrange(T, low, high) v) {
    3737    return high;
     
    4444// of exception handling here.  Inlining allows the compiler to eliminate
    4545// bounds checks.
    46 forall (otype T | ordered(T), T low, T high)
     46forall (T | ordered(T), T low, T high)
    4747inline subrange(T, low, high) ?=?(subrange(T, low, high)* target, T source) {
    4848    if (low <= source && source <= high) *((T*)target) = source;
     
    5454// compares range bounds so that the compiler can optimize checks away when the
    5555// ranges are known to overlap.
    56 forall (otype T | ordered(T), T t_low, T t_high, T s_low, T s_high)
     56forall (T | ordered(T), T t_low, T t_high, T s_low, T s_high)
    5757inline subrange(T, t_low, t_high) ?=?(subrange(T, t_low, t_high)* target,
    5858                                      subrange(T, s_low, s_high) source) {
Note: See TracChangeset for help on using the changeset viewer.