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 in_generator |
| 36 import license |
| 37 |
| 38 |
| 39 IMPLEMENTATION_TEMPLATE = """%(license)s |
| 40 #include "config.h" |
| 41 #include "%(namespace)sFactory.h" |
| 42 |
| 43 #include "%(namespace)sHeaders.h" |
| 44 #include "RuntimeEnabledFeatures.h" |
| 45 |
| 46 namespace WebCore { |
| 47 |
| 48 PassRefPtr<%(namespace)s> %(namespace)sFactory::create(const String& type) |
| 49 { |
| 50 %(factory_implementation)s |
| 51 return 0; |
| 52 } |
| 53 |
| 54 } // namespace WebCore |
| 55 """ |
| 56 |
| 57 |
| 58 class EventFactoryWriter(in_generator.Writer): |
| 59 defaults = { |
| 60 'interfaceName' : None, |
| 61 'conditional' : None, |
| 62 'runtimeConditional': None, |
| 63 } |
| 64 default_parameters = { |
| 65 'namespace': '', |
| 66 } |
| 67 class_name = 'EventFactory' |
| 68 |
| 69 def _namespace(self): |
| 70 return self.in_file.parameters['namespace'] |
| 71 |
| 72 def _events(self): |
| 73 return self.in_file.name_dictionaries |
| 74 |
| 75 def _factory_implementation(self, event): |
| 76 runtime_condition = '' |
| 77 if event['runtimeConditional']: |
| 78 runtime_condition = ' && RuntimeEnabledFeatures::' + event['runtimeC
onditional'] + '()' |
| 79 name = os.path.basename(event['name']) |
| 80 interface_name = event['interfaceName'] if event['interfaceName'] else n
ame |
| 81 implementation = """ if (type == "%(name)s"%(runtime_condition)s) |
| 82 return %(interface_name)s::create();""" % { |
| 83 'name': name, |
| 84 'runtime_condition': runtime_condition, |
| 85 'interface_name': interface_name, |
| 86 } |
| 87 return self.wrap_with_condition(implementation, event['conditional']) |
| 88 |
| 89 def generate_header(self): |
| 90 pass |
| 91 |
| 92 def generate_implementation(self): |
| 93 return IMPLEMENTATION_TEMPLATE % { |
| 94 'namespace': self._namespace().strip('"'), |
| 95 'license': license.license_for_generated_cpp(), |
| 96 'factory_implementation': "\n".join(map(self._factory_implementation
, self._events())), |
| 97 } |
| 98 |
| 99 |
| 100 if __name__ == "__main__": |
| 101 in_generator.Maker(EventFactoryWriter).main(sys.argv) |
OLD | NEW |