예제 #1
0
static void IntersectAllowedClassExpressions(
  void *theEnv,
  CONSTRAINT_RECORD *constraint1,
  CONSTRAINT_RECORD *constraint2,
  CONSTRAINT_RECORD *newConstraint)
  {
   struct expr *theList1, *theList2;
   struct expr *theHead = NULL, *tmpExpr;

   /*============================================*/
   /* Loop through each value in allowed-classes */
   /* list of the first constraint record. Add   */
   /* each value to a list if it satisfies the   */
   /* restrictions for both constraint records.  */
   /*============================================*/
   
   for (theList1 = constraint1->classList;
        theList1 != NULL;
        theList1 = theList1->nextArg)
     {
      if (CheckAllowedClassesConstraint(theEnv,theList1->type,theList1->value,constraint1) &&
          CheckAllowedClassesConstraint(theEnv,theList1->type,theList1->value,constraint2))
        {
         tmpExpr = GenConstant(theEnv,theList1->type,theList1->value);
         tmpExpr->nextArg = theHead;
         theHead = tmpExpr;
        }
     }

   /*============================================*/
   /* Loop through each value in allowed-classes */
   /* list of the second constraint record. Add  */
   /* each value to a list if it satisfies the   */
   /* restrictions for both constraint records.  */
   /*============================================*/

   for (theList2 = constraint2->classList;
        theList2 != NULL;
        theList2 = theList2->nextArg)
     {
      if (FindItemInExpression(theList2->type,theList2->value,TRUE,theHead))
        { /* The value is already in the list--Do nothing */ }
      else if (CheckAllowedClassesConstraint(theEnv,theList2->type,theList2->value,constraint1) &&
               CheckAllowedClassesConstraint(theEnv,theList2->type,theList2->value,constraint2))
        {
         tmpExpr = GenConstant(theEnv,theList2->type,theList2->value);
         tmpExpr->nextArg = theHead;
         theHead = tmpExpr;
        }
     }

   /*=================================================*/
   /* Set the allowed classes list for the constraint */
   /* record to the intersected values of the two     */
   /* other constraint records.                       */
   /*=================================================*/

   newConstraint->classList = theHead;
  }
예제 #2
0
globle int ConstraintCheckValue(
  void *theEnv,
  int theType,
  void *theValue,
  CONSTRAINT_RECORD *theConstraints)
  {
   if (CheckTypeConstraint(theType,theConstraints) == FALSE)
     { return(TYPE_VIOLATION); }

   else if (CheckAllowedValuesConstraint(theType,theValue,theConstraints) == FALSE)
     { return(ALLOWED_VALUES_VIOLATION); }

   else if (CheckAllowedClassesConstraint(theEnv,theType,theValue,theConstraints) == FALSE)
     { return(ALLOWED_CLASSES_VIOLATION); }

   else if (CheckRangeConstraint(theEnv,theType,theValue,theConstraints) == FALSE)
     { return(RANGE_VIOLATION); }

   else if (theType == FCALL)
     {
      if (CheckFunctionReturnType((int) ValueFunctionType(theValue),theConstraints) == FALSE)
        { return(FUNCTION_RETURN_TYPE_VIOLATION); }
     }

   return(NO_VIOLATION);
  }