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

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

Issue 143473003: Generate ax enums from idl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Caught Blink enum conversion bug! Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
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 """Generator for C++ structs from api json files. 5 """Generator for C++ structs from api json files.
6 6
7 The purpose of this tool is to remove the need for hand-written code that 7 The purpose of this tool is to remove the need for hand-written code that
8 converts to and from base::Value types when receiving javascript api calls. 8 converts to and from base::Value types when receiving javascript api calls.
9 Originally written for generating code for extension apis. Reference schemas 9 Originally written for generating code for extension apis. Reference schemas
10 are in chrome/common/extensions/api. 10 are in chrome/common/extensions/api.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 relpath = os.path.relpath(os.path.normpath(schema_filename), root) 64 relpath = os.path.relpath(os.path.normpath(schema_filename), root)
65 namespace = api_model.AddNamespace(target_namespace, 65 namespace = api_model.AddNamespace(target_namespace,
66 relpath, 66 relpath,
67 include_compiler_options=True) 67 include_compiler_options=True)
68 if default_namespace is None: 68 if default_namespace is None:
69 default_namespace = namespace 69 default_namespace = namespace
70 70
71 path, filename = os.path.split(schema_filename) 71 path, filename = os.path.split(schema_filename)
72 short_filename, extension = os.path.splitext(filename) 72 short_filename, extension = os.path.splitext(filename)
73 73
74 # Filenames are checked against the unix_names of the namespaces they
75 # generate because the gyp uses the names of the JSON files to generate
76 # the names of the .cc and .h files. We want these to be using unix_names.
77 if namespace.unix_name != short_filename:
78 sys.exit("Filename %s is illegal. Name files using unix_hacker style." %
79 schema_filename)
80
81 # Construct the type generator with all the namespaces in this model. 74 # Construct the type generator with all the namespaces in this model.
82 type_generator = CppTypeGenerator(api_model, 75 type_generator = CppTypeGenerator(api_model,
83 schema_loader, 76 schema_loader,
84 default_namespace=default_namespace) 77 default_namespace=default_namespace)
85 78
86 if generator == 'cpp-bundle': 79 if generator == 'cpp-bundle':
87 cpp_bundle_generator = CppBundleGenerator(root, 80 cpp_bundle_generator = CppBundleGenerator(root,
88 api_model, 81 api_model,
89 api_defs, 82 api_defs,
90 type_generator, 83 type_generator,
91 root_namespace, 84 root_namespace,
92 namespace.source_file_dir) 85 namespace.source_file_dir)
93 generators = [ 86 generators = [
94 ('generated_api.cc', cpp_bundle_generator.api_cc_generator), 87 ('generated_api.cc', cpp_bundle_generator.api_cc_generator),
95 ('generated_api.h', cpp_bundle_generator.api_h_generator), 88 ('generated_api.h', cpp_bundle_generator.api_h_generator),
96 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator), 89 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator),
97 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator) 90 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator)
98 ] 91 ]
99 elif generator == 'cpp': 92 elif generator == 'cpp':
100 cpp_generator = CppGenerator(type_generator, root_namespace) 93 cpp_generator = CppGenerator(type_generator, root_namespace)
101 generators = [ 94 generators = [
102 ('%s.h' % namespace.unix_name, cpp_generator.h_generator), 95 ('%s.h' % short_filename, cpp_generator.h_generator),
103 ('%s.cc' % namespace.unix_name, cpp_generator.cc_generator) 96 ('%s.cc' % short_filename, cpp_generator.cc_generator)
104 ] 97 ]
105 elif generator == 'dart': 98 elif generator == 'dart':
106 generators = [ 99 generators = [
107 ('%s.dart' % namespace.unix_name, DartGenerator( 100 ('%s.dart' % namespace.unix_name, DartGenerator(
108 dart_overrides_dir)) 101 dart_overrides_dir))
109 ] 102 ]
110 elif generator == 'ppapi': 103 elif generator == 'ppapi':
111 generator = PpapiGenerator() 104 generator = PpapiGenerator()
112 generators = [ 105 generators = [
113 (os.path.join('api', 'ppb_%s.idl' % namespace.unix_name), 106 (os.path.join('api', 'ppb_%s.idl' % namespace.unix_name),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 # Unless in bundle mode, only one file should be specified. 147 # Unless in bundle mode, only one file should be specified.
155 if opts.generator != 'cpp-bundle' and len(filenames) > 1: 148 if opts.generator != 'cpp-bundle' and len(filenames) > 1:
156 # TODO(sashab): Could also just use filenames[0] here and not complain. 149 # TODO(sashab): Could also just use filenames[0] here and not complain.
157 raise Exception( 150 raise Exception(
158 "Unless in bundle mode, only one file can be specified at a time.") 151 "Unless in bundle mode, only one file can be specified at a time.")
159 152
160 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, 153 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir,
161 opts.namespace, opts.dart_overrides_dir) 154 opts.namespace, opts.dart_overrides_dir)
162 if not opts.destdir: 155 if not opts.destdir:
163 print result 156 print result
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/cpp_type_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698