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

📄 gencode.c

📁 这是关于RFC3261实现sip的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			if (td -> module != pt -> module)				continue;			fqname = NULL;			mname = NULL;			sat = "unknown";			switch (td -> type.atype)			{			case string_type:				sat = (td -> type.nrderefs == 0 ? "char" : "string");				break;			case sstring_type:				sat = (td -> type.nrderefs == 0 ? "schar" : "sstring");				break;			case ustring_type:				sat = (td -> type.nrderefs == 0 ? "uchar" : "ustring");				break;			case short_type:				sat = "short";				break;			case ushort_type:				sat = "ushort";				break;			case cint_type:			case int_type:				sat = "int";				break;			case uint_type:				sat = "uint";				break;			case long_type:				sat = "long";				break;			case ulong_type:				sat = "ulong";				break;			case longlong_type:				sat = "longlong";				break;			case ulonglong_type:				sat = "ulonglong";				break;			case cfloat_type:			case float_type:				sat = "float";				break;			case cdouble_type:			case double_type:				sat = "double";				break;			case bool_type:			case cbool_type:				sat = "bool";				break;			case void_type:				if (td -> type.nrderefs != 0)					sat = "void";				break;			case enum_type:				if ((fqname = td -> type.u.ed -> fqcname) != NULL)				{					sat = "enum";					if (td -> type.u.ed -> module != pt -> module)						mname = td -> type.u.ed -> module -> name;				}				break;			case class_type:				sat = "class";				fqname = classFQCName(td -> type.u.cd);				if (td -> type.u.cd -> iff -> module != pt -> module)					mname = td -> type.u.cd -> iff -> module -> name;				break;			case mapped_type:				sat = "mtype";				fqname = td -> type.u.mtd -> iff -> fqcname;				if (td -> type.u.mtd -> iff -> module != pt -> module)					mname = td -> type.u.mtd -> iff -> module -> name;				break;			}			prcode(fp,"	{\"%S\", %s_sat", td -> fqname, sat);			if (fqname != NULL)				prcode(fp, ", \"%S\"", fqname);			else				prcode(fp, ", NULL");			if (mname != NULL)				prcode(fp, ", \"%s\"", mname);			else				prcode(fp, ", NULL");			prcode(fp, "},\n"				);		}		prcode(fp,"	{NULL, unknown_sat, NULL, NULL}\n""};\n"			);	}	if (pt -> module -> nrvirthandlers > 0)	{		prcode(fp,"\n""\n""/*\n"" * This defines the virtual handlers that this module implements and can be\n"" * used by other modules.\n"" */\n""static sipVirtHandlerFunc virtHandlersTable[] = {\n"			);		for (vhd = pt -> module -> virthandlers; vhd != NULL; vhd = vhd -> next)			if (!isDuplicateVH(vhd))				prcode(fp,"	(sipVirtHandlerFunc)sipVH_%s_%d,\n"					,mname,vhd -> virthandlernr);		prcode(fp,"};\n"			);	}	if (pt->allimports != NULL)	{		prcode(fp,"\n""\n""/* This defines the modules that this module needs to import. */\n""static sipImportedModuleDef importsTable[] = {\n"			);		for (mld = pt->allimports; mld != NULL; mld = mld->next)			prcode(fp,"	{\"%s\", %d, NULL},\n"				, mld->module->fullname, mld->module->version);		prcode(fp,"	{NULL, -1, NULL}\n""};\n"			);	}	if (nrSccs > 0)	{		prcode(fp,"\n""\n""/* This defines the class sub-convertors that this module defines. */\n""static sipSubClassConvertorDef convertorsTable[] = {\n"			);		for (cd = pt -> classes; cd != NULL; cd = cd -> next)		{			if (cd -> iff -> module != pt -> module)				continue;			if (cd -> convtosubcode == NULL)				continue;			prcode(fp,"	{sipSubClass_%C, ",classFQCName(cd));			generateEncodedClass(pt,cd -> subbase,0,fp);			prcode(fp,", NULL},\n");		}		prcode(fp,"	{NULL, {0, 0, 0}, NULL}\n""};\n"			);	}	/* Generate any license information. */	if (pt -> module -> license != NULL)	{		licenseDef *ld = pt -> module -> license;		prcode(fp,"\n""\n""/* Define the module's license. */\n""static sipLicenseDef module_license = {\n"			);		prcode(fp,"	\"%s\",\n"			,ld -> type);		if (ld -> licensee != NULL)			prcode(fp,"	\"%s\",\n"				,ld -> licensee);		else			prcode(fp,"	NULL,\n"				);		if (ld -> timestamp != NULL)			prcode(fp,"	\"%s\",\n"				,ld -> timestamp);		else			prcode(fp,"	NULL,\n"				);		if (ld -> sig != NULL)			prcode(fp,"	\"%s\"\n"				,ld -> sig);		else			prcode(fp,"	NULL\n"				);		prcode(fp,"};\n"			);	}	/* Generate each instance table. */	is_inst_class = generateClasses(pt,NULL,fp);	is_inst_voidp = generateVoidPointers(pt,NULL,fp);	is_inst_char = generateChars(pt,NULL,fp);	is_inst_string = generateStrings(pt,NULL,fp);	is_inst_int = generateInts(pt,NULL,fp);	is_inst_long = generateLongs(pt,NULL,fp);	is_inst_ulong = generateUnsignedLongs(pt,NULL,fp);	is_inst_longlong = generateLongLongs(pt,NULL,fp);	is_inst_ulonglong = generateUnsignedLongLongs(pt,NULL,fp);	is_inst_double = generateDoubles(pt,NULL,fp);	is_inst_enum = generateEnums(pt,NULL,fp);	/* Generate any exceptions table. */	if (pt->module->nrexceptions > 0)	       prcode(fp,"\n""\n""static PyObject *exceptionsTable[%d];\n"			,pt->module->nrexceptions);	/* Generate any Qt support API. */	if (pt->qobjclass >= 0)		prcode(fp,"\n""\n""/* This defines the Qt support API. */\n""static sipQtAPI qtAPI = {\n""	&typesTable[%d],\n""	sipQtIsQtSignal,\n""	sipQtCreateUniversalSignalShortcut,\n""	sipQtCreateUniversalSignal,\n""	sipQtFindUniversalSignalShortcut,\n""	sipQtFindUniversalSignal,\n""	sipQtEmitSignalShortcut,\n""	sipQtEmitSignal,\n""	sipQtCreateUniversalSlot,\n""	sipQtDestroyUniversalSlot,\n""	sipQtFindSlot,\n""	sipQtConnect,\n""	sipQtDisconnect,\n""	sipQtSignalsBlocked,\n""	sipQtGetSender,\n""	sipQtForgetSender,\n""	sipQtSameSignalSlotName\n""};\n"			,pt->qobjclass);	prcode(fp,"\n""\n""/* This defines this module. */\n""sipExportedModuleDef sipModuleAPI_%s = {\n""	NULL,\n""	SIP_API_MINOR_NR,\n""	\"%s\",\n""	NULL,\n""	%d,\n""	%s,\n""	%s,\n""	%d,\n""	%s,\n""	%s,\n""	%s,\n""	%d,\n""	NULL,\n""	%s,\n""	%d,\n""	%s,\n""	%s,\n""	%s,\n""	%s,\n""	{%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s},\n""	%s,\n""	%s,\n""	%s,\n""	%s,\n""	%s,\n""	NULL\n""};\n"		,mname		, pt->module->fullname		,pt -> module -> version		,(pt->allimports != NULL ? "importsTable" : "NULL")		,(pt -> qobjclass >= 0 ? "&qtAPI" : "NULL")		,pt -> module -> nrclasses		,(pt -> module -> nrclasses > 0 ? "typesTable" : "NULL")		, (hasexternal ? "externalTypesTable" : "NULL")		,(pt -> module -> nrmappedtypes > 0 ? "mappedTypesTable" : "NULL")		,pt -> module -> nrenums		,(pt -> module -> nrenums > 0 ? "enumTypesTable" : "NULL")		,nr_enummembers		,(nr_enummembers > 0 ? "enummembers" : "NULL")		,(pt -> module -> nrtypedefs > 0 ? "typedefsTable" : "NULL")		,(pt -> module -> nrvirthandlers > 0 ? "virtHandlersTable" : "NULL")		,(nrSccs > 0 ? "convertorsTable" : "NULL")		,(is_inst_class ? "classInstances" : "NULL")		,(is_inst_voidp ? "voidPtrInstances" : "NULL")		,(is_inst_char ? "charInstances" : "NULL")		,(is_inst_string ? "stringInstances" : "NULL")		,(is_inst_int ? "intInstances" : "NULL")		,(is_inst_long ? "longInstances" : "NULL")		,(is_inst_ulong ? "unsignedLongInstances" : "NULL")		,(is_inst_longlong ? "longLongInstances" : "NULL")		,(is_inst_ulonglong ? "unsignedLongLongInstances" : "NULL")		,(is_inst_double ? "doubleInstances" : "NULL")		,(is_inst_enum ? "enumInstances" : "NULL")		,(pt -> module -> license != NULL ? "&module_license" : "NULL")		,(pt -> module -> nrexceptions > 0 ? "exceptionsTable" : "NULL")		, (slot_extenders ? "slotExtenders" : "NULL")		, (ctor_extenders ? "initExtenders" : "NULL")		, (hasDelayedDtors(pt->module) ? "sipDelayedDtors" : "NULL"));	/* Generate the storage for the external API pointers. */	prcode(fp,"\n""\n""/* The SIP API and the APIs of any imported modules. */\n""const sipAPIDef *sipAPI_%s;\n"		,mname);	for (mld = pt->allimports; mld != NULL; mld = mld->next)		prcode(fp,"const sipExportedModuleDef *sipModuleAPI_%s_%s;\n"			,mname,mld -> module -> name);	/* Generate the Python module initialisation function. */	prcode(fp,"\n""\n""/* The Python module initialisation function. */\n""#if defined(SIP_STATIC_MODULE)\n""%svoid init%s()\n""#else\n""PyMODINIT_FUNC init%s()\n""#endif\n""{\n""	static PyMethodDef sip_methods[] = {\n"		,(generating_c ? "" : "extern \"C\" "), mname		,mname);	/* Generate the global functions. */	for (md = pt -> othfuncs; md != NULL; md = md -> next)		if (md -> module == pt -> module && md -> slot == no_slot)			prcode(fp,"		{%N, func_%s, METH_VARARGS, NULL},\n"				,md -> pyname,md -> pyname -> text);	prcode(fp,"		{0, 0, 0, 0}\n""	};\n""\n""	PyObject *sipModule, *sipModuleDict, *sip_sipmod, *sip_capiobj;\n""\n"		);	/* Generate the pre-initialisation code. */	generateCppCodeBlock(pt -> preinitcode,fp);	prcode(fp,"	/* Initialise the module and get it's dictionary. */\n""	sipModule = Py_InitModule(sipModuleAPI_%s.em_name,sip_methods);\n""	sipModuleDict = PyModule_GetDict(sipModule);\n""\n""	/* Import the SIP module and get it's API. */\n""	sip_sipmod = PyImport_ImportModule(\"sip\");\n""\n""	if (sip_sipmod == NULL)\n""		return;\n""\n""	sip_capiobj = PyDict_GetItemString(PyModule_GetDict(sip_sipmod),\"_C_API\");\n""\n""	if (sip_capiobj == NULL || !PyCObject_Check(sip_capiobj))\n""		return;\n""\n"		,mname);	if (generating_c)		prcode(fp,"	sipAPI_%s = (const sipAPIDef *)PyCObject_AsVoidPtr(sip_capiobj);\n"		,mname);	else		prcode(fp,"	sipAPI_%s = reinterpret_cast<const sipAPIDef *>(PyCObject_AsVoidPtr(sip_capiobj));\n"		,mname);	prcode(fp,"\n""	/* Export the module and publish it's API. */\n""	if (sipAPI_%s -> api_export_module(&sipModuleAPI_%s,SIP_API_MAJOR_NR,SIP_API_MINOR_NR,sipModuleDict) < 0)\n""		return;\n"		,mname		,mname);	noIntro = TRUE;	for (mld = pt->allimports; mld != NULL; mld = mld->next)	{		if (noIntro)		{			prcode(fp,"\n""	/* Get the APIs of the modules that this one is dependent on. */\n"				);			noIntro = FALSE;		}		prcode(fp,"	sipModuleAPI_%s_%s = sipModuleAPI_%s.em_imports[%d].im_module;\n"			,mname,mld -> module -> name,mname,mld -> module -> modulenr);	}	generateClassesInline(pt,fp);	generateEnumsInline(pt, fp);	/* Create any exceptions. */	for (xd = pt->exceptions; xd != NULL; xd = xd->next)	{		if (xd->iff->module != pt->module)			continue;		if (xd->iff->type != exception_iface)			continue;		if (xd->exceptionnr < 0)			continue;		prcode(fp,"\n""	if ((exceptionsTable[%d] = PyErr_NewException(\"%s.%s\",", xd->exceptionnr, xd->iff->module->name, xd->pyname);		if (xd->bibase != NULL)			prcode(fp, "PyExc_%s", xd->bibase);		else if (xd->base->iff->module == pt->module)			prcode(fp, "exceptionsTable[%d]", xd->base->exceptionnr);		else			prcode(fp, "sipException_%C", xd->base->iff->fqcname);		prcode(fp, ",NULL)) == NULL || PyDict_SetItemString(sipModuleDict,\"%s\",exceptionsTable[%d]) < 0)\n""		return;\n"			, xd->pyname, xd->exceptionnr);	}	/* Generate the post-initialisation code. */	generateCppCodeBlock(pt -> postinitcode,fp);	prcode(fp,"}\n"		);	/* Generate the interface source and header files. */	for (iff = pt -> ifacefiles; iff != NULL; iff = iff -> next)	{		if (iff -> module == pt -> module && iff -> type != exception_iface)		{			if (*parts && files_in_part++ == max_per_part)			{				/* Close the old part. */				closeFile(fp);				free(cppfile);				/* Create a new one. */				files_in_part = 1;				++this_part;				cppfile = makePartName(codeDir,mname,this_part,srcSuffix);				fp = createFile(pt,cppfile,"Module code.");			}			generateIfaceCpp(pt,iff,codeDir,srcSuffix,(*parts ? fp : NULL));		}		generateIfaceHeader(pt,iff,codeDir);	}	closeFile(fp);	free(cppfile);	/* How many parts we actually generated. */	if (*parts)		*parts = this_part + 1;}/* * Generate an entry for a class in the classes table and all its children. */static void generateClassTableEntries(sipSpec *pt, nodeDef *nd, FILE *fp){	nodeDef *cnd;	/* Generate the entry if it's not the root. */	if (nd -> cd != NULL)		if (isExternal(nd->cd))			prcode(fp,"	0,\n"				);		else			prcode(fp,"	(sipWrapperType *)&sipType_%s_%C,\n"				, pt->module->name, classFQCName(nd->cd));	/* Generate all it's children. */	for (cnd = nd -> child; cnd != NULL; cnd = cnd -> next)		generateClassTableEntries(pt, cnd, fp);}/* * Generate the structure representing an encoded class. */static void generateEncodedClass(sipSpec *pt,classDef *cd,int last,FILE *fp){	moduleDef *mod = cd -> iff -> module;	prcode(fp,"{%u, ",cd -> classnr);	if (mod == pt -> module)		prcode(fp,"255");	else		prcode(fp,"%u",mod -> modulenr);	prcode(fp,", %u}",last);}/* * Generate an ordinary function (ie. not a class method). */static void generateOrdinaryFunction(sipSpec *pt,classDef *cd,memberDef *md,				     FILE *fp){	overDef *od;	prcode(fp,"\n"

⌨️ 快捷键说明

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