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

📄 modulpsr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*=============================================================*/   SavePPBuffer(" ");   GetToken(readSource,theToken);      if (theToken->type == SF_VARIABLE)     {      /*==============================*/      /* Check to see if the variable */      /* is either ?ALL or ?NONE.     */      /*==============================*/            if (strcmp(ValueToString(theToken->value),"ALL") == 0)        {         newPort = (struct portItem *) get_struct(portItem);         newPort->moduleName = moduleName;         newPort->constructType = theConstruct;         newPort->constructName = NULL;         newPort->next = NULL;        }      else if (strcmp(ValueToString(theToken->value),"NONE") == 0)        { newPort = NULL; }      else        {         SyntaxErrorMessage(errorMessage);         return(CLIPS_TRUE);        }              /*=======================================================*/      /* The export/import specification must end with a right */      /* parenthesis after ?ALL or ?NONE at this point.        */      /*=======================================================*/            GetToken(readSource,theToken);            if (theToken->type != RPAREN)        {         if (newPort != NULL) rtn_struct(portItem,newPort);         PPBackup();         SavePPBuffer(" ");         SavePPBuffer(theToken->printForm);         SyntaxErrorMessage(errorMessage);         return(CLIPS_TRUE);        }              /*=====================================*/      /* Add the new specification to either */      /* the import or export list.          */      /*=====================================*/            if (newPort != NULL)         {         if (importModule != NULL)           {            newPort->next = newModule->importList;            newModule->importList = newPort;           }         else           {            newPort->next = newModule->exportList;            newModule->exportList = newPort;           }        }            /*============================================*/      /* Return FALSE to indicate the import/export */      /* specification was successfully parsed.     */      /*============================================*/            return(CLIPS_FALSE);     }        /*============================================*/   /* There must be at least one named construct */   /* in the import/export list at this point.   */   /*============================================*/      if (theToken->type == RPAREN)     {      SyntaxErrorMessage(errorMessage);      return(CLIPS_TRUE);     }        /*=====================================*/   /* Read in the list of imported items. */   /*=====================================*/            while (theToken->type != RPAREN)     {            if (theToken->type != thePortConstruct->typeExpected)        {         SyntaxErrorMessage(errorMessage);         return(CLIPS_TRUE);        }            /*========================================*/      /* Create the data structure to represent */      /* the import/export specification for    */      /* the named construct.                   */      /*========================================*/            newPort = (struct portItem *) get_struct(portItem);      newPort->moduleName = moduleName;      newPort->constructType = theConstruct;      newPort->constructName = (SYMBOL_HN *) theToken->value;            /*=====================================*/      /* Add the new specification to either */      /* the import or export list.          */      /*=====================================*/      if (importModule != NULL)        {         newPort->next = newModule->importList;         newModule->importList = newPort;        }      else        {         newPort->next = newModule->exportList;         newModule->exportList = newPort;        }           /*===================================*/      /* Move on to the next import/export */      /* specification.                    */      /*===================================*/            SavePPBuffer(" ");      GetToken(readSource,theToken);     }    /*=============================*/   /* Fix up pretty print buffer. */   /*=============================*/      PPBackup();   PPBackup();   SavePPBuffer(")");      /*============================================*/   /* Return FALSE to indicate the import/export */   /* specification was successfully parsed.     */   /*============================================*/   return(CLIPS_FALSE);  }  /*************************************************************//* ValidPortConstructItem: Returns TRUE if a given construct *//*   name is in the list of constructs which can be exported *//*   and imported, otherwise FALSE is returned.              *//*************************************************************/globle struct portConstructItem *ValidPortConstructItem(theName)  char *theName;  {      struct portConstructItem *theItem;      for (theItem = ListOfPortConstructItems;         theItem != NULL;         theItem = theItem->next)     { if (strcmp(theName,theItem->constructName) == 0) return(theItem); }        return(NULL);  }   /***********************************************************//* FindMultiImportConflict: Determines if a module imports *//*   the same named construct from more than one module    *//*   (i.e. an ambiguous reference which is not allowed).   *//***********************************************************/static int FindMultiImportConflict(theModule)  struct defmodule *theModule;  {   struct defmodule *testModule;   int count;   struct portConstructItem *thePCItem;   struct construct *theConstruct;   VOID *theCItem;         /*==========================*/   /* Save the current module. */   /*==========================*/      SaveCurrentModule();      /*============================*/   /* Loop through every module. */   /*============================*/      for (testModule = (struct defmodule *) GetNextDefmodule(NULL);        testModule != NULL;        testModule = (struct defmodule *) GetNextDefmodule(testModule))     {      /*========================================*/      /* Loop through every construct type that */      /* can be imported/exported by a module.  */      /*========================================*/            for (thePCItem = ListOfPortConstructItems;            thePCItem != NULL;            thePCItem = thePCItem->next)         {         SetCurrentModule((VOID *) testModule);                  /*=====================================================*/         /* Loop through every construct of the specified type. */         /*=====================================================*/                  theConstruct = FindConstruct(thePCItem->constructName);                  for (theCItem = (*theConstruct->getNextItemFunction)(NULL);              theCItem != NULL;              theCItem = (*theConstruct->getNextItemFunction)(theCItem))            {                  /*===============================================*/             /* Check to see if the specific construct in the */             /* module can be imported with more than one     */             /* reference into the module we're examining for */             /* ambiguous import  specifications.             */             /*===============================================*/             SetCurrentModule((VOID *) theModule);             FindImportedConstruct(thePCItem->constructName,NULL,                                   ValueToString((*theConstruct->getConstructNameFunction)(theCItem)),                                   &count,CLIPS_FALSE,NULL);             if (count > 1)               {                ImportExportConflictMessage("defmodule",GetDefmoduleName(theModule),                                            thePCItem->constructName,                                            ValueToString((*theConstruct->getConstructNameFunction)(theCItem)));                RestoreCurrentModule();                return(CLIPS_TRUE);               }                            SetCurrentModule((VOID *) testModule);            }        }     }        /*=============================*/   /* Restore the current module. */   /*=============================*/      RestoreCurrentModule();      /*=======================================*/   /* Return FALSE to indicate no ambiguous */   /* references were found.                */   /*=======================================*/      return(CLIPS_FALSE);  }/******************************************************//* NotExportedErrorMessage: Generalized error message *//*  for indicating that a construct type or specific  *//*  named construct is not exported.                  *//******************************************************/static VOID NotExportedErrorMessage(theModule,theConstruct,theName)  char *theModule;  char *theConstruct;  char *theName;  {   PrintErrorID("MODULPSR",1,CLIPS_TRUE);   PrintCLIPS(WERROR,"Module ");   PrintCLIPS(WERROR,theModule);   PrintCLIPS(WERROR," does not export ");      if (theConstruct == NULL) PrintCLIPS(WERROR,"any constructs");   else if (theName == NULL)     {      PrintCLIPS(WERROR,"any ");      PrintCLIPS(WERROR,theConstruct);      PrintCLIPS(WERROR," constructs");     }   else     {      PrintCLIPS(WERROR,"the ");      PrintCLIPS(WERROR,theConstruct);      PrintCLIPS(WERROR," ");      PrintCLIPS(WERROR,theName);     }      PrintCLIPS(WERROR,".\n");  }/*************************************************************//* FindImportExportConflict: Determines if the definition of *//*   a construct would cause an import/export conflict. The  *//*   construct is not yet defined when this function is      *//*   called. TRUE is returned if an import/export conflicts  *//*   is found, otherwise FALSE is returned.                  *//*************************************************************/globle int FindImportExportConflict(constructName,matchModule,findName)  char *constructName;  struct defmodule *matchModule;  char *findName;  {   struct defmodule *theModule;   struct moduleItem *theModuleItem;   int count;      /*===========================================================*/   /* If the construct type can't be imported or exported, then */   /* it's not possible to have an import/export conflict.      */   /*===========================================================*/      if (ValidPortConstructItem(constructName) == NULL) return(CLIPS_FALSE);      /*============================================*/   /* There module name should already have been */   /* separated fromthe construct's name.        */   /*============================================*/      if (FindModuleSeparator(findName)) return(CLIPS_FALSE);      /*===============================================================*/   /* The construct must be capable of being stored within a module */   /* (this test should never fail). The construct must also have   */   /* a find function associated with it so we can actually look    */   /* for import/export conflicts.                                  */   /*===============================================================*/      if ((theModuleItem = FindModuleItem(constructName)) == NULL) return(CLIPS_FALSE);   if (theModuleItem->findFunction == NULL) return(CLIPS_FALSE);           /*==========================*/   /* Save the current module. */   /*==========================*/      SaveCurrentModule();      /*================================================================*/   /* Look at each module and count each definition of the specified */   /* construct which is visible to the module. If more than one     */   /* definition is visible, then an import/export conflict exists   */   /* and TRUE is returned.                                          */   /*================================================================*/      for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {      SetCurrentModule((VOID *) theModule);               FindImportedConstruct(constructName,NULL,findName,&count,CLIPS_TRUE,matchModule);      if (count > 1)        {         RestoreCurrentModule();         return(CLIPS_TRUE);        }     }        /*==========================================*/   /* Restore the current module. No conflicts */   /* were detected so FALSE is returned.      */   /*==========================================*/      RestoreCurrentModule();   return(CLIPS_FALSE);  }#endif /* DEFMODULE_CONSTRUCT && (! RUN_TIME) && (! BLOAD_ONLY) */

⌨️ 快捷键说明

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