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. 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):
@ -5008,9 +5012,8 @@ 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}',
@ -5077,9 +5080,7 @@ class CGBindingRoot(CGThing):
'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)
@ -5988,24 +5989,11 @@ class GlobalGenRoots():
@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):
@ -6138,8 +6126,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)
@ -6163,7 +6153,7 @@ 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',
@ -6189,7 +6179,8 @@ class GlobalGenRoots():
'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)