aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorNathan Froyd <froydnj@gmail.com>2015-10-15 22:04:21 -0400
committerNathan Froyd <froydnj@gmail.com>2015-10-27 15:07:55 -0400
commitdd74572dc0c0d34124ef8cbcd7ffa0dc62935d94 (patch)
treec2d755af6b040d343a39894498fb6162d453d2d9 /components/script/dom/bindings/codegen/CodegenRust.py
parentefc4ce876f0fb81e2b7b39c9c567d0bf6944bd64 (diff)
downloadservo-dd74572dc0c0d34124ef8cbcd7ffa0dc62935d94.tar.gz
servo-dd74572dc0c0d34124ef8cbcd7ffa0dc62935d94.zip
add CGMemberJITInfo.{getJSArgType,getSingleArgType}
These are copied directly from Gecko's Codegen.py, with two changes: - We need to use ArgType:: to qualify the enums rather than plain JSJitInfo:: - Given Rust's stronger notion of enums, we need to treat everything as an i32 so we can bitwise-or things together.
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 1d054d03f14..452dde13149 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -3286,6 +3286,73 @@ class CGMemberJITInfo(CGThing):
# Different types
return "JSVAL_TYPE_UNKNOWN"
+ @staticmethod
+ def getJSArgType(t):
+ assert not t.isVoid()
+ if t.nullable():
+ # Sometimes it might return null, sometimes not
+ return "ArgType::Null as i32 | %s" % CGMemberJITInfo.getJSArgType(t.inner)
+ if t.isArray():
+ # No idea yet
+ assert False
+ if t.isSequence():
+ return "ArgType::Object as i32"
+ if t.isGeckoInterface():
+ return "ArgType::Object as i32"
+ if t.isString():
+ return "ArgType::String as i32"
+ if t.isEnum():
+ return "ArgType::String as i32"
+ if t.isCallback():
+ return "ArgType::Object as i32"
+ if t.isAny():
+ # The whole point is to return various stuff
+ return "ArgType::Any as i32"
+ if t.isObject():
+ return "ArgType::Object as i32"
+ if t.isSpiderMonkeyInterface():
+ return "ArgType::Object as i32"
+ if t.isUnion():
+ u = t.unroll()
+ type = "JSJitInfo::Null as i32" if u.hasNullableType else ""
+ return reduce(CGMemberJITInfo.getSingleArgType,
+ u.flatMemberTypes, type)
+ if t.isDictionary():
+ return "ArgType::Object as i32"
+ if t.isDate():
+ return "ArgType::Object as i32"
+ if not t.isPrimitive():
+ raise TypeError("No idea what type " + str(t) + " is.")
+ tag = t.tag()
+ if tag == IDLType.Tags.bool:
+ return "ArgType::Boolean as i32"
+ if tag in [IDLType.Tags.int8, IDLType.Tags.uint8,
+ IDLType.Tags.int16, IDLType.Tags.uint16,
+ IDLType.Tags.int32]:
+ return "ArgType::Integer as i32"
+ if tag in [IDLType.Tags.int64, IDLType.Tags.uint64,
+ IDLType.Tags.unrestricted_float, IDLType.Tags.float,
+ IDLType.Tags.unrestricted_double, IDLType.Tags.double]:
+ # These all use JS_NumberValue, which can return int or double.
+ # But TI treats "double" as meaning "int or double", so we're
+ # good to return JSVAL_TYPE_DOUBLE here.
+ return "ArgType::Double as i32"
+ if tag != IDLType.Tags.uint32:
+ raise TypeError("No idea what type " + str(t) + " is.")
+ # uint32 is sometimes int and sometimes double.
+ return "ArgType::Double as i32"
+
+ @staticmethod
+ def getSingleArgType(existingType, t):
+ type = CGMemberJITInfo.getJSArgType(t)
+ if existingType == "":
+ # First element of the list; just return its type
+ return type
+
+ if type == existingType:
+ return existingType
+ return "%s | %s" % (existingType, type)
+
def getEnumValueName(value):
# Some enum values can be empty strings. Others might have weird