blob: 34edea18f3e27c552e7ee94aa5a38d70b7e312db [file] [log] [blame]
Chris Lattner38c42722002-07-14 23:48:42 +00001// Test list stuff
2
3void *malloc(unsigned);
4
5// Test opaque structure support. the list type is defined later
6struct list;
7
8struct list *PassThroughList(struct list *L) {
9 return L;
10}
11
12
13// Recursive data structure tests...
14
15typedef struct list {
16 int Data;
17 struct list *Next;
18} list;
19
20list *Data;
21
22void foo() {
23 static int Foo = 0; // Test static local variable
24 Foo += 1; // Increment static variable
25
26 Data = (list*)malloc(12); // This is not a proper list allocation
27}
28
29extern list ListNode1;
30list ListNode3 = { 4, 0 };
31list ListNode2 = { 3, &ListNode3 };
32list ListNode0 = { 1, &ListNode1 };
33list ListNode1 = { 2, &ListNode2 };
34
35
36list ListArray[10];
37
38// Iterative insert fn
39void InsertIntoListTail(list **L, int Data) {
40 while (*L)
41 L = &(*L)->Next;
42 *L = (list*)malloc(sizeof(list));
43 (*L)->Data = Data;
44 (*L)->Next = 0;
45}
46
47// Recursive list search fn
48list *FindData(list *L, int Data) {
49 if (L == 0) return 0;
50 if (L->Data == Data) return L;
51 return FindData(L->Next, Data);
52}
53
54void foundIt(void);
55
56// Driver fn...
57void DoListStuff() {
58 list *MyList = 0;
59 InsertIntoListTail(&MyList, 100);
60 InsertIntoListTail(&MyList, 12);
61 InsertIntoListTail(&MyList, 42);
62 InsertIntoListTail(&MyList, 1123);
63 InsertIntoListTail(&MyList, 1213);
64
65 if (FindData(MyList, 75)) foundIt();
66 if (FindData(MyList, 42)) foundIt();
67 if (FindData(MyList, 700)) foundIt();
68}
69