factgen.c

来自「clips源代码」· C语言 代码 · 共 1,258 行 · 第 1/4 页

C
1,258
字号
   /* A slot value of zero indicates that we */   /* want the pattern address returned.     */   /*========================================*/   if (theNode->slotNumber <= 0)     {      hack.factAddress = 1;      hack.allFields = 0;      hack.whichSlot = 0;      hack.whichField = 0;     }   /*=====================================================*/   /* A slot value greater than zero and a field value of */   /* zero indicate that we want the entire contents of   */   /* the slot whether it is a single field or multifield */   /* slot.                                               */   /*=====================================================*/   else if (theNode->index <= 0)     {      hack.factAddress = 0;      hack.allFields = 1;      hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);      hack.whichField = 0;     }   /*=====================================================*/   /* A slot value, m, and a field value, n, both greater */   /* than zero indicate that we want the nth field of    */   /* the mth slot.                                       */   /*=====================================================*/   else     {      hack.factAddress = 0;      hack.allFields = 0;      hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);      hack.whichField = (unsigned short) (theNode->index - 1);     }   /*=============================*/   /* Return the argument bitmap. */   /*=============================*/   return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN1Call)));  }/**************************************************************//* FactGetVarJN2: Creates the arguments for the routine which *//*   retrieves a variable's value from a single field slot of *//*   a fact. The retrieval relies on information stored in a  *//*   partial match, so this retrieval mechanism is used by    *//*   expressions in the join network or from the RHS of a     *//*   rule.                                                    *//**************************************************************/static void *FactGetVarJN2(  void *theEnv,  struct lhsParseNode *theNode,  int side)  {   struct factGetVarJN2Call hack;   /*===================================================*/   /* Clear the bitmap for storing the argument values. */   /*===================================================*/   ClearBitString(&hack,sizeof(struct factGetVarJN2Call));   /*=====================================================*/   /* Store the position in the partial match from which  */   /* the fact will be retrieved and the slot in the fact */   /* from which the value will be retrieved.             */   /*=====================================================*/   hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);   if (side == LHS)     {       hack.lhs = 1;       hack.whichPattern = (unsigned short) theNode->joinDepth;     }   else if (side == RHS)     {       hack.rhs = 1;       hack.whichPattern = (unsigned short) 0;     }   else if (side == NESTED_RHS)     {       hack.rhs = 1;       hack.whichPattern = (unsigned short) theNode->joinDepth;     }   else     { hack.whichPattern = (unsigned short) theNode->joinDepth; }   /*=============================*/   /* Return the argument bitmap. */   /*=============================*/   return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN2Call)));  }/*************************************************************//* FactGetVarJN3: Creates the arguments for the routine for  *//*   retrieving a variable's value from a multifield slot of *//*   a fact. For this routine, the variable's value must be  *//*   from a multifield slot that contains at most one        *//*   multifield variable or contains no multifield variables *//*   before the variable's value to be retrieved. The        *//*   retrieval relies on information stored in a partial     *//*   match, so this retrieval mechanism is used by           *//*   expressions in the join network or from the RHS of a    *//*   rule.                                                   *//*************************************************************/static void *FactGetVarJN3(  void *theEnv,  struct lhsParseNode *theNode,  int side)  {   struct factGetVarJN3Call hack;   /*===================================================*/   /* Clear the bitmap for storing the argument values. */   /*===================================================*/   ClearBitString(&hack,sizeof(struct factGetVarJN3Call));   /*=====================================================*/   /* Store the position in the partial match from which  */   /* the fact will be retrieved and the slot in the fact */   /* from which the value will be retrieved.             */   /*=====================================================*/   hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);   if (side == LHS)     {       hack.lhs = 1;       hack.whichPattern = (unsigned short) theNode->joinDepth;     }   else if (side == RHS)     {       hack.rhs = 1;       hack.whichPattern = (unsigned short) 0;     }   else if (side == NESTED_RHS)     {       hack.rhs = 1;       hack.whichPattern = (unsigned short) theNode->joinDepth;     }   else     { hack.whichPattern = (unsigned short) theNode->joinDepth; }   /*==============================================================*/   /* If a single field variable value is being retrieved, then... */   /*==============================================================*/   if ((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE))     {      /*=========================================================*/      /* If no multifield values occur before the variable, then */      /* the variable's value can be retrieved based on its      */      /* offset from the beginning of the slot's value           */      /* regardless of the number of multifield variables or     */      /* wildcards following the variable being retrieved.       */      /*=========================================================*/      if (theNode->multiFieldsBefore == 0)        {         hack.fromBeginning = 1;         hack.fromEnd = 0;         hack.beginOffset = theNode->singleFieldsBefore;         hack.endOffset = 0;        }      /*===============================================*/      /* Otherwise the variable is retrieved based its */      /* position relative to the end of the slot.     */      /*===============================================*/      else        {         hack.fromBeginning = 0;         hack.fromEnd = 1;         hack.beginOffset = 0;         hack.endOffset = theNode->singleFieldsAfter;        }      /*=============================*/      /* Return the argument bitmap. */      /*=============================*/      return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN3Call)));     }   /*============================================================*/   /* A multifield variable value is being retrieved. This means */   /* that there are no other multifield variables or wildcards  */   /* in the slot. The multifield value is retrieved by storing  */   /* the number of single field values which come before and    */   /* after the multifield value. The multifield value can then  */   /* be retrieved based on the length of the value in the slot  */   /* and the number of single field values which must occur     */   /* before and after the multifield value.                     */   /*============================================================*/   hack.fromBeginning = 1;   hack.fromEnd = 1;   hack.beginOffset = theNode->singleFieldsBefore;   hack.endOffset = theNode->singleFieldsAfter;   /*=============================*/   /* Return the argument bitmap. */   /*=============================*/   return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarJN3Call)));  }/**************************************************************//* FactGetVarPN1: Creates the arguments for the most general  *//*   routine for retrieving a variable's value from the slot  *//*   of a fact. The retrieval relies on information stored    *//*   during fact pattern matching, so this retrieval          *//*   mechanism is only used by expressions in the pattern     *//*   network.                                                 *//**************************************************************/static void *FactGetVarPN1(  void *theEnv,  struct lhsParseNode *theNode)  {   struct factGetVarPN1Call hack;   /*===================================================*/   /* Clear the bitmap for storing the argument values. */   /*===================================================*/   ClearBitString(&hack,sizeof(struct factGetVarPN1Call));   /*========================================*/   /* A slot value of zero indicates that we */   /* want the pattern address returned.     */   /*========================================*/   if (theNode->slotNumber <= 0)     {      hack.factAddress = 1;      hack.allFields = 0;      hack.whichSlot = 0;      hack.whichField = 0;     }   /*=====================================================*/   /* A slot value greater than zero and a field value of */   /* zero indicate that we want the entire contents of   */   /* the slot whether it is a single field or multifield */   /* slot.                                               */   /*=====================================================*/   else if (theNode->index <= 0)     {      hack.factAddress = 0;      hack.allFields = 1;      hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);      hack.whichField = 0;     }   /*=============================================*/   /* A slot value, m, and a field value, n, both */   /* greater than zero indicate that we want the */   /* nth field of the mth slot.                  */   /*=============================================*/   else     {      hack.factAddress = 0;      hack.allFields = 0;      hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);      hack.whichField = (unsigned short) (theNode->index - 1);     }   /*=============================*/   /* Return the argument bitmap. */   /*=============================*/   return(AddBitMap(theEnv,&hack,sizeof(struct factGetVarPN1Call)));  }/***************************************************************//* FactGetVarPN2: Creates the arguments for the routine which  *//*   retrieves a variable's value from a single field slot of  *//*   a fact. The retrieval relies on information stored during *//*   fact pattern matching, so this retrieval mechanism is     *//*   only used by expressions in the pattern network.          *//***************************************************************/static void *FactGetVarPN2(  void *theEnv,  struct lhsParseNode *theNode)  {   struct factGetVarPN2Call hack;   /*===================================================*/   /* Clear the bitmap for storing the argument values. */   /*===================================================*/   ClearBitString(&hack,sizeof(struct factGetVarPN2Call));   /*=======================================*/   /* Store the slot in the fact from which */   /* the value will be retrieved.          */   /*=======================================*/   hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);   /*=============================*/   /* Return the argument bitmap. */

⌨️ 快捷键说明

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