コード例 #1
0
ファイル: classpsr.c プロジェクト: nickmain/CLIPS
/*******************************************************
  NAME         : BuildSubclassLinks
  DESCRIPTION  : Follows the list of superclasses
                 for a class and puts the class in
                 each of the superclasses' subclass
                 list.
  INPUTS       : The address of the class
  RETURNS      : Nothing useful
  SIDE EFFECTS : The subclass lists for every superclass
                 are modified.
  NOTES        : Assumes the superclass list is formed.
 *******************************************************/
static void BuildSubclassLinks(
  void *theEnv,
  DEFCLASS *cls)
  {
   long i;

   for (i = 0 ; i < cls->directSuperclasses.classCount ; i++)
     AddClassLink(theEnv,&cls->directSuperclasses.classArray[i]->directSubclasses,cls,-1);
  }
コード例 #2
0
ファイル: classini.c プロジェクト: DrItanium/AdventureEngine
/*********************************************************
  NAME         : AddSystemClass
  DESCRIPTION  : Performs all necessary allocations
                   for adding a system class
  INPUTS       : 1) The name-string of the system class
                 2) The address of the parent class
                    (NULL if none)
  RETURNS      : The address of the new system class
  SIDE EFFECTS : Allocations performed
  NOTES        : Assumes system-class name is unique
                 Also assumes SINGLE INHERITANCE for
                   system classes to simplify precedence
                   list determination
                 Adds classes to has table but NOT to
                  class list (this is responsibility
                  of caller)
 *********************************************************/
static DEFCLASS *AddSystemClass(
    void *theEnv,
    char *name,
    DEFCLASS *parent)
{
    DEFCLASS *sys;
    long i;
    char defaultScopeMap[1];

    sys = NewClass(theEnv,(SYMBOL_HN *) EnvAddSymbol(theEnv,name));
    sys->abstract = 1;
#if DEFRULE_CONSTRUCT
    sys->reactive = 0;
#endif
    IncrementSymbolCount(sys->header.name);
    sys->installed = 1;
    sys->system = 1;
    sys->hashTableIndex = HashClass(sys->header.name);

    AddClassLink(theEnv,&sys->allSuperclasses,sys,-1);
    if (parent != NULL)
    {
        AddClassLink(theEnv,&sys->directSuperclasses,parent,-1);
        AddClassLink(theEnv,&parent->directSubclasses,sys,-1);
        AddClassLink(theEnv,&sys->allSuperclasses,parent,-1);
        for (i = 1 ; i < parent->allSuperclasses.classCount ; i++)
            AddClassLink(theEnv,&sys->allSuperclasses,parent->allSuperclasses.classArray[i],-1);
    }
    sys->nxtHash = DefclassData(theEnv)->ClassTable[sys->hashTableIndex];
    DefclassData(theEnv)->ClassTable[sys->hashTableIndex] = sys;

    /* =========================================
       Add default scope maps for a system class
       There is only one module (MAIN) so far -
       which has an id of 0
       ========================================= */
    ClearBitString((void *) defaultScopeMap,(int) sizeof(char));
    SetBitMap(defaultScopeMap,0);
#if DEFMODULE_CONSTRUCT
    sys->scopeMap = (BITMAP_HN *) EnvAddBitMap(theEnv,(void *) defaultScopeMap,(int) sizeof(char));
    IncrementBitMapCount(sys->scopeMap);
#endif
    return(sys);
}
コード例 #3
0
ファイル: classini.c プロジェクト: DrItanium/AdventureEngine
/***************************************************************
  NAME         : CreateSystemClasses
  DESCRIPTION  : Creates the built-in system classes
  INPUTS       : None
  RETURNS      : Nothing useful
  SIDE EFFECTS : System classes inserted in the
                   class hash table
  NOTES        : The binary/load save indices for the primitive
                   types (integer, float, symbol and string,
                   multifield, external-address and fact-address)
                   are very important.  Need to be able to refer
                   to types with the same index regardless of
                   whether the object system is installed or
                   not.  Thus, the bsave/blaod indices of these
                   classes match their integer codes.
                WARNING!!: Assumes no classes exist yet!
 ***************************************************************/
globle void CreateSystemClasses(
    void *theEnv)
{
    DEFCLASS *user,*any,*primitive,*number,*lexeme,*address,*instance;
#if DEFRULE_CONSTRUCT
    DEFCLASS *initialObject;
#endif

    /* ===================================
       Add canonical slot name entries for
       the is-a and name fields - used for
       object patterns
       =================================== */
    AddSlotName(theEnv,DefclassData(theEnv)->ISA_SYMBOL,ISA_ID,TRUE);
    AddSlotName(theEnv,DefclassData(theEnv)->NAME_SYMBOL,NAME_ID,TRUE);

    /* =========================================================
       Bsave Indices for non-primitive classes start at 9
                Object is 9, Primitive is 10, Number is 11,
                Lexeme is 12, Address is 13, and Instance is 14.
       because: float = 0, integer = 1, symbol = 2, string = 3,
                multifield = 4, and external-address = 5 and
                fact-address = 6, instance-adress = 7 and
                instance-name = 8.
       ========================================================= */
    any = AddSystemClass(theEnv,OBJECT_TYPE_NAME,NULL);
    primitive = AddSystemClass(theEnv,PRIMITIVE_TYPE_NAME,any);
    user = AddSystemClass(theEnv,USER_TYPE_NAME,any);

    number = AddSystemClass(theEnv,NUMBER_TYPE_NAME,primitive);
    DefclassData(theEnv)->PrimitiveClassMap[INTEGER] = AddSystemClass(theEnv,INTEGER_TYPE_NAME,number);
    DefclassData(theEnv)->PrimitiveClassMap[FLOAT] = AddSystemClass(theEnv,FLOAT_TYPE_NAME,number);
    lexeme = AddSystemClass(theEnv,LEXEME_TYPE_NAME,primitive);
    DefclassData(theEnv)->PrimitiveClassMap[SYMBOL] = AddSystemClass(theEnv,SYMBOL_TYPE_NAME,lexeme);
    DefclassData(theEnv)->PrimitiveClassMap[STRING] = AddSystemClass(theEnv,STRING_TYPE_NAME,lexeme);
    DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD] = AddSystemClass(theEnv,MULTIFIELD_TYPE_NAME,primitive);
    address = AddSystemClass(theEnv,ADDRESS_TYPE_NAME,primitive);
    DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS] = AddSystemClass(theEnv,EXTERNAL_ADDRESS_TYPE_NAME,address);
    DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS] = AddSystemClass(theEnv,FACT_ADDRESS_TYPE_NAME,address);
    instance = AddSystemClass(theEnv,INSTANCE_TYPE_NAME,primitive);
    DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS] = AddSystemClass(theEnv,INSTANCE_ADDRESS_TYPE_NAME,instance);
    DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME] = AddSystemClass(theEnv,INSTANCE_NAME_TYPE_NAME,instance);
#if DEFRULE_CONSTRUCT
    initialObject = AddSystemClass(theEnv,INITIAL_OBJECT_CLASS_NAME,user);
    initialObject->abstract = 0;
    initialObject->reactive = 1;
#endif

    /* ================================================================================
        INSTANCE-ADDRESS is-a INSTANCE and ADDRESS.  The links between INSTANCE-ADDRESS
        and ADDRESS still need to be made.
        =============================================================================== */
    AddClassLink(theEnv,&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS]->directSuperclasses,address,-1);
    AddClassLink(theEnv,&DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS]->allSuperclasses,address,2);
    AddClassLink(theEnv,&address->directSubclasses,DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS],-1);

    /* =======================================================================
       The order of the class in the list MUST correspond to their type codes!
       See CONSTANT.H
       ======================================================================= */
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[FLOAT]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[INTEGER]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[SYMBOL]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[STRING]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[MULTIFIELD]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[EXTERNAL_ADDRESS]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[FACT_ADDRESS]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_ADDRESS]);
    AddConstructToModule((struct constructHeader *) DefclassData(theEnv)->PrimitiveClassMap[INSTANCE_NAME]);
    AddConstructToModule((struct constructHeader *) any);
    AddConstructToModule((struct constructHeader *) primitive);
    AddConstructToModule((struct constructHeader *) number);
    AddConstructToModule((struct constructHeader *) lexeme);
    AddConstructToModule((struct constructHeader *) address);
    AddConstructToModule((struct constructHeader *) instance);
    AddConstructToModule((struct constructHeader *) user);
#if DEFRULE_CONSTRUCT
    AddConstructToModule((struct constructHeader *) initialObject);
#endif
    for (any = (DEFCLASS *) EnvGetNextDefclass(theEnv,NULL) ;
            any != NULL ;
            any = (DEFCLASS *) EnvGetNextDefclass(theEnv,(void *) any))
        AssignClassID(theEnv,any);
}