]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/slist.cpp
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / Pccts / h / slist.cpp
CommitLineData
3eb9473e 1/*\r
2 * SList.C\r
3 *\r
4 * SOFTWARE RIGHTS\r
5 *\r
6 * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public\r
7 * domain. An individual or company may do whatever they wish with\r
8 * source code distributed with SORCERER or the code generated by\r
9 * SORCERER, including the incorporation of SORCERER, or its output, into\r
10 * commerical software.\r
11 *\r
12 * We encourage users to develop software with SORCERER. However, we do\r
13 * ask that credit is given to us for developing SORCERER. By "credit",\r
14 * we mean that if you incorporate our source code into one of your\r
15 * programs (commercial product, research project, or otherwise) that you\r
16 * acknowledge this fact somewhere in the documentation, research report,\r
17 * etc... If you like SORCERER and have developed a nice tool with the\r
18 * output, please mention that you developed it using SORCERER. In\r
19 * addition, we ask that this header remain intact in our source code.\r
20 * As long as these guidelines are kept, we expect to continue enhancing\r
21 * this system and expect to make other tools available as they are\r
22 * completed.\r
23 *\r
24 * PCCTS 1.33\r
25 * Terence Parr\r
26 * Parr Research Corporation\r
27 * with Purdue University and AHPCRC, University of Minnesota\r
28 * 1992-1998\r
29 */\r
30\r
31#define ANTLR_SUPPORT_CODE\r
32\r
33#include "SList.h"\r
34\r
35/* Iterate over a list of elements; returns ptr to a new element\r
36 * in list upon every call and NULL when no more are left.\r
37 * Very useful like this:\r
38 *\r
39 * cursor = mylist;\r
40 * while ( (p=mylist->iterate(&cursor)) ) {\r
41 * // place with element p\r
42 * }\r
43 *\r
44 * The cursor must be initialized to point to the list to iterate over.\r
45 */\r
46void *SList::\r
47iterate(SListNode **cursor)\r
48{\r
49 void *e;\r
50\r
51 if ( cursor == NULL || *cursor==NULL ) return NULL;\r
52 if ( head == *cursor ) { *cursor = (*cursor)->next(); }\r
53 e = (*cursor)->elem();\r
54 (*cursor) = (*cursor)->next();\r
55 return e;\r
56}\r
57\r
58/* add an element to end of list. */\r
59void SList::\r
60add(void *e)\r
61{\r
62 SListNode *p, *tail=NULL;\r
63 require(e!=NULL, "slist_add: attempting to add NULL list element");\r
64\r
65 p = new SListNode;\r
66 require(p!=NULL, "add: cannot alloc new list node");\r
67 p->setElem(e);\r
68 if ( head == NULL )\r
69 {\r
70 head = tail = p;\r
71 }\r
72 else /* find end of list */\r
73 {\r
74 tail->setNext(p);\r
75 tail = p;\r
76 }\r
77}\r
78\r
79void SList::\r
80lfree()\r
81{\r
82 SListNode *p,*q;\r
83\r
84 if ( head==NULL ) return; /* empty list */\r
85 for (p = head; p!=NULL; p=q)\r
86 {\r
87 q = p->next();\r
88 free(p);\r
89 }\r
90}\r
91\r
92PCCTS_AST *SList::\r
93to_ast(SList list)\r
94{\r
95 PCCTS_AST *t=NULL, *last=NULL;\r
96 SListNode *p;\r
97\r
98 for (p = head; p!=NULL; p=p->next())\r
99 {\r
100 PCCTS_AST *u = (PCCTS_AST *)p->elem();\r
101 if ( last==NULL ) last = t = u;\r
102 else { last->setRight(u); last = u; }\r
103 }\r
104 return t;\r
105}\r