xref: /titanic_51/usr/src/tools/ndrgen/ndrgen.h (revision 356f72340a69936724c69f2f87fffa6f5887f885)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _NDRGEN_H
28 #define	_NDRGEN_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <assert.h>
38 
39 typedef struct node {
40 	int		label;
41 	int		line_number;
42 	struct symbol	*file_name;
43 	struct node	*n_next;		/* handy for lists */
44 
45 	union {
46 		struct symbol		*nu_sym;
47 		unsigned long		nu_int;
48 		char			*nu_str;
49 		void			*nu_ptr;
50 		struct node		*nu_node[4];	/* descendents */
51 		void			*nu_arg[4];	/* utility */
52 	}	n_u;
53 #define	n_ptr n_u.nu_ptr
54 #define	n_sym n_u.nu_sym
55 #define	n_str n_u.nu_str
56 #define	n_int n_u.nu_int
57 #define	n_arg n_u.nu_arg
58 #define	n_node n_u.nu_node
59 
60 #define	n_c_advice	n_node[0]
61 #define	n_c_typename	n_node[1]
62 #define	n_c_members	n_node[2]
63 
64 #define	n_m_advice	n_node[0]
65 #define	n_m_type	n_node[1]
66 #define	n_m_decl	n_node[2]
67 #define	n_m_name	n_node[3]
68 
69 #define	n_a_arg		n_node[0]
70 #define	n_a_arg1	n_node[1]
71 #define	n_a_arg2	n_node[2]
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 void *		ndr_alloc(size_t nelem, size_t elsize);
197 extern void		compile_error(const char *, ...);
198 extern void		fatal_error(const char *, ...);
199 extern struct node	*n_cons(int, ...);
200 extern void		n_splice(struct node *, struct node *);
201 
202 /* ndr_print.c */
203 extern void	tdata_dump(void);
204 extern void	print_node(ndr_node_t *);
205 extern void	print_field_attr(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