| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 import re | 30 import re |
| 31 | 31 |
| 32 from in_generator import Maker | 32 from in_generator import Maker |
| 33 import in_generator | 33 import in_generator |
| 34 import license | 34 import license |
| 35 import name_utilities | 35 import name_utilities |
| 36 | 36 |
| 37 | 37 |
| 38 HEADER_TEMPLATE = """%(license)s | 38 HEADER_TEMPLATE = """%(license)s |
| 39 | 39 |
| 40 #ifndef %(namespace)sHeaders_h | 40 #ifndef %(namespace)s%(suffix)sHeaders_h |
| 41 #define %(namespace)sHeaders_h | 41 #define %(namespace)s%(suffix)sHeaders_h |
| 42 | 42 %(base_header_for_suffix)s |
| 43 %(includes)s | 43 %(includes)s |
| 44 | 44 |
| 45 #endif // %(namespace)sHeaders_h | 45 #endif // %(namespace)s%(suffix)sHeaders_h |
| 46 """ | 46 """ |
| 47 | 47 |
| 48 | 48 |
| 49 INTERFACES_HEADER_TEMPLATE = """%(license)s | 49 INTERFACES_HEADER_TEMPLATE = """%(license)s |
| 50 | 50 |
| 51 #ifndef %(namespace)sInterfaces_h | 51 #ifndef %(namespace)s%(suffix)sInterfaces_h |
| 52 #define %(namespace)sInterfaces_h | 52 #define %(namespace)s%(suffix)sInterfaces_h |
| 53 | 53 %(base_header_for_suffix)s |
| 54 %(declare_conditional_macros)s | 54 %(declare_conditional_macros)s |
| 55 | 55 |
| 56 #define %(macro_style_name)s_INTERFACES_FOR_EACH(macro) \\ | 56 #define %(macro_style_name)s_INTERFACES_FOR_EACH(macro) \\ |
| 57 \\ | 57 \\ |
| 58 %(unconditional_macros)s | 58 %(unconditional_macros)s |
| 59 \\ | 59 \\ |
| 60 %(conditional_macros)s | 60 %(conditional_macros)s |
| 61 | 61 |
| 62 #endif // %(namespace)sInterfaces_h | 62 #endif // %(namespace)s%(suffix)sInterfaces_h |
| 63 """ | 63 """ |
| 64 | 64 |
| 65 | 65 |
| 66 class Writer(in_generator.Writer): | 66 class Writer(in_generator.Writer): |
| 67 def __init__(self, in_file_path): | 67 def __init__(self, in_file_path): |
| 68 super(Writer, self).__init__(in_file_path) | 68 super(Writer, self).__init__(in_file_path) |
| 69 self.namespace = self.in_file.parameters['namespace'].strip('"') | 69 self.namespace = self.in_file.parameters['namespace'].strip('"') |
| 70 self.suffix = self.in_file.parameters['suffix'].strip('"') |
| 70 self._entries_by_conditional = {} | 71 self._entries_by_conditional = {} |
| 71 self._unconditional_entries = [] | 72 self._unconditional_entries = [] |
| 72 self._validate_entries() | 73 self._validate_entries() |
| 73 self._sort_entries_by_conditional() | 74 self._sort_entries_by_conditional() |
| 74 self._outputs = {(self.namespace + "Headers.h"): self.generate_headers_h
eader, | 75 self._outputs = {(self.namespace + self.suffix + "Headers.h"): self.gene
rate_headers_header, |
| 75 (self.namespace + "Interfaces.h"): self.generate_interf
aces_header, | 76 (self.namespace + self.suffix + "Interfaces.h"): self.g
enerate_interfaces_header, |
| 76 } | 77 } |
| 77 | 78 |
| 78 def _validate_entries(self): | 79 def _validate_entries(self): |
| 79 # If there is more than one entry with the same script name, only the fi
rst one will ever | 80 # If there is more than one entry with the same script name, only the fi
rst one will ever |
| 80 # be hit in practice, and so we'll silently ignore any properties reques
ted for the second | 81 # be hit in practice, and so we'll silently ignore any properties reques
ted for the second |
| 81 # (like RuntimeEnabled - see crbug.com/332588). | 82 # (like RuntimeEnabled - see crbug.com/332588). |
| 82 entries_by_script_name = dict() | 83 entries_by_script_name = dict() |
| 83 for entry in self.in_file.name_dictionaries: | 84 for entry in self.in_file.name_dictionaries: |
| 84 script_name = name_utilities.script_name(entry) | 85 script_name = name_utilities.script_name(entry) |
| 85 if script_name in entries_by_script_name: | 86 if script_name in entries_by_script_name: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if cpp_name in includes: | 132 if cpp_name in includes: |
| 132 continue | 133 continue |
| 133 include = '#include "%(path)s"\n#include "V8%(script_name)s.h"' % { | 134 include = '#include "%(path)s"\n#include "V8%(script_name)s.h"' % { |
| 134 'path': self._headers_header_include_path(entry), | 135 'path': self._headers_header_include_path(entry), |
| 135 'script_name': name_utilities.script_name(entry), | 136 'script_name': name_utilities.script_name(entry), |
| 136 } | 137 } |
| 137 includes[cpp_name] = self.wrap_with_condition(include, entry['Condit
ional']) | 138 includes[cpp_name] = self.wrap_with_condition(include, entry['Condit
ional']) |
| 138 return includes.values() | 139 return includes.values() |
| 139 | 140 |
| 140 def generate_headers_header(self): | 141 def generate_headers_header(self): |
| 142 base_header_for_suffix = '' |
| 143 if self.suffix: |
| 144 base_header_for_suffix = '\n#include "%(namespace)sHeaders.h"\n' % {
'namespace': self.namespace} |
| 141 return HEADER_TEMPLATE % { | 145 return HEADER_TEMPLATE % { |
| 142 'license': license.license_for_generated_cpp(), | 146 'license': license.license_for_generated_cpp(), |
| 143 'namespace': self.namespace, | 147 'namespace': self.namespace, |
| 148 'suffix': self.suffix, |
| 149 'base_header_for_suffix': base_header_for_suffix, |
| 144 'includes': '\n'.join(self._headers_header_includes(self.in_file.nam
e_dictionaries)), | 150 'includes': '\n'.join(self._headers_header_includes(self.in_file.nam
e_dictionaries)), |
| 145 } | 151 } |
| 146 | 152 |
| 147 def _declare_one_conditional_macro(self, conditional, entries): | 153 def _declare_one_conditional_macro(self, conditional, entries): |
| 148 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s'
% { | 154 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s'
% { |
| 149 'macro_style_name': name_utilities.to_macro_style(self.namespace), | 155 'macro_style_name': name_utilities.to_macro_style(self.namespace + s
elf.suffix), |
| 150 'conditional': conditional, | 156 'conditional': conditional, |
| 151 } | 157 } |
| 152 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\ | 158 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\ |
| 153 %(declarations)s | 159 %(declarations)s |
| 154 | 160 |
| 155 #else | 161 #else |
| 156 #define %(macro_name)s(macro)""" % { | 162 #define %(macro_name)s(macro)""" % { |
| 157 'macro_name': macro_name, | 163 'macro_name': macro_name, |
| 158 'declarations': '\n'.join(sorted(set([ | 164 'declarations': '\n'.join(sorted(set([ |
| 159 ' macro(%(cpp_name)s) \\' % {'cpp_name': name_utilities.cpp_n
ame(entry)} | 165 ' macro(%(cpp_name)s) \\' % {'cpp_name': name_utilities.cpp_n
ame(entry)} |
| 160 for entry in entries]))), | 166 for entry in entries]))), |
| 161 }, conditional) | 167 }, conditional) |
| 162 | 168 |
| 163 def _declare_conditional_macros(self): | 169 def _declare_conditional_macros(self): |
| 164 return '\n'.join([ | 170 return '\n'.join([ |
| 165 self._declare_one_conditional_macro(conditional, entries) | 171 self._declare_one_conditional_macro(conditional, entries) |
| 166 for conditional, entries in self._entries_by_conditional.items()]) | 172 for conditional, entries in self._entries_by_conditional.items()]) |
| 167 | 173 |
| 168 def _unconditional_macro(self, entry): | 174 def _unconditional_macro(self, entry): |
| 169 return ' macro(%(cpp_name)s) \\' % {'cpp_name': name_utilities.cpp_na
me(entry)} | 175 return ' macro(%(cpp_name)s) \\' % {'cpp_name': name_utilities.cpp_na
me(entry)} |
| 170 | 176 |
| 171 def _conditional_macros(self, conditional): | 177 def _conditional_macros(self, conditional): |
| 172 return ' %(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s(mac
ro) \\' % { | 178 return ' %(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s(mac
ro) \\' % { |
| 173 'macro_style_name': name_utilities.to_macro_style(self.namespace), | 179 'macro_style_name': name_utilities.to_macro_style(self.namespace + s
elf.suffix), |
| 174 'conditional': conditional, | 180 'conditional': conditional, |
| 175 } | 181 } |
| 176 | 182 |
| 177 def generate_interfaces_header(self): | 183 def generate_interfaces_header(self): |
| 184 base_header_for_suffix = '' |
| 185 if self.suffix: |
| 186 base_header_for_suffix = '\n#include "%(namespace)sInterfaces.h"\n'
% {'namespace': self.namespace} |
| 178 return INTERFACES_HEADER_TEMPLATE % { | 187 return INTERFACES_HEADER_TEMPLATE % { |
| 179 'license': license.license_for_generated_cpp(), | 188 'license': license.license_for_generated_cpp(), |
| 180 'namespace': self.namespace, | 189 'namespace': self.namespace, |
| 181 'macro_style_name': name_utilities.to_macro_style(self.namespace), | 190 'suffix': self.suffix, |
| 191 'base_header_for_suffix': base_header_for_suffix, |
| 192 'macro_style_name': name_utilities.to_macro_style(self.namespace + s
elf.suffix), |
| 182 'declare_conditional_macros': self._declare_conditional_macros(), | 193 'declare_conditional_macros': self._declare_conditional_macros(), |
| 183 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional
_macro, self._unconditional_entries)))), | 194 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional
_macro, self._unconditional_entries)))), |
| 184 'conditional_macros': '\n'.join(map(self._conditional_macros, self._
entries_by_conditional.keys())), | 195 'conditional_macros': '\n'.join(map(self._conditional_macros, self._
entries_by_conditional.keys())), |
| 185 } | 196 } |
| OLD | NEW |