Back to index

lightning-sunbird  0.9+nobinonly
xpidl.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * Intramodule declarations.
00040  */
00041 
00042 #ifndef __xpidl_h
00043 #define __xpidl_h
00044 
00045 #include <errno.h>
00046 #include <stddef.h>
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <glib.h>
00050 #include <string.h> /* After glib.h to avoid warnings about shadowing 'index'. */
00051 
00052 #ifndef XP_MAC
00053 #include <libIDL/IDL.h>
00054 #else
00055 #include <IDL.h>
00056 #endif
00057 
00058 #include <xpt_struct.h>
00059 
00060 /*
00061  * IDL_tree_warning bombs on libIDL version 6.5, and I don't want to not write
00062  * warnings... so I define a versioned one here.  Thanks to Mike Shaver for the
00063  * this solution, which allows us to pass through varargs calls.
00064  */
00065 #if !(LIBIDL_MAJOR_VERSION == 0 && LIBIDL_MINOR_VERSION == 6 && \
00066       LIBIDL_MICRO_VERSION == 5) && !defined(DEBUG_shaver)
00067 /*
00068  * This turns a varargs call to XPIDL_WARNING directly into a varargs
00069  * call to IDL_tree_warning or xpidl_tree_warning as appropriate.  The
00070  * only tricky bit is that you must call XPIDL_WARNING with extra
00071  * parens, e.g. XPIDL_WARNING((foo, bar, "sil"))
00072  *
00073  * Probably best removed when we leave 6.5.  */
00074 #define XPIDL_WARNING(x) IDL_tree_warning x
00075 #else
00076 extern void xpidl_tree_warning(IDL_tree p, int level, const char *fmt, ...);
00077 #define XPIDL_WARNING(x) xpidl_tree_warning x
00078 #endif
00079 
00080 /*
00081  * Internal operation flags.
00082  */
00083 extern gboolean enable_debug;
00084 extern gboolean enable_warnings;
00085 extern gboolean verbose_mode;
00086 extern gboolean emit_typelib_annotations;
00087 extern gboolean explicit_output_filename;
00088 
00089 extern PRUint8  major_version;
00090 extern PRUint8  minor_version;
00091 
00092 typedef struct TreeState TreeState;
00093 
00094 /*
00095  * A function to handle an IDL_tree type.
00096  */
00097 typedef gboolean (*nodeHandler)(TreeState *);
00098 
00099 /*
00100  * Struct containing functions to define the behavior of a given output mode.
00101  */
00102 typedef struct backend {
00103     nodeHandler *dispatch_table; /* nodeHandlers table, indexed by node type. */
00104     nodeHandler emit_prolog;     /* called at beginning of output generation. */
00105     nodeHandler emit_epilog;     /* called at end. */
00106 } backend;
00107 
00108 /* Function that produces a struct of output-generation functions */
00109 typedef backend *(*backendFactory)();
00110  
00111 extern backend *xpidl_header_dispatch(void);
00112 extern backend *xpidl_typelib_dispatch(void);
00113 extern backend *xpidl_doc_dispatch(void);
00114 extern backend *xpidl_java_dispatch(void);
00115 
00116 typedef struct ModeData {
00117     char               *mode;
00118     char               *modeInfo;
00119     char               *suffix;
00120     backendFactory     factory;
00121 } ModeData;
00122 
00123 typedef struct IncludePathEntry {
00124     char                    *directory;
00125     struct IncludePathEntry *next;
00126 } IncludePathEntry;
00127 
00128 struct TreeState {
00129     FILE             *file;
00130     char             *filename;
00131     /* Maybe supplied by -o. Not related to (g_)basename from string.h or glib */
00132     char             *basename;
00133     char             *package;
00134     IDL_ns           ns;
00135     IDL_tree         tree;
00136     GSList           *base_includes;
00137     nodeHandler      *dispatch;
00138     void             *priv;     /* mode-private data */
00139 };
00140 
00141 
00142 struct java_priv_data {
00143     GHashTable *typedefTable;
00144     int         numMethods;
00145     gboolean    bHasBaseClass;
00146     gboolean    bCountingMethods;
00147 
00148     GHashTable *keywords;
00149     char       *filename;
00150 };
00151 
00152 /*
00153  * Process an IDL file, generating InterfaceInfo, documentation and headers as
00154  * appropriate.
00155  */
00156 int
00157 xpidl_process_idl(char *filename, IncludePathEntry *include_path,
00158                   char *file_basename, char *package, ModeData *mode);
00159 
00160 /*
00161  * Iterate over an IDLN_LIST -- why is this not part of libIDL?
00162  */
00163 void
00164 xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data);
00165 
00166 /*
00167  * Wrapper whines to stderr then exits after null return from malloc or strdup.
00168  */
00169 void *
00170 xpidl_malloc(size_t nbytes);
00171 
00172 char *
00173 xpidl_strdup(const char *s);
00174 
00175 /*
00176  * Return a pointer to the start of the base filename of path
00177  */
00178 const char *
00179 xpidl_basename(const char * path);
00180 
00181 /*
00182  * Process an XPIDL node and its kids, if any.
00183  */
00184 gboolean
00185 xpidl_process_node(TreeState *state);
00186 
00187 /*
00188  * Write a newline folllowed by an indented, one-line comment containing IDL
00189  * source decompiled from state->tree.
00190  */
00191 void
00192 xpidl_write_comment(TreeState *state, int indent);
00193 
00194 
00195 
00196 /*
00197  * Functions for parsing and printing UUIDs.
00198  */
00199 
00200 /*
00201  * How large should the buffer supplied to xpidl_sprint_IID be?
00202  */
00203 #define UUID_LENGTH 37
00204 
00205 /*
00206  * Print an iid to into a supplied buffer; the buffer should be at least
00207  * UUID_LENGTH bytes.
00208  */
00209 gboolean
00210 xpidl_sprint_iid(nsID *iid, char iidbuf[]);
00211 
00212 /*
00213  * Parse a uuid string into an nsID struct.  We cannot link against libxpcom,
00214  * so we re-implement nsID::Parse here.
00215  */
00216 gboolean
00217 xpidl_parse_iid(nsID *id, const char *str);
00218 
00219 
00220 /* Try to common a little node-handling stuff. */
00221 
00222 /* is this node from an aggregate type (interface)? */
00223 #define UP_IS_AGGREGATE(node)                                                 \
00224     (IDL_NODE_UP(node) &&                                                     \
00225      (IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_INTERFACE ||                   \
00226       IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_FORWARD_DCL))
00227 
00228 #define UP_IS_NATIVE(node)                                                    \
00229     (IDL_NODE_UP(node) &&                                                     \
00230      IDL_NODE_TYPE(IDL_NODE_UP(node)) == IDLN_NATIVE)
00231 
00232 /* is this type output in the form "<foo> *"? */
00233 #define STARRED_TYPE(node) (IDL_NODE_TYPE(node) == IDLN_TYPE_STRING ||        \
00234                             IDL_NODE_TYPE(node) == IDLN_TYPE_WIDE_STRING ||   \
00235                             (IDL_NODE_TYPE(node) == IDLN_IDENT &&             \
00236                              UP_IS_AGGREGATE(node)))
00237 
00238 #define DIPPER_TYPE(node)                                                     \
00239     (NULL != IDL_tree_property_get(node, "domstring")  ||                     \
00240      NULL != IDL_tree_property_get(node, "utf8string") ||                     \
00241      NULL != IDL_tree_property_get(node, "cstring")    ||                     \
00242      NULL != IDL_tree_property_get(node, "astring"))
00243 
00244 /*
00245  * Find the underlying type of an identifier typedef.  Returns NULL
00246  * (and doesn't complain) on failure.
00247  */
00248 IDL_tree /* IDL_TYPE_DCL */
00249 find_underlying_type(IDL_tree typedef_ident);
00250 
00251 /*
00252  * Check that const declarations match their stated sign and are of the
00253  * appropriate types.
00254  */
00255 gboolean
00256 verify_const_declaration(IDL_tree const_tree);
00257 
00258 /*
00259  * Check that scriptable attributes in scriptable interfaces actually are.
00260  */
00261 gboolean
00262 verify_attribute_declaration(IDL_tree method_tree);
00263 
00264 /*
00265  * Perform various validation checks on methods.
00266  */
00267 gboolean
00268 verify_method_declaration(IDL_tree method_tree);
00269 
00270 /*
00271  * Verifies the interface declaration
00272  */ 
00273 gboolean
00274 verify_interface_declaration(IDL_tree method_tree);
00275 
00276 /*
00277  * Verify that a native declaration has an associated C++ expression, i.e. that
00278  * it's of the form native <idl-name>(<c++-name>)
00279  */
00280 gboolean
00281 check_native(TreeState *state);
00282 
00283 void
00284 printlist(FILE *outfile, GSList *slist);
00285 
00286 #endif /* __xpidl_h */