00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define _CSTRNUTL_SOURCE_
00025
00026 #include <stdio.h>
00027 #define _STDIO_INCLUDED_
00028 #include <stdlib.h>
00029
00030 #include "setup.h"
00031
00032 #include "constant.h"
00033 #include "envrnmnt.h"
00034 #include "memalloc.h"
00035 #include "router.h"
00036 #include "extnfunc.h"
00037 #include "scanner.h"
00038 #include "multifld.h"
00039 #include "argacces.h"
00040
00041 #include "cstrnutl.h"
00042
00043
00044
00045
00046
00047 globle struct constraintRecord *GetConstraintRecord(
00048 void *theEnv)
00049 {
00050 CONSTRAINT_RECORD *constraints;
00051 unsigned i;
00052
00053 constraints = get_struct(theEnv,constraintRecord);
00054
00055 for (i = 0 ; i < sizeof(CONSTRAINT_RECORD) ; i++)
00056 { ((char *) constraints)[i] = '\0'; }
00057
00058 SetAnyAllowedFlags(constraints,TRUE);
00059
00060 constraints->multifieldsAllowed = FALSE;
00061 constraints->singlefieldsAllowed = TRUE;
00062
00063 constraints->anyRestriction = FALSE;
00064 constraints->symbolRestriction = FALSE;
00065 constraints->stringRestriction = FALSE;
00066 constraints->floatRestriction = FALSE;
00067 constraints->integerRestriction = FALSE;
00068 constraints->classRestriction = FALSE;
00069 constraints->instanceNameRestriction = FALSE;
00070 constraints->classList = NULL;
00071 constraints->restrictionList = NULL;
00072 constraints->minValue = GenConstant(theEnv,SYMBOL,SymbolData(theEnv)->NegativeInfinity);
00073 constraints->maxValue = GenConstant(theEnv,SYMBOL,SymbolData(theEnv)->PositiveInfinity);
00074 constraints->minFields = GenConstant(theEnv,INTEGER,SymbolData(theEnv)->Zero);
00075 constraints->maxFields = GenConstant(theEnv,SYMBOL,SymbolData(theEnv)->PositiveInfinity);
00076 constraints->bucket = -1;
00077 constraints->count = 0;
00078 constraints->multifield = NULL;
00079 constraints->next = NULL;
00080
00081 return(constraints);
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091 globle void SetAnyAllowedFlags(
00092 CONSTRAINT_RECORD *theConstraint,
00093 int justOne)
00094 {
00095 int flag1, flag2;
00096
00097 if (justOne)
00098 {
00099 flag1 = TRUE;
00100 flag2 = FALSE;
00101 }
00102 else
00103 {
00104 flag1 = FALSE;
00105 flag2 = TRUE;
00106 }
00107
00108 theConstraint->anyAllowed = flag1;
00109 theConstraint->symbolsAllowed = flag2;
00110 theConstraint->stringsAllowed = flag2;
00111 theConstraint->floatsAllowed = flag2;
00112 theConstraint->integersAllowed = flag2;
00113 theConstraint->instanceNamesAllowed = flag2;
00114 theConstraint->instanceAddressesAllowed = flag2;
00115 theConstraint->externalAddressesAllowed = flag2;
00116 theConstraint->voidAllowed = flag2;
00117 theConstraint->factAddressesAllowed = flag2;
00118 }
00119
00120
00121
00122
00123 globle struct constraintRecord *CopyConstraintRecord(
00124 void *theEnv,
00125 CONSTRAINT_RECORD *sourceConstraint)
00126 {
00127 CONSTRAINT_RECORD *theConstraint;
00128
00129 if (sourceConstraint == NULL) return(NULL);
00130
00131 theConstraint = get_struct(theEnv,constraintRecord);
00132
00133 theConstraint->anyAllowed = sourceConstraint->anyAllowed;
00134 theConstraint->symbolsAllowed = sourceConstraint->symbolsAllowed;
00135 theConstraint->stringsAllowed = sourceConstraint->stringsAllowed;
00136 theConstraint->floatsAllowed = sourceConstraint->floatsAllowed;
00137 theConstraint->integersAllowed = sourceConstraint->integersAllowed;
00138 theConstraint->instanceNamesAllowed = sourceConstraint->instanceNamesAllowed;
00139 theConstraint->instanceAddressesAllowed = sourceConstraint->instanceAddressesAllowed;
00140 theConstraint->externalAddressesAllowed = sourceConstraint->externalAddressesAllowed;
00141 theConstraint->voidAllowed = sourceConstraint->voidAllowed;
00142 theConstraint->multifieldsAllowed = sourceConstraint->multifieldsAllowed;
00143 theConstraint->singlefieldsAllowed = sourceConstraint->singlefieldsAllowed;
00144 theConstraint->factAddressesAllowed = sourceConstraint->factAddressesAllowed;
00145 theConstraint->anyRestriction = sourceConstraint->anyRestriction;
00146 theConstraint->symbolRestriction = sourceConstraint->symbolRestriction;
00147 theConstraint->stringRestriction = sourceConstraint->stringRestriction;
00148 theConstraint->floatRestriction = sourceConstraint->floatRestriction;
00149 theConstraint->integerRestriction = sourceConstraint->integerRestriction;
00150 theConstraint->classRestriction = sourceConstraint->classRestriction;
00151 theConstraint->instanceNameRestriction = sourceConstraint->instanceNameRestriction;
00152 theConstraint->classList = CopyExpression(theEnv,sourceConstraint->classList);
00153 theConstraint->restrictionList = CopyExpression(theEnv,sourceConstraint->restrictionList);
00154 theConstraint->minValue = CopyExpression(theEnv,sourceConstraint->minValue);
00155 theConstraint->maxValue = CopyExpression(theEnv,sourceConstraint->maxValue);
00156 theConstraint->minFields = CopyExpression(theEnv,sourceConstraint->minFields);
00157 theConstraint->maxFields = CopyExpression(theEnv,sourceConstraint->maxFields);
00158 theConstraint->bucket = -1;
00159 theConstraint->count = 0;
00160 theConstraint->multifield = CopyConstraintRecord(theEnv,sourceConstraint->multifield);
00161 theConstraint->next = NULL;
00162
00163 return(theConstraint);
00164 }
00165
00166 #if (! RUN_TIME) && (! BLOAD_ONLY)
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 globle void SetAnyRestrictionFlags(
00177 CONSTRAINT_RECORD *theConstraint,
00178 int justOne)
00179 {
00180 int flag1, flag2;
00181
00182 if (justOne)
00183 {
00184 flag1 = TRUE;
00185 flag2 = FALSE;
00186 }
00187 else
00188 {
00189 flag1 = FALSE;
00190 flag2 = TRUE;
00191 }
00192
00193 theConstraint->anyRestriction = flag1;
00194 theConstraint->symbolRestriction = flag2;
00195 theConstraint->stringRestriction = flag2;
00196 theConstraint->floatRestriction = flag2;
00197 theConstraint->integerRestriction = flag2;
00198 theConstraint->instanceNameRestriction = flag2;
00199 }
00200
00201
00202
00203
00204
00205
00206 globle int SetConstraintType(
00207 int theType,
00208 CONSTRAINT_RECORD *constraints)
00209 {
00210 int rv = TRUE;
00211
00212 switch(theType)
00213 {
00214 case UNKNOWN_VALUE:
00215 rv = constraints->anyAllowed;
00216 constraints->anyAllowed = TRUE;
00217 break;
00218
00219 case SYMBOL:
00220 rv = constraints->symbolsAllowed;
00221 constraints->symbolsAllowed = TRUE;
00222 break;
00223
00224 case STRING:
00225 rv = constraints->stringsAllowed;
00226 constraints->stringsAllowed = TRUE;
00227 break;
00228
00229 case SYMBOL_OR_STRING:
00230 rv = (constraints->stringsAllowed | constraints->symbolsAllowed);
00231 constraints->symbolsAllowed = TRUE;
00232 constraints->stringsAllowed = TRUE;
00233 break;
00234
00235 case INTEGER:
00236 rv = constraints->integersAllowed;
00237 constraints->integersAllowed = TRUE;
00238 break;
00239
00240 case FLOAT:
00241 rv = constraints->floatsAllowed;
00242 constraints->floatsAllowed = TRUE;
00243 break;
00244
00245 case INTEGER_OR_FLOAT:
00246 rv = (constraints->integersAllowed | constraints->floatsAllowed);
00247 constraints->integersAllowed = TRUE;
00248 constraints->floatsAllowed = TRUE;
00249 break;
00250
00251 case INSTANCE_ADDRESS:
00252 rv = constraints->instanceAddressesAllowed;
00253 constraints->instanceAddressesAllowed = TRUE;
00254 break;
00255
00256 case INSTANCE_NAME:
00257 rv = constraints->instanceNamesAllowed;
00258 constraints->instanceNamesAllowed = TRUE;
00259 break;
00260
00261 case INSTANCE_OR_INSTANCE_NAME:
00262 rv = (constraints->instanceNamesAllowed | constraints->instanceAddressesAllowed);
00263 constraints->instanceNamesAllowed = TRUE;
00264 constraints->instanceAddressesAllowed = TRUE;
00265 break;
00266
00267 case EXTERNAL_ADDRESS:
00268 rv = constraints->externalAddressesAllowed;
00269 constraints->externalAddressesAllowed = TRUE;
00270 break;
00271
00272 case RVOID:
00273 rv = constraints->voidAllowed;
00274 constraints->voidAllowed = TRUE;
00275 break;
00276
00277 case FACT_ADDRESS:
00278 rv = constraints->factAddressesAllowed;
00279 constraints->factAddressesAllowed = TRUE;
00280 break;
00281
00282 case MULTIFIELD:
00283 rv = constraints->multifieldsAllowed;
00284 constraints->multifieldsAllowed = TRUE;
00285 break;
00286 }
00287
00288 if (theType != UNKNOWN_VALUE) constraints->anyAllowed = FALSE;
00289 return(rv);
00290 }
00291
00292 #endif
00293
00294
00295
00296
00297
00298
00299
00300 globle int CompareNumbers(
00301 void *theEnv,
00302 int type1,
00303 void *vptr1,
00304 int type2,
00305 void *vptr2)
00306 {
00307
00308
00309
00310
00311
00312 if (vptr1 == vptr2) return(EQUAL);
00313
00314
00315
00316
00317
00318
00319 if (vptr1 == SymbolData(theEnv)->PositiveInfinity) return(GREATER_THAN);
00320
00321 if (vptr1 == SymbolData(theEnv)->NegativeInfinity) return(LESS_THAN);
00322
00323 if (vptr2 == SymbolData(theEnv)->PositiveInfinity) return(LESS_THAN);
00324
00325 if (vptr2 == SymbolData(theEnv)->NegativeInfinity) return(GREATER_THAN);
00326
00327
00328
00329
00330
00331 if ((type1 == INTEGER) && (type2 == INTEGER))
00332 {
00333 if (ValueToLong(vptr1) < ValueToLong(vptr2))
00334 { return(LESS_THAN); }
00335 else if (ValueToLong(vptr1) > ValueToLong(vptr2))
00336 { return(GREATER_THAN); }
00337
00338 return(EQUAL);
00339 }
00340
00341
00342
00343
00344
00345 if ((type1 == FLOAT) && (type2 == FLOAT))
00346 {
00347 if (ValueToDouble(vptr1) < ValueToDouble(vptr2))
00348 { return(LESS_THAN); }
00349 else if (ValueToDouble(vptr1) > ValueToDouble(vptr2))
00350 { return(GREATER_THAN); }
00351
00352 return(EQUAL);
00353 }
00354
00355
00356
00357
00358
00359 if ((type1 == INTEGER) && (type2 == FLOAT))
00360 {
00361 if (((double) ValueToLong(vptr1)) < ValueToDouble(vptr2))
00362 { return(LESS_THAN); }
00363 else if (((double) ValueToLong(vptr1)) > ValueToDouble(vptr2))
00364 { return(GREATER_THAN); }
00365
00366 return(EQUAL);
00367 }
00368
00369
00370
00371
00372
00373 if ((type1 == FLOAT) && (type2 == INTEGER))
00374 {
00375 if (ValueToDouble(vptr1) < ((double) ValueToLong(vptr2)))
00376 { return(LESS_THAN); }
00377 else if (ValueToDouble(vptr1) > ((double) ValueToLong(vptr2)))
00378 { return(GREATER_THAN); }
00379
00380 return(EQUAL);
00381 }
00382
00383
00384
00385
00386
00387
00388 return(-1);
00389 }
00390
00391
00392
00393
00394
00395
00396
00397 globle CONSTRAINT_RECORD *ExpressionToConstraintRecord(
00398 void *theEnv,
00399 struct expr *theExpression)
00400 {
00401 CONSTRAINT_RECORD *rv;
00402
00403
00404
00405
00406
00407
00408 if (theExpression == NULL)
00409 {
00410 rv = GetConstraintRecord(theEnv);
00411 rv->anyAllowed = FALSE;
00412 return(rv);
00413 }
00414
00415
00416
00417
00418
00419 if ((theExpression->type == SF_VARIABLE) ||
00420 (theExpression->type == MF_VARIABLE) ||
00421 #if DEFGENERIC_CONSTRUCT
00422 (theExpression->type == GCALL) ||
00423 #endif
00424 #if DEFFUNCTION_CONSTRUCT
00425 (theExpression->type == PCALL) ||
00426 #endif
00427 (theExpression->type == GBL_VARIABLE) ||
00428 (theExpression->type == MF_GBL_VARIABLE))
00429 {
00430 rv = GetConstraintRecord(theEnv);
00431 rv->multifieldsAllowed = TRUE;
00432 return(rv);
00433 }
00434 else if (theExpression->type == FCALL)
00435 { return(FunctionCallToConstraintRecord(theEnv,theExpression->value)); }
00436
00437
00438
00439
00440
00441 rv = GetConstraintRecord(theEnv);
00442 rv->anyAllowed = FALSE;
00443
00444 if (theExpression->type == FLOAT)
00445 {
00446 rv->floatRestriction = TRUE;
00447 rv->floatsAllowed = TRUE;
00448 }
00449 else if (theExpression->type == INTEGER)
00450 {
00451 rv->integerRestriction = TRUE;
00452 rv->integersAllowed = TRUE;
00453 }
00454 else if (theExpression->type == SYMBOL)
00455 {
00456 rv->symbolRestriction = TRUE;
00457 rv->symbolsAllowed = TRUE;
00458 }
00459 else if (theExpression->type == STRING)
00460 {
00461 rv->stringRestriction = TRUE;
00462 rv->stringsAllowed = TRUE;
00463 }
00464 else if (theExpression->type == INSTANCE_NAME)
00465 {
00466 rv->instanceNameRestriction = TRUE;
00467 rv->instanceNamesAllowed = TRUE;
00468 }
00469 else if (theExpression->type == INSTANCE_ADDRESS)
00470 { rv->instanceAddressesAllowed = TRUE; }
00471
00472 if (rv->floatsAllowed || rv->integersAllowed || rv->symbolsAllowed ||
00473 rv->stringsAllowed || rv->instanceNamesAllowed)
00474 { rv->restrictionList = GenConstant(theEnv,theExpression->type,theExpression->value); }
00475
00476 return(rv);
00477 }
00478
00479
00480
00481
00482
00483
00484
00485 globle CONSTRAINT_RECORD *FunctionCallToConstraintRecord(
00486 void *theEnv,
00487 void *theFunction)
00488 {
00489 CONSTRAINT_RECORD *rv;
00490
00491 rv = GetConstraintRecord(theEnv);
00492 rv->anyAllowed = FALSE;
00493
00494 switch ((char) ValueFunctionType(theFunction))
00495 {
00496 case 'a':
00497 rv->externalAddressesAllowed = TRUE;
00498 break;
00499
00500 case 'f':
00501 case 'd':
00502 rv->floatsAllowed = TRUE;
00503 break;
00504
00505 case 'i':
00506 case 'g':
00507 case 'l':
00508 rv->integersAllowed = TRUE;
00509 break;
00510
00511 case 'j':
00512 rv->instanceNamesAllowed = TRUE;
00513 rv->symbolsAllowed = TRUE;
00514 rv->stringsAllowed = TRUE;
00515 break;
00516
00517 case 'k':
00518 rv->symbolsAllowed = TRUE;
00519 rv->stringsAllowed = TRUE;
00520 break;
00521
00522 case 'm':
00523 rv->singlefieldsAllowed = FALSE;
00524 rv->multifieldsAllowed = TRUE;
00525 break;
00526
00527 case 'n':
00528 rv->floatsAllowed = TRUE;
00529 rv->integersAllowed = TRUE;
00530 break;
00531
00532 case 'o':
00533 rv->instanceNamesAllowed = TRUE;
00534 break;
00535
00536 case 's':
00537 rv->stringsAllowed = TRUE;
00538 break;
00539
00540 case 'u':
00541 rv->anyAllowed = TRUE;
00542 rv->multifieldsAllowed = TRUE;
00543 break;
00544
00545 case 'w':
00546 case 'c':
00547 case 'b':
00548 rv->symbolsAllowed = TRUE;
00549 break;
00550
00551 case 'x':
00552 rv->instanceAddressesAllowed = TRUE;
00553 break;
00554
00555 case 'v':
00556 rv->voidAllowed = TRUE;
00557 break;
00558 }
00559
00560 return(rv);
00561 }
00562
00563
00564
00565
00566
00567
00568 globle CONSTRAINT_RECORD *ArgumentTypeToConstraintRecord(
00569 void *theEnv,
00570 int theRestriction)
00571 {
00572 CONSTRAINT_RECORD *rv;
00573
00574 rv = GetConstraintRecord(theEnv);
00575 rv->anyAllowed = FALSE;
00576
00577 switch (theRestriction)
00578 {
00579 case 'a':
00580 rv->externalAddressesAllowed = TRUE;
00581 break;
00582
00583 case 'e':
00584 rv->symbolsAllowed = TRUE;
00585 rv->instanceNamesAllowed = TRUE;
00586 rv->instanceAddressesAllowed = TRUE;
00587 break;
00588
00589 case 'd':
00590 case 'f':
00591 rv->floatsAllowed = TRUE;
00592 break;
00593
00594 case 'g':
00595 rv->integersAllowed = TRUE;
00596 rv->floatsAllowed = TRUE;
00597 rv->symbolsAllowed = TRUE;
00598 break;
00599
00600 case 'h':
00601 rv->factAddressesAllowed = TRUE;
00602 rv->integersAllowed = TRUE;
00603 rv->symbolsAllowed = TRUE;
00604 rv->instanceNamesAllowed = TRUE;
00605 rv->instanceAddressesAllowed = TRUE;
00606 break;
00607
00608 case 'i':
00609 case 'l':
00610 rv->integersAllowed = TRUE;
00611 break;
00612
00613 case 'j':
00614 rv->symbolsAllowed = TRUE;
00615 rv->stringsAllowed = TRUE;
00616 rv->instanceNamesAllowed = TRUE;
00617 break;
00618
00619 case 'k':
00620 rv->symbolsAllowed = TRUE;
00621 rv->stringsAllowed = TRUE;
00622 break;
00623
00624 case 'm':
00625 rv->singlefieldsAllowed = FALSE;
00626 rv->multifieldsAllowed = TRUE;
00627 break;
00628
00629 case 'n':
00630 rv->floatsAllowed = TRUE;
00631 rv->integersAllowed = TRUE;
00632 break;
00633
00634 case 'o':
00635 rv->instanceNamesAllowed = TRUE;
00636 break;
00637
00638 case 'p':
00639 rv->instanceNamesAllowed = TRUE;
00640 rv->symbolsAllowed = TRUE;
00641 break;
00642
00643 case 'q':
00644 rv->symbolsAllowed = TRUE;
00645 rv->stringsAllowed = TRUE;
00646 rv->multifieldsAllowed = TRUE;
00647 break;
00648
00649 case 's':
00650 rv->stringsAllowed = TRUE;
00651 break;
00652
00653 case 'w':
00654 rv->symbolsAllowed = TRUE;
00655 break;
00656
00657 case 'x':
00658 rv->instanceAddressesAllowed = TRUE;
00659 break;
00660
00661 case 'y':
00662 rv->factAddressesAllowed = TRUE;
00663 break;
00664
00665 case 'z':
00666 rv->symbolsAllowed = TRUE;
00667 rv->factAddressesAllowed = TRUE;
00668 rv->integersAllowed = TRUE;
00669 break;
00670
00671 case 'u':
00672 rv->anyAllowed = TRUE;
00673 rv->multifieldsAllowed = TRUE;
00674 break;
00675
00676 case 'v':
00677 rv->voidAllowed = TRUE;
00678 break;
00679 }
00680
00681 return(rv);
00682 }
00683
00684
00685
00686