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