VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_util.c

Last change on this file was 103505, checked in by vboxsync, 2 months ago

libs/xpcom: Fix some unused variable warnings, bugref:3409

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.1 KB
Line 
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 * Utility functions called by various backends.
40 */
41
42#include "xpidl.h"
43
44/* XXXbe static */ char OOM[] = "ERROR: out of memory\n";
45
46void *
47xpidl_malloc(size_t nbytes)
48{
49 void *p = malloc(nbytes);
50 if (!p) {
51 fputs(OOM, stderr);
52 exit(1);
53 }
54 return p;
55}
56
57char *
58xpidl_strdup(const char *s)
59{
60#if defined(XP_MAC) || defined(XP_SOLARIS) /* bird: dunno why this is required, but whatever*/
61 size_t len = strlen(s);
62 char *ns = malloc(len + 1);
63 if (ns)
64 memcpy(ns, s, len + 1);
65#else
66 char *ns = strdup(s);
67#endif
68 if (!ns) {
69 fputs(OOM, stderr);
70 exit(1);
71 }
72 return ns;
73}
74
75void
76xpidl_write_comment(TreeState *state, int indent)
77{
78 fprintf(state->file, "%*s/* ", indent, "");
79 IDL_tree_to_IDL(state->tree, state->ns, state->file,
80 IDLF_OUTPUT_NO_NEWLINES |
81 IDLF_OUTPUT_NO_QUALIFY_IDENTS |
82 IDLF_OUTPUT_PROPERTIES);
83 fputs(" */\n", state->file);
84}
85
86/*
87 * Print an iid to into a supplied buffer; the buffer should be at least
88 * UUID_LENGTH bytes.
89 */
90gboolean
91xpidl_sprint_iid(nsID *id, char iidbuf[])
92{
93 int printed;
94
95 printed = sprintf(iidbuf,
96 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
97 (PRUint32) id->m0, (PRUint32) id->m1,(PRUint32) id->m2,
98 (PRUint32) id->m3[0], (PRUint32) id->m3[1],
99 (PRUint32) id->m3[2], (PRUint32) id->m3[3],
100 (PRUint32) id->m3[4], (PRUint32) id->m3[5],
101 (PRUint32) id->m3[6], (PRUint32) id->m3[7]);
102
103#ifdef SPRINTF_RETURNS_STRING
104 return (printed && strlen((char *)printed) == 36);
105#else
106 return (printed == 36);
107#endif
108}
109
110/* We only parse the {}-less format. */
111static const char nsIDFmt2[] =
112 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
113
114/*
115 * Parse a uuid string into an nsID struct. We cannot link against libxpcom,
116 * so we re-implement nsID::Parse here.
117 */
118gboolean
119xpidl_parse_iid(nsID *id, const char *str)
120{
121 PRInt32 count = 0;
122 PRInt32 n1, n2, n3[8];
123 PRInt32 n0, i;
124
125 XPT_ASSERT(str != NULL);
126
127 if (strlen(str) != 36) {
128 return FALSE;
129 }
130
131#ifdef DEBUG_shaver_iid
132 fprintf(stderr, "parsing iid %s\n", str);
133#endif
134
135 count = sscanf(str, nsIDFmt2,
136 &n0, &n1, &n2,
137 &n3[0],&n3[1],&n3[2],&n3[3],
138 &n3[4],&n3[5],&n3[6],&n3[7]);
139
140 id->m0 = (PRInt32) n0;
141 id->m1 = (PRInt16) n1;
142 id->m2 = (PRInt16) n2;
143 for (i = 0; i < 8; i++) {
144 id->m3[i] = (PRInt8) n3[i];
145 }
146
147#ifdef DEBUG_shaver_iid
148 if (count == 11) {
149 fprintf(stderr, "IID parsed to ");
150 print_IID(id, stderr);
151 fputs("\n", stderr);
152 }
153#endif
154 return (gboolean)(count == 11);
155}
156
157gboolean
158verify_const_declaration(IDL_tree const_tree) {
159 struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(const_tree);
160 const char *name = IDL_IDENT(dcl->ident).str;
161 IDL_tree real_type;
162
163 /* const -> list -> interface */
164 if (!IDL_NODE_UP(IDL_NODE_UP(const_tree)) ||
165 IDL_NODE_TYPE(IDL_NODE_UP(IDL_NODE_UP(const_tree)))
166 != IDLN_INTERFACE) {
167 IDL_tree_error(const_tree,
168 "const declaration \'%s\' outside interface",
169 name);
170 return FALSE;
171 }
172
173 /* Could be a typedef; try to map it to the real type. */
174 real_type = find_underlying_type(dcl->const_type);
175 real_type = real_type ? real_type : dcl->const_type;
176 if (IDL_NODE_TYPE(real_type) == IDLN_TYPE_INTEGER &&
177 (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_SHORT ||
178 IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG))
179 {
180 if (!IDL_TYPE_INTEGER(real_type).f_signed &&
181 IDL_INTEGER(dcl->const_exp).value < 0)
182 {
183#ifndef G_HAVE_GINT64
184 /*
185 * For platforms without longlong support turned on we can get
186 * confused by the high bit of the long value and think that it
187 * represents a negative value in an unsigned declaration.
188 * In that case we don't know if it is the programmer who is
189 * confused or the compiler. So we issue a warning instead of
190 * an error.
191 */
192 if (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG)
193 {
194 XPIDL_WARNING((const_tree, IDL_WARNING1,
195 "unsigned const declaration \'%s\' "
196 "initialized with (possibly) negative constant",
197 name));
198 return TRUE;
199 }
200#endif
201 IDL_tree_error(const_tree,
202 "unsigned const declaration \'%s\' initialized with "
203 "negative constant",
204 name);
205 return FALSE;
206 }
207 } else {
208 IDL_tree_error(const_tree,
209 "const declaration \'%s\' must be of type short or long",
210 name);
211 return FALSE;
212 }
213
214 return TRUE;
215}
216
217
218
219/*
220 * This method consolidates error checking needed when coercing the XPIDL compiler
221 * via the -t flag to generate output for a specific version of XPConnect.
222 */
223static gboolean
224verify_type_fits_version(IDL_tree in_tree, IDL_tree error_tree)
225{
226 if (major_version == 1 && minor_version == 1)
227 {
228 /* XPIDL Version 1.1 checks */
229
230 /* utf8string, cstring, and astring types are not supported */
231 if (IDL_tree_property_get(in_tree, "utf8string") != NULL ||
232 IDL_tree_property_get(in_tree, "cstring") != NULL ||
233 IDL_tree_property_get(in_tree, "astring") != NULL)
234 {
235 IDL_tree_error(error_tree,
236 "Cannot use [utf8string], [cstring] and [astring] "
237 "types when generating version 1.1 typelibs\n");
238 return FALSE;
239 }
240 }
241 return TRUE;
242}
243
244gboolean
245verify_attribute_declaration(IDL_tree attr_tree)
246{
247 IDL_tree iface;
248 IDL_tree ident;
249 IDL_tree attr_type;
250 gboolean scriptable_interface;
251
252 /* We don't support attributes named IID, conflicts with static GetIID
253 * member. The conflict is due to certain compilers (VC++) choosing a
254 * different vtable order, placing GetIID at the beginning regardless
255 * of it's placement
256 */
257 if (strcmp(
258 IDL_IDENT(
259 IDL_LIST(IDL_ATTR_DCL(attr_tree).simple_declarations).data).str,
260 "IID") == 0) {
261 IDL_tree_error(attr_tree,
262 "Attributes named IID not supported, causes vtable "
263 "ordering problems");
264 return FALSE;
265 }
266 /*
267 * Verify that we've been called on an interface, and decide if the
268 * interface was marked [scriptable].
269 */
270 if (IDL_NODE_UP(attr_tree) && IDL_NODE_UP(IDL_NODE_UP(attr_tree)) &&
271 IDL_NODE_TYPE(iface = IDL_NODE_UP(IDL_NODE_UP(attr_tree)))
272 == IDLN_INTERFACE)
273 {
274 scriptable_interface =
275 (IDL_tree_property_get(IDL_INTERFACE(iface).ident, "scriptable")
276 != NULL);
277 } else {
278 IDL_tree_error(attr_tree,
279 "verify_attribute_declaration called on a non-interface?");
280 return FALSE;
281 }
282
283 /*
284 * Grab the first of the list of idents and hope that it'll
285 * say scriptable or no.
286 */
287 ident = IDL_LIST(IDL_ATTR_DCL(attr_tree).simple_declarations).data;
288
289 /*
290 * If the interface isn't scriptable, or the attribute is marked noscript,
291 * there's no need to check.
292 */
293 if (!scriptable_interface ||
294 IDL_tree_property_get(ident, "noscript") != NULL)
295 return TRUE;
296
297 /*
298 * If it should be scriptable, check that the type is non-native. nsid,
299 * domstring, utf8string, cstring, astring are exempted.
300 */
301 attr_type = IDL_ATTR_DCL(attr_tree).param_type_spec;
302
303 if (attr_type != NULL)
304 {
305 if (UP_IS_NATIVE(attr_type) &&
306 IDL_tree_property_get(attr_type, "nsid") == NULL &&
307 IDL_tree_property_get(attr_type, "domstring") == NULL &&
308 IDL_tree_property_get(attr_type, "utf8string") == NULL &&
309 IDL_tree_property_get(attr_type, "cstring") == NULL &&
310 IDL_tree_property_get(attr_type, "astring") == NULL)
311 {
312 IDL_tree_error(attr_tree,
313 "attributes in [scriptable] interfaces that are "
314 "non-scriptable because they refer to native "
315 "types must be marked [noscript]\n");
316 return FALSE;
317 }
318 /*
319 * We currently don't support properties of type nsid that aren't
320 * pointers or references, unless they are marked [notxpcom} and
321 * must be read-only
322 */
323
324 if ((IDL_tree_property_get(ident, "notxpcom") == NULL || !(IDL_ATTR_DCL(attr_tree).f_readonly)) &&
325 IDL_tree_property_get(attr_type,"nsid") != NULL &&
326 IDL_tree_property_get(attr_type,"ptr") == NULL &&
327 IDL_tree_property_get(attr_type,"ref") == NULL)
328 {
329 IDL_tree_error(attr_tree,
330 "Feature not currently supported: "
331 "attributes with a type of nsid must be marked "
332 "either [ptr] or [ref], or "
333 "else must be marked [notxpcom] "
334 "and must be read-only\n");
335 return FALSE;
336 }
337
338 /*
339 * Run additional error checks on the attribute type if targetting an
340 * older version of XPConnect.
341 */
342
343 if (!verify_type_fits_version(attr_type, attr_tree))
344 return FALSE;
345 }
346
347 if (IDL_LIST(IDL_ATTR_DCL(attr_tree).simple_declarations).next != NULL)
348 {
349 IDL_tree_error(attr_tree,
350 "multiple attributes in a single declaration is not supported\n");
351 return FALSE;
352 }
353 return TRUE;
354}
355
356/*
357 * Find the underlying type of an identifier typedef.
358 *
359 * All the needed tree-walking seems pretty shaky; isn't there something in
360 * libIDL to automate this?
361 */
362IDL_tree /* IDL_TYPE_DCL */
363find_underlying_type(IDL_tree typedef_ident)
364{
365 IDL_tree up;
366
367 if (typedef_ident == NULL || IDL_NODE_TYPE(typedef_ident) != IDLN_IDENT)
368 return NULL;
369
370 up = IDL_NODE_UP(typedef_ident);
371 if (up == NULL || IDL_NODE_TYPE(up) != IDLN_LIST)
372 return NULL;
373 up = IDL_NODE_UP(up);
374 if (up == NULL || IDL_NODE_TYPE(up) != IDLN_TYPE_DCL)
375 return NULL;
376
377 return IDL_TYPE_DCL(up).type_spec;
378}
379
380static IDL_tree /* IDL_PARAM_DCL */
381find_named_parameter(IDL_tree method_tree, const char *param_name)
382{
383 IDL_tree iter;
384 for (iter = IDL_OP_DCL(method_tree).parameter_dcls; iter;
385 iter = IDL_LIST(iter).next)
386 {
387 IDL_tree param = IDL_LIST(iter).data;
388 IDL_tree simple_decl = IDL_PARAM_DCL(param).simple_declarator;
389 const char *current_name = IDL_IDENT(simple_decl).str;
390 if (strcmp(current_name, param_name) == 0)
391 return param;
392 }
393 return NULL;
394}
395
396typedef enum ParamAttrType {
397 IID_IS,
398 LENGTH_IS,
399 SIZE_IS
400} ParamAttrType;
401
402/*
403 * Check that parameters referred to by attributes such as size_is exist and
404 * refer to parameters of the appropriate type.
405 */
406static gboolean
407check_param_attribute(IDL_tree method_tree, IDL_tree param,
408 ParamAttrType whattocheck)
409{
410 const char *referred_name = NULL;
411 IDL_tree simple_decl = IDL_PARAM_DCL(param).simple_declarator;
412 const char *attr_name;
413 const char *needed_type;
414
415 if (whattocheck == IID_IS) {
416 attr_name = "iid_is";
417 needed_type = "IID";
418 } else if (whattocheck == LENGTH_IS) {
419 attr_name = "length_is";
420 needed_type = "unsigned long (or PRUint32)";
421 } else if (whattocheck == SIZE_IS) {
422 attr_name = "size_is";
423 needed_type = "unsigned long (or PRUint32)";
424 } else {
425 XPT_ASSERT("asked to check an unknown attribute type!");
426 return TRUE;
427 }
428
429 referred_name = IDL_tree_property_get(simple_decl, attr_name);
430 if (referred_name != NULL) {
431 IDL_tree referred_param = find_named_parameter(method_tree,
432 referred_name);
433 IDL_tree referred_param_type;
434 if (referred_param == NULL) {
435 IDL_tree_error(method_tree,
436 "attribute [%s(%s)] refers to missing "
437 "parameter \"%s\"",
438 attr_name, referred_name, referred_name);
439 return FALSE;
440 }
441 if (referred_param == param) {
442 IDL_tree_error(method_tree,
443 "attribute [%s(%s)] refers to it's own parameter",
444 attr_name, referred_name);
445 return FALSE;
446 }
447
448 referred_param_type = IDL_PARAM_DCL(referred_param).param_type_spec;
449 if (whattocheck == IID_IS) {
450 /* require IID type */
451 if (IDL_tree_property_get(referred_param_type, "nsid") == NULL) {
452 IDL_tree_error(method_tree,
453 "target \"%s\" of [%s(%s)] attribute "
454 "must be of %s type",
455 referred_name, attr_name, referred_name,
456 needed_type);
457 return FALSE;
458 }
459 } else if (whattocheck == LENGTH_IS || whattocheck == SIZE_IS) {
460 /* require PRUint32 type */
461 IDL_tree real_type;
462
463 /* Could be a typedef; try to map it to the real type. */
464 real_type = find_underlying_type(referred_param_type);
465 real_type = real_type ? real_type : referred_param_type;
466
467 if (IDL_NODE_TYPE(real_type) != IDLN_TYPE_INTEGER ||
468 IDL_TYPE_INTEGER(real_type).f_signed != FALSE ||
469 IDL_TYPE_INTEGER(real_type).f_type != IDL_INTEGER_TYPE_LONG)
470 {
471 IDL_tree_error(method_tree,
472 "target \"%s\" of [%s(%s)] attribute "
473 "must be of %s type",
474 referred_name, attr_name, referred_name,
475 needed_type);
476
477 return FALSE;
478 }
479 }
480 }
481
482 return TRUE;
483}
484
485
486/*
487 * Common method verification code, called by *op_dcl in the various backends.
488 */
489gboolean
490verify_method_declaration(IDL_tree method_tree)
491{
492 struct _IDL_OP_DCL *op = &IDL_OP_DCL(method_tree);
493 IDL_tree iface;
494 IDL_tree iter;
495 gboolean notxpcom;
496 gboolean scriptable_interface;
497 gboolean scriptable_method;
498 gboolean seen_retval = FALSE;
499 const char *method_name = IDL_IDENT(IDL_OP_DCL(method_tree).ident).str;
500
501 /* We don't support attributes named IID, conflicts with static GetIID
502 * member. The conflict is due to certain compilers (VC++) choosing a
503 * different vtable order, placing GetIID at the beginning regardless
504 * of it's placement
505 */
506 if (strcmp(method_name, "GetIID") == 0) {
507 IDL_tree_error(method_tree,
508 "Methods named GetIID not supported, causes vtable "
509 "ordering problems");
510 return FALSE;
511 }
512 if (op->f_varargs) {
513 /* We don't currently support varargs. */
514 IDL_tree_error(method_tree, "varargs are not currently supported");
515 return FALSE;
516 }
517
518 /*
519 * Verify that we've been called on an interface, and decide if the
520 * interface was marked [scriptable].
521 */
522 if (IDL_NODE_UP(method_tree) && IDL_NODE_UP(IDL_NODE_UP(method_tree)) &&
523 IDL_NODE_TYPE(iface = IDL_NODE_UP(IDL_NODE_UP(method_tree)))
524 == IDLN_INTERFACE)
525 {
526 scriptable_interface =
527 (IDL_tree_property_get(IDL_INTERFACE(iface).ident, "scriptable")
528 != NULL);
529 } else {
530 IDL_tree_error(method_tree,
531 "verify_method_declaration called on a non-interface?");
532 return FALSE;
533 }
534
535 /*
536 * Require that any method in an interface marked as [scriptable], that
537 * *isn't* scriptable because it refers to some native type, be marked
538 * [noscript] or [notxpcom].
539 *
540 * Also check that iid_is points to nsid, and length_is, size_is points
541 * to unsigned long.
542 */
543 notxpcom = IDL_tree_property_get(op->ident, "notxpcom") != NULL;
544
545 scriptable_method = scriptable_interface &&
546 !notxpcom &&
547 IDL_tree_property_get(op->ident, "noscript") == NULL;
548
549 /* Loop through the parameters and check. */
550 for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
551 IDL_tree param = IDL_LIST(iter).data;
552 IDL_tree param_type =
553 IDL_PARAM_DCL(param).param_type_spec;
554 IDL_tree simple_decl =
555 IDL_PARAM_DCL(param).simple_declarator;
556 const char *param_name = IDL_IDENT(simple_decl).str;
557
558 /*
559 * Reject this method if it should be scriptable and some parameter is
560 * native that isn't marked with either nsid, domstring, utf8string,
561 * cstring, astring or iid_is.
562 */
563 if (scriptable_method &&
564 UP_IS_NATIVE(param_type) &&
565 IDL_tree_property_get(param_type, "nsid") == NULL &&
566 IDL_tree_property_get(simple_decl, "iid_is") == NULL &&
567 IDL_tree_property_get(param_type, "domstring") == NULL &&
568 IDL_tree_property_get(param_type, "utf8string") == NULL &&
569 IDL_tree_property_get(param_type, "cstring") == NULL &&
570 IDL_tree_property_get(param_type, "astring") == NULL)
571 {
572 IDL_tree_error(method_tree,
573 "methods in [scriptable] interfaces that are "
574 "non-scriptable because they refer to native "
575 "types (parameter \"%s\") must be marked "
576 "[noscript]", param_name);
577 return FALSE;
578 }
579
580 /*
581 * nsid's parameters that aren't ptr's or ref's are not currently
582 * supported in xpcom or non-xpcom (marked with [notxpcom]) methods
583 * as input parameters
584 */
585 if (!(notxpcom && IDL_PARAM_DCL(param).attr != IDL_PARAM_IN) &&
586 IDL_tree_property_get(param_type, "nsid") != NULL &&
587 IDL_tree_property_get(param_type, "ptr") == NULL &&
588 IDL_tree_property_get(param_type, "ref") == NULL)
589 {
590 IDL_tree_error(method_tree,
591 "Feature currently not supported: "
592 "parameter \"%s\" is of type nsid and "
593 "must be marked either [ptr] or [ref] "
594 "or method \"%s\" must be marked [notxpcom] "
595 "and must not be an input parameter",
596 param_name,
597 method_name);
598 return FALSE;
599 }
600 /*
601 * Sanity checks on return values.
602 */
603 if (IDL_tree_property_get(simple_decl, "retval") != NULL) {
604 if (IDL_LIST(iter).next != NULL) {
605 IDL_tree_error(method_tree,
606 "only the last parameter can be marked [retval]");
607 return FALSE;
608 }
609 if (op->op_type_spec) {
610 IDL_tree_error(method_tree,
611 "can't have [retval] with non-void return type");
612 return FALSE;
613 }
614 /* In case XPConnect relaxes the retval-is-last restriction. */
615 if (seen_retval) {
616 IDL_tree_error(method_tree,
617 "can't have more than one [retval] parameter");
618 return FALSE;
619 }
620 seen_retval = TRUE;
621 }
622
623 /*
624 * Confirm that [shared] attributes are only used with string, wstring,
625 * or native (but not nsid, domstring, utf8string, cstring or astring)
626 * and can't be used with [array].
627 */
628 if (IDL_tree_property_get(simple_decl, "shared") != NULL) {
629 IDL_tree real_type;
630 real_type = find_underlying_type(param_type);
631 real_type = real_type ? real_type : param_type;
632
633 if (IDL_tree_property_get(simple_decl, "array") != NULL) {
634 IDL_tree_error(method_tree,
635 "[shared] parameter \"%s\" cannot "
636 "be of array type", param_name);
637 return FALSE;
638 }
639
640 if (!(IDL_NODE_TYPE(real_type) == IDLN_TYPE_STRING ||
641 IDL_NODE_TYPE(real_type) == IDLN_TYPE_WIDE_STRING ||
642 (UP_IS_NATIVE(real_type) &&
643 !IDL_tree_property_get(real_type, "nsid") &&
644 !IDL_tree_property_get(real_type, "domstring") &&
645 !IDL_tree_property_get(real_type, "utf8string") &&
646 !IDL_tree_property_get(real_type, "cstring") &&
647 !IDL_tree_property_get(real_type, "astring"))))
648 {
649 IDL_tree_error(method_tree,
650 "[shared] parameter \"%s\" must be of type "
651 "string, wstring or native", param_name);
652 return FALSE;
653 }
654 }
655
656 /*
657 * inout is not allowed with "domstring", "UTF8String", "CString"
658 * and "AString" types
659 */
660 if (IDL_PARAM_DCL(param).attr == IDL_PARAM_INOUT &&
661 UP_IS_NATIVE(param_type) &&
662 (IDL_tree_property_get(param_type, "domstring") != NULL ||
663 IDL_tree_property_get(param_type, "utf8string") != NULL ||
664 IDL_tree_property_get(param_type, "cstring") != NULL ||
665 IDL_tree_property_get(param_type, "astring") != NULL )) {
666 IDL_tree_error(method_tree,
667 "[domstring], [utf8string], [cstring], [astring] "
668 "types cannot be used as inout parameters");
669 return FALSE;
670 }
671
672
673 /*
674 * arrays of domstring, utf8string, cstring, astring types not allowed
675 */
676 if (IDL_tree_property_get(simple_decl, "array") != NULL &&
677 UP_IS_NATIVE(param_type) &&
678 (IDL_tree_property_get(param_type, "domstring") != NULL ||
679 IDL_tree_property_get(param_type, "utf8string") != NULL ||
680 IDL_tree_property_get(param_type, "cstring") != NULL ||
681 IDL_tree_property_get(param_type, "astring") != NULL)) {
682 IDL_tree_error(method_tree,
683 "[domstring], [utf8string], [cstring], [astring] "
684 "types cannot be used in array parameters");
685 return FALSE;
686 }
687
688 if (!check_param_attribute(method_tree, param, IID_IS) ||
689 !check_param_attribute(method_tree, param, LENGTH_IS) ||
690 !check_param_attribute(method_tree, param, SIZE_IS))
691 return FALSE;
692
693 /*
694 * Run additional error checks on the parameter type if targetting an
695 * older version of XPConnect.
696 */
697
698 if (!verify_type_fits_version(param_type, method_tree))
699 return FALSE;
700
701 }
702
703 /* XXX q: can return type be nsid? */
704 /* Native return type? */
705 if (scriptable_method &&
706 op->op_type_spec != NULL && UP_IS_NATIVE(op->op_type_spec) &&
707 IDL_tree_property_get(op->op_type_spec, "nsid") == NULL &&
708 IDL_tree_property_get(op->op_type_spec, "domstring") == NULL &&
709 IDL_tree_property_get(op->op_type_spec, "utf8string") == NULL &&
710 IDL_tree_property_get(op->op_type_spec, "cstring") == NULL &&
711 IDL_tree_property_get(op->op_type_spec, "astring") == NULL)
712 {
713 IDL_tree_error(method_tree,
714 "methods in [scriptable] interfaces that are "
715 "non-scriptable because they return native "
716 "types must be marked [noscript]");
717 return FALSE;
718 }
719
720
721 /*
722 * nsid's parameters that aren't ptr's or ref's are not currently
723 * supported in xpcom
724 */
725 if (!notxpcom &&
726 op->op_type_spec != NULL &&
727 IDL_tree_property_get(op->op_type_spec, "nsid") != NULL &&
728 IDL_tree_property_get(op->op_type_spec, "ptr") == NULL &&
729 IDL_tree_property_get(op->op_type_spec, "ref") == NULL)
730 {
731 IDL_tree_error(method_tree,
732 "Feature currently not supported: "
733 "return value is of type nsid and "
734 "must be marked either [ptr] or [ref], "
735 "or else method \"%s\" must be marked [notxpcom] ",
736 method_name);
737 return FALSE;
738 }
739
740 /*
741 * Run additional error checks on the return type if targetting an
742 * older version of XPConnect.
743 */
744
745 if (op->op_type_spec != NULL &&
746 !verify_type_fits_version(op->op_type_spec, method_tree))
747 {
748 return FALSE;
749 }
750
751 return TRUE;
752}
753
754/*
755 * Verify that a native declaration has an associated C++ expression, i.e. that
756 * it's of the form native <idl-name>(<c++-name>)
757 */
758gboolean
759check_native(TreeState *state)
760{
761 char *native_name;
762 /* require that native declarations give a native type */
763 if (IDL_NATIVE(state->tree).user_type)
764 return TRUE;
765 native_name = IDL_IDENT(IDL_NATIVE(state->tree).ident).str;
766 IDL_tree_error(state->tree,
767 "``native %s;'' needs C++ type: ``native %s(<C++ type>);''",
768 native_name, native_name);
769 return FALSE;
770}
771
772/*
773 * Print a GSList as char strings to a file.
774 */
775void
776printlist(FILE *outfile, GSList *slist)
777{
778 guint i;
779 guint len = g_slist_length(slist);
780
781 for(i = 0; i < len; i++) {
782 fprintf(outfile,
783 "%s\n", (char *)g_slist_nth_data(slist, i));
784 }
785}
786
787void
788xpidl_list_foreach(IDL_tree p, IDL_tree_func foreach, gpointer user_data)
789{
790 IDL_tree_func_data tfd;
791
792 while (p) {
793 struct _IDL_LIST *list = &IDL_LIST(p);
794 tfd.tree = list->data;
795 if (!foreach(&tfd, user_data))
796 return;
797 p = list->next;
798 }
799}
800
801/*
802 * Verify that the interface declaration is correct
803 */
804gboolean
805verify_interface_declaration(IDL_tree interface_tree)
806{
807 IDL_tree iter;
808 /*
809 * If we have the scriptable attribute then make sure all of our direct
810 * parents have it as well.
811 * NOTE: We don't recurse since all interfaces will fall through here
812 */
813 if (IDL_tree_property_get(IDL_INTERFACE(interface_tree).ident,
814 "scriptable")) {
815 for (iter = IDL_INTERFACE(interface_tree).inheritance_spec; iter;
816 iter = IDL_LIST(iter).next) {
817 if (IDL_tree_property_get(
818 IDL_INTERFACE(iter).ident, "scriptable") == 0) {
819 XPIDL_WARNING((interface_tree,IDL_WARNING1,
820 "%s is scriptable but inherits from the non-scriptable interface %s\n",
821 IDL_IDENT(IDL_INTERFACE(interface_tree).ident).str,
822 IDL_IDENT(IDL_INTERFACE(iter).ident).str));
823 }
824 }
825 }
826 return TRUE;
827}
828
829/*
830 * Return a pointer to the start of the base filename of path
831 */
832char *
833xpidl_basename(const char * path)
834{
835 char * result = g_path_get_basename(path);
836 /*
837 *If this is windows then we'll handle either / or \ as a separator
838 * g_basename only handles \ for windows
839 */
840#if defined(XP_WIN32)
841# error adapt regarding g_basename() vs. g_path_get_basename()!
842 const char * slash = strrchr(path, '/');
843 /* If we found a slash and its after the current default OS separator */
844 if (slash != NULL && (slash > result))
845 result = slash + 1;
846#endif
847 return result;
848}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use