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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ''' | 317 ''' |
318 Given an IDLNode representing an IDL namespace, converts into a Python | 318 Given an IDLNode representing an IDL namespace, converts into a Python |
319 dictionary that the JSON schema compiler expects to see. | 319 dictionary that the JSON schema compiler expects to see. |
320 ''' | 320 ''' |
321 | 321 |
322 def __init__(self, | 322 def __init__(self, |
323 namespace_node, | 323 namespace_node, |
324 description, | 324 description, |
325 nodoc=False, | 325 nodoc=False, |
326 internal=False, | 326 internal=False, |
327 platforms=None): | 327 platforms=None, |
| 328 compiler_options=None): |
328 self.namespace = namespace_node | 329 self.namespace = namespace_node |
329 self.nodoc = nodoc | 330 self.nodoc = nodoc |
330 self.internal = internal | 331 self.internal = internal |
331 self.platforms = platforms | 332 self.platforms = platforms |
| 333 self.compiler_options = compiler_options |
332 self.events = [] | 334 self.events = [] |
333 self.functions = [] | 335 self.functions = [] |
334 self.types = [] | 336 self.types = [] |
335 self.callbacks = OrderedDict() | 337 self.callbacks = OrderedDict() |
336 self.description = description | 338 self.description = description |
337 | 339 |
338 def process(self): | 340 def process(self): |
339 for node in self.namespace.children: | 341 for node in self.namespace.children: |
340 if node.cls == 'Dictionary': | 342 if node.cls == 'Dictionary': |
341 self.types.append(Dictionary(node).process(self.callbacks)) | 343 self.types.append(Dictionary(node).process(self.callbacks)) |
342 elif node.cls == 'Callback': | 344 elif node.cls == 'Callback': |
343 k, v = Member(node).process(self.callbacks) | 345 k, v = Member(node).process(self.callbacks) |
344 self.callbacks[k] = v | 346 self.callbacks[k] = v |
345 elif node.cls == 'Interface' and node.GetName() == 'Functions': | 347 elif node.cls == 'Interface' and node.GetName() == 'Functions': |
346 self.functions = self.process_interface(node) | 348 self.functions = self.process_interface(node) |
347 elif node.cls == 'Interface' and node.GetName() == 'Events': | 349 elif node.cls == 'Interface' and node.GetName() == 'Events': |
348 self.events = self.process_interface(node) | 350 self.events = self.process_interface(node) |
349 elif node.cls == 'Enum': | 351 elif node.cls == 'Enum': |
350 self.types.append(Enum(node).process(self.callbacks)) | 352 self.types.append(Enum(node).process(self.callbacks)) |
351 else: | 353 else: |
352 sys.exit('Did not process %s %s' % (node.cls, node)) | 354 sys.exit('Did not process %s %s' % (node.cls, node)) |
| 355 if self.compiler_options is not None: |
| 356 compiler_options = self.compiler_options |
| 357 else: |
| 358 compiler_options = {} |
353 return {'namespace': self.namespace.GetName(), | 359 return {'namespace': self.namespace.GetName(), |
354 'description': self.description, | 360 'description': self.description, |
355 'nodoc': self.nodoc, | 361 'nodoc': self.nodoc, |
356 'types': self.types, | 362 'types': self.types, |
357 'functions': self.functions, | 363 'functions': self.functions, |
358 'internal': self.internal, | 364 'internal': self.internal, |
359 'events': self.events, | 365 'events': self.events, |
360 'platforms': self.platforms} | 366 'platforms': self.platforms, |
| 367 'compiler_options': compiler_options} |
361 | 368 |
362 def process_interface(self, node): | 369 def process_interface(self, node): |
363 members = [] | 370 members = [] |
364 for member in node.children: | 371 for member in node.children: |
365 if member.cls == 'Member': | 372 if member.cls == 'Member': |
366 name, properties = Member(member).process(self.callbacks) | 373 name, properties = Member(member).process(self.callbacks) |
367 members.append(properties) | 374 members.append(properties) |
368 return members | 375 return members |
369 | 376 |
370 | 377 |
371 class IDLSchema(object): | 378 class IDLSchema(object): |
372 ''' | 379 ''' |
373 Given a list of IDLNodes and IDLAttributes, converts into a Python list | 380 Given a list of IDLNodes and IDLAttributes, converts into a Python list |
374 of api_defs that the JSON schema compiler expects to see. | 381 of api_defs that the JSON schema compiler expects to see. |
375 ''' | 382 ''' |
376 | 383 |
377 def __init__(self, idl): | 384 def __init__(self, idl): |
378 self.idl = idl | 385 self.idl = idl |
379 | 386 |
380 def process(self): | 387 def process(self): |
381 namespaces = [] | 388 namespaces = [] |
382 nodoc = False | 389 nodoc = False |
383 internal = False | 390 internal = False |
384 description = None | 391 description = None |
385 platforms = None | 392 platforms = None |
| 393 compiler_options = None |
386 for node in self.idl: | 394 for node in self.idl: |
387 if node.cls == 'Namespace': | 395 if node.cls == 'Namespace': |
388 if not description: | 396 if not description: |
389 # TODO(kalman): Go back to throwing an error here. | 397 # TODO(kalman): Go back to throwing an error here. |
390 print('%s must have a namespace-level comment. This will ' | 398 print('%s must have a namespace-level comment. This will ' |
391 'appear on the API summary page.' % node.GetName()) | 399 'appear on the API summary page.' % node.GetName()) |
392 description = '' | 400 description = '' |
393 namespace = Namespace(node, description, nodoc, internal, platforms) | 401 namespace = Namespace(node, description, nodoc, internal, |
| 402 platforms=platforms, |
| 403 compiler_options=compiler_options) |
394 namespaces.append(namespace.process()) | 404 namespaces.append(namespace.process()) |
395 nodoc = False | 405 nodoc = False |
396 internal = False | 406 internal = False |
397 platforms = None | 407 platforms = None |
| 408 compiler_options = None |
398 elif node.cls == 'Copyright': | 409 elif node.cls == 'Copyright': |
399 continue | 410 continue |
400 elif node.cls == 'Comment': | 411 elif node.cls == 'Comment': |
401 description = node.GetName() | 412 description = node.GetName() |
402 elif node.cls == 'ExtAttribute': | 413 elif node.cls == 'ExtAttribute': |
403 if node.name == 'nodoc': | 414 if node.name == 'nodoc': |
404 nodoc = bool(node.value) | 415 nodoc = bool(node.value) |
405 elif node.name == 'internal': | 416 elif node.name == 'internal': |
406 internal = bool(node.value) | 417 internal = bool(node.value) |
407 elif node.name == 'platforms': | 418 elif node.name == 'platforms': |
408 platforms = list(node.value) | 419 platforms = list(node.value) |
| 420 elif node.name == 'implemented_in': |
| 421 compiler_options = {'implemented_in': node.value} |
409 else: | 422 else: |
410 continue | 423 continue |
411 else: | 424 else: |
412 sys.exit('Did not process %s %s' % (node.cls, node)) | 425 sys.exit('Did not process %s %s' % (node.cls, node)) |
413 return namespaces | 426 return namespaces |
414 | 427 |
415 | 428 |
416 def Load(filename): | 429 def Load(filename): |
417 ''' | 430 ''' |
418 Given the filename of an IDL file, parses it and returns an equivalent | 431 Given the filename of an IDL file, parses it and returns an equivalent |
(...skipping 14 matching lines...) Expand all Loading... |
433 Dump a json serialization of parse result for the IDL files whose names | 446 Dump a json serialization of parse result for the IDL files whose names |
434 were passed in on the command line. | 447 were passed in on the command line. |
435 ''' | 448 ''' |
436 for filename in sys.argv[1:]: | 449 for filename in sys.argv[1:]: |
437 schema = Load(filename) | 450 schema = Load(filename) |
438 print json.dumps(schema, indent=2) | 451 print json.dumps(schema, indent=2) |
439 | 452 |
440 | 453 |
441 if __name__ == '__main__': | 454 if __name__ == '__main__': |
442 Main() | 455 Main() |
OLD | NEW |