📄 constrnt.c
字号:
hashValue = (int) (count % SIZE_CONSTRAINT_HASH);
if (hashValue < 0) hashValue = - hashValue;
return(hashValue);
}
/**********************************************/
/* ConstraintCompare: Compares two constraint */
/* records and returns TRUE if they are */
/* identical, otherwise FALSE. */
/**********************************************/
static int ConstraintCompare(
struct constraintRecord *constraint1,
struct constraintRecord *constraint2)
{
struct expr *tmpPtr1, *tmpPtr2;
if ((constraint1->anyAllowed != constraint2->anyAllowed) ||
(constraint1->symbolsAllowed != constraint2->symbolsAllowed) ||
(constraint1->stringsAllowed != constraint2->stringsAllowed) ||
(constraint1->floatsAllowed != constraint2->floatsAllowed) ||
(constraint1->integersAllowed != constraint2->integersAllowed) ||
(constraint1->instanceNamesAllowed != constraint2->instanceNamesAllowed) ||
(constraint1->instanceAddressesAllowed != constraint2->instanceAddressesAllowed) ||
(constraint1->externalAddressesAllowed != constraint2->externalAddressesAllowed) ||
(constraint1->voidAllowed != constraint2->voidAllowed) ||
(constraint1->multifieldsAllowed != constraint2->multifieldsAllowed) ||
(constraint1->singlefieldsAllowed != constraint2->singlefieldsAllowed) ||
(constraint1->factAddressesAllowed != constraint2->factAddressesAllowed) ||
(constraint1->anyRestriction != constraint2->anyRestriction) ||
(constraint1->symbolRestriction != constraint2->symbolRestriction) ||
(constraint1->stringRestriction != constraint2->stringRestriction) ||
(constraint1->floatRestriction != constraint2->floatRestriction) ||
(constraint1->integerRestriction != constraint2->integerRestriction) ||
(constraint1->classRestriction != constraint2->classRestriction) ||
(constraint1->instanceNameRestriction != constraint2->instanceNameRestriction))
{ return(FALSE); }
for (tmpPtr1 = constraint1->classList, tmpPtr2 = constraint2->classList;
(tmpPtr1 != NULL) && (tmpPtr2 != NULL);
tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)
{
if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))
{ return(FALSE); }
}
if (tmpPtr1 != tmpPtr2) return(FALSE);
for (tmpPtr1 = constraint1->restrictionList, tmpPtr2 = constraint2->restrictionList;
(tmpPtr1 != NULL) && (tmpPtr2 != NULL);
tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)
{
if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))
{ return(FALSE); }
}
if (tmpPtr1 != tmpPtr2) return(FALSE);
for (tmpPtr1 = constraint1->minValue, tmpPtr2 = constraint2->minValue;
(tmpPtr1 != NULL) && (tmpPtr2 != NULL);
tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)
{
if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))
{ return(FALSE); }
}
if (tmpPtr1 != tmpPtr2) return(FALSE);
for (tmpPtr1 = constraint1->maxValue, tmpPtr2 = constraint2->maxValue;
(tmpPtr1 != NULL) && (tmpPtr2 != NULL);
tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)
{
if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))
{ return(FALSE); }
}
if (tmpPtr1 != tmpPtr2) return(FALSE);
for (tmpPtr1 = constraint1->minFields, tmpPtr2 = constraint2->minFields;
(tmpPtr1 != NULL) && (tmpPtr2 != NULL);
tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)
{
if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))
{ return(FALSE); }
}
if (tmpPtr1 != tmpPtr2) return(FALSE);
for (tmpPtr1 = constraint1->maxFields, tmpPtr2 = constraint2->maxFields;
(tmpPtr1 != NULL) && (tmpPtr2 != NULL);
tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)
{
if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))
{ return(FALSE); }
}
if (tmpPtr1 != tmpPtr2) return(FALSE);
if (((constraint1->multifield == NULL) && (constraint2->multifield != NULL)) ||
((constraint1->multifield != NULL) && (constraint2->multifield == NULL)))
{ return(FALSE); }
else if (constraint1->multifield == constraint2->multifield)
{ return(TRUE); }
return(ConstraintCompare(constraint1->multifield,constraint2->multifield));
}
/************************************/
/* AddConstraint: Adds a constraint */
/* to the constraint hash table. */
/************************************/
globle struct constraintRecord *AddConstraint(
void *theEnv,
struct constraintRecord *theConstraint)
{
struct constraintRecord *tmpPtr;
int hashValue;
if (theConstraint == NULL) return(NULL);
hashValue = HashConstraint(theConstraint);
for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[hashValue];
tmpPtr != NULL;
tmpPtr = tmpPtr->next)
{
if (ConstraintCompare(theConstraint,tmpPtr))
{
tmpPtr->count++;
ReturnConstraintRecord(theEnv,theConstraint);
return(tmpPtr);
}
}
InstallConstraintRecord(theEnv,theConstraint);
theConstraint->count = 1;
theConstraint->bucket = hashValue;
theConstraint->next = ConstraintData(theEnv)->ConstraintHashtable[hashValue];
ConstraintData(theEnv)->ConstraintHashtable[hashValue] = theConstraint;
return(theConstraint);
}
/*************************************************/
/* InstallConstraintRecord: Increments the count */
/* values of all occurrences of primitive data */
/* types found in a constraint record. */
/*************************************************/
static void InstallConstraintRecord(
void *theEnv,
CONSTRAINT_RECORD *constraints)
{
struct expr *tempExpr;
tempExpr = AddHashedExpression(theEnv,constraints->classList);
ReturnExpression(theEnv,constraints->classList);
constraints->classList = tempExpr;
tempExpr = AddHashedExpression(theEnv,constraints->restrictionList);
ReturnExpression(theEnv,constraints->restrictionList);
constraints->restrictionList = tempExpr;
tempExpr = AddHashedExpression(theEnv,constraints->maxValue);
ReturnExpression(theEnv,constraints->maxValue);
constraints->maxValue = tempExpr;
tempExpr = AddHashedExpression(theEnv,constraints->minValue);
ReturnExpression(theEnv,constraints->minValue);
constraints->minValue = tempExpr;
tempExpr = AddHashedExpression(theEnv,constraints->minFields);
ReturnExpression(theEnv,constraints->minFields);
constraints->minFields = tempExpr;
tempExpr = AddHashedExpression(theEnv,constraints->maxFields);
ReturnExpression(theEnv,constraints->maxFields);
constraints->maxFields = tempExpr;
if (constraints->multifield != NULL)
{ InstallConstraintRecord(theEnv,constraints->multifield); }
}
#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
/**********************************************/
/* SDCCommand: H/L access routine for the */
/* set-dynamic-constraint-checking command. */
/**********************************************/
globle int SDCCommand(
void *theEnv)
{
int oldValue;
DATA_OBJECT arg_ptr;
oldValue = EnvGetDynamicConstraintChecking(theEnv);
if (EnvArgCountCheck(theEnv,"set-dynamic-constraint-checking",EXACTLY,1) == -1)
{ return(oldValue); }
EnvRtnUnknown(theEnv,1,&arg_ptr);
if ((arg_ptr.value == EnvFalseSymbol(theEnv)) && (arg_ptr.type == SYMBOL))
{ EnvSetDynamicConstraintChecking(theEnv,FALSE); }
else
{ EnvSetDynamicConstraintChecking(theEnv,TRUE); }
return(oldValue);
}
/**********************************************/
/* GDCCommand: H/L access routine for the */
/* get-dynamic-constraint-checking command. */
/**********************************************/
globle int GDCCommand(
void *theEnv)
{
int oldValue;
oldValue = EnvGetDynamicConstraintChecking(theEnv);
if (EnvArgCountCheck(theEnv,"get-dynamic-constraint-checking",EXACTLY,0) == -1)
{ return(oldValue); }
return(oldValue);
}
/*********************************************/
/* SSCCommand: H/L access routine for the */
/* set-static-constraint-checking command. */
/*********************************************/
globle int SSCCommand(
void *theEnv)
{
int oldValue;
DATA_OBJECT arg_ptr;
oldValue = EnvGetStaticConstraintChecking(theEnv);
if (EnvArgCountCheck(theEnv,"set-static-constraint-checking",EXACTLY,1) == -1)
{ return(oldValue); }
EnvRtnUnknown(theEnv,1,&arg_ptr);
if ((arg_ptr.value == EnvFalseSymbol(theEnv)) && (arg_ptr.type == SYMBOL))
{ EnvSetStaticConstraintChecking(theEnv,FALSE); }
else
{ EnvSetStaticConstraintChecking(theEnv,TRUE); }
return(oldValue);
}
/*********************************************/
/* GSCCommand: H/L access routine for the */
/* get-static-constraint-checking command. */
/*********************************************/
globle int GSCCommand(
void *theEnv)
{
int oldValue;
oldValue = EnvGetStaticConstraintChecking(theEnv);
if (EnvArgCountCheck(theEnv,"get-static-constraint-checking",EXACTLY,0) == -1)
{ return(oldValue); }
return(oldValue);
}
/******************************************************/
/* EnvSetDynamicConstraintChecking: C access routine */
/* for the set-dynamic-constraint-checking command. */
/******************************************************/
globle intBool EnvSetDynamicConstraintChecking(
void *theEnv,
int value)
{
int ov;
ov = ConstraintData(theEnv)->DynamicConstraintChecking;
ConstraintData(theEnv)->DynamicConstraintChecking = value;
return(ov);
}
/******************************************************/
/* EnvGetDynamicConstraintChecking: C access routine */
/* for the get-dynamic-constraint-checking command. */
/******************************************************/
globle intBool EnvGetDynamicConstraintChecking(
void *theEnv)
{
return(ConstraintData(theEnv)->DynamicConstraintChecking);
}
/*****************************************************/
/* EnvSetStaticConstraintChecking: C access routine */
/* for the set-static-constraint-checking command. */
/*****************************************************/
globle intBool EnvSetStaticConstraintChecking(
void *theEnv,
int value)
{
int ov;
ov = ConstraintData(theEnv)->StaticConstraintChecking;
ConstraintData(theEnv)->StaticConstraintChecking = value;
return(ov);
}
/*****************************************************/
/* EnvGetStaticConstraintChecking: C access routine */
/* for the get-static-constraint-checking command. */
/*****************************************************/
globle intBool EnvGetStaticConstraintChecking(
void *theEnv)
{
return(ConstraintData(theEnv)->StaticConstraintChecking);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -