factgen.c

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

C
1,258
字号
/*******************************************************/globle struct expr *FactGenGetfield(  void *theEnv,  struct lhsParseNode *theNode)  {   /*===================================================*/   /* Generate call to retrieve single field slot value */   /* or the fact relation name.                        */   /*===================================================*/   if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == FALSE))     { return(GenConstant(theEnv,FACT_PN_VAR2,FactGetVarPN2(theEnv,theNode))); }   /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/   if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE) || ConstantType(theNode->type)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))     { return(GenConstant(theEnv,FACT_PN_VAR3,FactGetVarPN3(theEnv,theNode))); }   if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&        (theNode->multiFieldsBefore == 0) && (theNode->multiFieldsAfter == 0))     { return(GenConstant(theEnv,FACT_PN_VAR3,FactGetVarPN3(theEnv,theNode))); }   /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/   return(GenConstant(theEnv,FACT_PN_VAR1,FactGetVarPN1(theEnv,theNode)));  }/**************************************************//* FactGenGetvar: Generates an expression for use *//*   in the join network that retrieves a value   *//*   from a single or multifield slot of a fact.  *//**************************************************/globle struct expr *FactGenGetvar(  void *theEnv,  struct lhsParseNode *theNode,  int side)  {   /*====================================================*/   /* Generate call to retrieve single field slot value. */   /*====================================================*/   if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == FALSE))     { return(GenConstant(theEnv,FACT_JN_VAR2,FactGetVarJN2(theEnv,theNode,side))); }   /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/   if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))     { return(GenConstant(theEnv,FACT_JN_VAR3,FactGetVarJN3(theEnv,theNode,side))); }   if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) &&       (theNode->multiFieldsAfter == 0))     { return(GenConstant(theEnv,FACT_JN_VAR3,FactGetVarJN3(theEnv,theNode,side))); }   /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/   return(GenConstant(theEnv,FACT_JN_VAR1,FactGetVarJN1(theEnv,theNode,side)));  }/**************************************************************//* FactGenCheckLength: Generates an expression for use in the *//*   fact pattern network that determines if the value of a   *//*   multifield slot contains enough fields to satisfy the    *//*   number of pattern matching constaints. For example, the  *//*   slot constraints (foo ?x a $? ?y) couldn't be matched    *//*   unless the foo slot contained at least 3 fields.         *//**************************************************************/globle struct expr *FactGenCheckLength(  void *theEnv,  struct lhsParseNode *theNode)  {   struct factCheckLengthPNCall hack;   /*===================================================*/   /* If the slot contains no single field constraints, */   /* then a length test is not necessary.              */   /*===================================================*/   if ((theNode->singleFieldsAfter == 0) &&       (theNode->type != SF_VARIABLE) &&       (theNode->type != SF_WILDCARD))     { return(NULL); }   /*=======================================*/   /* Initialize the length test arguments. */   /*=======================================*/   ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));   hack.whichSlot = (unsigned short) (theNode->slotNumber - 1);   /*============================================*/   /* If the slot has no multifield constraints, */   /* then the length must match exactly.        */   /*============================================*/   if ((theNode->type != MF_VARIABLE) &&       (theNode->type != MF_WILDCARD) &&       (theNode->multiFieldsAfter == 0))     { hack.exactly = 1; }   else     { hack.exactly = 0; }   /*============================================*/   /* The minimum length is the number of single */   /* field constraints contained in the slot.   */   /*============================================*/   if ((theNode->type == SF_VARIABLE) || (theNode->type == SF_WILDCARD))     { hack.minLength = (unsigned short) (1 + theNode->singleFieldsAfter); }   else     { hack.minLength = theNode->singleFieldsAfter; }   /*========================================================*/   /* Generate call to test the length of a multifield slot. */   /*========================================================*/   return(GenConstant(theEnv,FACT_SLOT_LENGTH,AddBitMap(theEnv,&hack,sizeof(struct factCheckLengthPNCall))));  }/**************************************************************//* FactGenCheckZeroLength: Generates an expression for use in *//*   the fact pattern network that determines if the value of *//*   a multifield slot is a zero length multifield value.     *//**************************************************************/globle struct expr *FactGenCheckZeroLength(  void *theEnv,  unsigned theSlot)  {   struct factCheckLengthPNCall hack;   ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));   hack.whichSlot = (unsigned short) (theSlot - 1);   hack.exactly = 1;   hack.minLength = 0;   return(GenConstant(theEnv,FACT_SLOT_LENGTH,AddBitMap(theEnv,&hack,sizeof(struct factCheckLengthPNCall))));  }/*********************************************************************//* FactReplaceGetvar: Replaces a variable reference in an expression *//*   with a function call to retrieve the variable using the join    *//*   network variable access functions for facts.                    *//*********************************************************************/globle void FactReplaceGetvar(  void *theEnv,  struct expr *theItem,  struct lhsParseNode *theNode,  int side)  {   /*====================================================*/   /* Generate call to retrieve single field slot value. */   /*====================================================*/   if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == FALSE))     {      theItem->type = FACT_JN_VAR2;      theItem->value = FactGetVarJN2(theEnv,theNode,side);      return;     }   /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/   if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))     {      theItem->type = FACT_JN_VAR3;      theItem->value = FactGetVarJN3(theEnv,theNode,side);      return;     }   if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) &&       (theNode->multiFieldsAfter == 0))     {      theItem->type = FACT_JN_VAR3;      theItem->value = FactGetVarJN3(theEnv,theNode,side);      return;     }   /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/   theItem->type = FACT_JN_VAR1;   theItem->value = FactGetVarJN1(theEnv,theNode,side);  }/***********************************************************************//* FactReplaceGetfield: Replaces a variable reference in an expression *//*   with a function call to retrieve the variable using the pattern   *//*   network variable access functions for facts.                      *//***********************************************************************/globle void FactReplaceGetfield(  void *theEnv,  struct expr *theItem,  struct lhsParseNode *theNode)  {   /*====================================================*/   /* Generate call to retrieve single field slot value. */   /*====================================================*/   if (theNode->withinMultifieldSlot == FALSE)     {      theItem->type = FACT_PN_VAR2;      theItem->value = FactGetVarPN2(theEnv,theNode);      return;     }   /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/   if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))     {      theItem->type = FACT_PN_VAR3;      theItem->value = FactGetVarPN3(theEnv,theNode);      return;     }   if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) &&       (theNode->multiFieldsAfter == 0))     {      theItem->type = FACT_PN_VAR3;      theItem->value = FactGetVarPN3(theEnv,theNode);      return;     }   /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/   theItem->type = FACT_PN_VAR1;   theItem->value = FactGetVarPN1(theEnv,theNode);  }/*************************************************************//* FactGetVarJN1: 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   *//*   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 *FactGetVarJN1(  void *theEnv,  struct lhsParseNode *theNode,  int side)  {   struct factGetVarJN1Call hack;   /*===================================================*/   /* Clear the bitmap for storing the argument values. */   /*===================================================*/   ClearBitString(&hack,sizeof(struct factGetVarJN1Call));   /*=========================================*/   /* Store the position in the partial match */   /* from which the fact will be retrieved.  */   /*=========================================*/   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; }        /*========================================*/

⌨️ 快捷键说明

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