]>
Commit | Line | Data |
---|---|---|
878ddf1f | 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-2000\r | |
29 | */\r | |
30 | \r | |
31 | #define ANTLR_SUPPORT_CODE\r | |
32 | \r | |
33 | #include "SList.h"\r | |
34 | #include "pccts_stdarg.h" // MR23\r | |
35 | \r | |
36 | /* Iterate over a list of elements; returns ptr to a new element\r | |
37 | * in list upon every call and NULL when no more are left.\r | |
38 | * Very useful like this:\r | |
39 | *\r | |
40 | * cursor = mylist;\r | |
41 | * while ( (p=mylist->iterate(&cursor)) ) {\r | |
42 | * // place with element p\r | |
43 | * }\r | |
44 | *\r | |
45 | * The cursor must be initialized to point to the list to iterate over.\r | |
46 | */\r | |
47 | void *SList::\r | |
48 | iterate(SListNode **cursor)\r | |
49 | {\r | |
50 | void *e;\r | |
51 | \r | |
52 | if ( cursor == NULL || *cursor==NULL ) return NULL;\r | |
53 | if ( head == *cursor ) { *cursor = (*cursor)->next(); }\r | |
54 | e = (*cursor)->elem();\r | |
55 | (*cursor) = (*cursor)->next();\r | |
56 | return e;\r | |
57 | }\r | |
58 | \r | |
59 | /* add an element to end of list. */\r | |
60 | void SList::\r | |
61 | add(void *e)\r | |
62 | {\r | |
63 | SListNode *p, *tail=NULL;\r | |
64 | require(e!=NULL, "slist_add: attempting to add NULL list element");\r | |
65 | \r | |
66 | p = new SListNode;\r | |
67 | require(p!=NULL, "add: cannot alloc new list node");\r | |
68 | p->setElem(e);\r | |
69 | if ( head == NULL )\r | |
70 | {\r | |
71 | head = tail = p;\r | |
72 | }\r | |
73 | else /* find end of list */\r | |
74 | {\r | |
75 | tail->setNext(p);\r | |
76 | tail = p;\r | |
77 | }\r | |
78 | }\r | |
79 | \r | |
80 | void SList::\r | |
81 | lfree()\r | |
82 | {\r | |
83 | SListNode *p,*q;\r | |
84 | \r | |
85 | if ( head==NULL ) return; /* empty list */\r | |
86 | for (p = head; p!=NULL; p=q)\r | |
87 | {\r | |
88 | q = p->next();\r | |
89 | free(p);\r | |
90 | }\r | |
91 | }\r | |
92 | \r | |
93 | PCCTS_AST *SList::\r | |
94 | to_ast(SList list)\r | |
95 | {\r | |
96 | PCCTS_AST *t=NULL, *last=NULL;\r | |
97 | SListNode *p;\r | |
98 | \r | |
99 | for (p = head; p!=NULL; p=p->next())\r | |
100 | {\r | |
101 | PCCTS_AST *u = (PCCTS_AST *)p->elem();\r | |
102 | if ( last==NULL ) last = t = u;\r | |
103 | else { last->setRight(u); last = u; }\r | |
104 | }\r | |
105 | return t;\r | |
106 | }\r | |
107 | \r | |
108 | // MR23\r | |
109 | int SList::printMessage(FILE* pFile, const char* pFormat, ...)\r | |
110 | {\r | |
111 | va_list marker;\r | |
112 | va_start( marker, pFormat );\r | |
113 | int iRet = vfprintf(pFile, pFormat, marker);\r | |
114 | va_end( marker );\r | |
115 | return iRet;\r | |
116 | }\r |