📄 factgen.c
字号:
hack.whichSlot = theNode->slotNumber - 1; /*=============================*/ /* Return the argument bitmap. */ /*=============================*/ return(AddBitMap(&hack,sizeof(struct factGetVarPN2Call))); } /*************************************************************//* FactGetVarPN3: 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 during fact *//* pattern matching, so this retrieval mechanism is only *//* used by expressions in the pattern network. *//*************************************************************/static VOID *FactGetVarPN3(theNode) struct lhsParseNode *theNode; { struct factGetVarPN3Call hack; /*===================================================*/ /* Clear the bitmap for storing the argument values. */ /*===================================================*/ ClearBitString(&hack,sizeof(struct factGetVarPN3Call)); /*=======================================*/ /* Store the slot in the fact from which */ /* the value will be retrieved. */ /*=======================================*/ hack.whichSlot = theNode->slotNumber - 1; /*==============================================================*/ /* 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(AddBitMap(&hack,sizeof(struct factGetVarPN3Call))); } /*============================================================*/ /* 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(&hack,sizeof(struct factGetVarPN3Call))); } /*************************************************************//* FactPNVariableComparison: Generates an expression for use *//* in the fact pattern network to compare two variables of *//* the same name found in the same pattern. *//*************************************************************/ globle struct expr *FactPNVariableComparison(selfNode,referringNode) struct lhsParseNode *selfNode, *referringNode; { struct expr *top; struct factCompVarsPN1Call hack; /*===================================================*/ /* Clear the bitmap for storing the argument values. */ /*===================================================*/ ClearBitString(&hack,sizeof(struct factCompVarsPN1Call)); /*================================================================*/ /* If two single field slots of a deftemplate are being compared, */ /* then use the following specified variable comparison routine. */ /*================================================================*/ if ((selfNode->withinMultifieldSlot == CLIPS_FALSE) && (selfNode->slotNumber > 0) && (referringNode->withinMultifieldSlot == CLIPS_FALSE) && (referringNode->slotNumber > 0)) { hack.pass = 0; hack.fail = 0; hack.field1 = (unsigned int) selfNode->slotNumber - 1; hack.field2 = (unsigned int) referringNode->slotNumber - 1; if (selfNode->negated) hack.fail = 1; else hack.pass = 1; top = GenConstant(FACT_PN_CMP1,AddBitMap(&hack,sizeof(struct factCompVarsPN1Call))); } /*================================================================*/ /* Otherwise, use the eq function to compare the values retrieved */ /* by the appropriate get variable value functions. */ /*================================================================*/ else { if (selfNode->negated) top = GenConstant(FCALL,PTR_NEQ); else top = GenConstant(FCALL,PTR_EQ); top->argList = FactGenGetfield(selfNode); top->argList->nextArg = FactGenGetfield(referringNode); } /*======================================*/ /* Return the expression for performing */ /* the variable comparison. */ /*======================================*/ return(top); } /*********************************************************//* FactJNVariableComparison: Generates an expression for *//* use in the join network to compare two variables of *//* the same name found in different patterns. *//*********************************************************/globle struct expr *FactJNVariableComparison(selfNode,referringNode) struct lhsParseNode *selfNode, *referringNode; { struct expr *top; struct factCompVarsJN1Call hack1; struct factCompVarsJN2Call hack2; /*================================================================*/ /* If two single field slots of a deftemplate are being compared, */ /* then use the following specified variable comparison routine. */ /*================================================================*/ if ((selfNode->withinMultifieldSlot == CLIPS_FALSE) && (selfNode->slotNumber > 0) && (referringNode->withinMultifieldSlot == CLIPS_FALSE) && (referringNode->slotNumber > 0)) { ClearBitString(&hack1,sizeof(struct factCompVarsJN1Call)); hack1.pass = 0; hack1.fail = 0; hack1.slot1 = (unsigned int) selfNode->slotNumber - 1; hack1.pattern2 = (unsigned int) referringNode->pattern; if (referringNode->index < 0) hack1.slot2 = 0; else hack1.slot2 = (unsigned int) referringNode->slotNumber - 1; if (selfNode->negated) hack1.fail = 1; else hack1.pass = 1; top = GenConstant(FACT_JN_CMP1,AddBitMap(&hack1,sizeof(struct factCompVarsJN1Call))); } /*===============================================================*/ /* If two single field values are compared and either or both of */ /* them are contained in multifield slots (and the value can be */ /* accessed relative to either the beginning or end of the slot */ /* with no intervening multifield variables), then use the */ /* following specified variable comparison routine. */ /*===============================================================*/ else if ((selfNode->slotNumber > 0) && (selfNode->type == SF_VARIABLE) && ((selfNode->multiFieldsBefore == 0) || ((selfNode->multiFieldsBefore == 1) && (selfNode->multiFieldsAfter == 0))) && (referringNode->slotNumber > 0) && (referringNode->type == SF_VARIABLE) && ((referringNode->multiFieldsBefore == 0) || (referringNode->multiFieldsAfter == 0))) { ClearBitString(&hack2,sizeof(struct factCompVarsJN2Call)); hack2.pass = 0; hack2.fail = 0; hack2.slot1 = (unsigned int) selfNode->slotNumber - 1; hack2.pattern2 = (unsigned int) referringNode->pattern; hack2.slot2 = (unsigned int) referringNode->slotNumber - 1; if (selfNode->multiFieldsBefore == 0) { hack2.fromBeginning1 = 1; hack2.offset1 = selfNode->singleFieldsBefore; } else { hack2.fromBeginning1 = 0; hack2.offset1 = selfNode->singleFieldsAfter; } if (referringNode->multiFieldsBefore == 0) { hack2.fromBeginning2 = 1; hack2.offset2 = referringNode->singleFieldsBefore; } else { hack2.fromBeginning2 = 0; hack2.offset2 = referringNode->singleFieldsAfter; } if (selfNode->negated) hack2.fail = 1; else hack2.pass = 1; top = GenConstant(FACT_JN_CMP2,AddBitMap(&hack2,sizeof(struct factCompVarsJN2Call))); } /*===============================================================*/ /* Otherwise, use the equality or inequality function to compare */ /* the values returned by the appropriate join network variable */ /* retrieval function call. */ /*===============================================================*/ else { if (selfNode->negated) { top = GenConstant(FCALL,PTR_NEQ); } else { top = GenConstant(FCALL,PTR_EQ); } top->argList = FactGenGetvar(selfNode); top->argList->nextArg = FactGenGetvar(referringNode); } /*======================================*/ /* Return the expression for performing */ /* the variable comparison. */ /*======================================*/ return(top); } #endif /* (! RUN_TIME) && (! BLOAD_ONLY) */ #endif /* DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -