⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvgenc.c

📁 DataDraw is an ultra-fast persistent database for high performance programs written in C. It s so fa
💻 C
📖 第 1 页 / 共 5 页
字号:
        "    }\n",        dvPrefix, parentName, dvRelationshipGetChildLabel(relationship), childName,        dvClassGetPrefix(theClass), dvClassGetPrefix(childClass));    if(dvRelationshipAccessParent(relationship)) {        dvWrtemp(dvFile,             "    if(%0%2Get%4%1(_%2) != %3%1Null) {\n"            "        utExit(\"Attempting to add %3 to %1 twice\");\n"            "    }\n",            dvPrefix, parentName, childName, dvClassGetPrefix(theClass),            dvRelationshipGetParentLabel(relationship));    }    dvWrtemp(dvFile,         "#endif\n"        "    %0%1Seti%2%3(%1, x, _%3);\n"        "    %0%3Set%1%2Index(_%3, x);\n"        "    %0%1SetUsed%2%3(%1, utMax(%0%1GetUsed%2%3(%1), x + 1));\n",        dvPrefix, parentName, dvRelationshipGetChildLabel(relationship), childName);    if(dvRelationshipAccessParent(relationship)) {        dvWrtemp(dvFile,            "    %0%3Set%2%1(_%3, %1);\n",            dvPrefix, parentName, dvRelationshipGetParentLabel(relationship), childName);    }    dvWrtemp(dvFile, "}\n\n");}/*--------------------------------------------------------------------------------------------------  Write an array append relationship routine for theClass.--------------------------------------------------------------------------------------------------*/static void writeClassArrayAppendFunction(    dvClass theClass,    dvRelationship relationship){    char *parentName = dvClassGetName(theClass);    dvClass childClass = dvRelationshipGetChildClass(relationship);    char *childName = dvClassGetName(childClass);    dvWrtemp(dvFile,         "/*----------------------------------------------------------------------------------------\n"        "  Add the %2%3 to the end of the %1%2%3% array.\n"        "----------------------------------------------------------------------------------------*/\n"        "void %0%1Append%2%3(\n"        "    %4%1 %1,\n"        "    %5%3 _%3)\n"        "{\n"        "    uint32 used%2%3 = %0%1GetUsed%2%3(%1);\n"        "\n"        "#if defined(DD_DEBUG)\n"        "    if(%1 == %4%1Null) {\n"        "        utExit(\"Non existent %1\");\n"        "    }\n"        "#endif\n"        "    if(used%2%3 >= %0%1GetNum%2%3(%1)) {\n"        "        %0%1Resize%2%3s(%1, used%2%3 + (used%2%3 << 1) + 1);\n"        "    }\n"        "    %0%1Seti%2%3(%1, used%2%3, _%3);\n"        "    %0%3Set%1%2Index(_%3, used%2%3);\n"        "    %0%1SetUsed%2%3(%1, used%2%3 + 1);\n",        dvPrefix, parentName, dvRelationshipGetChildLabel(relationship), childName,        dvClassGetPrefix(theClass), dvClassGetPrefix(childClass));    if(dvRelationshipAccessParent(relationship)) {        dvWrtemp(dvFile,            "    %0%3Set%2%1(_%3, %1);\n",            dvPrefix, parentName, dvRelationshipGetParentLabel(relationship), childName);    }    dvWrtemp(dvFile, "}\n\n");}/*--------------------------------------------------------------------------------------------------  Write a delete relationship routine for array relationship.--------------------------------------------------------------------------------------------------*/static void writeClassRemoveArray(    dvClass theClass,    dvRelationship relationship){    char *parentName = dvClassGetName(theClass);    dvClass childClass = dvRelationshipGetChildClass(relationship);    char *childName = dvClassGetName(childClass);    char *childLabel = dvRelationshipGetChildLabel(relationship);        dvWrtemp(dvFile,         "/*----------------------------------------------------------------------------------------\n"        "  Remove the %2%3 from the %1.\n"        "----------------------------------------------------------------------------------------*/\n"        "void %0%1Remove%2%3(\n"        "    %4%1 %1,\n"        "    %5%3 _%3)\n"        "{\n",        dvPrefix, parentName, childLabel, childName, dvClassGetPrefix(theClass),        dvClassGetPrefix(childClass));    dvWrtemp(dvFile,        "#if defined(DD_DEBUG)\n"        "    if(_%3 == %5%3Null) {\n"        "        utExit(\"Non-existent %3\");\n"        "    }\n",        dvPrefix, parentName, childLabel, childName, dvClassGetPrefix(theClass),        dvClassGetPrefix(childClass));    if(dvRelationshipAccessParent(relationship)) {        dvWrtemp(dvFile,             "    if(%0%3Get%1%2(_%3) != %4%2Null && %0%3Get%1%2(_%3) != %2) {\n"            "        utExit(\"Delete %3 from non-owning %2\");\n"            "    }\n",            dvPrefix,  dvRelationshipGetParentLabel(relationship), parentName, childName,            dvClassGetPrefix(theClass));    }    dvWrtemp(dvFile,         "#endif\n"        "    %0%1Seti%2%3(%1, %0%3Get%1%2Index(_%3), %5%3Null);\n"        "    %0%3Set%1%2Index(_%3, UINT32_MAX);\n",        dvPrefix, parentName, dvRelationshipGetChildLabel(relationship), childName,        dvClassGetPrefix(theClass), dvClassGetPrefix(childClass));    if(dvRelationshipAccessParent(relationship)) {        dvWrtemp(dvFile,            "    %0%1Set%2%3(_%1, %4%3Null);\n",            dvPrefix, childName, dvRelationshipGetParentLabel(relationship), parentName,            dvClassGetPrefix(theClass));    }    dvWrtemp(dvFile, "}\n\n");}/*--------------------------------------------------------------------------------------------------  Write the allocation for the property fields of theClass.--------------------------------------------------------------------------------------------------*/static void writeClassPropFieldAllocs(    dvClass theClass){    dvUnion theUnion;    dvProperty prop;    char *name = dvClassGetName(theClass);    dvForeachClassProperty(theClass, prop) {        if(dvPropertyGetUnion(prop) == dvUnionNull) {            if(!dvPropertyArray(prop)) {                dvWrtemp(dvFile,                     "    %0%1s.%2 = utNewA(%4, (%3Allocated%1()%5);\n",                    dvPrefix, name, dvPropertyGetName(prop), dvClassGetPrefix(theClass),                    dvPropertyGetTypeName(prop),                    dvPropertyGetType(prop) == PROP_BIT? " + 7) >> 3" : ")");                if(dvClassGetBaseClass(theClass) != dvClassNull) {                    dvWrtemp(dvFile,                        "    memset(%0%1s.%2, %4, ((%3Allocated%1()%6)*sizeof(%5));\n",                        dvPrefix, name, dvPropertyGetName(prop), dvClassGetPrefix(theClass),                        dvPropertyFindInitValue(prop), dvPropertyGetTypeName(prop),                        dvPropertyGetType(prop) == PROP_BIT? " + 7) >> 3" : ")");                }            } else {                dvWrtemp(dvFile,                     "    %0SetUsed%1%2(0);\n"                    "    %0SetAllocated%1%2(2);\n"                    "    %0SetFree%1%2(0);\n"                    "    %0%1s.%2 = utNewA(%4, %0Allocated%1%2());\n",                    dvPrefix, name, dvPropertyGetName(prop), dvClassGetPrefix(theClass),                    dvPropertyGetTypeName(prop));            }        }    } dvEndForeachClassProperty;    dvForeachClassUnion(theClass, theUnion) {        dvWrtemp(dvFile,             "    %0%1s.%3 = utNewA(%4, %2Allocated%1());\n",            dvPrefix, dvClassGetName(theClass), dvClassGetPrefix(theClass),            dvUnionGetFieldName(theUnion), dvUnionGetTypeName(theUnion));        if(dvClassGetBaseClass(theClass) != dvClassNull) {            dvWrtemp(dvFile,                "    memset(%0%1s.%3, %5, %2Allocated%1()*sizeof(%4));\n",                dvPrefix, dvClassGetName(theClass), dvClassGetPrefix(theClass),                dvUnionGetFieldName(theUnion), dvUnionGetTypeName(theUnion),                dvPropertyFindInitValue(dvUnionGetFirstProperty(theUnion)));        }    } dvEndForeachClassUnion;}/*--------------------------------------------------------------------------------------------------  Write the reallocation for the property fields of theClass.--------------------------------------------------------------------------------------------------*/static void writeClassPropFieldReallocs(    dvClass theClass){    dvUnion theUnion;    dvProperty prop;    char *name = dvClassGetName(theClass);    dvForeachClassProperty(theClass, prop) {        if(!dvPropertyArray(prop) && dvPropertyGetUnion(prop) == dvUnionNull) {            if(dvClassUndo(theClass)) {                dvWrtemp(dvFile,                     "    utRecordResize(%0ModuleID, %3, (%2Allocated%1()%4, true);\n",                    dvPrefix, name, dvClassGetPrefix(theClass),                    utSprintf("%u", dvPropertyGetFieldNumber(prop)),                    dvPropertyGetType(prop) == PROP_BIT? " + 7) >> 3" : ")");            }            dvWrtemp(dvFile,                 "    utResizeArray(%0%1s.%2, (newSize%4);\n",                dvPrefix, name, dvPropertyGetName(prop), dvClassGetPrefix(theClass),                dvPropertyGetType(prop) == PROP_BIT? " + 7) >> 3" : ")");            if(dvClassRedo(theClass)) {                dvWrtemp(dvFile,                     "    utRecordResize(%0ModuleID, %3, (newSize%4, false);\n",                    dvPrefix, name, dvClassGetPrefix(theClass),                    utSprintf("%u", dvPropertyGetFieldNumber(prop)),                    dvPropertyGetType(prop) == PROP_BIT? " + 7) >> 3" : ")");            }        }    } dvEndForeachClassProperty;    dvForeachClassUnion(theClass, theUnion) {        if(dvClassUndo(theClass)) {            dvWrtemp(dvFile,                 "    utRecordResize(%0ModuleID, %3, %2Allocated%1(), true);\n",                dvPrefix, dvClassGetName(theClass), dvClassGetPrefix(theClass),                utSprintf("%u", dvUnionGetFieldNumber(theUnion)));        }        dvWrtemp(dvFile,             "    utResizeArray(%0%1s.%2, newSize);\n",            dvPrefix, dvClassGetName(theClass), dvUnionGetFieldName(theUnion),            dvClassGetPrefix(theClass));        if(dvClassRedo(theClass)) {            dvWrtemp(dvFile,                 "    utRecordResize(%0ModuleID, %3, newSize, false);\n",                dvPrefix, dvClassGetName(theClass), dvClassGetPrefix(theClass),                utSprintf("%u", dvPropertyGetFieldNumber(prop)));        }    } dvEndForeachClassUnion;}/*--------------------------------------------------------------------------------------------------  Write the free statements for the property fields of theClass.--------------------------------------------------------------------------------------------------*/static void writeClassPropFieldFrees(    dvClass theClass){    dvUnion theUnion;    dvProperty prop;    char *name = dvClassGetName(theClass);    dvForeachClassProperty(theClass, prop) {        if(dvPropertyGetUnion(prop) == dvUnionNull) {            dvWrtemp(dvFile,                 "    utFree(%0%1s.%2);\n",                dvPrefix, name, dvPropertyGetName(prop));        }    } dvEndForeachClassProperty;    dvForeachClassUnion(theClass, theUnion) {        dvWrtemp(dvFile,             "    utFree(%0%1s.%2);\n",            dvPrefix, dvClassGetName(theClass), dvUnionGetFieldName(theUnion));    } dvEndForeachClassUnion;}/*--------------------------------------------------------------------------------------------------  Write out the allocation stuff for a class.--------------------------------------------------------------------------------------------------*/static void writeClassAllocs(    dvClass theClass){    char *name = dvClassGetName(theClass);    dvWrtemp(dvFile,         "/*----------------------------------------------------------------------------------------\n"        "  Allocate the field arrays of %1.\n"        "----------------------------------------------------------------------------------------*/\n"        "static void alloc%1s(void)\n"        "{\n", dvPrefix, name);    if(dvClassGetBaseClass(theClass) == dvClassNull) {        dvWrtemp(dvFile,            "    %0SetAllocated%1(2);\n"            "    %0SetUsed%1(0);\n",            dvPrefix, name);        if(dvClassGetMemoryStyle(theClass) == MEM_FREE_LIST) {            dvWrtemp(dvFile,                "    %0SetFirstFree%1(%0%1Null);\n",                dvPrefix, name);        }    }    writeClassPropFieldAllocs(theClass);    if(dvClassGetBaseClass(theClass) != dvClassNull) {        dvWrtemp(dvFile,             "    %0SetAllocated%1(%2Allocated%1());\n"            "    %0%1ConstructorCallback = %2%1GetConstructorCallback();\n"            "    %2%1SetConstructorCallback(init%1);\n",            dvPrefix, name, dvClassGetPrefix(theClass));        if(dvClassGetMemoryStyle(theClass) == MEM_FREE_LIST) {            dvWrtemp(dvFile,                 "    %0%1DestructorCallback = %2%1GetDestructorCallback();\n"                "    %2%1SetDestructorCallback(destroy%1);\n",                dvPrefix, name, dvClassGetPrefix(theClass));        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -