diff options
author | penghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 20:06:50 +0000 |
---|---|---|
committer | penghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 20:06:50 +0000 |
commit | 0796c78cdf00480f61dd0c9c88020d4f617199bf (patch) | |
tree | 8aeff3c881fd930000fc856ebbcc9ebead0cb450 /tools | |
parent | 8ee5a16de174a3acb3d1eedd90a2286a1a5a8cbd (diff) | |
download | chromium_src-0796c78cdf00480f61dd0c9c88020d4f617199bf.zip chromium_src-0796c78cdf00480f61dd0c9c88020d4f617199bf.tar.gz chromium_src-0796c78cdf00480f61dd0c9c88020d4f617199bf.tar.bz2 |
Support enum in idl file.
BUG=127658
TEST=Manually
Review URL: https://chromiumcodereview.appspot.com/10389078
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136957 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r-- | tools/json_schema_compiler/cc_generator.py | 1 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 5 | ||||
-rw-r--r-- | tools/json_schema_compiler/idl_schema.py | 24 | ||||
-rwxr-xr-x | tools/json_schema_compiler/idl_schema_test.py | 20 | ||||
-rw-r--r-- | tools/json_schema_compiler/test/idl_basics.idl | 10 |
5 files changed, 59 insertions, 1 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py index 4ba5b37..dbe797a 100644 --- a/tools/json_schema_compiler/cc_generator.py +++ b/tools/json_schema_compiler/cc_generator.py @@ -358,6 +358,7 @@ class CCGenerator(object): elif self._IsFundamentalOrFundamentalRef(prop): if prop.optional: var = '*' + var + prop = self._cpp_type_generator.GetReferencedProperty(prop); return { PropertyType.STRING: 'Value::CreateStringValue(%s)', PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index 1d3ac303..8a9960e 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -145,7 +145,10 @@ class CppTypeGenerator(object): elif prop.type_ == PropertyType.OBJECT: cpp_type = cpp_util.Classname(prop.name) elif prop.type_ == PropertyType.ARRAY: - if prop.item_type.type_ in ( + item_type = prop.item_type + if item_type.type_ == PropertyType.REF: + item_type = self.GetReferencedProperty(item_type) + if item_type.type_ in ( PropertyType.REF, PropertyType.ANY, PropertyType.OBJECT): cpp_type = 'std::vector<linked_ptr<%s> > ' else: diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py index 09794b2..8e46d12 100644 --- a/tools/json_schema_compiler/idl_schema.py +++ b/tools/json_schema_compiler/idl_schema.py @@ -97,6 +97,28 @@ class Dictionary(object): 'properties': properties, 'type': 'object' } +class Enum(object): + ''' + Given an IDL Enum node, converts into a Python dictionary that the JSON + schema compiler expects to see. + ''' + def __init__(self, enum_node): + self.node = enum_node + + def process(self, callbacks): + enum = [] + for node in self.node.children: + if node.cls == 'EnumItem': + name = node.GetName() + enum.append(name) + else: + sys.exit("Did not process %s %s" % (node.cls, node)) + return { "id" : self.node.GetName(), + 'enum': enum, + 'type': 'string' } + + + class Member(object): ''' Given an IDL dictionary or interface member, converts into a name/value pair @@ -215,6 +237,8 @@ class Namespace(object): self.functions = self.process_interface(node) elif cls == "Interface" and node.GetName() == "Events": self.events = self.process_interface(node) + elif cls == "Enum": + self.types.append(Enum(node).process(self.callbacks)) else: sys.exit("Did not process %s %s" % (node.cls, node)) diff --git a/tools/json_schema_compiler/idl_schema_test.py b/tools/json_schema_compiler/idl_schema_test.py index 024f408..943c76c 100755 --- a/tools/json_schema_compiler/idl_schema_test.py +++ b/tools/json_schema_compiler/idl_schema_test.py @@ -16,6 +16,11 @@ def getParams(schema, name): function = getFunction(schema, name) return function['parameters'] +def getType(schema, id): + for item in schema['types']: + if item['id'] == id: + return item + class IdlSchemaTest(unittest.TestCase): def setUp(self): loaded = idl_schema.Load('test/idl_basics.idl') @@ -51,5 +56,20 @@ class IdlSchemaTest(unittest.TestCase): 'parameters':[{'type':'integer', 'name':'x'}]}}] self.assertEquals(expected, getParams(schema, 'whatever')) + def testEnum(self): + schema = self.idl_basics + expected = {'enum': ['name1', 'name2'], + 'type': 'string', 'id': 'idl_basics.EnumType'} + self.assertEquals(expected, getType(schema, 'idl_basics.EnumType')) + + expected = [{'name':'type', '$ref':'idl_basics.EnumType'}, + {'type':'function', 'name':'Callback5', + 'parameters':[{'name':'type', '$ref':'idl_basics.EnumType'}]}] + self.assertEquals(expected, getParams(schema, 'function13')) + + expected = [{'items': {'$ref': 'idl_basics.EnumType'}, 'name': 'types', + 'type': 'array'}] + self.assertEquals(expected, getParams(schema, 'function14')) + if __name__ == '__main__': unittest.main() diff --git a/tools/json_schema_compiler/test/idl_basics.idl b/tools/json_schema_compiler/test/idl_basics.idl index 53155c7..7f0c3da 100644 --- a/tools/json_schema_compiler/test/idl_basics.idl +++ b/tools/json_schema_compiler/test/idl_basics.idl @@ -5,6 +5,11 @@ // Tests a variety of basic API definition features. namespace idl_basics { + enum EnumType { + name1, + name2 + }; + dictionary MyType1 { long x; // This comment tests "double-quotes". DOMString y; @@ -18,6 +23,7 @@ namespace idl_basics { callback Callback2 = void(long x); callback Callback3 = void(MyType1 arg); callback Callback4 = void(MyType2[] arg); + callback Callback5 = void(EnumType type); interface Functions { static void function1(); @@ -36,11 +42,15 @@ namespace idl_basics { static void function11(MyType1[] arg); static void function12(Callback4 cb); + + static void function13(EnumType type, Callback5 cb); + static void function14(EnumType[] types); }; interface Events { static void onFoo1(); static void onFoo2(long x); static void onFoo2(MyType1 arg); + static void onFoo3(EnumType type); }; }; |