auto merge of #2156 : Ms2ger/servo/codegen-deadcode, r=jdm

This commit is contained in:
bors-servo 2014-04-18 10:28:11 -04:00
commit 58efe0bf75
2 changed files with 23 additions and 81 deletions

View file

@ -9,7 +9,7 @@ import string
import operator import operator
from WebIDL import * from WebIDL import *
from Configuration import NoSuchDescriptorError, Descriptor from Configuration import Descriptor
AUTOGENERATED_WARNING_COMMENT = \ AUTOGENERATED_WARNING_COMMENT = \
"/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n" "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
@ -498,9 +498,6 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
# they really should be! # they really should be!
if exceptionCode is None: if exceptionCode is None:
exceptionCode = "return 0;" exceptionCode = "return 0;"
# We often want exceptionCode to be indented, since it often appears in an
# if body.
exceptionCodeIndented = CGIndenter(CGGeneric(exceptionCode))
# Unfortunately, .capitalize() on a string will lowercase things inside the # Unfortunately, .capitalize() on a string will lowercase things inside the
# string, which we do not want. # string, which we do not want.
@ -620,12 +617,6 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
failureCode) failureCode)
return (template, declType, None, isOptional, None) return (template, declType, None, isOptional, None)
# Sequences and callbacks have to hold a strong ref to the thing being
# passed down.
forceOwningType = descriptor.interface.isCallback() or isMember
typePtr = descriptor.nativeType
templateBody = "" templateBody = ""
if descriptor.interface.isConsequential(): if descriptor.interface.isConsequential():
raise TypeError("Consequential interface %s being used as an " raise TypeError("Consequential interface %s being used as an "
@ -648,7 +639,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject, templateBody = wrapObjectTemplate(templateBody, isDefinitelyObject,
type, failureCode) type, failureCode)
declType = CGGeneric(typePtr) declType = CGGeneric(descriptor.nativeType)
if type.nullable() or isOptional: if type.nullable() or isOptional:
declType = CGWrapper(declType, pre="Option<", post=">") declType = CGWrapper(declType, pre="Option<", post=">")
@ -803,15 +794,9 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
assert not isOptional assert not isOptional
typeName = CGDictionary.makeDictionaryName(type.inner) typeName = CGDictionary.makeDictionaryName(type.inner)
actualTypeName = typeName
selfRef = "${declName}" selfRef = "${declName}"
declType = CGGeneric(actualTypeName) declType = CGGeneric(typeName)
# If we're a member of something else, the const
# will come from the Optional or our container.
if not isMember:
selfRef = "%s" % selfRef
# We do manual default value handling here, because we # We do manual default value handling here, because we
# actually do want a jsval, and we only handle null anyway # actually do want a jsval, and we only handle null anyway
@ -824,7 +809,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
template = ("%s = %s::new();\n" template = ("%s = %s::new();\n"
"if %s.Init(cx, %s) == 0 {\n" "if %s.Init(cx, %s) == 0 {\n"
" return 0;\n" " return 0;\n"
"}" % (selfRef, actualTypeName, selfRef, val)) "}" % (selfRef, typeName, selfRef, val))
return (template, declType, None, False, None) return (template, declType, None, False, None)
@ -837,11 +822,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
if not type.isPrimitive(): if not type.isPrimitive():
raise TypeError("Need conversion for argument type '%s'" % str(type)) raise TypeError("Need conversion for argument type '%s'" % str(type))
conversionBehavior = "eDefault" assert not isEnforceRange and not isClamp
if isEnforceRange:
conversionBehavior = "eEnforceRange"
elif isClamp:
conversionBehavior = "eClamp"
if failureCode is None: if failureCode is None:
failureCode = 'return 0' failureCode = 'return 0'
@ -925,8 +906,6 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
originalDeclName = replacements["declName"] originalDeclName = replacements["declName"]
if declType is not None: if declType is not None:
if dealWithOptional:
mutableDeclType = CGWrapper(declType, pre="Option< ", post=" >")
newDecl = [CGGeneric("let mut "), newDecl = [CGGeneric("let mut "),
CGGeneric(originalDeclName), CGGeneric(originalDeclName),
CGGeneric(": "), CGGeneric(": "),
@ -2237,7 +2216,6 @@ class CGCallGenerator(CGThing):
name = "(JSObject&)" + name name = "(JSObject&)" + name
#XXXjdm Perhaps we should pass all nontrivial types by borrowed pointer #XXXjdm Perhaps we should pass all nontrivial types by borrowed pointer
if a.type.isGeckoInterface(): if a.type.isGeckoInterface():
argDescriptor = descriptorProvider.getDescriptor(a.type.name)
if not (a.type.nullable() or a.optional): if not (a.type.nullable() or a.optional):
name = "&mut " + name name = "&mut " + name
elif a.type.isDictionary(): elif a.type.isDictionary():
@ -2897,15 +2875,12 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
name = type.name name = type.name
typeName = "/*" + type.name + "*/" typeName = "/*" + type.name + "*/"
(template, declType, holderType, (template, _, holderType,
dealWithOptional, initialValue) = getJSToNativeConversionTemplate( dealWithOptional, initialValue) = getJSToNativeConversionTemplate(
type, descriptorProvider, failureCode="return Ok(None);", type, descriptorProvider, failureCode="return Ok(None);",
exceptionCode='return Err(());', exceptionCode='return Err(());',
isDefinitelyObject=True, isOptional=False) isDefinitelyObject=True, isOptional=False)
structType = declType.define()
externalType = getUnionAccessorSignatureType(type, descriptorProvider).define()
assert not type.isObject() assert not type.isObject()
jsConversion = string.Template(template).substitute({ jsConversion = string.Template(template).substitute({
"val": "value", "val": "value",
@ -3537,7 +3512,6 @@ class CGProxySpecialOperation(CGPerSignatureCall):
operation = descriptor.operations[operation] operation = descriptor.operations[operation]
assert len(operation.signatures()) == 1 assert len(operation.signatures()) == 1
signature = operation.signatures()[0] signature = operation.signatures()[0]
extendedAttributes = descriptor.getExtendedAttributes(operation)
(returnType, arguments) = signature (returnType, arguments) = signature
@ -4041,13 +4015,16 @@ class CGDescriptor(CGThing):
else: else:
hasSetter = True hasSetter = True
cgThings.append(CGMemberJITInfo(descriptor, m)) cgThings.append(CGMemberJITInfo(descriptor, m))
if hasMethod: cgThings.append(CGGenericMethod(descriptor)) if hasMethod:
if hasGetter: cgThings.append(CGGenericGetter(descriptor)) cgThings.append(CGGenericMethod(descriptor))
#if hasLenientGetter: cgThings.append(CGGenericGetter(descriptor, if hasGetter:
# lenientThis=True)) cgThings.append(CGGenericGetter(descriptor))
if hasSetter: cgThings.append(CGGenericSetter(descriptor)) if hasLenientGetter:
#if hasLenientSetter: cgThings.append(CGGenericSetter(descriptor, pass
# lenientThis=True)) if hasSetter:
cgThings.append(CGGenericSetter(descriptor))
if hasLenientSetter:
pass
if descriptor.concrete: if descriptor.concrete:
cgThings.append(CGClassFinalizeHook(descriptor)) cgThings.append(CGClassFinalizeHook(descriptor))
@ -4189,9 +4166,6 @@ class CGDictionary(CGThing):
"pub struct ${selfName} {\n" + "pub struct ${selfName} {\n" +
"${inheritance}" + "${inheritance}" +
"\n".join(memberDecls) + "\n" + "\n".join(memberDecls) + "\n" +
"\n".join(" //static jsid " +
self.makeIdName(m.identifier.name) + ";" for
m in d.members) + "\n"
"}").substitute( { "selfName": self.makeClassName(d), "}").substitute( { "selfName": self.makeClassName(d),
"inheritance": inheritance })) "inheritance": inheritance }))
@ -4207,15 +4181,6 @@ class CGDictionary(CGThing):
memberInits = [CGIndenter(self.getMemberConversion(m), indentLevel=6).define() memberInits = [CGIndenter(self.getMemberConversion(m), indentLevel=6).define()
for m in self.memberInfo] for m in self.memberInfo]
idinit = [CGGeneric('!InternJSString(cx, %s, "%s")' %
(m.identifier.name + "_id", m.identifier.name))
for m in d.members]
idinit = CGList(idinit, " ||\n")
idinit = CGWrapper(idinit, pre="if (",
post=(") {\n"
" return false;\n"
"}"),
reindent=True)
def defaultValue(ty): def defaultValue(ty):
if ty is "bool": if ty is "bool":
@ -4230,11 +4195,6 @@ class CGDictionary(CGThing):
return "/* uh oh: %s */" % ty return "/* uh oh: %s */" % ty
return string.Template( return string.Template(
"static initedIds: bool = false;\n" +
"\n".join("static %s: jsid = JSID_VOID;" %
self.makeIdName(m.identifier.name)
for m in d.members) + "\n"
"\n"
"impl ${selfName} {\n" "impl ${selfName} {\n"
" pub fn new() -> ${selfName} {\n" " pub fn new() -> ${selfName} {\n"
" ${selfName} {\n" + " ${selfName} {\n" +
@ -4244,18 +4204,8 @@ class CGDictionary(CGThing):
" }\n" " }\n"
" }\n" " }\n"
"\n" "\n"
" pub fn InitIds(&mut self, cx: *JSContext) -> bool {\n"
" //MOZ_ASSERT(!initedIds);\n"
" /*${idInit}\n"
" initedIds = true;*/ //XXXjdm\n"
" return true;\n"
" }\n"
"\n"
" pub fn Init(&mut self, cx: *JSContext, val: JSVal) -> JSBool {\n" " pub fn Init(&mut self, cx: *JSContext, val: JSVal) -> JSBool {\n"
" unsafe {\n" " unsafe {\n"
" if !initedIds && !self.InitIds(cx) {\n"
" return 0;\n"
" }\n"
"${initParent}" "${initParent}"
" let mut found: JSBool = 0;\n" " let mut found: JSBool = 0;\n"
" let temp: JSVal = NullValue();\n" " let temp: JSVal = NullValue();\n"
@ -4273,7 +4223,6 @@ class CGDictionary(CGThing):
"selfName": self.makeClassName(d), "selfName": self.makeClassName(d),
"initParent": CGIndenter(CGGeneric(initParent), indentLevel=6).define(), "initParent": CGIndenter(CGGeneric(initParent), indentLevel=6).define(),
"initMembers": "\n\n".join(memberInits), "initMembers": "\n\n".join(memberInits),
"idInit": CGIndenter(idinit).define(),
}) })
@staticmethod @staticmethod
@ -4318,18 +4267,11 @@ class CGDictionary(CGThing):
if member.defaultValue: if member.defaultValue:
replacements["haveValue"] = "found != 0" replacements["haveValue"] = "found != 0"
if True: #XXXjdm hack until 'static mut' exists for global jsids
propName = member.identifier.name propName = member.identifier.name
propCheck = ('"%s".to_c_str().with_ref(|s| { JS_HasProperty(cx, val.to_object(), s, &found) })' % propCheck = ('"%s".to_c_str().with_ref(|s| { JS_HasProperty(cx, val.to_object(), s, &found) })' %
propName) propName)
propGet = ('"%s".to_c_str().with_ref(|s| { JS_GetProperty(cx, val.to_object(), s, &temp) })' % propGet = ('"%s".to_c_str().with_ref(|s| { JS_GetProperty(cx, val.to_object(), s, &temp) })' %
propName) propName)
else:
propId = self.makeIdName(member.identifier.name);
propCheck = ("JS_HasPropertyById(cx, val.to_object(), %s, &found)" %
propId)
propGet = ("JS_GetPropertyById(cx, val.to_object(), %s, &temp)" %
propId)
conversionReplacements = { conversionReplacements = {
"prop": "(this->%s)" % member.identifier.name, "prop": "(this->%s)" % member.identifier.name,

View file

@ -16,8 +16,8 @@ interface Blob {
readonly attribute unsigned long long size; readonly attribute unsigned long long size;
readonly attribute DOMString type; readonly attribute DOMString type;
Blob slice([Clamp] optional long long start, Blob slice(/*[Clamp]*/ optional long long start,
[Clamp] optional long long end, /*[Clamp]*/ optional long long end,
optional DOMString contentType); optional DOMString contentType);
void close(); void close();
}; };