| 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 21 matching lines...) Expand all Loading... |
| 32 import string | 32 import string |
| 33 import sys | 33 import sys |
| 34 | 34 |
| 35 template_h = string.Template("""// Code generated from InspectorInstrumentation.
idl | 35 template_h = string.Template("""// Code generated from InspectorInstrumentation.
idl |
| 36 | 36 |
| 37 #ifndef ${file_name}_h | 37 #ifndef ${file_name}_h |
| 38 #define ${file_name}_h | 38 #define ${file_name}_h |
| 39 | 39 |
| 40 ${includes} | 40 ${includes} |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace blink { |
| 43 |
| 44 ${forward_declarations} |
| 43 | 45 |
| 44 namespace InspectorInstrumentation { | 46 namespace InspectorInstrumentation { |
| 45 | 47 |
| 46 $methods | 48 $methods |
| 47 } // namespace InspectorInstrumentation | 49 } // namespace InspectorInstrumentation |
| 48 | 50 |
| 49 } // namespace WebCore | 51 } // namespace blink |
| 50 | 52 |
| 51 #endif // !defined(${file_name}_h) | 53 #endif // !defined(${file_name}_h) |
| 52 """) | 54 """) |
| 53 | 55 |
| 54 template_inline = string.Template(""" | 56 template_inline = string.Template(""" |
| 55 inline void ${name}(${params_public}) | 57 inline void ${name}(${params_public}) |
| 56 { ${fast_return} | 58 { ${fast_return} |
| 57 if (${condition}) | 59 if (${condition}) |
| 58 ${name}Impl(${params_impl}); | 60 ${name}Impl(${params_impl}); |
| 59 } | 61 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 } | 77 } |
| 76 """) | 78 """) |
| 77 | 79 |
| 78 | 80 |
| 79 template_cpp = string.Template("""// Code generated from InspectorInstrumentatio
n.idl | 81 template_cpp = string.Template("""// Code generated from InspectorInstrumentatio
n.idl |
| 80 | 82 |
| 81 #include "config.h" | 83 #include "config.h" |
| 82 | 84 |
| 83 ${includes} | 85 ${includes} |
| 84 | 86 |
| 85 namespace WebCore { | 87 namespace blink { |
| 86 ${extra_definitions} | 88 ${extra_definitions} |
| 87 | 89 |
| 88 namespace InspectorInstrumentation { | 90 namespace InspectorInstrumentation { |
| 89 $methods | 91 $methods |
| 90 | 92 |
| 91 } // namespace InspectorInstrumentation | 93 } // namespace InspectorInstrumentation |
| 92 | 94 |
| 93 } // namespace WebCore | 95 } // namespace blink |
| 94 """) | 96 """) |
| 95 | 97 |
| 96 template_outofline = string.Template(""" | 98 template_outofline = string.Template(""" |
| 97 ${return_type} ${name}Impl(${params_impl}) | 99 ${return_type} ${name}Impl(${params_impl}) |
| 98 {${impl_lines} | 100 {${impl_lines} |
| 99 }""") | 101 }""") |
| 100 | 102 |
| 101 template_agent_call = string.Template(""" | 103 template_agent_call = string.Template(""" |
| 102 if (${agent_class}* agent = ${agent_fetch}) | 104 if (${agent_class}* agent = ${agent_fetch}) |
| 103 ${maybe_return}agent->${name}(${params_agent});""") | 105 ${maybe_return}agent->${name}(${params_agent});""") |
| 104 | 106 |
| 105 template_agent_call_timeline_returns_cookie = string.Template(""" | 107 template_agent_call_timeline_returns_cookie = string.Template(""" |
| 106 int timelineAgentId = 0; | 108 int timelineAgentId = 0; |
| 107 if (InspectorTimelineAgent* agent = agents->inspectorTimelineAgent()) { | 109 if (InspectorTimelineAgent* agent = agents->inspectorTimelineAgent()) { |
| 108 if (agent->${name}(${params_agent})) | 110 if (agent->${name}(${params_agent})) |
| 109 timelineAgentId = agent->id(); | 111 timelineAgentId = agent->id(); |
| 110 }""") | 112 }""") |
| 111 | 113 |
| 112 | 114 |
| 113 template_instrumenting_agents_h = string.Template("""// Code generated from Insp
ectorInstrumentation.idl | 115 template_instrumenting_agents_h = string.Template("""// Code generated from Insp
ectorInstrumentation.idl |
| 114 | 116 |
| 115 #ifndef InstrumentingAgentsInl_h | 117 #ifndef InstrumentingAgentsInl_h |
| 116 #define InstrumentingAgentsInl_h | 118 #define InstrumentingAgentsInl_h |
| 117 | 119 |
| 120 #include "platform/heap/Handle.h" |
| 118 #include "wtf/FastAllocBase.h" | 121 #include "wtf/FastAllocBase.h" |
| 119 #include "wtf/Noncopyable.h" | 122 #include "wtf/Noncopyable.h" |
| 120 #include "wtf/PassRefPtr.h" | 123 #include "wtf/PassRefPtr.h" |
| 121 #include "wtf/RefCounted.h" | 124 #include "wtf/RefCounted.h" |
| 122 | 125 |
| 123 namespace WebCore { | 126 namespace blink { |
| 124 | 127 |
| 125 ${forward_list} | 128 ${forward_list} |
| 126 | 129 |
| 127 class InstrumentingAgents : public RefCounted<InstrumentingAgents> { | 130 class InstrumentingAgents : public RefCountedWillBeGarbageCollectedFinalized<Ins
trumentingAgents> { |
| 128 WTF_MAKE_NONCOPYABLE(InstrumentingAgents); | 131 WTF_MAKE_NONCOPYABLE(InstrumentingAgents); |
| 129 WTF_MAKE_FAST_ALLOCATED; | 132 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 130 public: | 133 public: |
| 131 static PassRefPtr<InstrumentingAgents> create() | 134 static PassRefPtrWillBeRawPtr<InstrumentingAgents> create() |
| 132 { | 135 { |
| 133 return adoptRef(new InstrumentingAgents()); | 136 return adoptRefWillBeNoop(new InstrumentingAgents()); |
| 134 } | 137 } |
| 135 ~InstrumentingAgents() { } | 138 ~InstrumentingAgents() { } |
| 139 void trace(Visitor*); |
| 136 void reset(); | 140 void reset(); |
| 137 | 141 |
| 138 ${accessor_list} | 142 ${accessor_list} |
| 139 | 143 |
| 140 private: | 144 private: |
| 141 InstrumentingAgents(); | 145 InstrumentingAgents(); |
| 142 | 146 |
| 143 ${member_list} | 147 ${member_list} |
| 144 }; | 148 }; |
| 145 | 149 |
| 146 } | 150 } |
| 147 | 151 |
| 148 #endif // !defined(InstrumentingAgentsInl_h) | 152 #endif // !defined(InstrumentingAgentsInl_h) |
| 149 """) | 153 """) |
| 150 | 154 |
| 151 template_instrumenting_agent_accessor = string.Template(""" | 155 template_instrumenting_agent_accessor = string.Template(""" |
| 152 ${class_name}* ${getter_name}() const { return ${member_name}; } | 156 ${class_name}* ${getter_name}() const { return ${member_name}; } |
| 153 void set${class_name}(${class_name}* agent) { ${member_name} = agent; }""") | 157 void set${class_name}(${class_name}* agent) { ${member_name} = agent; }""") |
| 154 | 158 |
| 155 template_instrumenting_agents_cpp = string.Template(""" | 159 template_instrumenting_agents_cpp = string.Template(""" |
| 156 InstrumentingAgents::InstrumentingAgents() | 160 InstrumentingAgents::InstrumentingAgents() |
| 157 : $init_list | 161 : $init_list |
| 158 { | 162 { |
| 159 } | 163 } |
| 160 | 164 |
| 165 void InstrumentingAgents::trace(Visitor* visitor) |
| 166 { |
| 167 $trace_list |
| 168 } |
| 169 |
| 161 void InstrumentingAgents::reset() | 170 void InstrumentingAgents::reset() |
| 162 { | 171 { |
| 163 $reset_list | 172 $reset_list |
| 164 }""") | 173 }""") |
| 165 | 174 |
| 166 | 175 |
| 167 | 176 |
| 168 def match_and_consume(pattern, source): | 177 def match_and_consume(pattern, source): |
| 169 match = re.match(pattern, source) | 178 match = re.match(pattern, source) |
| 170 if match: | 179 if match: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 188 model.append(File(match.group(1), match.group(2))) | 197 model.append(File(match.group(1), match.group(2))) |
| 189 | 198 |
| 190 return model | 199 return model |
| 191 | 200 |
| 192 | 201 |
| 193 class File: | 202 class File: |
| 194 def __init__(self, name, source): | 203 def __init__(self, name, source): |
| 195 self.name = name | 204 self.name = name |
| 196 self.header_name = self.name + "Inl" | 205 self.header_name = self.name + "Inl" |
| 197 self.includes = [include_inspector_header("InspectorInstrumentation")] | 206 self.includes = [include_inspector_header("InspectorInstrumentation")] |
| 207 self.forward_declarations = [] |
| 198 self.declarations = [] | 208 self.declarations = [] |
| 199 for line in map(str.strip, source.split("\n")): | 209 for line in map(str.strip, source.split("\n")): |
| 200 line = re.sub("\s{2,}", " ", line).strip() # Collapse whitespace | 210 line = re.sub("\s{2,}", " ", line).strip() # Collapse whitespace |
| 201 if len(line) == 0: | 211 if len(line) == 0: |
| 202 continue | 212 continue |
| 203 if line[0] == "#": | 213 if line[0] == "#": |
| 204 self.includes.append(line) | 214 self.includes.append(line) |
| 215 elif line.startswith("class "): |
| 216 self.forward_declarations.append(line) |
| 205 else: | 217 else: |
| 206 self.declarations.append(Method(line)) | 218 self.declarations.append(Method(line)) |
| 207 self.includes.sort() | 219 self.includes.sort() |
| 220 self.forward_declarations.sort() |
| 208 | 221 |
| 209 def generate(self, cpp_lines, used_agents): | 222 def generate(self, cpp_lines, used_agents): |
| 210 header_lines = [] | 223 header_lines = [] |
| 211 for declaration in self.declarations: | 224 for declaration in self.declarations: |
| 212 for agent in set(declaration.agents): | 225 for agent in set(declaration.agents): |
| 213 used_agents.add(agent) | 226 used_agents.add(agent) |
| 214 declaration.generate_header(header_lines) | 227 declaration.generate_header(header_lines) |
| 215 declaration.generate_cpp(cpp_lines) | 228 declaration.generate_cpp(cpp_lines) |
| 216 | 229 |
| 217 return template_h.substitute(None, | 230 return template_h.substitute(None, |
| 218 file_name=self.header_name, | 231 file_name=self.header_name, |
| 219 includes="\n".join(self.includes), | 232 includes="\n".join(self.includes), |
| 233 forward_declarations="\n".join(self.forward
_declarations), |
| 220 methods="\n".join(header_lines)) | 234 methods="\n".join(header_lines)) |
| 221 | 235 |
| 222 | 236 |
| 223 class Method: | 237 class Method: |
| 224 def __init__(self, source): | 238 def __init__(self, source): |
| 225 match = re.match("(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", sou
rce) | 239 match = re.match("(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", sou
rce) |
| 226 if not match: | 240 if not match: |
| 227 sys.stderr.write("Cannot parse %s\n" % source) | 241 sys.stderr.write("Cannot parse %s\n" % source) |
| 228 sys.exit(1) | 242 sys.exit(1) |
| 229 | 243 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 240 # Splitting parameters by a comma, assuming that attribute lists contain
no more than one attribute. | 254 # Splitting parameters by a comma, assuming that attribute lists contain
no more than one attribute. |
| 241 self.params = map(Parameter, map(str.strip, match.group(4).split(","))) | 255 self.params = map(Parameter, map(str.strip, match.group(4).split(","))) |
| 242 | 256 |
| 243 self.accepts_cookie = len(self.params) and self.params[0].type == "const
InspectorInstrumentationCookie&" | 257 self.accepts_cookie = len(self.params) and self.params[0].type == "const
InspectorInstrumentationCookie&" |
| 244 self.returns_cookie = self.return_type == "InspectorInstrumentationCooki
e" | 258 self.returns_cookie = self.return_type == "InspectorInstrumentationCooki
e" |
| 245 | 259 |
| 246 self.returns_value = self.return_type != "void" | 260 self.returns_value = self.return_type != "void" |
| 247 | 261 |
| 248 if self.return_type == "bool": | 262 if self.return_type == "bool": |
| 249 self.default_return_value = "false" | 263 self.default_return_value = "false" |
| 264 elif self.return_type == "int": |
| 265 self.default_return_value = "0" |
| 250 elif self.return_type == "String": | 266 elif self.return_type == "String": |
| 251 self.default_return_value = "\"\"" | 267 self.default_return_value = "\"\"" |
| 252 else: | 268 else: |
| 253 self.default_return_value = self.return_type + "()" | 269 self.default_return_value = self.return_type + "()" |
| 254 | 270 |
| 255 for param in self.params: | 271 for param in self.params: |
| 256 if "DefaultReturn" in param.options: | 272 if "DefaultReturn" in param.options: |
| 257 self.default_return_value = param.name | 273 self.default_return_value = param.name |
| 258 | 274 |
| 259 self.params_impl = self.params | 275 self.params_impl = self.params |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 return include_header("core/inspector/" + name) | 449 return include_header("core/inspector/" + name) |
| 434 | 450 |
| 435 | 451 |
| 436 def generate_instrumenting_agents(used_agents): | 452 def generate_instrumenting_agents(used_agents): |
| 437 agents = list(used_agents) | 453 agents = list(used_agents) |
| 438 | 454 |
| 439 forward_list = [] | 455 forward_list = [] |
| 440 accessor_list = [] | 456 accessor_list = [] |
| 441 member_list = [] | 457 member_list = [] |
| 442 init_list = [] | 458 init_list = [] |
| 459 trace_list = [] |
| 443 reset_list = [] | 460 reset_list = [] |
| 444 | 461 |
| 445 for agent in agents: | 462 for agent in agents: |
| 446 class_name, getter_name = agent_getter_signature(agent) | 463 class_name, getter_name = agent_getter_signature(agent) |
| 447 member_name = "m_" + getter_name | 464 member_name = "m_" + getter_name |
| 448 | 465 |
| 449 forward_list.append("class %s;" % class_name) | 466 forward_list.append("class %s;" % class_name) |
| 450 accessor_list.append(template_instrumenting_agent_accessor.substitute( | 467 accessor_list.append(template_instrumenting_agent_accessor.substitute( |
| 451 None, | 468 None, |
| 452 class_name=class_name, | 469 class_name=class_name, |
| 453 getter_name=getter_name, | 470 getter_name=getter_name, |
| 454 member_name=member_name)) | 471 member_name=member_name)) |
| 455 member_list.append(" %s* %s;" % (class_name, member_name)) | 472 member_list.append(" RawPtrWillBeMember<%s> %s;" % (class_name, membe
r_name)) |
| 456 init_list.append("%s(0)" % member_name) | 473 init_list.append("%s(nullptr)" % member_name) |
| 457 reset_list.append("%s = 0;" % member_name) | 474 trace_list.append("visitor->trace(%s);" % member_name) |
| 475 reset_list.append("%s = nullptr;" % member_name) |
| 458 | 476 |
| 459 forward_list.sort() | 477 forward_list.sort() |
| 460 accessor_list.sort() | 478 accessor_list.sort() |
| 461 member_list.sort() | 479 member_list.sort() |
| 462 init_list.sort() | 480 init_list.sort() |
| 481 trace_list.sort() |
| 463 reset_list.sort() | 482 reset_list.sort() |
| 464 | 483 |
| 465 header_lines = template_instrumenting_agents_h.substitute( | 484 header_lines = template_instrumenting_agents_h.substitute( |
| 466 None, | 485 None, |
| 467 forward_list="\n".join(forward_list), | 486 forward_list="\n".join(forward_list), |
| 468 accessor_list="\n".join(accessor_list), | 487 accessor_list="\n".join(accessor_list), |
| 469 member_list="\n".join(member_list)) | 488 member_list="\n".join(member_list)) |
| 470 | 489 |
| 471 cpp_lines = template_instrumenting_agents_cpp.substitute( | 490 cpp_lines = template_instrumenting_agents_cpp.substitute( |
| 472 None, | 491 None, |
| 473 init_list="\n , ".join(init_list), | 492 init_list="\n , ".join(init_list), |
| 493 trace_list="\n ".join(trace_list), |
| 474 reset_list="\n ".join(reset_list)) | 494 reset_list="\n ".join(reset_list)) |
| 475 | 495 |
| 476 return header_lines, cpp_lines | 496 return header_lines, cpp_lines |
| 477 | 497 |
| 478 | 498 |
| 479 def generate(input_path, output_dir): | 499 def generate(input_path, output_dir): |
| 480 fin = open(input_path, "r") | 500 fin = open(input_path, "r") |
| 481 files = load_model_from_idl(fin.read()) | 501 files = load_model_from_idl(fin.read()) |
| 482 fin.close() | 502 fin.close() |
| 483 | 503 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 if not output_dirpath: | 542 if not output_dirpath: |
| 523 raise Exception("Output directory must be specified") | 543 raise Exception("Output directory must be specified") |
| 524 except Exception: | 544 except Exception: |
| 525 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html | 545 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
| 526 exc = sys.exc_info()[1] | 546 exc = sys.exc_info()[1] |
| 527 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) | 547 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
| 528 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum
entation.idl\n") | 548 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum
entation.idl\n") |
| 529 exit(1) | 549 exit(1) |
| 530 | 550 |
| 531 generate(input_path, output_dirpath) | 551 generate(input_path, output_dirpath) |
| OLD | NEW |