Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: Source/core/scripts/name_macros.py

Issue 17271002: Clean up *.in files related to DOM exceptions and events (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix order in EventTargetFactory.in Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/scripts/make_event_factory.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 #endif // %(class_name)sInterfaces_h 61 #endif // %(class_name)sInterfaces_h
62 """ 62 """
63 63
64 64
65 def _to_macro_style(name): 65 def _to_macro_style(name):
66 s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) 66 s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
67 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper() 67 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper()
68 68
69 69
70 def _name_for_entry(entry):
71 if entry['interfaceName']:
72 return entry['interfaceName']
73 return os.path.basename(entry['name'])
74
75
76 def _js_name_for_entry(entry):
77 if entry['JSInterfaceName']:
78 return entry['JSInterfaceName']
79 return _name_for_entry(entry)
80
81 class Writer(in_generator.Writer): 70 class Writer(in_generator.Writer):
82 def __init__(self, in_file_path, enabled_conditions): 71 def __init__(self, in_file_path, enabled_conditions):
83 super(Writer, self).__init__(in_file_path, enabled_conditions) 72 super(Writer, self).__init__(in_file_path, enabled_conditions)
84 self.class_name = self.in_file.parameters['namespace'].strip('"') 73 self.class_name = self.in_file.parameters['namespace'].strip('"')
85 self._entries_by_conditional = {} 74 self._entries_by_conditional = {}
86 self._unconditional_entries = [] 75 self._unconditional_entries = []
87 self._sort_entries_by_conditional() 76 self._sort_entries_by_conditional()
88 self._outputs = {(self.class_name + "Headers.h"): self.generate_headers_ header, 77 self._outputs = {(self.class_name + "Headers.h"): self.generate_headers_ header,
89 (self.class_name + "Interfaces.h"): self.generate_inter faces_header, 78 (self.class_name + "Interfaces.h"): self.generate_inter faces_header,
90 } 79 }
91 80
92 def _sort_entries_by_conditional(self): 81 def _sort_entries_by_conditional(self):
93 unconditional_names = set() 82 unconditional_names = set()
94 for entry in self.in_file.name_dictionaries: 83 for entry in self.in_file.name_dictionaries:
95 conditional = entry['conditional'] 84 conditional = entry['conditional']
96 if not conditional: 85 if not conditional:
97 name = _name_for_entry(entry) 86 name = self._class_name_for_entry(entry)
98 if name in unconditional_names: 87 if name in unconditional_names:
99 continue 88 continue
100 unconditional_names.add(name) 89 unconditional_names.add(name)
101 self._unconditional_entries.append(entry) 90 self._unconditional_entries.append(entry)
102 continue 91 continue
103 for entry in self.in_file.name_dictionaries: 92 for entry in self.in_file.name_dictionaries:
104 name = _name_for_entry(entry) 93 name = self._class_name_for_entry(entry)
105 if name in unconditional_names: 94 if name in unconditional_names:
106 continue 95 continue
107 conditional = entry['conditional'] 96 conditional = entry['conditional']
108 if not conditional in self._entries_by_conditional: 97 if not conditional in self._entries_by_conditional:
109 self._entries_by_conditional[conditional] = [] 98 self._entries_by_conditional[conditional] = []
110 self._entries_by_conditional[conditional].append(entry) 99 self._entries_by_conditional[conditional].append(entry)
111 100
112 def _headers_header_include(self, entry): 101 def _class_name_for_entry(self, entry):
113 path = entry['name'] 102 if entry['implementedAs']:
114 js_name = _js_name_for_entry(entry) 103 return entry['implementedAs']
115 if entry['interfaceName']: 104 return os.path.basename(entry['name'])
116 path = entry['interfaceName'] # FIXME: This seems wrong 105
117 include = '#include "%(path)s.h"\n#include "V8%(js_name)s.h"' % { 106 def _headers_header_include_path(self, entry):
118 'path': path, 107 if entry['implementedAs']:
119 'js_name': js_name, 108 path = os.path.dirname(entry['name'])
120 } 109 if len(path):
121 return self.wrap_with_condition(include, entry['conditional']) 110 path += '/'
111 path += entry['implementedAs']
112 else:
113 path = entry['name']
114 return path + '.h'
115
116 def _headers_header_includes(self, entries):
117 includes = dict()
118 for entry in entries:
119 class_name = self._class_name_for_entry(entry)
120 # Avoid duplicate includes.
121 if class_name in includes:
122 continue
123 include = '#include "%(path)s"\n#include "V8%(js_name)s.h"' % {
124 'path': self._headers_header_include_path(entry),
125 'js_name': os.path.basename(entry['name']),
126 }
127 includes[class_name] = self.wrap_with_condition(include, entry['cond itional'])
128 return includes.values()
122 129
123 def generate_headers_header(self): 130 def generate_headers_header(self):
124 return HEADER_TEMPLATE % { 131 return HEADER_TEMPLATE % {
125 'license': license.license_for_generated_cpp(), 132 'license': license.license_for_generated_cpp(),
126 'class_name': self.class_name, 133 'class_name': self.class_name,
127 'includes': '\n'.join(map(self._headers_header_include, self.in_file .name_dictionaries)), 134 'includes': '\n'.join(self._headers_header_includes(self.in_file.nam e_dictionaries)),
128 } 135 }
129 136
130 def _declare_one_conditional_macro(self, conditional, entries): 137 def _declare_one_conditional_macro(self, conditional, entries):
131 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s' % { 138 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s' % {
132 'macro_style_name': _to_macro_style(self.class_name), 139 'macro_style_name': _to_macro_style(self.class_name),
133 'conditional': conditional, 140 'conditional': conditional,
134 } 141 }
135 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\ 142 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\
136 %(declarations)s 143 %(declarations)s
137 144
138 #else 145 #else
139 #define %(macro_name)s(macro)""" % { 146 #define %(macro_name)s(macro)""" % {
140 'macro_name': macro_name, 147 'macro_name': macro_name,
141 'declarations': '\n'.join(sorted(set([ 148 'declarations': '\n'.join(sorted(set([
142 ' macro(%(name)s) \\' % {'name': _name_for_entry(entry)} 149 ' macro(%(name)s) \\' % {'name': self._class_name_for_entry(e ntry)}
143 for entry in entries]))), 150 for entry in entries]))),
144 }, conditional) 151 }, conditional)
145 152
146 def _declare_conditional_macros(self): 153 def _declare_conditional_macros(self):
147 return '\n'.join([ 154 return '\n'.join([
148 self._declare_one_conditional_macro(conditional, entries) 155 self._declare_one_conditional_macro(conditional, entries)
149 for conditional, entries in self._entries_by_conditional.items()]) 156 for conditional, entries in self._entries_by_conditional.items()])
150 157
151 def _unconditional_macro(self, entry): 158 def _unconditional_macro(self, entry):
152 return ' macro(%(name)s) \\' % {'name': _name_for_entry(entry)} 159 return ' macro(%(name)s) \\' % {'name': self._class_name_for_entry(en try)}
153 160
154 def _conditional_macros(self, conditional): 161 def _conditional_macros(self, conditional):
155 return ' %(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s(mac ro) \\' % { 162 return ' %(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s(mac ro) \\' % {
156 'macro_style_name': _to_macro_style(self.class_name), 163 'macro_style_name': _to_macro_style(self.class_name),
157 'conditional': conditional, 164 'conditional': conditional,
158 } 165 }
159 166
160 def generate_interfaces_header(self): 167 def generate_interfaces_header(self):
161 return INTERFACES_HEADER_TEMPLATE % { 168 return INTERFACES_HEADER_TEMPLATE % {
162 'license': license.license_for_generated_cpp(), 169 'license': license.license_for_generated_cpp(),
163 'class_name': self.class_name, 170 'class_name': self.class_name,
164 'macro_style_name': _to_macro_style(self.class_name), 171 'macro_style_name': _to_macro_style(self.class_name),
165 'declare_conditional_macros': self._declare_conditional_macros(), 172 'declare_conditional_macros': self._declare_conditional_macros(),
166 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional _macro, self._unconditional_entries)))), 173 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional _macro, self._unconditional_entries)))),
167 'conditional_macros': '\n'.join(map(self._conditional_macros, self._ entries_by_conditional.keys())), 174 'conditional_macros': '\n'.join(map(self._conditional_macros, self._ entries_by_conditional.keys())),
168 } 175 }
OLDNEW
« no previous file with comments | « Source/core/scripts/make_event_factory.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698