Fix #9508: Beautify our union enums constructors

This commit is contained in:
Alexander Lopatin 2016-02-07 02:55:21 +03:00
parent 7c249b1d53
commit 2be49404be
13 changed files with 69 additions and 71 deletions

View file

@ -3636,10 +3636,10 @@ class CGUnionStruct(CGThing):
templateVars = map(lambda t: getUnionTypeTemplateVars(t, self.descriptorProvider),
self.type.flatMemberTypes)
enumValues = [
" e%s(%s)," % (v["name"], v["typeName"]) for v in templateVars
" %s(%s)," % (v["name"], v["typeName"]) for v in templateVars
]
enumConversions = [
" %s::e%s(ref inner) => inner.to_jsval(cx, rval),"
" %s::%s(ref inner) => inner.to_jsval(cx, rval),"
% (self.type, v["name"]) for v in templateVars
]
return ("""\
@ -3681,7 +3681,7 @@ class CGUnionConversionStruct(CGThing):
return (
"match %s::TryConvertTo%s(cx, value) {\n"
" Err(_) => return Err(()),\n"
" Ok(Some(value)) => return Ok(%s::e%s(value)),\n"
" Ok(Some(value)) => return Ok(%s::%s(value)),\n"
" Ok(None) => (),\n"
"}\n") % (self.type, name, self.type, name)
@ -3757,7 +3757,7 @@ class CGUnionConversionStruct(CGThing):
match = (
"match %s::TryConvertTo%s(cx, value) {\n"
" Err(_) => return Err(()),\n"
" Ok(Some(value)) => return Ok(%s::e%s(value)),\n"
" Ok(Some(value)) => return Ok(%s::%s(value)),\n"
" Ok(None) => (),\n"
"}\n") % (self.type, name, self.type, name)
conversions.append(CGGeneric(match))