/[ascend]/trunk/ascend/compiler/expr_types.h
ViewVC logotype

Contents of /trunk/ascend/compiler/expr_types.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2018 - (show annotations) (download) (as text)
Wed Apr 29 03:38:10 2009 UTC (11 years, 2 months ago) by jpye
File MIME type: text/x-chdr
File size: 7994 byte(s)
Fixed compile for new header file locations <ascend/compiler/xxx.h> etc.
1 /* ASCEND modelling environment
2 Copyright (C) 2006, 2007 Carnegie Mellon University
3 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
4
5 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
10 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 *//*
20 @file
21 Name, set and expr type definitions
22
23 @todo Complete documentation of types.h.
24
25 Renamed from 'types.h' -- JP, 21 Jun 2006.
26 *//*
27 by Tom Epperly
28 July 31, 1989
29 Last in CVS $Revision: 1.17 $ $Date: 1998/03/25 00:32:31 $ $Author: ballan $
30 */
31
32 #ifndef ASC_TYPES_H
33 #define ASC_TYPES_H
34
35 /** @addtogroup compiler Compiler
36 @{
37 */
38
39 #include <limits.h>
40 #include "compiler.h"
41 #include "dimen.h"
42 #include <ascend/general/list.h>
43 #include "functype.h"
44
45 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
46 * Please see usage notes at top of Expr_enum before modifying it.
47 * In particular, if you mess with it, make sure the defines still work.
48 */
49 #define NUM_EXPR_ENUMS 44
50 /**
51 * Expression token types. Note that several have
52 * multiple uses. Where more than 1 use is listed, only the first
53 * can be encountered in real valued equations.
54 * If you must add a type, do so after e_ipower.
55 * If you explicitly use the values of the enum instead of the
56 * symbolic name, put the string TOKEN_ENUM in a comment at
57 * the top of the function so that dependent code is easy to find
58 * in the event of drastic changes. If appropriate, also put in header.
59 * If you assign explicit values, do so without leaving a gap anywhere
60 * as the statistics code in check.c depends on values being 0-NUM_EXPR_ENUMS-1
61 */
62 enum Expr_enum {
63 /* shouldn't be seen, but just in case */
64 e_nop = 0, /**< null instruction */
65
66 /**< relation implementation kinds */
67 e_undefined = 1, /**< relation type undefined */
68 e_glassbox = 2, /**< glassbox relation type */
69 e_blackbox = 3, /**< blackbox relation type */
70 e_opcode = 4, /**< unimplemented opcode relation type. not seen */
71 e_token = 5, /**< token array infix/postfix relation type */
72
73 e_zero = 6, /**< symbolic processing <==> quiet wild real 0.0 */
74 e_real = 7, /**< real constant invariant across for loops */
75 e_int = 8, /**< integer constant invariant across for loops */
76 /* two types only to be seen in fully compiled token relations, and not
77 yet seen at all. These are the types for RelationRealConst terms and
78 RelationIntegerConst terms.
79 e_realconst = 7a,
80 e_intconst = 8a,
81 */
82 e_var = 9, /**< real variable */
83
84 e_uminus = 10, /**< unary minus */
85 e_func = 11, /**< unary real function */
86
87 e_plus = 12, /**< addition, set union */
88 e_minus = 13, /**< subtraction, set difference */
89 e_times = 14, /**< multiplication, set intersection */
90 e_divide = 15, /**< division */
91 e_power = 16, /**< a^x */
92 e_ipower = 17, /**< a^n */
93 /* Don't mess with the ordering of the above items */
94
95 /* Boolean Relations */
96 e_bol_token,
97
98 /* relational operators, at present somewhat overloaded. may be in any kind*/
99 e_notequal, /**< <> strict real inequality */
100 e_equal, /**< =, rather overloaded */
101 e_less, /**< < strict real inequality */
102 e_greater, /**< > strict real inequality */
103 e_lesseq, /**< <=, =< tolerant real inequality */
104 e_greatereq, /**< >=, => tolerant real inequality */
105 e_maximize, /**< MAXIMIZE by convention implies a unary minus, we minimize */
106 e_minimize, /**< MINIMIZE objective function. max and min both become lhs */
107 e_boolean_eq, /**< boolean equality */
108 e_boolean_neq, /**< boolean inequality */
109
110 /* ALL following are never encountered in compiled real relations */
111 e_boolean, /**< boolean constant */
112 /*e_var_bool, unimplemented boolean variable */
113 e_or, /**< OR */
114 e_and, /**< AND, ",", + */
115 e_not, /**< NOT */
116 e_satisfied, /**< Operator for boolean relations */
117
118 /* ALL following are never encountered in compiled bool relations */
119 e_subexpr, /**< intermediate symbolic processing */
120 e_const, /**< intermediate symbolic processing */
121 e_par, /**< intermediate symbolic processing */
122 e_sum, /**< unexpanded summation */
123 e_prod, /**< unexpanded product */
124
125 e_symbol, /**< symbol constant, symbol variable. needs to be fixed*/
126 /*e_var_sym unimplemented symbol variable */
127 e_set, /**< [set definition] */
128 e_in, /**< IN */
129 e_st, /**< | (such that) */
130 e_card, /**< CARD (set cardinality) */
131 e_choice, /**< CHOICE (set pick one arbitrary but consistent) */
132 e_union, /**< UNION (set union aka ",") */
133 e_inter, /**< INTERSECTION (set intersection, aka "*") */
134
135 /* miscellany */
136 e_qstring /**< a quoted string */
137 };
138
139 #define TOK_SCALAR_LOW e_zero
140 #define TOK_SCALAR_HIGH e_var
141 #define TOK_CONSTANT_LOW e_zero
142 #define TOK_CONSTANT_HIGH e_int
143 #define TOK_XARY_LOW e_uminus
144 #define TOK_XARY_HIGH e_ipower
145 #define TOK_BINARY_LOW e_plus
146 #define TOK_BINARY_HIGH e_ipower
147 #define TOK_UNARY_LOW e_uminus
148 #define TOK_UNARY_HIGH e_func
149 #define TOK_REAL_REL_LOW e_zero
150 #define TOK_REAL_REL_HIGH e_ipower
151 #define TOK_REL_TYPE_LOW e_glassbox
152 #define TOK_REL_TYPE_HIGH e_token
153
154 struct ExprReal {
155 double rvalue;
156 CONST dim_type *dimensions;
157 };
158
159 struct SatisfiedExpr {
160 struct ExprReal ser;
161 struct Name *sen;
162 };
163
164 union ExprUnion {
165 struct Name *nptr;
166 long ivalue;
167 symchar *sym_ptr; /**< symbol pointer */
168 struct Set *s;
169 struct ExprReal r;
170 CONST struct Func *fptr;
171 unsigned bvalue; /**< boolean value true or false */
172 struct SatisfiedExpr se;
173 };
174
175 struct Expr {
176 struct Expr *next;
177 enum Expr_enum t;
178 union ExprUnion v;
179 };
180
181 struct Range {
182 struct Expr *lower,*upper;
183 };
184
185 union SetUnion {
186 struct Expr *e; /**< single value */
187 struct Range r; /**< range of values lower..upper */
188 };
189
190 struct Set {
191 struct Set *next;
192 unsigned range; /**< 0 single expression, 1 range */
193 union SetUnion val;
194 unsigned long ref_count;
195 };
196
197 union NameUnion {
198 symchar *id; /**< symbol table member */
199 struct Set *s;
200 int attribute; /**< supported attribute name index */
201 };
202
203 struct Name {
204 /* this element info */
205 unsigned int bits;
206 /**<
207 * if NAMEBIT_IDTY 1,
208 * this name is an identifier (id) name. if 0, it's a set.
209 * if NAMEBIT_ATTR 1,
210 * this name is a supported attribute id that should be
211 * printed with a $ in front of it.
212 * if NAMEBIT_CHAT 1,
213 * chain this is part of contains a supported attribute
214 * element. This is determinable at parse time and it costs no
215 * more to store that fact here for all elements in the chain.
216 * This makes it possible to test conditionals much earlier,
217 * perhaps at parse stage.
218 * if NAMEBIT_AUTO 1,
219 * this name element is system generated.
220 */
221 #define NAMEBIT_IDTY 0x1
222 #define NAMEBIT_ATTR 0x2
223 #define NAMEBIT_CHAT 0x4
224 #define NAMEBIT_AUTO 0x8
225 struct Name *next;
226 union NameUnion val;
227 };
228
229 /**
230 * MAXINTREAL
231 * This is the largest e_real number we will convert to an e_int
232 * in certain relation simplifications.
233 * Note that there is an upper limit beyond which double precision
234 * floating point numbers cannot map uniquely to ints and back again.
235 * On DEC alphas (ieee 64 bit), this was found to be near 130000.
236 * The IEEE gurus will tell you OTHERWISE, of course.
237 */
238 #define MAXINTREAL 100000
239
240 /* @} */
241
242 #endif /* ASC_TYPES_H */
243

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