OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from model import PropertyType |
| 6 import code |
| 7 import cpp_util |
| 8 import model |
| 9 |
| 10 SOURCE_BASE_PATH = 'chrome/common/extensions/api' |
| 11 |
| 12 class HBundleGenerator(object): |
| 13 """A .h generator for namespace bundle functionality. |
| 14 """ |
| 15 def __init__(self, model, cpp_type_generator): |
| 16 self._cpp_type_generator = cpp_type_generator |
| 17 self._model = model |
| 18 |
| 19 def Generate(self): |
| 20 """Generates a code.Code object with the .h for a bundle. |
| 21 """ |
| 22 c = code.Code() |
| 23 (c.Append(cpp_util.CHROMIUM_LICENSE) |
| 24 .Append() |
| 25 .Append(cpp_util.GENERATED_BUNDLE_FILE_MESSAGE % SOURCE_BASE_PATH) |
| 26 .Append() |
| 27 ) |
| 28 |
| 29 ifndef_name = cpp_util.GenerateIfndefName(SOURCE_BASE_PATH, |
| 30 'generated_api') |
| 31 (c.Append('#ifndef %s' % ifndef_name) |
| 32 .Append('#define %s' % ifndef_name) |
| 33 .Append('#pragma once') |
| 34 .Append() |
| 35 .Append('#include <string>') |
| 36 .Append() |
| 37 .Append('#include "base/basictypes.h"')) |
| 38 |
| 39 for namespace in self._model.namespaces.values(): |
| 40 namespace_name = namespace.name.replace( |
| 41 "experimental.", "") |
| 42 c.Append('#include "chrome/browser/extensions/api/%s/%s_api.h"' % ( |
| 43 namespace_name, namespace_name)) |
| 44 |
| 45 (c.Append() |
| 46 .Append("class ExtensionFunctionRegistry;") |
| 47 .Append()) |
| 48 |
| 49 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) |
| 50 |
| 51 for namespace in self._model.namespaces.values(): |
| 52 c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name)) |
| 53 c.Append() |
| 54 |
| 55 c.Concat(self.GenerateFunctionRegistry()) |
| 56 |
| 57 (c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) |
| 58 .Append() |
| 59 .Append('#endif // %s' % ifndef_name) |
| 60 .Append() |
| 61 ) |
| 62 return c |
| 63 |
| 64 def GenerateFunctionRegistry(self): |
| 65 c = code.Code() |
| 66 c.Sblock("class GeneratedFunctionRegistry {") |
| 67 c.Append("public:") |
| 68 c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {") |
| 69 for namespace in self._model.namespaces.values(): |
| 70 for function in namespace.functions.values(): |
| 71 namespace_name = namespace.name.replace( |
| 72 "experimental.", "").capitalize() |
| 73 function_name = namespace_name + function.name.capitalize() |
| 74 c.Append("registry->RegisterFunction<%sFunction>();" % ( |
| 75 function_name)) |
| 76 c.Eblock("}") |
| 77 c.Eblock("};") |
| 78 c.Append() |
| 79 return c |
OLD | NEW |