?? factgen.c
字號:
/*=============================*/ return(AddBitMap(theEnv,&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( void *theEnv, 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 = (unsigned short) (theNode->slotNumber - 1); /*==============================================================*/ /* If a single field variable value is being retrieved, then... */ /*==============================================================*/ if ((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE) || ConstantType(theNode->type)) { /*=========================================================*/ /* 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(theEnv,&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(theEnv,&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( void *theEnv, struct lhsParseNode *selfNode, struct lhsParseNode *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 == FALSE) && (selfNode->slotNumber > 0) && (referringNode->withinMultifieldSlot == 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(theEnv,FACT_PN_CMP1,AddBitMap(theEnv,&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(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); else top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); top->argList = FactGenGetfield(theEnv,selfNode); top->argList->nextArg = FactGenGetfield(theEnv,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( void *theEnv, struct lhsParseNode *selfNode, struct lhsParseNode *referringNode, int nandJoin) { 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 == FALSE) && (selfNode->slotNumber > 0) && (referringNode->withinMultifieldSlot == FALSE) && (referringNode->slotNumber > 0)) { ClearBitString(&hack1,sizeof(struct factCompVarsJN1Call)); hack1.pass = 0; hack1.fail = 0; hack1.slot1 = (unsigned int) selfNode->slotNumber - 1; if (nandJoin) { hack1.pattern1 = selfNode->joinDepth; } else { hack1.pattern1 = 0; } hack1.p1rhs = TRUE; if (nandJoin && (selfNode->beginNandDepth == referringNode->beginNandDepth)) { hack1.p2rhs = TRUE; } else { hack1.p2lhs = TRUE; } hack1.pattern2 = (unsigned int) referringNode->joinDepth; 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(theEnv,FACT_JN_CMP1,AddBitMap(theEnv,&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; if (nandJoin) { hack2.pattern1 = selfNode->joinDepth; } else { hack2.pattern1 = 0; } hack2.p1rhs = TRUE; if (nandJoin && (selfNode->beginNandDepth == referringNode->beginNandDepth)) { hack2.p2rhs = TRUE; } else { hack2.p2lhs = TRUE; } hack2.pattern2 = (unsigned int) referringNode->joinDepth; 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(theEnv,FACT_JN_CMP2,AddBitMap(theEnv,&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(theEnv,FCALL,ExpressionData(theEnv)->PTR_NEQ); } else { top = GenConstant(theEnv,FCALL,ExpressionData(theEnv)->PTR_EQ); } if (nandJoin) { top->argList = FactGenGetvar(theEnv,selfNode,NESTED_RHS); } else { top->argList = FactGenGetvar(theEnv,selfNode,RHS); } if (nandJoin && (selfNode->beginNandDepth == referringNode->beginNandDepth)) { top->argList->nextArg = FactGenGetvar(theEnv,referringNode,NESTED_RHS); } else { top->argList->nextArg = FactGenGetvar(theEnv,referringNode,LHS); } } /*======================================*/ /* 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 + -