Cleanup and simplify CGImports.

This commit is contained in:
Ms2ger 2014-03-11 12:56:04 +01:00
parent c97408969e
commit d08ad3c243

View file

@ -1880,25 +1880,29 @@ class CGImports(CGWrapper):
"""
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|.
Also includes the files in |declareIncludes| in the header
file and the files in |defineIncludes| in the .cpp.
Adds a set of imports.
"""
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,
declarePre=_useString(sorted(declareImports)))
declarePre='\n'.join(statements) + '\n\n')
@staticmethod
def getDeclarationFilename(decl):
@ -5008,9 +5012,8 @@ class CGBindingRoot(CGThing):
# Add imports
#XXXjdm This should only import the namespace for the current binding,
# not every binding ever.
curr = CGImports(descriptors,
dictionaries,
['js::{crust, JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}',
curr = CGImports(curr, [
'js::{crust, JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}',
'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS}',
'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}',
'js::{JSCLASS_RESERVED_SLOTS_MASK, JSID_VOID, JSJitInfo}',
@ -5077,9 +5080,7 @@ class CGBindingRoot(CGThing):
'std::num',
'std::unstable::intrinsics::uninit',
'std::unstable::raw::Box',
],
[],
curr)
])
# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@ -5988,24 +5989,11 @@ class GlobalGenRoots():
@staticmethod
def RegisterBindings(config):
# TODO - Generate the methods we want
curr = CGRegisterProtos(config)
# Wrap all of that in our namespaces.
#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
return CGImports(CGRegisterProtos(config), [
'dom::bindings::codegen',
'script_task::JSPageInfo',
])
@staticmethod
def InterfaceTypes(config):
@ -6138,8 +6126,10 @@ class GlobalGenRoots():
# Add include guards.
#curr = CGIncludeGuard('UnionTypes', curr)
curr = CGImports([], [], ['dom::bindings::js::JS',
'dom::types::*'], [], curr)
curr = CGImports(curr, [
'dom::bindings::js::JS',
'dom::types::*',
])
# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@ -6163,7 +6153,7 @@ class GlobalGenRoots():
# Add include guards.
#curr = CGIncludeGuard('UnionConversions', curr)
curr = CGImports([], [], [
curr = CGImports(curr, [
'dom::bindings::utils::unwrap_jsmanaged',
'dom::bindings::codegen::UnionTypes::*',
'dom::bindings::codegen::PrototypeList',
@ -6189,7 +6179,8 @@ class GlobalGenRoots():
'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}',
'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}',
'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.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)