00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifdef USE_PCH
00051 #include "be_com_pch.h"
00052 #endif
00053 #pragma hdrstop
00054
00055 #ifdef _KEEP_RCS_ID
00056 static const char source_file[] = __FILE__;
00057 #endif
00058
00059 #ifndef dvector_INCLUDED
00060 #include "dvector.h"
00061 #endif
00062
00063
00083 extern DEP DEP_SetDirection(DIRECTION direction)
00084 {
00085 DEP dep=0;
00086
00087 if (direction == DIR_EQ) {
00088 return(DEP_SetDistance(0));
00089 } else {
00090 dep = DEP_MAKE_DIST_NON_CONST_PRIVATE(dep);
00091 dep = DEP_SET_DIR_PRIVATE(dep,direction);
00092
00093
00094 if (direction == DIR_POS) {
00095 dep = DEP_SET_DIST_PRIVATE(dep,1);
00096 } else if (direction == DIR_NEG) {
00097 dep = DEP_SET_DIST_PRIVATE(dep,1);
00098 } else {
00099 dep = DEP_SET_DIST_PRIVATE(dep,0);
00100 }
00101 }
00102 return(dep);
00103 }
00104
00105 extern DEP DEP_UnionDirection(DEP dep,DIRECTION direction)
00106 {
00107 if (DEP_Direction(dep) == direction) {
00108 if (direction != DIR_EQ) {
00109 dep = DEP_MAKE_DIST_NON_CONST_PRIVATE(dep);
00110 if (direction == DIR_POS) {
00111 dep = DEP_SET_DIST_PRIVATE(dep,1);
00112 } else if (direction == DIR_NEG) {
00113 dep = DEP_SET_DIST_PRIVATE(dep,1);
00114 } else {
00115 dep = DEP_SET_DIST_PRIVATE(dep,0);
00116 }
00117 }
00118 return (dep);
00119 }
00120 dep = DEP_MAKE_DIST_NON_CONST_PRIVATE(dep);
00121 dep |= (((mINT16) direction) << 12);
00122 dep = DEP_SET_DIST_PRIVATE(dep,0);
00123 return (dep);
00124 }
00125
00126 extern DEP DEP_Negate(DEP dep)
00127 {
00128 DEP tmp=0;
00129
00130
00131 if (DEP_IsDistance(dep)) return DEP_SetDistance(-DEP_Distance(dep));
00132
00133 tmp = DEP_MAKE_DIST_NON_CONST_PRIVATE(tmp);
00134 if (DEP_Direction(dep) == DIR_POS) {
00135 tmp = DEP_SET_DIR_PRIVATE(tmp,DIR_NEG);
00136 tmp = DEP_SET_DIST_PRIVATE(tmp,1);
00137 } else if (DEP_Direction(dep) == DIR_NEG) {
00138 tmp = DEP_SET_DIR_PRIVATE(tmp,DIR_POS);
00139 tmp = DEP_SET_DIST_PRIVATE(tmp,1);
00140 } else if (DEP_Direction(dep) == DIR_POSEQ) {
00141 tmp = DEP_SET_DIR_PRIVATE(tmp,DIR_NEGEQ);
00142 tmp = DEP_SET_DIST_PRIVATE(tmp,0);
00143 } else if (DEP_Direction(dep) == DIR_NEGEQ) {
00144 tmp = DEP_SET_DIR_PRIVATE(tmp,DIR_POSEQ);
00145 tmp = DEP_SET_DIST_PRIVATE(tmp,0);
00146 } else tmp = dep;
00147
00148 return(tmp);
00149 }
00150
00151
00152 extern DEP DEP_SetDistance(INT32 distance)
00153 {
00154 DEP dep=0;
00155
00156 if (distance > MAX_DISTANCE_PRIVATE) {
00157 dep = DEP_MAKE_DIST_NON_CONST_PRIVATE(dep);
00158 distance = MAX_BOUND_PRIVATE;
00159 } else if (distance < MIN_DISTANCE_PRIVATE) {
00160 dep = DEP_MAKE_DIST_NON_CONST_PRIVATE(dep);
00161 distance = MAX_BOUND_PRIVATE;
00162 } else {
00163 dep = DEP_MAKE_DIST_CONST_PRIVATE(dep);
00164 }
00165
00166 if (distance > 0) {
00167 dep = DEP_SET_DIR_PRIVATE(dep,DIR_POS);
00168 } else if (distance < 0) {
00169 dep = DEP_SET_DIR_PRIVATE(dep,DIR_NEG);
00170 } else {
00171 dep = DEP_SET_DIR_PRIVATE(dep,DIR_EQ);
00172 }
00173 dep = DEP_SET_DIST_PRIVATE(dep,distance);
00174 return(dep);
00175 }
00176
00177
00178 extern void DIRECTION_Print(DIRECTION dir,FILE *fp)
00179 {
00180 switch (dir) {
00181 case DIR_POS: fprintf(fp," + "); break;
00182 case DIR_NEG: fprintf(fp," - "); break;
00183 case DIR_EQ: fprintf(fp," = "); break;
00184 case DIR_POSNEG: fprintf(fp," +- "); break;
00185 case DIR_POSEQ: fprintf(fp," += "); break;
00186 case DIR_NEGEQ: fprintf(fp," -= "); break;
00187 case DIR_STAR: fprintf(fp," * "); break;
00188 default: Is_True(0,("Illegal direction in DIRECTION_Print"));
00189 };
00190 }
00191
00192 extern void DEP_Print(const DEP dep,FILE *fp)
00193 {
00194 if (DEP_IsDistance(dep)) fprintf(fp," %d ",DEP_Distance(dep));
00195 else DIRECTION_Print(DEP_Direction(dep),fp);
00196 }
00197
00198 extern void DEP_PrintBound(const DEP dep,FILE *fp)
00199 {
00200 fprintf(fp," %d ",(INT32) DEP_DistanceBound(dep));
00201 }
00202
00203
00204 extern DEPV *DEPV_Create(MEM_POOL *mem_pool,UINT8 num_dim)
00205 {
00206 DEPV *depv;
00207
00208 depv = TYPE_MEM_POOL_ALLOC_N(DEP,mem_pool,num_dim);
00209 return(depv);
00210 }
00211
00212
00213 extern DEPV *DEPV_CreateStar(MEM_POOL *mem_pool,UINT8 num_dim)
00214 {
00215 DEPV *depv;
00216 INT i;
00217
00218 depv = TYPE_MEM_POOL_ALLOC_N(DEP,mem_pool,num_dim);
00219 for (i=0; i< num_dim; i++) {
00220 depv[i] = DEP_SetDirection(DIR_STAR);
00221 }
00222 return(depv);
00223 }
00224
00225 extern DEPV *DEPV_CreateEqual(MEM_POOL *mem_pool,UINT8 num_dim)
00226 {
00227 DEPV *depv;
00228 INT i;
00229
00230 depv = TYPE_MEM_POOL_ALLOC_N(DEP,mem_pool,num_dim);
00231 for (i=0; i< num_dim; i++) {
00232 depv[i] = DEP_SetDirection(DIR_EQ);
00233 }
00234 return(depv);
00235 }
00236
00237 extern DEPV *DEPV_Copy(MEM_POOL *mem_pool, DEPV *depv, UINT8 num_dim)
00238 {
00239 DEPV *result;
00240 INT i;
00241
00242 result = TYPE_MEM_POOL_ALLOC_N(DEP,mem_pool,num_dim);
00243 for (i=0; i<num_dim; i++) {
00244 result[i] = depv[i];
00245 }
00246 return(result);
00247 }
00248
00249
00250
00251 extern void DEPV_Print(const DEPV *depv,FILE *fp, UINT8 num_dim)
00252 {
00253 INT i;
00254
00255 fprintf(fp," ( ");
00256 for (i=0; i<num_dim; i++) {
00257 DEP_Print(DEPV_Dep(depv,i),fp);
00258 }
00259 fprintf(fp," ) ");
00260 }
00261
00262 extern void DEPV_PrintBound(const DEPV *depv,FILE *fp, UINT8 num_dim)
00263 {
00264 INT i;
00265
00266 fprintf(fp," ( ");
00267 for (i=0; i<num_dim; i++) {
00268 DEP_PrintBound(DEPV_Dep(depv,i),fp);
00269 }
00270 fprintf(fp," ) ");
00271 }
00272
00273
00274 void DEP_Lex_Pos_Decompose(DEP dep,MEM_POOL *pool, DEP **pos,
00275 DEP **neg, BOOL keep_pos_equals, BOOL keep_neg_equals)
00276 {
00277 if (DEP_Direction(dep) == DIR_POS) {
00278 *pos = TYPE_MEM_POOL_ALLOC(DEP,pool);
00279 *neg = NULL;
00280 **pos = dep;
00281 } else if (DEP_Direction(dep) == DIR_NEG) {
00282 *neg = TYPE_MEM_POOL_ALLOC(DEP,pool);
00283 *pos = NULL;
00284 **neg = DEP_Negate(dep);
00285 } else if (DEP_Direction(dep) == DIR_POSNEG) {
00286 *pos = TYPE_MEM_POOL_ALLOC(DEP,pool);
00287 *neg = TYPE_MEM_POOL_ALLOC(DEP,pool);
00288 **pos = **neg = DEP_SetDirection(DIR_POS);
00289 } else if (DEP_Direction(dep) == DIR_POSEQ) {
00290 *pos = TYPE_MEM_POOL_ALLOC(DEP,pool);
00291 *neg = NULL;
00292 if (keep_pos_equals) {
00293 **pos = dep;
00294 } else {
00295 **pos = DEP_SetDirection(DIR_POS);
00296 }
00297 if (keep_neg_equals) {
00298 *neg = TYPE_MEM_POOL_ALLOC(DEP,pool);
00299 **neg = DEP_SetDirection(DIR_EQ);
00300 }
00301 } else if (DEP_Direction(dep) == DIR_NEGEQ) {
00302 *neg = TYPE_MEM_POOL_ALLOC(DEP,pool);
00303 *pos = NULL;
00304 if (keep_neg_equals) {
00305 **neg = DEP_SetDirection(DIR_POSEQ);
00306 } else {
00307 **neg = DEP_SetDirection(DIR_POS);
00308 }
00309 if (keep_pos_equals) {
00310 *pos = TYPE_MEM_POOL_ALLOC(DEP,pool);
00311 **pos = DEP_SetDirection(DIR_EQ);
00312 }
00313 } else if (DEP_Direction(dep) == DIR_STAR) {
00314 *neg = TYPE_MEM_POOL_ALLOC(DEP,pool);
00315 *pos = TYPE_MEM_POOL_ALLOC(DEP,pool);
00316 if (keep_pos_equals) {
00317 **pos = DEP_SetDirection(DIR_POSEQ);
00318 } else {
00319 **pos = DEP_SetDirection(DIR_POS);
00320 }
00321 if (keep_neg_equals) {
00322 **neg = DEP_SetDirection(DIR_POSEQ);
00323 } else {
00324 **neg = DEP_SetDirection(DIR_POS);
00325 }
00326 } else {
00327
00328 *pos = *neg = NULL;
00329 if (keep_pos_equals) {
00330 *pos = TYPE_MEM_POOL_ALLOC(DEP,pool);
00331 **pos = DEP_SetDirection(DIR_EQ);
00332 }
00333 if (keep_neg_equals) {
00334 *neg = TYPE_MEM_POOL_ALLOC(DEP,pool);
00335 **neg = DEP_SetDirection(DIR_EQ);
00336 }
00337 }
00338 }
00339
00340
00341 DEP DEP_Lex_Pos_Compose(DEP *pos, DEP *neg, BOOL *pos_has_eq, BOOL *neg_has_eq)
00342 {
00343 Is_True(pos || neg,("Two null deps in DEP_Lex_Pos_Compose"));
00344
00345 *pos_has_eq = FALSE;
00346 *neg_has_eq = FALSE;
00347 if (pos) {
00348 if ((DEP_Direction(*pos) == DIR_POSEQ)||(DEP_Direction(*pos) == DIR_EQ)) {
00349 *pos_has_eq = TRUE;
00350 }
00351 }
00352
00353 if (neg) {
00354 if ((DEP_Direction(*neg) == DIR_POSEQ)||(DEP_Direction(*neg) == DIR_EQ)) {
00355 *neg_has_eq = TRUE;
00356 }
00357 }
00358
00359 if (!neg) return (*pos);
00360 if (!pos) return (DEP_Negate(*neg));
00361 return(DEP_UnionDirection(DEP_Negate(*neg),DEP_Direction(*pos)));
00362 }
00363
00364
00365