/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Utility functions called by various backends.
*/
#include "xpidl.h"
void *
{
if (!p) {
exit(1);
}
return p;
}
char *
xpidl_strdup(const char *s)
{
if (ns)
#else
#endif
if (!ns) {
exit(1);
}
return ns;
}
void
{
}
/*
* Print an iid to into a supplied buffer; the buffer should be at least
* UUID_LENGTH bytes.
*/
{
int printed;
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
#ifdef SPRINTF_RETURNS_STRING
#else
return (printed == 36);
#endif
}
/* We only parse the {}-less format. */
static const char nsIDFmt2[] =
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
/*
* Parse a uuid string into an nsID struct. We cannot link against libxpcom,
* so we re-implement nsID::Parse here.
*/
{
return FALSE;
}
#ifdef DEBUG_shaver_iid
#endif
for (i = 0; i < 8; i++) {
}
#ifdef DEBUG_shaver_iid
if (count == 11) {
}
#endif
}
/* const -> list -> interface */
!= IDLN_INTERFACE) {
"const declaration \'%s\' outside interface",
name);
return FALSE;
}
/* Could be a typedef; try to map it to the real type. */
{
{
#ifndef G_HAVE_GINT64
/*
* For platforms without longlong support turned on we can get
* confused by the high bit of the long value and think that it
* represents a negative value in an unsigned declaration.
* In that case we don't know if it is the programmer who is
* confused or the compiler. So we issue a warning instead of
* an error.
*/
{
"unsigned const declaration \'%s\' "
"initialized with (possibly) negative constant",
name));
return TRUE;
}
#endif
"unsigned const declaration \'%s\' initialized with "
"negative constant",
name);
return FALSE;
}
} else {
"const declaration \'%s\' must be of type short or long",
name);
return FALSE;
}
return TRUE;
}
/*
* This method consolidates error checking needed when coercing the XPIDL compiler
* via the -t flag to generate output for a specific version of XPConnect.
*/
static gboolean
{
{
/* XPIDL Version 1.1 checks */
/* utf8string, cstring, and astring types are not supported */
{
"Cannot use [utf8string], [cstring] and [astring] "
"types when generating version 1.1 typelibs\n");
return FALSE;
}
}
return TRUE;
}
{
IDL_tree ident;
/* We don't support attributes named IID, conflicts with static GetIID
* member. The conflict is due to certain compilers (VC++) choosing a
* different vtable order, placing GetIID at the beginning regardless
* of it's placement
*/
if (strcmp(
"IID") == 0) {
"Attributes named IID not supported, causes vtable "
"ordering problems");
return FALSE;
}
/*
* Verify that we've been called on an interface, and decide if the
* interface was marked [scriptable].
*/
== IDLN_INTERFACE)
{
!= NULL);
} else {
"verify_attribute_declaration called on a non-interface?");
return FALSE;
}
/*
* Grab the first of the list of idents and hope that it'll
* say scriptable or no.
*/
/*
* If the interface isn't scriptable, or the attribute is marked noscript,
* there's no need to check.
*/
if (!scriptable_interface ||
return TRUE;
/*
* If it should be scriptable, check that the type is non-native. nsid,
* domstring, utf8string, cstring, astring are exempted.
*/
{
if (UP_IS_NATIVE(attr_type) &&
{
"attributes in [scriptable] interfaces that are "
"non-scriptable because they refer to native "
"types must be marked [noscript]\n");
return FALSE;
}
/*
* We currently don't support properties of type nsid that aren't
* pointers or references, unless they are marked [notxpcom} and
* must be read-only
*/
{
"Feature not currently supported: "
"attributes with a type of nsid must be marked "
"either [ptr] or [ref], or "
"else must be marked [notxpcom] "
"and must be read-only\n");
return FALSE;
}
/*
* Run additional error checks on the attribute type if targetting an
* older version of XPConnect.
*/
return FALSE;
}
{
"multiple attributes in a single declaration is not supported\n");
return FALSE;
}
return TRUE;
}
/*
* Find the underlying type of an identifier typedef.
*
* All the needed tree-walking seems pretty shaky; isn't there something in
* libIDL to automate this?
*/
IDL_tree /* IDL_TYPE_DCL */
{
return NULL;
return NULL;
return NULL;
}
static IDL_tree /* IDL_PARAM_DCL */
{
{
return param;
}
return NULL;
}
typedef enum ParamAttrType {
/*
* Check that parameters referred to by attributes such as size_is exist and
* refer to parameters of the appropriate type.
*/
static gboolean
{
const char *attr_name;
const char *needed_type;
if (whattocheck == IID_IS) {
attr_name = "iid_is";
needed_type = "IID";
} else if (whattocheck == LENGTH_IS) {
attr_name = "length_is";
needed_type = "unsigned long (or PRUint32)";
} else if (whattocheck == SIZE_IS) {
attr_name = "size_is";
needed_type = "unsigned long (or PRUint32)";
} else {
XPT_ASSERT("asked to check an unknown attribute type!");
return TRUE;
}
if (referred_name != NULL) {
if (referred_param == NULL) {
"attribute [%s(%s)] refers to missing "
"parameter \"%s\"",
return FALSE;
}
if (referred_param == param) {
"attribute [%s(%s)] refers to it's own parameter",
return FALSE;
}
if (whattocheck == IID_IS) {
/* require IID type */
"target \"%s\" of [%s(%s)] attribute "
"must be of %s type",
return FALSE;
}
/* require PRUint32 type */
/* Could be a typedef; try to map it to the real type. */
{
"target \"%s\" of [%s(%s)] attribute "
"must be of %s type",
return FALSE;
}
}
}
return TRUE;
}
/*
* Common method verification code, called by *op_dcl in the various backends.
*/
{
/* We don't support attributes named IID, conflicts with static GetIID
* member. The conflict is due to certain compilers (VC++) choosing a
* different vtable order, placing GetIID at the beginning regardless
* of it's placement
*/
"Methods named GetIID not supported, causes vtable "
"ordering problems");
return FALSE;
}
/* We don't currently support varargs. */
return FALSE;
}
/*
* Verify that we've been called on an interface, and decide if the
* interface was marked [scriptable].
*/
== IDLN_INTERFACE)
{
!= NULL);
} else {
"verify_method_declaration called on a non-interface?");
return FALSE;
}
/*
* Require that any method in an interface marked as [scriptable], that
* *isn't* scriptable because it refers to some native type, be marked
* [noscript] or [notxpcom].
*
* Also check that iid_is points to nsid, and length_is, size_is points
* to unsigned long.
*/
!notxpcom &&
/* Loop through the parameters and check. */
/*
* Reject this method if it should be scriptable and some parameter is
* native that isn't marked with either nsid, domstring, utf8string,
* cstring, astring or iid_is.
*/
if (scriptable_method &&
{
"methods in [scriptable] interfaces that are "
"non-scriptable because they refer to native "
"types (parameter \"%s\") must be marked "
"[noscript]", param_name);
return FALSE;
}
/*
* nsid's parameters that aren't ptr's or ref's are not currently
* supported in xpcom or non-xpcom (marked with [notxpcom]) methods
* as input parameters
*/
{
"Feature currently not supported: "
"parameter \"%s\" is of type nsid and "
"must be marked either [ptr] or [ref] "
"or method \"%s\" must be marked [notxpcom] "
"and must not be an input parameter",
return FALSE;
}
/*
* Sanity checks on return values.
*/
"only the last parameter can be marked [retval]");
return FALSE;
}
if (op->op_type_spec) {
"can't have [retval] with non-void return type");
return FALSE;
}
/* In case XPConnect relaxes the retval-is-last restriction. */
if (seen_retval) {
"can't have more than one [retval] parameter");
return FALSE;
}
seen_retval = TRUE;
}
/*
* Confirm that [shared] attributes are only used with string, wstring,
* or native (but not nsid, domstring, utf8string, cstring or astring)
* and can't be used with [array].
*/
"[shared] parameter \"%s\" cannot "
"be of array type", param_name);
return FALSE;
}
(UP_IS_NATIVE(real_type) &&
{
"[shared] parameter \"%s\" must be of type "
"string, wstring or native", param_name);
return FALSE;
}
}
/*
* inout is not allowed with "domstring", "UTF8String", "CString"
* and "AString" types
*/
"[domstring], [utf8string], [cstring], [astring] "
"types cannot be used as inout parameters");
return FALSE;
}
/*
* arrays of domstring, utf8string, cstring, astring types not allowed
*/
"[domstring], [utf8string], [cstring], [astring] "
"types cannot be used in array parameters");
return FALSE;
}
return FALSE;
/*
* Run additional error checks on the parameter type if targetting an
* older version of XPConnect.
*/
return FALSE;
}
/* XXX q: can return type be nsid? */
/* Native return type? */
if (scriptable_method &&
{
"methods in [scriptable] interfaces that are "
"non-scriptable because they return native "
"types must be marked [noscript]");
return FALSE;
}
/*
* nsid's parameters that aren't ptr's or ref's are not currently
* supported in xpcom
*/
if (!notxpcom &&
{
"Feature currently not supported: "
"return value is of type nsid and "
"must be marked either [ptr] or [ref], "
"or else method \"%s\" must be marked [notxpcom] ",
return FALSE;
}
/*
* Run additional error checks on the return type if targetting an
* older version of XPConnect.
*/
{
return FALSE;
}
return TRUE;
}
/*
* Verify that a native declaration has an associated C++ expression, i.e. that
* it's of the form native <idl-name>(<c++-name>)
*/
{
char *native_name;
/* require that native declarations give a native type */
return TRUE;
"``native %s;'' needs C++ type: ``native %s(<C++ type>);''",
return FALSE;
}
/*
* Print a GSList as char strings to a file.
*/
void
{
guint i;
for(i = 0; i < len; i++) {
}
}
void
{
while (p) {
return;
}
}
/*
* Verify that the interface declaration is correct
*/
{
/*
* If we have the scriptable attribute then make sure all of our direct
* parents have it as well.
* NOTE: We don't recurse since all interfaces will fall through here
*/
"scriptable")) {
"%s is scriptable but inherits from the non-scriptable interface %s\n",
}
}
}
return TRUE;
}
/*
* Return a pointer to the start of the base filename of path
*/
const char *
{
/*
*If this is windows then we'll handle either / or \ as a separator
* g_basename only handles \ for windows
*/
#if defined(XP_WIN32)
/* If we found a slash and its after the current default OS separator */
#endif
return result;
}