def todo(self, formatstring):
self.dprint(("// %s " % Compiler.TODOSTR) +formatstring)
- def prepare(self):
+ def prepare(self, module):
self.ctx = dict()
+ self.ctx['interfaces'] = dict()
self.ctx['modules'] = []
self.ctx['implementedObject'] = None
- self.ctx['implementedClass'] = None
+ self.ctx['implementedClass'] = []
self.ctx['export'] = dict()
self.ctx['callback'] = dict()
self.ctx['dictionary'] = dict()
self.ctx['Tizen'] = []
self.ctx['Window'] = []
self.ctx['cmdtable'] = dict()
+ self.ctx['exportModule'] = module
self.q = Queue()
for m in self.tree:
for iface in m.getTypes('Interface'):
- if iface.inherit in [x.name for x in self.ctx['exportedInterface']]:
- iface.exported = True
- if iface.name in self.ctx['callback']:
- iface.isListener = True
+ #if iface.inherit in [x.name for x in self.ctx['exportedInterface']]:
+ # iface.exported = True
+ #if iface.name in self.ctx['callback']:
+ #iface.isListener = True
for operation in iface.getTypes('Operation'):
if hasattr(iface, 'exported') and iface.exported:
operation.native_cmd = iface.name+'_'+operation.name
operation.native_function = iface.name+(operation.name.title())
self.ctx['cmdtable'][operation.native_function] = operation.native_cmd
operation.argnames = [a.name for a in operation.arguments]
- operation.primitiveArgs = [x for x in operation.arguments if not x.optional and x.xtype.name in cppPrimitiveMap]
+ operation.primitiveArgs = [x for x in operation.arguments if x.xtype.name in cppPrimitiveMap]
for arg in operation.arguments:
if arg.xtype.name in self.ctx['enum']:
arg.isEnum = True
arg.enums = reduce(lambda x,y: x+y, [ self.ctx['enum'][x] for x in self.ctx['enum'] if x in union_names])
arg.isTypes = reduce(lambda x, y: x & y, [ x in m.getTypes('Interface') for x in union_names])
if arg.xtype.name in self.ctx['callback']:
+ callback = self.ctx['callback'][arg.xtype.name]
+ if callback.functionOnly:
+ arg.functionOnly = True
arg.isListener = True
arg.listenerType = self.ctx['callback'][arg.xtype.name]
operation.async = True
break
def prepareX(self, x):
- if isinstance(x, WebIDL.XImplements) and (x.name in ['Tizen', 'Window']):
- self.ctx['implementedClass'] = x.impl
+ if isinstance(x, WebIDL.XImplements) and (x.name in ['Tizen', 'Window']) and x.parent.name.lower() == self.ctx['exportModule'].lower():
+ self.ctx['implementedClass'].append(x.impl)
self.ctx[x.name].append(x.impl)
impl = x.parent.get('Interface', x.impl)
impl.implements = x.name
if isinstance(x, WebIDL.XAttribute) and isinstance(x.parent, WebIDL.XInterface):
- if x.parent.name == self.ctx['implementedClass']:
+ if x.parent.name in self.ctx['implementedClass']:
self.ctx['implementedObject'] = x.name
- inheritIface = x.parent.parent.get('Interface', x.xtype.name)
+ #inheritIface = x.parent.parent.get('Interface', x.xtype.name)
+ inheritIface = self.ctx['interfaces'][x.xtype.name]
if inheritIface :
self.ctx[x.parent.implements] = inheritIface.name
inheritIface.exported = True
self.ctx['exportedInterface'].append(inheritIface)
if isinstance(x, WebIDL.XInterface):
- xattrs = [attr.name for attr in x.getTypes('ExtendedAttribute')]
- if 'Callback' in xattrs:
+ xcallback = next((a for a in x.getTypes('ExtendedAttribute') if a.name == 'Callback'), None)
+ if xcallback:
self.ctx['callback'][x.name] = x
+ x.functionOnly = xcallback and xcallback.identity == 'FunctionOnly'
+ self.ctx['interfaces'][x.name] = x;
+
+ xctor = next((c for c in x.getTypes('ExtendedAttribute') if c.name == 'Constructor'), None)
+ if xctor:
+ x.constructor = xctor
if isinstance(x, WebIDL.XOperation):
module = x.parent.parent
- if module.get('Interface', x.returnType.name):
+ #if module.get('Interface', x.returnType.name):
+ if x.returnType.name in self.ctx['interfaces']:
self.ctx['activeObjects'].add(x.returnType.name)
- inheritIface = module.get('Interface', x.returnType.name)
+ #inheritIface = module.get('Interface', x.returnType.name)
+ inheritIface = self.ctx['interfaces'][x.returnType.name]
if inheritIface :
inheritIface.exported = True
self.ctx['exportedInterface'].append(inheritIface)
TPL_API_JS = "tpl_api.js"
- def makeJSStub(self):
- self.prepare()
+ def makeJSStub(self, module):
+ self.prepare(module)
tpl = self.tplEnv.get_template(Compiler.TPL_API_JS)
- return tpl.render({'modules':self.tree,
+ modules = self.tree if module == None else [m for m in self.tree if m.name.lower() == module.lower()]
+ return tpl.render({'modules':modules,
'callbacks':self.ctx['callback'],
'tizen': self.ctx['Tizen'],
'window': self.ctx['Window'],
if __name__ == '__main__':
argv = sys.argv[1:]
try:
- opts, args = getopt.getopt(argv, "ht:d:")
+ opts, args = getopt.getopt(argv, "htm:d:")
except getopt.GetoptError:
printhelp()
sys.exit(2)
sys.exit(2)
if not moduleName:
- moduleName = args[0][args[0].find('/')+1:args[0].find('.')]
+ import os
+ basename = os.path.basename(args[0])
+ moduleName = basename[0:basename.find('.')]
- f = open(args[0])
- widl = f.read()
- f.close()
+ widl = ""
+ for arg in args:
+ f = open(arg)
+ widl += f.read()
+ f.close()
p = WebIDL.Parser()
tree = p.parse(widl)
c = Compiler(tree)
- jscode = c.makeJSStub()
+ jscode = c.makeJSStub(moduleName)
cppcode = c.makeCppStubs(moduleName)
if outDirectory:
{% for iface in module.getTypes('Interface') %}
{% if iface.exported %}
-function {{iface.name}}() {
+function {{iface.name}}(
+ {%-if iface.constructor -%}
+ {%- for arg in iface.constructor.arguments -%}
+ {{arg.name}}{%- if not loop.last %}, {% endif -%}
+ {%- endfor -%}
+ {%- endif -%}) {
// constructor of {{iface.name}}
}
{% for operation in iface.getTypes('Operation') %}
{{iface.name}}.prototype.{{operation.name}} = function(
{%- for arg in operation.arguments -%}
- {%- if not arg.optional -%}
- {%- if not loop.first %}, {% endif -%}
- {{arg.name}}
- {%- endif -%}
+ {%- if not loop.first %}, {% endif -%}
+ {{arg.name}}
{%- endfor %}) {
{% if operation.arguments %}
var args = validator_.validateArgs(arguments, [
{% for arg in operation.arguments %}
{'name' : '{{arg.name}}', 'type': types_.
- {%- if arg.isListener -%}
+ {%- if arg.functionOnly -%}
+ FUNCTION
+ {%- elif arg.isListener -%}
LISTENER, 'values' : [
{%- for listener in arg.listenerType.getTypes('Operation') -%}
'{{listener.name}}'{% if not loop.last %}, {% endif %}
{% if operation.arguments %}
var nativeParam = {
- {% for arg in operation.primitiveArgs %}
- '{{arg.name}}': args.{{arg.name}}{% if not loop.last %},{% endif %}
+ {% for arg in operation.primitiveArgs if not arg.optional %}
+ '{{arg.name}}': args.{{arg.name}}{% if not loop.last %},{% endif %}
{% endfor %}
};
- {% for arg in operation.arguments %}
- {% if arg.optional %}
+
+ {% for arg in operation.primitiveArgs if arg.optional %}
if (args['{{arg.name}}']) {
nativeParam['{{arg.name}}'] = args.{{arg.name}};
}
- {% endif %}
{% endfor %}
{% endif %}
{% set successcbs = [] %}