mirror of
https://github.com/servo/servo.git
synced 2025-06-12 18:34:39 +00:00
parent
56d3426431
commit
a276bfa57c
2 changed files with 4 additions and 234 deletions
|
@ -5,7 +5,6 @@
|
||||||
# Common codegen classes.
|
# Common codegen classes.
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import textwrap
|
import textwrap
|
||||||
|
@ -24,7 +23,6 @@ from Configuration import getTypesFromDescriptor, getTypesFromDictionary, getTyp
|
||||||
|
|
||||||
AUTOGENERATED_WARNING_COMMENT = \
|
AUTOGENERATED_WARNING_COMMENT = \
|
||||||
"/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
|
"/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
|
||||||
ADDPROPERTY_HOOK_NAME = '_addProperty'
|
|
||||||
FINALIZE_HOOK_NAME = '_finalize'
|
FINALIZE_HOOK_NAME = '_finalize'
|
||||||
TRACE_HOOK_NAME = '_trace'
|
TRACE_HOOK_NAME = '_trace'
|
||||||
CONSTRUCT_HOOK_NAME = '_constructor'
|
CONSTRUCT_HOOK_NAME = '_constructor'
|
||||||
|
@ -528,17 +526,6 @@ class CGMethodCall(CGThing):
|
||||||
return self.cgRoot.define()
|
return self.cgRoot.define()
|
||||||
|
|
||||||
|
|
||||||
class FakeCastableDescriptor():
|
|
||||||
def __init__(self, descriptor):
|
|
||||||
self.nativeType = "*const %s" % descriptor.concreteType
|
|
||||||
self.name = descriptor.name
|
|
||||||
|
|
||||||
class FakeInterface:
|
|
||||||
def inheritanceDepth(self):
|
|
||||||
return descriptor.interface.inheritanceDepth()
|
|
||||||
self.interface = FakeInterface()
|
|
||||||
|
|
||||||
|
|
||||||
def dictionaryHasSequenceMember(dictionary):
|
def dictionaryHasSequenceMember(dictionary):
|
||||||
return (any(typeIsSequenceOrHasSequenceMember(m.type) for m in
|
return (any(typeIsSequenceOrHasSequenceMember(m.type) for m in
|
||||||
dictionary.members) or
|
dictionary.members) or
|
||||||
|
@ -695,15 +682,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
'%s' % (firstCap(sourceDescription), exceptionCode))),
|
'%s' % (firstCap(sourceDescription), exceptionCode))),
|
||||||
post="\n")
|
post="\n")
|
||||||
|
|
||||||
def onFailureBadType(failureCode, typeName):
|
|
||||||
return CGWrapper(
|
|
||||||
CGGeneric(
|
|
||||||
failureCode or
|
|
||||||
('throw_type_error(cx, \"%s does not implement interface %s.\");\n'
|
|
||||||
'%s' % (firstCap(sourceDescription), typeName,
|
|
||||||
exceptionCode))),
|
|
||||||
post="\n")
|
|
||||||
|
|
||||||
def onFailureNotCallable(failureCode):
|
def onFailureNotCallable(failureCode):
|
||||||
return CGWrapper(
|
return CGWrapper(
|
||||||
CGGeneric(
|
CGGeneric(
|
||||||
|
@ -1267,18 +1245,6 @@ def typeNeedsCx(type, retVal=False):
|
||||||
return type.isAny() or type.isObject()
|
return type.isAny() or type.isObject()
|
||||||
|
|
||||||
|
|
||||||
def typeRetValNeedsRooting(type):
|
|
||||||
if type is None:
|
|
||||||
return False
|
|
||||||
if type.nullable():
|
|
||||||
type = type.inner
|
|
||||||
return type.isGeckoInterface() and not type.isCallback() and not type.isCallbackInterface()
|
|
||||||
|
|
||||||
|
|
||||||
def memberIsCreator(member):
|
|
||||||
return member.getExtendedAttribute("Creator") is not None
|
|
||||||
|
|
||||||
|
|
||||||
# Returns a CGThing containing the type of the return value.
|
# Returns a CGThing containing the type of the return value.
|
||||||
def getRetvalDeclarationForType(returnType, descriptorProvider):
|
def getRetvalDeclarationForType(returnType, descriptorProvider):
|
||||||
if returnType is None or returnType.isVoid():
|
if returnType is None or returnType.isVoid():
|
||||||
|
@ -1726,13 +1692,6 @@ class CGImports(CGWrapper):
|
||||||
CGWrapper.__init__(self, child,
|
CGWrapper.__init__(self, child,
|
||||||
pre='\n'.join(statements) + '\n\n')
|
pre='\n'.join(statements) + '\n\n')
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def getDeclarationFilename(decl):
|
|
||||||
# Use our local version of the header, not the exported one, so that
|
|
||||||
# test bindings, which don't export, will work correctly.
|
|
||||||
basename = os.path.basename(decl.filename())
|
|
||||||
return basename.replace('.webidl', 'Binding.rs')
|
|
||||||
|
|
||||||
|
|
||||||
class CGIfWrapper(CGWrapper):
|
class CGIfWrapper(CGWrapper):
|
||||||
def __init__(self, child, condition):
|
def __init__(self, child, condition):
|
||||||
|
@ -2649,11 +2608,6 @@ class CGCallGenerator(CGThing):
|
||||||
return self.cgRoot.define()
|
return self.cgRoot.define()
|
||||||
|
|
||||||
|
|
||||||
class MethodNotCreatorError(Exception):
|
|
||||||
def __init__(self, typename):
|
|
||||||
self.typename = typename
|
|
||||||
|
|
||||||
|
|
||||||
class CGPerSignatureCall(CGThing):
|
class CGPerSignatureCall(CGThing):
|
||||||
"""
|
"""
|
||||||
This class handles the guts of generating code for a particular
|
This class handles the guts of generating code for a particular
|
||||||
|
@ -2826,10 +2780,6 @@ class CGSetterCall(CGPerSignatureCall):
|
||||||
def getArgc(self):
|
def getArgc(self):
|
||||||
return "1"
|
return "1"
|
||||||
|
|
||||||
def getArgvDecl(self):
|
|
||||||
# We just get our stuff from our last arg no matter what
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
class CGAbstractStaticBindingMethod(CGAbstractMethod):
|
class CGAbstractStaticBindingMethod(CGAbstractMethod):
|
||||||
"""
|
"""
|
||||||
|
@ -3695,31 +3645,6 @@ class ClassMethod(ClassItem):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ClassUsingDeclaration(ClassItem):
|
|
||||||
""""
|
|
||||||
Used for importing a name from a base class into a CGClass
|
|
||||||
|
|
||||||
baseClass is the name of the base class to import the name from
|
|
||||||
|
|
||||||
name is the name to import
|
|
||||||
|
|
||||||
visibility determines the visibility of the name (public,
|
|
||||||
protected, private), defaults to public.
|
|
||||||
"""
|
|
||||||
def __init__(self, baseClass, name, visibility='public'):
|
|
||||||
self.baseClass = baseClass
|
|
||||||
ClassItem.__init__(self, name, visibility)
|
|
||||||
|
|
||||||
def declare(self, cgClass):
|
|
||||||
return string.Template("""\
|
|
||||||
using ${baseClass}::${name};
|
|
||||||
""").substitute({'baseClass': self.baseClass,
|
|
||||||
'name': self.name})
|
|
||||||
|
|
||||||
def define(self, cgClass):
|
|
||||||
return ''
|
|
||||||
|
|
||||||
|
|
||||||
class ClassConstructor(ClassItem):
|
class ClassConstructor(ClassItem):
|
||||||
"""
|
"""
|
||||||
Used for adding a constructor to a CGClass.
|
Used for adding a constructor to a CGClass.
|
||||||
|
@ -3825,77 +3750,6 @@ ${className}::${className}(${args})${initializationList}
|
||||||
'body': body})
|
'body': body})
|
||||||
|
|
||||||
|
|
||||||
class ClassDestructor(ClassItem):
|
|
||||||
"""
|
|
||||||
Used for adding a destructor to a CGClass.
|
|
||||||
|
|
||||||
inline should be True if the destructor should be marked inline.
|
|
||||||
|
|
||||||
bodyInHeader should be True if the body should be placed in the class
|
|
||||||
declaration in the header.
|
|
||||||
|
|
||||||
visibility determines the visibility of the destructor (public,
|
|
||||||
protected, private), defaults to private.
|
|
||||||
|
|
||||||
body contains a string with the code for the destructor, defaults to empty.
|
|
||||||
|
|
||||||
virtual determines whether the destructor is virtual, defaults to False.
|
|
||||||
"""
|
|
||||||
def __init__(self, inline=False, bodyInHeader=False,
|
|
||||||
visibility="private", body='', virtual=False):
|
|
||||||
self.inline = inline or bodyInHeader
|
|
||||||
self.bodyInHeader = bodyInHeader
|
|
||||||
self.body = body
|
|
||||||
self.virtual = virtual
|
|
||||||
ClassItem.__init__(self, None, visibility)
|
|
||||||
|
|
||||||
def getDecorators(self, declaring):
|
|
||||||
decorators = []
|
|
||||||
if self.virtual and declaring:
|
|
||||||
decorators.append('virtual')
|
|
||||||
if self.inline and declaring:
|
|
||||||
decorators.append('inline')
|
|
||||||
if decorators:
|
|
||||||
return ' '.join(decorators) + ' '
|
|
||||||
return ''
|
|
||||||
|
|
||||||
def getBody(self):
|
|
||||||
return self.body
|
|
||||||
|
|
||||||
def declare(self, cgClass):
|
|
||||||
if self.bodyInHeader:
|
|
||||||
body = ' ' + self.getBody()
|
|
||||||
body = stripTrailingWhitespace(body.replace('\n', '\n '))
|
|
||||||
if len(body) > 0:
|
|
||||||
body += '\n'
|
|
||||||
body = '\n{\n' + body + '}'
|
|
||||||
else:
|
|
||||||
body = ';'
|
|
||||||
|
|
||||||
return string.Template("""\
|
|
||||||
${decorators}~${className}()${body}
|
|
||||||
""").substitute({'decorators': self.getDecorators(True),
|
|
||||||
'className': cgClass.getNameString(),
|
|
||||||
'body': body})
|
|
||||||
|
|
||||||
def define(self, cgClass):
|
|
||||||
if self.bodyInHeader:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
body = ' ' + self.getBody()
|
|
||||||
body = '\n' + stripTrailingWhitespace(body.replace('\n', '\n '))
|
|
||||||
if len(body) > 0:
|
|
||||||
body += '\n'
|
|
||||||
|
|
||||||
return string.Template("""\
|
|
||||||
${decorators}
|
|
||||||
${className}::~${className}()
|
|
||||||
{${body}}
|
|
||||||
""").substitute({'decorators': self.getDecorators(False),
|
|
||||||
'className': cgClass.getNameString(),
|
|
||||||
'body': body})
|
|
||||||
|
|
||||||
|
|
||||||
class ClassMember(ClassItem):
|
class ClassMember(ClassItem):
|
||||||
def __init__(self, name, type, visibility="priv", static=False,
|
def __init__(self, name, type, visibility="priv", static=False,
|
||||||
body=None):
|
body=None):
|
||||||
|
@ -3918,63 +3772,14 @@ class ClassMember(ClassItem):
|
||||||
self.name, body)
|
self.name, body)
|
||||||
|
|
||||||
|
|
||||||
class ClassTypedef(ClassItem):
|
|
||||||
def __init__(self, name, type, visibility="public"):
|
|
||||||
self.type = type
|
|
||||||
ClassItem.__init__(self, name, visibility)
|
|
||||||
|
|
||||||
def declare(self, cgClass):
|
|
||||||
return 'typedef %s %s;\n' % (self.type, self.name)
|
|
||||||
|
|
||||||
def define(self, cgClass):
|
|
||||||
# Only goes in the header
|
|
||||||
return ''
|
|
||||||
|
|
||||||
|
|
||||||
class ClassEnum(ClassItem):
|
|
||||||
def __init__(self, name, entries, values=None, visibility="public"):
|
|
||||||
self.entries = entries
|
|
||||||
self.values = values
|
|
||||||
ClassItem.__init__(self, name, visibility)
|
|
||||||
|
|
||||||
def declare(self, cgClass):
|
|
||||||
entries = []
|
|
||||||
for i in range(0, len(self.entries)):
|
|
||||||
if not self.values or i >= len(self.values):
|
|
||||||
entry = '%s' % self.entries[i]
|
|
||||||
else:
|
|
||||||
entry = '%s = %s' % (self.entries[i], self.values[i])
|
|
||||||
entries.append(entry)
|
|
||||||
name = '' if not self.name else ' ' + self.name
|
|
||||||
return 'enum%s\n{\n%s\n};\n' % (name, ',\n '.join(entries))
|
|
||||||
|
|
||||||
def define(self, cgClass):
|
|
||||||
# Only goes in the header
|
|
||||||
return ''
|
|
||||||
|
|
||||||
|
|
||||||
class ClassUnion(ClassItem):
|
|
||||||
def __init__(self, name, entries, visibility="public"):
|
|
||||||
self.entries = [entry + ";" for entry in entries]
|
|
||||||
ClassItem.__init__(self, name, visibility)
|
|
||||||
|
|
||||||
def declare(self, cgClass):
|
|
||||||
return 'union %s\n{\n%s\n};\n' % (self.name, '\n '.join(self.entries))
|
|
||||||
|
|
||||||
def define(self, cgClass):
|
|
||||||
# Only goes in the header
|
|
||||||
return ''
|
|
||||||
|
|
||||||
|
|
||||||
class CGClass(CGThing):
|
class CGClass(CGThing):
|
||||||
def __init__(self, name, bases=[], members=[], constructors=[],
|
def __init__(self, name, bases=[], members=[], constructors=[],
|
||||||
destructor=None, methods=[],
|
destructor=None, methods=[],
|
||||||
typedefs=[], enums=[], unions=[], templateArgs=[],
|
typedefs=[], enums=[], unions=[], templateArgs=[],
|
||||||
templateSpecialization=[], isStruct=False,
|
templateSpecialization=[],
|
||||||
disallowCopyConstruction=False, indent='',
|
disallowCopyConstruction=False, indent='',
|
||||||
decorators='',
|
decorators='',
|
||||||
extradeclarations='',
|
extradeclarations=''):
|
||||||
extradefinitions=''):
|
|
||||||
CGThing.__init__(self)
|
CGThing.__init__(self)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.bases = bases
|
self.bases = bases
|
||||||
|
@ -3989,12 +3794,10 @@ class CGClass(CGThing):
|
||||||
self.unions = unions
|
self.unions = unions
|
||||||
self.templateArgs = templateArgs
|
self.templateArgs = templateArgs
|
||||||
self.templateSpecialization = templateSpecialization
|
self.templateSpecialization = templateSpecialization
|
||||||
self.isStruct = isStruct
|
|
||||||
self.disallowCopyConstruction = disallowCopyConstruction
|
self.disallowCopyConstruction = disallowCopyConstruction
|
||||||
self.indent = indent
|
self.indent = indent
|
||||||
self.decorators = decorators
|
self.decorators = decorators
|
||||||
self.extradeclarations = extradeclarations
|
self.extradeclarations = extradeclarations
|
||||||
self.extradefinitions = extradefinitions
|
|
||||||
|
|
||||||
def getNameString(self):
|
def getNameString(self):
|
||||||
className = self.name
|
className = self.name
|
||||||
|
@ -4170,15 +3973,6 @@ class CGProxyNamedGetter(CGProxySpecialOperation):
|
||||||
CGProxySpecialOperation.__init__(self, descriptor, 'NamedGetter')
|
CGProxySpecialOperation.__init__(self, descriptor, 'NamedGetter')
|
||||||
|
|
||||||
|
|
||||||
class CGProxyNamedPresenceChecker(CGProxyNamedGetter):
|
|
||||||
"""
|
|
||||||
Class to generate a call that checks whether a named property exists.
|
|
||||||
For now, we just delegate to CGProxyNamedGetter
|
|
||||||
"""
|
|
||||||
def __init__(self, descriptor):
|
|
||||||
CGProxyNamedGetter.__init__(self, descriptor)
|
|
||||||
|
|
||||||
|
|
||||||
class CGProxyNamedSetter(CGProxySpecialOperation):
|
class CGProxyNamedSetter(CGProxySpecialOperation):
|
||||||
"""
|
"""
|
||||||
Class to generate a call to a named setter.
|
Class to generate a call to a named setter.
|
||||||
|
@ -5040,10 +4834,6 @@ class CGDictionary(CGThing):
|
||||||
|
|
||||||
return CGGeneric(conversion)
|
return CGGeneric(conversion)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def makeIdName(name):
|
|
||||||
return name + "_id"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def makeMemberName(name):
|
def makeMemberName(name):
|
||||||
# Can't use Rust keywords as member names.
|
# Can't use Rust keywords as member names.
|
||||||
|
@ -5297,12 +5087,8 @@ def return_type(descriptorProvider, rettype, infallible):
|
||||||
|
|
||||||
class CGNativeMember(ClassMethod):
|
class CGNativeMember(ClassMethod):
|
||||||
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
|
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
|
||||||
breakAfter=True, passJSBitsAsNeeded=True, visibility="public",
|
breakAfter=True, passJSBitsAsNeeded=True, visibility="public"):
|
||||||
jsObjectsArePtr=False, variadicIsSequence=False):
|
|
||||||
"""
|
"""
|
||||||
If jsObjectsArePtr is true, typed arrays and "object" will be
|
|
||||||
passed as JSObject*.
|
|
||||||
|
|
||||||
If passJSBitsAsNeeded is false, we don't automatically pass in a
|
If passJSBitsAsNeeded is false, we don't automatically pass in a
|
||||||
JSContext* or a JSObject* based on the return and argument types.
|
JSContext* or a JSObject* based on the return and argument types.
|
||||||
"""
|
"""
|
||||||
|
@ -5310,8 +5096,6 @@ class CGNativeMember(ClassMethod):
|
||||||
self.member = member
|
self.member = member
|
||||||
self.extendedAttrs = extendedAttrs
|
self.extendedAttrs = extendedAttrs
|
||||||
self.passJSBitsAsNeeded = passJSBitsAsNeeded
|
self.passJSBitsAsNeeded = passJSBitsAsNeeded
|
||||||
self.jsObjectsArePtr = jsObjectsArePtr
|
|
||||||
self.variadicIsSequence = variadicIsSequence
|
|
||||||
breakAfterSelf = "\n" if breakAfter else ""
|
breakAfterSelf = "\n" if breakAfter else ""
|
||||||
ClassMethod.__init__(self, name,
|
ClassMethod.__init__(self, name,
|
||||||
self.getReturnType(signature[0]),
|
self.getReturnType(signature[0]),
|
||||||
|
@ -5543,8 +5327,7 @@ class CallbackMember(CGNativeMember):
|
||||||
name, (self.retvalType, args),
|
name, (self.retvalType, args),
|
||||||
extendedAttrs={},
|
extendedAttrs={},
|
||||||
passJSBitsAsNeeded=False,
|
passJSBitsAsNeeded=False,
|
||||||
visibility=visibility,
|
visibility=visibility)
|
||||||
jsObjectsArePtr=True)
|
|
||||||
# We have to do all the generation of our body now, because
|
# We have to do all the generation of our body now, because
|
||||||
# the caller relies on us throwing if we can't manage it.
|
# the caller relies on us throwing if we can't manage it.
|
||||||
self.exceptionCode = "return Err(JSFailed);"
|
self.exceptionCode = "return Err(JSFailed);"
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
from WebIDL import IDLInterface
|
from WebIDL import IDLInterface
|
||||||
|
|
||||||
autogenerated_comment = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n"
|
|
||||||
|
|
||||||
|
|
||||||
class Configuration:
|
class Configuration:
|
||||||
"""
|
"""
|
||||||
|
@ -344,17 +342,6 @@ def getTypesFromDescriptor(descriptor):
|
||||||
return types
|
return types
|
||||||
|
|
||||||
|
|
||||||
def getFlatTypes(types):
|
|
||||||
retval = set()
|
|
||||||
for type in types:
|
|
||||||
type = type.unroll()
|
|
||||||
if type.isUnion():
|
|
||||||
retval |= set(type.flatMemberTypes)
|
|
||||||
else:
|
|
||||||
retval.add(type)
|
|
||||||
return retval
|
|
||||||
|
|
||||||
|
|
||||||
def getTypesFromDictionary(dictionary):
|
def getTypesFromDictionary(dictionary):
|
||||||
"""
|
"""
|
||||||
Get all member types for this dictionary
|
Get all member types for this dictionary
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue