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

📄 gen-code.c

📁 asn to c编译器 源代码
💻 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: /baseline/SNACC/compiler/back-ends/c++-gen/gen-code.c,v 1.129 2004/04/06 15:13:41 gronej Exp $ * */#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 "asn-incl.h"#include "asn1module.h"#include "rules.h"#include "snacc-util.h"#include "print.h"#include "tag-util.h"  /* get GetTags/FreeTags/CountTags/TagByteLen */#include "cxxconstraints.h"#include "cxxmultipleconstraints.h"#if META#include "meta.h"#endifenum BasicTypeChoiceId ParanoidGetBuiltinType PARAMS ((t),Type *t);void PrintConditionalIncludeOpen PROTO ((FILE *f, char *fileName));void PrintConditionalIncludeClose PROTO ((FILE *f, char *fileName));void PrintCxxAnyCode PROTO ((FILE *src, FILE *hdr, CxxRules *r,							ModuleList *mods, Module *m));void PrintCxxValueDef PROTO ((FILE *src, CxxRules *r, ValueDef *v));void PrintCxxValueExtern PROTO ((FILE *hdr, CxxRules *r, ValueDef *v));char *LookupNamespace PROTO ((Type *t, ModuleList *mods));static void PrintCxxSeqSetPrintFunction(FILE* src, FILE* hdr,										MyString className,										BasicType *pBasicType);/* PER specific methods*/static voidPrintCxxDefCode_SetSeqPEREncode (FILE *src, FILE *hdr, CxxRules *r, TypeDef *td,     NamedType **pSetElementNamedType,    int iElementCount);      /* IN, ELEMENT Count to process in arrays */static voidPrintCxxDefCode_SetSeqPERDecode (FILE *src, FILE *hdr, CxxRules *r, TypeDef *td,     NamedType **pSetElementNamedType,    int iElementCount);      /* IN, ELEMENT Count to process in arrays */static voidPrintCxxDefCode_PERSort (    NamedType ***pppElementNamedType, /* OUT, array of sorted NameType(s) */    int **ppElementTag,      /* OUT, actual tag for sorted. */    AsnList *pElementList);  /* IN, actual eSNACC defs for NameType(s). *//* flag to see if constraints were present */int constraints_flag;long lconstraintvar=0;extern char *bVDAGlobalDLLExport;extern int gNO_NAMESPACE;extern const char *gAlternateNamespaceString;extern int genPERCode;//extern short ImportedFilesG;static const char	bufTypeNameG[] = "AsnBuf";static const char	lenTypeNameG[] = "AsnLen";static const char	tagTypeNameG[] = "AsnTag";static const char	envTypeNameG[] = "ENV_TYPE";static long 		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 *//* PIERCE added 10-27-2002 */void PrintCxxEncodeContaining(Type *t, CxxRules *r, FILE *src);void PrintCxxDecodeContaining(Type *t, CxxRules *r, FILE *src);void PrintCxxPEREncodeContaining(Type *t, CxxRules *r, FILE *src);void PrintCxxPERDecodeContaining(Type *t, CxxRules *r, FILE *src);/* PIERCE added 9-4-2002 */void PrintCxxSetTypeByCode(NamedType *defByNamedType, CxxTRI *cxxtri, FILE *src);// normalizeValue// // strip whitespace and { } from valueNation values.//void normalizeValue(char **normalized, char *input){   int i;   while(*input == ' ' || *input == '{' )      input++;   *normalized = strdup(input);      i = strlen(*normalized) - 1;   while ( (*normalized)[i] == ' ' || (*normalized)[i] == '}' )   {      (*normalized)[i] = 0;      i--;   }}static char *GetImportFileName (char *Impname, ModuleList *mods){	Module *currMod;	char *fileName = NULL;    FOR_EACH_LIST_ELMT (currMod, mods)	{		/* Find the import Module in the Modules and		 * return the header file name		 */		if ((strcmp(Impname, currMod->modId->name) == 0))		{			/* Set the file name and break */			fileName = currMod->cxxHdrFileName;			break;		}	}	return fileName;}/* RWC; added 7/25/03 */static Module *GetImportModuleRef (char *Impname, ModuleList *mods){	Module *currMod=NULL;    FOR_EACH_LIST_ELMT (currMod, mods)	{		/* Find the import Module in the Modules and		 * return the header file name		 */		if ((strcmp(Impname, currMod->modId->name) == 0))		{			break;		}	}	return currMod;}/* PIERCE added 8-22-2001 */void PrintCopyConstructor(FILE *hdr, FILE *src, char *className){   fprintf(hdr, "   %s(const %s& that);\n", className, className);   fprintf(src,"%s::%s(const %s &that)\n{\n",className, className,className);   /*fprintf(src,"   Clear();\n");*/   fprintf(src,"   Init();\n");   fprintf(src,"   *this = that;\n}\n");}void PrintSimpleMeta(FILE *hdr, char *className,int exportMember){	char *ptr="";   /* NOT DLL Exported, or ignored on Unix. */	if (bVDAGlobalDLLExport != NULL && exportMember == 1)		ptr = bVDAGlobalDLLExport;	fprintf(hdr, "public:\n\t%s virtual const char* typeName() const\t{ return \"%s\"; }\n",		ptr, className);}void PrintSimpleCheck(FILE *hdr, FILE* src, char *className,int exportMember){	char *ptr="";   /* NOT DLL Exported, or ignored on Unix. */	if (bVDAGlobalDLLExport != NULL && exportMember == 1)        ptr = bVDAGlobalDLLExport;	fprintf(hdr, "\t%s virtual int checkConstraints(ConstraintFailList* pConstraintFails) const;\n",		ptr);	fprintf(src, "int %s::checkConstraints(ConstraintFailList* pConstraintFails) const\n{\n",		className);	fprintf(src, "\treturn checkListConstraints(pConstraintFails);\n");	fprintf(src, "}\n");}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, "\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, "\n");} /* PrintSrcComment */static voidPrintSrcIncludes PARAMS ((src, mods, m),    FILE *src _AND_    ModuleList *mods _AND_    Module *m){	mods = mods;	if (m->cxxHdrFileName)		fprintf (src, "#include \"%s\"\n", m->cxxHdrFileName);    m = m;  /*AVOIDS warning.*/} /* 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){    char *pszNamespace=NULL;    pszNamespace = LookupNamespace(t, mods);    if (pszNamespace)    {        fprintf (hdr, "%s::%s       ", pszNamespace, t->cxxTypeRefInfo->className);    }    else    {        fprintf (hdr, "%s       ", t->cxxTypeRefInfo->className);    }           // END IF BASICTYPE_IMPORTTYPEREF    if (t->cxxTypeRefInfo->isPtr)        fprintf (hdr, "*");    parent = parent;td = td;r = r;m = m;mods=mods;  /*AVOIDS warning.*/} /* PrintCxxType *//* *  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 (hdr, "  AsnType		*Clone() const;\n\n");    fprintf (src, "AsnType *%s::Clone() const\n", td->cxxTypeDefInfo->className);    fprintf (src, "{\n");    fprintf (src, "  return new %s(*this);\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)

⌨️ 快捷键说明

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