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

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

Issue 12041098: Initial commit of the Dart Chrome Extension APIs generators (Closed) Base URL: http://git.chromium.org/chromium/src.git@file_path_bugfix
Patch Set: Kalman fixes 2 (nocompile ignored in bundle mode) 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
« no previous file with comments | « build/json_schema_compile.gypi ('k') | tools/json_schema_compiler/code.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 model 8 import model
9 import schema_util 9 import schema_util
10 import sys 10 import sys
11 import util_cc_helper 11 import util_cc_helper
12 12
13 class CCGenerator(object): 13 class CCGenerator(object):
14 def __init__(self, type_generator, cpp_namespace):
15 self._type_generator = type_generator
16 self._cpp_namespace = cpp_namespace
17
18 def Generate(self, namespace):
19 return _Generator(namespace,
20 self._type_generator,
21 self._cpp_namespace).Generate()
22
23 class _Generator(object):
14 """A .cc generator for a namespace. 24 """A .cc generator for a namespace.
15 """ 25 """
16 def __init__(self, namespace, cpp_type_generator): 26 def __init__(self, namespace, cpp_type_generator, cpp_namespace):
27 self._namespace = namespace
17 self._type_helper = cpp_type_generator 28 self._type_helper = cpp_type_generator
18 self._namespace = namespace 29 self._cpp_namespace = cpp_namespace
19 self._target_namespace = ( 30 self._target_namespace = (
20 self._type_helper.GetCppNamespaceName(self._namespace)) 31 self._type_helper.GetCppNamespaceName(self._namespace))
21 self._util_cc_helper = ( 32 self._util_cc_helper = (
22 util_cc_helper.UtilCCHelper(self._type_helper)) 33 util_cc_helper.UtilCCHelper(self._type_helper))
23 34
24 def Generate(self): 35 def Generate(self):
25 """Generates a Code object with the .cc for a single namespace. 36 """Generates a Code object with the .cc for a single namespace.
26 """ 37 """
27 c = Code() 38 c = Code()
28 (c.Append(cpp_util.CHROMIUM_LICENSE) 39 (c.Append(cpp_util.CHROMIUM_LICENSE)
29 .Append() 40 .Append()
30 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) 41 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file)
31 .Append() 42 .Append()
32 .Append(self._util_cc_helper.GetIncludePath()) 43 .Append(self._util_cc_helper.GetIncludePath())
33 .Append('#include "base/json/json_writer.h"') 44 .Append('#include "base/json/json_writer.h"')
34 .Append('#include "base/logging.h"') 45 .Append('#include "base/logging.h"')
35 .Append('#include "base/string_number_conversions.h"') 46 .Append('#include "base/string_number_conversions.h"')
36 .Append('#include "%s/%s.h"' % 47 .Append('#include "%s/%s.h"' %
37 (self._namespace.source_file_dir, self._namespace.unix_name)) 48 (self._namespace.source_file_dir, self._namespace.unix_name))
38 .Cblock(self._type_helper.GenerateIncludes(include_soft=True)) 49 .Cblock(self._type_helper.GenerateIncludes(include_soft=True))
39 .Concat(self._type_helper.GetRootNamespaceStart()) 50 .Concat(cpp_util.OpenNamespace(self._cpp_namespace))
40 .Cblock(self._type_helper.GetNamespaceStart()) 51 .Cblock(self._type_helper.GetNamespaceStart())
41 ) 52 )
42 if self._namespace.properties: 53 if self._namespace.properties:
43 (c.Append('//') 54 (c.Append('//')
44 .Append('// Properties') 55 .Append('// Properties')
45 .Append('//') 56 .Append('//')
46 .Append() 57 .Append()
47 ) 58 )
48 for property in self._namespace.properties.values(): 59 for property in self._namespace.properties.values():
49 property_code = self._type_helper.GeneratePropertyValues( 60 property_code = self._type_helper.GeneratePropertyValues(
(...skipping 19 matching lines...) Expand all
69 c.Cblock(self._GenerateFunction(function)) 80 c.Cblock(self._GenerateFunction(function))
70 if self._namespace.events: 81 if self._namespace.events:
71 (c.Append('//') 82 (c.Append('//')
72 .Append('// Events') 83 .Append('// Events')
73 .Append('//') 84 .Append('//')
74 .Append() 85 .Append()
75 ) 86 )
76 for event in self._namespace.events.values(): 87 for event in self._namespace.events.values():
77 c.Cblock(self._GenerateEvent(event)) 88 c.Cblock(self._GenerateEvent(event))
78 (c.Concat(self._type_helper.GetNamespaceEnd()) 89 (c.Concat(self._type_helper.GetNamespaceEnd())
79 .Cblock(self._type_helper.GetRootNamespaceEnd()) 90 .Cblock(cpp_util.CloseNamespace(self._cpp_namespace))
80 ) 91 )
81 return c 92 return c
82 93
83 def _GenerateType(self, cpp_namespace, type_): 94 def _GenerateType(self, cpp_namespace, type_):
84 """Generates the function definitions for a type. 95 """Generates the function definitions for a type.
85 """ 96 """
86 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) 97 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name))
87 c = Code() 98 c = Code()
88 99
89 if type_.functions: 100 if type_.functions:
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 """ 813 """
803 c = Code() 814 c = Code()
804 underlying_type = self._type_helper.FollowRef(prop.type_) 815 underlying_type = self._type_helper.FollowRef(prop.type_)
805 if (underlying_type.property_type == PropertyType.ENUM and 816 if (underlying_type.property_type == PropertyType.ENUM and
806 prop.optional): 817 prop.optional):
807 c.Append('%s->%s = %s;' % ( 818 c.Append('%s->%s = %s;' % (
808 dst, 819 dst,
809 prop.unix_name, 820 prop.unix_name,
810 self._type_helper.GetEnumNoneValue(prop.type_))) 821 self._type_helper.GetEnumNoneValue(prop.type_)))
811 return c 822 return c
OLDNEW
« no previous file with comments | « build/json_schema_compile.gypi ('k') | tools/json_schema_compiler/code.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698