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

📄 gen-code.c

📁 asn.1 compiler
💻 C
📖 第 1 页 / 共 5 页
字号:
/* *   compiler/back_ends/c++_gen/gen_code.c - routines for printing C++ code from type trees * *   assumes that the type tree has already been run through the *   c++ type generator (c++_gen/types.c). * *  This was hastily written - it has some huge routines in it. *  Needs a lot of cleaning up and modularization... * * Mike Sample * 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: /usr/app/odstb/CVS/snacc/compiler/back-ends/c++-gen/gen-code.c,v 1.12 1997/02/28 13:39:53 wan Exp $ * $Log: gen-code.c,v $ * Revision 1.12  1997/02/28 13:39:53  wan * Modifications collected for new version 1.3: Bug fixes, tk4.2. * * Revision 1.11  1997/02/16 15:14:06  rj * made return *this after calling abort()'' a compile time option. * * Revision 1.10  1997/02/16 12:46:31  rj * use the TIME_WITH_SYS_TIME flag (checked and generated by configure). * return *this after calling abort() for compilers that don't know about this volatile function. * comment out unused parameters, the compiler otherwise may complain. * * Revision 1.9  1995/09/07  20:47:32  rj * deep copying assingment operators added. * * Revision 1.8  1995/09/07  19:25:27  rj * PrintCxxCode(): boolean genMeta changed to enum type MetaNameStyle. used globally in printMetaG. * * set Tcl's errorCode variable. * * Revision 1.7  1995/08/17  15:00:06  rj * the PDU flag belongs to the metacode, not only to the tcl interface. (type and variable named adjusted) * * Revision 1.6  1995/07/27  10:52:28  rj * include config.h before using its #define's :-) * * file name has been shortened for redundant part: c++-gen/gen-c++-code -> c++-gen/gen-code. * * functions used only locally made static. * * #if TCL ... #endif wrapped into #if META ... #endif, both here and in generated files. * * code changes to allow for more than one PDU (meta code), e.g. generate -create() functions. * * generate additional TclUnsetVal() function to delete OPTIONAL members and SEQUENCE OF and SET OF list elements. * * _getref() gets an additional optional argument to faciliate the different member access semantics of TclGetVal() and TclSetVal(). * * the list functions Append(), Prepend(), InsertBefore() and InsertAfter() now set the current element to the element just inserted. * * changed `_' to `-' in file names. * * Revision 1.5  1995/02/18  14:45:16  rj * tried to make the print function's output a little more readable. [kho] * * Revision 1.4  1994/10/08  03:19:24  rj * since i was still irritated by cpp standing for c++ and not the C preprocessor, i renamed them to cxx (which is one known suffix for C++ source files). since the standard #define is __cplusplus, cplusplus would have been the more obvious choice, but it is a little too long. * * turned the functions order upside down to get rid of those annoying declarations. * * turned character pointers into constant character arrays. * * code for meta structures added (provides information about the generated code itself). * * code for Tcl interface added (makes use of the above mentioned meta code). * * instead of being a no-op, the no-arg-constructors (that get used by Clone()) do something useful now, namely: * - initialize the pointer in a choice union. (the destruktor may try to free the bogus pointer). * - for the same reason: initialize pointers in sequences and sets. * * to complement the destructors, T::T (const T&) and T &T::operator = (const T &) have been added to override the defaults supplied by the compiler. * reason: simple pointer duplication may lead to unreferenced objects and to objects referenced more than once (on which the destructors delete may choke). * * virtual inline functions (the destructor and the Clone() function) moved from inc/*.h to src/*.C because g++ turns every one of them into a static non-inline function in every file where the .h file gets included. * * made Print() const (and some other, mainly comparison functions). * * Revision 1.3  1994/09/01  00:16:29  rj * change of IBM ENC integrated: large inlines turned into normal functions. * more portable .h file inclusion. * * Revision 1.2  1994/08/31  09:49:05  rj * for the C++ code generated: turned TRUE/FALSE into true/false; * the keyword `struct' had to be removed before AsnListElmt, or gcc 2.6 wouldn't compile the generated code. * * Revision 1.1  1994/08/28  09:48:01  rj * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. * */#include "snacc.h"#if TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H#  include <sys/time.h># else#  include <time.h># endif#endif#if STDC_HEADERS || HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#include <stdio.h>#include "asn-incl.h"#include "asn1module.h"#include "define.h"#include "mem.h"#include "lib-types.h"#include "rules.h"#include "types.h"#include "cond.h"#include "str-util.h"#include "snacc-util.h"#include "print.h"#include "tag-util.h"  /* get GetTags/FreeTags/CountTags/TagByteLen */#if META#include "meta.h"#endif#include "gen-vals.h"#include "gen-any.h"#include "gen-code.h"static const char	bufTypeNameG[] = "BUF_TYPE";static const char	lenTypeNameG[] = "AsnLen";static const char	tagTypeNameG[] = "AsnTag";static const char	envTypeNameG[] = "ENV_TYPE";static long int		longJmpValG  = -100;static const char	baseClassesG[] = ": public AsnType";static int		printTypesG;static int		printEncodersG;static int		printDecodersG;static int		printPrintersG;static int		printFreeG;#if METAstatic MetaNameStyle	printMetaG;static MetaPDU		*meta_pdus_G;#if TCLstatic int		printTclG;#endif#endif /* META */static voidPrintHdrComment PARAMS ((hdr, m),    FILE *hdr _AND_    Module *m){    time_t now = time (NULL);    fprintf (hdr, "//   NOTE: this is a machine generated file--editing not recommended\n");    fprintf (hdr, "//\n");    fprintf (hdr, "// %s - class definitions for ASN.1 module %s\n", m->cxxHdrFileName, m->modId->name);    fprintf (hdr, "//\n");    fprintf (hdr, "//   This file was generated by snacc on %s", ctime (&now));    fprintf (hdr, "//   UBC snacc by Mike Sample\n");    fprintf (hdr, "//   A couple of enhancements made by IBM European Networking Center\n"); /* 20.8.93 Thomas Meyer */    fprintf (hdr, "\n");} /* PrintHdrComment */static voidPrintSrcComment PARAMS ((src, m),    FILE *src _AND_    Module *m){    time_t now = time (NULL);    fprintf (src, "//   NOTE: this is a machine generated file--editing not recommended\n");    fprintf (src, "//\n");    fprintf (src, "// %s - class member functions for ASN.1 module %s\n", m->cxxSrcFileName, m->modId->name);    fprintf (src, "//\n");    fprintf (src, "//   This file was generated by snacc on %s", ctime (&now));    fprintf (src, "//   UBC snacc written by Mike Sample\n");    fprintf (src, "//   A couple of enhancements made by IBM European Networking Center\n"); /* 20.8.93 Thomas Meyer */    fprintf (src, "\n");} /* PrintSrcComment */static voidPrintSrcIncludes PARAMS ((src, if_IBM_ENC (srcdb COMMA) mods, m),    FILE *src _AND_    if_IBM_ENC (FILE *srcdb _AND_)    ModuleList *mods _AND_    Module *m){    void *tmp;    Module *currMod;#ifdef _IBM_ENC_    size_t length;    char *inclstring;#endif /* _IBM_ENC_ */    fprintf (src, "#include \"asn-incl.h\"\n");    tmp = (void *)CURR_LIST_NODE (mods); /* remember curr loc */    FOR_EACH_LIST_ELMT (currMod, mods)        fprintf (src, "#include \"%s\"\n", currMod->cxxHdrFileName);    SET_CURR_LIST_NODE (mods, tmp);#ifdef _IBM_ENC_#include "./ibm_editor/print_src_includes.h"#endif /* _IBM_ENC_ */} /* PrintSrcIncludes */static voidPrintTypeDecl PARAMS ((f, td),    FILE *f _AND_    TypeDef *td){    switch (td->type->basicType->choiceId)    {        case BASICTYPE_COMPONENTSOF:        case BASICTYPE_SELECTION:        case BASICTYPE_UNKNOWN:        case BASICTYPE_MACRODEF:        case BASICTYPE_MACROTYPE:            return; /* do nothing */        default:            if (IsNewType (td->type))                fprintf (f, "class %s;\n", td->cxxTypeDefInfo->className);    }} /* PrintTypeDecl */static voidPrintCxxType PARAMS ((hdr, mods, m, r, td, parent, t),    FILE *hdr _AND_    ModuleList *mods _AND_    Module *m _AND_    CxxRules *r _AND_    TypeDef *td _AND_    Type *parent _AND_    Type *t){    fprintf (hdr, "%s		", t->cxxTypeRefInfo->className);    if (t->cxxTypeRefInfo->isPtr)        fprintf (hdr, "*");} /* PrintCxxType */#ifdef _IBM_ENC_static voidPrintCxxTypedb PARAMS ((srcdb, mods, m, r, td, parent, t),    FILE *srcdb _AND_    ModuleList *mods _AND_    Module *m _AND_    CxxRules *r _AND_    TypeDef *td _AND_    Type *parent _AND_    Type *t){#include "./ibm_editor/print_cxx_type_db.h"} /* PrintCxxTypedb */#endif/* *  Uses the Constructor that takes no args. *  Assumes file f is positioned inside a class definition. *  All Classes get this to support the ANY type. */static voidPrintCloneMethod PARAMS ((hdr, src, td),    FILE *hdr _AND_    FILE *src _AND_    TypeDef *td){    fprintf (hdr, "  AsnType		*Clone() const;\n\n", td->cxxTypeDefInfo->className);    fprintf (src, "AsnType *%s::Clone() const\n", td->cxxTypeDefInfo->className);    fprintf (src, "{\n");    fprintf (src, "  return new %s;\n", td->cxxTypeDefInfo->className);    fprintf (src, "}\n\n");} /* PrintCloneMethod *//* * prints inline definition of constructors if this class is * derived from a library class. * assumes FILE *f is positioned in the derived class definition (.h) * * 12/92 MS - added overloaded "=" ops for string types. */static voidPrintDerivedConstructors PARAMS ((f, r, td),    FILE *f _AND_    CxxRules *r _AND_    TypeDef *td){    enum BasicTypeChoiceId typeId;    char *derivedClassName;    char *baseClassName;    typeId = GetBuiltinType (td->type);    derivedClassName = td->cxxTypeDefInfo->className;    baseClassName = td->type->cxxTypeRefInfo->className;    /* every class gets the no-arg constructor */#if TCL    if (printTclG && typeId == BASICTYPE_ENUMERATED)    {	fprintf (f, "#if TCL\n");	fprintf (f, "			%s(): %s (_nmdescs[0].value) {}\n", derivedClassName, baseClassName);	fprintf (f, "#else\n");    }#endif /* TCL */    fprintf (f, "			%s(): %s() {}\n", derivedClassName, baseClassName);#if TCL    if (printTclG && typeId == BASICTYPE_ENUMERATED)      fprintf (f, "#endif\n");#endif /* TCL */    switch (typeId)    {        case BASICTYPE_BOOLEAN:            fprintf (f, "			%s (bool b): %s (b) {}\n", derivedClassName, baseClassName);            break;        case BASICTYPE_ENUMERATED:        case BASICTYPE_INTEGER:            fprintf (f, "			%s (int i): %s (i) {}\n", derivedClassName, baseClassName);            break;        case BASICTYPE_REAL:            fprintf (f, "			%s (double d): %s (d) {}\n", derivedClassName, baseClassName);            break;	case BASICTYPE_OCTETSTRING:            fprintf (f, "			%s (const char *str): %s (str) {}\n", derivedClassName, baseClassName);            fprintf (f, "			%s (const char *str, const size_t len): %s (str, len) {}\n", derivedClassName, baseClassName);            fprintf (f, "			%s (const %s &o): %s (o) {}\n", derivedClassName, baseClassName, baseClassName);

⌨️ 快捷键说明

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