Skip to content

Commit

Permalink
auto merge of #1895 : Ms2ger/servo/outparams, r=jdm
Browse files Browse the repository at this point in the history
  • Loading branch information
bors-servo committed Mar 13, 2014
2 parents a0f527b + c7e09c0 commit 3933d17
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/components/script/dom/bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,36 +1225,36 @@ def memberIsCreator(member):
def getRetvalDeclarationForType(returnType, descriptorProvider):
if returnType is None or returnType.isVoid():
# Nothing to declare
return None, False
return None
if returnType.isPrimitive() and returnType.tag() in builtinNames:
result = CGGeneric(builtinNames[returnType.tag()])
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result, False
return result
if returnType.isString():
result = CGGeneric("DOMString")
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result, False
return result
if returnType.isEnum():
if returnType.nullable():
raise TypeError("We don't support nullable enum return values")
return CGGeneric(returnType.inner.identifier.name), False
return CGGeneric(returnType.inner.identifier.name)
if returnType.isGeckoInterface():
descriptor = descriptorProvider.getDescriptor(
returnType.unroll().inner.identifier.name)
result = CGGeneric(descriptor.nativeType)
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result, False
return result
if returnType.isCallback():
# XXXbz we're going to assume that callback types are always
# nullable for now.
return CGGeneric("*JSObject"), False
return CGGeneric("*JSObject")
if returnType.isAny():
return CGGeneric("JSVal"), False
return CGGeneric("JSVal")
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
return CGGeneric("*JSObject"), False
return CGGeneric("*JSObject")
if returnType.isSequence():
raise TypeError("We don't support sequence return values")

Expand Down Expand Up @@ -2420,8 +2420,7 @@ def __init__(self, errorReport, arguments, argsPre, returnType,

isFallible = errorReport is not None

(result, resultOutParam) = getRetvalDeclarationForType(returnType,
descriptorProvider)
result = getRetvalDeclarationForType(returnType, descriptorProvider)

args = CGList([CGGeneric(arg) for arg in argsPre], ", ")
for (a, name) in arguments:
Expand All @@ -2437,10 +2436,6 @@ def __init__(self, errorReport, arguments, argsPre, returnType,
name = "&" + name
args.append(CGGeneric(name))

# Return values that go in outparams go here
if resultOutParam:
args.append(CGGeneric("result"))

needsCx = (typeNeedsCx(returnType, True) or
any(typeNeedsCx(a.type) for (a, _) in arguments))

Expand All @@ -2467,7 +2462,7 @@ def __init__(self, errorReport, arguments, argsPre, returnType,

if isFallible:
call = CGWrapper(call, pre="result_fallible = ")
elif result is not None and not resultOutParam:
elif result is not None:
call = CGWrapper(call, pre="result = ")

call = CGWrapper(call)
Expand All @@ -2477,7 +2472,7 @@ def __init__(self, errorReport, arguments, argsPre, returnType,
self.cgRoot.append(CGGeneric("if (result_fallible.is_err()) {"))
self.cgRoot.append(CGIndenter(errorReport))
self.cgRoot.append(CGGeneric("}"))
if result is not None and not resultOutParam:
if result is not None:
self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();"))

def define(self):
Expand Down Expand Up @@ -2790,16 +2785,14 @@ def definition_body(self):
nativeName = MakeNativeName(name)
extraPre = ''
argsPre = []
(_, resultOutParam) = getRetvalDeclarationForType(self.attr.type,
self.descriptor)
infallible = ('infallible' in
self.descriptor.getExtendedAttributes(self.attr,
getter=True))
if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = ' let mut abstract_this = %s::from_box(this);\n' % abstractName
argsPre = ['&mut abstract_this']
if resultOutParam or self.attr.type.nullable() or not infallible:
if self.attr.type.nullable() or not infallible:
nativeName = "Get" + nativeName
return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName,
self.descriptor, self.attr)),
Expand Down

0 comments on commit 3933d17

Please sign in to comment.