mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Fix Const IDL value compilation errors in codegen
This commit is contained in:
parent
2bcb3b4ca9
commit
3ed5899a64
2 changed files with 20 additions and 3 deletions
|
@ -1198,12 +1198,12 @@ def convertConstIDLValueToJSVal(value):
|
||||||
if tag == IDLType.Tags.uint32:
|
if tag == IDLType.Tags.uint32:
|
||||||
return "ConstantVal::UintVal(%s)" % (value.value)
|
return "ConstantVal::UintVal(%s)" % (value.value)
|
||||||
if tag in [IDLType.Tags.int64, IDLType.Tags.uint64]:
|
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:
|
if tag == IDLType.Tags.bool:
|
||||||
return "ConstantVal::BoolVal(true)" if value.value else "ConstantVal::BoolVal(false)"
|
return "ConstantVal::BoolVal(true)" if value.value else "ConstantVal::BoolVal(false)"
|
||||||
if tag in [IDLType.Tags.unrestricted_float, IDLType.Tags.float,
|
if tag in [IDLType.Tags.unrestricted_float, IDLType.Tags.float,
|
||||||
IDLType.Tags.unrestricted_double, IDLType.Tags.double]:
|
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)
|
raise TypeError("Const value of unhandled type: " + value.type)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4077,7 +4077,17 @@ class CGConstant(CGThing):
|
||||||
def define(self):
|
def define(self):
|
||||||
name = self.constant.identifier.name
|
name = self.constant.identifier.name
|
||||||
value = convertConstIDLValueToRust(self.constant.value)
|
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):
|
def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||||
|
|
|
@ -151,6 +151,13 @@ interface TestBinding {
|
||||||
[BinaryName="BinaryRenamedAttribute2"] attribute DOMString attr-to-binary-rename;
|
[BinaryName="BinaryRenamedAttribute2"] attribute DOMString attr-to-binary-rename;
|
||||||
attribute DOMString attr-to-automatically-rename;
|
attribute DOMString attr-to-automatically-rename;
|
||||||
|
|
||||||
|
const long long constantInt64 = -1;
|
||||||
|
const unsigned long long constantUint64 = 1;
|
||||||
|
const float constantFloat32 = 1.0;
|
||||||
|
const double constantFloat64 = 1.0;
|
||||||
|
const unrestricted float constantUnrestrictedFloat32 = 1.0;
|
||||||
|
const unrestricted double constantUnrestrictedFloat64 = 1.0;
|
||||||
|
|
||||||
[PutForwards=booleanAttribute]
|
[PutForwards=booleanAttribute]
|
||||||
readonly attribute TestBinding forwardedAttribute;
|
readonly attribute TestBinding forwardedAttribute;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue