📄 insmoddp.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* INSTANCE MODIFY AND DUPLICATE MODULE */ /*******************************************************//*************************************************************//* Purpose: Instance modify and duplicate support routines *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* *//* Revision History: *//* *//*************************************************************/ /* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if OBJECT_SYSTEM#if INSTANCE_PATTERN_MATCHING#include "network.h"#include "objrtmch.h"#endif#include "argacces.h"#include "clipsmem.h"#include "extnfunc.h"#include "insfun.h"#include "insmngr.h"#include "inspsr.h"#include "msgfun.h"#include "msgpass.h"#include "prccode.h"#include "router.h"#define _INSMODDP_SOURCE_#include "insmoddp.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */ /* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */ /* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILERstatic DATA_OBJECT *EvaluateSlotOverrides(EXPRESSION *,int *,int *);static VOID DeleteSlotOverrideEvaluations(DATA_OBJECT *,int);static VOID ModifyMsgHandlerSupport(DATA_OBJECT *,int);static VOID DuplicateMsgHandlerSupport(DATA_OBJECT *,int);#elsestatic DATA_OBJECT *EvaluateSlotOverrides();static VOID DeleteSlotOverrideEvaluations();static VOID ModifyMsgHandlerSupport();static VOID DuplicateMsgHandlerSupport();#endif/* ========================================= ***************************************** EXTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** *//* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */static BOOLEAN ObjectModDupMsgValid = CLIPS_FALSE;/* ========================================= ***************************************** 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 CLIPS NOTES : None ***************************************************/globle VOID SetupInstanceModDupCommands() {#if INSTANCE_PATTERN_MATCHING DefineFunction2("modify-instance",'u',PTIF InactiveModifyInstance,"InactiveModifyInstance",NULL); DefineFunction2("active-modify-instance",'u',PTIF ModifyInstance,"ModifyInstance",NULL); AddFunctionParser("active-modify-instance",ParseInitializeInstance); DefineFunction2("message-modify-instance",'u',PTIF InactiveMsgModifyInstance, "InactiveMsgModifyInstance",NULL); DefineFunction2("active-message-modify-instance",'u',PTIF MsgModifyInstance, "MsgModifyInstance",NULL); AddFunctionParser("active-message-modify-instance",ParseInitializeInstance); DefineFunction2("duplicate-instance",'u', PTIF InactiveDuplicateInstance,"InactiveDuplicateInstance",NULL); DefineFunction2("active-duplicate-instance",'u',PTIF DuplicateInstance,"DuplicateInstance",NULL); AddFunctionParser("active-duplicate-instance",ParseInitializeInstance); DefineFunction2("message-duplicate-instance",'u',PTIF InactiveMsgDuplicateInstance, "InactiveMsgDuplicateInstance",NULL); DefineFunction2("active-message-duplicate-instance",'u',PTIF MsgDuplicateInstance, "MsgDuplicateInstance",NULL); AddFunctionParser("active-message-duplicate-instance",ParseInitializeInstance);#else DefineFunction2("modify-instance",'u',PTIF ModifyInstance,"ModifyInstance",NULL); DefineFunction2("message-modify-instance",'u',PTIF MsgModifyInstance, "MsgModifyInstance",NULL); DefineFunction2("duplicate-instance",'u',PTIF DuplicateInstance,"DuplicateInstance",NULL); DefineFunction2("message-duplicate-instance",'u',PTIF MsgDuplicateInstance, "MsgDuplicateInstance",NULL);#endif DefineFunction2("(direct-modify)",'u',PTIF DirectModifyMsgHandler,"DirectModifyMsgHandler",NULL); DefineFunction2("(message-modify)",'u',PTIF MsgModifyMsgHandler,"MsgModifyMsgHandler",NULL); DefineFunction2("(direct-duplicate)",'u',PTIF DirectDuplicateMsgHandler,"DirectDuplicateMsgHandler",NULL); DefineFunction2("(message-duplicate)",'u',PTIF MsgDuplicateMsgHandler,"MsgDuplicateMsgHandler",NULL); AddFunctionParser("modify-instance",ParseInitializeInstance); AddFunctionParser("message-modify-instance",ParseInitializeInstance); AddFunctionParser("duplicate-instance",ParseInitializeInstance); AddFunctionParser("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 : CLIPS Syntax: (modify-instance <instance> <slot-override>*) *************************************************************/globle VOID ModifyInstance(result) DATA_OBJECT *result; { INSTANCE_TYPE *ins; EXPRESSION exp; 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(GetFirstArgument()->nextArg, &overrideCount,&error); if (error) { SetpType(result,SYMBOL); SetpValue(result,CLIPSFalseSymbol); return; } /* ================================== Find the instance and make sure it wasn't deleted by the overrides ================================== */ ins = CheckInstance(ValueToString(ExpressionFunctionCallName(CurrentExpression))); if (ins == NULL) { SetpType(result,SYMBOL); SetpValue(result,CLIPSFalseSymbol); DeleteSlotOverrideEvaluations(overrides,overrideCount); return; } /* ====================================== We are passing the slot override expression information along to whatever message-handler implements the modify ====================================== */ exp.type = EXTERNAL_ADDRESS; exp.value = (VOID *) overrides; exp.argList = NULL; exp.nextArg = NULL; oldOMDMV = ObjectModDupMsgValid; ObjectModDupMsgValid = CLIPS_TRUE; DirectMessage(FindSymbol(DIRECT_MODIFY_STRING),ins,result,&exp); ObjectModDupMsgValid = oldOMDMV; DeleteSlotOverrideEvaluations(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 : CLIPS Syntax: (message-modify-instance <instance> <slot-override>*) *************************************************************/globle VOID MsgModifyInstance(result) DATA_OBJECT *result; { INSTANCE_TYPE *ins; EXPRESSION exp; 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(GetFirstArgument()->nextArg, &overrideCount,&error); if (error) { SetpType(result,SYMBOL); SetpValue(result,CLIPSFalseSymbol); return; } /* ================================== Find the instance and make sure it wasn't deleted by the overrides ================================== */ ins = CheckInstance(ValueToString(ExpressionFunctionCallName(CurrentExpression))); if (ins == NULL) { SetpType(result,SYMBOL); SetpValue(result,CLIPSFalseSymbol); DeleteSlotOverrideEvaluations(overrides,overrideCount); return; } /* ====================================== We are passing the slot override expression information along to whatever message-handler implements the modify ====================================== */ exp.type = EXTERNAL_ADDRESS; exp.value = (VOID *) overrides; exp.argList = NULL; exp.nextArg = NULL; oldOMDMV = ObjectModDupMsgValid; ObjectModDupMsgValid = CLIPS_TRUE; DirectMessage(FindSymbol(MSG_MODIFY_STRING),ins,result,&exp); ObjectModDupMsgValid = oldOMDMV; DeleteSlotOverrideEvaluations(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 : CLIPS Syntax: (duplicate-instance <instance> [to <instance-name>] <slot-override>*) *************************************************************/globle VOID DuplicateInstance(result) DATA_OBJECT *result; { INSTANCE_TYPE *ins; DATA_OBJECT newName; EXPRESSION exp[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(GetFirstArgument()->nextArg->nextArg, &overrideCount,&error); if (error) { SetpType(result,SYMBOL); SetpValue(result,CLIPSFalseSymbol); return; } /* ================================== Find the instance and make sure it wasn't deleted by the overrides ================================== */ ins = CheckInstance(ValueToString(ExpressionFunctionCallName(CurrentExpression))); if (ins == NULL) { SetpType(result,SYMBOL); SetpValue(result,CLIPSFalseSymbol); DeleteSlotOverrideEvaluations(overrides,overrideCount); return; } if (ArgTypeCheck(ValueToString(ExpressionFunctionCallName(CurrentExpression)), 2,INSTANCE_NAME,&newName) == CLIPS_FALSE) { SetpType(result,SYMBOL); SetpValue(result,CLIPSFalseSymbol); DeleteSlotOverrideEvaluations(overrides,overrideCount); return; } /* ====================================== We are passing the slot override
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -