ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since c9b3a41 was
c9b3a41,
checked in by Peter A. Buhr <pabuhr@…>, 7 years ago
|
update CFA evaluation code
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | #include <stdlib> |
---|
2 | #include "cfa-stack.h" |
---|
3 | |
---|
4 | forall(otype T) struct stack_node { |
---|
5 | T value; |
---|
6 | stack_node(T) * next; |
---|
7 | }; |
---|
8 | forall(otype T) void ?{}( stack_node(T) & node, T value, stack_node(T) * next ) { |
---|
9 | node.value = value; |
---|
10 | node.next = next; |
---|
11 | } |
---|
12 | |
---|
13 | forall(otype T) void ?{}( stack(T) & s ) { (s.head){ 0 }; } |
---|
14 | |
---|
15 | forall(otype T) void ?{}( stack(T) & s, stack(T) t ) { |
---|
16 | stack_node(T) ** crnt = &s.head; |
---|
17 | for ( stack_node(T) * next = t.head; next; next = next->next ) { |
---|
18 | *crnt = new( next->value, 0 ); |
---|
19 | stack_node(T) * acrnt = *crnt; |
---|
20 | crnt = &acrnt->next; |
---|
21 | } |
---|
22 | *crnt = 0; |
---|
23 | } |
---|
24 | |
---|
25 | forall(otype T) stack(T) ?=?( stack(T) & s, stack(T) t ) { |
---|
26 | if ( s.head == t.head ) return s; |
---|
27 | clear( s ); |
---|
28 | s{ t }; |
---|
29 | return s; |
---|
30 | } |
---|
31 | |
---|
32 | forall(otype T) void ^?{}( stack(T) & s) { clear( s ); } |
---|
33 | |
---|
34 | forall(otype T) _Bool empty( const stack(T) & s ) { return s.head == 0; } |
---|
35 | |
---|
36 | forall(otype T) void push( stack(T) & s, T value ) { |
---|
37 | s.head = new( value, s.head ); |
---|
38 | } |
---|
39 | |
---|
40 | forall(otype T) T pop( stack(T) & s ) { |
---|
41 | stack_node(T) * n = s.head; |
---|
42 | s.head = n->next; |
---|
43 | T v = n->value; |
---|
44 | // ^n{}; |
---|
45 | free( n ); |
---|
46 | return v; |
---|
47 | } |
---|
48 | |
---|
49 | forall(otype T) void clear( stack(T) & s ) { |
---|
50 | for ( stack_node(T) * next = s.head; next; ) { |
---|
51 | stack_node(T) * crnt = next; |
---|
52 | next = crnt->next; |
---|
53 | delete( crnt ); |
---|
54 | } |
---|
55 | s.head = 0; |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.