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

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

Issue 9617010: Move chrome.downloads out of experimental to dev (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 8 years, 6 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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from code import Code 5 from code import Code
6 from model import PropertyType 6 from model import PropertyType
7 import cpp_util 7 import cpp_util
8 import model
9 import os
10 import schema_util 8 import schema_util
11 9
12 class HGenerator(object): 10 class HGenerator(object):
13 """A .h generator for a namespace. 11 """A .h generator for a namespace.
14 """ 12 """
15 def __init__(self, namespace, cpp_type_generator): 13 def __init__(self, namespace, cpp_type_generator):
16 self._cpp_type_generator = cpp_type_generator 14 self._cpp_type_generator = cpp_type_generator
17 self._namespace = namespace 15 self._namespace = namespace
18 self._target_namespace = ( 16 self._target_namespace = (
19 self._cpp_type_generator.GetCppNamespaceName(self._namespace)) 17 self._cpp_type_generator.GetCppNamespaceName(self._namespace))
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 """Generates the list of types in the current namespace in an order in which 102 """Generates the list of types in the current namespace in an order in which
105 depended-upon types appear before types which depend on them. 103 depended-upon types appear before types which depend on them.
106 """ 104 """
107 dependency_order = [] 105 dependency_order = []
108 106
109 def ExpandType(path, type_): 107 def ExpandType(path, type_):
110 if type_ in path: 108 if type_ in path:
111 raise ValueError("Illegal circular dependency via cycle " + 109 raise ValueError("Illegal circular dependency via cycle " +
112 ", ".join(map(lambda x: x.name, path + [type_]))) 110 ", ".join(map(lambda x: x.name, path + [type_])))
113 for prop in type_.properties.values(): 111 for prop in type_.properties.values():
114 if not prop.optional and prop.type_ == PropertyType.REF: 112 if schema_util.IsLocalReference(prop, self._namespace.name):
not at google - send to devlin 2012/06/07 03:00:54 IsReferenceInNamespace? though I would still have
benjhayden 2012/06/08 16:41:52 Done.
115 ExpandType(path + [type_], self._namespace.types[prop.ref_type]) 113 ExpandType(path + [type_], self._namespace.types[prop.ref_type])
116 if not type_ in dependency_order: 114 if not type_ in dependency_order:
117 dependency_order.append(type_) 115 dependency_order.append(type_)
118 116
119 for type_ in self._namespace.types.values(): 117 for type_ in self._namespace.types.values():
120 ExpandType([], type_) 118 ExpandType([], type_)
121 return dependency_order 119 return dependency_order
122 120
123 def _GenerateEnumDeclaration(self, enum_name, prop, values): 121 def _GenerateEnumDeclaration(self, enum_name, prop, values):
124 """Generate the declaration of a C++ enum for the given property and 122 """Generate the declaration of a C++ enum for the given property and
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if type_.description: 169 if type_.description:
172 c.Comment(type_.description) 170 c.Comment(type_.description)
173 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') 171 c.Append('typedef std::vector<%(item_type)s> %(classname)s;')
174 c.Substitute({'classname': classname, 'item_type': 172 c.Substitute({'classname': classname, 'item_type':
175 self._cpp_type_generator.GetType(type_.item_type, 173 self._cpp_type_generator.GetType(type_.item_type,
176 wrap_optional=True)}) 174 wrap_optional=True)})
177 elif type_.type_ == PropertyType.STRING: 175 elif type_.type_ == PropertyType.STRING:
178 if type_.description: 176 if type_.description:
179 c.Comment(type_.description) 177 c.Comment(type_.description)
180 c.Append('typedef std::string %(classname)s;') 178 c.Append('typedef std::string %(classname)s;')
181 c.Substitute({'classname': classname}) 179 elif type_.type_ == PropertyType.DOUBLE:
180 if type_.description:
181 c.Comment(type_.description)
182 c.Append('typedef double %(classname)s;')
183 elif type_.type_ == PropertyType.INTEGER:
184 if type_.description:
185 c.Comment(type_.description)
186 # TODO(benjhayden): c.Sblock('enum %(classname)s {') ... .Eblock('};')
187 # Generated cpp code should contain all constants defined in the IDL so
188 # that they don't need to be copied between the IDL and the
189 # implementation. This requires correctly parsing and transmitting the
190 # constants' names from the IDL to here. The same goes for string and
191 # double enums.
not at google - send to devlin 2012/06/07 03:00:54 We do generate code for constants that are defined
benjhayden 2012/06/08 16:41:52 Antony suggested using extended attributes to be m
192 c.Append('typedef int %(classname)s;')
182 else: 193 else:
183 if type_.description: 194 if type_.description:
184 c.Comment(type_.description) 195 c.Comment(type_.description)
185 (c.Sblock('struct %(classname)s {') 196 (c.Sblock('struct %(classname)s {')
186 .Append('~%(classname)s();') 197 .Append('~%(classname)s();')
187 .Append('%(classname)s();') 198 .Append('%(classname)s();')
188 .Append() 199 .Append()
189 .Concat(self._GeneratePropertyStructures(type_.properties.values())) 200 .Concat(self._GeneratePropertyStructures(type_.properties.values()))
190 .Concat(self._GenerateFields(type_.properties.values())) 201 .Concat(self._GenerateFields(type_.properties.values()))
191 ) 202 )
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 c.Comment(param.description) 307 c.Comment(param.description)
297 if param.type_ == PropertyType.ANY: 308 if param.type_ == PropertyType.ANY:
298 c.Comment("Value* Result::Create(Value*) not generated " 309 c.Comment("Value* Result::Create(Value*) not generated "
299 "because it's redundant.") 310 "because it's redundant.")
300 continue 311 continue
301 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( 312 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration(
302 param, self._cpp_type_generator.GetType(param))) 313 param, self._cpp_type_generator.GetType(param)))
303 c.Eblock('};') 314 c.Eblock('};')
304 315
305 return c 316 return c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698