⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clsltpsr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
  }  /*************************************************************  NAME         : ParseDefaultFacet  DESCRIPTION  : Parses the facet for a slot  INPUTS       : 1) The input logical name                 2) The bitmap indicating which facets have                    already been parsed                 3) The slot descriptor to set  RETURNS      : CLIPS_TRUE if all OK, CLIPS_FALSE otherwise  SIDE EFFECTS : Slot  set and parsed facet bitmap set  NOTES        : Syntax: (default ?NONE|<expression>*)                         (default-dynamic <expression>*) *************************************************************/static BOOLEAN ParseDefaultFacet(readSource,specbits,slot)  char *readSource,*specbits;  SLOT_DESC *slot;  {   EXPRESSION *tmp;   int error,noneSpecified,deriveSpecified;      if (TestBitMap(specbits,DEFAULT_BIT))     {      PrintErrorID("CLSLTPSR",2,CLIPS_FALSE);      PrintCLIPS(WERROR,"default facet already specified.\n");      return(CLIPS_FALSE);     }   SetBitMap(specbits,DEFAULT_BIT);   error = CLIPS_FALSE;   tmp = ParseDefault(readSource,1,(int) TestBitMap(specbits,DEFAULT_DYNAMIC_BIT),                      0,&noneSpecified,&deriveSpecified,&error);   if (error == CLIPS_TRUE)     return(CLIPS_FALSE);   if (noneSpecified || deriveSpecified)     {     if (noneSpecified)       {        slot->noDefault = 1;        slot->defaultSpecified = 1;       }      else        ClearBitMap(specbits,DEFAULT_BIT);     }   else     {      slot->defaultValue = (VOID *) PackExpression(tmp);      ReturnExpression(tmp);      ExpressionInstall((EXPRESSION *) slot->defaultValue);      slot->defaultSpecified = 1;     }   return(CLIPS_TRUE);  }  /**************************************************************************  NAME         : BuildCompositeFacets  DESCRIPTION  : Composite slots are ones that get their facets                   from more than one class.  By default, the most                   specific class in object's precedence list specifies                   the complete set of facets for a slot.  The composite                   facet in a slot allows facets that are not overridden                   by the most specific class to be obtained from other                   classes.                                    Since all superclasses are predetermined before creating                   a new class based on them, this routine need only                   examine the immediately next most specific class for                   extra facets.  Even if that slot is also composite, the                   other facets have already been filtered down.  If the                   slot is no-inherit, the next most specific class must                   be examined.  INPUTS       : 1) The slot descriptor                 2) The class precedence list                 3) The bitmap marking which facets were specified in                    the original slot definition  RETURNS      : Nothing useful  SIDE EFFECTS : Composite slot is updated to reflect facets from                   a less specific class  NOTES        : Assumes slot is composite *************************************************************************/static VOID BuildCompositeFacets(sd,preclist,specbits,parsedConstraint)  SLOT_DESC *sd;  PACKED_CLASS_LINKS *preclist;  char *specbits;  CONSTRAINT_PARSE_RECORD *parsedConstraint;  {   SLOT_DESC *compslot;   register unsigned i;      for (i = 1 ; i < preclist->classCount ; i++)     {      compslot = FindClassSlot(preclist->classArray[i],sd->slotName->name);      if ((compslot != NULL) ? (compslot->noInherit == 0) : CLIPS_FALSE)        break;     }   if (compslot != NULL)     {      if ((sd->defaultSpecified == 0) && (compslot->defaultSpecified == 1))        {         sd->dynamicDefault = compslot->dynamicDefault;         sd->noDefault = compslot->noDefault;         sd->defaultSpecified = 1;         if (compslot->defaultValue != NULL)           {            if (sd->dynamicDefault)              {               sd->defaultValue = (VOID *) PackExpression((EXPRESSION *) compslot->defaultValue);               ExpressionInstall((EXPRESSION *) sd->defaultValue);              }            else              {               sd->defaultValue = (VOID *) get_struct(dataObject);               CopyMemory(DATA_OBJECT,1,sd->defaultValue,compslot->defaultValue);               ValueInstall((DATA_OBJECT *) sd->defaultValue);              }           }        }      if (TestBitMap(specbits,FIELD_BIT) == 0)        sd->multiple = compslot->multiple;      if (TestBitMap(specbits,STORAGE_BIT) == 0)        sd->shared = compslot->shared;      if (TestBitMap(specbits,ACCESS_BIT) == 0)        {         sd->noWrite = compslot->noWrite;         sd->initializeOnly = compslot->initializeOnly;        }#if INSTANCE_PATTERN_MATCHING      if (TestBitMap(specbits,MATCH_BIT) == 0)        sd->reactive = compslot->reactive;#endif      if (TestBitMap(specbits,VISIBILITY_BIT) == 0)        sd->publicVisibility = compslot->publicVisibility;      if (TestBitMap(specbits,CREATE_ACCESSOR_BIT) == 0)        {         sd->createReadAccessor = compslot->createReadAccessor;         sd->createWriteAccessor = compslot->createWriteAccessor;        }      if ((TestBitMap(specbits,OVERRIDE_MSG_BIT) == 0) &&          compslot->overrideMessageSpecified)        {         DecrementSymbolCount(sd->overrideMessage);         sd->overrideMessage = compslot->overrideMessage;         IncrementSymbolCount(sd->overrideMessage);         sd->overrideMessageSpecified = CLIPS_TRUE;        }      OverlayConstraint(parsedConstraint,sd->constraint,compslot->constraint);     }  }/***************************************************  NAME         : CheckForFacetConflicts  DESCRIPTION  : Determines if all facets specified                 (and inherited) for a slot are                 consistent  INPUTS       : 1) The slot descriptor                 2) The parse record for the                    type constraints on the slot  RETURNS      : CLIPS_TRUE if all OK,                 CLIPS_FALSE otherwise  SIDE EFFECTS : Min and Max fields replaced in                 constraint for single-field slot  NOTES        : None ***************************************************/static BOOLEAN CheckForFacetConflicts(sd,parsedConstraint)  SLOT_DESC *sd;  CONSTRAINT_PARSE_RECORD *parsedConstraint;  {   if (sd->multiple == 0)     {      if (parsedConstraint->cardinality)        {         PrintErrorID("CLSLTPSR",3,CLIPS_TRUE);         PrintCLIPS(WERROR,"Cardinality facet can only be used with multifield slots\n");         return(CLIPS_FALSE);        }      else        {         ReturnExpression(sd->constraint->minFields);         ReturnExpression(sd->constraint->maxFields);         sd->constraint->minFields = GenConstant(INTEGER,AddLong(1L));         sd->constraint->maxFields = GenConstant(INTEGER,AddLong(1L));        }     }   if (sd->noDefault && sd->noWrite)     {      PrintErrorID("CLSLTPSR",4,CLIPS_TRUE);      PrintCLIPS(WERROR,"read-only slots must have a default value\n");      return(CLIPS_FALSE);     }   if (sd->noWrite && (sd->createWriteAccessor || sd->overrideMessageSpecified))     {      PrintErrorID("CLSLTPSR",5,CLIPS_TRUE);      PrintCLIPS(WERROR,"read-only slots cannot have a write accessor\n");      return(CLIPS_FALSE);     }   if (sd->noInherit && sd->publicVisibility)     {      PrintErrorID("CLSLTPSR",6,CLIPS_TRUE);      PrintCLIPS(WERROR,"no-inherit slots cannot also be public\n");      return(CLIPS_FALSE);     }   return(CLIPS_TRUE);  }       /********************************************************************  NAME         : EvaluateSlotDefaultValue  DESCRIPTION  : Checks the default value against the slot                 constraints and evaluates static default values  INPUTS       : 1) The slot descriptor                 2) The bitmap marking which facets were specified in                    the original slot definition  RETURNS      : CLIPS_TRUE if all OK, CLIPS_FALSE otherwise  SIDE EFFECTS : Static default value expressions deleted and                 replaced with data object evaluation  NOTES        : On errors, slot is marked as dynamix so that                 DeleteSlots() will erase the slot expression ********************************************************************/static BOOLEAN EvaluateSlotDefaultValue(sd,specbits)  SLOT_DESC *sd;  char *specbits;  {   DATA_OBJECT temp;   int oldce,olddcc,vCode;      /* ===================================================================      Slot default value expression is marked as dynamic until now so      that DeleteSlots() would erase in the event of an error.  The delay      was so that the evaluation of a static default value could be      delayed until all the constraints were parsed.      =================================================================== */   if (TestBitMap(specbits,DEFAULT_DYNAMIC_BIT) == 0)     sd->dynamicDefault = 0;      if (sd->noDefault)     return(CLIPS_TRUE);        if (sd->dynamicDefault == 0)     {      if (TestBitMap(specbits,DEFAULT_BIT))        {         oldce = ExecutingConstruct();         SetExecutingConstruct(CLIPS_TRUE);         olddcc = SetDynamicConstraintChecking(GetStaticConstraintChecking());         vCode = EvaluateAndStoreInDataObject((int) sd->multiple,                  (EXPRESSION *) sd->defaultValue,&temp);         if (vCode != CLIPS_FALSE)           vCode = ValidSlotValue(&temp,sd,NULL,"slot default value");         SetDynamicConstraintChecking(olddcc);         SetExecutingConstruct(oldce);         if (vCode)           {            ExpressionDeinstall((EXPRESSION *) sd->defaultValue);            ReturnPackedExpression((EXPRESSION *) sd->defaultValue);            sd->defaultValue = (VOID *) get_struct(dataObject);            CopyMemory(DATA_OBJECT,1,sd->defaultValue,&temp);            ValueInstall((DATA_OBJECT *) sd->defaultValue);           }         else           {            sd->dynamicDefault = 1;            return(CLIPS_FALSE);           }        }      else if (sd->defaultSpecified == 0)        {         sd->defaultValue = (VOID *) get_struct(dataObject);         DeriveDefaultFromConstraints(sd->constraint,                                      (DATA_OBJECT *) sd->defaultValue,(int) sd->multiple);         ValueInstall((DATA_OBJECT *) sd->defaultValue);        }     }   else if (GetStaticConstraintChecking())     {      vCode = ConstraintCheckExpressionChain((EXPRESSION *) sd->defaultValue,sd->constraint);      if (vCode != NO_VIOLATION)        {         PrintErrorID("CSTRNCHK",1,CLIPS_FALSE);         PrintCLIPS(WERROR,"Expression for ");         PrintSlot(WERROR,sd,NULL,"dynamic default value");         ConstraintViolationErrorMessage(NULL,NULL,0,0,NULL,0,                                         vCode,sd->constraint,CLIPS_FALSE);         return(CLIPS_FALSE);        }     }   return(CLIPS_TRUE);  }    #endif   /***************************************************  NAME         :   DESCRIPTION  :   INPUTS       :   RETURNS      :   SIDE EFFECTS :   NOTES        :  ***************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -