Ignore:
Timestamp:
Jun 14, 2016, 1:23:18 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
545ef59, c738ca4, ee51534
Parents:
6cbc25a (diff), c8c03683 (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

Conflicts:

Makefile.in
aclocal.m4
configure
src/Makefile.in
src/Tests/Context.c
src/driver/Makefile.in
src/examples/Makefile.in
src/examples/ctxts.c
src/examples/esskaykay.c
src/libcfa/Makefile.in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/Subrange.c

    r6cbc25a r7ff30d07  
    1 // A small context defining the notion of an ordered type.  (The standard
     1// A small context defining the notion of an ordered otype.  (The standard
    22// library should probably contain a context for this purpose.)
    3 context ordered(type T) {
     3context ordered(otype T) {
    44    int ?<?(T, T), ?<=?(T, T);
    55};
    66
    7 // A subrange type resembling an Ada subtype with a base type and a range
     7// A subrange otype resembling an Ada subotype with a base otype and a range
    88// constraint.
    9 type subrange(type base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;
     9otype subrange(otype base_t | ordered(base_t), base_t low = 0, base_t high = 8) = base_t;
    1010
    11 // Note that subrange() can be applied to floating-point and pointer types, not
    12 // just integral types.
    13 //   This requires a "type generator" extension to Cforall.  Type generators
    14 // must accept type and non-type parameters, which is beyond what we discussed
     11// Note that subrange() can be applied to floating-point and pointer otypes, not
     12// just integral otypes.
     13//   This requires a "otype generator" extension to Cforall.  Type generators
     14// must accept otype and non-otype parameters, which is beyond what we discussed
    1515// previously.  Type parameters must be usable in the declaration of
    1616// subsequent parameters: parameter T is used to declare parameters "low"
     
    2222subrange(int, 0, (rand() & 0xF) ) foo;
    2323
    24 // What sorts of expressions can be used as arguments of type generators?  Is
     24// What sorts of expressions can be used as arguments of otype generators?  Is
    2525// "subrange(int, 0, rand() & 0xF)" legal?  Probably.  The nearest C equivalent
    2626// to the "low" and "high" arguments is the array size in a variable-length
     
    2828
    2929// Convenient access to subrange bounds, for instance for iteration:
    30 forall (type T, T low, T high)
     30forall (otype T, T low, T high)
    3131T lbound( subrange(T, low, high) v) {
    3232    return low;
    3333}
    3434
    35 forall (type T, T low, T high)
     35forall (otype T, T low, T high)
    3636T hbound( subrange(T, low, high) v) {
    3737    return high;
     
    4141unsigned lday = lbound(day_of_month);
    4242
    43 // Assignment from the base type, with bounds checking.  I'll ignore the issue
     43// Assignment from the base otype, with bounds checking.  I'll ignore the issue
    4444// of exception handling here.  Inlining allows the compiler to eliminate
    4545// bounds checks.
    46 forall (type T | ordered(T), T low, T high)
     46forall (otype 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;
     
    5151}
    5252
    53 // Assignment between subranges with a common base type.  The bounds check
     53// Assignment between subranges with a common base otype.  The bounds check
    5454// compares range bounds so that the compiler can optimize checks away when the
    5555// ranges are known to overlap.
    56 forall (type T | ordered(T), T t_low, T t_high, T s_low, T s_high)
     56forall (otype 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.