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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 708 - (show annotations) (download) (as text)
Tue Jun 27 07:34:31 2006 UTC (17 years, 11 months ago) by johnpye
File MIME type: text/x-csrc
File size: 6362 byte(s)
Replaced some references to ascmalloc with ASC_NEW_ARRAY
1 /*
2 * When Output Routines
3 * by Vicente Rico-Ramirez
4 * Version: $Revision: 1.10 $
5 * Version control file: $RCSfile: when_io.c,v $
6 * Date last modified: $Date: 1997/07/29 15:52:57 $
7 * Last modified by: $Author: rv2a $
8 *
9 * This file is part of the Ascend Language Interpreter.
10 *
11 * Copyright (C) 1997 Carnegie Mellon University
12 *
13 * The Ascend Language Interpreter is free software; you can redistribute
14 * it and/or modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of the
16 * License, or (at your option) any later version.
17 *
18 * The Ascend Language Interpreter is distributed in hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with the program; if not, write to the Free Software Foundation,
25 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
26 * COPYING.
27 *
28 */
29 #include <utilities/ascConfig.h>
30 #include <utilities/ascMalloc.h>
31 #include <general/list.h>
32 #include <general/dstring.h>
33 #include "compiler.h"
34 #include "symtab.h"
35 #include "fractions.h"
36 #include "dimen.h"
37 #include "functype.h"
38 #include "expr_types.h"
39 #include "instance_enum.h"
40 #include "instance_types.h"
41 #include "mathinst.h"
42 #include "case.h"
43 #include "when_util.h"
44 #include "instance_io.h"
45 #include "setio.h"
46 #include "exprio.h"
47 #include "when_io.h"
48
49
50 static
51 void WriteCase(FILE *f, struct Case *cur_case, CONST struct Instance *ref)
52 {
53 struct Set *values;
54 struct gl_list_t *reflist;
55 struct Instance *inst;
56 unsigned long len,c;
57
58 values = GetCaseValues(cur_case);
59 FPRINTF(f," ");
60 if (values!=NULL){
61 FPRINTF(f,"CASE ");
62 WriteSet(f,values);
63 }
64 else FPRINTF(f,"OTHERWISE");
65 FPRINTF(f," :\n");
66
67 reflist = GetCaseReferences(cur_case);
68 len = gl_length(reflist);
69 for (c=1;c<=len;c++) {
70 inst = (struct Instance *)gl_fetch(reflist,c);
71 FPRINTF(f," ");
72 WriteInstanceName(f,inst,ref);
73 FPRINTF(f,"; \n");
74 }
75 }
76
77
78 void WriteWhen(FILE *f, CONST struct Instance *wheninst,
79 CONST struct Instance *ref)
80 {
81 struct gl_list_t *whens;
82 struct gl_list_t *vars;
83 struct gl_list_t *cases;
84 struct Case *cur_case;
85 struct Instance *inst;
86 unsigned long len,c;
87
88 whens = GetInstanceWhens(wheninst);
89 vars = GetInstanceWhenVars(wheninst);
90 cases = GetInstanceWhenCases(wheninst);
91
92 FPRINTF(f,"NAME :");
93 WriteInstanceName(f,wheninst,ref);
94 FPRINTF(f,"\n");
95 FPRINTF(f,"\n");
96 FPRINTF(f,"WHEN ");
97 if (vars!=NULL) {
98 len = gl_length(vars);
99 for (c=1;c<=len;c++) {
100 inst = (struct Instance *)gl_fetch(vars,c);
101 WriteInstanceName(f,inst,ref);
102 if (c<len) {
103 FPRINTF(f,", ");
104 }
105 if (c==len) {
106 FPRINTF(f," \n");
107 }
108 }
109 }
110 if (cases!=NULL) {
111 len = gl_length(cases);
112 for (c=1;c<=len;c++) {
113 cur_case = (struct Case *)gl_fetch(cases,c);
114 WriteCase(f,cur_case,ref);
115 }
116 FPRINTF(f,"END ");
117 FPRINTF(f,"\n");
118 }
119 FPRINTF(f,"\n");
120 if (whens!=NULL) {
121 len = gl_length(whens);
122 FPRINTF(f,"USED IN CASES OF: ");
123 FPRINTF(f," \n");
124 for (c=1;c<=len;c++) {
125 inst = (struct Instance *)gl_fetch(whens,c);
126 FPRINTF(f," ");
127 WriteInstanceName(f,inst,ref);
128 FPRINTF(f," \n");
129 }
130 }
131 }
132
133
134 static
135 void WriteCaseDS(Asc_DString *dsPtr, struct Case *cur_case,
136 CONST struct Instance *ref)
137 {
138 struct Set *values;
139 struct gl_list_t *reflist;
140 struct Instance *inst;
141 unsigned long len,c;
142
143 values = GetCaseValues(cur_case);
144 Asc_DStringAppend(dsPtr," ",2);
145 if (values!=NULL){
146 Asc_DStringAppend(dsPtr,"CASE ",5);
147 WriteSet2Str(dsPtr,values);
148 }
149 else Asc_DStringAppend(dsPtr,"OTHERWISE",9);
150 Asc_DStringAppend(dsPtr," : ",2);
151 Asc_DStringAppend(dsPtr,"\n",-1);
152
153 reflist = GetCaseReferences(cur_case);
154 len = gl_length(reflist);
155 for (c=1;c<=len;c++) {
156 inst = (struct Instance *)gl_fetch(reflist,c);
157 Asc_DStringAppend(dsPtr," ",6);
158 WriteInstanceNameDS(dsPtr,inst,ref);
159 Asc_DStringAppend(dsPtr,";",1);
160 Asc_DStringAppend(dsPtr,"\n",-1);
161 }
162 }
163
164 static
165 void WriteWhenDS(Asc_DString *dsPtr, CONST struct Instance *wheninst,
166 CONST struct Instance *ref)
167 {
168 struct gl_list_t *whens;
169 struct gl_list_t *vars;
170 struct gl_list_t *cases;
171 struct Case *cur_case;
172 struct Instance *inst;
173 unsigned long len,c;
174
175 whens = GetInstanceWhens(wheninst);
176 vars = GetInstanceWhenVars(wheninst);
177 cases = GetInstanceWhenCases(wheninst);
178
179 Asc_DStringAppend(dsPtr,"NAME :",6);
180 WriteInstanceNameDS(dsPtr,wheninst,ref);
181 Asc_DStringAppend(dsPtr,"\n",-1);
182 Asc_DStringAppend(dsPtr,"\n",-1);
183
184 Asc_DStringAppend(dsPtr,"WHEN ",5);
185 if (vars!=NULL) {
186 len = gl_length(vars);
187 for (c=1;c<=len;c++) {
188 inst = (struct Instance *)gl_fetch(vars,c);
189 WriteInstanceNameDS(dsPtr,inst,ref);
190 if (c<len) {
191 Asc_DStringAppend(dsPtr,", ",3);
192 }
193 if (c==len) {
194 Asc_DStringAppend(dsPtr," ",1);
195 Asc_DStringAppend(dsPtr,"\n",-1);
196 }
197 }
198 }
199 if (cases!=NULL) {
200 len = gl_length(cases);
201 for (c=1;c<=len;c++) {
202 cur_case = (struct Case *)gl_fetch(cases,c);
203 WriteCaseDS(dsPtr,cur_case,ref);
204 }
205 Asc_DStringAppend(dsPtr,"END ",4);
206 Asc_DStringAppend(dsPtr,"\n",-1);
207 }
208 Asc_DStringAppend(dsPtr,"\n",-1);
209 if (whens!=NULL) {
210 len = gl_length(whens);
211 Asc_DStringAppend(dsPtr,"USED IN CASES OF: ",18);
212 Asc_DStringAppend(dsPtr,"\n",-1);
213 for (c=1;c<=len;c++) {
214 inst = (struct Instance *)gl_fetch(whens,c);
215 Asc_DStringAppend(dsPtr," ",6);
216 WriteInstanceNameDS(dsPtr,inst,ref);
217 Asc_DStringAppend(dsPtr," ",1);
218 Asc_DStringAppend(dsPtr,"\n",-1);
219 }
220 }
221 }
222
223
224 char *WriteWhenString(CONST struct Instance *wheninst,
225 CONST struct Instance *ref)
226 {
227 static Asc_DString ds;
228 Asc_DString *dsPtr;
229 char *result;
230
231 result = ASC_NEW_ARRAY(char,15);
232 if (result == NULL) {
233 FPRINTF(stderr,"Memory error in WriteWhenString\n");
234 return result;
235 }
236
237 dsPtr = &ds;
238 Asc_DStringInit(dsPtr);
239 WriteWhenDS(dsPtr,wheninst,ref);
240 result = Asc_DStringResult(dsPtr);
241 Asc_DStringFree(dsPtr);
242 return result;
243
244 }
245
246
247
248
249
250

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