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

📄 gen-print.c

📁 asn.1 compiler
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * compiler/back-ends/c-gen/gen-print.c - routines for printing C hierachical print routines * * Mike Sample * 92/04 * 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-print.c,v 1.3 1995/07/25 18:43:18 rj Exp $ * $Log: gen-print.c,v $ * Revision 1.3  1995/07/25 18:43:18  rj * file name has been shortened for redundant part: c-gen/gen-c-print -> c-gen/gen-print. * * changed `_' to `-' in file names. * * Revision 1.2  1994/09/01  00:23:43  rj * snacc_config.h and other superfluous .h files removed. * * Revision 1.1  1994/08/28  09:48:28  rj * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. * */#include <stdio.h>#include "asn-incl.h"#include "asn1module.h"#include "mem.h"#include "define.h"#include "rules.h"#include "type-info.h"#include "str-util.h"#include "util.h"#include "gen-print.h"static char *returnTypeG = "void";static char *valueArgNameG = "v";static char *fileTypeNameG = "FILE*";static char *indentTypeNameG = "unsigned short int";static CRules *genPrintCRulesG;/* non-exported prototypes */static void PrintCPrintPrototype PROTO ((FILE *hdr, TypeDef *td));static void PrintCPrintDeclaration PROTO ((FILE *src, TypeDef *td));static void PrintCPrintDefine PROTO ((FILE *hdr, TypeDef *td));static void PrintCPrintLocals PROTO ((FILE *src,TypeDef *td));/*static void PrintCPrintElmts PROTO ((FILE *src, TypeDef *td, Type *parent, NamedTypeList *elmts, char *varName));*/static void PrintCChoiceElmtPrint PROTO ((FILE *src, TypeDef *td, Type *parent, NamedTypeList *elmts, NamedType *e, char *varName));static void PrintCElmtPrintWithIndent PROTO ((FILE *src, TypeDef *td, Type *parent, NamedTypeList *elmts, NamedType *e, char *varName, int allOpt));static void PrintCChoicePrintRoutine PROTO ((FILE *src, FILE *hdr, CRules *r, ModuleList *mods, Module *m, TypeDef *td));static void PrintCSetPrintRoutine  PROTO ((FILE *src, FILE *hdr, CRules *r, ModuleList *mods, Module *m, TypeDef *td));static void PrintCSeqPrintRoutine  PROTO ((FILE *src, FILE *hdr, CRules *r, ModuleList *mods, Module *m, TypeDef *td));static void PrintCSeqOfPrintRoutine PROTO ((FILE *src, FILE *hdr, CRules *r, ModuleList *mods, Module *m, TypeDef *td));static void PrintCSetOfPrintRoutine PROTO ((FILE *src, FILE *hdr, CRules *r, ModuleList *mods, Module *m, TypeDef *td));voidPrintCPrinter PARAMS ((src, hdr, r, mods, m, td),    FILE *src _AND_    FILE *hdr _AND_    CRules *r _AND_    ModuleList *mods _AND_    Module *m _AND_    TypeDef *td){    if ((td->cTypeDefInfo == NULL) || !(td->cTypeDefInfo->genPrintRoutine))        return;    genPrintCRulesG = r;    switch (td->type->basicType->choiceId)    {        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_INTEGER:  /* library type */        case BASICTYPE_BITSTRING:  /* library type */        case BASICTYPE_ENUMERATED:  /* library type */        case BASICTYPE_ANYDEFINEDBY:  /* ANY types */        case BASICTYPE_ANY:            PrintCPrintDefine (hdr, td);            fprintf (hdr, "\n\n");            break;        case BASICTYPE_SETOF:            PrintCSetOfPrintRoutine (src, hdr, r, mods, m, td);            break;        case BASICTYPE_SEQUENCEOF:            PrintCSeqOfPrintRoutine (src, hdr, r, mods, m, td);            break;        case BASICTYPE_CHOICE:            PrintCChoicePrintRoutine (src, hdr, r, mods, m, td);            break;        case BASICTYPE_SET:            PrintCSetPrintRoutine (src, hdr, r, mods, m, td);            break;        case BASICTYPE_SEQUENCE:            PrintCSeqPrintRoutine (src, hdr, r, mods, m, td);            break;        default:            break;    }}  /*  PrintCPrint *//* * Prints prototype for encode routine in hdr file */static voidPrintCPrintPrototype PARAMS ((hdr, td),    FILE *hdr _AND_    TypeDef *td){    CTDI *ctdi;    ctdi = td->cTypeDefInfo;    fprintf (hdr,"%s %s PROTO ((%s f, %s *v, %s indent));\n", returnTypeG, ctdi->printRoutineName, fileTypeNameG, ctdi->cTypeName, indentTypeNameG);}  /*  PrintCPrintPrototype *//* * Prints declarations of encode routine for the given type def */static voidPrintCPrintDeclaration PARAMS ((src, td),    FILE *src _AND_    TypeDef *td){    CTDI *ctdi;    ctdi =  td->cTypeDefInfo;    fprintf (src,"%s\n%s PARAMS ((f, v, indent),\n%s f _AND_\n%s *v _AND_\n%s indent)\n", returnTypeG, ctdi->printRoutineName, fileTypeNameG, ctdi->cTypeName, indentTypeNameG);}  /*  PrintCPrintDeclaration */static voidPrintCPrintDefine PARAMS ((hdr, td),    FILE *hdr _AND_    TypeDef *td){    fprintf(hdr, "#define %s %s", td->cTypeDefInfo->printRoutineName, td->type->cTypeRefInfo->printRoutineName);/*    fprintf(hdr, "#define %s(f, v, indent)  ", td->cTypeDefInfo->printRoutineName);    fprintf (hdr, "%s (f, v, indent)", td->type->cTypeRefInfo->printRoutineName);*/}  /*  PrintCPrintDefine */static voidPrintCPrintLocals PARAMS ((src, td),    FILE *src _AND_    TypeDef *td){    /* none yet */}  /*  PrintCPrintLocals *//*static voidPrintCPrintElmts PARAMS ((src, td, parent, elmts, varName),    FILE *src _AND_    TypeDef *td _AND_    Type *parent _AND_    NamedTypeList *elmts _AND_    char *varName){    NamedType *e;    FOR_EACH_LIST_ELMT (e, elmts)        PrintCElmtPrint (src, td, parent, elmts, e, varName);}  PrintCBerElmtsEncodeCode *//* * Prints code for printing a CHOICE element * */static voidPrintCChoiceElmtPrint PARAMS ((src, td, parent, elmts,  e, varName),    FILE *src _AND_    TypeDef *td _AND_    Type *parent _AND_    NamedTypeList *elmts _AND_    NamedType *e _AND_    char *varName){    CTRI *ctri;    char elmtVarRef[MAX_VAR_REF];    Type *tmpType;    int inTailOpts;    ctri =  e->type->cTypeRefInfo;    /* build ref to the elmt */    MakeVarPtrRef (genPrintCRulesG, td, parent, e->type, varName, elmtVarRef);    if (e->fieldName != NULL)    {        fprintf (src,"    fprintf (f,\"%s \");\n", e->fieldName);        fprintf (src,"    %s (f, %s, indent + stdIndentG);\n", e->type->cTypeRefInfo->printRoutineName, elmtVarRef);    }    else    {        fprintf (src,"    %s (f, %s, indent + stdIndentG);\n", e->type->cTypeRefInfo->printRoutineName, elmtVarRef);    }}  /*  PrintCChoiceElmtPrint *//* * Prints code for printing an elmt of a SEQ or SET * * Does funny things to print commas correctly * eg for the following type * Foo ::= SET * { *      A,                   --> print   A ",\n" *      B,                               B ",\n" *      C OPTIONAL,                      C ",\n" if C present *      D,                               D ",\n" *      E,                               E ",\n" *      F,                               F       <- nothing after last non-opt *                                                  before tail opts. *      G OPTIONAL,                      ",\n" G *      H OPTIONAL                       ",\n" H "\n" * } */static voidPrintCElmtPrintWithIndent PARAMS ((src, td, parent, elmts, e, varName, allOpt),    FILE *src _AND_

⌨️ 快捷键说明

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