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

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

Issue 19605006: Roll IDL to multivm@1316 (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 7 years, 5 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 | « core/scripts/make_style_builder.py ('k') | core/scripts/rule_bison.py » ('j') | 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 class Writer(in_generator.Writer): 70 class Writer(in_generator.Writer):
76 def __init__(self, in_file_path, enabled_conditions): 71 def __init__(self, in_file_path, enabled_conditions):
77 super(Writer, self).__init__(in_file_path, enabled_conditions) 72 super(Writer, self).__init__(in_file_path, enabled_conditions)
78 self.class_name = self.in_file.parameters['namespace'].strip('"') 73 self.class_name = self.in_file.parameters['namespace'].strip('"')
79 self._entries_by_conditional = {} 74 self._entries_by_conditional = {}
80 self._unconditional_entries = [] 75 self._unconditional_entries = []
81 self._sort_entries_by_conditional() 76 self._sort_entries_by_conditional()
82 self._outputs = {(self.class_name + "Headers.h"): self.generate_headers_ header, 77 self._outputs = {(self.class_name + "Headers.h"): self.generate_headers_ header,
83 (self.class_name + "Interfaces.h"): self.generate_inter faces_header, 78 (self.class_name + "Interfaces.h"): self.generate_inter faces_header,
84 } 79 }
85 80
86 def _sort_entries_by_conditional(self): 81 def _sort_entries_by_conditional(self):
87 unconditional_names = set() 82 unconditional_names = set()
88 for entry in self.in_file.name_dictionaries: 83 for entry in self.in_file.name_dictionaries:
89 conditional = entry['conditional'] 84 conditional = entry['conditional']
90 if not conditional: 85 if not conditional:
91 name = _name_for_entry(entry) 86 name = self._class_name_for_entry(entry)
92 if name in unconditional_names: 87 if name in unconditional_names:
93 continue 88 continue
94 unconditional_names.add(name) 89 unconditional_names.add(name)
95 self._unconditional_entries.append(entry) 90 self._unconditional_entries.append(entry)
96 continue 91 continue
97 for entry in self.in_file.name_dictionaries: 92 for entry in self.in_file.name_dictionaries:
98 name = _name_for_entry(entry) 93 name = self._class_name_for_entry(entry)
99 if name in unconditional_names: 94 if name in unconditional_names:
100 continue 95 continue
101 conditional = entry['conditional'] 96 conditional = entry['conditional']
102 if not conditional in self._entries_by_conditional: 97 if not conditional in self._entries_by_conditional:
103 self._entries_by_conditional[conditional] = [] 98 self._entries_by_conditional[conditional] = []
104 self._entries_by_conditional[conditional].append(entry) 99 self._entries_by_conditional[conditional].append(entry)
105 100
106 def _headers_header_include(self, entry): 101 def _class_name_for_entry(self, entry):
107 path = entry['name'] 102 if entry['implementedAs']:
108 name = _name_for_entry(entry) 103 return entry['implementedAs']
109 if entry['interfaceName']: 104 return os.path.basename(entry['name'])
110 path = entry['interfaceName'] # FIXME: This seems wrong 105
111 include = '#include "%(path)s.h"\n#include "V8%(name)s.h"' % { 106 def _headers_header_include_path(self, entry):
112 'path': path, 107 if entry['implementedAs']:
113 'name': name, 108 path = os.path.dirname(entry['name'])
114 } 109 if len(path):
115 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()
116 129
117 def generate_headers_header(self): 130 def generate_headers_header(self):
118 return HEADER_TEMPLATE % { 131 return HEADER_TEMPLATE % {
119 'license': license.license_for_generated_cpp(), 132 'license': license.license_for_generated_cpp(),
120 'class_name': self.class_name, 133 'class_name': self.class_name,
121 '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)),
122 } 135 }
123 136
124 def _declare_one_conditional_macro(self, conditional, entries): 137 def _declare_one_conditional_macro(self, conditional, entries):
125 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s' % { 138 macro_name = '%(macro_style_name)s_INTERFACES_FOR_EACH_%(conditional)s' % {
126 'macro_style_name': _to_macro_style(self.class_name), 139 'macro_style_name': _to_macro_style(self.class_name),
127 'conditional': conditional, 140 'conditional': conditional,
128 } 141 }
129 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\ 142 return self.wrap_with_condition("""#define %(macro_name)s(macro) \\
130 %(declarations)s 143 %(declarations)s
131 144
132 #else 145 #else
133 #define %(macro_name)s(macro)""" % { 146 #define %(macro_name)s(macro)""" % {
134 'macro_name': macro_name, 147 'macro_name': macro_name,
135 'declarations': '\n'.join(sorted(set([ 148 'declarations': '\n'.join(sorted(set([
136 ' macro(%(name)s) \\' % {'name': _name_for_entry(entry)} 149 ' macro(%(name)s) \\' % {'name': self._class_name_for_entry(e ntry)}
137 for entry in entries]))), 150 for entry in entries]))),
138 }, conditional) 151 }, conditional)
139 152
140 def _declare_conditional_macros(self): 153 def _declare_conditional_macros(self):
141 return '\n'.join([ 154 return '\n'.join([
142 self._declare_one_conditional_macro(conditional, entries) 155 self._declare_one_conditional_macro(conditional, entries)
143 for conditional, entries in self._entries_by_conditional.items()]) 156 for conditional, entries in self._entries_by_conditional.items()])
144 157
145 def _unconditional_macro(self, entry): 158 def _unconditional_macro(self, entry):
146 return ' macro(%(name)s) \\' % {'name': _name_for_entry(entry)} 159 return ' macro(%(name)s) \\' % {'name': self._class_name_for_entry(en try)}
147 160
148 def _conditional_macros(self, conditional): 161 def _conditional_macros(self, conditional):
149 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) \\' % {
150 'macro_style_name': _to_macro_style(self.class_name), 163 'macro_style_name': _to_macro_style(self.class_name),
151 'conditional': conditional, 164 'conditional': conditional,
152 } 165 }
153 166
154 def generate_interfaces_header(self): 167 def generate_interfaces_header(self):
155 return INTERFACES_HEADER_TEMPLATE % { 168 return INTERFACES_HEADER_TEMPLATE % {
156 'license': license.license_for_generated_cpp(), 169 'license': license.license_for_generated_cpp(),
157 'class_name': self.class_name, 170 'class_name': self.class_name,
158 'macro_style_name': _to_macro_style(self.class_name), 171 'macro_style_name': _to_macro_style(self.class_name),
159 'declare_conditional_macros': self._declare_conditional_macros(), 172 'declare_conditional_macros': self._declare_conditional_macros(),
160 '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)))),
161 '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())),
162 } 175 }
OLDNEW
« no previous file with comments | « core/scripts/make_style_builder.py ('k') | core/scripts/rule_bison.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698