aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-10-25 06:48:43 -0500
committerGitHub <noreply@github.com>2017-10-25 06:48:43 -0500
commit6449c00fc95c2aebe5b8322a70018d3664941d77 (patch)
tree7eb5bd3d80699c8af237e584a2c7f47e7593c756 /components/script/dom/bindings/codegen/CodegenRust.py
parent5da0a8d8725edde1aab0e802b1381bb379fd6638 (diff)
parent3ed5899a64e2e386b3ed94954c5d41048c02335b (diff)
downloadservo-6449c00fc95c2aebe5b8322a70018d3664941d77.tar.gz
servo-6449c00fc95c2aebe5b8322a70018d3664941d77.zip
Auto merge of #19007 - MortimerGoro:const_codegen, r=emilio
Fix Const IDL value compilation errors in codegen <!-- Please describe your changes on the following line: --> I found that some const WebIDL values fail at rust compile time. Example: const long long TIMEOUT_IGNORED = -1; ``` 906 | ConstantSpec { name: b"TIMEOUT_IGNORED\0", value: ConstantVal::DoubleVal(-1) }] | ^^ expected f64, found integral variable | = note: expected type `f64` found type `{integer}` ``` I added a explicit cast to to fix the problem in conversions that may fail to compile. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19007) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 3251290f398..b7438e6be0a 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1198,12 +1198,12 @@ def convertConstIDLValueToJSVal(value):
if tag == IDLType.Tags.uint32:
return "ConstantVal::UintVal(%s)" % (value.value)
if tag in [IDLType.Tags.int64, IDLType.Tags.uint64]:
- return "ConstantVal::DoubleVal(%s)" % (value.value)
+ return "ConstantVal::DoubleVal(%s as f64)" % (value.value)
if tag == IDLType.Tags.bool:
return "ConstantVal::BoolVal(true)" if value.value else "ConstantVal::BoolVal(false)"
if tag in [IDLType.Tags.unrestricted_float, IDLType.Tags.float,
IDLType.Tags.unrestricted_double, IDLType.Tags.double]:
- return "ConstantVal::DoubleVal(%s)" % (value.value)
+ return "ConstantVal::DoubleVal(%s as f64)" % (value.value)
raise TypeError("Const value of unhandled type: " + value.type)
@@ -4077,7 +4077,17 @@ class CGConstant(CGThing):
def define(self):
name = self.constant.identifier.name
value = convertConstIDLValueToRust(self.constant.value)
- return "pub const %s: %s = %s;\n" % (name, builtinNames[self.constant.value.type.tag()], value)
+
+ tag = self.constant.value.type.tag()
+ const_type = builtinNames[self.constant.value.type.tag()]
+ # Finite<f32> or Finite<f64> cannot be used un a constant declaration.
+ # Remote the Finite type from restricted float and double tag declarations.
+ if tag == IDLType.Tags.float:
+ const_type = "f32"
+ elif tag == IDLType.Tags.double:
+ const_type = "f64"
+
+ return "pub const %s: %s = %s;\n" % (name, const_type, value)
def getUnionTypeTemplateVars(type, descriptorProvider):