1#!/usr/bin/env python 2# Copyright (C) 2013 Google Inc. All rights reserved. 3# Copyright (C) 2013 Igalia S.L. All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: 8# 9# * Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# * Redistributions in binary form must reproduce the above 12# copyright notice, this list of conditions and the following disclaimer 13# in the documentation and/or other materials provided with the 14# distribution. 15# * Neither the name of Google Inc. nor the names of its 16# contributors may be used to endorse or promote products derived from 17# this software without specific prior written permission. 18# 19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31import sys 32 33import json5_generator 34import name_utilities 35import template_expander 36 37 38def to_passing_type(typename): 39 if typename == 'String': 40 return 'const String&' 41 return typename 42 43 44def to_idl_type(typename): 45 if typename == 'int': 46 return 'long' 47 if typename == 'unsigned' or typename == 'size_t': 48 return 'unsigned long' 49 if typename == 'String': 50 return 'DOMString' 51 if typename == 'bool': 52 return 'boolean' 53 if typename == 'double': 54 return 'double' 55 return None 56 57 58class MakeSettingsWriter(json5_generator.Writer): 59 filters = { 60 'cpp_bool': name_utilities.cpp_bool, 61 'to_passing_type': to_passing_type, 62 'to_idl_type': to_idl_type, 63 } 64 65 def __init__(self, json5_file_path, output_dir): 66 super(MakeSettingsWriter, self).__init__(json5_file_path, output_dir) 67 68 self.json5_file.name_dictionaries.sort( 69 key=lambda entry: entry['name'].original) 70 71 self._outputs = { 72 ('settings_macros.h'): self.generate_macros, 73 } 74 self._template_context = { 75 'input_files': 76 self._input_files, 77 'settings': 78 self.json5_file.name_dictionaries, 79 'header_guard': 80 self.make_header_guard(self._relative_output_dir + 81 'settings_macros.h') 82 } 83 84 @template_expander.use_jinja( 85 'templates/settings_macros.h.tmpl', filters=filters) 86 def generate_macros(self): 87 return self._template_context 88 89 90if __name__ == '__main__': 91 json5_generator.Maker(MakeSettingsWriter).main() 92