Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: tools/json_schema_compiler/idl_schema.py

Issue 38573008: Add "platforms" key in IDL schema compiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment issues Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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=None):
not at google - send to devlin 2013/10/28 17:04:48 bad news; now these need to all be on different li
Haojian Wu 2013/10/29 02:09:32 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 = None
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
387 platforms = None
383 elif node.cls == 'Copyright': 388 elif node.cls == 'Copyright':
384 continue 389 continue
385 elif node.cls == 'Comment': 390 elif node.cls == 'Comment':
386 description = node.GetName() 391 description = node.GetName()
387 elif node.cls == 'ExtAttribute': 392 elif node.cls == 'ExtAttribute':
388 if node.name == 'nodoc': 393 if node.name == 'nodoc':
389 nodoc = bool(node.value) 394 nodoc = bool(node.value)
390 elif node.name == 'internal': 395 elif node.name == 'internal':
391 internal = bool(node.value) 396 internal = bool(node.value)
397 elif node.name == 'platforms':
398 platforms = list(node.value)
392 else: 399 else:
393 continue 400 continue
394 else: 401 else:
395 sys.exit('Did not process %s %s' % (node.cls, node)) 402 sys.exit('Did not process %s %s' % (node.cls, node))
396 return namespaces 403 return namespaces
397 404
398 405
399 def Load(filename): 406 def Load(filename):
400 ''' 407 '''
401 Given the filename of an IDL file, parses it and returns an equivalent 408 Given the filename of an IDL file, parses it and returns an equivalent
(...skipping 14 matching lines...) Expand all
416 Dump a json serialization of parse result for the IDL files whose names 423 Dump a json serialization of parse result for the IDL files whose names
417 were passed in on the command line. 424 were passed in on the command line.
418 ''' 425 '''
419 for filename in sys.argv[1:]: 426 for filename in sys.argv[1:]:
420 schema = Load(filename) 427 schema = Load(filename)
421 print json.dumps(schema, indent=2) 428 print json.dumps(schema, indent=2)
422 429
423 430
424 if __name__ == '__main__': 431 if __name__ == '__main__':
425 Main() 432 Main()
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema_test.py » ('j') | tools/json_schema_compiler/model.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698