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