?? insmoddp.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.24 05/17/06 */ /* */ /* INSTANCE MODIFY AND DUPLICATE MODULE */ /*******************************************************//*************************************************************//* Purpose: Instance modify and duplicate support routines *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* *//* Revision History: *//* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 *//* *//* Changed name of variable exp to theExp *//* because of Unix compiler warnings of shadowed *//* definitions. *//* *//* 6.24: Converted INSTANCE_PATTERN_MATCHING to *//* DEFRULE_CONSTRUCT. *//* *//*************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if OBJECT_SYSTEM#if DEFRULE_CONSTRUCT#include "network.h"#include "objrtmch.h"#endif#include "argacces.h"#include "memalloc.h"#include "envrnmnt.h"#include "extnfunc.h"#include "inscom.h"#include "insfun.h"#include "insmngr.h"#include "inspsr.h"#include "miscfun.h"#include "msgcom.h"#include "msgfun.h"#include "msgpass.h"#include "prccode.h"#include "router.h"#define _INSMODDP_SOURCE_#include "insmoddp.h"/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */static DATA_OBJECT *EvaluateSlotOverrides(void *,EXPRESSION *,int *,int *);static void DeleteSlotOverrideEvaluations(void *,DATA_OBJECT *,int);static void ModifyMsgHandlerSupport(void *,DATA_OBJECT *,int);static void DuplicateMsgHandlerSupport(void *,DATA_OBJECT *,int);/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */#if (! RUN_TIME)/*************************************************** NAME : SetupInstanceModDupCommands DESCRIPTION : Defines function interfaces for modify- and duplicate- instance functions INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Functions defined to KB NOTES : None ***************************************************/globle void SetupInstanceModDupCommands( void *theEnv) {#if DEFRULE_CONSTRUCT EnvDefineFunction2(theEnv,"modify-instance",'u',PTIEF InactiveModifyInstance,"InactiveModifyInstance",NULL); EnvDefineFunction2(theEnv,"active-modify-instance",'u',PTIEF ModifyInstance,"ModifyInstance",NULL); AddFunctionParser(theEnv,"active-modify-instance",ParseInitializeInstance); EnvDefineFunction2(theEnv,"message-modify-instance",'u',PTIEF InactiveMsgModifyInstance, "InactiveMsgModifyInstance",NULL); EnvDefineFunction2(theEnv,"active-message-modify-instance",'u',PTIEF MsgModifyInstance, "MsgModifyInstance",NULL); AddFunctionParser(theEnv,"active-message-modify-instance",ParseInitializeInstance); EnvDefineFunction2(theEnv,"duplicate-instance",'u', PTIEF InactiveDuplicateInstance,"InactiveDuplicateInstance",NULL); EnvDefineFunction2(theEnv,"active-duplicate-instance",'u',PTIEF DuplicateInstance,"DuplicateInstance",NULL); AddFunctionParser(theEnv,"active-duplicate-instance",ParseInitializeInstance); EnvDefineFunction2(theEnv,"message-duplicate-instance",'u',PTIEF InactiveMsgDuplicateInstance, "InactiveMsgDuplicateInstance",NULL); EnvDefineFunction2(theEnv,"active-message-duplicate-instance",'u',PTIEF MsgDuplicateInstance, "MsgDuplicateInstance",NULL); AddFunctionParser(theEnv,"active-message-duplicate-instance",ParseInitializeInstance);#else EnvDefineFunction2(theEnv,"modify-instance",'u',PTIEF ModifyInstance,"ModifyInstance",NULL); EnvDefineFunction2(theEnv,"message-modify-instance",'u',PTIEF MsgModifyInstance, "MsgModifyInstance",NULL); EnvDefineFunction2(theEnv,"duplicate-instance",'u',PTIEF DuplicateInstance,"DuplicateInstance",NULL); EnvDefineFunction2(theEnv,"message-duplicate-instance",'u',PTIEF MsgDuplicateInstance, "MsgDuplicateInstance",NULL);#endif EnvDefineFunction2(theEnv,"(direct-modify)",'u',PTIEF DirectModifyMsgHandler,"DirectModifyMsgHandler",NULL); EnvDefineFunction2(theEnv,"(message-modify)",'u',PTIEF MsgModifyMsgHandler,"MsgModifyMsgHandler",NULL); EnvDefineFunction2(theEnv,"(direct-duplicate)",'u',PTIEF DirectDuplicateMsgHandler,"DirectDuplicateMsgHandler",NULL); EnvDefineFunction2(theEnv,"(message-duplicate)",'u',PTIEF MsgDuplicateMsgHandler,"MsgDuplicateMsgHandler",NULL); AddFunctionParser(theEnv,"modify-instance",ParseInitializeInstance); AddFunctionParser(theEnv,"message-modify-instance",ParseInitializeInstance); AddFunctionParser(theEnv,"duplicate-instance",ParseInitializeInstance); AddFunctionParser(theEnv,"message-duplicate-instance",ParseInitializeInstance); }#endif/************************************************************* NAME : ModifyInstance DESCRIPTION : Modifies slots of an instance via the direct-modify message INPUTS : The address of the result value RETURNS : Nothing useful SIDE EFFECTS : Slot updates performed directly NOTES : H/L Syntax: (modify-instance <instance> <slot-override>*) *************************************************************/globle void ModifyInstance( void *theEnv, DATA_OBJECT *result) { INSTANCE_TYPE *ins; EXPRESSION theExp; DATA_OBJECT *overrides; int oldOMDMV,overrideCount,error; /* =========================================== The slot-overrides need to be evaluated now to resolve any variable references before a new frame is pushed for message-handler execution =========================================== */ overrides = EvaluateSlotOverrides(theEnv,GetFirstArgument()->nextArg, &overrideCount,&error); if (error) { SetpType(result,SYMBOL); SetpValue(result,EnvFalseSymbol(theEnv)); return; } /* ================================== Find the instance and make sure it wasn't deleted by the overrides ================================== */ ins = CheckInstance(theEnv,ValueToString(ExpressionFunctionCallName(EvaluationData(theEnv)->CurrentExpression))); if (ins == NULL) { SetpType(result,SYMBOL); SetpValue(result,EnvFalseSymbol(theEnv)); DeleteSlotOverrideEvaluations(theEnv,overrides,overrideCount); return; } /* ====================================== We are passing the slot override expression information along to whatever message-handler implements the modify ====================================== */ theExp.type = EXTERNAL_ADDRESS; theExp.value = (void *) overrides; theExp.argList = NULL; theExp.nextArg = NULL; oldOMDMV = InstanceData(theEnv)->ObjectModDupMsgValid; InstanceData(theEnv)->ObjectModDupMsgValid = TRUE; DirectMessage(theEnv,FindSymbolHN(theEnv,DIRECT_MODIFY_STRING),ins,result,&theExp); InstanceData(theEnv)->ObjectModDupMsgValid = oldOMDMV; DeleteSlotOverrideEvaluations(theEnv,overrides,overrideCount); }/************************************************************* NAME : MsgModifyInstance DESCRIPTION : Modifies slots of an instance via the direct-modify message INPUTS : The address of the result value RETURNS : Nothing useful SIDE EFFECTS : Slot updates performed with put- messages NOTES : H/L Syntax: (message-modify-instance <instance> <slot-override>*) *************************************************************/globle void MsgModifyInstance( void *theEnv, DATA_OBJECT *result) { INSTANCE_TYPE *ins; EXPRESSION theExp; DATA_OBJECT *overrides; int oldOMDMV,overrideCount,error; /* =========================================== The slot-overrides need to be evaluated now to resolve any variable references before a new frame is pushed for message-handler execution =========================================== */ overrides = EvaluateSlotOverrides(theEnv,GetFirstArgument()->nextArg, &overrideCount,&error); if (error) { SetpType(result,SYMBOL); SetpValue(result,EnvFalseSymbol(theEnv)); return; } /* ================================== Find the instance and make sure it wasn't deleted by the overrides ================================== */ ins = CheckInstance(theEnv,ValueToString(ExpressionFunctionCallName(EvaluationData(theEnv)->CurrentExpression))); if (ins == NULL) { SetpType(result,SYMBOL); SetpValue(result,EnvFalseSymbol(theEnv)); DeleteSlotOverrideEvaluations(theEnv,overrides,overrideCount); return; } /* ====================================== We are passing the slot override expression information along to whatever message-handler implements the modify ====================================== */ theExp.type = EXTERNAL_ADDRESS; theExp.value = (void *) overrides; theExp.argList = NULL; theExp.nextArg = NULL; oldOMDMV = InstanceData(theEnv)->ObjectModDupMsgValid; InstanceData(theEnv)->ObjectModDupMsgValid = TRUE; DirectMessage(theEnv,FindSymbolHN(theEnv,MSG_MODIFY_STRING),ins,result,&theExp); InstanceData(theEnv)->ObjectModDupMsgValid = oldOMDMV; DeleteSlotOverrideEvaluations(theEnv,overrides,overrideCount); }/************************************************************* NAME : DuplicateInstance DESCRIPTION : Duplicates an instance via the direct-duplicate message INPUTS : The address of the result value RETURNS : Nothing useful SIDE EFFECTS : Slot updates performed directly NOTES : H/L Syntax: (duplicate-instance <instance> [to <instance-name>] <slot-override>*) *************************************************************/globle void DuplicateInstance( void *theEnv, DATA_OBJECT *result) { INSTANCE_TYPE *ins; DATA_OBJECT newName; EXPRESSION theExp[2]; DATA_OBJECT *overrides; int oldOMDMV,overrideCount,error; /* =========================================== The slot-overrides need to be evaluated now to resolve any variable references before a new frame is pushed for message-handler execution =========================================== */ overrides = EvaluateSlotOverrides(theEnv,GetFirstArgument()->nextArg->nextArg, &overrideCount,&error); if (error) { SetpType(result,SYMBOL); SetpValue(result,EnvFalseSymbol(theEnv)); return; } /* ================================== Find the instance and make sure it wasn't deleted by the overrides ================================== */ ins = CheckInstance(theEnv,ValueToString(ExpressionFunctionCallName(EvaluationData(theEnv)->CurrentExpression))); if (ins == NULL) { SetpType(result,SYMBOL); SetpValue(result,EnvFalseSymbol(theEnv)); DeleteSlotOverrideEvaluations(theEnv,overrides,overrideCount); return; } if (EnvArgTypeCheck(theEnv,ValueToString(ExpressionFunctionCallName(EvaluationData(theEnv)->CurrentExpression)), 2,INSTANCE_NAME,&newName) == FALSE) { SetpType(result,SYMBOL); SetpValue(result,EnvFalseSymbol(theEnv)); DeleteSlotOverrideEvaluations(theEnv,overrides,overrideCount); return; } /* ====================================== We are passing the slot override expression information along to whatever message-handler implements the duplicate ====================================== */ theExp[0].type = INSTANCE_NAME; theExp[0].value = newName.value; theExp[0].argList = NULL; theExp[0].nextArg = &theExp[1]; theExp[1].type = EXTERNAL_ADDRESS; theExp[1].value = (void *) overrides; theExp[1].argList = NULL; theExp[1].nextArg = NULL;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -