1 |
johnpye |
485 |
/* ASCEND modelling environment |
2 |
|
|
Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
3 |
|
|
Copyright (C) 2006 Carnegie Mellon University |
4 |
aw0a |
1 |
|
5 |
johnpye |
485 |
This program is free software; you can redistribute it and/or modify |
6 |
|
|
it under the terms of the GNU General Public License as published by |
7 |
|
|
the Free Software Foundation; either version 2, or (at your option) |
8 |
|
|
any later version. |
9 |
aw0a |
1 |
|
10 |
johnpye |
485 |
This program is distributed in the hope that it will be useful, |
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
GNU General Public License for more details. |
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU General Public License |
16 |
|
|
along with this program; if not, write to the Free Software |
17 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
|
|
Boston, MA 02111-1307, USA. |
19 |
|
|
*//** @file |
20 |
|
|
Relation Output Routines. |
21 |
|
|
|
22 |
|
|
Requires: |
23 |
|
|
#include <stdio.h> |
24 |
|
|
#include "utilities/ascConfig.h" |
25 |
|
|
#include "instance_enum.h" |
26 |
|
|
#include "fractions.h" |
27 |
|
|
#include "compiler.h" |
28 |
|
|
#include "dimen.h" |
29 |
johnpye |
669 |
#include "expr_types.h" |
30 |
johnpye |
485 |
#include "relation_type.h" |
31 |
|
|
#include "exprs.h" |
32 |
|
|
#include "relation.h" |
33 |
|
|
*//* |
34 |
|
|
by Tom Epperly |
35 |
|
|
Created: 2/8/90 |
36 |
|
|
Version: $Revision: 1.9 $ |
37 |
|
|
Date last modified: $Date: 1998/01/27 11:00:18 $ |
38 |
|
|
Last modified by: $Author: ballan $ |
39 |
|
|
*/ |
40 |
|
|
|
41 |
johnpye |
204 |
#ifndef ASC_RELATION_IO_H |
42 |
|
|
#define ASC_RELATION_IO_H |
43 |
aw0a |
1 |
|
44 |
johnpye |
1066 |
/** addtogroup compiler Compiler |
45 |
|
|
@{ |
46 |
|
|
*/ |
47 |
|
|
|
48 |
johnpye |
485 |
#include <utilities/ascConfig.h> |
49 |
|
|
|
50 |
johnpye |
480 |
/**< |
51 |
jds |
54 |
* This enum controls the format of function names and other |
52 |
|
|
* minor operator variations in the supported languages. |
53 |
|
|
* |
54 |
|
|
* Add others here as desired and then update RelationWriteString. |
55 |
|
|
*/ |
56 |
aw0a |
1 |
enum rel_lang_format { |
57 |
|
|
relio_ascend, |
58 |
|
|
relio_C |
59 |
|
|
}; |
60 |
|
|
|
61 |
|
|
typedef char * (*WRSNameFunc)(CONST struct relation *,unsigned long,void *); |
62 |
jds |
54 |
/**< |
63 |
|
|
* For use with WriteRelationString() and token relations. |
64 |
aw0a |
1 |
* Func should return a name for varnum in tokenrel. |
65 |
|
|
* Userdata will be that which the caller of WriteRelationString provides. |
66 |
|
|
* We do not keep the name returned or free it -- it is the func's |
67 |
|
|
* responsibility to track this memory. |
68 |
|
|
*/ |
69 |
|
|
|
70 |
|
|
struct RXNameData{ |
71 |
|
|
char *prefix; |
72 |
|
|
int *indices; |
73 |
|
|
char *suffix; |
74 |
|
|
}; |
75 |
|
|
|
76 |
jds |
54 |
extern char *RelationVarXName(CONST struct relation *r, |
77 |
|
|
unsigned long varnum, |
78 |
|
|
struct RXNameData *rxndata); |
79 |
|
|
/**< |
80 |
aw0a |
1 |
* Returns names like x23. |
81 |
|
|
* Returns a character string (which we own, not the caller, but it won't |
82 |
jds |
54 |
* change until we're called again) with the name of the |
83 |
aw0a |
1 |
* the variable in "Prefix%luSuffix" format. prefix and suffix are limited |
84 |
|
|
* to 110 characters and are taken from rxndata. |
85 |
|
|
* If indices is not NULL, then the number printed will be |
86 |
jds |
54 |
* (unsigned long)indices[varnum] (remember: varnums go from 1 and |
87 |
aw0a |
1 |
* C arrays from 0!) else number printed will be varnum. |
88 |
|
|
* If prefix is NULL, "x" will be assumed and suffix will be assumed "". |
89 |
|
|
* If prefix is not NULL, suffix must not be NULL. |
90 |
jds |
54 |
* r is ignored entirely.<br><br> |
91 |
aw0a |
1 |
* |
92 |
jds |
54 |
* This function is compatible with WriteRelationString(). |
93 |
aw0a |
1 |
*/ |
94 |
|
|
|
95 |
jds |
54 |
extern int NeedParen(enum Expr_enum parent, enum Expr_enum child, int rhs); |
96 |
|
|
/**< |
97 |
aw0a |
1 |
* Given a unary or binary expression, will determine whether, the |
98 |
|
|
* child expression needs parentheses. "rhs" tells if we are looking |
99 |
|
|
* at the left or right side of a binary token. |
100 |
|
|
* E.g x ^ (2/y), would need parens exactly as shown to give the |
101 |
|
|
* correct precedence. |
102 |
|
|
* This would be called as : NeedParen(e_power,e_divide,right); |
103 |
|
|
* and would return nonzero. |
104 |
|
|
*/ |
105 |
|
|
|
106 |
jds |
54 |
extern void WriteRelation(FILE *f, |
107 |
|
|
CONST struct Instance *relinst, |
108 |
|
|
CONST struct Instance *ref); |
109 |
|
|
/**< |
110 |
aw0a |
1 |
* Write the relation in infix to the file indicated. |
111 |
|
|
* This function comfortably handles all the relation types. |
112 |
|
|
* Variables are written with names relative to ref. |
113 |
|
|
*/ |
114 |
|
|
|
115 |
johnpye |
1063 |
ASC_DLLSPEC char*WriteRelationString( |
116 |
johnpye |
480 |
CONST struct Instance *relinst, |
117 |
|
|
CONST struct Instance *ref, |
118 |
|
|
WRSNameFunc func, |
119 |
|
|
void *userdata, |
120 |
|
|
enum rel_lang_format lang, |
121 |
|
|
int *lenptr |
122 |
|
|
); |
123 |
jds |
54 |
/**< |
124 |
aw0a |
1 |
* Write the token relation in infix to a char using the |
125 |
|
|
* variable names as generated by func. |
126 |
|
|
* If func is NULL, name will be written in ascend form |
127 |
|
|
* from ref to the variable. |
128 |
jds |
54 |
* This function comfortably handles all the relation types, |
129 |
aw0a |
1 |
* but glassbox and blackbox do not use func or userdata. |
130 |
jds |
54 |
* lenptr contains the length of the string returned, or -1 |
131 |
aw0a |
1 |
* if string is NULL. If lenptr is NULL, it is ignored. |
132 |
|
|
*/ |
133 |
|
|
|
134 |
jds |
54 |
extern void WriteRelationPostfix(FILE *f, |
135 |
|
|
CONST struct Instance *relinst, |
136 |
|
|
CONST struct Instance *ref); |
137 |
|
|
/**< |
138 |
aw0a |
1 |
* Write the relation in postfix to the file indicated. |
139 |
|
|
* This function at the moment is only applicable to token relations. |
140 |
|
|
*/ |
141 |
|
|
|
142 |
johnpye |
1063 |
ASC_DLLSPEC char *WriteRelationPostfixString(CONST struct Instance *relinst, |
143 |
jds |
54 |
CONST struct Instance *ref); |
144 |
|
|
/**< |
145 |
aw0a |
1 |
* Write the relation in postfix to the file indicated. |
146 |
|
|
* This function at the moment is only applicable to token relations. |
147 |
|
|
*/ |
148 |
|
|
|
149 |
jds |
54 |
extern void Infix_WriteRelation(FILE *f, |
150 |
|
|
CONST struct Instance *r, |
151 |
|
|
CONST struct Instance *ref); |
152 |
|
|
/**< |
153 |
aw0a |
1 |
* Write the relation in infixe to the file indicated. |
154 |
|
|
* This function uses the "new" infix representation of relations. |
155 |
|
|
* This function at the moment is only applicable to token relations. |
156 |
|
|
*/ |
157 |
|
|
|
158 |
jds |
54 |
extern void WriteRelationsInTree(FILE *f, struct Instance *relinst); |
159 |
|
|
/**< |
160 |
aw0a |
1 |
* Search for relations in an instance and write them to the |
161 |
|
|
* file given in various formats. |
162 |
|
|
*/ |
163 |
|
|
|
164 |
jds |
54 |
extern void WriteRelationsInList(FILE *f, struct gl_list_t *l); |
165 |
|
|
/**< |
166 |
aw0a |
1 |
* Search for relations in an instance list and write them to the |
167 |
|
|
* file given in various formats. |
168 |
|
|
*/ |
169 |
|
|
|
170 |
|
|
extern void SaveRelationVariables(FILE *fp, CONST struct relation *r); |
171 |
jds |
54 |
/**< |
172 |
aw0a |
1 |
* Given a relation will save its variable list in the ASCEND condensed |
173 |
|
|
* format. |
174 |
|
|
*/ |
175 |
|
|
|
176 |
|
|
extern void SaveGlassBoxRelation(FILE *fp, CONST struct Instance *relinst); |
177 |
jds |
54 |
/**< |
178 |
aw0a |
1 |
* Given a glassbox relation will save it in the ASCEND condensed |
179 |
|
|
* format. |
180 |
|
|
*/ |
181 |
|
|
|
182 |
|
|
extern void SaveTokenRelation(FILE *fp, CONST struct Instance *relinst); |
183 |
jds |
54 |
/**< |
184 |
aw0a |
1 |
* Given a token relation will save it in the ASCEND condensed |
185 |
|
|
* format. |
186 |
|
|
*/ |
187 |
|
|
|
188 |
jds |
54 |
extern void SaveReln2GlassBox(FILE *fp, |
189 |
|
|
CONST struct Instance *relinst, |
190 |
|
|
char *prefix, |
191 |
|
|
unsigned long index_); |
192 |
|
|
/**< |
193 |
aw0a |
1 |
* Given a relation will save it and perform conversion to the glassbox |
194 |
|
|
* format. |
195 |
|
|
*/ |
196 |
|
|
|
197 |
johnpye |
206 |
extern int ConversionIsValid(enum Expr_enum old, enum Expr_enum new_enum); |
198 |
jds |
54 |
/**< |
199 |
|
|
* Given a relation format will return TRUE if conversion to another |
200 |
aw0a |
1 |
* format is valid. It assumes that new is a valid relation type. |
201 |
|
|
*/ |
202 |
|
|
|
203 |
|
|
extern void RelationIO_init_pool(void); |
204 |
jds |
54 |
/**< |
205 |
|
|
* starts memory recycle. Do not call twice before stopping recycle. |
206 |
aw0a |
1 |
*/ |
207 |
|
|
|
208 |
|
|
extern void RelationIO_destroy_pool(void); |
209 |
jds |
54 |
/**< |
210 |
|
|
* Stops memory recycle. Do not call while ANY Expr are outstanding. |
211 |
aw0a |
1 |
*/ |
212 |
|
|
|
213 |
|
|
extern void RelationIO_report_pool(void); |
214 |
jds |
54 |
/**< |
215 |
|
|
* Write the pool report to ASCERR for the ppe pool. |
216 |
aw0a |
1 |
*/ |
217 |
|
|
|
218 |
johnpye |
1031 |
extern void WriteNamesInList(FILE *f, struct gl_list_t *l, CONST char *sep); |
219 |
|
|
/**< |
220 |
|
|
* Write each element of l as a struct Name * on file separated by sep. |
221 |
|
|
*/ |
222 |
|
|
|
223 |
|
|
extern void WriteNamesInList2D(FILE *f, struct gl_list_t *l, CONST char *sep, CONST char *sep2); |
224 |
|
|
/**< |
225 |
|
|
* Write each element of l as a list of struct Name * on file separated by sep2. |
226 |
|
|
*/ |
227 |
|
|
|
228 |
johnpye |
1066 |
/* @} */ |
229 |
|
|
|
230 |
johnpye |
204 |
#endif /* ASC_RELATION_IO_H */ |
231 |
aw0a |
1 |
|