1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Netscape Public License
|
---|
6 | * Version 1.1 (the "License"); you may not use this file except in
|
---|
7 | * compliance with the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/NPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the NPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the NPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Intramodule declarations.
|
---|
40 | */
|
---|
41 |
|
---|
42 | #ifndef __xpidl_h
|
---|
43 | #define __xpidl_h
|
---|
44 |
|
---|
45 | #include <errno.h>
|
---|
46 | #include <stddef.h>
|
---|
47 | #include <stdio.h>
|
---|
48 | #include <stdlib.h>
|
---|
49 | #include <glib.h>
|
---|
50 | #include <string.h> /* After glib.h to avoid warnings about shadowing 'index'. */
|
---|
51 |
|
---|
52 | #ifndef XP_MAC
|
---|
53 | #include <libIDL/IDL.h>
|
---|
54 | #else
|
---|
55 | #include <IDL.h>
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #include <xpt_struct.h>
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * IDL_tree_warning bombs on libIDL version 6.5, and I don't want to not write
|
---|
62 | * warnings... so I define a versioned one here. Thanks to Mike Shaver for the
|
---|
63 | * this solution, which allows us to pass through varargs calls.
|
---|
64 | */
|
---|
65 | #if !(LIBIDL_MAJOR_VERSION == 0 && LIBIDL_MINOR_VERSION == 6 && \
|
---|
66 | LIBIDL_MICRO_VERSION == 5) && !defined(DEBUG_shaver)
|
---|
67 | /*
|
---|
68 | * This turns a varargs call to XPIDL_WARNING directly into a varargs
|
---|
69 | * call to IDL_tree_warning or xpidl_tree_warning as appropriate. The
|
---|
70 | * only tricky bit is that you must call XPIDL_WARNING with extra
|
---|
71 | * parens, e.g. XPIDL_WARNING((foo, bar, "sil"))
|
---|
72 | *
|
---|
73 | * Probably best removed when we leave 6.5. */
|
---|
74 | #define XPIDL_WARNING(x) IDL_tree_warning x
|
---|
75 | #else
|
---|
76 | extern void xpidl_tree_warning(IDL_tree p, int level, const char *fmt, ...);
|
---|
77 | #define XPIDL_WARNING(x) xpidl_tree_warning x
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * Internal operation flags.
|
---|
82 | */
|
---|
83 | extern gboolean enable_debug;
|
---|
84 | extern gboolean enable_warnings;
|
---|
85 | extern gboolean verbose_mode;
|
---|
86 | extern gboolean emit_typelib_annotations;
|
---|
87 | extern gboolean explicit_output_filename;
|
---|
88 |
|
---|
89 | extern PRUint8 major_version;
|
---|
90 | extern PRUint8 minor_version;
|
---|
91 |
|
---|
92 | typedef struct TreeState TreeState;
|
---|
93 |
|
---|
94 | /*
|
---|
95 | * A function to handle an IDL_tree type.
|
---|
96 | */
|
---|
97 | typedef gboolean (*nodeHandler)(TreeState *);
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * Struct containing functions to define the behavior of a given output mode.
|
---|
101 | */
|
---|
102 | typedef struct backend {
|
---|
103 | nodeHandler *dispatch_table; /* nodeHandlers table, indexed by node type. */
|
---|
104 | nodeHandler emit_prolog; /* called at beginning of output generation. */
|
---|
105 | nodeHandler emit_epilog; /* called at end. */
|
---|
106 | } backend;
|
---|
107 |
|
---|
108 | /* Function that produces a struct of output-generation functions */
|
---|
109 | typedef backend *(*backendFactory)();
|
---|
110 |
|
---|
111 | extern backend *xpidl_header_dispatch(void);
|
---|
112 | extern backend *xpidl_typelib_dispatch(void);
|
---|
113 | extern backend *xpidl_doc_dispatch(void);
|
---|
114 | extern backend *xpidl_java_dispatch(void);
|
---|
115 |
|
---|
116 | typedef struct ModeData {
|
---|
117 | char *mode;
|
---|
118 | char *modeInfo;
|
---|
119 | char *suffix;
|
---|
120 | backendFactory factory;
|
---|
121 | } ModeData;
|
---|
122 |
|
---|
123 | typedef struct IncludePathEntry {
|
---|
124 | char *directory;
|
---|
125 | struct IncludePathEntry *next;
|
---|
126 | } IncludePathEntry;
|
---|
127 |
|
---|
128 | struct TreeState {
|
---|
129 | FILE *file;
|
---|
130 | /* Maybe supplied by -o. Not related to (g_)basename from string.h or glib */
|
---|
131 | char *basename;
|
---|
132 | IDL_ns ns;
|
---|
133 | IDL_tree tree;
|
---|
134 | GSList *base_includes;
|
---|
135 | nodeHandler *dispatch;
|
---|
136 | void *priv; /* mode-private data */
|
---|
137 | };
|
---|
138 |
|
---|
139 | /*
|
---|
140 | * Process an IDL file, generating InterfaceInfo, documentation and headers as
|
---|
141 | * appropriate.
|
---|
142 | */
|
---|
143 | int
|
---|
144 | xpidl_process_idl(char *filename, IncludePathEntry *include_path,
|
---|
145 | char *file_basename, ModeData *mode);
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * Iterate over an IDLN_LIST -- why is this not part of libIDL?
|
---|
149 | */
|
---|
150 | void
|
---|
151 | xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data);
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * Wrapper whines to stderr then exits after null return from malloc or strdup.
|
---|
155 | */
|
---|
156 | void *
|
---|
157 | xpidl_malloc(size_t nbytes);
|
---|
158 |
|
---|
159 | char *
|
---|
160 | xpidl_strdup(const char *s);
|
---|
161 |
|
---|
162 | /*
|
---|
163 | * Return a pointer to the start of the base filename of path
|
---|
164 | */
|
---|
165 | const char *
|
---|
166 | xpidl_basename(const char * path);
|
---|
167 |
|
---|
168 | /*
|
---|
169 | * Process an XPIDL node and its kids, if any.
|
---|
170 | */
|
---|
171 | gboolean
|
---|
172 | xpidl_process_node(TreeState *state);
|
---|
173 |
|
---|
174 | /*
|
---|
175 | * Write a newline folllowed by an indented, one-line comment containing IDL
|
---|
176 | * source decompiled from state->tree.
|
---|
177 | */
|
---|
178 | void
|
---|
179 | xpidl_write_comment(TreeState *state, int indent);
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 | /*
|
---|
184 | * Functions for parsing and printing UUIDs.
|
---|
185 | */
|
---|
186 |
|
---|
187 | /*
|
---|
188 | * How large should the buffer supplied to xpidl_sprint_IID be?
|
---|
189 | */
|
---|
190 | #define UUID_LENGTH 37
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * Print an iid to into a supplied buffer; the buffer should be at least
|
---|
194 | * UUID_LENGTH bytes.
|
---|
195 | */
|
---|
196 | gboolean
|
---|
197 | xpidl_sprint_iid(nsID *iid, char iidbuf[]);
|
---|
198 |
|
---|
199 | /*
|
---|
200 | * Parse a uuid string into an nsID struct. We cannot link against libxpcom,
|
---|
201 | * so we re-implement nsID::Parse here.
|
---|
202 | */
|
---|
203 | gboolean
|
---|
204 | xpidl_parse_iid(nsID *id, const char *str);
|
---|
205 |
|
---|
206 |
|
---|
207 | /* Try to common a little node-handling stuff. */
|
---|
208 |
|
---|
209 | /* is this node from an aggregate type (interface)? */
|
---|
210 | #define UP_IS_AGGREGATE(node) \
|
---|
211 | (IDL_NODE_UP(node) && \
|
---|
212 | (IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_INTERFACE || \
|
---|
213 | IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_FORWARD_DCL))
|
---|
214 |
|
---|
215 | #define UP_IS_NATIVE(node) \
|
---|
216 | (IDL_NODE_UP(node) && \
|
---|
217 | IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_NATIVE)
|
---|
218 |
|
---|
219 | /* is this type output in the form "<foo> *"? */
|
---|
220 | #define STARRED_TYPE(node) (IDL_NODE_TYPE(node) == IDLN_TYPE_STRING || \
|
---|
221 | IDL_NODE_TYPE(node) == IDLN_TYPE_WIDE_STRING || \
|
---|
222 | (IDL_NODE_TYPE(node) == IDLN_IDENT && \
|
---|
223 | UP_IS_AGGREGATE(node)))
|
---|
224 |
|
---|
225 | #define DIPPER_TYPE(node) \
|
---|
226 | (NULL != IDL_tree_property_get(node, "domstring") || \
|
---|
227 | NULL != IDL_tree_property_get(node, "utf8string") || \
|
---|
228 | NULL != IDL_tree_property_get(node, "cstring") || \
|
---|
229 | NULL != IDL_tree_property_get(node, "astring"))
|
---|
230 |
|
---|
231 | /*
|
---|
232 | * Find the underlying type of an identifier typedef. Returns NULL
|
---|
233 | * (and doesn't complain) on failure.
|
---|
234 | */
|
---|
235 | IDL_tree /* IDL_TYPE_DCL */
|
---|
236 | find_underlying_type(IDL_tree typedef_ident);
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * Check that const declarations match their stated sign and are of the
|
---|
240 | * appropriate types.
|
---|
241 | */
|
---|
242 | gboolean
|
---|
243 | verify_const_declaration(IDL_tree const_tree);
|
---|
244 |
|
---|
245 | /*
|
---|
246 | * Check that scriptable attributes in scriptable interfaces actually are.
|
---|
247 | */
|
---|
248 | gboolean
|
---|
249 | verify_attribute_declaration(IDL_tree method_tree);
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * Perform various validation checks on methods.
|
---|
253 | */
|
---|
254 | gboolean
|
---|
255 | verify_method_declaration(IDL_tree method_tree);
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * Verifies the interface declaration
|
---|
259 | */
|
---|
260 | gboolean
|
---|
261 | verify_interface_declaration(IDL_tree method_tree);
|
---|
262 |
|
---|
263 | /*
|
---|
264 | * Verify that a native declaration has an associated C++ expression, i.e. that
|
---|
265 | * it's of the form native <idl-name>(<c++-name>)
|
---|
266 | */
|
---|
267 | gboolean
|
---|
268 | check_native(TreeState *state);
|
---|
269 |
|
---|
270 | void
|
---|
271 | printlist(FILE *outfile, GSList *slist);
|
---|
272 |
|
---|
273 | #endif /* __xpidl_h */
|
---|