1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Portions of this software have been released under the following terms: 31 * 32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC. 33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY 34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION 35 * 36 * To anyone who acknowledges that this file is provided "AS IS" 37 * without any express or implied warranty: 38 * permission to use, copy, modify, and distribute this file for any 39 * purpose is hereby granted without fee, provided that the above 40 * copyright notices and this notice appears in all source code copies, 41 * and that none of the names of Open Software Foundation, Inc., Hewlett- 42 * Packard Company or Digital Equipment Corporation be used 43 * in advertising or publicity pertaining to distribution of the software 44 * without specific, written prior permission. Neither Open Software 45 * Foundation, Inc., Hewlett-Packard Company nor Digital 46 * Equipment Corporation makes any representations about the suitability 47 * of this software for any purpose. 48 * 49 * Copyright (c) 2007, Novell, Inc. All rights reserved. 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in the 58 * documentation and/or other materials provided with the distribution. 59 * 3. Neither the name of Novell Inc. nor the names of its contributors 60 * may be used to endorse or promote products derived from this 61 * this software without specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY 67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 * 74 * @APPLE_LICENSE_HEADER_END@ 75 */ 76 77/* 78** NAME: 79** 80** cspeldcl.c 81** 82** FACILITY: 83** 84** IDL Compiler Backend 85** 86** ABSTRACT: 87** 88** Routines to spell declaration related material to C source 89** 90** VERSION: DCE 1.0 91*/ 92 93#include <nidl.h> 94#include <ast.h> 95#include <bedeck.h> 96#include <cspell.h> 97#include <cspeldcl.h> 98#include <hdgen.h> 99 100/******************************************************************************/ 101/* */ 102/* Build text string for constant value */ 103/* */ 104/******************************************************************************/ 105void CSPELL_constant_val_to_string 106( 107 AST_constant_n_t *cp, 108 char *str 109) 110{ 111 char const *str2; 112 113 switch (cp->kind) { 114 case AST_nil_const_k: 115 sprintf (str, "NULL"); 116 break; 117 case AST_boolean_const_k: 118 if (cp->value.boolean_val) 119 sprintf (str, "ndr_true"); 120 else 121 sprintf (str, "ndr_false"); 122 break; 123 case AST_int_const_k: 124 sprintf (str, "%ld", cp->value.int_val); 125 break; 126 case AST_string_const_k: 127 STRTAB_str_to_string (cp->value.string_val, &str2); 128 sprintf (str, "\"%s\"", str2); 129 break; 130 case AST_char_const_k: 131 sprintf (str, "'%s'", mapchar(cp, FALSE)); 132 break; 133 default: 134 INTERNAL_ERROR("Unsupported tag in CSPELL_constant_val_to_string"); 135 break; 136 } 137} 138 139/******************************************************************************/ 140/* */ 141/* Routine to spell constant to C source */ 142/* */ 143/******************************************************************************/ 144void CSPELL_constant_val 145( 146 FILE *fid, 147 AST_constant_n_t *cp 148) 149{ 150 char str[max_string_len]; 151 152 CSPELL_constant_val_to_string (cp, str); 153 fprintf (fid, "%s", str); 154} 155 156/******************************************************************************/ 157/* */ 158/* Routine to spell union case label comment to C source */ 159/* */ 160/******************************************************************************/ 161void CSPELL_labels 162( 163 FILE *fid, 164 AST_case_label_n_t *clp 165) 166{ 167 boolean first = true; 168 169 fprintf (fid, "/* case(s): "); 170 for (; clp; clp = clp->next) { 171 if (first) 172 first = false; 173 else 174 fprintf (fid, ", "); 175 if (clp->default_label) 176 fprintf (fid, "default"); 177 else 178 CSPELL_constant_val (fid, clp->value); 179 }; 180 fprintf (fid, " */\n"); 181} 182 183/******************************************************************************/ 184/* */ 185/* Routine to spell function parameter list to C source */ 186/* */ 187/******************************************************************************/ 188void CSPELL_parameter_list 189( 190 FILE *fid, 191 AST_parameter_n_t *pp, 192 boolean encoding_services /* TRUE => [encode] or [decode] on operation */ 193) 194{ 195 boolean first = true; 196 197 if (pp) 198 { 199 for (; pp; pp = pp->next) 200 { 201 if (AST_HIDDEN_SET(pp)) 202 { 203 /* Parameter does not appear in signature delivered to user */ 204 continue; 205 } 206 if (first) 207 { 208 first = false; 209 if (encoding_services) 210 { 211 /* First parameter is a pickling handle */ 212 fprintf(fid, " /* [in] */ idl_es_handle_t "); 213 if (pp->type->kind == AST_pointer_k) 214 { 215 /* Passed by reference */ 216 fprintf(fid, "*"); 217 } 218 spell_name(fid, pp->name); 219 continue; 220 } 221 } 222 else 223 fprintf (fid, ",\n"); 224 fprintf (fid, " /* ["); 225 if (AST_IN_SET(pp)) 226 { 227 fprintf(fid, "in"); 228 if (AST_OUT_SET(pp)) fprintf (fid, ", out"); 229 } 230 else fprintf (fid, "out"); 231 fprintf (fid, "] */ "); 232#ifndef MIA 233 if (pp->be_info.param) 234 CSPELL_typed_name (fid, pp->type, 235 pp->be_info.param->name, NULL, false, true, false); 236 else 237#endif 238 CSPELL_typed_name (fid, pp->type, pp->name, NULL, false, true, 239 false); 240 } 241 } 242 else 243 fprintf (fid, " void"); 244} 245 246/******************************************************************************/ 247/* */ 248/* Spell new and old style parameter lists */ 249/* */ 250/******************************************************************************/ 251void CSPELL_finish_synopsis 252( 253 FILE *fid ATTRIBUTE_UNUSED, 254 AST_parameter_n_t *paramlist ATTRIBUTE_UNUSED 255) 256{ 257 /* this function used to put in the function parameters 258 when prototypes were NOT being used. Since we now 259 always use function prototypes, this function now does 260 nothing */ 261} 262