/[ascend]/trunk/ascend/compiler/vlist.c
ViewVC logotype

Contents of /trunk/ascend/compiler/vlist.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2781 - (show annotations) (download) (as text)
Fri Jun 20 05:12:07 2014 UTC (4 years, 2 months ago) by jpye
File MIME type: text/x-csrc
File size: 3858 byte(s)
remove RCS comments per warnings from clang 3.4
1 /*
2 * Variable name list implementation
3 * by Tom Epperly
4 * August 8, 1989
5 * Version: $Revision: 1.7 $
6 * Version control file: $RCSfile: vlist.c,v $
7 * Date last modified: $Date: 1997/07/18 12:36:36 $
8 * Last modified by: $Author: mthomas $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
13 *
14 * The Ascend Language Interpreter is free software; you can redistribute
15 * it and/or modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * The Ascend Language Interpreter is distributed in hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28 #include<stdio.h>
29 #include<assert.h>
30 #include <ascend/general/platform.h>
31
32 #include <ascend/general/ascMalloc.h>
33
34
35 #include "functype.h"
36 #include "expr_types.h"
37 #include "vlist.h"
38 #include "name.h"
39
40 #define NLMALLOC ASC_NEW(struct VariableList)
41
42 #ifndef TRUE
43 #define TRUE 1
44 #endif
45
46 struct VariableList *CreateVariableNode(struct Name *n)
47 {
48 register struct VariableList *result;
49 assert(n!=NULL);
50 result = NLMALLOC;
51 assert(result!=NULL);
52 result->nptr = n;
53 result->next = NULL;
54 return result;
55 }
56
57 void LinkVariableNodes(struct VariableList *cur, struct VariableList *next)
58 {
59 assert(cur!=NULL);
60 cur->next = next;
61 }
62
63 CONST struct VariableList *NextVariableNodeF(CONST struct VariableList *n)
64 {
65 assert(n!=NULL);
66 return n->next;
67 }
68
69 CONST struct Name *NamePointerF(CONST struct VariableList *n)
70 {
71 assert(n!=NULL);
72 return n->nptr;
73 }
74
75 struct VariableList *CopyVariableList(struct VariableList *n)
76 {
77 register struct VariableList *result,*p,*np;
78 if (n==NULL) return NULL;
79 np = n;
80 result = NLMALLOC;
81 result->nptr = CopyName(np->nptr);
82 p = result;
83 while(np->next !=NULL) {
84 p->next = NLMALLOC;
85 p = p->next;
86 np = np->next;
87 p->nptr = CopyName(np->nptr);
88 }
89 p->next = NULL;
90 return result;
91 }
92
93 unsigned long VariableListLength(CONST struct VariableList *n)
94 {
95 unsigned long len=0L;
96 while(n!=NULL) {
97 n = n->next;
98 len++;
99 }
100 return len;
101 }
102
103 void DestroyVariableList(register struct VariableList *n)
104 {
105 register struct VariableList *next;
106 while (n!=NULL) {
107 next = n->next;
108 DestroyName(n->nptr);
109 ascfree((char *)n);
110 n = next;
111 }
112 }
113
114 void DestroyVariableListNode(struct VariableList *n)
115 {
116 if (n!=NULL) {
117 DestroyName(n->nptr);
118 ascfree((char *)n);
119 }
120 }
121
122 struct VariableList *JoinVariableLists(struct VariableList *n1,
123 struct VariableList *n2)
124 {
125 register struct VariableList *p;
126 if (n1==NULL) return n2;
127 /* find end of name list n1 */
128 p = n1;
129 while (p->next) p = p->next;
130 /* link to n2 */
131 p->next = n2;
132 return n1;
133 }
134
135 struct VariableList *ReverseVariableList(register struct VariableList *n)
136 {
137 register struct VariableList *next,*previous=NULL;
138 if (n==NULL) return n;
139 while (TRUE) { /* loop until broken */
140 next = n->next;
141 n->next = previous;
142 if (next==NULL) return n;
143 previous = n;
144 n = next;
145 }
146 }
147
148 int CompareVariableLists(CONST struct VariableList *vl1,
149 CONST struct VariableList *vl2)
150 {
151 int ctmp;
152 if (vl1==vl2) { return 0; }
153 if (vl1==NULL) { return 1; }
154 if (vl2==NULL) { return -1; }
155 while(vl1!=NULL && vl2!=NULL) {
156 ctmp = CompareNames(vl1->nptr,vl2->nptr);
157 if (ctmp != 0) { return ctmp; }
158 vl1 = vl1->next;
159 vl2 = vl2->next;
160 }
161 if (vl1!=NULL) { return 1; }
162 if (vl2!=NULL) { return -1; }
163 return 0;
164 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22