def testJsFunctionNameToClassName(self): self.assertEquals('FooBar', JsFunctionNameToClassName('foo', 'bar')) self.assertEquals('FooBar', JsFunctionNameToClassName('experimental.foo', 'bar')) self.assertEquals('FooBarBaz', JsFunctionNameToClassName('foo.bar', 'baz')) self.assertEquals( 'FooBarBaz', JsFunctionNameToClassName('experimental.foo.bar', 'baz'))
def _GenerateFunctionRegistryRegisterAll(self): c = code.Code() c.Append('// static') c.Sblock( 'void %s::RegisterAll(ExtensionFunctionRegistry* registry) {' % self._GenerateBundleClass('GeneratedFunctionRegistry')) for namespace in self._model.namespaces.values(): namespace_ifdefs = self._GetPlatformIfdefs(namespace) if namespace_ifdefs is not None: c.Append("#if %s" % namespace_ifdefs, indent_level=0) for function in namespace.functions.values(): if function.nocompile: continue c.Concat( self._GenerateRegisterFunctions(namespace.name, function)) for type_ in namespace.types.values(): for function in type_.functions.values(): if function.nocompile: continue namespace_types_name = JsFunctionNameToClassName( namespace.name, type_.name) c.Concat( self._GenerateRegisterFunctions( namespace_types_name, function)) if namespace_ifdefs is not None: c.Append("#endif // %s" % namespace_ifdefs, indent_level=0) c.Eblock("}") return c
def _GenerateFunctionRegistryRegisterAll(self): c = code.Code() c.Append('// static') c.Sblock('void GeneratedFunctionRegistry::RegisterAll(' 'ExtensionFunctionRegistry* registry) {') for namespace in self._model.namespaces.values(): namespace_ifdefs = self._GetPlatformIfdefs(namespace) if namespace_ifdefs is not None: c.Append("#if %s" % namespace_ifdefs, indent_level=0) namespace_name = CapitalizeFirstLetter( namespace.name.replace("experimental.", "")) for function in namespace.functions.values(): if function.nocompile: continue c.Concat( self._GenerateRegisterFunctions(namespace.name, function)) for type_ in namespace.types.values(): for function in type_.functions.values(): if function.nocompile: continue namespace_types_name = JsFunctionNameToClassName( namespace.name, type_.name) c.Concat( self._GenerateRegisterFunctions( namespace_types_name, function)) if namespace_ifdefs is not None: c.Append("#endif // %s" % namespace_ifdefs, indent_level=0) c.Eblock("}") return c
def _GenerateRegisterFunctions(self, namespace_name, function): c = code.Code() function_ifdefs = self._GetPlatformIfdefs(function) if function_ifdefs is not None: c.Append("#if %s" % function_ifdefs, indent_level=0) function_name = JsFunctionNameToClassName(namespace_name, function.name) c.Append("registry->RegisterFunction<%sFunction>();" % (function_name)) if function_ifdefs is not None: c.Append("#endif // %s" % function_ifdefs, indent_level=0) return c
def _GenerateRegistrationEntry(self, namespace_name, function): c = code.Code() function_ifdefs = self._GetPlatformIfdefs(function) if function_ifdefs is not None: c.Append("#if %s" % function_ifdefs, indent_level=0) function_name = '%sFunction' % JsFunctionNameToClassName( namespace_name, function.name) c.Sblock('{') c.Append('&NewExtensionFunction<%s>,' % function_name) c.Append('%s::static_function_name(),' % function_name) c.Append('%s::static_histogram_value(),' % function_name) c.Eblock('},') if function_ifdefs is not None: c.Append("#endif // %s" % function_ifdefs, indent_level=0) return c
def GenerateFunctionRegistry(self): c = code.Code() c.Sblock("class GeneratedFunctionRegistry {") c.Append("public:") c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {") for namespace in self._model.namespaces.values(): namespace_name = CapitalizeFirstLetter(namespace.name.replace( "experimental.", "")) for function in namespace.functions.values(): if function.nocompile: continue function_name = JsFunctionNameToClassName(namespace.name, function.name) c.Append("registry->RegisterFunction<%sFunction>();" % ( function_name)) c.Eblock("}") c.Eblock("};") c.Append() return c