]> git.proxmox.com Git - mirror_edk2.git/blobdiff - 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
diff --git a/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/slist.cpp b/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/slist.cpp
new file mode 100644 (file)
index 0000000..d6b8bf6
--- /dev/null
@@ -0,0 +1,105 @@
+/*\r
+ * SList.C\r
+ *\r
+ * SOFTWARE RIGHTS\r
+ *\r
+ * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public\r
+ * domain.  An individual or company may do whatever they wish with\r
+ * source code distributed with SORCERER or the code generated by\r
+ * SORCERER, including the incorporation of SORCERER, or its output, into\r
+ * commerical software.\r
+ *\r
+ * We encourage users to develop software with SORCERER.  However, we do\r
+ * ask that credit is given to us for developing SORCERER.  By "credit",\r
+ * we mean that if you incorporate our source code into one of your\r
+ * programs (commercial product, research project, or otherwise) that you\r
+ * acknowledge this fact somewhere in the documentation, research report,\r
+ * etc...  If you like SORCERER and have developed a nice tool with the\r
+ * output, please mention that you developed it using SORCERER.  In\r
+ * addition, we ask that this header remain intact in our source code.\r
+ * As long as these guidelines are kept, we expect to continue enhancing\r
+ * this system and expect to make other tools available as they are\r
+ * completed.\r
+ *\r
+ * PCCTS 1.33\r
+ * Terence Parr\r
+ * Parr Research Corporation\r
+ * with Purdue University and AHPCRC, University of Minnesota\r
+ * 1992-1998\r
+ */\r
+\r
+#define ANTLR_SUPPORT_CODE\r
+\r
+#include "SList.h"\r
+\r
+/* Iterate over a list of elements; returns ptr to a new element\r
+ * in list upon every call and NULL when no more are left.\r
+ * Very useful like this:\r
+ *\r
+ *             cursor = mylist;\r
+ *             while ( (p=mylist->iterate(&cursor)) ) {\r
+ *                     // place with element p\r
+ *             }\r
+ *\r
+ * The cursor must be initialized to point to the list to iterate over.\r
+ */\r
+void *SList::\r
+iterate(SListNode **cursor)\r
+{\r
+       void *e;\r
+\r
+       if ( cursor == NULL || *cursor==NULL ) return NULL;\r
+       if ( head == *cursor ) { *cursor = (*cursor)->next(); }\r
+       e = (*cursor)->elem();\r
+       (*cursor) = (*cursor)->next();\r
+       return e;\r
+}\r
+\r
+/* add an element to end of list. */\r
+void SList::\r
+add(void *e)\r
+{\r
+       SListNode *p, *tail=NULL;\r
+       require(e!=NULL, "slist_add: attempting to add NULL list element");\r
+\r
+       p = new SListNode;\r
+       require(p!=NULL, "add: cannot alloc new list node");\r
+       p->setElem(e);\r
+       if ( head == NULL )\r
+       {\r
+               head = tail = p;\r
+       }\r
+       else                                                            /* find end of list */\r
+       {\r
+               tail->setNext(p);\r
+               tail = p;\r
+       }\r
+}\r
+\r
+void SList::\r
+lfree()\r
+{\r
+       SListNode *p,*q;\r
+\r
+       if ( head==NULL ) return;       /* empty list */\r
+       for (p = head; p!=NULL; p=q)\r
+       {\r
+               q = p->next();\r
+               free(p);\r
+       }\r
+}\r
+\r
+PCCTS_AST *SList::\r
+to_ast(SList list)\r
+{\r
+       PCCTS_AST *t=NULL, *last=NULL;\r
+       SListNode *p;\r
+\r
+       for (p = head; p!=NULL; p=p->next())\r
+       {\r
+               PCCTS_AST *u = (PCCTS_AST *)p->elem();\r
+               if ( last==NULL ) last = t = u;\r
+               else { last->setRight(u); last = u; }\r
+       }\r
+       return t;\r
+}\r