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

Unified Diff: tools/json_schema_compiler/cpp_bundle_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: Small style & structure fixes to dart_generator, and similar. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/cpp_bundle_generator.py
diff --git a/tools/json_schema_compiler/schema_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py
similarity index 78%
rename from tools/json_schema_compiler/schema_bundle_generator.py
rename to tools/json_schema_compiler/cpp_bundle_generator.py
index e9fb9267935db4da8fd71daf6651e725e88edf46..98670fbabcb9692f375c9d7335189b625f81804c 100644
--- a/tools/json_schema_compiler/schema_bundle_generator.py
+++ b/tools/json_schema_compiler/cpp_bundle_generator.py
@@ -31,7 +31,7 @@ def _RemoveDescriptions(node):
return [_RemoveDescriptions(v) for v in node]
return node
-class SchemaBundleGenerator(object):
+class CppBundleGenerator(object):
"""This class contains methods to generate code based on multiple schemas.
"""
@@ -41,6 +41,10 @@ class SchemaBundleGenerator(object):
self._api_defs = api_defs
self._cpp_type_generator = cpp_type_generator
+ self.api_h_generator = GenerateAPIHeader(self)
+ self.schemas_cc_generator = GenerateSchemasCC(self)
+ self.schemas_h_generator = GenerateSchemasHeader(self)
+
def GenerateHeader(self, file_base, body_code):
"""Generates a code.Code object for a header file
@@ -76,49 +80,6 @@ class SchemaBundleGenerator(object):
raise ValueError("Unsupported platform ifdef: %s" % platform.name)
return ' and '.join(ifdefs)
- def GenerateAPIHeader(self):
- """Generates the header for API registration / declaration"""
- c = code.Code()
-
- c.Append('#include <string>')
- c.Append()
- c.Append('#include "base/basictypes.h"')
-
- for namespace in self._model.namespaces.values():
- namespace_name = namespace.unix_name.replace("experimental_", "")
- implementation_header = namespace.compiler_options.get(
- "implemented_in",
- "chrome/browser/extensions/api/%s/%s_api.h" % (namespace_name,
- namespace_name))
- if not os.path.exists(
- os.path.join(self._root, os.path.normpath(implementation_header))):
- if "implemented_in" in namespace.compiler_options:
- raise ValueError('Header file for namespace "%s" specified in '
- 'compiler_options not found: %s' %
- (namespace.unix_name, implementation_header))
- continue
- ifdefs = self._GetPlatformIfdefs(namespace)
- if ifdefs is not None:
- c.Append("#if %s" % ifdefs, indent_level=0)
-
- c.Append('#include "%s"' % implementation_header)
-
- if ifdefs is not None:
- c.Append("#endif // %s" % ifdefs, indent_level=0)
-
- c.Append()
- c.Append("class ExtensionFunctionRegistry;")
- c.Append()
-
- c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
- for namespace in self._model.namespaces.values():
- c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name))
- c.Append()
- c.Concat(self.GenerateFunctionRegistry())
- c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
- c.Append()
- return self.GenerateHeader('generated_api', c)
-
def _GetNamespaceFunctions(self, namespace):
functions = list(namespace.functions.values())
if namespace.compiler_options.get("generate_type_functions", False):
@@ -159,15 +120,67 @@ class SchemaBundleGenerator(object):
c.Append()
return c
- def GenerateSchemasHeader(self):
- """Generates a code.Code object for the generated schemas .h file"""
+class GenerateAPIHeader(object):
not at google - send to devlin 2013/02/02 00:45:48 _APIHGenerator would be more consistent with namin
sashab 2013/02/04 05:09:27 Done.
+ """Generates the header for API registration / declaration"""
+ def __init__(self, cpp_bundle):
+ self._bundle = cpp_bundle
+
+ def Generate(self, namespace):
+ c = code.Code()
+
+ c.Append('#include <string>')
+ c.Append()
+ c.Append('#include "base/basictypes.h"')
+
+ for namespace in self._bundle._model.namespaces.values():
+ namespace_name = namespace.unix_name.replace("experimental_", "")
+ implementation_header = namespace.compiler_options.get(
+ "implemented_in",
+ "chrome/browser/extensions/api/%s/%s_api.h" % (namespace_name,
+ namespace_name))
+ if not os.path.exists(
+ os.path.join(self._bundle._root,
+ os.path.normpath(implementation_header))):
+ if "implemented_in" in namespace.compiler_options:
+ raise ValueError('Header file for namespace "%s" specified in '
+ 'compiler_options not found: %s' %
+ (namespace.unix_name, implementation_header))
+ continue
+ ifdefs = self._bundle._GetPlatformIfdefs(namespace)
+ if ifdefs is not None:
+ c.Append("#if %s" % ifdefs, indent_level=0)
+
+ c.Append('#include "%s"' % implementation_header)
+
+ if ifdefs is not None:
+ c.Append("#endif // %s" % ifdefs, indent_level=0)
+
+ c.Append()
+ c.Append("class ExtensionFunctionRegistry;")
+ c.Append()
+
+ c.Concat(self._bundle._cpp_type_generator.GetRootNamespaceStart())
+ for namespace in self._bundle._model.namespaces.values():
+ c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name))
+ c.Append()
+ c.Concat(self._bundle.GenerateFunctionRegistry())
+ c.Concat(self._bundle._cpp_type_generator.GetRootNamespaceEnd())
+ c.Append()
+ return self._bundle.GenerateHeader('generated_api', c)
+
+class GenerateSchemasHeader(object):
not at google - send to devlin 2013/02/02 00:45:48 _SchemasHGenerator
sashab 2013/02/04 05:09:27 Done.
+ """Generates a code.Code object for the generated schemas .h file"""
+ def __init__(self, cpp_bundle):
+ self._bundle = cpp_bundle
+
+ def Generate(self, namespace):
c = code.Code()
c.Append('#include <map>')
c.Append('#include <string>')
c.Append();
c.Append('#include "base/string_piece.h"')
c.Append()
- c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
+ c.Concat(self._bundle._cpp_type_generator.GetRootNamespaceStart())
c.Append()
c.Sblock('class GeneratedSchemas {')
c.Append(' public:')
@@ -176,25 +189,30 @@ class SchemaBundleGenerator(object):
'std::map<std::string, base::StringPiece>* schemas);')
c.Eblock('};');
c.Append()
- c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
+ c.Concat(self._bundle._cpp_type_generator.GetRootNamespaceEnd())
c.Append()
- return self.GenerateHeader('generated_schemas', c)
+ return self._bundle.GenerateHeader('generated_schemas', c)
+
+class GenerateSchemasCC(object):
not at google - send to devlin 2013/02/02 00:45:48 _SchemasCCGenerator
sashab 2013/02/04 05:09:27 Done.
+ """Generates a code.Code object for the generated schemas .cc file"""
+
+ def __init__(self, cpp_bundle):
+ self._bundle = cpp_bundle
- def GenerateSchemasCC(self):
- """Generates a code.Code object for the generated schemas .cc file"""
+ def Generate(self, namespace):
c = code.Code()
c.Append(cpp_util.CHROMIUM_LICENSE)
c.Append()
c.Append('#include "%s"' % (os.path.join(SOURCE_BASE_PATH,
'generated_schemas.h')))
c.Append()
- c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
+ c.Concat(self._bundle._cpp_type_generator.GetRootNamespaceStart())
c.Append()
c.Append('// static')
c.Sblock('void GeneratedSchemas::Get('
'std::map<std::string, base::StringPiece>* schemas) {')
- for api in self._api_defs:
- namespace = self._model.namespaces[api.get('namespace')]
+ for api in self._bundle._api_defs:
+ namespace = self._bundle._model.namespaces[api.get('namespace')]
# JSON parsing code expects lists of schemas, so dump a singleton list.
json_content = json.dumps([_RemoveDescriptions(api)],
separators=(',', ':'))
@@ -204,6 +222,6 @@ class SchemaBundleGenerator(object):
c.Append('(*schemas)["%s"] = "%s";' % (namespace.name, json_content))
c.Eblock('}')
c.Append()
- c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
+ c.Concat(self._bundle._cpp_type_generator.GetRootNamespaceEnd())
c.Append()
return c

Powered by Google App Engine
This is Rietveld 408576698