📄 objrtbld.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* OBJECT PATTERN MATCHER MODULE */ /*******************************************************//**************************************************************//* Purpose: RETE Network Parsing Interface for Objects *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//**************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if INSTANCE_PATTERN_MATCHING#if (! BLOAD_ONLY) && (! RUN_TIME)#if ANSI_COMPILER#include <string.h>#endif#include "classcom.h"#include "classfun.h"#include "clipsmem.h"#include "cstrnutl.h"#include "constrnt.h"#include "cstrnchk.h"#include "cstrnops.h"#include "ruledef.h"#include "drive.h"#include "exprnpsr.h"#include "insfun.h"#include "insmngr.h"#include "network.h"#include "object.h"#include "pattern.h"#include "reteutil.h"#include "rulepsr.h"#include "scanner.h"#include "symbol.h"#include "utility.h"#endif#include "constrct.h"#include "objrtmch.h"#include "objrtgen.h"#include "objrtfnx.h"#include "reorder.h"#include "router.h"#if CONSTRUCT_COMPILER && (! RUN_TIME)#include "objrtcmp.h"#endif#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY#include "objrtbin.h"#endif#define _OBJRTBLD_SOURCE_#include "objrtbld.h"#if ! DEFINSTANCES_CONSTRUCT#include "extnfunc.h"#include "classfun.h"#include "classcom.h"#endif#if (! BLOAD_ONLY) && (! RUN_TIME)/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */#define OBJECT_PATTERN_INDICATOR "object"/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILERstatic BOOLEAN PatternParserFind(SYMBOL_HN *);static struct lhsParseNode *ObjectLHSParse(char *,struct token *);static BOOLEAN ReorderAndAnalyzeObjectPattern(struct lhsParseNode *);static struct patternNodeHeader *PlaceObjectPattern(struct lhsParseNode *);static OBJECT_PATTERN_NODE *FindObjectPatternNode(OBJECT_PATTERN_NODE *,struct lhsParseNode *, OBJECT_PATTERN_NODE **,unsigned);static OBJECT_PATTERN_NODE *CreateNewObjectPatternNode(struct lhsParseNode *,OBJECT_PATTERN_NODE *, OBJECT_PATTERN_NODE *,unsigned);static VOID DetachObjectPattern(struct patternNodeHeader *);static VOID ClearObjectPatternMatches(OBJECT_ALPHA_NODE *);static VOID RemoveObjectPartialMatches(INSTANCE_TYPE *,struct patternNodeHeader *);static BOOLEAN CheckDuplicateSlots(struct lhsParseNode *,SYMBOL_HN *);static struct lhsParseNode *ParseClassRestriction(char *,struct token *);static struct lhsParseNode *ParseNameRestriction(char *,struct token *);static struct lhsParseNode *ParseSlotRestriction(char *,struct token *,CONSTRAINT_RECORD *,int);static CLASS_BITMAP *NewClassBitMap(int,int);static VOID InitializeClassBitMap(CLASS_BITMAP *,int);static VOID DeleteIntermediateClassBitMap(CLASS_BITMAP *);static VOID *CopyClassBitMap(VOID *);static VOID DeleteClassBitMap(VOID *);static VOID MarkBitMapClassesBusy(BITMAP_HN *,int);static BOOLEAN EmptyClassBitMap(CLASS_BITMAP *);static BOOLEAN IdenticalClassBitMap(CLASS_BITMAP *,CLASS_BITMAP *);static BOOLEAN ProcessClassRestriction(CLASS_BITMAP *,struct lhsParseNode **,int);static CONSTRAINT_RECORD *ProcessSlotRestriction(CLASS_BITMAP *,SYMBOL_HN *,int *);static VOID IntersectClassBitMaps(CLASS_BITMAP *,CLASS_BITMAP *);static VOID UnionClassBitMaps(CLASS_BITMAP *,CLASS_BITMAP *);static CLASS_BITMAP *PackClassBitMap(CLASS_BITMAP *);static struct lhsParseNode *FilterObjectPattern(struct patternParser *, struct lhsParseNode *,struct lhsParseNode **, struct lhsParseNode **,struct lhsParseNode **);static BITMAP_HN *FormSlotBitMap(struct lhsParseNode *);static struct lhsParseNode *RemoveSlotExistenceTests(struct lhsParseNode *,BITMAP_HN **);static struct lhsParseNode *CreateInitialObjectPattern(void);static EXPRESSION *ObjectMatchDelayParse(EXPRESSION *,char *);#if INCREMENTAL_RESETstatic VOID MarkObjectPtnIncrementalReset(struct patternNodeHeader *,int);static VOID ObjectIncrementalReset(void);#endif#elsestatic BOOLEAN PatternParserFind();static struct lhsParseNode *ObjectLHSParse();static BOOLEAN ReorderAndAnalyzeObjectPattern();static struct patternNodeHeader *PlaceObjectPattern();static OBJECT_PATTERN_NODE *FindObjectPatternNode();static OBJECT_PATTERN_NODE *CreateNewObjectPatternNode();static VOID DetachObjectPattern();static VOID ClearObjectPatternMatches();static VOID RemoveObjectPartialMatches();static BOOLEAN CheckDuplicateSlots();static struct lhsParseNode *ParseClassRestriction();static struct lhsParseNode *ParseNameRestriction();static struct lhsParseNode *ParseSlotRestriction();static CLASS_BITMAP *NewClassBitMap();static VOID InitializeClassBitMap();static VOID DeleteIntermediateClassBitMap();static VOID *CopyClassBitMap();static VOID DeleteClassBitMap();static VOID MarkBitMapClassesBusy();static BOOLEAN EmptyClassBitMap();static BOOLEAN IdenticalClassBitMap();static BOOLEAN ProcessClassRestriction();static CONSTRAINT_RECORD *ProcessSlotRestriction();static VOID IntersectClassBitMaps();static VOID UnionClassBitMaps();static CLASS_BITMAP *PackClassBitMap();static struct lhsParseNode *FilterObjectPattern();static BITMAP_HN *FormSlotBitMap();static struct lhsParseNode *RemoveSlotExistenceTests();static struct lhsParseNode *CreateInitialObjectPattern();static EXPRESSION *ObjectMatchDelayParse();#if INCREMENTAL_RESETstatic VOID MarkObjectPtnIncrementalReset();static VOID ObjectIncrementalReset();#endif#endif#endif#if ! DEFINSTANCES_CONSTRUCT#if ANSI_COMPILERstatic VOID ResetInitialObject(void);#elsestatic VOID ResetInitialObject();#endif#endif/* ========================================= ***************************************** EXTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** *//* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** *//* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//******************************************************** NAME : SetupObjectPatternStuff DESCRIPTION : Installs the parsers and other items necessary for recognizing and processing object patterns in defrules INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Rete network interfaces for objects initialized NOTES : None ********************************************************/globle VOID SetupObjectPatternStuff() {#if (! BLOAD_ONLY) && (! RUN_TIME) if (ReservedPatternSymbol("object",NULL) == CLIPS_TRUE) { CLIPSSystemError("OBJRTBLD",1); ExitCLIPS(5); } AddReservedPatternSymbol("object",NULL); /* =========================================================================== The object pattern parser needs to have a higher priority than deftemplates or regular facts so that the "object" keyword is always recognized first =========================================================================== */ AddPatternParser("objects",20,&InstanceInfo,PatternParserFind, ObjectLHSParse,ReorderAndAnalyzeObjectPattern, PlaceObjectPattern,DetachObjectPattern, NULL,ReplaceGetJNObjectValue, GenGetJNObjectValue,ObjectJNVariableComparison, GenObjectPNConstantCompare,ReplaceGetPNObjectValue, GenGetPNObjectValue,ObjectPNVariableComparison, DeleteClassBitMap,CopyClassBitMap,#if INCREMENTAL_RESET MarkObjectPtnIncrementalReset,ObjectIncrementalReset,#else NULL,NULL,#endif CreateInitialObjectPattern,#if CONSTRUCT_COMPILER && (! RUN_TIME) ObjectPatternNodeReference#else NULL#endif ); DefineFunction2("object-pattern-match-delay",'u', PTIF ObjectMatchDelay,"ObjectMatchDelay",NULL); AddFunctionParser("object-pattern-match-delay",ObjectMatchDelayParse); FuncSeqOvlFlags("object-pattern-match-delay",CLIPS_FALSE,CLIPS_FALSE);#endif#if CONSTRUCT_COMPILER && (! RUN_TIME) ObjectPatternsCompilerSetup();#endif#if ! DEFINSTANCES_CONSTRUCT AddResetFunction("reset-initial-object",ResetInitialObject,0);#endif InstallObjectPrimitives();#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY SetupObjectPatternsBload();#endif }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */#if ! DEFINSTANCES_CONSTRUCTstatic VOID ResetInitialObject() { EXPRESSION *tmp; DATA_OBJECT rtn; tmp = GenConstant(FCALL,(VOID *) FindFunction("make-instance")); tmp->argList = GenConstant(INSTANCE_NAME,(VOID *) INITIAL_OBJECT_SYMBOL); tmp->argList->nextArg = GenConstant(DEFCLASS_PTR,(VOID *) LookupDefclassInScope(INITIAL_OBJECT_CLASS_NAME)); EvaluateExpression(tmp,&rtn); ReturnExpression(tmp); }#endif #if (! BLOAD_ONLY) && (! RUN_TIME)/***************************************************** NAME : PatternParserFind DESCRIPTION : Determines if a pattern CE is an object pattern (i.e. the first field is the constant symbol "object") INPUTS : 1) The type of the first field 2) The value of the first field RETURNS : CLIPS_TRUE if it is an object pattern, CLIPS_FALSE otherwise SIDE EFFECTS : None NOTES : Used by AddPatternParser() *****************************************************/static BOOLEAN PatternParserFind(value) SYMBOL_HN *value; { if (strcmp(ValueToString(value),OBJECT_PATTERN_INDICATOR) == 0) return(CLIPS_TRUE); return(CLIPS_FALSE); } /************************************************************************************ NAME : ObjectLHSParse DESCRIPTION : Scans and parses an object pattern for a rule INPUTS : 1) The logical name of the input source 2) A buffer holding the last token read RETURNS : The address of struct lhsParseNodes, NULL on errors SIDE EFFECTS : A series of struct lhsParseNodes are created to represent the intermediate parse of the pattern Pretty-print form for the pattern is saved NOTES : Object Pattern Syntax: (object [<class-constraint>] [<name-constraint>] <slot-constraint>*) <class-constraint> ::= (is-a <constraint>) <name-constraint> ::= (name <constraint>) <slot-constraint> ::= (<slot-name> <constraint>*) ************************************************************************************/#if IBM_TBC#pragma argsused#endifstatic struct lhsParseNode *ObjectLHSParse(readSource,lastToken) char *readSource; struct token *lastToken; {#if MAC_MPW || MAC_MCW#pragma unused(lastToken)#endif struct token theToken; struct lhsParseNode *firstNode = NULL,*lastNode = NULL,*tmpNode; CLASS_BITMAP *clsset,*tmpset; CONSTRAINT_RECORD *slotConstraints; int ppbackupReqd = CLIPS_FALSE,multip; /* ======================================================== Get a bitmap big enough to mark the ids of all currently existing classes - and set all bits, since the initial set of applicable classes is everything.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -