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

Unified Diff: tools/json_schema_compiler/idl_schema.py

Issue 10080014: Fix a bug in IDL parsing related to arrays of callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added in test file Created 8 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/idl_schema.py
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py
old mode 100644
new mode 100755
index 1d3c83ae3b9652767c0f73ec4e56601d8e2b933c..8d735e800bbbefdb803cf5e37c39f991f914691a
--- a/tools/json_schema_compiler/idl_schema.py
+++ b/tools/json_schema_compiler/idl_schema.py
@@ -1,7 +1,9 @@
+#! /usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
import os.path
import sys
@@ -28,10 +30,10 @@ class Callspec(object):
def __init__(self, callspec_node):
self.node = callspec_node
- def process(self, refs):
+ def process(self, callbacks):
parameters = []
for node in self.node.children:
- parameters.append(Param(node).process(refs))
+ parameters.append(Param(node).process(callbacks))
return self.node.GetName(), parameters
class Param(object):
@@ -42,10 +44,10 @@ class Param(object):
def __init__(self, param_node):
self.node = param_node
- def process(self, refs):
+ def process(self, callbacks):
return Typeref(self.node.GetProperty( 'TYPEREF'),
self.node,
- { 'name': self.node.GetName() }).process(refs)
+ { 'name': self.node.GetName() }).process(callbacks)
class Dictionary(object):
'''
@@ -55,11 +57,11 @@ class Dictionary(object):
def __init__(self, dictionary_node):
self.node = dictionary_node
- def process(self, refs):
+ def process(self, callbacks):
properties = {}
for node in self.node.children:
if node.cls == 'Member':
- k, v = Member(node).process(refs)
+ k, v = Member(node).process(callbacks)
properties[k] = v
return { 'id': self.node.GetName(),
'properties': properties,
@@ -74,7 +76,7 @@ class Member(object):
def __init__(self, member_node):
self.node = member_node
- def process(self, refs):
+ def process(self, callbacks):
properties = {}
name = self.node.GetName()
if self.node.GetProperty('OPTIONAL'):
@@ -85,14 +87,14 @@ class Member(object):
for node in self.node.children:
if node.cls == 'Callspec':
is_function = True
- name, parameters = Callspec(node).process(refs)
+ name, parameters = Callspec(node).process(callbacks)
properties['parameters'] = parameters
properties['name'] = name
if is_function:
properties['type'] = 'function'
else:
properties = Typeref(self.node.GetProperty('TYPEREF'),
- self.node, properties).process(refs)
+ self.node, properties).process(callbacks)
return name, properties
class Typeref(object):
@@ -106,7 +108,7 @@ class Typeref(object):
self.parent = parent
self.additional_properties = additional_properties
- def process(self, refs):
+ def process(self, callbacks):
properties = self.additional_properties
result = properties
@@ -141,9 +143,9 @@ class Typeref(object):
elif self.typeref is None:
properties['type'] = 'function'
else:
- try:
- result = refs[self.typeref]
- except KeyError, e:
+ if self.typeref in callbacks:
+ properties.update(callbacks[self.typeref])
+ else:
properties['$ref'] = self.typeref
return result
@@ -160,16 +162,16 @@ class Namespace(object):
self.events = []
self.functions = []
self.types = []
- self.refs = {}
+ self.callbacks = {}
def process(self):
for node in self.namespace.children:
cls = node.cls
if cls == "Dictionary":
- self.types.append(Dictionary(node).process(self.refs))
+ self.types.append(Dictionary(node).process(self.callbacks))
elif cls == "Callback":
- k, v = Member(node).process(self.refs)
- self.refs[k] = v
+ k, v = Member(node).process(self.callbacks)
+ self.callbacks[k] = v
elif cls == "Interface" and node.GetName() == "Functions":
self.functions = self.process_interface(node)
elif cls == "Interface" and node.GetName() == "Events":
@@ -187,7 +189,7 @@ class Namespace(object):
members = []
for member in node.children:
if member.cls == 'Member':
- name, properties = Member(member).process(self.refs)
+ name, properties = Member(member).process(self.callbacks)
members.append(properties)
return members
@@ -234,3 +236,15 @@ def Load(filename):
idl = idl_parser.IDLParser().ParseData(contents, filename)
idl_schema = IDLSchema(idl)
return idl_schema.process()
+
+def Main():
+ '''
+ Dump a json serialization of parse result for the IDL files whose names
+ were passed in on the command line.
+ '''
+ for filename in sys.argv[1:]:
+ schema = Load(filename)
+ print json.dumps(schema, indent=2)
+
+if __name__ == '__main__':
+ Main()
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698