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

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: 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
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): 70 def _class_name_for_entry(entry):
71 if entry['interfaceName']: 71 if entry['implementedAs']:
72 return entry['interfaceName'] 72 return entry['implementedAs']
73 return os.path.basename(entry['name']) 73 return os.path.basename(entry['name'])
74 74
75 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): 76 class Writer(in_generator.Writer):
82 def __init__(self, in_file_path, enabled_conditions): 77 def __init__(self, in_file_path, enabled_conditions):
83 super(Writer, self).__init__(in_file_path, enabled_conditions) 78 super(Writer, self).__init__(in_file_path, enabled_conditions)
84 self.class_name = self.in_file.parameters['namespace'].strip('"') 79 self.class_name = self.in_file.parameters['namespace'].strip('"')
85 self._entries_by_conditional = {} 80 self._entries_by_conditional = {}
86 self._unconditional_entries = [] 81 self._unconditional_entries = []
87 self._sort_entries_by_conditional() 82 self._sort_entries_by_conditional()
88 self._outputs = {(self.class_name + "Headers.h"): self.generate_headers_ header, 83 self._outputs = {(self.class_name + "Headers.h"): self.generate_headers_ header,
89 (self.class_name + "Interfaces.h"): self.generate_inter faces_header, 84 (self.class_name + "Interfaces.h"): self.generate_inter faces_header,
90 } 85 }
91 86
92 def _sort_entries_by_conditional(self): 87 def _sort_entries_by_conditional(self):
93 unconditional_names = set() 88 unconditional_names = set()
94 for entry in self.in_file.name_dictionaries: 89 for entry in self.in_file.name_dictionaries:
95 conditional = entry['conditional'] 90 conditional = entry['conditional']
96 if not conditional: 91 if not conditional:
97 name = _name_for_entry(entry) 92 name = _class_name_for_entry(entry)
98 if name in unconditional_names: 93 if name in unconditional_names:
99 continue 94 continue
100 unconditional_names.add(name) 95 unconditional_names.add(name)
101 self._unconditional_entries.append(entry) 96 self._unconditional_entries.append(entry)
102 continue 97 continue
103 for entry in self.in_file.name_dictionaries: 98 for entry in self.in_file.name_dictionaries:
104 name = _name_for_entry(entry) 99 name = _class_name_for_entry(entry)
105 if name in unconditional_names: 100 if name in unconditional_names:
106 continue 101 continue
107 conditional = entry['conditional'] 102 conditional = entry['conditional']
108 if not conditional in self._entries_by_conditional: 103 if not conditional in self._entries_by_conditional:
109 self._entries_by_conditional[conditional] = [] 104 self._entries_by_conditional[conditional] = []
110 self._entries_by_conditional[conditional].append(entry) 105 self._entries_by_conditional[conditional].append(entry)
111 106
112 def _headers_header_include(self, entry): 107 def _headers_header_include_path(self, entry):
113 path = entry['name'] 108 if entry['implementedAs']:
114 js_name = _js_name_for_entry(entry) 109 path = os.path.dirname(entry['name'])
115 if entry['interfaceName']: 110 if len(path):
116 path = entry['interfaceName'] # FIXME: This seems wrong 111 path += '/'
117 include = '#include "%(path)s.h"\n#include "V8%(js_name)s.h"' % { 112 path += entry['implementedAs']
118 'path': path, 113 else:
119 'js_name': js_name, 114 path = entry['name']
120 } 115 return path + '.h'
121 return self.wrap_with_condition(include, entry['conditional']) 116
117 def _headers_header_includes(self, entries):
118 includes = dict()
119 for entry in entries:
120 class_name = _class_name_for_entry(entry)
121 # Avoid duplicate includes.
122 if class_name in includes:
123 continue
124 include = '#include "%(path)s"\n#include "V8%(js_name)s.h"' % {
125 'path': self._headers_header_include_path(entry),
126 'js_name': os.path.basename(entry['name']),
127 }
128 includes[class_name] = self.wrap_with_condition(include, entry['cond itional'])
129 return includes.values()
122 130
123 def generate_headers_header(self): 131 def generate_headers_header(self):
124 return HEADER_TEMPLATE % { 132 return HEADER_TEMPLATE % {
125 'license': license.license_for_generated_cpp(), 133 'license': license.license_for_generated_cpp(),
126 'class_name': self.class_name, 134 'class_name': self.class_name,
127 'includes': '\n'.join(map(self._headers_header_include, self.in_file .name_dictionaries)), 135 'includes': '\n'.join(self._headers_header_includes(self.in_file.nam e_dictionaries)),
128 } 136 }
129 137
130 def _declare_one_conditional_macro(self, conditional, entries): 138 def _declare_one_conditional_macro(self, conditional, entries):
131 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s' % { 139 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s' % {
132 'macro_style_name': _to_macro_style(self.class_name), 140 'macro_style_name': _to_macro_style(self.class_name),
133 'conditional': conditional, 141 'conditional': conditional,
134 } 142 }
135 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\ 143 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\
136 %(declarations)s 144 %(declarations)s
137 145
138 #else 146 #else
139 #define %(macro_name)s(macro)""" % { 147 #define %(macro_name)s(macro)""" % {
140 'macro_name': macro_name, 148 'macro_name': macro_name,
141 'declarations': '\n'.join(sorted(set([ 149 'declarations': '\n'.join(sorted(set([
142 ' macro(%(name)s) \\' % {'name': _name_for_entry(entry)} 150 ' macro(%(name)s) \\' % {'name': _class_name_for_entry(entry) }
143 for entry in entries]))), 151 for entry in entries]))),
144 }, conditional) 152 }, conditional)
145 153
146 def _declare_conditional_macros(self): 154 def _declare_conditional_macros(self):
147 return '\n'.join([ 155 return '\n'.join([
148 self._declare_one_conditional_macro(conditional, entries) 156 self._declare_one_conditional_macro(conditional, entries)
149 for conditional, entries in self._entries_by_conditional.items()]) 157 for conditional, entries in self._entries_by_conditional.items()])
150 158
151 def _unconditional_macro(self, entry): 159 def _unconditional_macro(self, entry):
152 return ' macro(%(name)s) \\' % {'name': _name_for_entry(entry)} 160 return ' macro(%(name)s) \\' % {'name': _class_name_for_entry(entry)}
153 161
154 def _conditional_macros(self, conditional): 162 def _conditional_macros(self, conditional):
155 return ' %(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s(mac ro) \\' % { 163 return ' %(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s(mac ro) \\' % {
156 'macro_style_name': _to_macro_style(self.class_name), 164 'macro_style_name': _to_macro_style(self.class_name),
157 'conditional': conditional, 165 'conditional': conditional,
158 } 166 }
159 167
160 def generate_interfaces_header(self): 168 def generate_interfaces_header(self):
161 return INTERFACES_HEADER_TEMPLATE % { 169 return INTERFACES_HEADER_TEMPLATE % {
162 'license': license.license_for_generated_cpp(), 170 'license': license.license_for_generated_cpp(),
163 'class_name': self.class_name, 171 'class_name': self.class_name,
164 'macro_style_name': _to_macro_style(self.class_name), 172 'macro_style_name': _to_macro_style(self.class_name),
165 'declare_conditional_macros': self._declare_conditional_macros(), 173 'declare_conditional_macros': self._declare_conditional_macros(),
166 'unconditional_macros': '\n'.join(sorted(set(map(self._unconditional _macro, self._unconditional_entries)))), 174 '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())), 175 'conditional_macros': '\n'.join(map(self._conditional_macros, self._ entries_by_conditional.keys())),
168 } 176 }
OLDNEW
« Source/core/scripts/make_event_factory.py ('K') | « 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