mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Common up some more code in the handling of default values for primitive types.
This commit is contained in:
parent
9fba4bcfba
commit
3a0b7fe621
1 changed files with 7 additions and 12 deletions
|
@ -1256,12 +1256,7 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
if defaultValue is not None:
|
||||
if isinstance(defaultValue, IDLNullValue):
|
||||
assert type.nullable()
|
||||
template = CGWrapper(CGIndenter(CGGeneric(template)),
|
||||
pre="if ${haveValue} {\n",
|
||||
post=("\n"
|
||||
"} else {\n"
|
||||
" ${declName} = None;\n"
|
||||
"}")).define()
|
||||
defaultStr = "None"
|
||||
else:
|
||||
tag = defaultValue.type.tag()
|
||||
if tag in numericTags:
|
||||
|
@ -1273,12 +1268,12 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
if type.nullable():
|
||||
defaultStr = "Some(%s)" % defaultStr
|
||||
|
||||
template = CGWrapper(CGIndenter(CGGeneric(template)),
|
||||
pre="if ${haveValue} {\n",
|
||||
post=("\n"
|
||||
"} else {\n"
|
||||
" ${declName} = %s;\n"
|
||||
"}" % defaultStr)).define()
|
||||
template = CGWrapper(CGIndenter(CGGeneric(template)),
|
||||
pre="if ${haveValue} {\n",
|
||||
post=("\n"
|
||||
"} else {\n"
|
||||
" ${declName} = %s;\n"
|
||||
"}" % defaultStr)).define()
|
||||
|
||||
initialVal = "false" if typeName == "bool" else ("0 as %s" % typeName)
|
||||
if type.nullable():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue