auto merge of #1883 : Ms2ger/servo/cleanup-codegen, r=jdm

This commit is contained in:
bors-servo 2014-03-11 10:10:54 -04:00
commit d004e43331
4 changed files with 161 additions and 270 deletions

View file

@ -301,7 +301,7 @@ $(AUTOGEN_SRC_script): $(BINDINGS_SRC)/%Binding.rs: $(bindinggen_dependencies) \
$(Q) $(CFG_PYTHON2) $(BINDINGS_SRC)/pythonpath.py \ $(Q) $(CFG_PYTHON2) $(BINDINGS_SRC)/pythonpath.py \
-I$(BINDINGS_SRC)/parser -I$(BINDINGS_SRC)/ply \ -I$(BINDINGS_SRC)/parser -I$(BINDINGS_SRC)/ply \
-D$(BINDINGS_SRC) \ -D$(BINDINGS_SRC) \
$(BINDINGS_SRC)/BindingGen.py rs \ $(BINDINGS_SRC)/BindingGen.py \
$(BINDINGS_SRC)/Bindings.conf $*Binding $(addprefix $(WEBIDLS_SRC)/, $*.webidl) $(BINDINGS_SRC)/Bindings.conf $*Binding $(addprefix $(WEBIDLS_SRC)/, $*.webidl)
$(Q)touch $@ $(Q)touch $@

View file

@ -10,30 +10,6 @@ import cPickle
import WebIDL import WebIDL
from Configuration import * from Configuration import *
from CodegenRust import CGBindingRoot, replaceFileIfChanged from CodegenRust import CGBindingRoot, replaceFileIfChanged
# import Codegen in general, so we can set a variable on it
import Codegen
def generate_binding_header(config, outputprefix, webidlfile):
"""
|config| Is the configuration object.
|outputprefix| is a prefix to use for the header guards and filename.
"""
filename = outputprefix + ".h"
root = CGBindingRoot(config, outputprefix, webidlfile)
if replaceFileIfChanged(filename, root.declare()):
print "Generating binding header: %s" % (filename)
def generate_binding_cpp(config, outputprefix, webidlfile):
"""
|config| Is the configuration object.
|outputprefix| is a prefix to use for the header guards and filename.
"""
filename = outputprefix + ".cpp"
root = CGBindingRoot(config, outputprefix, webidlfile)
if replaceFileIfChanged(filename, root.define()):
print "Generating binding implementation: %s" % (filename)
def generate_binding_rs(config, outputprefix, webidlfile): def generate_binding_rs(config, outputprefix, webidlfile):
""" """
@ -45,25 +21,22 @@ def generate_binding_rs(config, outputprefix, webidlfile):
root = CGBindingRoot(config, outputprefix, webidlfile) root = CGBindingRoot(config, outputprefix, webidlfile)
root2 = CGBindingRoot(config, outputprefix, webidlfile) root2 = CGBindingRoot(config, outputprefix, webidlfile)
if replaceFileIfChanged(filename, root.declare() + root2.define()): if replaceFileIfChanged(filename, root.declare() + root2.define()):
#if replaceFileIfChanged(filename, root.declare()):
print "Generating binding implementation: %s" % (filename) print "Generating binding implementation: %s" % (filename)
def main(): def main():
# Parse arguments. # Parse arguments.
from optparse import OptionParser from optparse import OptionParser
usagestring = "usage: %prog [header|cpp] configFile outputPrefix webIDLFile" usagestring = "usage: %prog configFile outputPrefix webIDLFile"
o = OptionParser(usage=usagestring) o = OptionParser(usage=usagestring)
o.add_option("--verbose-errors", action='store_true', default=False, o.add_option("--verbose-errors", action='store_true', default=False,
help="When an error happens, display the Python traceback.") help="When an error happens, display the Python traceback.")
(options, args) = o.parse_args() (options, args) = o.parse_args()
if len(args) != 4 or (args[0] != "header" and args[0] != "cpp" and args[0] != "rs"): if len(args) != 3:
o.error(usagestring) o.error(usagestring)
buildTarget = args[0] configFile = os.path.normpath(args[0])
configFile = os.path.normpath(args[1]) outputPrefix = args[1]
outputPrefix = args[2] webIDLFile = os.path.normpath(args[2])
webIDLFile = os.path.normpath(args[3])
# Load the parsing results # Load the parsing results
f = open('ParserResults.pkl', 'rb') f = open('ParserResults.pkl', 'rb')
@ -74,14 +47,7 @@ def main():
config = Configuration(configFile, parserData) config = Configuration(configFile, parserData)
# Generate the prototype classes. # Generate the prototype classes.
if buildTarget == "header": generate_binding_rs(config, outputPrefix, webIDLFile);
generate_binding_header(config, outputPrefix, webIDLFile);
elif buildTarget == "cpp":
generate_binding_cpp(config, outputPrefix, webIDLFile);
elif buildTarget == "rs":
generate_binding_rs(config, outputPrefix, webIDLFile);
else:
assert False # not reached
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1880,25 +1880,29 @@ class CGImports(CGWrapper):
""" """
Generates the appropriate import/use statements. Generates the appropriate import/use statements.
""" """
def __init__(self, descriptors, dictionaries, declareImports, defineImports, child): def __init__(self, child, imports):
""" """
Builds a set of imports to cover |descriptors|. Adds a set of imports.
Also includes the files in |declareIncludes| in the header
file and the files in |defineIncludes| in the .cpp.
""" """
ignored_warnings = [
# Allow unreachable_code because we use 'break' in a way that
# sometimes produces two 'break's in a row. See for example
# CallbackMember.getArgConversions.
'unreachable_code',
'non_uppercase_statics',
'unused_imports',
'unused_variable',
'unused_unsafe',
'unused_mut',
'dead_assignment',
'dead_code',
]
# TODO imports to cover descriptors, etc. statements = ['#[allow(%s)];' % ','.join(ignored_warnings)]
statements.extend('use %s;' % i for i in sorted(imports))
def _useString(imports):
# Allow unreachable_code because we use 'break' in a way that sometimes produces
# two 'break's in a row. See for example CallbackMember.getArgConversions.
return '\n'.join([
'#[allow(unreachable_code,non_uppercase_statics,unused_imports,unused_variable,unused_unsafe,unused_mut,dead_assignment,dead_code)];',
''.join('use %s;\n' % i for i in imports),
''])
CGWrapper.__init__(self, child, CGWrapper.__init__(self, child,
declarePre=_useString(sorted(declareImports))) declarePre='\n'.join(statements) + '\n\n')
@staticmethod @staticmethod
def getDeclarationFilename(decl): def getDeclarationFilename(decl):
@ -2244,14 +2248,11 @@ class CGAbstractMethod(CGThing):
alwaysInline should be True to generate an inline method annotated with alwaysInline should be True to generate an inline method annotated with
MOZ_ALWAYS_INLINE. MOZ_ALWAYS_INLINE.
static should be True to generate a static method, which only has
a definition.
If templateArgs is not None it should be a list of strings containing If templateArgs is not None it should be a list of strings containing
template arguments, and the function will be templatized using those template arguments, and the function will be templatized using those
arguments. arguments.
""" """
def __init__(self, descriptor, name, returnType, args, inline=False, alwaysInline=False, static=False, extern=False, pub=False, templateArgs=None, unsafe=True): def __init__(self, descriptor, name, returnType, args, inline=False, alwaysInline=False, extern=False, pub=False, templateArgs=None, unsafe=True):
CGThing.__init__(self) CGThing.__init__(self)
self.descriptor = descriptor self.descriptor = descriptor
self.name = name self.name = name
@ -2259,7 +2260,6 @@ class CGAbstractMethod(CGThing):
self.args = args self.args = args
self.inline = inline self.inline = inline
self.alwaysInline = alwaysInline self.alwaysInline = alwaysInline
self.static = static
self.extern = extern self.extern = extern
self.templateArgs = templateArgs self.templateArgs = templateArgs
self.pub = pub; self.pub = pub;
@ -2270,27 +2270,22 @@ class CGAbstractMethod(CGThing):
if self.templateArgs is None: if self.templateArgs is None:
return '' return ''
return '<%s>\n' % ', '.join(self.templateArgs) return '<%s>\n' % ', '.join(self.templateArgs)
def _decorators(self): def _decorators(self):
decorators = [] decorators = []
if self.alwaysInline: if self.alwaysInline:
decorators.append('#[inline(always)]') decorators.append('#[inline(always)]')
elif self.inline:
#decorators.append('inline')
pass
if self.extern: if self.extern:
decorators.append('extern') decorators.append('extern')
if not self.extern:
pass
if self.static:
#decorators.append('static')
pass
if self.pub: if self.pub:
decorators.append('pub') decorators.append('pub')
if not decorators: if not decorators:
return '' return ''
#maybeNewline = " " if self.inline else "\n" return ' '.join(decorators) + ' '
maybeNewline = " "
return ' '.join(decorators) + maybeNewline
def _returnType(self): def _returnType(self):
return (" -> %s" % self.returnType) if self.returnType != "void" else "" return (" -> %s" % self.returnType) if self.returnType != "void" else ""
def _unsafe_open(self): def _unsafe_open(self):
@ -2539,7 +2534,7 @@ class CGGetPerInterfaceObject(CGAbstractMethod):
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aGlobal'), args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aGlobal'),
Argument('*JSObject', 'aReceiver')] Argument('*JSObject', 'aReceiver')]
CGAbstractMethod.__init__(self, descriptor, name, CGAbstractMethod.__init__(self, descriptor, name,
'*JSObject', args, inline=True, pub=pub) '*JSObject', args, pub=pub)
self.id = idPrefix + "id::" + self.descriptor.name self.id = idPrefix + "id::" + self.descriptor.name
def definition_body(self): def definition_body(self):
return """ return """
@ -2989,18 +2984,6 @@ class CGGenericMethod(CGAbstractBindingMethod):
"let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n" "let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n"
"return CallJitMethodOp(_info, cx, obj, this as *libc::c_void, argc, &*vp);")) "return CallJitMethodOp(_info, cx, obj, this as *libc::c_void, argc, &*vp);"))
class CGAbstractStaticMethod(CGAbstractMethod):
"""
Abstract base class for codegen of implementation-only (no
declaration) static methods.
"""
def __init__(self, descriptor, name, returnType, args):
CGAbstractMethod.__init__(self, descriptor, name, returnType, args,
inline=False, static=True)
def declare(self):
# We only have implementation
return ""
class CGSpecializedMethod(CGAbstractExternMethod): class CGSpecializedMethod(CGAbstractExternMethod):
""" """
A class for generating the C++ code for a specialized method that the JIT A class for generating the C++ code for a specialized method that the JIT
@ -4560,6 +4543,11 @@ class CGDescriptor(CGThing):
assert not descriptor.concrete or descriptor.interface.hasInterfacePrototypeObject() assert not descriptor.concrete or descriptor.interface.hasInterfacePrototypeObject()
cgThings = [] cgThings = []
if descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGGetProtoObjectMethod(descriptor))
else:
cgThings.append(CGGetConstructorObjectMethod(descriptor))
if descriptor.interface.hasInterfacePrototypeObject(): if descriptor.interface.hasInterfacePrototypeObject():
(hasMethod, hasGetter, hasLenientGetter, (hasMethod, hasGetter, hasLenientGetter,
hasSetter, hasLenientSetter) = False, False, False, False, False hasSetter, hasLenientSetter) = False, False, False, False, False
@ -4603,10 +4591,6 @@ class CGDescriptor(CGThing):
properties = PropertyArrays(descriptor) properties = PropertyArrays(descriptor)
cgThings.append(CGGeneric(define=str(properties))) cgThings.append(CGGeneric(define=str(properties)))
cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties)) cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties))
if descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGGetProtoObjectMethod(descriptor))
else:
cgThings.append(CGGetConstructorObjectMethod(descriptor))
# Set up our Xray callbacks as needed. # Set up our Xray callbacks as needed.
if descriptor.interface.hasInterfacePrototypeObject(): if descriptor.interface.hasInterfacePrototypeObject():
@ -4648,7 +4632,7 @@ class CGDescriptor(CGThing):
cgThings.append(CGWrapMethod(descriptor)) cgThings.append(CGWrapMethod(descriptor))
cgThings = CGList((CGIndenter(t, declareOnly=True) for t in cgThings), "\n") cgThings = CGList(cgThings, "\n")
cgThings = CGWrapper(cgThings, pre='\n', post='\n') cgThings = CGWrapper(cgThings, pre='\n', post='\n')
#self.cgRoot = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name), #self.cgRoot = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name),
# cgThings), # cgThings),
@ -5029,78 +5013,75 @@ class CGBindingRoot(CGThing):
# Add imports # Add imports
#XXXjdm This should only import the namespace for the current binding, #XXXjdm This should only import the namespace for the current binding,
# not every binding ever. # not every binding ever.
curr = CGImports(descriptors, curr = CGImports(curr, [
dictionaries, 'js::{crust, JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}',
['js::{crust, JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}', 'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS}',
'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS}', 'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}',
'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}', 'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}',
'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}', 'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}',
'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}', 'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED}',
'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED}', 'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}',
'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}', 'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}', 'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}', 'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_IsExceptionPending}',
'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_IsExceptionPending}', 'js::jsapi::{JS_NewObject, JS_ObjectIsCallable, JS_SetPrototype}',
'js::jsapi::{JS_NewObject, JS_ObjectIsCallable, JS_SetPrototype}', 'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSBool, JSContext}',
'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSBool, JSContext}', 'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}',
'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}', 'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor}',
'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor}', 'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}',
'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}', 'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer}',
'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer}', 'js::jsval::JSVal',
'js::jsval::JSVal', 'js::jsval::{ObjectValue, ObjectOrNullValue, PrivateValue}',
'js::jsval::{ObjectValue, ObjectOrNullValue, PrivateValue}', 'js::jsval::{NullValue, UndefinedValue}',
'js::jsval::{NullValue, UndefinedValue}', 'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}',
'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}', 'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}', 'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}',
'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}', 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'dom::types::*',
'dom::types::*', 'dom::bindings::js::JS',
'dom::bindings::js::JS', 'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}', 'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}', 'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}',
'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}', 'dom::bindings::utils::{DOMJSClass}',
'dom::bindings::utils::{DOMJSClass}', 'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}',
'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}', 'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}',
'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}', 'dom::bindings::utils::{GetReflector, HasPropertyOnPrototype, IntVal}',
'dom::bindings::utils::{GetReflector, HasPropertyOnPrototype, IntVal}', 'dom::bindings::utils::{jsid_to_str}',
'dom::bindings::utils::{jsid_to_str}', 'dom::bindings::utils::{NativePropertyHooks}',
'dom::bindings::utils::{NativePropertyHooks}', 'dom::bindings::utils::global_object_for_js_object',
'dom::bindings::utils::global_object_for_js_object', 'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{Reflectable}', 'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{squirrel_away_unique}', 'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}', 'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}',
'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}', 'dom::bindings::utils::{with_gc_enabled, XrayResolveProperty}',
'dom::bindings::utils::{with_gc_enabled, XrayResolveProperty}', 'dom::bindings::trace::Traceable',
'dom::bindings::trace::Traceable', 'dom::bindings::callback::{CallbackContainer,CallbackInterface}',
'dom::bindings::callback::{CallbackContainer,CallbackInterface}', 'dom::bindings::callback::{CallSetup,ExceptionHandling}',
'dom::bindings::callback::{CallSetup,ExceptionHandling}', 'dom::bindings::callback::{WrapCallThisObject}',
'dom::bindings::callback::{WrapCallThisObject}', 'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}',
'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}', 'dom::bindings::conversions::{Default, Empty}',
'dom::bindings::conversions::{Default, Empty}', 'dom::bindings::codegen::*',
'dom::bindings::codegen::*', 'dom::bindings::codegen::UnionTypes::*',
'dom::bindings::codegen::UnionTypes::*', 'dom::bindings::codegen::UnionConversions::*',
'dom::bindings::codegen::UnionConversions::*', 'dom::bindings::error::{FailureUnknown, Fallible, Error, ErrorResult}',
'dom::bindings::error::{FailureUnknown, Fallible, Error, ErrorResult}', 'dom::bindings::error::{throw_method_failed_with_details}',
'dom::bindings::error::{throw_method_failed_with_details}', 'dom::bindings::error::{throw_not_in_union}',
'dom::bindings::error::{throw_not_in_union}', 'script_task::JSPageInfo',
'script_task::JSPageInfo', 'dom::bindings::proxyhandler',
'dom::bindings::proxyhandler', 'dom::bindings::proxyhandler::{_obj_toString, defineProperty}',
'dom::bindings::proxyhandler::{_obj_toString, defineProperty}', 'dom::bindings::proxyhandler::{FillPropertyDescriptor, GetExpandoObject}',
'dom::bindings::proxyhandler::{FillPropertyDescriptor, GetExpandoObject}', 'dom::bindings::proxyhandler::{getPropertyDescriptor}',
'dom::bindings::proxyhandler::{getPropertyDescriptor}', 'servo_util::str::DOMString',
'servo_util::str::DOMString', 'servo_util::vec::zip_copies',
'servo_util::vec::zip_copies', 'std::cast',
'std::cast', 'std::libc',
'std::libc', 'std::ptr',
'std::ptr', 'std::vec',
'std::vec', 'std::str',
'std::str', 'std::num',
'std::num', 'std::unstable::intrinsics::uninit',
'std::unstable::intrinsics::uninit', 'std::unstable::raw::Box',
'std::unstable::raw::Box', ])
],
[],
curr)
# Add the auto-generated comment. # Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@ -5997,74 +5978,23 @@ class GlobalGenRoots():
@staticmethod @staticmethod
def PrototypeList(config): def PrototypeList(config):
# Prototype ID enum. # Prototype ID enum.
protos = [d.name for d in config.getDescriptors(hasInterfacePrototypeObject=True)] protos = [d.name for d in config.getDescriptors(hasInterfacePrototypeObject=True)]
idEnum = CGNamespacedEnum('id', 'ID', protos, [0], deriving="Eq") return CGList([
idEnum = CGList([idEnum]) CGGeneric(AUTOGENERATED_WARNING_COMMENT),
idEnum.append(CGGeneric(declare="pub static MAX_PROTO_CHAIN_LENGTH: uint = " + CGGeneric("pub static MAX_PROTO_CHAIN_LENGTH: uint = %d;\n\n" % config.maxProtoChainLength),
str(config.maxProtoChainLength) + ";\n\n")) CGNamespacedEnum('id', 'ID', protos, [0], deriving="Eq"),
])
# Wrap all of that in our namespaces.
#idEnum = CGNamespace.build(['mozilla', 'dom', 'prototypes'],
# CGWrapper(idEnum, pre='\n'))
#idEnum = CGWrapper(idEnum, post='\n')
curr = CGList([idEnum])
# Constructor ID enum.
constructors = [d.name for d in config.getDescriptors(hasInterfaceObject=True,
hasInterfacePrototypeObject=False)]
idEnum = CGNamespacedEnum('id', 'ID', constructors, [0])
# Wrap all of that in our namespaces.
idEnum = CGNamespace.build(['mozilla', 'dom', 'constructors'],
CGWrapper(idEnum, pre='\n'))
idEnum = CGWrapper(idEnum, post='\n')
#XXXjdm Not sure what to do with the constructors right now
#curr.append(idEnum)
#traitsDecl = CGGeneric(declare="""
#template <prototypes::ID PrototypeID>
#struct PrototypeTraits;
#
#template <class ConcreteClass>
#struct PrototypeIDMap;
#""")
#traitsDecl = CGNamespace.build(['mozilla', 'dom'],
# CGWrapper(traitsDecl, post='\n'))
#curr.append(traitsDecl)
# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
# Done.
return curr
@staticmethod @staticmethod
def RegisterBindings(config): def RegisterBindings(config):
# TODO - Generate the methods we want # TODO - Generate the methods we want
curr = CGRegisterProtos(config) return CGImports(CGRegisterProtos(config), [
'dom::bindings::codegen',
# Wrap all of that in our namespaces. 'script_task::JSPageInfo',
#curr = CGNamespace.build(['mozilla', 'dom'], ])
# CGWrapper(curr, post='\n'))
#curr = CGWrapper(curr, post='\n')
# Add the includes
defineIncludes = [CGImports.getDeclarationFilename(desc.interface)
for desc in config.getDescriptors(hasInterfaceObject=True,
register=True)]
curr = CGImports([], [], ['dom::bindings::codegen',
'script_task::JSPageInfo'], defineIncludes, curr)
# Done.
return curr
@staticmethod @staticmethod
def InterfaceTypes(config): def InterfaceTypes(config):
@ -6197,8 +6127,10 @@ class GlobalGenRoots():
# Add include guards. # Add include guards.
#curr = CGIncludeGuard('UnionTypes', curr) #curr = CGIncludeGuard('UnionTypes', curr)
curr = CGImports([], [], ['dom::bindings::js::JS', curr = CGImports(curr, [
'dom::types::*'], [], curr) 'dom::bindings::js::JS',
'dom::types::*',
])
# Add the auto-generated comment. # Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@ -6222,33 +6154,34 @@ class GlobalGenRoots():
# Add include guards. # Add include guards.
#curr = CGIncludeGuard('UnionConversions', curr) #curr = CGIncludeGuard('UnionConversions', curr)
curr = CGImports([], [], [ curr = CGImports(curr, [
'dom::bindings::utils::unwrap_jsmanaged', 'dom::bindings::utils::unwrap_jsmanaged',
'dom::bindings::codegen::UnionTypes::*', 'dom::bindings::codegen::UnionTypes::*',
'dom::bindings::codegen::PrototypeList', 'dom::bindings::codegen::PrototypeList',
'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}', 'dom::bindings::conversions::{FromJSValConvertible, ToJSValConvertible}',
'js::{crust, JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}', 'js::{crust, JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}',
'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS}', 'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS}',
'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}', 'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}',
'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}', 'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}',
'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}', 'js::{JSPROP_ENUMERATE, JSPROP_NATIVE_ACCESSORS, JSPROP_SHARED}',
'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED}', 'js::{JSRESOLVE_ASSIGNING, JSRESOLVE_QUALIFIED}',
'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}', 'js::jsapi::{JS_CallFunctionValue, JS_GetClass, JS_GetGlobalForObject}',
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}', 'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}', 'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_IsExceptionPending}', 'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_IsExceptionPending}',
'js::jsapi::{JS_NewObject, JS_ObjectIsCallable, JS_SetPrototype}', 'js::jsapi::{JS_NewObject, JS_ObjectIsCallable, JS_SetPrototype}',
'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSBool, JSContext}', 'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSBool, JSContext}',
'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}', 'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}',
'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor}', 'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor}',
'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}', 'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec}',
'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer}', 'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer}',
'js::jsval::JSVal', 'js::jsval::JSVal',
'js::jsval::PrivateValue', 'js::jsval::PrivateValue',
'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}', 'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}',
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}', 'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}', 'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}',
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',], [], curr) 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
])
# Add the auto-generated comment. # Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT) curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)

View file

@ -17,21 +17,13 @@ from CodegenRust import GlobalGenRoots, replaceFileIfChanged
# import Codegen in general, so we can set a variable on it # import Codegen in general, so we can set a variable on it
import Codegen import Codegen
def generate_file(config, name, action): def generate_file(config, name):
filename = name + '.rs'
root = getattr(GlobalGenRoots, name)(config) root = getattr(GlobalGenRoots, name)(config)
if action is 'declare': code = root.declare()
filename = name + '.rs' root2 = getattr(GlobalGenRoots, name)(config)
code = root.declare() code += root2.define()
elif action == 'declare+define':
filename = name + '.rs'
code = root.declare()
root2 = getattr(GlobalGenRoots, name)(config)
code += root2.define()
else:
assert action is 'define'
filename = name + '.rs'
code = root.define()
if replaceFileIfChanged(filename, code): if replaceFileIfChanged(filename, code):
print "Generating %s" % (filename) print "Generating %s" % (filename)
@ -75,22 +67,22 @@ def main():
config = Configuration(configFile, parserResults) config = Configuration(configFile, parserResults)
# Generate the prototype list. # Generate the prototype list.
generate_file(config, 'PrototypeList', 'declare+define') generate_file(config, 'PrototypeList')
# Generate the common code. # Generate the common code.
generate_file(config, 'RegisterBindings', 'declare+define') generate_file(config, 'RegisterBindings')
# Generate the type list. # Generate the type list.
generate_file(config, 'InterfaceTypes', 'declare+define') generate_file(config, 'InterfaceTypes')
# Generate the type list. # Generate the type list.
generate_file(config, 'InheritTypes', 'declare+define') generate_file(config, 'InheritTypes')
# Generate the module declarations. # Generate the module declarations.
generate_file(config, 'BindingDeclarations', 'declare+define') generate_file(config, 'BindingDeclarations')
generate_file(config, 'UnionTypes', 'declare+define') generate_file(config, 'UnionTypes')
generate_file(config, 'UnionConversions', 'declare+define') generate_file(config, 'UnionConversions')
if __name__ == '__main__': if __name__ == '__main__':
main() main()