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

Side by Side Diff: core/inspector/CodeGeneratorInstrumentation.py

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 years, 10 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
« no previous file with comments | « core/inspector/CodeGeneratorInspectorStrings.py ('k') | core/inspector/DevToolsHost.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 template_outofline = string.Template(""" 98 template_outofline = string.Template("""
99 ${return_type} ${name}Impl(${params_impl}) 99 ${return_type} ${name}Impl(${params_impl})
100 {${impl_lines} 100 {${impl_lines}
101 }""") 101 }""")
102 102
103 template_agent_call = string.Template(""" 103 template_agent_call = string.Template("""
104 if (${agent_class}* agent = ${agent_fetch}) 104 if (${agent_class}* agent = ${agent_fetch})
105 ${maybe_return}agent->${name}(${params_agent});""") 105 ${maybe_return}agent->${name}(${params_agent});""")
106 106
107 template_agent_call_timeline_returns_cookie = string.Template("""
108 int timelineAgentId = 0;
109 if (InspectorTimelineAgent* agent = agents->inspectorTimelineAgent()) {
110 if (agent->${name}(${params_agent}))
111 timelineAgentId = agent->id();
112 }""")
113
114
115 template_instrumenting_agents_h = string.Template("""// Code generated from Insp ectorInstrumentation.idl 107 template_instrumenting_agents_h = string.Template("""// Code generated from Insp ectorInstrumentation.idl
116 108
117 #ifndef InstrumentingAgentsInl_h 109 #ifndef InstrumentingAgentsInl_h
118 #define InstrumentingAgentsInl_h 110 #define InstrumentingAgentsInl_h
119 111
112 #include "core/CoreExport.h"
120 #include "platform/heap/Handle.h" 113 #include "platform/heap/Handle.h"
121 #include "wtf/FastAllocBase.h" 114 #include "wtf/FastAllocBase.h"
122 #include "wtf/Noncopyable.h" 115 #include "wtf/Noncopyable.h"
123 #include "wtf/PassRefPtr.h" 116 #include "wtf/PassRefPtr.h"
124 #include "wtf/RefCounted.h" 117 #include "wtf/RefCounted.h"
125 118
126 namespace blink { 119 namespace blink {
127 120
128 ${forward_list} 121 ${forward_list}
129 122
130 class InstrumentingAgents : public RefCountedWillBeGarbageCollectedFinalized<Ins trumentingAgents> { 123 class CORE_EXPORT InstrumentingAgents : public RefCountedWillBeGarbageCollectedF inalized<InstrumentingAgents> {
131 WTF_MAKE_NONCOPYABLE(InstrumentingAgents); 124 WTF_MAKE_NONCOPYABLE(InstrumentingAgents);
132 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; 125 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(InstrumentingAgents);
133 public: 126 public:
134 static PassRefPtrWillBeRawPtr<InstrumentingAgents> create() 127 static PassRefPtrWillBeRawPtr<InstrumentingAgents> create()
135 { 128 {
136 return adoptRefWillBeNoop(new InstrumentingAgents()); 129 return adoptRefWillBeNoop(new InstrumentingAgents());
137 } 130 }
138 ~InstrumentingAgents() { } 131 ~InstrumentingAgents() { }
139 void trace(Visitor*); 132 DECLARE_TRACE();
140 void reset(); 133 void reset();
141 134
142 ${accessor_list} 135 ${accessor_list}
143 136
144 private: 137 private:
145 InstrumentingAgents(); 138 InstrumentingAgents();
146 139
147 ${member_list} 140 ${member_list}
148 }; 141 };
149 142
150 } 143 }
151 144
152 #endif // !defined(InstrumentingAgentsInl_h) 145 #endif // !defined(InstrumentingAgentsInl_h)
153 """) 146 """)
154 147
155 template_instrumenting_agent_accessor = string.Template(""" 148 template_instrumenting_agent_accessor = string.Template("""
156 ${class_name}* ${getter_name}() const { return ${member_name}; } 149 ${class_name}* ${getter_name}() const { return ${member_name}; }
157 void set${class_name}(${class_name}* agent) { ${member_name} = agent; }""") 150 void set${class_name}(${class_name}* agent) { ${member_name} = agent; }""")
158 151
159 template_instrumenting_agents_cpp = string.Template(""" 152 template_instrumenting_agents_cpp = string.Template("""
160 InstrumentingAgents::InstrumentingAgents() 153 InstrumentingAgents::InstrumentingAgents()
161 : $init_list 154 : $init_list
162 { 155 {
163 } 156 }
164 157
165 void InstrumentingAgents::trace(Visitor* visitor) 158 DEFINE_TRACE(InstrumentingAgents)
166 { 159 {
167 $trace_list 160 $trace_list
168 } 161 }
169 162
170 void InstrumentingAgents::reset() 163 void InstrumentingAgents::reset()
171 { 164 {
172 $reset_list 165 $reset_list
173 }""") 166 }""")
174 167
175 168
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if not "Keep" in self.params_impl[0].options: 270 if not "Keep" in self.params_impl[0].options:
278 self.params_impl = self.params_impl[1:] 271 self.params_impl = self.params_impl[1:]
279 self.params_impl = [Parameter("InstrumentingAgents* agents")] + self .params_impl 272 self.params_impl = [Parameter("InstrumentingAgents* agents")] + self .params_impl
280 273
281 self.agents = filter(lambda option: not "=" in option, self.options) 274 self.agents = filter(lambda option: not "=" in option, self.options)
282 275
283 def generate_header(self, header_lines): 276 def generate_header(self, header_lines):
284 if "Inline=Custom" in self.options: 277 if "Inline=Custom" in self.options:
285 return 278 return
286 279
287 header_lines.append("%s %sImpl(%s);" % ( 280 header_lines.append("CORE_EXPORT %s %sImpl(%s);" % (
288 self.return_type, self.name, ", ".join(map(Parameter.to_str_class, s elf.params_impl)))) 281 self.return_type, self.name, ", ".join(map(Parameter.to_str_class, s elf.params_impl))))
289 282
290 if "Inline=FastReturn" in self.options or "Inline=Forward" in self.optio ns: 283 if "Inline=FastReturn" in self.options or "Inline=Forward" in self.optio ns:
291 fast_return = "\n FAST_RETURN_IF_NO_FRONTENDS(%s);" % self.defaul t_return_value 284 fast_return = "\n FAST_RETURN_IF_NO_FRONTENDS(%s);" % self.defaul t_return_value
292 else: 285 else:
293 fast_return = "" 286 fast_return = ""
294 287
295 for param in self.params: 288 for param in self.params:
296 if "FastReturn" in param.options: 289 if "FastReturn" in param.options:
297 fast_return += "\n if (!%s)\n return %s;" % (param.nam e, self.default_return_value) 290 fast_return += "\n if (!%s)\n return %s;" % (param.nam e, self.default_return_value)
(...skipping 23 matching lines...) Expand all
321 condition=condition)) 314 condition=condition))
322 315
323 def generate_cpp(self, cpp_lines): 316 def generate_cpp(self, cpp_lines):
324 if len(self.agents) == 0: 317 if len(self.agents) == 0:
325 return 318 return
326 319
327 body_lines = map(self.generate_ref_ptr, self.params) 320 body_lines = map(self.generate_ref_ptr, self.params)
328 body_lines += map(self.generate_agent_call, self.agents) 321 body_lines += map(self.generate_agent_call, self.agents)
329 322
330 if self.returns_cookie: 323 if self.returns_cookie:
331 if "Timeline" in self.agents: 324 body_lines.append("\n return InspectorInstrumentationCookie(agent s);")
332 timeline_agent_id = "timelineAgentId"
333 else:
334 timeline_agent_id = "0"
335 body_lines.append("\n return InspectorInstrumentationCookie(agent s, %s);" % timeline_agent_id)
336 elif self.returns_value: 325 elif self.returns_value:
337 body_lines.append("\n return %s;" % self.default_return_value) 326 body_lines.append("\n return %s;" % self.default_return_value)
338 327
339 cpp_lines.append(template_outofline.substitute( 328 generated_outofline = template_outofline.substitute(
340 None, 329 None,
341 return_type=self.return_type, 330 return_type=self.return_type,
342 name=self.name, 331 name=self.name,
343 params_impl=", ".join(map(Parameter.to_str_class_and_name, self.para ms_impl)), 332 params_impl=", ".join(map(Parameter.to_str_class_and_name, self.para ms_impl)),
344 impl_lines="".join(body_lines))) 333 impl_lines="".join(body_lines))
334 if generated_outofline not in cpp_lines:
335 cpp_lines.append(generated_outofline)
345 336
346 def generate_agent_call(self, agent): 337 def generate_agent_call(self, agent):
347 agent_class, agent_getter = agent_getter_signature(agent) 338 agent_class, agent_getter = agent_getter_signature(agent)
348 339
349 leading_param_name = self.params_impl[0].name 340 leading_param_name = self.params_impl[0].name
350 if not self.accepts_cookie: 341 if not self.accepts_cookie:
351 agent_fetch = "%s->%s()" % (leading_param_name, agent_getter) 342 agent_fetch = "%s->%s()" % (leading_param_name, agent_getter)
352 elif agent == "Timeline":
353 agent_fetch = "retrieveTimelineAgent(%s)" % leading_param_name
354 else: 343 else:
355 agent_fetch = "%s.instrumentingAgents()->%s()" % (leading_param_name , agent_getter) 344 agent_fetch = "%s.instrumentingAgents()->%s()" % (leading_param_name , agent_getter)
356 345
357 if agent == "Timeline" and self.returns_cookie: 346 template = template_agent_call
358 template = template_agent_call_timeline_returns_cookie
359 else:
360 template = template_agent_call
361 347
362 if not self.returns_value or self.returns_cookie: 348 if not self.returns_value or self.returns_cookie:
363 maybe_return = "" 349 maybe_return = ""
364 else: 350 else:
365 maybe_return = "return " 351 maybe_return = "return "
366 352
367 return template.substitute( 353 return template.substitute(
368 None, 354 None,
369 name=self.name, 355 name=self.name,
370 agent_class=agent_class, 356 agent_class=agent_class,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 def to_str_value(self): 419 def to_str_value(self):
434 return self.value 420 return self.value
435 421
436 422
437 def generate_param_name(param_type): 423 def generate_param_name(param_type):
438 base_name = re.match("(const |PassRefPtr<)?(\w*)", param_type).group(2) 424 base_name = re.match("(const |PassRefPtr<)?(\w*)", param_type).group(2)
439 return "param" + base_name 425 return "param" + base_name
440 426
441 427
442 def agent_class_name(agent): 428 def agent_class_name(agent):
443 custom_agent_names = ["PageDebugger", "PageRuntime", "WorkerRuntime"] 429 custom_agent_names = ["PageDebugger", "PageRuntime", "WorkerRuntime", "PageC onsole"]
444 if agent in custom_agent_names: 430 if agent in custom_agent_names:
445 return "%sAgent" % agent 431 return "%sAgent" % agent
432 if agent == "AsyncCallTracker":
433 return agent
446 return "Inspector%sAgent" % agent 434 return "Inspector%sAgent" % agent
447 435
448 436
449 def agent_getter_signature(agent): 437 def agent_getter_signature(agent):
450 agent_class = agent_class_name(agent) 438 agent_class = agent_class_name(agent)
451 return agent_class, agent_class[0].lower() + agent_class[1:] 439 return agent_class, agent_class[0].lower() + agent_class[1:]
452 440
453 441
454 def include_header(name): 442 def include_header(name):
455 return "#include \"%s.h\"" % name 443 return "#include \"%s.h\"" % name
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 for f in files: 505 for f in files:
518 cpp_includes.append(include_header(f.header_name)) 506 cpp_includes.append(include_header(f.header_name))
519 507
520 fout = open(output_dir + "/" + f.header_name + ".h", "w") 508 fout = open(output_dir + "/" + f.header_name + ".h", "w")
521 fout.write(f.generate(cpp_lines, used_agents)) 509 fout.write(f.generate(cpp_lines, used_agents))
522 fout.close() 510 fout.close()
523 511
524 for agent in used_agents: 512 for agent in used_agents:
525 cpp_includes.append(include_inspector_header(agent_class_name(agent))) 513 cpp_includes.append(include_inspector_header(agent_class_name(agent)))
526 cpp_includes.append(include_header("InstrumentingAgentsInl")) 514 cpp_includes.append(include_header("InstrumentingAgentsInl"))
515 cpp_includes.append(include_header("core/CoreExport"))
527 cpp_includes.sort() 516 cpp_includes.sort()
528 517
529 instrumenting_agents_header, instrumenting_agents_cpp = generate_instrumenti ng_agents(used_agents) 518 instrumenting_agents_header, instrumenting_agents_cpp = generate_instrumenti ng_agents(used_agents)
530 519
531 fout = open(output_dir + "/" + "InstrumentingAgentsInl.h", "w") 520 fout = open(output_dir + "/" + "InstrumentingAgentsInl.h", "w")
532 fout.write(instrumenting_agents_header) 521 fout.write(instrumenting_agents_header)
533 fout.close() 522 fout.close()
534 523
535 fout = open(output_dir + "/InspectorInstrumentationImpl.cpp", "w") 524 fout = open(output_dir + "/InspectorInstrumentationImpl.cpp", "w")
536 fout.write(template_cpp.substitute(None, 525 fout.write(template_cpp.substitute(None,
(...skipping 15 matching lines...) Expand all
552 if not output_dirpath: 541 if not output_dirpath:
553 raise Exception("Output directory must be specified") 542 raise Exception("Output directory must be specified")
554 except Exception: 543 except Exception:
555 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html 544 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
556 exc = sys.exc_info()[1] 545 exc = sys.exc_info()[1]
557 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) 546 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc)
558 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum entation.idl\n") 547 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum entation.idl\n")
559 exit(1) 548 exit(1)
560 549
561 generate(input_path, output_dirpath) 550 generate(input_path, output_dirpath)
OLDNEW
« no previous file with comments | « core/inspector/CodeGeneratorInspectorStrings.py ('k') | core/inspector/DevToolsHost.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698