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

📄 gen-code.c

📁 asn to c编译器 源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * compiler/back-ends/c-gen/gen-code.c - generate C hdr and src files * * Assumes you have called FillCTypeInfo * * MS 92 * Copyright (C) 1991, 1992 Michael Sample *            and the University of British Columbia * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * $Header: /baseline/SNACC/compiler/back-ends/c-gen/gen-code.c,v 1.17 2004/03/25 19:20:16 gronej Exp $ * $Log: gen-code.c,v $ * Revision 1.17  2004/03/25 19:20:16  gronej * fixed some linux warnings * * Revision 1.16  2004/03/12 18:51:20  gronej * updated c-library to error on extension additions as it does with untagged elements * * Revision 1.15  2004/01/14 19:07:53  gronej * Updated Compiler to accept and process relative-oid's * * Revision 1.14  2003/12/17 19:05:04  gronej * SNACC baseline merged with PER v1_7 tag * * Revision 1.13.2.1  2003/11/05 14:58:57  gronej * working PER code merged with esnacc_1_6 * * Revision 1.13  2003/07/30 15:20:22  colestor * Added "#pragma" to disable MS Windows compiler warning on produced .c * source file for unused local variables. * * Revision 1.12  2003/07/30 00:48:15  colestor * Removed final init_* method declarations.  Also, for "C" code generation, to move * all IMPORT include references to the module .h file (as in C++).  This allows the resulting * .c source to properly build with appropriately ordered IMPORT references. * * Revision 1.11  2003/07/28 11:13:51  colestor * Changes to complete handing of the "--snacc namespace" compiler directive. * Also, updates to handle ASN.1 constant integer tag designations for C++/C. * * Revision 1.10  2003/07/07 14:53:38  nicholar * Eliminated headers and cleaned up include references * * Revision 1.9  2003/04/29 21:05:15  leonberp * integerated Deepak's changes for IOB support * * Revision 1.8  2003/02/07 17:03:12  leonberp * added #ifdef __cplusplus extern "C" * * Revision 1.7  2002/11/01 16:19:54  mcphersc * Fixed compiler warnings and errors not caught by microsoft * * Revision 1.6  2002/10/30 13:39:56  mcphersc * added include references to sources include file, and only produce src and include files for non imported files - files not referenced by the -I option * * Revision 1.5  2002/10/07 13:45:25  mcphersc * When a "-u filename" is on the argument line, the executable will go into an infinite * loop. This fixes that problem * * Revision 1.4  2002/10/01 13:51:34  mcphersc * Modified snacc to accept either the -I import option or the original way to list the * asn modules on the command line * * Revision 1.3  2002/09/04 17:59:34  vracarl * got rid of c++ comments * * Revision 1.2  2000/10/24 14:54:46  rwc * Updated to remove high-level warnings (level 4 on MSVC++) for an easier build. * SOME warnings persist due to difficulty in modifying the SNACC compiler to * properly build clean source; also some files are built by Lex/Yacc. * * Revision 1.1.1.1  2000/08/21 20:36:05  leonberp * First CVS Version of SNACC. * * Revision 1.4  1995/07/25 18:39:46  rj * file name has been shortened for redundant part: c-gen/gen-c-code -> c-gen/gen-code. * * PrintConditionalIncludeOpen() and PrintConditionalIncludeClose() moved to back-ends/cond.c * * changed `_' to `-' in file names. * * Revision 1.3  1995/02/18  12:50:53  rj * typo fixed. * * Revision 1.2  1994/09/01  00:21:54  rj * snacc_config.h and other superfluous .h files removed. * * Revision 1.1  1994/08/28  09:48:17  rj * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. * */#include <time.h>#include <string.h>#include "asn-incl.h"#include "asn1module.h"#include "rules.h"#include "str-util.h"#include "enc-rules.h"#include "lib-types.h"#include "tag-util.h"/* Function Prototypes */char *Code2UnivCodeStr PROTO ((BER_UNIV_CODE code));void PrintCAnyCode(FILE *src, FILE *hdr, CRules *r, ModuleList *mods, 				   Module *m, int printEncoders, int printDecoders, 				   int printPrinters, int printFree);void PrintCContentDecoder PROTO ((FILE *src, FILE *hdr, CRules *r, Module *m,								 TypeDef *td, long int *longJmpVal));void PrintCContentEncoder PROTO ((FILE *src, FILE *hdr, CRules *r, Module *m,								 TypeDef *td));void PrintCDecoder PROTO ((FILE *src, FILE *hdr, CRules *r, Module *m,						  TypeDef *td, long int *longJmpVal));void PrintCEncoder PROTO ((FILE *src, FILE *hdr, CRules *r, Module *m,						  TypeDef *td));void PrintCFree PROTO ((FILE *src, FILE *hdr, CRules *r, ModuleList *mods,					   Module *m, TypeDef *td));void PrintCPrinter PROTO ((FILE *src, FILE *hdr, CRules *r, ModuleList *mods,						  Module *m, TypeDef *td));void PrintCTypeDef PROTO ((FILE *f, CRules *r, Module *m, TypeDef *td));void PrintCValueDef PROTO ((FILE *src, CRules *r, ValueDef *v));void PrintCValueExtern  PROTO ((FILE *hdr, CRules *r, ValueDef *v));void PrintCValueInstantiation PROTO ((FILE *hdr, CRules *r, Value *v));void PrintConditionalIncludeOpen PROTO ((FILE *f, char *fileName));void PrintConditionalIncludeClose PROTO ((FILE *f, char *fileName));/* Global Variables */extern int isTableConstraintAllowed;	/* defined in snacc.c *//* unexported prototypes */static void PrintCSrcComment PROTO ((FILE *src, Module *m));static void PrintCSrcIncludes PROTO ((FILE *src, Module *m, ModuleList *mods));static void PrintCHdrComment PROTO ((FILE *hdr, Module *m));static void PrintCHdrObjectDeclaration_and_Init PROTO ((FILE *hdr, Module *m, CRules *r));//RWC;static void PrintCHdrObjectField PROTO ((FILE *hdr, Module *m, CRules *r, char *objName, ObjectAssignmentField *oaf));//extern short ImportedFilesG;/* * Fills the hdr file with the C type and encode/decode prototypes * Fills the src file with the encoded/decode routine definitions */voidPrintCCode PARAMS ((src, hdr, mods, m, r, longJmpVal, printTypes, printValues, printEncoders, printDecoders, printPrinters, printFree),    FILE *src _AND_    FILE *hdr _AND_    ModuleList *mods _AND_    Module *m _AND_    CRules *r _AND_    long int longJmpVal _AND_    int printTypes _AND_    int printValues _AND_    int printEncoders _AND_    int printDecoders _AND_    int printPrinters _AND_    int printFree){    TypeDef *td;    ValueDef *vd;	/* Deepak: suppose the asn source file is test.asn	 * then the C source file name is test.c and C header file is test.h	 */    PrintCSrcComment (src, m);	// Deepak: Write the comments in the source file.    PrintCSrcIncludes (hdr/*RWC;src*/, m, mods);	// Deepak: #include "asn-incl.h" and #include "test.h".    PrintCHdrComment (hdr, m);	// Deepak: Write the comments in the header file.    PrintConditionalIncludeOpen (hdr, m->cHdrFileName);		/* Deepak: the above fn writes 	 * #ifndef _test_h_ 	 * #define _test_h_     */	/* PIERCE TBD: Is this necessary still after Deepak's mods?     *	 * Add include reference to source file	 *      */    fprintf (src, "#include \"%s\"\n", m->cHdrFileName);    fprintf (hdr,"\n\n");    fprintf (hdr,"#ifdef __cplusplus\n");    fprintf (hdr,"extern \"C\" {\n");    fprintf (hdr,"#endif\n");    // RWC; ADDED to remove warning about "unreferenced local variable" for     //   variables that are hardcoded by the eSNACC compiler; depending on     //   the recursed data types (e.g. in a CHOICE), the variables may not be    //   used.  We just ignore the warning.    fprintf (hdr,"#ifdef _WIN32\n");    fprintf (hdr,"#pragma warning( disable : 4101 )\n");    fprintf (hdr,"#endif\n");    fprintf (src,"\n\n");    if (printValues)    {        /* put value defs at beginning of .c file */        FOR_EACH_LIST_ELMT (vd, m->valueDefs)        {            PrintCValueDef (src, r, vd);        }    }    PrintCAnyCode (src, hdr, r, mods, m, printEncoders, printDecoders, 		printPrinters, printFree);    FOR_EACH_LIST_ELMT (td, m->typeDefs)    {        if (printTypes)            PrintCTypeDef (hdr, r, m, td);        /* for PDU type or types ref'd with ANY/ANY DEF BY */        if (printEncoders && ((td->anyRefs != NULL) || td->cTypeDefInfo->isPdu))            PrintCEncoder (src, hdr, r, m, td);        /* for PDU type or types ref'd with ANY/ANY DEF BY */        if (printDecoders && ((td->anyRefs != NULL) || td->cTypeDefInfo->isPdu))            PrintCDecoder (src, hdr, r, m, td, &longJmpVal);        if (printEncoders)		{            PrintCContentEncoder (src, hdr, r, m, td);			//if (td->bHasTableConstraint)			//	PrintCTableConstraintEncoder (src, hdr, m, td);		// Deepak: 25/Mar/2003		}        if (printDecoders)		{            PrintCContentDecoder (src, hdr, r, m, td, &longJmpVal);			//if (td->bHasTableConstraint)			//	PrintCTableConstraintDecoder (src, hdr, m, td);		// Deepak: 25/Mar/2003		}        if (printPrinters)            PrintCPrinter (src, hdr, r, mods, m, td);        if (printFree)            PrintCFree (src, hdr, r, mods, m, td);        /* only print new lines for normal types */        switch (td->type->basicType->choiceId)        {            case BASICTYPE_SEQUENCEOF:  /* list types */            case BASICTYPE_SETOF:            case BASICTYPE_CHOICE:            case BASICTYPE_SET:            case BASICTYPE_SEQUENCE:			case BASICTYPE_SEQUENCET:	// Deepak: 30/Nov/2002			case BASICTYPE_OBJECTCLASS:	// Deepak: 14/Mar/2003                fprintf (src, "\n");                /* fall through */            case BASICTYPE_IMPORTTYPEREF:  /* type references */            case BASICTYPE_LOCALTYPEREF:            case BASICTYPE_BOOLEAN:  /* library type */            case BASICTYPE_REAL:  /* library type */            case BASICTYPE_OCTETSTRING:  /* library type */            case BASICTYPE_NULL:  /* library type */            case BASICTYPE_OID:  /* library type */            case BASICTYPE_RELATIVE_OID: /* library type */            case BASICTYPE_INTEGER:  /* library type */            case BASICTYPE_BITSTRING:  /* library type */            case BASICTYPE_ENUMERATED:  /* library type */            case BASICTYPE_ANYDEFINEDBY:  /* ANY types */            case BASICTYPE_ANY:			case BASICTYPE_NUMERIC_STR:		/* library type */			case BASICTYPE_PRINTABLE_STR:	/* library type */			case BASICTYPE_IA5_STR:			/* library type */			case BASICTYPE_BMP_STR:			/* library type */			case BASICTYPE_UNIVERSAL_STR:	/* library type */			case BASICTYPE_UTF8_STR:		/* library type */			case BASICTYPE_T61_STR:			/* library type */                fprintf (hdr, "\n");                break;			default:	  break;        }    }	// Declare ObjectAssignment, ObjestSetAssignment, & initialize them.	if(isTableConstraintAllowed)	{		PrintCHdrObjectDeclaration_and_Init (hdr, m, r);	// Deepak: 24/Mar/2003	}    if (printValues)    {        /* put value externs at end of .h file */        FOR_EACH_LIST_ELMT (vd, m->valueDefs)        {            PrintCValueExtern (hdr, r, vd);        }    }    fprintf (hdr,"#ifdef __cplusplus\n");    fprintf (hdr,"extern \"C\" {\n");    fprintf (hdr,"#endif\n");

⌨️ 快捷键说明

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