?? clsltpsr.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.24 05/17/06 */ /* */ /* CLASS PARSER MODULE */ /*******************************************************//**************************************************************//* Purpose: Parsing Routines for Defclass Construct *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//* 6.24: Converted INSTANCE_PATTERN_MATCHING to *//* DEFRULE_CONSTRUCT. *//* *//* Renamed BOOLEAN macro type to intBool. *//* *//**************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if OBJECT_SYSTEM && (! BLOAD_ONLY) && (! RUN_TIME)#include <string.h>#include "classcom.h"#include "classfun.h"#include "cstrnchk.h"#include "cstrnpsr.h"#include "cstrnutl.h"#include "default.h"#include "envrnmnt.h"#include "insfun.h"#include "memalloc.h"#include "prntutil.h"#include "router.h"#include "scanner.h"#define _CLSLTPSR_SOURCE_#include "clsltpsr.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */#define DEFAULT_FACET "default"#define DYNAMIC_FACET "default-dynamic"#define VARIABLE_VAR "VARIABLE"#define STORAGE_FACET "storage"#define SLOT_SHARE_RLN "shared"#define SLOT_LOCAL_RLN "local"#define ACCESS_FACET "access"#define SLOT_RDONLY_RLN "read-only"#define SLOT_RDWRT_RLN "read-write"#define SLOT_INIT_RLN "initialize-only"#define PROPAGATION_FACET "propagation"#define SLOT_NO_INH_RLN "no-inherit"#define SLOT_INH_RLN "inherit"#define SOURCE_FACET "source"#define SLOT_COMPOSITE_RLN "composite"#define SLOT_EXCLUSIVE_RLN "exclusive"#define MATCH_FACET MATCH_RLN#define SLOT_REACTIVE_RLN REACTIVE_RLN#define SLOT_NONREACTIVE_RLN NONREACTIVE_RLN#define VISIBILITY_FACET "visibility"#define SLOT_PUBLIC_RLN "public"#define SLOT_PRIVATE_RLN "private"#define CREATE_ACCESSOR_FACET "create-accessor"#define SLOT_READ_RLN "read"#define SLOT_WRITE_RLN "write"#define SLOT_NONE_RLN "NONE"#define OVERRIDE_MSG_FACET "override-message"#define SLOT_DEFAULT_RLN "DEFAULT"#define STORAGE_BIT 0#define FIELD_BIT 1#define ACCESS_BIT 2#define PROPAGATION_BIT 3#define SOURCE_BIT 4#define MATCH_BIT 5#define DEFAULT_BIT 6#define DEFAULT_DYNAMIC_BIT 7#define VISIBILITY_BIT 8#define CREATE_ACCESSOR_BIT 9#define OVERRIDE_MSG_BIT 10/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */static SLOT_DESC *NewSlot(void *,SYMBOL_HN *);static TEMP_SLOT_LINK *InsertSlot(void *,TEMP_SLOT_LINK *,SLOT_DESC *);static int ParseSimpleFacet(void *,char *,char*,char *,int,char *,char *,char *,char *,SYMBOL_HN **);static intBool ParseDefaultFacet(void *,char *,char *,SLOT_DESC *);static void BuildCompositeFacets(void *,SLOT_DESC *,PACKED_CLASS_LINKS *,char *, CONSTRAINT_PARSE_RECORD *);static intBool CheckForFacetConflicts(void *,SLOT_DESC *,CONSTRAINT_PARSE_RECORD *);static intBool EvaluateSlotDefaultValue(void *,SLOT_DESC *,char *);/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//************************************************************ NAME : ParseSlot DESCRIPTION : Parses slot definitions for a defclass statement INPUTS : 1) The logical name of the input source 2) The current slot list 3) The class precedence list for the class to which this slot is being attached (used to find facets for composite slots) 4) A flag indicating if this is a multifield slot or not 5) A flag indicating if the type of slot (single or multi) was explicitly specified or not RETURNS : The address of the list of slots, NULL if there was an error SIDE EFFECTS : The slot list is allocated NOTES : Assumes "(slot" has already been parsed. ************************************************************/globle TEMP_SLOT_LINK *ParseSlot( void *theEnv, char *readSource, TEMP_SLOT_LINK *slist, PACKED_CLASS_LINKS *preclist, int multiSlot, int fieldSpecified) { SLOT_DESC *slot; CONSTRAINT_PARSE_RECORD parsedConstraint; char specbits[2]; int rtnCode; SYMBOL_HN *newOverrideMsg; /* =============================================================== Bits in specbits are when slot qualifiers are specified so that duplicate or conflicting qualifiers can be detected. Shared/local bit-0 Single/multiple bit-1 Read-only/Read-write/Initialize-Only bit-2 Inherit/No-inherit bit-3 Composite/Exclusive bit-4 Reactive/Nonreactive bit-5 Default bit-6 Default-dynamic bit-7 Visibility bit-8 Override-message bit-9 =============================================================== */ SavePPBuffer(theEnv," "); specbits[0] = specbits[1] = '\0'; GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken); if (GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL) { DeleteSlots(theEnv,slist); SyntaxErrorMessage(theEnv,"defclass slot"); return(NULL); } if ((DefclassData(theEnv)->ObjectParseToken.value == (void *) DefclassData(theEnv)->ISA_SYMBOL) || (DefclassData(theEnv)->ObjectParseToken.value == (void *) DefclassData(theEnv)->NAME_SYMBOL)) { DeleteSlots(theEnv,slist); SyntaxErrorMessage(theEnv,"defclass slot"); return(NULL); } slot = NewSlot(theEnv,(SYMBOL_HN *) GetValue(DefclassData(theEnv)->ObjectParseToken)); slist = InsertSlot(theEnv,slist,slot); if (slist == NULL) return(NULL); if (multiSlot) slot->multiple = TRUE; if (fieldSpecified) SetBitMap(specbits,FIELD_BIT); GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken); IncrementIndentDepth(theEnv,3); InitializeConstraintParseRecord(&parsedConstraint); while (GetType(DefclassData(theEnv)->ObjectParseToken) == LPAREN) { PPBackup(theEnv); PPCRAndIndent(theEnv); SavePPBuffer(theEnv,"("); GetToken(theEnv,readSource,&DefclassData(theEnv)->ObjectParseToken); if (GetType(DefclassData(theEnv)->ObjectParseToken) != SYMBOL) { SyntaxErrorMessage(theEnv,"defclass slot"); goto ParseSlotError; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),DEFAULT_FACET) == 0) { if (ParseDefaultFacet(theEnv,readSource,specbits,slot) == FALSE) goto ParseSlotError; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),DYNAMIC_FACET) == 0) { SetBitMap(specbits,DEFAULT_DYNAMIC_BIT); if (ParseDefaultFacet(theEnv,readSource,specbits,slot) == FALSE) goto ParseSlotError; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),ACCESS_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,ACCESS_FACET,ACCESS_BIT, SLOT_RDWRT_RLN,SLOT_RDONLY_RLN,SLOT_INIT_RLN, NULL,NULL); if (rtnCode == -1) goto ParseSlotError; else if (rtnCode == 1) slot->noWrite = 1; else if (rtnCode == 2) slot->initializeOnly = 1; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),STORAGE_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,STORAGE_FACET,STORAGE_BIT, SLOT_LOCAL_RLN,SLOT_SHARE_RLN,NULL,NULL,NULL); if (rtnCode == -1) goto ParseSlotError; slot->shared = rtnCode; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),PROPAGATION_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,PROPAGATION_FACET,PROPAGATION_BIT, SLOT_INH_RLN,SLOT_NO_INH_RLN,NULL,NULL,NULL); if (rtnCode == -1) goto ParseSlotError; slot->noInherit = rtnCode; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),SOURCE_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,SOURCE_FACET,SOURCE_BIT, SLOT_EXCLUSIVE_RLN,SLOT_COMPOSITE_RLN,NULL,NULL,NULL); if (rtnCode == -1) goto ParseSlotError; slot->composite = rtnCode; }#if DEFRULE_CONSTRUCT else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),MATCH_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,MATCH_FACET,MATCH_BIT, SLOT_NONREACTIVE_RLN,SLOT_REACTIVE_RLN,NULL,NULL,NULL); if (rtnCode == -1) goto ParseSlotError; slot->reactive = rtnCode; }#endif else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),VISIBILITY_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,VISIBILITY_FACET,VISIBILITY_BIT, SLOT_PRIVATE_RLN,SLOT_PUBLIC_RLN,NULL,NULL,NULL); if (rtnCode == -1) goto ParseSlotError; slot->publicVisibility = rtnCode; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),CREATE_ACCESSOR_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,CREATE_ACCESSOR_FACET, CREATE_ACCESSOR_BIT, SLOT_READ_RLN,SLOT_WRITE_RLN,SLOT_RDWRT_RLN, SLOT_NONE_RLN,NULL); if (rtnCode == -1) goto ParseSlotError; if ((rtnCode == 0) || (rtnCode == 2)) slot->createReadAccessor = TRUE; if ((rtnCode == 1) || (rtnCode == 2)) slot->createWriteAccessor = TRUE; } else if (strcmp(DOToString(DefclassData(theEnv)->ObjectParseToken),OVERRIDE_MSG_FACET) == 0) { rtnCode = ParseSimpleFacet(theEnv,readSource,specbits,OVERRIDE_MSG_FACET,OVERRIDE_MSG_BIT, NULL,NULL,NULL,SLOT_DEFAULT_RLN,&newOverrideMsg);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -