Home | History | Annotate | Download | only in ndrgen
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 
     22 /*
     23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 #ifndef _NDRGEN_H
     30 #define	_NDRGEN_H
     31 
     32 #ifdef __cplusplus
     33 extern "C" {
     34 #endif
     35 
     36 #include <stdio.h>
     37 #include <stdlib.h>
     38 #include <string.h>
     39 #include <assert.h>
     40 
     41 typedef struct node {
     42 	int		label;
     43 	int		line_number;
     44 	struct symbol	*file_name;
     45 	struct node	*n_next;		/* handy for lists */
     46 
     47 	union {
     48 		struct symbol		*nu_sym;
     49 		unsigned long		nu_int;
     50 		char			*nu_str;
     51 		void			*nu_ptr;
     52 		struct node		*nu_node[4];	/* descendents */
     53 		void			*nu_arg[4];	/* utility */
     54 	}	n_u;
     55 #define	n_ptr n_u.nu_ptr
     56 #define	n_sym n_u.nu_sym
     57 #define	n_str n_u.nu_str
     58 #define	n_int n_u.nu_int
     59 #define	n_arg n_u.nu_arg
     60 #define	n_node n_u.nu_node
     61 
     62 #define	n_c_advice	n_node[0]
     63 #define	n_c_typename	n_node[1]
     64 #define	n_c_members	n_node[2]
     65 
     66 #define	n_m_advice	n_node[0]
     67 #define	n_m_type	n_node[1]
     68 #define	n_m_decl	n_node[2]
     69 #define	n_m_name	n_node[3]
     70 
     71 #define	n_a_arg		n_node[0]
     72 
     73 #define	n_d_descend	n_node[0]
     74 #define	n_d_dim		n_node[1]
     75 } ndr_node_t;
     76 
     77 typedef struct keyword {
     78 	char		*name;
     79 	int		token;
     80 	long		value;
     81 } ndr_keyword_t;
     82 
     83 typedef struct symbol {
     84 	struct symbol	*next;
     85 	char		*name;
     86 	ndr_keyword_t	*kw;
     87 	struct node	*typedefn;
     88 	struct node	s_node;
     89 } ndr_symbol_t;
     90 
     91 typedef struct integer {
     92 	struct integer	*next;
     93 	long		value;
     94 	struct node	s_node;
     95 } ndr_integer_t;
     96 
     97 #define	NDLBUFSZ	100
     98 
     99 /* This makes certain things much easier */
    100 #define	N_ADVICE	18
    101 
    102 typedef struct advice {
    103 	struct node		*a_nodes[N_ADVICE];
    104 
    105 /* alias for basic types */
    106 #define	a_transmit_as	a_nodes[0]
    107 
    108 /* arg used for size, union or generic purpose */
    109 #define	a_arg_is	a_nodes[1]
    110 
    111 /* operation parameter in/out stuff */
    112 #define	a_operation	a_nodes[2]
    113 #define	a_in		a_nodes[3]
    114 #define	a_out		a_nodes[4]
    115 
    116 /* size stuff */
    117 #define	a_string	a_nodes[5]
    118 #define	a_size_is	a_nodes[6]
    119 #define	a_length_is	a_nodes[7]
    120 
    121 /* union stuff */
    122 #define	a_case		a_nodes[8]
    123 #define	a_default	a_nodes[9]
    124 #define	a_switch_is	a_nodes[10]
    125 
    126 /* interface stuff */
    127 #define	a_interface	a_nodes[11]
    128 #define	a_uuid		a_nodes[12]
    129 #define	a_no_reorder	a_nodes[13]
    130 #define	a_extern	a_nodes[14]
    131 #define	a_reference	a_nodes[15]
    132 #define	a_align		a_nodes[16]
    133 } ndr_advice_t;
    134 
    135 typedef struct typeinfo {
    136 	struct typeinfo		*next;
    137 
    138 	unsigned int		alignment	: 3;	/* mask */
    139 	unsigned int		is_conformant	: 1;
    140 	unsigned int		is_varying	: 1;
    141 	unsigned int		is_string	: 1;
    142 	unsigned int		max_given	: 1;
    143 	unsigned int		min_given	: 1;
    144 	unsigned int		complete	: 1;
    145 	unsigned int		has_pointers	: 1;
    146 	unsigned int		is_referenced	: 1;
    147 	unsigned int		is_extern	: 1;
    148 
    149 	unsigned short		type_op;	/* STAR LB */
    150 						/* STRUCT BASIC_TYPE */
    151 	struct node		*type_dim;	/* for LB */
    152 	struct typeinfo		*type_down;	/* for STAR LB */
    153 	struct node		*definition;
    154 	struct node		*type_name;	/* symbol */
    155 	ndr_advice_t		advice;
    156 	unsigned int		size_fixed_part;
    157 	unsigned int		size_variable_part;
    158 
    159 	/* size_is(n_members) */
    160 	struct member		*member;		/* array */
    161 	int			n_member;
    162 } ndr_typeinfo_t;
    163 
    164 typedef struct member {
    165 	char			*name;
    166 	struct typeinfo		*type;
    167 	int			is_conformant;
    168 	struct node		*definition;
    169 	ndr_advice_t		advice;
    170 	unsigned int		pdu_offset;
    171 } ndr_member_t;
    172 
    173 extern ndr_typeinfo_t	*typeinfo_list;
    174 extern struct node	*construct_list;
    175 
    176 /* ndr_anal.c */
    177 extern void	analyze(void);
    178 extern void	show_typeinfo_list(void);
    179 extern void	type_extern_suffix(ndr_typeinfo_t *, char *, size_t);
    180 extern void	type_null_decl(ndr_typeinfo_t *, char *, size_t);
    181 extern void	type_name_decl(ndr_typeinfo_t *, char *, size_t, char *);
    182 extern void	show_advice(ndr_advice_t *, int);
    183 extern void	member_fixup(ndr_node_t *);
    184 extern void	construct_fixup(ndr_node_t *);
    185 
    186 /* ndr_gen.c */
    187 extern void	generate(void);
    188 
    189 /* ndr_lex.c */
    190 extern ndr_symbol_t	*symbol_list;
    191 extern int		line_number;
    192 extern int		n_compile_error;
    193 extern struct node	*yylval;
    194 extern void		set_lex_input(FILE *, char *);
    195 extern int		yylex(void);
    196 extern ndr_symbol_t	*sym_enter(char *);
    197 extern void *		ndr_alloc(size_t nelem, size_t elsize);
    198 extern void		compile_error(const char *, ...);
    199 extern void		fatal_error(const char *, ...);
    200 extern struct node	*n_cons(int, ...);
    201 extern void		n_splice(struct node *, struct node *);
    202 
    203 /* ndr_print.c */
    204 extern void	tdata_dump(void);
    205 extern void	print_node(ndr_node_t *);
    206 
    207 /* ndr_parse.y */
    208 extern int	yyparse(void);
    209 
    210 /* ndr_main.c */
    211 extern int	yyerror(char *);
    212 
    213 #ifdef __cplusplus
    214 }
    215 #endif
    216 
    217 #endif /* _NDRGEN_H */
    218