| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 #!/usr/bin/env python |  | 
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. |  | 
| 3 # |  | 
| 4 # Redistribution and use in source and binary forms, with or without |  | 
| 5 # modification, are permitted provided that the following conditions are |  | 
| 6 # met: |  | 
| 7 # |  | 
| 8 #     * Redistributions of source code must retain the above copyright |  | 
| 9 # notice, this list of conditions and the following disclaimer. |  | 
| 10 #     * Redistributions in binary form must reproduce the above |  | 
| 11 # copyright notice, this list of conditions and the following disclaimer |  | 
| 12 # in the documentation and/or other materials provided with the |  | 
| 13 # distribution. |  | 
| 14 #     * Neither the name of Google Inc. nor the names of its |  | 
| 15 # contributors may be used to endorse or promote products derived from |  | 
| 16 # this software without specific prior written permission. |  | 
| 17 # |  | 
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |  | 
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |  | 
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |  | 
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |  | 
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |  | 
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |  | 
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |  | 
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |  | 
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |  | 
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |  | 
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |  | 
| 29 |  | 
| 30 import os.path |  | 
| 31 import sys |  | 
| 32 import shutil |  | 
| 33 |  | 
| 34 from in_file import InFile |  | 
| 35 import name_macros |  | 
| 36 from name_utilities import lower_first |  | 
| 37 import license |  | 
| 38 |  | 
| 39 |  | 
| 40 IMPLEMENTATION_TEMPLATE = """%(license)s |  | 
| 41 #include "config.h" |  | 
| 42 #include "core/events/%(class_name)sFactory.h" |  | 
| 43 |  | 
| 44 #include "%(class_name)sHeaders.h" |  | 
| 45 #include "RuntimeEnabledFeatures.h" |  | 
| 46 |  | 
| 47 namespace WebCore { |  | 
| 48 |  | 
| 49 PassRefPtr<%(class_name)s> %(class_name)sFactory::create(const String& type) |  | 
| 50 { |  | 
| 51 %(factory_implementation)s |  | 
| 52     return 0; |  | 
| 53 } |  | 
| 54 |  | 
| 55 } // namespace WebCore |  | 
| 56 """ |  | 
| 57 |  | 
| 58 |  | 
| 59 class EventFactoryWriter(name_macros.Writer): |  | 
| 60     defaults = { |  | 
| 61         'ImplementedAs': None, |  | 
| 62         'Conditional': None, |  | 
| 63         'EnabledAtRuntime': None, |  | 
| 64     } |  | 
| 65     default_parameters = { |  | 
| 66         'namespace': '', |  | 
| 67     } |  | 
| 68 |  | 
| 69     def __init__(self, in_file_path, enabled_conditions): |  | 
| 70         super(EventFactoryWriter, self).__init__(in_file_path, enabled_condition
     s) |  | 
| 71         self._outputs[(self.class_name + ".cpp")] = self.generate_implementation |  | 
| 72 |  | 
| 73     def _events(self): |  | 
| 74         return self.in_file.name_dictionaries |  | 
| 75 |  | 
| 76     def _factory_implementation(self, event): |  | 
| 77         if event['EnabledAtRuntime']: |  | 
| 78             runtime_condition = ' && RuntimeEnabledFeatures::%s()' % lower_first
     (event['EnabledAtRuntime']) |  | 
| 79         else: |  | 
| 80             runtime_condition = '' |  | 
| 81         name = os.path.basename(event['name']) |  | 
| 82         class_name = self._class_name_for_entry(event) |  | 
| 83         implementation = """    if (type == "%(name)s"%(runtime_condition)s) |  | 
| 84         return %(class_name)s::create();""" % { |  | 
| 85             'name': name, |  | 
| 86             'runtime_condition': runtime_condition, |  | 
| 87             'class_name': class_name, |  | 
| 88         } |  | 
| 89         return self.wrap_with_condition(implementation, event['Conditional']) |  | 
| 90 |  | 
| 91     def generate_implementation(self): |  | 
| 92         return IMPLEMENTATION_TEMPLATE % { |  | 
| 93             'class_name': self.class_name, |  | 
| 94             'license': license.license_for_generated_cpp(), |  | 
| 95             'factory_implementation': "\n".join(map(self._factory_implementation
     , self._events())), |  | 
| 96         } |  | 
| 97 |  | 
| 98 |  | 
| 99 if __name__ == "__main__": |  | 
| 100     name_macros.Maker(EventFactoryWriter).main(sys.argv) |  | 
| OLD | NEW | 
|---|