📄 dvgenh.c
字号:
dvModule module){ dvClass theClass; dvWrtemp(dvFile, "/*----------------------------------------------------------------------------------------\n" " Temp Union structure - Macro temp variables, use only one\n" "----------------------------------------------------------------------------------------*/\n" "union %0TempType_ {\n" , dvPrefix); dvForeachModuleClass(module, theClass) { dvWrtemp(dvFile, " %0%1 %1;\n", dvClassGetPrefix(theClass), dvClassGetName(theClass)); } dvEndForeachModuleClass; fputs("};\n\n", dvFile); dvWrtemp(dvFile, "extern union %0TempType_ %0Temp_;\n\n", dvPrefix);}/*-------------------------------------------------------------------------------------------------- Write out union types for the class.--------------------------------------------------------------------------------------------------*/static void writeUnionTypes( dvClass theClass){ dvUnion theUnion; dvProperty property; if(dvClassGetFirstUnion(theClass) == dvUnionNull) { return; } dvWrtemp(dvFile, "/*----------------------------------------------------------------------------------------\n" " Unions for class %0.\n" "----------------------------------------------------------------------------------------*/\n" , dvClassGetName(theClass)); dvForeachClassUnion(theClass, theUnion) { dvWrtemp(dvFile, "typedef union {\n"); dvForeachUnionProperty(theUnion, property) { dvWrtemp(dvFile, " %0 %1;\n", dvPropertyGetTypeName(property), dvPropertyGetName(property)); }dvEndForeachUnionProperty; dvWrtemp(dvFile, "} %0;\n\n", dvUnionGetTypeName(theUnion)); } dvEndForeachClassUnion;}/*-------------------------------------------------------------------------------------------------- Write out the property fields for theClass.--------------------------------------------------------------------------------------------------*/static void writeClassFields( dvClass theClass){ dvUnion theUnion; dvProperty prop; dvForeachClassProperty(theClass, prop) { if(dvPropertyGetUnion(prop) == dvUnionNull) { dvWrtemp(dvFile, " %0 *%1;\n", dvPropertyGetTypeName(prop), dvPropertyGetName(prop)); } } dvEndForeachClassProperty; dvForeachClassUnion(theClass, theUnion) { dvWrtemp(dvFile, " %0 *%1;\n", dvUnionGetTypeName(theUnion), dvUnionGetFieldName(theUnion)); } dvEndForeachClassUnion;}/*-------------------------------------------------------------------------------------------------- Write out the structure for a class.--------------------------------------------------------------------------------------------------*/static void writeClassStruct( dvClass theClass){ char *name = dvClassGetName(theClass); dvWrtemp(dvFile, "/*----------------------------------------------------------------------------------------\n" " Fields for class %1.\n" "----------------------------------------------------------------------------------------*/\n" "struct %0%1Fields {\n", dvPrefix, name); writeClassFields(theClass); dvWrtemp(dvFile, "};\n" "extern struct %0%1Fields %0%1s;\n" "\n", dvPrefix, name);}/*-------------------------------------------------------------------------------------------------- Write the header's bottom portion.--------------------------------------------------------------------------------------------------*/static void writeHeaderBot( dvModule module){ dvWrtemp(dvFile, "extern uint8 %0ModuleID;\n", dvPrefix); dvWrtemp(dvFile, "void %0DatabaseStart(void);\n" "void %0DatabaseStop(void);\n" "#if defined __cplusplus\n" "}\n" "#endif\n\n" "#endif\n", dvPrefix);}/*-------------------------------------------------------------------------------------------------- Write object's create function declaration.--------------------------------------------------------------------------------------------------*/static void writeClassCreateExternFunc( dvClass theClass){ dvProperty prop; char *name = dvClassGetName(theClass); if(dvClassGetBaseClass(theClass) == dvClassNull) { if(dvClassGetMemoryStyle(theClass) == MEM_FREE_LIST) { dvWrtemp(dvFile, "#define %0%1Free(%1) (", dvPrefix, name); dvForeachClassProperty(theClass, prop) { if(dvPropertyArray(prop)) { dvWrtemp(dvFile, "%0%1Free%2s(%1), \\\n ", dvPrefix, name, dvPropertyGetName(prop)); } } dvEndForeachClassProperty; dvWrtemp(dvFile, "%0%1SetNextFree(%1, %0RootData.firstFree%1), \\\n" " %0SetFirstFree%1(%1))\n" "void %0%1Destroy(%0%1 %1);\n", dvPrefix, name); } dvWrtemp(dvFile, "void %0%1AllocMore(void);\n", dvPrefix, name); }}/*-------------------------------------------------------------------------------------------------- Write the object's function declarations for property allocs.--------------------------------------------------------------------------------------------------*/static void writeClassPropExternFuncs( dvClass theClass){ char *name = dvClassGetName(theClass); dvProperty prop; dvForeachClassProperty(theClass, prop) { if(dvPropertyArray(prop)) { dvWrtemp(dvFile, "void %0%1Alloc%2s(%3%1 %1, uint32 num%2s);\n" "void %0%1Resize%2s(%3%1 %1, uint32 num%2s);\n" "void %0%1Free%2s(%3%1 %1);\n" "void %0Compact%1%2s(void);\n", dvPrefix, name, dvPropertyGetName(prop), dvClassGetPrefix(theClass)); } } dvEndForeachClassProperty;}/*-------------------------------------------------------------------------------------------------- Write the object's extern function declarations for relationships.--------------------------------------------------------------------------------------------------*/static void writeClassRelExternFuncs( dvClass theClass){ dvRelationship relationship; dvClass childClass; dvRelationshipType type; char *name = dvClassGetName(theClass); char *childLabel, *childName; dvForeachClassChildRelationship(theClass, relationship) { type = dvRelationshipGetType(relationship); childClass = dvRelationshipGetChildClass(relationship); childLabel = dvRelationshipGetChildLabel(relationship); childName = dvClassGetName(childClass); if(dvRelationshipAccessChild(relationship)) { if(type == REL_LINKED_LIST || type == REL_DOUBLY_LINKED || type == REL_TAIL_LINKED || type == REL_HASHED) { dvWrtemp(dvFile, "void %0%1Insert%2%3(%4%1 %1, %5%3 _%3);\n" "void %0%1Remove%2%3(%4%1 %1, %5%3 _%3);\n" "void %0%1InsertAfter%2%3(%4%1 %1, %5%3 prev%3, %5%3 _%3);\n", dvPrefix, name, childLabel, childName, dvClassGetPrefix(theClass), dvClassGetPrefix(childClass)); if(type != REL_LINKED_LIST) { dvWrtemp(dvFile, "void %0%1Append%2%3(%4%1 %1, %5%3 _%3);\n", dvPrefix, name, childLabel, childName, dvClassGetPrefix(theClass), dvClassGetPrefix(childClass)); } } else if(type == REL_ARRAY) { dvWrtemp(dvFile, "void %0%1Insert%2%3(%4%1 %1, uint32 x, %5%3 _%3);\n" "void %0%1Append%2%3(%4%1 %1, %5%3 _%3);\n" "void %0%1Remove%2%3(%4%1 %1, %5%3 _%3);\n", dvPrefix, name, childLabel, dvClassGetName(childClass), dvClassGetPrefix(theClass), dvClassGetPrefix(childClass)); } } } dvEndForeachClassChildRelationship;}/*-------------------------------------------------------------------------------------------------- Write the external function declarations for an object.--------------------------------------------------------------------------------------------------*/static void writeClassExternFuncs( dvClass theClass){ fputs("\n", dvFile); writeClassCreateExternFunc(theClass); writeClassPropExternFuncs(theClass); writeClassRelExternFuncs(theClass); fputs("\n", dvFile);}/*-------------------------------------------------------------------------------------------------- Write the class's property access macros.--------------------------------------------------------------------------------------------------*/static void writeClassPropMacros( dvClass theClass){ dvUnion theUnion; dvProperty prop; char *name; char *propName, *preString, *postString; dvForeachClassProperty(theClass, prop) { name = dvClassGetName(theClass); propName = dvPropertyGetName(prop); if(dvPropertyArray(prop)) { dvWrtemp(dvFile, "#if defined(DD_DEBUG)\n" "#define %0%1Check%2Index(%1, x) ((%4)(x) < %0%1GetNum%2(%1)? (x) : \\\n" " (utAssert(false),(x)))\n" "#else\n" "#define %0%1Check%2Index(%1, x) (x)\n" "#endif\n" "#define %0%1Geti%2(_%1, x) ((%0%1s.%2)[ \\\n" " %0%1Get%2Index(_%1) + %0%1Check%2Index(_%1, (x))])\n" "#define %0%1Get%2s(%1) (%0%1s.%2 + %0%1Get%2Index(%1))\n", dvPrefix, name, propName, dvClassGetPrefix(theClass), dvClassGetReferenceTypeName(theClass)); preString = dvSwrtemp(!dvClassUndo(theClass)? "" : " \\\n (void)utRecordArray(%0ModuleID, %3, %0%1Get%2Index(%1), " "%0%1GetNum%2(%1), true), \\\n ", dvPrefix, name, propName, utSprintf("%u", dvPropertyGetFieldNumber(prop))); postString = dvSwrtemp(!dvClassRedo(theClass)? "" : ", \\\n (void)utRecordArray(%0ModuleID, %3, %0%1Get%2Index(%1), " "%0%1GetNum%2(%1), false)", dvPrefix, name, propName, utSprintf("%u", dvPropertyGetFieldNumber(prop))); dvWrtemp(dvFile, "#define %0%1Set%2(%1, valuePtr) (%4memcpy(%0%1Get%2s(%1), valuePtr, \\\n" " %0%1GetNum%2(%1)*sizeof(%3))%5)\n", dvPrefix, name, propName, dvPropertyGetTypeName(prop), preString, postString); preString = dvSwrtemp(!dvClassUndo(theClass)? "" : " \\\n (void)utRecordField(%0ModuleID, %3, %0%1Get%2Index(%1) + (x), true)," " \\\n ", dvPrefix, name, propName, utSprintf("%u", dvPropertyGetFieldNumber(prop))); postString = dvSwrtemp(!dvClassRedo(theClass)? "" : ", \\\n (void)utRecordField(%0ModuleID, %3, %0%1Get%2Index(%1) + (x), false)",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -