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

📄 objrtgen.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
      ======================== */   if (theNode->slotNumber < 0)     {      hack1.objectAddress = 1;      theItem->type = (short) (joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1);      theItem->value = AddBitMap((VOID *) &hack1,(int) sizeof(struct ObjectMatchVar1));      return;     }        /* ======================================      Access the entire contents of the slot      ====================================== */   if ((theNode->singleFieldsBefore == 0) &&       (theNode->singleFieldsAfter == 0) &&       (theNode->multiFieldsBefore == 0) &&       (theNode->multiFieldsAfter == 0) &&       ((theNode->withinMultifieldSlot == CLIPS_FALSE) ||        (theNode->type == MF_VARIABLE) ||        (theNode->type == MF_WILDCARD)))     {      hack1.allFields = 1;      hack1.whichSlot = (unsigned) theNode->slotNumber;      theItem->type = (short) (joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1);      theItem->value = AddBitMap((VOID *) &hack1,(int) sizeof(struct ObjectMatchVar1));      return;     }        /* =============================================================      Access a particular field(s) in a multifield slot pattern      containing at most one multifield variable and at least      one (or two if no multifield variables) single-field variable      ============================================================= */   if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) || (theNode->multiFieldsAfter == 0)))     {      hack2.whichSlot = (unsigned) theNode->slotNumber;      if (theNode->multiFieldsBefore == 0)        {         hack2.fromBeginning = 1;         hack2.beginningOffset = theNode->singleFieldsBefore;        }      else        {         hack2.fromEnd = 1;         hack2.endOffset = theNode->singleFieldsAfter;        }      theItem->type = (short) (joinReference ? OBJ_GET_SLOT_JNVAR2 : OBJ_GET_SLOT_PNVAR2);      theItem->value = AddBitMap((VOID *) &hack2,sizeof(struct ObjectMatchVar2));      return;     }      if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) &&        (theNode->multiFieldsAfter == 0))     {      hack2.whichSlot = (unsigned) theNode->slotNumber;      hack2.fromBeginning = 1;      hack2.fromEnd = 1;      hack2.beginningOffset = theNode->singleFieldsBefore;      hack2.endOffset = theNode->singleFieldsAfter;      theItem->type = (short) (joinReference ? OBJ_GET_SLOT_JNVAR2 : OBJ_GET_SLOT_PNVAR2);      theItem->value = AddBitMap((VOID *) &hack2,sizeof(struct ObjectMatchVar2));      return;     }        /* ==================================================      General slot field access using multifield markers      ================================================== */   hack1.whichSlot = (unsigned) theNode->slotNumber;   hack1.whichField = (unsigned) theNode->index;   theItem->type = (short) (joinReference ? OBJ_GET_SLOT_JNVAR1 : OBJ_GET_SLOT_PNVAR1);   theItem->value = AddBitMap((VOID *) &hack1,sizeof(struct ObjectMatchVar1));  }  /****************************************************************  NAME         : IsSimpleSlotVariable  DESCRIPTION  : Determines if a slot pattern variable                 references a single-field slot or a single-field                 in a multifield slot which does not require                 use of multifield markers                 (Object addresses are not simple variables)  INPUTS       : The intermediate parse node  RETURNS      : CLIPS_TRUE if the variable is simple,                 CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : None ****************************************************************/static BOOLEAN IsSimpleSlotVariable(node)  struct lhsParseNode *node;  {   if ((node->type == MF_WILDCARD) || (node->type == MF_VARIABLE))     return(CLIPS_FALSE);   if ((node->slotNumber < 0) ||       (node->slotNumber == ISA_ID) ||       (node->slotNumber == NAME_ID))     return(CLIPS_FALSE);   if (node->withinMultifieldSlot == CLIPS_FALSE)     return(CLIPS_TRUE);   if (node->multifieldSlot == CLIPS_TRUE)     return(CLIPS_FALSE);   if ((node->multiFieldsBefore == 0) || (node->multiFieldsAfter == 0))     return(CLIPS_TRUE);   return(CLIPS_FALSE);  }    /***************************************************************  NAME         : GenerateSlotComparisonTest  DESCRIPTION  : Generates pattern and join network                 expressions for comparing object                 pattern variables  INPUTS       : 1) A flag indicating if this is a                    pattern or join network test                 2) The intermediate parse node                    for the first variable                 3) The intermediate parse node                    for the second variable  RETURNS      : An expression for comparing the                 variables  SIDE EFFECTS : Expression and bitmaps generated  NOTES        : The following tests are generated                 for the following scenarios:                                  SF slot w/ SF slot: PN_1 or JN_1                 Example: (foo ?x) with (bar ?xy)                                  SF slot w/ SF reference in MF slot: PN_2 or JN_2                 Example: (foo ?x) (bar ? ?x ? ?)                                  SF reference w/ SF reference: PN_3 or JN_3                 Example: (foo ? ?x ?) and (bar ? ? ? ?x)                                  All other cases: EQ/NEQ general test                 Example: (foo $? ?x $?) and (bar ?x) ***************************************************************/static EXPRESSION *GenerateSlotComparisonTest(joinTest,selfNode,referringNode)  int joinTest;  struct lhsParseNode *selfNode,*referringNode;  {   EXPRESSION *exp;   struct ObjectCmpPNSingleSlotVars1 phack1;   struct ObjectCmpPNSingleSlotVars2 phack2;   struct ObjectCmpPNSingleSlotVars3 phack3;   struct ObjectCmpJoinSingleSlotVars1 jhack1;   struct ObjectCmpJoinSingleSlotVars2 jhack2;   struct ObjectCmpJoinSingleSlotVars3 jhack3;       /* =========================================================      If we are comparing two single-field slot variables that      don't require multifield markers for lookup, use      a quick comparison.  Otherwise, use a general eq/neq with      the pattern variable access routines      ========================================================= */   if (IsSimpleSlotVariable(selfNode) && IsSimpleSlotVariable(referringNode))     {      /* ==============================         Compare two single-field slots         ============================== */      if ((selfNode->withinMultifieldSlot == CLIPS_FALSE) &&          (referringNode->withinMultifieldSlot == CLIPS_FALSE))        {         ClearBitString((VOID *) &phack1,(int) sizeof(struct ObjectCmpPNSingleSlotVars1));         ClearBitString((VOID *) &jhack1,(int) sizeof(struct ObjectCmpJoinSingleSlotVars1));         if (selfNode->negated)           phack1.fail = jhack1.fail = 1;         else           phack1.pass = jhack1.pass = 1;         phack1.firstSlot = jhack1.firstSlot = (unsigned) selfNode->slotNumber;         phack1.secondSlot = jhack1.secondSlot = (unsigned) referringNode->slotNumber;         if (joinTest)           {            jhack1.firstPattern = (unsigned) selfNode->pattern;            jhack1.secondPattern = (unsigned) referringNode->pattern;            exp = GenConstant(OBJ_JN_CMP1,AddBitMap((VOID *) &jhack1,                                           (int) sizeof(struct ObjectCmpJoinSingleSlotVars1)));           }         else           exp = GenConstant(OBJ_PN_CMP1,AddBitMap((VOID *) &phack1,                                           (int) sizeof(struct ObjectCmpPNSingleSlotVars1)));        }      /* ============================================         Compare a single-field slot with a         single-field in a multifield slot (make sure         the multifield slot reference is first         ============================================ */      else if ((selfNode->withinMultifieldSlot == CLIPS_FALSE) ||               (referringNode->withinMultifieldSlot == CLIPS_FALSE))        {         ClearBitString((VOID *) &phack2,(int) sizeof(struct ObjectCmpPNSingleSlotVars2));         ClearBitString((VOID *) &jhack2,(int) sizeof(struct ObjectCmpJoinSingleSlotVars2));         if (selfNode->negated)           phack2.fail = jhack2.fail = 1;         else           phack2.pass = jhack2.pass = 1;         if (selfNode->withinMultifieldSlot == CLIPS_TRUE)           {            phack2.firstSlot = jhack2.firstSlot = (unsigned) selfNode->slotNumber;            phack2.secondSlot = jhack2.secondSlot = (unsigned) referringNode->slotNumber;            if (joinTest)              {               jhack2.firstPattern = (unsigned) selfNode->pattern;               jhack2.secondPattern = (unsigned) referringNode->pattern;              }            if (selfNode->multiFieldsBefore == 0)              {               phack2.fromBeginning = jhack2.fromBeginning = 1;               phack2.offset = jhack2.offset = selfNode->singleFieldsBefore;              }            else              phack2.offset = jhack2.offset = selfNode->singleFieldsAfter;           }         else           {            phack2.firstSlot = jhack2.firstSlot = (unsigned) referringNode->slotNumber;            phack2.secondSlot = jhack2.secondSlot = (unsigned) selfNode->slotNumber;            if (joinTest)              {               jhack2.firstPattern = (unsigned) referringNode->pattern;               jhack2.secondPattern = (unsigned) selfNode->pattern;              }            if (referringNode->multiFieldsBefore == 0)              {               phack2.fromBeginning = jhack2.fromBeginning = 1;               phack2.offset = jhack2.offset = referringNode->singleFieldsBefore;              }            else              phack2.offset = jhack2.offset = referringNode->singleFieldsAfter;           }         if (joinTest)           exp = GenConstant(OBJ_JN_CMP2,AddBitMap((VOID *) &jhack2,                                           (int) sizeof(struct ObjectCmpJoinSingleSlotVars2)));         else           exp = GenConstant(OBJ_PN_CMP2,AddBitMap((VOID *) &phack2,                                           (int) sizeof(struct ObjectCmpPNSingleSlotVars2)));        }            /* ===================================         Compare two single-field references         within multifield slots         =================================== */      else        {         ClearBitString((VOID *) &phack3,(int) sizeof(struct ObjectCmpPNSingleSlotVars3));         ClearBitString((VOID *) &jhack3,(int) sizeof(struct ObjectCmpJoinSingleSlotVars3));         if (selfNode->negated)           phack3.fail = jhack3.fail = 1;         else           phack3.pass = jhack3.pass = 1;         phack3.firstSlot = jhack3.firstSlot = (unsigned) selfNode->slotNumber;         phack3.secondSlot = jhack3.secondSlot = (unsigned) referringNode->slotNumber;         if (selfNode->multiFieldsBefore == 0)           {            phack3.firstFromBeginning = jhack3.firstFromBeginning = 1;            phack3.firstOffset = jhack3.firstOffset = selfNode->singleFieldsBefore;           }         else           phack3.firstOffset = jhack3.firstOffset = selfNode->singleFieldsAfter;         if (referringNode->multiFieldsBefore == 0)           {            phack3.secondFromBeginning = jhack3.secondFromBeginning = 1;            phack3.secondOffset = jhack3.secondOffset = referringNode->singleFieldsBefore;           }         else           phack3.secondOffset = jhack3.secondOffset = referringNode->singleFieldsAfter;         if (joinTest)           {            jhack3.firstPattern = (unsigned) selfNode->pattern;            jhack3.secondPattern = (unsigned) referringNode->pattern;            exp = GenConstant(OBJ_JN_CMP3,AddBitMap((VOID *) &jhack3,                                         (int) sizeof(struct ObjectCmpJoinSingleSlotVars3)));           }         else           exp = GenConstant(OBJ_PN_CMP3,AddBitMap((VOID *) &phack3,                                           (int) sizeof(struct ObjectCmpPNSingleSlotVars3)));        }     }        /* ==================================================      General comparison for multifield slot references,      references which require multifield markers, and      object addresses      ================================================== */   else     {      exp = GenConstant(FCALL,selfNode->negated ? PTR_NEQ : PTR_EQ);      exp->argList = GenConstant(0,NULL);      GenObjectGetVar(joinTest,exp->argList,selfNode);      exp->argList->nextArg = GenConstant(0,NULL);      GenObjectGetVar(joinTest,exp->argList->nextArg,referringNode);     }   return(exp);  }#endif/***************************************************  NAME         :   DESCRIPTION  :   INPUTS       :   RETURNS      :   SIDE EFFECTS :   NOTES        :  ***************************************************/

⌨️ 快捷键说明

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