📄 cstrnpsr.c
字号:
/* the parsed constraint record. Assumes AddConstraint has */
/* not yet been called for the destination constraint */
/* record. */
/***********************************************************/
globle void OverlayConstraint(
void *theEnv,
CONSTRAINT_PARSE_RECORD *pc,
CONSTRAINT_RECORD *cdst,
CONSTRAINT_RECORD *csrc)
{
if (pc->type == 0)
{
cdst->anyAllowed = csrc->anyAllowed;
cdst->symbolsAllowed = csrc->symbolsAllowed;
cdst->stringsAllowed = csrc->stringsAllowed;
cdst->floatsAllowed = csrc->floatsAllowed;
cdst->integersAllowed = csrc->integersAllowed;
cdst->instanceNamesAllowed = csrc->instanceNamesAllowed;
cdst->instanceAddressesAllowed = csrc->instanceAddressesAllowed;
cdst->externalAddressesAllowed = csrc->externalAddressesAllowed;
cdst->voidAllowed = csrc->voidAllowed;
cdst->factAddressesAllowed = csrc->factAddressesAllowed;
}
if (pc->range == 0)
{
ReturnExpression(theEnv,cdst->minValue);
ReturnExpression(theEnv,cdst->maxValue);
cdst->minValue = CopyExpression(theEnv,csrc->minValue);
cdst->maxValue = CopyExpression(theEnv,csrc->maxValue);
}
if (pc->allowedClasses == 0)
{
ReturnExpression(theEnv,cdst->classList);
cdst->classList = CopyExpression(theEnv,csrc->classList);
}
if (pc->allowedValues == 0)
{
if ((pc->allowedSymbols == 0) &&
(pc->allowedStrings == 0) &&
(pc->allowedLexemes == 0) &&
(pc->allowedIntegers == 0) &&
(pc->allowedFloats == 0) &&
(pc->allowedNumbers == 0) &&
(pc->allowedInstanceNames == 0))
{
cdst->anyRestriction = csrc->anyRestriction;
cdst->symbolRestriction = csrc->symbolRestriction;
cdst->stringRestriction = csrc->stringRestriction;
cdst->floatRestriction = csrc->floatRestriction;
cdst->integerRestriction = csrc->integerRestriction;
cdst->classRestriction = csrc->classRestriction;
cdst->instanceNameRestriction = csrc->instanceNameRestriction;
cdst->restrictionList = CopyExpression(theEnv,csrc->restrictionList);
}
else
{
if ((pc->allowedSymbols == 0) && csrc->symbolRestriction)
{
cdst->symbolRestriction = 1;
AddToRestrictionList(theEnv,SYMBOL,cdst,csrc);
}
if ((pc->allowedStrings == 0) && csrc->stringRestriction)
{
cdst->stringRestriction = 1;
AddToRestrictionList(theEnv,STRING,cdst,csrc);
}
if ((pc->allowedLexemes == 0) && csrc->symbolRestriction && csrc->stringRestriction)
{
cdst->symbolRestriction = 1;
cdst->stringRestriction = 1;
AddToRestrictionList(theEnv,SYMBOL,cdst,csrc);
AddToRestrictionList(theEnv,STRING,cdst,csrc);
}
if ((pc->allowedIntegers == 0) && csrc->integerRestriction)
{
cdst->integerRestriction = 1;
AddToRestrictionList(theEnv,INTEGER,cdst,csrc);
}
if ((pc->allowedFloats == 0) && csrc->floatRestriction)
{
cdst->floatRestriction = 1;
AddToRestrictionList(theEnv,FLOAT,cdst,csrc);
}
if ((pc->allowedNumbers == 0) && csrc->integerRestriction && csrc->floatRestriction)
{
cdst->integerRestriction = 1;
cdst->floatRestriction = 1;
AddToRestrictionList(theEnv,INTEGER,cdst,csrc);
AddToRestrictionList(theEnv,FLOAT,cdst,csrc);
}
if ((pc->allowedInstanceNames == 0) && csrc->instanceNameRestriction)
{
cdst->instanceNameRestriction = 1;
AddToRestrictionList(theEnv,INSTANCE_NAME,cdst,csrc);
}
}
}
if (pc->cardinality == 0)
{
ReturnExpression(theEnv,cdst->minFields);
ReturnExpression(theEnv,cdst->maxFields);
cdst->minFields = CopyExpression(theEnv,csrc->minFields);
cdst->maxFields = CopyExpression(theEnv,csrc->maxFields);
}
}
/**********************************************/
/* OverlayConstraintParseRecord: Performs a */
/* field-wise "or" of the destination parse */
/* record with the source parse record. */
/**********************************************/
globle void OverlayConstraintParseRecord(
CONSTRAINT_PARSE_RECORD *dst,
CONSTRAINT_PARSE_RECORD *src)
{
if (src->type) dst->type = TRUE;
if (src->range) dst->range = TRUE;
if (src->allowedSymbols) dst->allowedSymbols = TRUE;
if (src->allowedStrings) dst->allowedStrings = TRUE;
if (src->allowedLexemes) dst->allowedLexemes = TRUE;
if (src->allowedIntegers) dst->allowedIntegers = TRUE;
if (src->allowedFloats) dst->allowedFloats = TRUE;
if (src->allowedNumbers) dst->allowedNumbers = TRUE;
if (src->allowedValues) dst->allowedValues = TRUE;
if (src->allowedInstanceNames) dst->allowedInstanceNames = TRUE;
if (src->allowedClasses) dst->allowedClasses = TRUE;
if (src->cardinality) dst->cardinality = TRUE;
}
/************************************************************/
/* AddToRestrictionList: Prepends atoms of the specified */
/* type from the source restriction list to the destination */
/************************************************************/
static void AddToRestrictionList(
void *theEnv,
int type,
CONSTRAINT_RECORD *cdst,
CONSTRAINT_RECORD *csrc)
{
struct expr *theExp,*tmp;
for (theExp = csrc->restrictionList; theExp != NULL; theExp = theExp->nextArg)
{
if (theExp->type == type)
{
tmp = GenConstant(theEnv,theExp->type,theExp->value);
tmp->nextArg = cdst->restrictionList;
cdst->restrictionList = tmp;
}
}
}
/*******************************************************************/
/* ParseAllowedValuesAttribute: Parses the allowed-... attributes. */
/*******************************************************************/
static intBool ParseAllowedValuesAttribute(
void *theEnv,
char *readSource,
char *constraintName,
CONSTRAINT_RECORD *constraints,
CONSTRAINT_PARSE_RECORD *parsedConstraints)
{
struct token inputToken;
int expectedType, restrictionType, error = FALSE;
struct expr *newValue, *lastValue;
int constantParsed = FALSE, variableParsed = FALSE;
char *tempPtr = NULL;
/*======================================================*/
/* The allowed-values attribute is not allowed if other */
/* allowed-... attributes have already been parsed. */
/*======================================================*/
if ((strcmp(constraintName,"allowed-values") == 0) &&
((parsedConstraints->allowedSymbols) ||
(parsedConstraints->allowedStrings) ||
(parsedConstraints->allowedLexemes) ||
(parsedConstraints->allowedIntegers) ||
(parsedConstraints->allowedFloats) ||
(parsedConstraints->allowedNumbers) ||
(parsedConstraints->allowedInstanceNames)))
{
if (parsedConstraints->allowedSymbols) tempPtr = "allowed-symbols";
else if (parsedConstraints->allowedStrings) tempPtr = "allowed-strings";
else if (parsedConstraints->allowedLexemes) tempPtr = "allowed-lexemes";
else if (parsedConstraints->allowedIntegers) tempPtr = "allowed-integers";
else if (parsedConstraints->allowedFloats) tempPtr = "allowed-floats";
else if (parsedConstraints->allowedNumbers) tempPtr = "allowed-numbers";
else if (parsedConstraints->allowedInstanceNames) tempPtr = "allowed-instance-names";
NoConjunctiveUseError(theEnv,"allowed-values",tempPtr);
return(FALSE);
}
/*=======================================================*/
/* The allowed-values/numbers/integers/floats attributes */
/* are not allowed with the range attribute. */
/*=======================================================*/
if (((strcmp(constraintName,"allowed-values") == 0) ||
(strcmp(constraintName,"allowed-numbers") == 0) ||
(strcmp(constraintName,"allowed-integers") == 0) ||
(strcmp(constraintName,"allowed-floats") == 0)) &&
(parsedConstraints->range))
{
NoConjunctiveUseError(theEnv,constraintName,"range");
return(FALSE);
}
/*===================================================*/
/* The allowed-... attributes are not allowed if the */
/* allowed-values attribute has already been parsed. */
/*===================================================*/
if ((strcmp(constraintName,"allowed-values") != 0) &&
(parsedConstraints->allowedValues))
{
NoConjunctiveUseError(theEnv,constraintName,"allowed-values");
return(FALSE);
}
/*==================================================*/
/* The allowed-numbers attribute is not allowed if */
/* the allowed-integers or allowed-floats attribute */
/* has already been parsed. */
/*==================================================*/
if ((strcmp(constraintName,"allowed-numbers") == 0) &&
((parsedConstraints->allowedFloats) || (parsedConstraints->allowedIntegers)))
{
if (parsedConstraints->allowedFloats) tempPtr = "allowed-floats";
else tempPtr = "allowed-integers";
NoConjunctiveUseError(theEnv,"allowed-numbers",tempPtr);
return(FALSE);
}
/*============================================================*/
/* The allowed-integers/floats attributes are not allowed if */
/* the allowed-numbers attribute has already been parsed. */
/*============================================================*/
if (((strcmp(constraintName,"allowed-integers") == 0) ||
(strcmp(constraintName,"allowed-floats") == 0)) &&
(parsedConstraints->allowedNumbers))
{
NoConjunctiveUseError(theEnv,constraintName,"allowed-number");
return(FALSE);
}
/*==================================================*/
/* The allowed-lexemes attribute is not allowed if */
/* the allowed-symbols or allowed-strings attribute */
/* has already been parsed. */
/*==================================================*/
if ((strcmp(constraintName,"allowed-lexemes") == 0) &&
((parsedConstraints->allowedSymbols) || (parsedConstraints->allowedStrings)))
{
if (parsedConstraints->allowedSymbols) tempPtr = "allowed-symbols";
else tempPtr = "allowed-strings";
NoConjunctiveUseError(theEnv,"allowed-lexemes",tempPtr);
return(FALSE);
}
/*===========================================================*/
/* The allowed-symbols/strings attributes are not allowed if */
/* the allowed-lexemes attribute has already been parsed. */
/*===========================================================*/
if (((strcmp(constraintName,"allowed-symbols") == 0) ||
(strcmp(constraintName,"allowed-strings") == 0)) &&
(parsedConstraints->allowedLexemes))
{
NoConjunctiveUseError(theEnv,constraintName,"allowed-lexemes");
return(FALSE);
}
/*========================*/
/* Get the expected type. */
/*========================*/
restrictionType = GetConstraintTypeFromAllowedName(constraintName);
SetRestrictionFlag(restrictionType,constraints,TRUE);
if (strcmp(constraintName,"allowed-classes") == 0)
{ expectedType = SYMBOL; }
else
{ expectedType = restrictionType; }
/*=================================================*/
/* Get the last value in the restriction list (the */
/* allowed values will be appended there). */
/*=================================================*/
if (strcmp(constraintName,"allowed-classes") == 0)
{ lastValue = constraints->classList; }
else
{ lastValue = constraints->restrictionList; }
if (lastValue != NULL)
{ while (lastValue->nextArg != NULL) lastValue = lastValue->nextArg; }
/*==================================================*/
/* Read the allowed values and add them to the list */
/* until a right parenthesis is encountered. */
/*==================================================*/
SavePPBuffer(theEnv," ");
GetToken(theEnv,readSource,&inputToken);
while (inputToken.type != RPAREN)
{
SavePPBuffer(theEnv," ");
/*=============================================*/
/* Determine the type of the token just parsed */
/* and if it is an appropriate value. */
/*=============================================*/
switch(inputToken.type)
{
case INTEGER:
if ((expectedType != UNKNOWN_VALUE) &&
(expectedType != INTEGER) &&
(expectedType != INTEGER_OR_FLOAT)) error = TRUE;
constantParsed = TRUE;
break;
case FLOAT:
if ((expectedType != UNKNOWN_VALUE) &&
(expectedType != FLOAT) &&
(expectedType != INTEGER_OR_FLOAT)) error = TRUE;
constantParsed = TRUE;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -