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

View file

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