mirror of
https://github.com/servo/servo.git
synced 2025-06-13 19:04:30 +00:00
Move responsibility for assigning to ${declName} out of getJSToNativeConversionTemplate.
This commit does not make any change to the generated code.
This commit is contained in:
parent
c5bf011d1e
commit
05d0ba783f
1 changed files with 20 additions and 18 deletions
|
@ -598,7 +598,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
templateBody = handleDefaultNull(templateBody.define(),
|
templateBody = handleDefaultNull(templateBody.define(),
|
||||||
"None")
|
"None")
|
||||||
|
|
||||||
return ("${declName} = " + templateBody + ";", declType, None, isOptional, "None" if isOptional else None)
|
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
if type.isGeckoInterface():
|
if type.isGeckoInterface():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -613,7 +613,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
|
|
||||||
template = wrapObjectTemplate(conversion, isDefinitelyObject, type,
|
template = wrapObjectTemplate(conversion, isDefinitelyObject, type,
|
||||||
failureCode)
|
failureCode)
|
||||||
return ("${declName} = " + template + ";", declType, None, isOptional, None)
|
return (template, declType, None, isOptional, None)
|
||||||
|
|
||||||
templateBody = ""
|
templateBody = ""
|
||||||
if descriptor.interface.isConsequential():
|
if descriptor.interface.isConsequential():
|
||||||
|
@ -640,7 +640,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
if type.nullable() or isOptional:
|
if type.nullable() or isOptional:
|
||||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||||
|
|
||||||
return ("${declName} = " + templateBody + ";", declType, None, isOptional, "None" if isOptional else None)
|
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
if type.isSpiderMonkeyInterface():
|
if type.isSpiderMonkeyInterface():
|
||||||
raise TypeError("Can't handle SpiderMonkey interface arguments yet")
|
raise TypeError("Can't handle SpiderMonkey interface arguments yet")
|
||||||
|
@ -700,7 +700,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
initialValue = "None"
|
initialValue = "None"
|
||||||
|
|
||||||
return (
|
return (
|
||||||
"${declName} = %s;" % getConversionCode(isOptional),
|
getConversionCode(isOptional),
|
||||||
CGGeneric(declType), None, #CGGeneric("FakeDependentString"),
|
CGGeneric(declType), None, #CGGeneric("FakeDependentString"),
|
||||||
False,
|
False,
|
||||||
initialValue)
|
initialValue)
|
||||||
|
@ -736,7 +736,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
(enum,
|
(enum,
|
||||||
getEnumValueName(defaultValue.value))))
|
getEnumValueName(defaultValue.value))))
|
||||||
|
|
||||||
return ("${declName} = " + template + ";", CGGeneric(enum), None, isOptional, None)
|
return (template, CGGeneric(enum), None, isOptional, None)
|
||||||
|
|
||||||
if type.isCallback():
|
if type.isCallback():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -768,7 +768,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
value = CGWrapper(value, pre="Some(", post=")")
|
value = CGWrapper(value, pre="Some(", post=")")
|
||||||
|
|
||||||
templateBody = handleDefaultNull(value.define(), "NullValue()")
|
templateBody = handleDefaultNull(value.define(), "NullValue()")
|
||||||
return ("${declName} = " + templateBody + ";", declType, None, isOptional, "None" if isOptional else None)
|
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
if type.isObject():
|
if type.isObject():
|
||||||
raise TypeError("Can't handle object arguments yet")
|
raise TypeError("Can't handle object arguments yet")
|
||||||
|
@ -794,10 +794,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
else:
|
else:
|
||||||
val = "${val}"
|
val = "${val}"
|
||||||
|
|
||||||
template = ("${declName} = match %s::new(cx, %s) {\n"
|
template = ("match %s::new(cx, %s) {\n"
|
||||||
" Ok(dictionary) => dictionary,\n"
|
" Ok(dictionary) => dictionary,\n"
|
||||||
" Err(_) => return 0,\n"
|
" Err(_) => return 0,\n"
|
||||||
"};" % (typeName, val))
|
"}" % (typeName, val))
|
||||||
|
|
||||||
return (template, declType, None, False, None)
|
return (template, declType, None, False, None)
|
||||||
|
|
||||||
|
@ -850,7 +850,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
CGGeneric(template),
|
CGGeneric(template),
|
||||||
CGGeneric(defaultStr)).define()
|
CGGeneric(defaultStr)).define()
|
||||||
|
|
||||||
return ("${declName} = " + template + ";", declType, None, isOptional, "None" if isOptional else None)
|
return (template, declType, None, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
||||||
argcAndIndex=None):
|
argcAndIndex=None):
|
||||||
|
@ -892,20 +892,22 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
||||||
tmpresult += [CGGeneric(";")]
|
tmpresult += [CGGeneric(";")]
|
||||||
result.append(CGList(tmpresult))
|
result.append(CGList(tmpresult))
|
||||||
|
|
||||||
originalDeclName = replacements["declName"]
|
conversion = CGGeneric(
|
||||||
|
string.Template(templateBody).substitute(replacements)
|
||||||
|
)
|
||||||
|
|
||||||
if declType is not None:
|
if declType is not None:
|
||||||
newDecl = [CGGeneric("let mut "),
|
newDecl = [CGGeneric("let mut "),
|
||||||
CGGeneric(originalDeclName),
|
CGGeneric(replacements["declName"]),
|
||||||
CGGeneric(": "),
|
CGGeneric(": "),
|
||||||
declType]
|
declType]
|
||||||
if initialValue:
|
if initialValue:
|
||||||
newDecl.append(CGGeneric(" = " + initialValue))
|
newDecl.append(CGGeneric(" = " + initialValue))
|
||||||
newDecl.append(CGGeneric(";"))
|
newDecl.append(CGGeneric(";"))
|
||||||
result.append(CGList(newDecl))
|
result.append(CGList(newDecl))
|
||||||
|
conversion = CGWrapper(conversion,
|
||||||
conversion = CGGeneric(
|
pre="%s = " % replacements["declName"],
|
||||||
string.Template(templateBody).substitute(replacements)
|
post=";")
|
||||||
)
|
|
||||||
|
|
||||||
if argcAndIndex is not None:
|
if argcAndIndex is not None:
|
||||||
declConstruct = None
|
declConstruct = None
|
||||||
|
@ -2916,8 +2918,8 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||||
"holderName": None,
|
"holderName": None,
|
||||||
})
|
})
|
||||||
jsConversion = CGWrapper(CGGeneric(jsConversion),
|
jsConversion = CGWrapper(CGGeneric(jsConversion),
|
||||||
pre="let retval;\n",
|
pre="let retval;\nretval = ",
|
||||||
post="\nOk(Some(retval))")
|
post=";\nOk(Some(retval))")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"name": name,
|
"name": name,
|
||||||
|
@ -4296,7 +4298,7 @@ class CGDictionary(CGThing):
|
||||||
|
|
||||||
propName = member.identifier.name
|
propName = member.identifier.name
|
||||||
conversion = CGIndenter(
|
conversion = CGIndenter(
|
||||||
CGGeneric(string.Template(templateBody).substitute(replacements)),
|
CGGeneric(string.Template("${declName} = " + templateBody + ";").substitute(replacements)),
|
||||||
8).define()
|
8).define()
|
||||||
if not member.defaultValue:
|
if not member.defaultValue:
|
||||||
raise TypeError("We don't support dictionary members without a "
|
raise TypeError("We don't support dictionary members without a "
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue