static void DeallocateExternalFunctionData( void *theEnv) { struct FunctionHash *fhPtr, *nextFHPtr; int i; #if ! RUN_TIME struct FunctionDefinition *tmpPtr, *nextPtr; tmpPtr = ExternalFunctionData(theEnv)->ListOfFunctions; while (tmpPtr != NULL) { nextPtr = tmpPtr->next; rtn_struct(theEnv,FunctionDefinition,tmpPtr); tmpPtr = nextPtr; } #endif if (ExternalFunctionData(theEnv)->FunctionHashtable == NULL) { return; } for (i = 0; i < SIZE_FUNCTION_HASH; i++) { fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[i]; while (fhPtr != NULL) { nextFHPtr = fhPtr->next; rtn_struct(theEnv,FunctionHash,fhPtr); fhPtr = nextFHPtr; } } genfree(theEnv,ExternalFunctionData(theEnv)->FunctionHashtable, (int) sizeof (struct FunctionHash *) * SIZE_FUNCTION_HASH); }
globle void InstallFunctionList( void *theEnv, struct FunctionDefinition *value) { int i; struct FunctionHash *fhPtr, *nextPtr; if (ExternalFunctionData(theEnv)->FunctionHashtable != NULL) { for (i = 0; i < SIZE_FUNCTION_HASH; i++) { fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[i]; while (fhPtr != NULL) { nextPtr = fhPtr->next; rtn_struct(theEnv,FunctionHash,fhPtr); fhPtr = nextPtr; } ExternalFunctionData(theEnv)->FunctionHashtable[i] = NULL; } } ExternalFunctionData(theEnv)->ListOfFunctions = value; while (value != NULL) { AddHashFunction(theEnv,value); value = value->next; } }
static int RemoveHashFunction( void *theEnv, struct FunctionDefinition *fdPtr) { struct FunctionHash *fhPtr, *lastPtr = NULL; unsigned hashValue; hashValue = HashSymbol(ValueToString(fdPtr->callFunctionName),SIZE_FUNCTION_HASH); for (fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[hashValue]; fhPtr != NULL; fhPtr = fhPtr->next) { if (fhPtr->fdPtr == fdPtr) { if (lastPtr == NULL) { ExternalFunctionData(theEnv)->FunctionHashtable[hashValue] = fhPtr->next; } else { lastPtr->next = fhPtr->next; } rtn_struct(theEnv,FunctionHash,fhPtr); return(TRUE); } lastPtr = fhPtr; } return(FALSE); }
globle int UndefineFunction( void *theEnv, const char *functionName) { SYMBOL_HN *findValue; struct FunctionDefinition *fPtr, *lastPtr = NULL; findValue = (SYMBOL_HN *) FindSymbolHN(theEnv,functionName); for (fPtr = ExternalFunctionData(theEnv)->ListOfFunctions; fPtr != NULL; fPtr = fPtr->next) { if (fPtr->callFunctionName == findValue) { DecrementSymbolCount(theEnv,fPtr->callFunctionName); RemoveHashFunction(theEnv,fPtr); if (lastPtr == NULL) { ExternalFunctionData(theEnv)->ListOfFunctions = fPtr->next; } else { lastPtr->next = fPtr->next; } ClearUserDataList(theEnv,fPtr->usrData); rtn_struct(theEnv,FunctionDefinition,fPtr); return(TRUE); } lastPtr = fPtr; } return(FALSE); }
static void InitializeFunctionHashTable( void *theEnv) { int i; ExternalFunctionData(theEnv)->FunctionHashtable = (struct FunctionHash **) gm2(theEnv,(int) sizeof (struct FunctionHash *) * SIZE_FUNCTION_HASH); for (i = 0; i < SIZE_FUNCTION_HASH; i++) ExternalFunctionData(theEnv)->FunctionHashtable[i] = NULL; }
static void AddHashFunction( void *theEnv, struct FunctionDefinition *fdPtr) { struct FunctionHash *newhash, *temp; unsigned hashValue; if (ExternalFunctionData(theEnv)->FunctionHashtable == NULL) InitializeFunctionHashTable(theEnv); newhash = get_struct(theEnv,FunctionHash); newhash->fdPtr = fdPtr; hashValue = HashSymbol(fdPtr->callFunctionName->contents,SIZE_FUNCTION_HASH); temp = ExternalFunctionData(theEnv)->FunctionHashtable[hashValue]; ExternalFunctionData(theEnv)->FunctionHashtable[hashValue] = newhash; newhash->next = temp; }
globle struct FunctionDefinition *FindFunction( void *theEnv, const char *functionName) { struct FunctionHash *fhPtr; unsigned hashValue; SYMBOL_HN *findValue; if (ExternalFunctionData(theEnv)->FunctionHashtable == NULL) return(NULL); hashValue = HashSymbol(functionName,SIZE_FUNCTION_HASH); findValue = (SYMBOL_HN *) FindSymbolHN(theEnv,functionName); for (fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[hashValue]; fhPtr != NULL; fhPtr = fhPtr->next) { if (fhPtr->fdPtr->callFunctionName == findValue) { return(fhPtr->fdPtr); } } return(NULL); }
globle struct FunctionDefinition *GetFunctionList( void *theEnv) { return(ExternalFunctionData(theEnv)->ListOfFunctions); }
globle int DefineFunction3( void *theEnv, const char *name, int returnType, int (*pointer)(void *), const char *actualName, const char *restrictions, intBool environmentAware, void *context) { struct FunctionDefinition *newFunction; if ( (returnType != 'a') && (returnType != 'b') && (returnType != 'c') && (returnType != 'd') && (returnType != 'f') && (returnType != 'g') && (returnType != 'i') && (returnType != 'j') && (returnType != 'k') && (returnType != 'l') && (returnType != 'm') && (returnType != 'n') && #if OBJECT_SYSTEM (returnType != 'o') && #endif (returnType != 's') && (returnType != 'u') && (returnType != 'v') && #if OBJECT_SYSTEM (returnType != 'x') && #endif (returnType != 'w') ) { return(0); } newFunction = FindFunction(theEnv,name); if (newFunction == NULL) { newFunction = get_struct(theEnv,FunctionDefinition); newFunction->callFunctionName = (SYMBOL_HN *) EnvAddSymbol(theEnv,name); IncrementSymbolCount(newFunction->callFunctionName); newFunction->next = GetFunctionList(theEnv); ExternalFunctionData(theEnv)->ListOfFunctions = newFunction; AddHashFunction(theEnv,newFunction); } newFunction->returnValueType = (char) returnType; newFunction->functionPointer = (int (*)(void)) pointer; newFunction->actualFunctionName = actualName; if (restrictions != NULL) { if (((int) (strlen(restrictions)) < 2) ? TRUE : ((! isdigit(restrictions[0]) && (restrictions[0] != '*')) || (! isdigit(restrictions[1]) && (restrictions[1] != '*')))) restrictions = NULL; } newFunction->restrictions = restrictions; newFunction->parser = NULL; newFunction->overloadable = TRUE; newFunction->sequenceuseok = TRUE; newFunction->environmentAware = (short) environmentAware; newFunction->usrData = NULL; newFunction->context = context; return(1); }
bool DefineFunction3( void *theEnv, const char *name, int returnType, unsigned returnTypeBits, void (*pointer)(UDFContext *,CLIPSValue *), const char *actualName, int minArgs, int maxArgs, const char *restrictions, void *context) { struct FunctionDefinition *newFunction; if ( (returnType != 'a') && (returnType != 'b') && (returnType != 'c') && (returnType != 'd') && (returnType != 'f') && (returnType != 'g') && (returnType != 'i') && (returnType != 'j') && (returnType != 'k') && (returnType != 'l') && (returnType != 'm') && (returnType != 'n') && #if OBJECT_SYSTEM (returnType != 'o') && #endif (returnType != 's') && (returnType != 'u') && (returnType != 'v') && #if OBJECT_SYSTEM (returnType != 'x') && #endif #if DEFTEMPLATE_CONSTRUCT (returnType != 'y') && #endif (returnType != 'w') && (returnType != 'z')) { return(false); } newFunction = FindFunction(theEnv,name); if (newFunction != NULL) return(0); newFunction = get_struct(theEnv,FunctionDefinition); newFunction->callFunctionName = (SYMBOL_HN *) EnvAddSymbol(theEnv,name); IncrementSymbolCount(newFunction->callFunctionName); newFunction->next = GetFunctionList(theEnv); ExternalFunctionData(theEnv)->ListOfFunctions = newFunction; AddHashFunction(theEnv,newFunction); newFunction->returnValueType = (char) returnType; newFunction->unknownReturnValueType = returnTypeBits; newFunction->functionPointer = pointer; newFunction->actualFunctionName = actualName; newFunction->minArgs = minArgs; newFunction->maxArgs = maxArgs; if ((restrictions != NULL) && (returnType != 'z')) { if (((int) (strlen(restrictions)) < 2) ? true : ((! isdigit(restrictions[0]) && (restrictions[0] != '*')) || (! isdigit(restrictions[1]) && (restrictions[1] != '*')))) restrictions = NULL; } if (restrictions == NULL) { newFunction->restrictions = NULL; } else { newFunction->restrictions = EnvAddSymbol(theEnv,restrictions); IncrementSymbolCount(newFunction->restrictions); } newFunction->parser = NULL; newFunction->overloadable = true; newFunction->sequenceuseok = true; newFunction->usrData = NULL; newFunction->context = context; return(true); }