mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 827486, part 2 - Refactor example class codegen into common base class. r=bz
This commit is contained in:
parent
496c9b693e
commit
3193b58d5e
@ -7655,24 +7655,28 @@ class CGExampleSetter(CGNativeMember):
|
|||||||
def define(self, cgClass):
|
def define(self, cgClass):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
class CGExampleClass(CGClass):
|
class CGBindingImplClass(CGClass):
|
||||||
"""
|
"""
|
||||||
Codegen for the actual example class implemenation for this descriptor
|
Common codegen for generating a C++ implementation of a WebIDL interface
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor, cgMethod, cgGetter, cgSetter):
|
||||||
|
"""
|
||||||
|
cgMethod, cgGetter and cgSetter are classes used to codegen methods,
|
||||||
|
getters and setters.
|
||||||
|
"""
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
|
|
||||||
iface = descriptor.interface
|
iface = descriptor.interface
|
||||||
|
|
||||||
methodDecls = []
|
self.methodDecls = []
|
||||||
def appendMethod(m):
|
def appendMethod(m):
|
||||||
sigs = m.signatures()
|
sigs = m.signatures()
|
||||||
for s in sigs[:-1]:
|
for s in sigs[:-1]:
|
||||||
# Don't put an empty line after overloads, until we
|
# Don't put an empty line after overloads, until we
|
||||||
# get to the last one.
|
# get to the last one.
|
||||||
methodDecls.append(CGExampleMethod(descriptor, m, s,
|
self.methodDecls.append(cgMethod(descriptor, m, s,
|
||||||
breakAfter=False))
|
breakAfter=False))
|
||||||
methodDecls.append(CGExampleMethod(descriptor, m, sigs[-1]))
|
self.methodDecls.append(cgMethod(descriptor, m, sigs[-1]))
|
||||||
|
|
||||||
if iface.ctor():
|
if iface.ctor():
|
||||||
appendMethod(iface.ctor())
|
appendMethod(iface.ctor())
|
||||||
@ -7684,9 +7688,9 @@ class CGExampleClass(CGClass):
|
|||||||
continue
|
continue
|
||||||
appendMethod(m)
|
appendMethod(m)
|
||||||
elif m.isAttr():
|
elif m.isAttr():
|
||||||
methodDecls.append(CGExampleGetter(descriptor, m))
|
self.methodDecls.append(cgGetter(descriptor, m))
|
||||||
if not m.readonly:
|
if not m.readonly:
|
||||||
methodDecls.append(CGExampleSetter(descriptor, m))
|
self.methodDecls.append(cgSetter(descriptor, m))
|
||||||
|
|
||||||
# Now do the special operations
|
# Now do the special operations
|
||||||
def appendSpecialOperation(name, op):
|
def appendSpecialOperation(name, op):
|
||||||
@ -7719,7 +7723,7 @@ class CGExampleClass(CGClass):
|
|||||||
else:
|
else:
|
||||||
# We already added this method
|
# We already added this method
|
||||||
return
|
return
|
||||||
methodDecls.append(
|
self.methodDecls.append(
|
||||||
CGNativeMember(descriptor, op,
|
CGNativeMember(descriptor, op,
|
||||||
name,
|
name,
|
||||||
(returnType, args),
|
(returnType, args),
|
||||||
@ -7732,7 +7736,7 @@ class CGExampleClass(CGClass):
|
|||||||
# If we support indexed properties, then we need a Length()
|
# If we support indexed properties, then we need a Length()
|
||||||
# method so we know which indices are supported.
|
# method so we know which indices are supported.
|
||||||
if descriptor.supportsIndexedProperties():
|
if descriptor.supportsIndexedProperties():
|
||||||
methodDecls.append(
|
self.methodDecls.append(
|
||||||
CGNativeMember(descriptor, FakeMember(),
|
CGNativeMember(descriptor, FakeMember(),
|
||||||
"Length",
|
"Length",
|
||||||
(BuiltinTypes[IDLBuiltinType.Types.unsigned_long],
|
(BuiltinTypes[IDLBuiltinType.Types.unsigned_long],
|
||||||
@ -7741,7 +7745,7 @@ class CGExampleClass(CGClass):
|
|||||||
# And if we support named properties we need to be able to
|
# And if we support named properties we need to be able to
|
||||||
# enumerate the supported names.
|
# enumerate the supported names.
|
||||||
if descriptor.supportsNamedProperties():
|
if descriptor.supportsNamedProperties():
|
||||||
methodDecls.append(
|
self.methodDecls.append(
|
||||||
CGNativeMember(
|
CGNativeMember(
|
||||||
descriptor, FakeMember(),
|
descriptor, FakeMember(),
|
||||||
"GetSupportedNames",
|
"GetSupportedNames",
|
||||||
@ -7752,18 +7756,37 @@ class CGExampleClass(CGClass):
|
|||||||
|
|
||||||
wrapArgs = [Argument('JSContext*', 'aCx'),
|
wrapArgs = [Argument('JSContext*', 'aCx'),
|
||||||
Argument('JSObject*', 'aScope')]
|
Argument('JSObject*', 'aScope')]
|
||||||
methodDecls.insert(0,
|
self.methodDecls.insert(0,
|
||||||
ClassMethod("WrapObject", "JSObject*",
|
ClassMethod("WrapObject", "JSObject*",
|
||||||
wrapArgs, virtual=descriptor.wrapperCache,
|
wrapArgs, virtual=descriptor.wrapperCache,
|
||||||
breakAfterReturnDecl=" "))
|
breakAfterReturnDecl=" ",
|
||||||
getParentObjectReturnType = (
|
body=self.getWrapObjectBody()))
|
||||||
"// TODO: return something sensible here, and change the return type\n"
|
self.methodDecls.insert(0,
|
||||||
"%s*" % descriptor.name)
|
ClassMethod("GetParentObject",
|
||||||
methodDecls.insert(0,
|
self.getGetParentObjectReturnType(),
|
||||||
ClassMethod("GetParentObject",
|
[], const=True,
|
||||||
getParentObjectReturnType,
|
breakAfterReturnDecl=" ",
|
||||||
[], const=True,
|
body=self.getGetParentObjectBody()))
|
||||||
breakAfterReturnDecl=" "))
|
|
||||||
|
# Invoke CGClass.__init__ in any subclasses afterwards to do the actual codegen.
|
||||||
|
|
||||||
|
def getWrapObjectBody(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def getGetParentObjectReturnType(self):
|
||||||
|
return ("// TODO: return something sensible here, and change the return type\n"
|
||||||
|
"%s*" % self.descriptor.name)
|
||||||
|
|
||||||
|
def getGetParentObjectBody(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
class CGExampleClass(CGBindingImplClass):
|
||||||
|
"""
|
||||||
|
Codegen for the actual example class implementation for this descriptor
|
||||||
|
"""
|
||||||
|
def __init__(self, descriptor):
|
||||||
|
CGBindingImplClass.__init__(self, descriptor, CGExampleMethod, CGExampleGetter, CGExampleSetter)
|
||||||
|
|
||||||
extradeclarations=(
|
extradeclarations=(
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n"
|
" NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n"
|
||||||
@ -7776,7 +7799,7 @@ class CGExampleClass(CGClass):
|
|||||||
constructors=[ClassConstructor([],
|
constructors=[ClassConstructor([],
|
||||||
visibility="public")],
|
visibility="public")],
|
||||||
destructor=ClassDestructor(visibility="public"),
|
destructor=ClassDestructor(visibility="public"),
|
||||||
methods=methodDecls,
|
methods=self.methodDecls,
|
||||||
decorators="MOZ_FINAL",
|
decorators="MOZ_FINAL",
|
||||||
extradeclarations=extradeclarations)
|
extradeclarations=extradeclarations)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user