void GetWatchItemCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { UDFValue theValue; const char *argument; bool recognized; /*========================================*/ /* Determine which item is to be watched. */ /*========================================*/ if (! UDFFirstArgument(context,SYMBOL_BIT,&theValue)) { return; } argument = theValue.lexemeValue->contents; ValidWatchItem(theEnv,argument,&recognized); if (recognized == false) { SetEvaluationError(theEnv,true); ExpectedTypeError1(theEnv,"get-watch-item",1,"'watchable symbol'"); returnValue->lexemeValue = FalseSymbol(theEnv); return; } /*===========================*/ /* Get the watch item value. */ /*===========================*/ if (GetWatchItem(theEnv,argument) == 1) { returnValue->lexemeValue = TrueSymbol(theEnv); } else { returnValue->lexemeValue = FalseSymbol(theEnv); } }
globle int GetWatchItemCommand() { DATA_OBJECT theValue; char *argument; int recognized; /*============================================*/ /* Check for the correct number of arguments. */ /*============================================*/ if (ArgCountCheck("get-watch-item",EXACTLY,1) == -1) { return(FALSE); } /*========================================*/ /* Determine which item is to be watched. */ /*========================================*/ if (ArgTypeCheck("get-watch-item",1,SYMBOL,&theValue) == FALSE) { return(FALSE); } argument = DOToString(theValue); ValidWatchItem(argument,&recognized); if (recognized == FALSE) { SetEvaluationError(TRUE); ExpectedTypeError1("get-watch-item",1,"watchable symbol"); return(FALSE); } /*===========================*/ /* Get the watch item value. */ /*===========================*/ if (GetWatchItem(argument) == 1) { return(TRUE); } return(FALSE); }
Deftemplate *CreateImpliedDeftemplate( Environment *theEnv, CLIPSLexeme *deftemplateName, bool setFlag) { Deftemplate *newDeftemplate; newDeftemplate = get_struct(theEnv,deftemplate); newDeftemplate->header.name = deftemplateName; newDeftemplate->header.ppForm = NULL; newDeftemplate->header.usrData = NULL; newDeftemplate->header.constructType = DEFTEMPLATE; newDeftemplate->header.env = theEnv; newDeftemplate->slotList = NULL; newDeftemplate->implied = setFlag; newDeftemplate->numberOfSlots = 0; newDeftemplate->inScope = 1; newDeftemplate->patternNetwork = NULL; newDeftemplate->factList = NULL; newDeftemplate->lastFact = NULL; newDeftemplate->busyCount = 0; newDeftemplate->watch = false; newDeftemplate->header.next = NULL; #if DEBUGGING_FUNCTIONS if (GetWatchItem(theEnv,"facts") == 1) { DeftemplateSetWatch(newDeftemplate,true); } #endif newDeftemplate->header.whichModule = (struct defmoduleItemHeader *) GetModuleItem(theEnv,NULL,DeftemplateData(theEnv)->DeftemplateModuleIndex); AddConstructToModule(&newDeftemplate->header); InstallDeftemplate(theEnv,newDeftemplate); return(newDeftemplate); }
globle struct deftemplate *CreateImpliedDeftemplate( SYMBOL_HN *deftemplateName, int setFlag) { struct deftemplate *newDeftemplate; newDeftemplate = get_struct(deftemplate); newDeftemplate->header.name = deftemplateName; newDeftemplate->header.ppForm = NULL; newDeftemplate->header.usrData = NULL; newDeftemplate->slotList = NULL; newDeftemplate->implied = setFlag; newDeftemplate->numberOfSlots = 0; newDeftemplate->inScope = 1; newDeftemplate->patternNetwork = NULL; newDeftemplate->busyCount = 0; newDeftemplate->watch = FALSE; newDeftemplate->header.next = NULL; #if FUZZY_DEFTEMPLATES newDeftemplate->hasFuzzySlots = FALSE; newDeftemplate->fuzzyTemplate = NULL; #endif #if DEBUGGING_FUNCTIONS if (GetWatchItem("facts")) { SetDeftemplateWatch(ON,(void *) newDeftemplate); } #endif newDeftemplate->header.whichModule = (struct defmoduleItemHeader *) GetModuleItem(NULL,DeftemplateModuleIndex); AddConstructToModule(&newDeftemplate->header); InstallDeftemplate(newDeftemplate); return(newDeftemplate); }
BOOL FAR PASCAL WatchDlgProc ( HWND hDlg, unsigned message, WORD wParam, LONG lParam) { static int count; switch (message) { case WM_INITDIALOG: { count = 0; count += SetCheckBox(hDlg, IDC_WATCH_COMPILE, GetWatchItem("compilations")); count += SetCheckBox(hDlg, IDC_WATCH_FACTS, GetWatchItem("facts")); count += SetCheckBox(hDlg, IDC_WATCH_INSTANCE, GetWatchItem("instances")); count += SetCheckBox(hDlg, IDC_WATCH_RULES, GetWatchItem("rules")); count += SetCheckBox(hDlg, IDC_WATCH_GENERIC, GetWatchItem("generic-functions")); count += SetCheckBox(hDlg, IDC_WATCH_MESSAGE, GetWatchItem("messages")); count += SetCheckBox(hDlg, IDC_WATCH_DEFFUN, GetWatchItem("deffunctions")); count += SetCheckBox(hDlg, IDC_WATCH_STATS, GetWatchItem("statistics")); count += SetCheckBox(hDlg, IDC_WATCH_GLOBAL, GetWatchItem("globals")); count += SetCheckBox(hDlg, IDC_WATCH_SLOT, GetWatchItem("slots")); count += SetCheckBox(hDlg, IDC_WATCH_ACTIVE, GetWatchItem("activations")); count += SetCheckBox(hDlg, IDC_WATCH_METHOD, GetWatchItem("methods")); count += SetCheckBox(hDlg, IDC_WATCH_FOCUS, GetWatchItem("focus")); count += SetCheckBox(hDlg, IDC_WATCH_MSGHANDLER, GetWatchItem("message-handlers")); if (count == IDC_WATCH_COUNT ) EnableWindow(GetDlgItem(hDlg, IDC_WATCH_ALL ), FALSE); else if ( count == 0 ) EnableWindow(GetDlgItem(hDlg, IDC_WATCH_NONE), FALSE); return (TRUE); } case WM_COMMAND: { switch (wParam) { case IDC_OK: SetWatchItem ("compilations", IsDlgButtonChecked (hDlg, IDC_WATCH_COMPILE),NULL); SetWatchItem ("statistics", IsDlgButtonChecked (hDlg, IDC_WATCH_STATS),NULL); #if DEFTEMPLATE_CONSTRUCT SetWatchItem ("facts", IsDlgButtonChecked (hDlg, IDC_WATCH_FACTS),NULL); #endif #if OBJECT_SYSTEM SetWatchItem ("instances", IsDlgButtonChecked (hDlg, IDC_WATCH_INSTANCE),NULL); SetWatchItem ("slots", IsDlgButtonChecked (hDlg, IDC_WATCH_SLOT),NULL); SetWatchItem ("messages", IsDlgButtonChecked (hDlg, IDC_WATCH_MESSAGE),NULL); SetWatchItem ("message-handlers", IsDlgButtonChecked (hDlg, IDC_WATCH_MSGHANDLER),NULL); #endif #if DEFFUNCTION_CONSTRUCT SetWatchItem ("deffunctions", IsDlgButtonChecked (hDlg, IDC_WATCH_DEFFUN),NULL); #endif #if DEFRULE_CONSTRUCT SetWatchItem ("rules", IsDlgButtonChecked (hDlg, IDC_WATCH_RULES),NULL); SetWatchItem ("activations", IsDlgButtonChecked (hDlg, IDC_WATCH_ACTIVE),NULL); SetWatchItem ("focus", IsDlgButtonChecked (hDlg, IDC_WATCH_FOCUS),NULL); #endif #if DEFGENERIC_CONSTRUCT SetWatchItem ("generic-functions",IsDlgButtonChecked (hDlg, IDC_WATCH_GENERIC),NULL); SetWatchItem ("methods", IsDlgButtonChecked (hDlg, IDC_WATCH_METHOD),NULL); #endif #if DEFGLOBAL_CONSTRUCT SetWatchItem ("globals", IsDlgButtonChecked (hDlg, IDC_WATCH_GLOBAL),NULL); #endif case IDC_CANCEL: { EndDialog ( hDlg, IDOK); return ( TRUE ); } case IDC_WATCH_COMPILE: case IDC_WATCH_FACTS: case IDC_WATCH_INSTANCE: case IDC_WATCH_RULES: case IDC_WATCH_GENERIC: case IDC_WATCH_MESSAGE: case IDC_WATCH_DEFFUN: case IDC_WATCH_STATS: case IDC_WATCH_GLOBAL: case IDC_WATCH_SLOT: case IDC_WATCH_METHOD: case IDC_WATCH_MSGHANDLER: case IDC_WATCH_ACTIVE: case IDC_WATCH_FOCUS: { if (IsDlgButtonChecked (hDlg, wParam)) { SetCheckBox ( hDlg, wParam, 0); count --; } else { SetCheckBox(hDlg, wParam, 1); count++; } if (count == IDC_WATCH_COUNT ) EnableWindow(GetDlgItem(hDlg, IDC_WATCH_ALL ), FALSE); else if ( count == 0 ) EnableWindow(GetDlgItem(hDlg, IDC_WATCH_NONE), FALSE); else { EnableWindow(GetDlgItem(hDlg, IDC_WATCH_ALL ), TRUE); EnableWindow(GetDlgItem(hDlg, IDC_WATCH_NONE ), TRUE); } return (TRUE); } case IDC_WATCH_ALL: { WORD x; for ( x=IDC_WATCH_START; x<=IDC_WATCH_END; x++) SetCheckBox ( hDlg,x,1); EnableWindow(GetDlgItem(hDlg, IDC_WATCH_ALL ), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_WATCH_NONE), TRUE); count = IDC_WATCH_COUNT; return ( TRUE ); } case IDC_WATCH_NONE: { WORD x; for ( x=IDC_WATCH_START; x<=IDC_WATCH_END; x++) SetCheckBox ( hDlg,x,0); EnableWindow(GetDlgItem(hDlg, IDC_WATCH_NONE), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_WATCH_ALL ), TRUE); count = 0; return ( TRUE ); } } } } return ( FALSE ); }
bool GetWatchState( Environment *theEnv, WatchItem item) { switch (item) { case ALL: return false; case FACTS: return (GetWatchItem(theEnv,"facts") == 1); case INSTANCES: return (GetWatchItem(theEnv,"instances") == 1); case SLOTS: return (GetWatchItem(theEnv,"slots") == 1); case RULES: return (GetWatchItem(theEnv,"rules") == 1); case ACTIVATIONS: return (GetWatchItem(theEnv,"activations") == 1); case MESSAGES: return (GetWatchItem(theEnv,"messages") == 1); case MESSAGE_HANDLERS: return (GetWatchItem(theEnv,"message-handlers") == 1); case GENERIC_FUNCTIONS: return (GetWatchItem(theEnv,"generic-functions") == 1); case METHODS: return (GetWatchItem(theEnv,"methods") == 1); case DEFFUNCTIONS: return (GetWatchItem(theEnv,"deffunctions") == 1); case COMPILATIONS: return (GetWatchItem(theEnv,"compilations") == 1); case STATISTICS: return (GetWatchItem(theEnv,"statistics") == 1); case GLOBALS: return (GetWatchItem(theEnv,"globals") == 1); case FOCUS: return (GetWatchItem(theEnv,"focus") == 1); } return false; }
static Defrule *ProcessRuleLHS( Environment *theEnv, struct lhsParseNode *theLHS, struct expr *actions, CLIPSLexeme *ruleName, bool *error) { struct lhsParseNode *tempNode = NULL; Defrule *topDisjunct = NULL, *currentDisjunct, *lastDisjunct = NULL; struct expr *newActions, *packPtr; int logicalJoin; unsigned short localVarCnt; unsigned short complexity; struct joinNode *lastJoin; bool emptyLHS; /*================================================*/ /* Initially set the parsing error flag to false. */ /*================================================*/ *error = false; /*===========================================================*/ /* The top level of the construct representing the LHS of a */ /* rule is assumed to be an OR. If the implied OR is at the */ /* top level of the pattern construct, then remove it. */ /*===========================================================*/ if (theLHS == NULL) { emptyLHS = true; } else { emptyLHS = false; if (theLHS->pnType == OR_CE_NODE) theLHS = theLHS->right; } /*=========================================*/ /* Loop through each disjunct of the rule. */ /*=========================================*/ localVarCnt = CountParsedBindNames(theEnv); while ((theLHS != NULL) || (emptyLHS == true)) { /*===================================*/ /* Analyze the LHS of this disjunct. */ /*===================================*/ if (emptyLHS) { tempNode = NULL; } else { if (theLHS->pnType == AND_CE_NODE) tempNode = theLHS->right; else if (theLHS->pnType == PATTERN_CE_NODE) tempNode = theLHS; } if (VariableAnalysis(theEnv,tempNode)) { *error = true; ReturnDefrule(theEnv,topDisjunct); return NULL; } /*=========================================*/ /* Perform entity dependent post analysis. */ /*=========================================*/ if (PostPatternAnalysis(theEnv,tempNode)) { *error = true; ReturnDefrule(theEnv,topDisjunct); return NULL; } /*========================================================*/ /* Print out developer information if it's being watched. */ /*========================================================*/ #if DEVELOPER && DEBUGGING_FUNCTIONS if (GetWatchItem(theEnv,"rule-analysis") == 1) { DumpRuleAnalysis(theEnv,tempNode); } #endif /*======================================================*/ /* Check to see if there are any RHS constraint errors. */ /*======================================================*/ if (CheckRHSForConstraintErrors(theEnv,actions,tempNode)) { *error = true; ReturnDefrule(theEnv,topDisjunct); return NULL; } /*=================================================*/ /* Replace variable references in the RHS with the */ /* appropriate variable retrieval functions. */ /*=================================================*/ newActions = CopyExpression(theEnv,actions); if (ReplaceProcVars(theEnv,"RHS of defrule",newActions,NULL,NULL, ReplaceRHSVariable,tempNode)) { *error = true; ReturnDefrule(theEnv,topDisjunct); ReturnExpression(theEnv,newActions); return NULL; } /*===================================================*/ /* Remove any test CEs from the LHS and attach their */ /* expression to the closest preceeding non-negated */ /* join at the same not/and depth. */ /*===================================================*/ AttachTestCEsToPatternCEs(theEnv,tempNode); /*========================================*/ /* Check to see that logical CEs are used */ /* appropriately in the LHS of the rule. */ /*========================================*/ if ((logicalJoin = LogicalAnalysis(theEnv,tempNode)) < 0) { *error = true; ReturnDefrule(theEnv,topDisjunct); ReturnExpression(theEnv,newActions); return NULL; } /*==================================*/ /* We're finished for this disjunct */ /* if we're only checking syntax. */ /*==================================*/ if (ConstructData(theEnv)->CheckSyntaxMode) { ReturnExpression(theEnv,newActions); if (emptyLHS) { emptyLHS = false; } else { theLHS = theLHS->bottom; } continue; } /*=================================*/ /* Install the disjunct's actions. */ /*=================================*/ ExpressionInstall(theEnv,newActions); packPtr = PackExpression(theEnv,newActions); ReturnExpression(theEnv,newActions); /*===============================================================*/ /* Create the pattern and join data structures for the new rule. */ /*===============================================================*/ lastJoin = ConstructJoins(theEnv,logicalJoin,tempNode,1,NULL,true,true); /*===================================================================*/ /* Determine the rule's complexity for use with conflict resolution. */ /*===================================================================*/ complexity = RuleComplexity(theEnv,tempNode); /*=====================================================*/ /* Create the defrule data structure for this disjunct */ /* and put it in the list of disjuncts for this rule. */ /*=====================================================*/ currentDisjunct = CreateNewDisjunct(theEnv,ruleName,localVarCnt,packPtr,complexity, (unsigned) logicalJoin,lastJoin); /*============================================================*/ /* Place the disjunct in the list of disjuncts for this rule. */ /* If the disjunct is the first disjunct, then increment the */ /* reference counts for the dynamic salience (the expression */ /* for the dynamic salience is only stored with the first */ /* disjuncts and the other disjuncts refer back to the first */ /* disjunct for their dynamic salience value. */ /*============================================================*/ if (topDisjunct == NULL) { topDisjunct = currentDisjunct; ExpressionInstall(theEnv,topDisjunct->dynamicSalience); } else lastDisjunct->disjunct = currentDisjunct; /*===========================================*/ /* Move on to the next disjunct of the rule. */ /*===========================================*/ lastDisjunct = currentDisjunct; if (emptyLHS) { emptyLHS = false; } else { theLHS = theLHS->bottom; } } return(topDisjunct); }
bool ParseDefrule( Environment *theEnv, const char *readSource) { #if (! RUN_TIME) && (! BLOAD_ONLY) CLIPSLexeme *ruleName; struct lhsParseNode *theLHS; struct expr *actions; struct token theToken; Defrule *topDisjunct, *tempPtr; struct defruleModule *theModuleItem; bool error; /*================================================*/ /* Flush the buffer which stores the pretty print */ /* representation for a rule. Add the already */ /* parsed keyword defrule to this buffer. */ /*================================================*/ SetPPBufferStatus(theEnv,true); FlushPPBuffer(theEnv); SavePPBuffer(theEnv,"(defrule "); /*=========================================================*/ /* Rules cannot be loaded when a binary load is in effect. */ /*=========================================================*/ #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE if ((Bloaded(theEnv) == true) && (! ConstructData(theEnv)->CheckSyntaxMode)) { CannotLoadWithBloadMessage(theEnv,"defrule"); return true; } #endif /*================================================*/ /* Parse the name and comment fields of the rule, */ /* deleting the rule if it already exists. */ /*================================================*/ #if DEBUGGING_FUNCTIONS DefruleData(theEnv)->DeletedRuleDebugFlags = 0; #endif ruleName = GetConstructNameAndComment(theEnv,readSource,&theToken,"defrule", (FindConstructFunction *) FindDefruleInModule, (DeleteConstructFunction *) Undefrule, "*",false, true,true,false); if (ruleName == NULL) return true; /*============================*/ /* Parse the LHS of the rule. */ /*============================*/ theLHS = ParseRuleLHS(theEnv,readSource,&theToken,ruleName->contents,&error); if (error) { ReturnPackedExpression(theEnv,PatternData(theEnv)->SalienceExpression); PatternData(theEnv)->SalienceExpression = NULL; return true; } /*============================*/ /* Parse the RHS of the rule. */ /*============================*/ ClearParsedBindNames(theEnv); ExpressionData(theEnv)->ReturnContext = true; actions = ParseRuleRHS(theEnv,readSource); if (actions == NULL) { ReturnPackedExpression(theEnv,PatternData(theEnv)->SalienceExpression); PatternData(theEnv)->SalienceExpression = NULL; ReturnLHSParseNodes(theEnv,theLHS); return true; } /*=======================*/ /* Process the rule LHS. */ /*=======================*/ topDisjunct = ProcessRuleLHS(theEnv,theLHS,actions,ruleName,&error); ReturnExpression(theEnv,actions); ClearParsedBindNames(theEnv); ReturnLHSParseNodes(theEnv,theLHS); if (error) { ReturnPackedExpression(theEnv,PatternData(theEnv)->SalienceExpression); PatternData(theEnv)->SalienceExpression = NULL; return true; } /*==============================================*/ /* If we're only checking syntax, don't add the */ /* successfully parsed defrule to the KB. */ /*==============================================*/ if (ConstructData(theEnv)->CheckSyntaxMode) { ReturnPackedExpression(theEnv,PatternData(theEnv)->SalienceExpression); PatternData(theEnv)->SalienceExpression = NULL; return false; } PatternData(theEnv)->SalienceExpression = NULL; /*======================================*/ /* Save the nice printout of the rules. */ /*======================================*/ SavePPBuffer(theEnv,"\n"); if (GetConserveMemory(theEnv) == true) { topDisjunct->header.ppForm = NULL; } else { topDisjunct->header.ppForm = CopyPPBuffer(theEnv); } /*=======================================*/ /* Store a pointer to the rule's module. */ /*=======================================*/ theModuleItem = (struct defruleModule *) GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"defrule")->moduleIndex); for (tempPtr = topDisjunct; tempPtr != NULL; tempPtr = tempPtr->disjunct) { tempPtr->header.whichModule = (struct defmoduleItemHeader *) theModuleItem; tempPtr->header.ppForm = topDisjunct->header.ppForm; } /*===============================================*/ /* Rule completely parsed. Add to list of rules. */ /*===============================================*/ AddToDefruleList(topDisjunct); /*========================================================================*/ /* If a rule is redefined, then we want to restore its breakpoint status. */ /*========================================================================*/ #if DEBUGGING_FUNCTIONS if (BitwiseTest(DefruleData(theEnv)->DeletedRuleDebugFlags,0)) { SetBreak(topDisjunct); } if (BitwiseTest(DefruleData(theEnv)->DeletedRuleDebugFlags,1) || (GetWatchItem(theEnv,"activations") == 1)) { DefruleSetWatchActivations(topDisjunct,true); } if (BitwiseTest(DefruleData(theEnv)->DeletedRuleDebugFlags,2) || (GetWatchItem(theEnv,"rules") == 1)) { DefruleSetWatchFirings(topDisjunct,true); } #endif /*================================*/ /* Perform the incremental reset. */ /*================================*/ IncrementalReset(theEnv,topDisjunct); /*=============================================*/ /* Return false to indicate no errors occured. */ /*=============================================*/ #endif return false; }