| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 import sys | 30 import sys |
| 31 | 31 |
| 32 import json5_generator | 32 import in_generator |
| 33 import trie_builder | 33 import trie_builder |
| 34 import template_expander | 34 import template_expander |
| 35 | 35 |
| 36 | 36 |
| 37 class ElementLookupTrieWriter(json5_generator.Writer): | 37 class ElementLookupTrieWriter(in_generator.Writer): |
| 38 # FIXME: Inherit all these from somewhere. | 38 # FIXME: Inherit all these from somewhere. |
| 39 defaults = { |
| 40 'JSInterfaceName': None, |
| 41 'constructorNeedsCreatedByParser': None, |
| 42 'interfaceName': None, |
| 43 'noConstructor': None, |
| 44 'runtimeEnabled': None, |
| 45 } |
| 39 default_parameters = { | 46 default_parameters = { |
| 40 'JSInterfaceName': {}, | |
| 41 'constructorNeedsCreatedByParser': {}, | |
| 42 'interfaceName': {}, | |
| 43 'noConstructor': {}, | |
| 44 'runtimeEnabled': {}, | |
| 45 } | |
| 46 default_metadata = { | |
| 47 'attrsNullNamespace': None, | 47 'attrsNullNamespace': None, |
| 48 'export': '', | 48 'export': '', |
| 49 'fallbackInterfaceName': '', | 49 'fallbackInterfaceName': '', |
| 50 'fallbackJSInterfaceName': '', | 50 'fallbackJSInterfaceName': '', |
| 51 'namespace': '', | 51 'namespace': '', |
| 52 'namespacePrefix': '', | 52 'namespacePrefix': '', |
| 53 'namespaceURI': '', | 53 'namespaceURI': '', |
| 54 } | 54 } |
| 55 | 55 |
| 56 def __init__(self, json5_file_paths): | 56 def __init__(self, in_file_paths): |
| 57 super(ElementLookupTrieWriter, self).__init__(json5_file_paths) | 57 super(ElementLookupTrieWriter, self).__init__(in_file_paths) |
| 58 self._tags = {} | 58 self._tags = {} |
| 59 for entry in self.json5_file.name_dictionaries: | 59 for entry in self.in_file.name_dictionaries: |
| 60 self._tags[entry['name']] = entry['name'] | 60 self._tags[entry['name']] = entry['name'] |
| 61 self._namespace = self.json5_file.metadata['namespace'].strip('"') | 61 self._namespace = self.in_file.parameters['namespace'].strip('"') |
| 62 self._outputs = { | 62 self._outputs = { |
| 63 (self._namespace + 'ElementLookupTrie.h'): self.generate_header, | 63 (self._namespace + 'ElementLookupTrie.h'): self.generate_header, |
| 64 (self._namespace + 'ElementLookupTrie.cpp'): self.generate_implement
ation, | 64 (self._namespace + 'ElementLookupTrie.cpp'): self.generate_implement
ation, |
| 65 } | 65 } |
| 66 | 66 |
| 67 @template_expander.use_jinja('ElementLookupTrie.h.tmpl') | 67 @template_expander.use_jinja('ElementLookupTrie.h.tmpl') |
| 68 def generate_header(self): | 68 def generate_header(self): |
| 69 return { | 69 return { |
| 70 'namespace': self._namespace, | 70 'namespace': self._namespace, |
| 71 } | 71 } |
| 72 | 72 |
| 73 @template_expander.use_jinja('ElementLookupTrie.cpp.tmpl') | 73 @template_expander.use_jinja('ElementLookupTrie.cpp.tmpl') |
| 74 def generate_implementation(self): | 74 def generate_implementation(self): |
| 75 return { | 75 return { |
| 76 'namespace': self._namespace, | 76 'namespace': self._namespace, |
| 77 'length_tries': trie_builder.trie_list_by_str_length(self._tags) | 77 'length_tries': trie_builder.trie_list_by_str_length(self._tags) |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 if __name__ == '__main__': | 81 if __name__ == '__main__': |
| 82 json5_generator.Maker(ElementLookupTrieWriter).main() | 82 in_generator.Maker(ElementLookupTrieWriter).main(sys.argv) |
| OLD | NEW |