ADT
arm-eh
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast-unique-expr
pthread-emulation
qualifiedEnum
Last change
on this file since 6387f07 was 9536761, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago |
formatting, change container iterator operator from ">>" to "|"
|
-
Property mode
set to
100644
|
File size:
1.8 KB
|
Line | |
---|
1 | #pragma once
|
---|
2 | #include <stdio.h> // REMOVE THIS AFTER DEBUGGING
|
---|
3 |
|
---|
4 |
|
---|
5 | struct Colable {
|
---|
6 | struct Colable * next; // next node in the list
|
---|
7 | // invariant: (next != 0) <=> listed()
|
---|
8 | };
|
---|
9 | #ifdef __cforall
|
---|
10 | static inline {
|
---|
11 | // PUBLIC
|
---|
12 |
|
---|
13 | void ?{}( Colable & co ) with( co ) {
|
---|
14 | next = 0p;
|
---|
15 | } // post: ! listed()
|
---|
16 |
|
---|
17 | // return true iff *this is an element of a collection
|
---|
18 | bool listed( Colable & co ) with( co ) { // pre: this != 0
|
---|
19 | return next != 0p;
|
---|
20 | }
|
---|
21 |
|
---|
22 | Colable & getNext( Colable & co ) with( co ) {
|
---|
23 | return *next;
|
---|
24 | }
|
---|
25 |
|
---|
26 | // PRIVATE
|
---|
27 |
|
---|
28 | Colable *& Next( Colable * cp ) {
|
---|
29 | return cp->next;
|
---|
30 | }
|
---|
31 |
|
---|
32 | // // wrappers to make Collection have T
|
---|
33 | // forall( dtype T ) {
|
---|
34 | // T *& Next( T * n ) {
|
---|
35 | // return (T *)Next( (Colable *)n );
|
---|
36 | // }
|
---|
37 | // } // distribution
|
---|
38 | } // distribution
|
---|
39 |
|
---|
40 | forall( dtype T | { T *& Next ( T * ); } ) {
|
---|
41 | bool listed( T * n ) {
|
---|
42 | return Next( n ) != 0p;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | struct Collection {
|
---|
47 | void * root; // pointer to root element of list
|
---|
48 | };
|
---|
49 |
|
---|
50 | static inline {
|
---|
51 | // class invariant: root == 0 & empty() | *root in *this
|
---|
52 | void ?{}( Collection &, const Collection & ) = void; // no copy
|
---|
53 | Collection & ?=?( const Collection & ) = void; // no assignment
|
---|
54 |
|
---|
55 | void ?{}( Collection & collection ) with( collection ) {
|
---|
56 | root = 0p;
|
---|
57 | } // post: empty()
|
---|
58 |
|
---|
59 | bool empty( Collection & collection ) with( collection ) { // 0 <=> *this contains no elements
|
---|
60 | return root == 0p;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void * head( Collection & collection ) with( collection ) {
|
---|
64 | return root;
|
---|
65 | } // post: empty() & head() == 0 | !empty() & head() in *this
|
---|
66 | } // distribution
|
---|
67 |
|
---|
68 |
|
---|
69 | struct ColIter {
|
---|
70 | void * curr; // element returned by |
|
---|
71 | };
|
---|
72 |
|
---|
73 | static inline {
|
---|
74 | void ?{}( ColIter & colIter ) with( colIter ) {
|
---|
75 | curr = 0p;
|
---|
76 | } // post: elts = null
|
---|
77 |
|
---|
78 | forall( dtype T ) {
|
---|
79 | T * Curr( ColIter & ci ) with( ci ) {
|
---|
80 | return (T *)curr;
|
---|
81 | }
|
---|
82 | } // distribution
|
---|
83 | } // distribution
|
---|
84 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.