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

📄 insfun.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
  BOOLEAN linefeedFlag;  {   PrintCLIPS(logicalName,"[");   PrintCLIPS(logicalName,GetInstanceName((VOID *) theInstance));   PrintCLIPS(logicalName,"] of ");   PrintClassName(logicalName,theInstance->cls,linefeedFlag);  }   /* =========================================   *****************************************          INTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** */   /*****************************************************  NAME         : FindImportedInstance  DESCRIPTION  : Searches imported modules for an                 instance of the correct name                 The imports are searched recursively                 in the order of the module definition  INPUTS       : 1) The module for which to                    search imported modules                 2) The currently active module                 3) The first instance of the                    correct name (cannot be NULL)  RETURNS      : An instance of the correct name                 imported from another module which                 is in scope of the current module  SIDE EFFECTS : None  NOTES        : None *****************************************************/static INSTANCE_TYPE *FindImportedInstance(theModule,currentModule,startInstance)  struct defmodule *theModule,*currentModule;  INSTANCE_TYPE *startInstance;  {   struct portItem *importList;   INSTANCE_TYPE *ins;      if (theModule->visitedFlag)     return(NULL);   theModule->visitedFlag = CLIPS_TRUE;   importList = theModule->importList;   while (importList != NULL)     {      theModule = (struct defmodule *)                  FindDefmodule(ValueToString(importList->moduleName));      for (ins = startInstance ;           (ins != NULL) ? (ins->name == startInstance->name) : CLIPS_FALSE ;           ins = ins->nxtHash)        if ((ins->cls->header.whichModule->theModule == theModule) &&             DefclassInScope(ins->cls,currentModule))          return(ins);      ins = FindImportedInstance(theModule,currentModule,startInstance);      if (ins != NULL)        return(ins);      importList = importList->next;     }      /* ========================================================      Make sure instances of system classes are always visible      ======================================================== */    for (ins = startInstance ;        (ins != NULL) ? (ins->name == startInstance->name) : CLIPS_FALSE ;        ins = ins->nxtHash)     if (ins->cls->system)       return(ins);          return(NULL);  }  /***************************************************  NAME         : PrintInstanceName  DESCRIPTION  : Used by the rule system commands                 such as (matches) and (agenda)                 to print out the name of an instance  INPUTS       : 1) The logical output name                 2) A pointer to the instance  RETURNS      : Nothing useful  SIDE EFFECTS : Name of instance printed  NOTES        : None ***************************************************/static VOID PrintInstanceName(log,vins)  char *log;  VOID *vins;  {   INSTANCE_TYPE *ins;      ins = (INSTANCE_TYPE *) vins;   if (ins->garbage)     {      PrintCLIPS(log,"<stale instance [");      PrintCLIPS(log,ValueToString(ins->name));      PrintCLIPS(log,"]>");     }   else     {      PrintCLIPS(log,"[");      PrintCLIPS(log,ValueToString(GetFullInstanceName(ins)));      PrintCLIPS(log,"]");     }  }/***************************************************  NAME         : PrintInstanceLongForm  DESCRIPTION  : Used by kernel to print                 instance addresses  INPUTS       : 1) The logical output name                 2) A pointer to the instance  RETURNS      : Nothing useful  SIDE EFFECTS : Address of instance printed  NOTES        : None ***************************************************/static VOID PrintInstanceLongForm(log,vins)  char *log;  VOID *vins;  {   INSTANCE_TYPE *ins = (INSTANCE_TYPE *) vins;      if (InstanceAddressesToNames)     {      if (ins == &DummyInstance)        PrintCLIPS(log,"\"<Dummy Instance>\"");      else        {         PrintCLIPS(log,"[");         PrintCLIPS(log,ValueToString(GetFullInstanceName(ins)));         PrintCLIPS(log,"]");        }     }   else     {      if (AddressesToStrings)        PrintCLIPS(log,"\"");      if (ins == &DummyInstance)        PrintCLIPS(log,"<Dummy Instance>");      else if (ins->garbage)        {         PrintCLIPS(log,"<Stale Instance-");         PrintCLIPS(log,ValueToString(ins->name));         PrintCLIPS(log,">");        }      else        {         PrintCLIPS(log,"<Instance-");         PrintCLIPS(log,ValueToString(GetFullInstanceName(ins)));         PrintCLIPS(log,">");        }      if (AddressesToStrings)        PrintCLIPS(log,"\"");     }  }#if INSTANCE_PATTERN_MATCHING/*****************************************************  NAME         : NetworkModifyForSharedSlot  DESCRIPTION  : Performs a Rete network modify for                 all instances which contain a                 specific shared slot  INPUTS       : 1) The traversal id to use when                    recursively entering subclasses                    to prevent duplicate examinations                    of a class                 2) The class                 3) The descriptor for the shared slot  RETURNS      : Nothing useful  SIDE EFFECTS : Instances which contain the shared                 slot are filtered through the                 Rete network via a retract/assert  NOTES        : Assumes traversal id has been                 established *****************************************************/static VOID NetworkModifyForSharedSlot(sharedTraversalID,cls,sd)  int sharedTraversalID;  DEFCLASS *cls;  SLOT_DESC *sd;  {   INSTANCE_TYPE *ins;   register unsigned i;      /* ================================================      Make sure we haven't already examined this class      ================================================ */   if (TestTraversalID(cls->traversalRecord,sharedTraversalID))     return;   SetTraversalID(cls->traversalRecord,sharedTraversalID);        /* ===========================================      If the instances of this class contain the      shared slot, send update events to the Rete      network for all of its instances      =========================================== */   if ((sd->slotName->id > cls->maxSlotNameID) ? CLIPS_FALSE :       ((cls->slotNameMap[sd->slotName->id] == 0) ? CLIPS_FALSE :        (cls->instanceTemplate[cls->slotNameMap[sd->slotName->id] - 1] == sd)))     {      for (ins = cls->instanceList ; ins != NULL ; ins = ins->nxtClass)        ObjectNetworkAction(OBJECT_MODIFY,(VOID *) ins,(int) sd->slotName->id);     }      /* ==================================      Check the subclasses of this class      ================================== */   for (i = 0 ; i < cls->directSubclasses.classCount ; i++)     NetworkModifyForSharedSlot(sharedTraversalID,cls->directSubclasses.classArray[i],sd);  }  /***************************************************  NAME         : DecrementObjectBasisCount  DESCRIPTION  : Decrements the basis count of an                 object indicating that it is in                 use by the partial match of the                 currently executing rule  INPUTS       : The instance address  RETURNS      : Nothing useful  SIDE EFFECTS : Basis count decremented and                 basis copy (possibly) deleted  NOTES        : When the count goes to zero, the                 basis copy of the object (if any)                 is deleted. ***************************************************/static VOID DecrementObjectBasisCount(vins)  VOID *vins;  {   INSTANCE_TYPE *ins;   register int i;      ins = (INSTANCE_TYPE *) vins;   ins->header.busyCount--;   if (ins->header.busyCount == 0)     {      if (ins->garbage)        RemoveInstanceData(ins);      if (ins->cls->instanceSlotCount != 0)        {         for (i = 0 ; i < ins->cls->instanceSlotCount ; i++)           if (ins->basisSlots[i].value != NULL)             {              if (ins->basisSlots[i].desc->multiple)                MultifieldDeinstall(ins->basisSlots[i].value);              else                AtomDeinstall((int) ins->basisSlots[i].type,                              ins->basisSlots[i].value);             }         rm((VOID *) ins->basisSlots,            (int) (ins->cls->instanceSlotCount * sizeof(INSTANCE_SLOT)));         ins->basisSlots = NULL;        }     }  }  /***************************************************  NAME         : IncrementObjectBasisCount  DESCRIPTION  : Increments the basis count of an                 object indicating that it is in                 use by the partial match of the                 currently executing rule                                  If this the count was zero,                 allocate an array of extra                 instance slots for use by                 slot variables  INPUTS       : The instance address  RETURNS      : Nothing useful  SIDE EFFECTS : Basis count incremented  NOTES        : None ***************************************************/static VOID IncrementObjectBasisCount(vins)  VOID *vins;  {   INSTANCE_TYPE *ins;   register int i;      ins = (INSTANCE_TYPE *) vins;   if (ins->header.busyCount == 0)     {      if (ins->cls->instanceSlotCount != 0)        {         ins->basisSlots = (INSTANCE_SLOT *)                             gm2((int) (sizeof(INSTANCE_SLOT) * ins->cls->instanceSlotCount));         for (i = 0 ; i < ins->cls->instanceSlotCount ; i++)           {            ins->basisSlots[i].desc = ins->slotAddresses[i]->desc;            ins->basisSlots[i].value = NULL;           }        }     }   ins->header.busyCount++;  }  /***************************************************  NAME         : MatchObjectFunction  DESCRIPTION  : Filters an instance through the                 object pattern network                 Used for incremental resets in                 binary loads and run-time modules  INPUTS       : The instance  RETURNS      : Nothing useful  SIDE EFFECTS : Instance pattern-matched  NOTES        : None ***************************************************/static VOID MatchObjectFunction(vins)  VOID *vins;  {   ObjectNetworkAction(OBJECT_ASSERT,(INSTANCE_TYPE *) vins,-1);  }  /***************************************************  NAME         : NetworkSynchronized  DESCRIPTION  : Determines if state of instance is                 consistent with last push through                 pattern-matching network  INPUTS       : The instance  RETURNS      : CLIPS_TRUE if instance has not                 changed since last push through the                 Rete network, CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : None ***************************************************/static BOOLEAN NetworkSynchronized(vins)  VOID * vins;  {   return(((INSTANCE_TYPE *) vins)->reteSynchronized);  }#endif#endif  /***************************************************  NAME         :   DESCRIPTION  :   INPUTS       :   RETURNS      :   SIDE EFFECTS :   NOTES        :  ***************************************************/

⌨️ 快捷键说明

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