~ubuntu-branches/ubuntu/precise/enigmail/precise-security

« back to all changes in this revision

Viewing changes to xpcom/idl-parser/header.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-11-12 16:36:01 UTC
  • mfrom: (0.12.15)
  • Revision ID: package-import@ubuntu.com-20121112163601-t8e8skdfi3ni9iqp
Tags: 2:1.4.6-0ubuntu0.12.04.1
* New upstream release v1.4.6
  - see LP: #1080212 for USN information
* Drop unneeded patches
  - remove debian/patches/correct-version-number.diff
  - remove debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Support building in an objdir
  - update debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# header.py - Generate C++ header files from IDL.
3
3
#
4
 
# ***** BEGIN LICENSE BLOCK *****
5
 
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
 
#
7
 
# The contents of this file are subject to the Mozilla Public License Version
8
 
# 1.1 (the "License"); you may not use this file except in compliance with
9
 
# the License. You may obtain a copy of the License at
10
 
# http://www.mozilla.org/MPL/
11
 
#
12
 
# Software distributed under the License is distributed on an "AS IS" basis,
13
 
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
 
# for the specific language governing rights and limitations under the
15
 
# License.
16
 
#
17
 
# The Original Code is mozilla.org code.
18
 
#
19
 
# The Initial Developer of the Original Code is
20
 
#   Mozilla Foundation.
21
 
# Portions created by the Initial Developer are Copyright (C) 2008
22
 
# the Initial Developer. All Rights Reserved.
23
 
#
24
 
# Contributor(s):
25
 
#   Benjamin Smedberg <benjamin@smedbergs.us>
26
 
#
27
 
# Alternatively, the contents of this file may be used under the terms of
28
 
# either of the GNU General Public License Version 2 or later (the "GPL"),
29
 
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
 
# in which case the provisions of the GPL or the LGPL are applicable instead
31
 
# of those above. If you wish to allow use of your version of this file only
32
 
# under the terms of either the GPL or the LGPL, and not to allow others to
33
 
# use your version of this file under the terms of the MPL, indicate your
34
 
# decision by deleting the provisions above and replace them with the notice
35
 
# and other provisions required by the GPL or the LGPL. If you do not delete
36
 
# the provisions above, a recipient may use your version of this file under
37
 
# the terms of any one of the MPL, the GPL or the LGPL.
38
 
#
39
 
# ***** END LICENSE BLOCK *****
 
4
# This Source Code Form is subject to the terms of the Mozilla Public
 
5
# License, v. 2.0. If a copy of the MPL was not distributed with this
 
6
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
40
7
 
41
8
"""Print a C++ header file for the IDL files specified on the command line"""
42
9
 
84
51
    return ", ".join(l)
85
52
 
86
53
def attributeAsNative(a, getter):
87
 
        scriptable = a.isScriptable() and "NS_SCRIPTABLE " or ""
88
54
        deprecated = a.deprecated and "NS_DEPRECATED " or ""
89
 
        params = {'scriptable': scriptable,
90
 
                  'deprecated': deprecated,
 
55
        params = {'deprecated': deprecated,
91
56
                  'returntype': attributeReturnType(a, 'NS_IMETHOD'),
92
57
                  'binaryname': attributeNativeName(a, getter),
93
58
                  'paramlist': attributeParamlist(a, getter)}
94
 
        return "%(deprecated)s%(scriptable)s%(returntype)s %(binaryname)s(%(paramlist)s)" % params
 
59
        return "%(deprecated)s%(returntype)s %(binaryname)s(%(paramlist)s)" % params
95
60
 
96
61
def methodNativeName(m):
97
62
    return m.binaryname is not None and m.binaryname or firstCap(m.name)
109
74
        return macro
110
75
 
111
76
def methodAsNative(m):
112
 
    scriptable = m.isScriptable() and "NS_SCRIPTABLE " or ""
113
 
 
114
 
    return "%s%s %s(%s)" % (scriptable,
115
 
                            methodReturnType(m, 'NS_IMETHOD'),
116
 
                            methodNativeName(m),
117
 
                            paramlistAsNative(m))
 
77
    return "%s %s(%s)" % (methodReturnType(m, 'NS_IMETHOD'),
 
78
                          methodNativeName(m),
 
79
                          paramlistAsNative(m))
118
80
 
119
81
def paramlistAsNative(m, empty='void'):
120
82
    l = [paramAsNative(p) for p in m.params]
123
85
        l.append("JSContext* cx")
124
86
 
125
87
    if m.optional_argc:
126
 
        l.append('PRUint8 _argc')
 
88
        l.append('uint8_t _argc')
127
89
 
128
90
    if not m.notxpcom and m.realtype.name != 'void':
129
91
        l.append(paramAsNative(xpidl.Param(paramtype='out',
139
101
    return ", ".join(l)
140
102
 
141
103
def paramAsNative(p):
142
 
    if p.paramtype == 'in':
143
 
        typeannotate = ''
144
 
    else:
145
 
        typeannotate = ' NS_%sPARAM' % p.paramtype.upper()
146
 
 
147
 
    return "%s%s%s" % (p.nativeType(),
148
 
                       p.name,
149
 
                       typeannotate)
 
104
    return "%s%s" % (p.nativeType(),
 
105
                     p.name)
150
106
 
151
107
def paramlistNames(m):
152
108
    names = [p.name for p in m.params]
182
138
#include "jspubtd.h"
183
139
"""
184
140
 
 
141
infallible_includes = """
 
142
#include "mozilla/Assertions.h"
 
143
#include "mozilla/Util.h"
 
144
"""
 
145
 
185
146
header_end = """/* For IDL files that don't want to include root IDL files. */
186
147
#ifndef NS_NO_VTABLE
187
148
#define NS_NO_VTABLE
214
175
    if idl.needsJSTypes():
215
176
        fd.write(jspubtd_include)
216
177
 
 
178
    # Include some extra files if any attributes are infallible.
 
179
    for iface in [p for p in idl.productions if p.kind == 'interface']:
 
180
        for attr in [m for m in iface.members if isinstance(m, xpidl.Attribute)]:
 
181
            if attr.infallible:
 
182
                fd.write(infallible_includes)
 
183
                break
 
184
 
217
185
    fd.write('\n')
218
186
    fd.write(header_end)
219
187
 
324
292
 
325
293
"""
326
294
 
 
295
attr_infallible_tmpl = """\
 
296
  inline %(realtype)s%(nativename)s(%(args)s)
 
297
  {
 
298
    %(realtype)sresult;
 
299
    mozilla::DebugOnly<nsresult> rv = %(nativename)s(%(argnames)s&result);
 
300
    MOZ_ASSERT(NS_SUCCEEDED(rv));
 
301
    return result;
 
302
  }
 
303
"""
 
304
 
327
305
def write_interface(iface, fd):
328
306
    if iface.namemap is None:
329
307
        raise Exception("Interface was not resolved.")
354
332
        fd.write("  /* %s */\n" % a.toIDL());
355
333
 
356
334
        fd.write("  %s = 0;\n" % attributeAsNative(a, True))
 
335
        if a.infallible:
 
336
            fd.write(attr_infallible_tmpl %
 
337
                     {'realtype': a.realtype.nativeType('in'),
 
338
                      'nativename': attributeNativeName(a, getter=True),
 
339
                      'args': '' if not a.implicit_jscontext else 'JSContext* cx',
 
340
                      'argnames': '' if not a.implicit_jscontext else 'cx, '})
 
341
 
357
342
        if not a.readonly:
358
343
            fd.write("  %s = 0;\n" % attributeAsNative(a, False))
359
344
        fd.write("\n")
390
375
    if not foundcdata:
391
376
        fd.write("NS_NO_VTABLE ")
392
377
 
393
 
    if iface.attributes.scriptable:
394
 
        fd.write("NS_SCRIPTABLE ")
395
378
    if iface.attributes.deprecated:
396
379
        fd.write("MOZ_DEPRECATED ")
397
380
    fd.write(iface.name)
505
488
            print >>sys.stderr, "--regen useless without --cachedir"
506
489
        # Delete the lex/yacc files.  Ply is too stupid to regenerate them
507
490
        # properly
508
 
        deadfiles = os.path.join(options.cachedir, "*.py*")
509
 
        for filename in glob.glob(deadfiles):
510
 
            print filename
511
 
            os.remove(filename)
 
491
        for fileglobs in [os.path.join(options.cachedir, f) for f in ["xpidllex.py*", "xpidlyacc.py*"]]:
 
492
            for filename in glob.glob(fileglobs):
 
493
                os.remove(filename)
512
494
 
513
495
    # Instantiate the parser.
514
496
    p = xpidl.IDLParser(outputdir=options.cachedir)