OLD | NEW |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import itertools | 6 import itertools |
7 import json | 7 import json |
8 import os.path | 8 import os.path |
9 import re | 9 import re |
10 import sys | 10 import sys |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 result[property_name] = True | 306 result[property_name] = True |
307 return result | 307 return result |
308 | 308 |
309 | 309 |
310 class Namespace(object): | 310 class Namespace(object): |
311 ''' | 311 ''' |
312 Given an IDLNode representing an IDL namespace, converts into a Python | 312 Given an IDLNode representing an IDL namespace, converts into a Python |
313 dictionary that the JSON schema compiler expects to see. | 313 dictionary that the JSON schema compiler expects to see. |
314 ''' | 314 ''' |
315 | 315 |
316 def __init__(self, namespace_node, description, nodoc=False, internal=False): | 316 def __init__(self, namespace_node, description, nodoc=False, internal=False, |
317 platforms=[]): | |
not at google - send to devlin
2013/10/25 17:00:08
don't set optional parameters to mutable objects,
Haojian Wu
2013/10/26 03:15:51
Done.
| |
317 self.namespace = namespace_node | 318 self.namespace = namespace_node |
318 self.nodoc = nodoc | 319 self.nodoc = nodoc |
319 self.internal = internal | 320 self.internal = internal |
321 self.platforms = platforms | |
320 self.events = [] | 322 self.events = [] |
321 self.functions = [] | 323 self.functions = [] |
322 self.types = [] | 324 self.types = [] |
323 self.callbacks = OrderedDict() | 325 self.callbacks = OrderedDict() |
324 self.description = description | 326 self.description = description |
325 | 327 |
326 def process(self): | 328 def process(self): |
327 for node in self.namespace.children: | 329 for node in self.namespace.children: |
328 if node.cls == 'Dictionary': | 330 if node.cls == 'Dictionary': |
329 self.types.append(Dictionary(node).process(self.callbacks)) | 331 self.types.append(Dictionary(node).process(self.callbacks)) |
330 elif node.cls == 'Callback': | 332 elif node.cls == 'Callback': |
331 k, v = Member(node).process(self.callbacks) | 333 k, v = Member(node).process(self.callbacks) |
332 self.callbacks[k] = v | 334 self.callbacks[k] = v |
333 elif node.cls == 'Interface' and node.GetName() == 'Functions': | 335 elif node.cls == 'Interface' and node.GetName() == 'Functions': |
334 self.functions = self.process_interface(node) | 336 self.functions = self.process_interface(node) |
335 elif node.cls == 'Interface' and node.GetName() == 'Events': | 337 elif node.cls == 'Interface' and node.GetName() == 'Events': |
336 self.events = self.process_interface(node) | 338 self.events = self.process_interface(node) |
337 elif node.cls == 'Enum': | 339 elif node.cls == 'Enum': |
338 self.types.append(Enum(node).process(self.callbacks)) | 340 self.types.append(Enum(node).process(self.callbacks)) |
339 else: | 341 else: |
340 sys.exit('Did not process %s %s' % (node.cls, node)) | 342 sys.exit('Did not process %s %s' % (node.cls, node)) |
341 return {'namespace': self.namespace.GetName(), | 343 return {'namespace': self.namespace.GetName(), |
342 'description': self.description, | 344 'description': self.description, |
343 'nodoc': self.nodoc, | 345 'nodoc': self.nodoc, |
344 'types': self.types, | 346 'types': self.types, |
345 'functions': self.functions, | 347 'functions': self.functions, |
346 'internal': self.internal, | 348 'internal': self.internal, |
347 'events': self.events} | 349 'events': self.events, |
350 'platforms': self.platforms} | |
348 | 351 |
349 def process_interface(self, node): | 352 def process_interface(self, node): |
350 members = [] | 353 members = [] |
351 for member in node.children: | 354 for member in node.children: |
352 if member.cls == 'Member': | 355 if member.cls == 'Member': |
353 name, properties = Member(member).process(self.callbacks) | 356 name, properties = Member(member).process(self.callbacks) |
354 members.append(properties) | 357 members.append(properties) |
355 return members | 358 return members |
356 | 359 |
357 | 360 |
358 class IDLSchema(object): | 361 class IDLSchema(object): |
359 ''' | 362 ''' |
360 Given a list of IDLNodes and IDLAttributes, converts into a Python list | 363 Given a list of IDLNodes and IDLAttributes, converts into a Python list |
361 of api_defs that the JSON schema compiler expects to see. | 364 of api_defs that the JSON schema compiler expects to see. |
362 ''' | 365 ''' |
363 | 366 |
364 def __init__(self, idl): | 367 def __init__(self, idl): |
365 self.idl = idl | 368 self.idl = idl |
366 | 369 |
367 def process(self): | 370 def process(self): |
368 namespaces = [] | 371 namespaces = [] |
369 nodoc = False | 372 nodoc = False |
370 internal = False | 373 internal = False |
371 description = None | 374 description = None |
375 platforms = [] | |
not at google - send to devlin
2013/10/25 17:00:08
None
Haojian Wu
2013/10/26 03:15:51
Done.
| |
372 for node in self.idl: | 376 for node in self.idl: |
373 if node.cls == 'Namespace': | 377 if node.cls == 'Namespace': |
374 if not description: | 378 if not description: |
375 # TODO(kalman): Go back to throwing an error here. | 379 # TODO(kalman): Go back to throwing an error here. |
376 print('%s must have a namespace-level comment. This will ' | 380 print('%s must have a namespace-level comment. This will ' |
377 'appear on the API summary page.' % node.GetName()) | 381 'appear on the API summary page.' % node.GetName()) |
378 description = '' | 382 description = '' |
379 namespace = Namespace(node, description, nodoc, internal) | 383 namespace = Namespace(node, description, nodoc, internal, platforms) |
380 namespaces.append(namespace.process()) | 384 namespaces.append(namespace.process()) |
381 nodoc = False | 385 nodoc = False |
382 internal = False | 386 internal = False |
not at google - send to devlin
2013/10/25 17:00:08
platforms = None here?
Haojian Wu
2013/10/26 03:15:51
Done. I forget to reset it here.
| |
383 elif node.cls == 'Copyright': | 387 elif node.cls == 'Copyright': |
384 continue | 388 continue |
385 elif node.cls == 'Comment': | 389 elif node.cls == 'Comment': |
386 description = node.GetName() | 390 description = node.GetName() |
387 elif node.cls == 'ExtAttribute': | 391 elif node.cls == 'ExtAttribute': |
388 if node.name == 'nodoc': | 392 if node.name == 'nodoc': |
389 nodoc = bool(node.value) | 393 nodoc = bool(node.value) |
390 elif node.name == 'internal': | 394 elif node.name == 'internal': |
391 internal = bool(node.value) | 395 internal = bool(node.value) |
396 elif node.name == 'platforms': | |
397 platforms = list(node.value) | |
392 else: | 398 else: |
393 continue | 399 continue |
394 else: | 400 else: |
395 sys.exit('Did not process %s %s' % (node.cls, node)) | 401 sys.exit('Did not process %s %s' % (node.cls, node)) |
396 return namespaces | 402 return namespaces |
397 | 403 |
398 | 404 |
399 def Load(filename): | 405 def Load(filename): |
400 ''' | 406 ''' |
401 Given the filename of an IDL file, parses it and returns an equivalent | 407 Given the filename of an IDL file, parses it and returns an equivalent |
(...skipping 14 matching lines...) Expand all Loading... | |
416 Dump a json serialization of parse result for the IDL files whose names | 422 Dump a json serialization of parse result for the IDL files whose names |
417 were passed in on the command line. | 423 were passed in on the command line. |
418 ''' | 424 ''' |
419 for filename in sys.argv[1:]: | 425 for filename in sys.argv[1:]: |
420 schema = Load(filename) | 426 schema = Load(filename) |
421 print json.dumps(schema, indent=2) | 427 print json.dumps(schema, indent=2) |
422 | 428 |
423 | 429 |
424 if __name__ == '__main__': | 430 if __name__ == '__main__': |
425 Main() | 431 Main() |
OLD | NEW |