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

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

Issue 11953121: Fix up how the JSON Schema compiler decides whether to include or forward (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert changes to webview so that this can land Created 7 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 # 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, Type 6 from model import PropertyType, Type
7 import cpp_util 7 import cpp_util
8 import schema_util 8 import schema_util
9 9
10 class HGenerator(object): 10 class HGenerator(object):
(...skipping 22 matching lines...) Expand all
33 .Append() 33 .Append()
34 .Append('#include <map>') 34 .Append('#include <map>')
35 .Append('#include <string>') 35 .Append('#include <string>')
36 .Append('#include <vector>') 36 .Append('#include <vector>')
37 .Append() 37 .Append()
38 .Append('#include "base/basictypes.h"') 38 .Append('#include "base/basictypes.h"')
39 .Append('#include "base/logging.h"') 39 .Append('#include "base/logging.h"')
40 .Append('#include "base/memory/linked_ptr.h"') 40 .Append('#include "base/memory/linked_ptr.h"')
41 .Append('#include "base/memory/scoped_ptr.h"') 41 .Append('#include "base/memory/scoped_ptr.h"')
42 .Append('#include "base/values.h"') 42 .Append('#include "base/values.h"')
43 .Cblock(self._type_helper.GenerateIncludes())
43 .Append() 44 .Append()
44 ) 45 )
45 46
46 c.Concat(self._type_helper.GetRootNamespaceStart()) 47 c.Concat(self._type_helper.GetRootNamespaceStart())
47 # TODO(calamity): These forward declarations should be #includes to allow 48 # TODO(calamity): These forward declarations should be #includes to allow
48 # $ref types from other files to be used as required params. This requires 49 # $ref types from other files to be used as required params. This requires
49 # some detangling of windows and tabs which will currently lead to circular 50 # some detangling of windows and tabs which will currently lead to circular
50 # #includes. 51 # #includes.
51 forward_declarations = ( 52 forward_declarations = (
52 self._type_helper.GenerateForwardDeclarations()) 53 self._type_helper.GenerateForwardDeclarations())
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 def _GenerateType(self, type_, is_toplevel=False, generate_typedefs=False): 156 def _GenerateType(self, type_, is_toplevel=False, generate_typedefs=False):
156 """Generates a struct for |type_|. 157 """Generates a struct for |type_|.
157 158
158 |is_toplevel| implies that the type was declared in the "types" field 159 |is_toplevel| implies that the type was declared in the "types" field
159 of an API schema. This determines the correct function 160 of an API schema. This determines the correct function
160 modifier(s). 161 modifier(s).
161 |generate_typedefs| controls whether primitive types should be generated as 162 |generate_typedefs| controls whether primitive types should be generated as
162 a typedef. This may not always be desired. If false, 163 a typedef. This may not always be desired. If false,
163 primitive types are ignored. 164 primitive types are ignored.
164 """ 165 """
165 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) 166 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name))
166 c = Code() 167 c = Code()
167 168
168 if type_.functions: 169 if type_.functions:
169 # Wrap functions within types in the type's namespace. 170 # Wrap functions within types in the type's namespace.
170 (c.Append('namespace %s {' % classname) 171 (c.Append('namespace %s {' % classname)
171 .Append() 172 .Append()
172 ) 173 )
173 for function in type_.functions.values(): 174 for function in type_.functions.values():
174 c.Cblock(self._GenerateFunction(function)) 175 c.Cblock(self._GenerateFunction(function))
175 c.Append('} // namespace %s' % classname) 176 c.Append('} // namespace %s' % classname)
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 def _GenerateFunctionResults(self, callback): 359 def _GenerateFunctionResults(self, callback):
359 """Generates namespace for passing a function's result back. 360 """Generates namespace for passing a function's result back.
360 """ 361 """
361 c = Code() 362 c = Code()
362 (c.Append('namespace Results {') 363 (c.Append('namespace Results {')
363 .Append() 364 .Append()
364 .Concat(self._GenerateCreateCallbackArguments(callback)) 365 .Concat(self._GenerateCreateCallbackArguments(callback))
365 .Append('} // namespace Results') 366 .Append('} // namespace Results')
366 ) 367 )
367 return c 368 return c
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cpp_type_generator_test.py ('k') | tools/json_schema_compiler/schema_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698