/[ascend]/trunk/base/generic/compiler/when.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/when.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations) (download) (as text)
Sat Nov 13 16:45:56 2004 UTC (15 years, 3 months ago) by aw0a
File MIME type: text/x-csrc
File size: 4135 byte(s)
moving things to base/generic
1 /*
2 * WHEN List Implementation
3 * by Vicente Rico-Ramirez
4 * 7/96
5 * Version: $Revision: 1.11 $
6 * Version control file: $RCSfile: when.c,v $
7 * Date last modified: $Date: 1997/07/29 15:52:56 $
8 * Last modified by: $Author: rv2a $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1996 Vicente Rico-Ramirez
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 along
25 * with the program; if not, write to the Free Software Foundation, Inc., 675
26 * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
27 */
28 #include<stdio.h>
29 #include<assert.h>
30 #include "utilities/ascConfig.h"
31 #include "compiler/compiler.h"
32 #include "utilities/ascMalloc.h"
33 #include "compiler/fractions.h"
34 #include "compiler/dimen.h"
35 #include "compiler/functype.h"
36 #include "compiler/types.h"
37 #include "compiler/stattypes.h"
38 #include "compiler/sets.h"
39 #include "compiler/exprs.h"
40 #include "compiler/slist.h"
41 #include "compiler/vlist.h"
42 #include "compiler/when.h"
43
44 #define WMALLOC(x) x = (struct WhenList *)ascmalloc(sizeof(struct WhenList))
45
46 #ifndef lint
47 static CONST char WhenRCSid[] = "$Id: when.c,v 1.11 1997/07/29 15:52:56 rv2a Exp $";
48 #endif
49
50
51 #ifdef THIS_IS_AN_UNUSED_FUNCTION
52 static
53 int SetNodeIsTrue(struct Set *s)
54 {
55 CONST struct Expr *e;
56 assert(s && (SetType(s)==0));
57 e = GetSingleExpr(s);
58 assert(e && (ExprType(e)==e_boolean) && (NextExpr(e)==NULL));
59 return ExprBValue(e);
60 }
61 #endif /* THIS_IS_AN_UNUSED_FUNCTION */
62
63
64 struct WhenList *CreateWhen(struct Set *set, struct StatementList *sl)
65 {
66 register struct WhenList *result;
67 WMALLOC(result);
68 result->slist = sl;
69 result->values =set;
70 result->next = NULL;
71 return result;
72 }
73
74 struct WhenList *ReverseWhenCases(struct WhenList *w)
75 {
76 register struct WhenList *next,*previous=NULL;
77 if (w==NULL) return w;
78 while (1) { /* loop until broken */
79 next = w->next;
80 w->next = previous;
81 if (next==NULL) return w;
82 previous = w;
83 w = next;
84 }
85 }
86
87 struct WhenList *LinkWhenCases(struct WhenList *w1, struct WhenList *w2)
88 {
89 register struct WhenList *p;
90 p = w1;
91 while (p->next!=NULL) p = p->next;
92 p->next = w2;
93 return w1;
94 }
95
96 struct WhenList *NextWhenCaseF(struct WhenList *w)
97 {
98 assert(w!=NULL);
99 return w->next;
100 }
101
102 struct Set *WhenSetListF(struct WhenList *w)
103 {
104 assert(w!=NULL);
105 return w->values;
106 }
107
108
109 struct StatementList *WhenStatementListF(struct WhenList *w)
110 {
111 assert(w!=NULL);
112 return w->slist;
113 }
114
115 void DestroyWhenNode(struct WhenList *w)
116 {
117 register struct Set *set;
118 if (w!=NULL){
119 set = w->values;
120 if (w->values) {
121 if (set->next == NULL) {
122 DestroySetNodeByReference(w->values);
123 }
124 else {
125 DestroySetListByReference(w->values);
126 }
127 }
128 DestroyStatementList(w->slist);
129 w->next = NULL;
130 ascfree((char *)w);
131 }
132 }
133
134 void DestroyWhenList(struct WhenList *w)
135 {
136 register struct WhenList *next;
137 while (w!=NULL){
138 next = NextWhenCase(w);
139 DestroyWhenNode(w);
140 w = next;
141 }
142 }
143
144 struct WhenList *CopyWhenNode(struct WhenList *w)
145 {
146 register struct WhenList *result;
147 assert(w!=NULL);
148 WMALLOC(result);
149 if (w->values) result->values = CopySetByReference(w->values);
150 else result->values = w->values;
151 result->slist = CopyListToModify(w->slist);
152 result->next = NULL;
153 return result;
154 }
155
156 struct WhenList *CopyWhenList(struct WhenList *w)
157 {
158 register struct WhenList *head=NULL,*p;
159 if (w!=NULL) {
160 p = head = CopyWhenNode(w);
161 w = w->next;
162 while(w!=NULL){
163 p->next = CopyWhenNode(w);
164 p = p->next;
165 w = w->next;
166 }
167 }
168 return head;
169 }
170
171
172
173
174
175
176
177
178

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