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

📄 gencode.c

📁 这是关于RFC3261实现sip的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
"#define	sipConvertFromInstance		sipAPI_%s -> api_convert_from_instance\n""#define	sipConvertFromNewInstance	sipAPI_%s -> api_convert_from_new_instance\n""#define	sipConvertFromMappedType	sipAPI_%s -> api_convert_from_mapped_type\n""#define	sipGetState			sipAPI_%s -> api_get_state\n""#define	sipFindMappedType		sipAPI_%s -> api_find_mapped_type\n""#define	sipLong_AsUnsignedLong		sipAPI_%s -> api_long_as_unsigned_long\n"		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname		,mname);	/* The name strings. */	noIntro = TRUE;	for (nd = pt -> namecache; nd != NULL; nd = nd -> next)	{		if (!isUsedName(nd))			continue;		if (noIntro)		{			prcode(fp,"\n""\n""/* The strings used by this module. */\n"				);			noIntro = FALSE;		}		prcode(fp,"extern char %N[];\n"			,nd);	}	/* The unscoped enum macros. */	generateEnumMacros(pt, NULL, fp);	prcode(fp,"\n""\n""/* The SIP API, this module's API and the APIs of any imported modules. */\n""extern const sipAPIDef *sipAPI_%s;\n""extern sipExportedModuleDef sipModuleAPI_%s;\n"		,mname		,mname,mname);	for (mld = pt->allimports; mld != NULL; mld = mld->next)		prcode(fp,"extern const sipExportedModuleDef *sipModuleAPI_%s_%s;\n"			,mname,mld -> module -> name);	/*	 * Note that we don't forward declare the virtual handlers.  This is	 * because we would need to #include everything needed for their	 * argument types.	 */	prcode(fp,"\n""#endif\n"		);	closeFile(fp);	free(hfile);}/* * Return the filename of a source code part on the heap. */static char *makePartName(char *codeDir,char *mname,int part,char *srcSuffix){	char buf[20];	sprintf(buf,"part%d",part);	return concat(codeDir,"/sip",mname,buf,srcSuffix,NULL);}/* * Generate the C/C++ code. */static void generateCpp(sipSpec *pt,char *codeDir,char *srcSuffix,int *parts){	char *cppfile, *mname = pt -> module -> name;	int noIntro, nrSccs = 0, files_in_part, max_per_part, this_part;	int is_inst_class, is_inst_voidp, is_inst_char, is_inst_string;	int is_inst_int, is_inst_long, is_inst_ulong, is_inst_longlong;	int is_inst_ulonglong, is_inst_double, is_inst_enum, nr_enummembers;	int hasexternal = FALSE, slot_extenders = FALSE, ctor_extenders = FALSE;	FILE *fp;	moduleListDef *mld;	classDef *cd;	memberDef *md;	ifaceFileDef *iff;	virtHandlerDef *vhd;	nameDef *nd;	exceptionDef *xd;	/* Calculate the number of files in each part. */	if (*parts)	{		int nr_files = 1;		for (iff = pt -> ifacefiles; iff != NULL; iff = iff -> next)			if (iff -> module == pt -> module)				++nr_files;		max_per_part = (nr_files + *parts - 1) / *parts;		files_in_part = 1;		this_part = 0;		cppfile = makePartName(codeDir,mname,0,srcSuffix);	}	else		cppfile = concat(codeDir,"/sip",mname,"cmodule",srcSuffix,NULL);	fp = createFile(pt,cppfile,"Module code.");	prcode(fp,"\n""#include \"sipAPI%s.h\"\n""\n"		,mname);	for (iff = pt -> ifacefiles; iff != NULL; iff = iff -> next)		if (iff -> module == pt -> module && iff -> type != exception_iface)			prcode(fp,"#include \"sip%s%F.h\"\n"				,iff -> module -> name,iff -> fqcname);	generateUsedIncludes(pt->used, FALSE, fp);	/* Define the names. */	noIntro = TRUE;	for (nd = pt -> namecache; nd != NULL; nd = nd -> next)	{		if (!isUsedName(nd))			continue;		if (noIntro)		{			prcode(fp,"\n""\n""/* Define the strings used by this module. */\n"				);			noIntro = FALSE;		}		prcode(fp,"char %N[] = \"%s\";\n"			,nd,nd -> text);	}	/* Generate the C++ code blocks. */	generateCppCodeBlock(pt -> cppcode,fp);	/* Generate any virtual handler declarations. */	for (vhd = pt -> module -> virthandlers; vhd != NULL; vhd = vhd -> next)		if (!isDuplicateVH(vhd))			generateVirtualHandler(pt,vhd,fp);	/* Generate the global functions. */	for (md = pt -> othfuncs; md != NULL; md = md -> next)	{		if (md->module != pt->module)			continue;		if (md->slot == no_slot)			generateOrdinaryFunction(pt,NULL,md,fp);		else		{			overDef *od;			/*			 * Make sure that there is still an overload and we			 * haven't moved them all to classes.			 */			for (od = pt->overs; od != NULL; od = od->next)				if (od->common == md)				{					generateSlot(pt, NULL, NULL, md, fp);					slot_extenders = TRUE;					break;				}		}	}	/* Generate any class specific ctor or slot extenders. */	for (cd = pt->proxies; cd != NULL; cd = cd->next)	{		if (cd->ctors != NULL)		{			generateTypeInit(pt, cd, fp);			ctor_extenders = TRUE;		}		for (md = cd->members; md != NULL; md = md->next)		{			generateSlot(pt, cd, NULL, md, fp);			slot_extenders = TRUE;		}	}	/* Generate any ctor extender table. */	if (ctor_extenders)	{		prcode(fp,"\n""static sipInitExtenderDef initExtenders[] = {\n"			);		for (cd = pt->proxies; cd != NULL; cd = cd->next)			if (cd->ctors != NULL)			{				prcode(fp,"	{init_%C, ", classFQCName(cd));				generateEncodedClass(pt, cd, 0, fp);				prcode(fp, ", NULL},\n"					);			}		prcode(fp,"	{NULL, {0, 0, 0}, NULL}\n""};\n"			);	}	/* Generate any slot extender table. */	if (slot_extenders)	{		prcode(fp,"\n""static sipPySlotExtenderDef slotExtenders[] = {\n"			);		for (md = pt->othfuncs; md != NULL; md = md->next)		{			overDef *od;			if (md->module != pt->module)				continue;			if (md->slot == no_slot)				continue;			for (od = pt->overs; od != NULL; od = od->next)				if (od->common == md)				{					prcode(fp,"	{(void *)slot_%s, %s, {0, 0, 0}},\n"						, md->pyname->text, slotName(md->slot));					break;				}		}		for (cd = pt->proxies; cd != NULL; cd = cd->next)			for (md = cd->members; md != NULL; md = md->next)			{				prcode(fp,"	{(void *)slot_%C_%s, %s, ", classFQCName(cd), md->pyname->text, slotName(md->slot));				generateEncodedClass(pt, cd, 0, fp);				prcode(fp, "},\n"				      );			}		prcode(fp,"	{NULL, (sipPySlotType)0, {0, 0, 0}}\n""};\n"			);	}	/* Generate the global access functions. */	generateAccessFunctions(pt,NULL,fp);	/* Generate the module data structures. */	if (pt -> module -> nrclasses > 0)	{		/* Generate the sub-class convertors. */		for (cd = pt -> classes; cd != NULL; cd = cd -> next)		{			if (cd -> iff -> module != pt -> module)				continue;			if (cd -> convtosubcode == NULL)				continue;			prcode(fp,"\n""\n""/* Convert to a sub-class if possible. */\n""static sipWrapperType *sipSubClass_%C(void **sipCppRet)\n""{\n""	%S *sipCpp = reinterpret_cast<%S *>(*sipCppRet);\n""	sipWrapperType *sipClass;\n""\n"				,classFQCName(cd)				,classFQCName(cd -> subbase),classFQCName(cd -> subbase));			generateCppCodeBlock(cd -> convtosubcode,fp);			prcode(fp,"\n""	return sipClass;\n""}\n"				);			++nrSccs;		}		prcode(fp,"\n""\n""/*\n"" * This defines each class in this module.  The values are replaced by the\n"" * proper Python types during the export process.\n"" */\n""static sipWrapperType *typesTable[] = {\n"			);		generateClassTableEntries(pt, &pt->module->root, fp);		prcode(fp,"};\n"			);		/* Generate the external classes table if needed. */		for (cd = pt->classes; cd != NULL; cd = cd->next)		{			if (!isExternal(cd))				continue;			if (cd->iff->module != pt->module)				continue;			if (!hasexternal)			{				prcode(fp,"\n""\n""/* This defines each external type declared in this module, */\n""static sipExternalTypeDef externalTypesTable[] = {\n"					);				hasexternal = TRUE;			}			prcode(fp,"	{%d, \"", cd->classnr);			prScopedName(fp, classFQCName(cd), ".");			prcode(fp,"\"},\n"				);		}		if (hasexternal)			prcode(fp,"	{-1, NULL}\n""};\n"				);	}	if (pt -> module -> nrmappedtypes > 0)	{		mappedTypeDef *mtd;		argDef type;		type.argflags = 0;		type.name = NULL;		type.nrderefs = 0;		type.defval = NULL;		prcode(fp,"\n""\n""/* This defines each mapped type in this module. */\n""static sipMappedType *mappedTypesTable[] = {\n"			);		for (mtd = pt -> mappedtypes; mtd != NULL; mtd = mtd -> next)		{			if (mtd -> iff -> module != pt -> module)				continue;			type.atype = mapped_type;			type.u.mtd = mtd;			prcode(fp,"	&sipMappedTypeDef_%T,\n"				,&type);		}		prcode(fp,"	0\n""};\n"			);	}	if (pt -> module -> nrenums > 0)	{		enumDef *ed;		prcode(fp,"\n""\n""/* Define each named enum in this module. */\n"			);		/* Generate any slot tables. */		for (ed = pt->enums; ed != NULL; ed = ed->next)		{			memberDef *slot;			if (ed->module != pt->module || ed->fqcname == NULL)				continue;			if (ed->slots == NULL)				continue;			for (slot = ed->slots; slot != NULL; slot = slot->next)				generateSlot(pt, NULL, ed, slot, fp);			prcode(fp,"\n""static sipPySlotDef slots_%C[] = {\n"				, ed->fqcname);			for (slot = ed->slots; slot != NULL; slot = slot->next)			{				const char *stype;				if ((stype = slotName(slot->slot)) != NULL)					prcode(fp,"	{(void *)slot_%C_%s, %s},\n"						, ed->fqcname, slot->pyname->text, stype);			}			prcode(fp,"	{0, (sipPySlotType)0}\n""};\n""\n"				);		}		prcode(fp,"static sipEnumDef enumTypesTable[] = {\n"			);		for (ed = pt -> enums; ed != NULL; ed = ed -> next)		{			char *emname;			if (ed -> module != pt -> module || ed -> fqcname == NULL)				continue;			if (ed->ecd == NULL)				emname = mname;			else if (ed->ecd->real == NULL)				emname = ed->module->name;			else				emname = ed->ecd->real->iff->module->name;			prcode(fp,"	{\"%s.%P\", ", emname, ed->ecd, ed->pyname->text);			if (isRenamedEnum(ed) || (ed -> ecd != NULL && isRenamedClass(ed -> ecd)))				prcode(fp, "\"%S\", ", ed -> fqcname);			else				prcode(fp, "NULL, ");			if (ed->ecd == NULL)				prcode(fp, "-1");			else				prcode(fp, "%d", ed->ecd->classnr);			if (ed->slots != NULL)				prcode(fp, ", slots_%C", ed->fqcname);			else				prcode(fp, ", NULL");			prcode(fp, "},\n"				);		}		prcode(fp,"};\n"			);		nr_enummembers = generateEnumMemberTable(pt,NULL,fp);	}	else		nr_enummembers = 0;	if (pt -> module -> nrtypedefs > 0)	{		typedefDef *td;		prcode(fp,"\n""\n""/*\n"" * These define each typedef in this module.  They are only needed in case\n"" * they are used as arguments to Qt signals.\n"" */\n""\n""static sipTypedefDef typedefsTable[] = {\n"			);		for (td = pt -> typedefs; td != NULL; td = td -> next)		{			char *mname, *sat;			scopedNameDef *fqname;

⌨️ 快捷键说明

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