ndr_gen.c revision a0b6e447978c306e15941d158bf6939a42ed2726
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <string.h>
#include "ndrgen.h"
#include "y.tab.h"
static void generate_struct(ndr_typeinfo_t *);
static void generate_params(ndr_typeinfo_t *);
static void generate_union(ndr_typeinfo_t *);
static void generate_arg(ndr_node_t *);
static void generate_member_macro(char *, char *, ndr_member_t *,
ndr_typeinfo_t *);
static void generate_member_macro_with_arg(char *, char *, ndr_member_t *,
ndr_typeinfo_t *, ndr_node_t *);
static void generate_prototypes(ndr_typeinfo_t *, char *);
char *);
static void generate_aggregate_common_begin(ndr_typeinfo_t *);
static void generate_aggregate_common_finish(ndr_typeinfo_t *);
static void generate_typeinfo_packing(ndr_typeinfo_t *);
static void generate_typeinfo_typeinfo(ndr_typeinfo_t *, int, char *);
void
generate(void)
{
char fname_type[NDLBUFSZ];
(void) printf("\n");
(void) printf(
"extern struct ndr_typeinfo ndt_%s;\n",
continue;
}
case STRUCT_KW:
else
break;
case UNION_KW:
break;
case TYPEDEF_KW:
/* silently skip */
continue;
case STRING_KW:
case STAR:
case LB:
case BASIC_TYPE:
if (!ti->is_referenced) {
}
break;
default:
continue;
}
}
}
static void
{
int i;
/* just use generate_params(), which can safely do this */
return;
}
(void) printf(" /* do all basic elements first */\n");
continue;
}
(void) printf("\n");
(void) printf(" /* do all constructed elements w/o pointers */\n");
continue;
continue;
}
(void) printf("\n");
(void) printf(" /* do members with pointers in order */\n");
continue;
continue;
}
}
static void
{
int i;
(void) printf(" /* do all members in order */\n");
}
}
static void
{
int i;
int have_default = 0;
ndr_node_t *np;
(void) printf(" switch (encl_ref->switch_is) {\n");
(void) printf(" case ");
(void) printf(":\n");
(void) printf(" default:\n");
if (have_default++) {
compile_error("multiple defaults");
}
} else {
compile_error("syntax error");
}
(void) printf(" break;\n\n");
}
if (!have_default) {
(void) printf(" default:\n");
(void) printf(" NDR_SET_ERROR(encl_ref, "
"NDR_ERR_SWITCH_VALUE_INVALID);\n");
(void) printf(" return 0;\n");
(void) printf(" break;\n");
}
(void) printf(" }\n");
(void) printf("\n");
}
static void
{
compile_error("invalid node pointer <null>");
return;
}
case SIZE_IS_KW:
case LENGTH_IS_KW:
case SWITCH_IS_KW:
(void) printf("val->");
break;
default:
else
break;
}
}
static void
{
char fname_type[NDLBUFSZ];
if (!macro)
macro = "";
if (!ti)
if (memkind) {
(void) printf(" NDR_%sMEMBER%s (%s, %s);\n",
} else {
(void) printf(" NDR_MEMBER%s (%s, %s, %uUL);\n",
}
}
static void
{
char fname_type[NDLBUFSZ];
if (!macro)
macro = "_WITH_ARG";
if (!ti)
if (memkind) {
(void) printf(" NDR_%sMEMBER%s (%s, %s,\n",
} else {
(void) printf(" NDR_MEMBER%s (%s, %s, %uUL,\n",
}
(void) printf("\t\t");
(void) printf(");\n");
}
static void
{
int i;
}
}
}
static void
{
(void) printf("\nextern void fixup%s(%s);\n",
}
}
}
static void
{
static char *fixup[] = {
"/*",
" * Cannot use the canned offsets to unmarshall multiple",
" * entry discriminated unions. The service must provide",
" * this function to patch the offsets at runtime.",
" */"
};
char fname_type[NDLBUFSZ];
ndr_node_t *np;
int is_reference = 0;
char *memkind = 0;
int cond_pending = 0;
int i;
memkind = "TOPMOST_";
memkind = "PARAMS_";
cond_pending = 1;
(void) printf(" if (NDR_DIR_IS_IN) {\n");
}
cond_pending = 1;
(void) printf(" if (NDR_DIR_IS_OUT) {\n");
}
case BASIC_TYPE:
case STRUCT_KW:
break;
case UNION_KW:
}
break;
case STAR:
is_reference = 1;
else
is_reference = 0;
if (np) {
"_REF_WITH_SIZE_IS" : "_PTR_WITH_SIZE_IS",
break;
}
if (np) {
"_REF_WITH_LENGTH_IS" : "_PTR_WITH_LENGTH_IS",
break;
}
break;
case LB:
if (np) {
"_ARR_WITH_SIZE_IS",
break;
}
if (np) {
"_WITH_LENGTH_IS",
break;
}
"_ARR_WITH_DIMENSION",
break;
default:
break;
}
if (cond_pending)
(void) printf(" }\n");
}
static void
{
char fname_type[NDLBUFSZ];
(void) printf("\n");
(void) printf("/*\n * ");
(void) printf(" */\n");
(void) printf("int\n");
(void) printf("ndr_%s (struct ndr_reference *encl_ref)\n",
(void) printf("{\n");
(void) printf(" struct ndr_reference myref;\n");
(void) printf("\n");
(void) printf(" (void) bzero(&myref, sizeof (myref));\n");
(void) printf(" myref.enclosing = encl_ref;\n");
(void) printf("\n");
}
/* ARGSUSED */
static void
{
(void) printf("\n");
(void) printf(" return 1;\n");
(void) printf("}\n");
}
/*
* Structures are normally 4-byte (dword) aligned but the align directive
* can be used to pack on a 2-byte (word) boundary. An align value of
* zero is taken to mean use default (dword) alignment. Default packing
* doesn't need to be flagged.
*/
static void
{
ndr_node_t *np;
unsigned long packing;
return;
return;
/* default alignment */
return;
}
if (packing != 2) {
/* NOTREACHED */
}
}
static void
{
*flags = 0;
if (ti->is_conformant)
else
}
else
}
if (*flags == 0)
else
(void) printf("\n\n\n");
if (is_static)
(void) printf("static ");
(void) printf("int ndr_%s (struct ndr_reference *encl_ref);\n",
if (is_static)
(void) printf("static ");
(void) printf("\t1, /* NDR version */\n");
(void) printf("\t%d, /* pdu_size_fixed_part */\n",
(void) printf("\t%d, /* pdu_size_variable_part */\n",
(void) printf("\t%d, /* c_size_fixed_part */\n",
(void) printf("\t%d, /* c_size_variable_part */\n",
(void) printf("};\n\n");
}