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

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

Issue 9701105: Revert 127159 - Refactor extension_function_dispatcher to extract ExtensionFunctionRegistry. This a… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 model import PropertyType 5 from model import PropertyType
6 import code 6 import code
7 import cpp_util 7 import cpp_util
8 import model 8 import model
9 import os 9 import os
10 10
11 class HGenerator(object): 11 class HGenerator(object):
12 """A .h generator for a namespace. 12 """A .h generator for a namespace.
13 """ 13 """
14 def __init__(self, namespace, cpp_type_generator): 14 def __init__(self, namespace, cpp_type_generator):
15 self._cpp_type_generator = cpp_type_generator 15 self._cpp_type_generator = cpp_type_generator
16 self._namespace = namespace 16 self._namespace = namespace
17 self._target_namespace = ( 17 self._target_namespace = (
18 self._cpp_type_generator.GetCppNamespaceName(self._namespace)) 18 self._cpp_type_generator.GetCppNamespaceName(self._namespace))
19 19
20 def Generate(self): 20 def Generate(self):
21 """Generates a code.Code object with the .h for a single namespace. 21 """Generates a code.Code object with the .h for a single namespace.
22 """ 22 """
23 c = code.Code() 23 c = code.Code()
24 (c.Append(cpp_util.CHROMIUM_LICENSE) 24 (c.Append(cpp_util.CHROMIUM_LICENSE)
25 .Append() 25 .Append()
26 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) 26 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file)
27 .Append() 27 .Append()
28 ) 28 )
29 29
30 ifndef_name = cpp_util.GenerateIfndefName(self._namespace.source_file_dir, 30 ifndef_name = self._GenerateIfndefName()
31 self._target_namespace)
32 (c.Append('#ifndef %s' % ifndef_name) 31 (c.Append('#ifndef %s' % ifndef_name)
33 .Append('#define %s' % ifndef_name) 32 .Append('#define %s' % ifndef_name)
34 .Append('#pragma once') 33 .Append('#pragma once')
35 .Append() 34 .Append()
36 .Append('#include <string>') 35 .Append('#include <string>')
37 .Append('#include <vector>') 36 .Append('#include <vector>')
38 .Append() 37 .Append()
39 .Append('#include "base/basictypes.h"') 38 .Append('#include "base/basictypes.h"')
40 .Append('#include "base/memory/linked_ptr.h"') 39 .Append('#include "base/memory/linked_ptr.h"')
41 .Append('#include "base/memory/scoped_ptr.h"') 40 .Append('#include "base/memory/scoped_ptr.h"')
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 c.Comment(param.description) 256 c.Comment(param.description)
258 if param.type_ == PropertyType.ANY: 257 if param.type_ == PropertyType.ANY:
259 c.Comment("Value* Result::Create(Value*) not generated " 258 c.Comment("Value* Result::Create(Value*) not generated "
260 "because it's redundant.") 259 "because it's redundant.")
261 continue 260 continue
262 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( 261 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration(
263 param, self._cpp_type_generator.GetType(param))) 262 param, self._cpp_type_generator.GetType(param)))
264 c.Eblock('};') 263 c.Eblock('};')
265 264
266 return c 265 return c
266
267 def _GenerateIfndefName(self):
268 """Formats a path and filename as a #define name.
269
270 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__.
271 """
272 return (('%s_%s_H__' %
273 (self._namespace.source_file_dir, self._target_namespace))
274 .upper().replace(os.sep, '_'))
275
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/h_bundle_generator.py ('k') | tools/json_schema_compiler/test/json_schema_compiler_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698