Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / xpcom / typelib / xpidl / xpidl.h
blob7a2f1322a334740f0b2fa034a5926bccea4b4b8d
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
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 MPL, 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 MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * Intramodule declarations.
42 #ifndef __xpidl_h
43 #define __xpidl_h
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'. */
52 #include <libIDL/IDL.h>
54 #include <xpt_struct.h>
57 * IDL_tree_warning bombs on libIDL version 6.5, and I don't want to not write
58 * warnings... so I define a versioned one here. Thanks to Mike Shaver for the
59 * this solution, which allows us to pass through varargs calls.
61 #if !(LIBIDL_MAJOR_VERSION == 0 && LIBIDL_MINOR_VERSION == 6 && \
62 LIBIDL_MICRO_VERSION == 5) && !defined(DEBUG_shaver)
64 * This turns a varargs call to XPIDL_WARNING directly into a varargs
65 * call to IDL_tree_warning or xpidl_tree_warning as appropriate. The
66 * only tricky bit is that you must call XPIDL_WARNING with extra
67 * parens, e.g. XPIDL_WARNING((foo, bar, "sil"))
69 * Probably best removed when we leave 6.5. */
70 #define XPIDL_WARNING(x) IDL_tree_warning x
71 #else
72 extern void xpidl_tree_warning(IDL_tree p, int level, const char *fmt, ...);
73 #define XPIDL_WARNING(x) xpidl_tree_warning x
74 #endif
77 * Internal operation flags.
79 extern gboolean enable_debug;
80 extern gboolean enable_warnings;
81 extern gboolean verbose_mode;
82 extern gboolean emit_typelib_annotations;
83 extern gboolean explicit_output_filename;
84 extern FILE *deps;
86 extern PRUint8 major_version;
87 extern PRUint8 minor_version;
89 typedef struct TreeState TreeState;
92 * A function to handle an IDL_tree type.
94 typedef gboolean (*nodeHandler)(TreeState *);
97 * Struct containing functions to define the behavior of a given output mode.
99 typedef struct backend {
100 nodeHandler *dispatch_table; /* nodeHandlers table, indexed by node type. */
101 nodeHandler emit_prolog; /* called at beginning of output generation. */
102 nodeHandler emit_epilog; /* called at end. */
103 } backend;
105 /* Function that produces a struct of output-generation functions */
106 typedef backend *(*backendFactory)();
108 extern backend *xpidl_header_dispatch(void);
109 extern backend *xpidl_typelib_dispatch(void);
110 extern backend *xpidl_doc_dispatch(void);
111 extern backend *xpidl_java_dispatch(void);
113 typedef struct ModeData {
114 char *mode;
115 char *modeInfo;
116 char *suffix;
117 backendFactory factory;
118 } ModeData;
120 typedef struct IncludePathEntry {
121 char *directory;
122 struct IncludePathEntry *next;
123 } IncludePathEntry;
125 struct TreeState {
126 FILE *file;
127 char *filename;
128 /* Maybe supplied by -o. Not related to (g_)basename from string.h or glib */
129 char *basename;
130 IDL_ns ns;
131 IDL_tree tree;
132 GSList *base_includes;
133 nodeHandler *dispatch;
134 void *priv; /* mode-private data */
137 struct java_priv_data {
138 GHashTable *typedefTable;
139 GHashTable *keywords;
140 char *filename;
141 GHashTable *nonIDLIfaces;
145 * Process an IDL file, generating InterfaceInfo, documentation and headers as
146 * appropriate.
149 xpidl_process_idl(char *filename, IncludePathEntry *include_path,
150 char *file_basename, ModeData *mode);
153 * Iterate over an IDLN_LIST -- why is this not part of libIDL?
155 void
156 xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data);
159 * Wrapper whines to stderr then exits after null return from malloc or strdup.
161 void *
162 xpidl_malloc(size_t nbytes);
164 char *
165 xpidl_strdup(const char *s);
168 * Return a pointer to the start of the base filename of path
170 const char *
171 xpidl_basename(const char * path);
174 * Process an XPIDL node and its kids, if any.
176 gboolean
177 xpidl_process_node(TreeState *state);
180 * Write a newline folllowed by an indented, one-line comment containing IDL
181 * source decompiled from state->tree.
183 void
184 xpidl_write_comment(TreeState *state, int indent);
189 * Functions for parsing and printing UUIDs.
193 * How large should the buffer supplied to xpidl_sprint_IID be?
195 #define UUID_LENGTH 37
198 * Print an iid to into a supplied buffer; the buffer should be at least
199 * UUID_LENGTH bytes.
201 gboolean
202 xpidl_sprint_iid(nsID *iid, char iidbuf[]);
205 * Parse a uuid string into an nsID struct. We cannot link against libxpcom,
206 * so we re-implement nsID::Parse here.
208 gboolean
209 xpidl_parse_iid(nsID *id, const char *str);
212 /* Try to common a little node-handling stuff. */
214 /* is this node from an aggregate type (interface)? */
215 #define UP_IS_AGGREGATE(node) \
216 (IDL_NODE_UP(node) && \
217 (IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_INTERFACE || \
218 IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_FORWARD_DCL))
220 #define UP_IS_NATIVE(node) \
221 (IDL_NODE_UP(node) && \
222 IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_NATIVE)
224 /* is this type output in the form "<foo> *"? */
225 #define STARRED_TYPE(node) (IDL_NODE_TYPE(node) == IDLN_TYPE_STRING || \
226 IDL_NODE_TYPE(node) == IDLN_TYPE_WIDE_STRING || \
227 (IDL_NODE_TYPE(node) == IDLN_IDENT && \
228 UP_IS_AGGREGATE(node)))
230 #define DIPPER_TYPE(node) \
231 (NULL != IDL_tree_property_get(node, "domstring") || \
232 NULL != IDL_tree_property_get(node, "utf8string") || \
233 NULL != IDL_tree_property_get(node, "cstring") || \
234 NULL != IDL_tree_property_get(node, "astring"))
237 * Find the underlying type of an identifier typedef. Returns NULL
238 * (and doesn't complain) on failure.
240 IDL_tree /* IDL_TYPE_DCL */
241 find_underlying_type(IDL_tree typedef_ident);
244 * Check that const declarations match their stated sign and are of the
245 * appropriate types.
247 gboolean
248 verify_const_declaration(IDL_tree const_tree);
251 * Check that scriptable attributes in scriptable interfaces actually are.
253 gboolean
254 verify_attribute_declaration(IDL_tree method_tree);
257 * Perform various validation checks on methods.
259 gboolean
260 verify_method_declaration(IDL_tree method_tree);
263 * Verifies the interface declaration
265 gboolean
266 verify_interface_declaration(IDL_tree method_tree);
269 * Verify that a native declaration has an associated C++ expression, i.e. that
270 * it's of the form native <idl-name>(<c++-name>)
272 gboolean
273 check_native(TreeState *state);
275 void
276 printlist(FILE *outfile, GSList *slist);
278 gboolean
279 is_method_scriptable(IDL_tree method_tree, IDL_tree ident);
281 #endif /* __xpidl_h */