зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 5beaad8a185b (bug 662341) for linting failure on a CLOSED TREE
This commit is contained in:
Родитель
6a58f5fcea
Коммит
b9b20a60f7
|
@ -33,11 +33,8 @@ def attributeParamName(a):
|
||||||
return "a" + firstCap(a.name)
|
return "a" + firstCap(a.name)
|
||||||
|
|
||||||
|
|
||||||
def attributeParamNames(a, getter):
|
def attributeParamNames(a):
|
||||||
if getter and a.notxpcom:
|
l = [attributeParamName(a)]
|
||||||
l = []
|
|
||||||
else:
|
|
||||||
l = [attributeParamName(a)]
|
|
||||||
if a.implicit_jscontext:
|
if a.implicit_jscontext:
|
||||||
l.insert(0, "cx")
|
l.insert(0, "cx")
|
||||||
return ", ".join(l)
|
return ", ".join(l)
|
||||||
|
@ -48,36 +45,20 @@ def attributeNativeName(a, getter):
|
||||||
return "%s%s" % (getter and 'Get' or 'Set', binaryname)
|
return "%s%s" % (getter and 'Get' or 'Set', binaryname)
|
||||||
|
|
||||||
|
|
||||||
def attributeReturnType(a, getter, macro):
|
def attributeReturnType(a, macro):
|
||||||
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
|
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
|
||||||
# Pick the type to be returned from the getter/setter.
|
|
||||||
if a.notxpcom:
|
|
||||||
ret = a.realtype.nativeType('in').strip() if getter else "void"
|
|
||||||
else:
|
|
||||||
ret = "nsresult"
|
|
||||||
|
|
||||||
# Set calling convention and virtual-ness
|
|
||||||
if a.nostdcall:
|
if a.nostdcall:
|
||||||
if macro == "NS_IMETHOD":
|
ret = macro == "NS_IMETHOD" and "virtual nsresult" or "nsresult"
|
||||||
# This is the declaration.
|
|
||||||
ret = "virtual %s" % ret
|
|
||||||
else:
|
else:
|
||||||
if ret == "nsresult":
|
ret = macro
|
||||||
ret = macro
|
|
||||||
else:
|
|
||||||
ret = "%s_(%s)" % (macro, ret)
|
|
||||||
|
|
||||||
if a.must_use:
|
if a.must_use:
|
||||||
ret = "MOZ_MUST_USE " + ret
|
ret = "MOZ_MUST_USE " + ret
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def attributeParamlist(a, getter):
|
def attributeParamlist(a, getter):
|
||||||
if getter and a.notxpcom:
|
l = ["%s%s" % (a.realtype.nativeType(getter and 'out' or 'in'),
|
||||||
l = []
|
attributeParamName(a))]
|
||||||
else:
|
|
||||||
l = ["%s%s" % (a.realtype.nativeType(getter and 'out' or 'in'),
|
|
||||||
attributeParamName(a))]
|
|
||||||
if a.implicit_jscontext:
|
if a.implicit_jscontext:
|
||||||
l.insert(0, "JSContext* cx")
|
l.insert(0, "JSContext* cx")
|
||||||
|
|
||||||
|
@ -85,7 +66,7 @@ def attributeParamlist(a, getter):
|
||||||
|
|
||||||
|
|
||||||
def attributeAsNative(a, getter, declType='NS_IMETHOD'):
|
def attributeAsNative(a, getter, declType='NS_IMETHOD'):
|
||||||
params = {'returntype': attributeReturnType(a, getter, declType),
|
params = {'returntype': attributeReturnType(a, declType),
|
||||||
'binaryname': attributeNativeName(a, getter),
|
'binaryname': attributeNativeName(a, getter),
|
||||||
'paramlist': attributeParamlist(a, getter)}
|
'paramlist': attributeParamlist(a, getter)}
|
||||||
return "%(returntype)s %(binaryname)s(%(paramlist)s)" % params
|
return "%(returntype)s %(binaryname)s(%(paramlist)s)" % params
|
||||||
|
@ -97,22 +78,15 @@ def methodNativeName(m):
|
||||||
|
|
||||||
def methodReturnType(m, macro):
|
def methodReturnType(m, macro):
|
||||||
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
|
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
|
||||||
if m.notxpcom:
|
if m.nostdcall and m.notxpcom:
|
||||||
ret = m.realtype.nativeType('in').strip()
|
ret = "%s%s" % (macro == "NS_IMETHOD" and "virtual " or "",
|
||||||
|
m.realtype.nativeType('in').strip())
|
||||||
|
elif m.nostdcall:
|
||||||
|
ret = "%snsresult" % (macro == "NS_IMETHOD" and "virtual " or "")
|
||||||
|
elif m.notxpcom:
|
||||||
|
ret = "%s_(%s)" % (macro, m.realtype.nativeType('in').strip())
|
||||||
else:
|
else:
|
||||||
ret = "nsresult"
|
ret = macro
|
||||||
|
|
||||||
# Set calling convention and virtual-ness
|
|
||||||
if m.nostdcall:
|
|
||||||
if macro == "NS_IMETHOD":
|
|
||||||
# This is the declaration
|
|
||||||
ret = "virtual %s" % ret
|
|
||||||
else:
|
|
||||||
if ret == "nsresult":
|
|
||||||
ret = macro
|
|
||||||
else:
|
|
||||||
ret = "%s_(%s)" % (macro, ret)
|
|
||||||
|
|
||||||
if m.must_use:
|
if m.must_use:
|
||||||
ret = "MOZ_MUST_USE " + ret
|
ret = "MOZ_MUST_USE " + ret
|
||||||
return ret
|
return ret
|
||||||
|
@ -541,14 +515,13 @@ def write_interface(iface, fd):
|
||||||
if forward_infallible and member.infallible:
|
if forward_infallible and member.infallible:
|
||||||
fd.write("\\\n using %s::%s; " %
|
fd.write("\\\n using %s::%s; " %
|
||||||
(iface.name, attributeNativeName(member, True)))
|
(iface.name, attributeNativeName(member, True)))
|
||||||
attr_tmpl = tmpl_notxpcom if member.notxpcom else tmpl
|
fd.write(tmpl % {'asNative': attributeAsNative(member, True),
|
||||||
fd.write(attr_tmpl % {'asNative': attributeAsNative(member, True),
|
'nativeName': attributeNativeName(member, True),
|
||||||
'nativeName': attributeNativeName(member, True),
|
'paramList': attributeParamNames(member)})
|
||||||
'paramList': attributeParamNames(member, True)})
|
|
||||||
if not member.readonly:
|
if not member.readonly:
|
||||||
fd.write(attr_tmpl % {'asNative': attributeAsNative(member, False),
|
fd.write(tmpl % {'asNative': attributeAsNative(member, False),
|
||||||
'nativeName': attributeNativeName(member, False),
|
'nativeName': attributeNativeName(member, False),
|
||||||
'paramList': attributeParamNames(member, False)})
|
'paramList': attributeParamNames(member)})
|
||||||
elif isinstance(member, xpidl.Method):
|
elif isinstance(member, xpidl.Method):
|
||||||
if member.notxpcom:
|
if member.notxpcom:
|
||||||
fd.write(tmpl_notxpcom % {'asNative': methodAsNative(member),
|
fd.write(tmpl_notxpcom % {'asNative': methodAsNative(member),
|
||||||
|
|
|
@ -202,21 +202,16 @@ def build_interface(iface):
|
||||||
hasretval=hasretval, symbol=m.symbol))
|
hasretval=hasretval, symbol=m.symbol))
|
||||||
|
|
||||||
def build_attr(a):
|
def build_attr(a):
|
||||||
assert a.realtype.name != 'void'
|
|
||||||
# Write the getter
|
# Write the getter
|
||||||
getter_params = []
|
param = mk_param(get_type(a.realtype, 'out'), out=1)
|
||||||
if not a.notxpcom:
|
methods.append(mk_method(a.name, [param], getter=1, hidden=a.noscript,
|
||||||
getter_params.append(mk_param(get_type(a.realtype, 'out'), out=1))
|
|
||||||
methods.append(mk_method(a.name, getter_params, getter=1,
|
|
||||||
notxpcom=a.notxpcom, hidden=a.noscript,
|
|
||||||
context=a.implicit_jscontext, hasretval=1,
|
context=a.implicit_jscontext, hasretval=1,
|
||||||
symbol=a.symbol))
|
symbol=a.symbol))
|
||||||
|
|
||||||
# And maybe the setter
|
# And maybe the setter
|
||||||
if not a.readonly:
|
if not a.readonly:
|
||||||
param = mk_param(get_type(a.realtype, 'in'), in_=1)
|
param = mk_param(get_type(a.realtype, 'in'), in_=1)
|
||||||
methods.append(mk_method(a.name, [param], setter=1,
|
methods.append(mk_method(a.name, [param], setter=1, hidden=a.noscript,
|
||||||
notxpcom=a.notxpcom, hidden=a.noscript,
|
|
||||||
context=a.implicit_jscontext,
|
context=a.implicit_jscontext,
|
||||||
symbol=a.symbol))
|
symbol=a.symbol))
|
||||||
|
|
||||||
|
|
|
@ -13,19 +13,19 @@
|
||||||
# documentation for the reasons why we don't generate certain types of bindings,
|
# documentation for the reasons why we don't generate certain types of bindings,
|
||||||
# so that we don't accidentally start generating them in the future.
|
# so that we don't accidentally start generating them in the future.
|
||||||
|
|
||||||
# notxpcom methods and attributes return their results directly by value. The x86
|
# notxpcom methods return their results directly by value. The x86 windows
|
||||||
# windows stdcall ABI returns aggregates by value differently for methods than
|
# stdcall ABI returns aggregates by value differently for methods than
|
||||||
# functions, and rust only exposes the function ABI, so that's the one we're
|
# functions, and rust only exposes the function ABI, so that's the one we're
|
||||||
# using. The correct ABI can be emulated for notxpcom methods returning aggregates
|
# using. The correct ABI can be emulated for notxpcom methods returning
|
||||||
# by passing an &mut ReturnType parameter as the second parameter. This strategy
|
# aggregates by passing an &mut ReturnType parameter as the second parameter.
|
||||||
# is used by the winapi-rs crate.
|
# This strategy is used by the winapi-rs crate.
|
||||||
# https://github.com/retep998/winapi-rs/blob/7338a5216a6a7abeefcc6bb1bc34381c81d3e247/src/macros.rs#L220-L231
|
# https://github.com/retep998/winapi-rs/blob/7338a5216a6a7abeefcc6bb1bc34381c81d3e247/src/macros.rs#L220-L231
|
||||||
#
|
#
|
||||||
# Right now we can generate code for notxpcom methods and attributes, as we don't
|
# Right now we can generate code for notxpcom methods, as we don't support
|
||||||
# support passing aggregates by value over these APIs ever (the types which are
|
# passing aggregates by value over these APIs ever (the types which are allowed
|
||||||
# allowed in xpidl.py shouldn't include any aggregates), so the code is
|
# in xpidl.py shouldn't include any aggregates), so the code is correct. In the
|
||||||
# correct. In the future if we want to start supporting returning aggregates by
|
# future if we want to start supporting returning aggregates by value, we will
|
||||||
# value, we will need to use a workaround such as the one used by winapi.rs.
|
# need to use a workaround such as the one used by winapi.rs.
|
||||||
|
|
||||||
# nostdcall methods on x86 windows will use the thiscall ABI, which is not
|
# nostdcall methods on x86 windows will use the thiscall ABI, which is not
|
||||||
# stable in rust right now, so we cannot generate bindings to them.
|
# stable in rust right now, so we cannot generate bindings to them.
|
||||||
|
@ -120,23 +120,13 @@ def attributeNativeName(a, getter):
|
||||||
return "%s%s" % ('Get' if getter else 'Set', binaryname)
|
return "%s%s" % ('Get' if getter else 'Set', binaryname)
|
||||||
|
|
||||||
|
|
||||||
def attributeReturnType(a, getter):
|
|
||||||
if a.notxpcom:
|
|
||||||
if getter:
|
|
||||||
return a.realtype.rustType('in').strip()
|
|
||||||
return "::libc::c_void"
|
|
||||||
return "::nserror::nsresult"
|
|
||||||
|
|
||||||
def attributeParamName(a):
|
def attributeParamName(a):
|
||||||
return "a" + firstCap(a.name)
|
return "a" + firstCap(a.name)
|
||||||
|
|
||||||
|
|
||||||
def attributeRawParamList(iface, a, getter):
|
def attributeRawParamList(iface, a, getter):
|
||||||
if getter and a.notxpcom:
|
l = [(attributeParamName(a),
|
||||||
l = []
|
a.realtype.rustType('out' if getter else 'in'))]
|
||||||
else:
|
|
||||||
l = [(attributeParamName(a),
|
|
||||||
a.realtype.rustType('out' if getter else 'in'))]
|
|
||||||
if a.implicit_jscontext:
|
if a.implicit_jscontext:
|
||||||
raise xpidl.RustNoncompat("jscontext is unsupported")
|
raise xpidl.RustNoncompat("jscontext is unsupported")
|
||||||
if a.nostdcall:
|
if a.nostdcall:
|
||||||
|
@ -152,10 +142,9 @@ def attributeParamList(iface, a, getter):
|
||||||
|
|
||||||
def attrAsVTableEntry(iface, m, getter):
|
def attrAsVTableEntry(iface, m, getter):
|
||||||
try:
|
try:
|
||||||
return "pub %s: unsafe extern \"system\" fn (%s) -> %s" % \
|
return "pub %s: unsafe extern \"system\" fn (%s) -> ::nserror::nsresult" % \
|
||||||
(attributeNativeName(m, getter),
|
(attributeNativeName(m, getter),
|
||||||
attributeParamList(iface, m, getter),
|
attributeParamList(iface, m, getter))
|
||||||
attributeReturnType(m, getter))
|
|
||||||
except xpidl.RustNoncompat as reason:
|
except xpidl.RustNoncompat as reason:
|
||||||
return """\
|
return """\
|
||||||
/// Unable to generate binding because `%s`
|
/// Unable to generate binding because `%s`
|
||||||
|
@ -264,13 +253,12 @@ def attrAsWrapper(iface, m, getter):
|
||||||
'realtype': m.realtype.rustType('in'),
|
'realtype': m.realtype.rustType('in'),
|
||||||
}
|
}
|
||||||
|
|
||||||
param_list = attributeRawParamList(iface, m, getter)
|
rust_type = m.realtype.rustType('out' if getter else 'in')
|
||||||
params = ["%s: %s" % x for x in param_list]
|
|
||||||
return method_impl_tmpl % {
|
return method_impl_tmpl % {
|
||||||
'name': attributeNativeName(m, getter),
|
'name': attributeNativeName(m, getter),
|
||||||
'params': ', '.join(params),
|
'params': name + ': ' + rust_type,
|
||||||
'ret_ty': attributeReturnType(m, getter),
|
'ret_ty': '::nserror::nsresult',
|
||||||
'args': '' if getter and m.notxpcom else name,
|
'args': name,
|
||||||
}
|
}
|
||||||
|
|
||||||
except xpidl.RustNoncompat:
|
except xpidl.RustNoncompat:
|
||||||
|
|
|
@ -682,10 +682,9 @@ class Interface(object):
|
||||||
if not isinstance(m, CDATA):
|
if not isinstance(m, CDATA):
|
||||||
self.namemap.set(m)
|
self.namemap.set(m)
|
||||||
|
|
||||||
if ((m.kind == 'method' or m.kind == 'attribute') and
|
if m.kind == 'method' and m.notxpcom and name != 'nsISupports':
|
||||||
m.notxpcom and name != 'nsISupports'):
|
# An interface cannot be implemented by JS if it has a
|
||||||
# An interface cannot be implemented by JS if it has a notxpcom
|
# notxpcom method. Such a type is an "implicit builtinclass".
|
||||||
# method or attribute. Such a type is an "implicit builtinclass".
|
|
||||||
#
|
#
|
||||||
# XXX(nika): Why does nostdcall not imply builtinclass?
|
# XXX(nika): Why does nostdcall not imply builtinclass?
|
||||||
# It could screw up the shims as well...
|
# It could screw up the shims as well...
|
||||||
|
@ -993,7 +992,6 @@ class CEnum(object):
|
||||||
class Attribute(object):
|
class Attribute(object):
|
||||||
kind = 'attribute'
|
kind = 'attribute'
|
||||||
noscript = False
|
noscript = False
|
||||||
notxpcom = False
|
|
||||||
readonly = False
|
readonly = False
|
||||||
symbol = False
|
symbol = False
|
||||||
implicit_jscontext = False
|
implicit_jscontext = False
|
||||||
|
@ -1024,8 +1022,6 @@ class Attribute(object):
|
||||||
|
|
||||||
if name == 'noscript':
|
if name == 'noscript':
|
||||||
self.noscript = True
|
self.noscript = True
|
||||||
elif name == 'notxpcom':
|
|
||||||
self.notxpcom = True
|
|
||||||
elif name == 'symbol':
|
elif name == 'symbol':
|
||||||
self.symbol = True
|
self.symbol = True
|
||||||
elif name == 'implicit_jscontext':
|
elif name == 'implicit_jscontext':
|
||||||
|
@ -1063,7 +1059,7 @@ class Attribute(object):
|
||||||
def isScriptable(self):
|
def isScriptable(self):
|
||||||
if not self.iface.attributes.scriptable:
|
if not self.iface.attributes.scriptable:
|
||||||
return False
|
return False
|
||||||
return not (self.noscript or self.notxpcom)
|
return not self.noscript
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "\t%sattribute %s %s\n" % (self.readonly and 'readonly ' or '',
|
return "\t%sattribute %s %s\n" % (self.readonly and 'readonly ' or '',
|
||||||
|
|
Загрузка…
Ссылка в новой задаче