Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2012 The Chromium Authors. All rights reserved. | 2 # Copyright 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 # Format for the JSON schema file: | 6 # Format for the JSON schema file: |
| 7 # { | 7 # { |
| 8 # "type_name": "DesiredCStructName", | 8 # "type_name": "DesiredCStructName", |
| 9 # "headers": [ // Optional list of headers to be included by the .h. | 9 # "headers": [ // Optional list of headers to be included by the .h. |
| 10 # "path/to/header.h" | 10 # "path/to/header.h" |
| 11 # ], | 11 # ], |
| 12 # "schema": [ // Fields of the generated structure. | 12 # "schema": [ // Fields of the generated structure. |
| 13 # { | 13 # { |
| 14 # "field": "my_enum_field", | 14 # "field": "my_enum_field", |
| 15 # "type": "enum", // Either: int, string, string16, enum, array. | 15 # "type": "enum", // Either: int, string, string16, enum, array. |
|
beaudoin
2015/07/06 16:01:12
Update doc to add 'object' here, with an example.
danduong
2015/07/08 23:07:03
Done.
| |
| 16 # "default": "RED", // Optional. Cannot be used for array. | 16 # "default": "RED", // Optional. Cannot be used for array. |
| 17 # "ctype": "Color" // Only for enum, specify the C type. | 17 # "ctype": "Color" // Only for enum, specify the C type. |
| 18 # }, | 18 # }, |
| 19 # { | 19 # { |
| 20 # "field": "my_int_array_field", // my_int_array_field_size will also | 20 # "field": "my_int_array_field", // my_int_array_field_size will also |
| 21 # "type": "array", // be generated. | 21 # "type": "array", // be generated. |
| 22 # "contents": { | 22 # "contents": { |
| 23 # "type": "int" // Either: int, string, string16, enum, array. | 23 # "type": "int" // Either: int, string, string16, enum, array. |
| 24 # } | 24 # } |
| 25 # }, | 25 # }, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 f.write('\n') | 112 f.write('\n') |
| 113 | 113 |
| 114 if namespace: | 114 if namespace: |
| 115 f.write('namespace %s {\n' % namespace) | 115 f.write('namespace %s {\n' % namespace) |
| 116 f.write('\n') | 116 f.write('\n') |
| 117 | 117 |
| 118 f.write(struct_generator.GenerateStruct( | 118 f.write(struct_generator.GenerateStruct( |
| 119 schema['type_name'], schema['schema'])) | 119 schema['type_name'], schema['schema'])) |
| 120 f.write('\n') | 120 f.write('\n') |
| 121 | 121 |
| 122 for var_name, value in description.get('int_variables', []).items(): | 122 for var_name, value in description.get('int_variables', {}).items(): |
| 123 f.write('extern const int %s;\n' % var_name) | 123 f.write('extern const int %s;\n' % var_name) |
| 124 f.write('\n') | 124 f.write('\n') |
| 125 | 125 |
| 126 for element_name, element in description['elements'].items(): | 126 for element_name, element in description['elements'].items(): |
| 127 f.write('extern const %s %s;\n' % (schema['type_name'], element_name)) | 127 f.write('extern const %s %s;\n' % (schema['type_name'], element_name)) |
| 128 | 128 |
| 129 if namespace: | 129 if namespace: |
| 130 f.write('\n') | 130 f.write('\n') |
| 131 f.write('} // namespace %s\n' % namespace) | 131 f.write('} // namespace %s\n' % namespace) |
| 132 | 132 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 basepath = os.path.normpath(opts.destbase) | 202 basepath = os.path.normpath(opts.destbase) |
| 203 else: | 203 else: |
| 204 basepath = '' | 204 basepath = '' |
| 205 | 205 |
| 206 schema = _Load(opts.schema) | 206 schema = _Load(opts.schema) |
| 207 description = _Load(description_filename) | 207 description = _Load(description_filename) |
| 208 | 208 |
| 209 head = HEAD % (datetime.now().year, opts.schema, description_filename) | 209 head = HEAD % (datetime.now().year, opts.schema, description_filename) |
| 210 _GenerateH(basepath, output_root, head, opts.namespace, schema, description) | 210 _GenerateH(basepath, output_root, head, opts.namespace, schema, description) |
| 211 _GenerateCC(basepath, output_root, head, opts.namespace, schema, description) | 211 _GenerateCC(basepath, output_root, head, opts.namespace, schema, description) |
| OLD | NEW |