mirror of
https://github.com/servo/servo.git
synced 2025-06-11 01:50:10 +00:00
parent
56d3426431
commit
a276bfa57c
2 changed files with 4 additions and 234 deletions
|
@ -5,7 +5,6 @@
|
|||
# Common codegen classes.
|
||||
|
||||
import operator
|
||||
import os
|
||||
import re
|
||||
import string
|
||||
import textwrap
|
||||
|
@ -24,7 +23,6 @@ from Configuration import getTypesFromDescriptor, getTypesFromDictionary, getTyp
|
|||
|
||||
AUTOGENERATED_WARNING_COMMENT = \
|
||||
"/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
|
||||
ADDPROPERTY_HOOK_NAME = '_addProperty'
|
||||
FINALIZE_HOOK_NAME = '_finalize'
|
||||
TRACE_HOOK_NAME = '_trace'
|
||||
CONSTRUCT_HOOK_NAME = '_constructor'
|
||||
|
@ -528,17 +526,6 @@ class CGMethodCall(CGThing):
|
|||
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):
|
||||
return (any(typeIsSequenceOrHasSequenceMember(m.type) for m in
|
||||
dictionary.members) or
|
||||
|
@ -695,15 +682,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
'%s' % (firstCap(sourceDescription), exceptionCode))),
|
||||
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):
|
||||
return CGWrapper(
|
||||
CGGeneric(
|
||||
|
@ -1267,18 +1245,6 @@ def typeNeedsCx(type, retVal=False):
|
|||
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.
|
||||
def getRetvalDeclarationForType(returnType, descriptorProvider):
|
||||
if returnType is None or returnType.isVoid():
|
||||
|
@ -1726,13 +1692,6 @@ class CGImports(CGWrapper):
|
|||
CGWrapper.__init__(self, child,
|
||||
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):
|
||||
def __init__(self, child, condition):
|
||||
|
@ -2649,11 +2608,6 @@ class CGCallGenerator(CGThing):
|
|||
return self.cgRoot.define()
|
||||
|
||||
|
||||
class MethodNotCreatorError(Exception):
|
||||
def __init__(self, typename):
|
||||
self.typename = typename
|
||||
|
||||
|
||||
class CGPerSignatureCall(CGThing):
|
||||
"""
|
||||
This class handles the guts of generating code for a particular
|
||||
|
@ -2826,10 +2780,6 @@ class CGSetterCall(CGPerSignatureCall):
|
|||
def getArgc(self):
|
||||
return "1"
|
||||
|
||||
def getArgvDecl(self):
|
||||
# We just get our stuff from our last arg no matter what
|
||||
return ""
|
||||
|
||||
|
||||
class CGAbstractStaticBindingMethod(CGAbstractMethod):
|
||||
"""
|
||||
|
@ -3695,31 +3645,6 @@ class ClassMethod(ClassItem):
|
|||
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):
|
||||
"""
|
||||
Used for adding a constructor to a CGClass.
|
||||
|
@ -3825,77 +3750,6 @@ ${className}::${className}(${args})${initializationList}
|
|||
'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):
|
||||
def __init__(self, name, type, visibility="priv", static=False,
|
||||
body=None):
|
||||
|
@ -3918,63 +3772,14 @@ class ClassMember(ClassItem):
|
|||
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):
|
||||
def __init__(self, name, bases=[], members=[], constructors=[],
|
||||
destructor=None, methods=[],
|
||||
typedefs=[], enums=[], unions=[], templateArgs=[],
|
||||
templateSpecialization=[], isStruct=False,
|
||||
templateSpecialization=[],
|
||||
disallowCopyConstruction=False, indent='',
|
||||
decorators='',
|
||||
extradeclarations='',
|
||||
extradefinitions=''):
|
||||
extradeclarations=''):
|
||||
CGThing.__init__(self)
|
||||
self.name = name
|
||||
self.bases = bases
|
||||
|
@ -3989,12 +3794,10 @@ class CGClass(CGThing):
|
|||
self.unions = unions
|
||||
self.templateArgs = templateArgs
|
||||
self.templateSpecialization = templateSpecialization
|
||||
self.isStruct = isStruct
|
||||
self.disallowCopyConstruction = disallowCopyConstruction
|
||||
self.indent = indent
|
||||
self.decorators = decorators
|
||||
self.extradeclarations = extradeclarations
|
||||
self.extradefinitions = extradefinitions
|
||||
|
||||
def getNameString(self):
|
||||
className = self.name
|
||||
|
@ -4170,15 +3973,6 @@ class CGProxyNamedGetter(CGProxySpecialOperation):
|
|||
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 to generate a call to a named setter.
|
||||
|
@ -5040,10 +4834,6 @@ class CGDictionary(CGThing):
|
|||
|
||||
return CGGeneric(conversion)
|
||||
|
||||
@staticmethod
|
||||
def makeIdName(name):
|
||||
return name + "_id"
|
||||
|
||||
@staticmethod
|
||||
def makeMemberName(name):
|
||||
# Can't use Rust keywords as member names.
|
||||
|
@ -5297,12 +5087,8 @@ def return_type(descriptorProvider, rettype, infallible):
|
|||
|
||||
class CGNativeMember(ClassMethod):
|
||||
def __init__(self, descriptorProvider, member, name, signature, extendedAttrs,
|
||||
breakAfter=True, passJSBitsAsNeeded=True, visibility="public",
|
||||
jsObjectsArePtr=False, variadicIsSequence=False):
|
||||
breakAfter=True, passJSBitsAsNeeded=True, visibility="public"):
|
||||
"""
|
||||
If jsObjectsArePtr is true, typed arrays and "object" will be
|
||||
passed as JSObject*.
|
||||
|
||||
If passJSBitsAsNeeded is false, we don't automatically pass in a
|
||||
JSContext* or a JSObject* based on the return and argument types.
|
||||
"""
|
||||
|
@ -5310,8 +5096,6 @@ class CGNativeMember(ClassMethod):
|
|||
self.member = member
|
||||
self.extendedAttrs = extendedAttrs
|
||||
self.passJSBitsAsNeeded = passJSBitsAsNeeded
|
||||
self.jsObjectsArePtr = jsObjectsArePtr
|
||||
self.variadicIsSequence = variadicIsSequence
|
||||
breakAfterSelf = "\n" if breakAfter else ""
|
||||
ClassMethod.__init__(self, name,
|
||||
self.getReturnType(signature[0]),
|
||||
|
@ -5543,8 +5327,7 @@ class CallbackMember(CGNativeMember):
|
|||
name, (self.retvalType, args),
|
||||
extendedAttrs={},
|
||||
passJSBitsAsNeeded=False,
|
||||
visibility=visibility,
|
||||
jsObjectsArePtr=True)
|
||||
visibility=visibility)
|
||||
# We have to do all the generation of our body now, because
|
||||
# the caller relies on us throwing if we can't manage it.
|
||||
self.exceptionCode = "return Err(JSFailed);"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue