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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 return_type=self.return_type, | 317 return_type=self.return_type, |
318 default_return_value=self.default_return_value, | 318 default_return_value=self.default_return_value, |
319 params_public=", ".join(map(Parameter.to_str_full, self.params)), | 319 params_public=", ".join(map(Parameter.to_str_full, self.params)), |
320 params_impl=", ".join(map(Parameter.to_str_name, self.params_impl)), | 320 params_impl=", ".join(map(Parameter.to_str_name, self.params_impl)), |
321 condition=condition)) | 321 condition=condition)) |
322 | 322 |
323 def generate_cpp(self, cpp_lines): | 323 def generate_cpp(self, cpp_lines): |
324 if len(self.agents) == 0: | 324 if len(self.agents) == 0: |
325 return | 325 return |
326 | 326 |
327 body_lines = map(self.generate_agent_call, self.agents) | 327 body_lines = map(self.generate_ref_ptr, self.params) |
| 328 body_lines += map(self.generate_agent_call, self.agents) |
328 | 329 |
329 if self.returns_cookie: | 330 if self.returns_cookie: |
330 if "Timeline" in self.agents: | 331 if "Timeline" in self.agents: |
331 timeline_agent_id = "timelineAgentId" | 332 timeline_agent_id = "timelineAgentId" |
332 else: | 333 else: |
333 timeline_agent_id = "0" | 334 timeline_agent_id = "0" |
334 body_lines.append("\n return InspectorInstrumentationCookie(agent
s, %s);" % timeline_agent_id) | 335 body_lines.append("\n return InspectorInstrumentationCookie(agent
s, %s);" % timeline_agent_id) |
335 elif self.returns_value: | 336 elif self.returns_value: |
336 body_lines.append("\n return %s;" % self.default_return_value) | 337 body_lines.append("\n return %s;" % self.default_return_value) |
337 | 338 |
(...skipping 26 matching lines...) Expand all Loading... |
364 maybe_return = "return " | 365 maybe_return = "return " |
365 | 366 |
366 return template.substitute( | 367 return template.substitute( |
367 None, | 368 None, |
368 name=self.name, | 369 name=self.name, |
369 agent_class=agent_class, | 370 agent_class=agent_class, |
370 agent_fetch=agent_fetch, | 371 agent_fetch=agent_fetch, |
371 maybe_return=maybe_return, | 372 maybe_return=maybe_return, |
372 params_agent=", ".join(map(Parameter.to_str_value, self.params_impl)
[1:])) | 373 params_agent=", ".join(map(Parameter.to_str_value, self.params_impl)
[1:])) |
373 | 374 |
| 375 def generate_ref_ptr(self, param): |
| 376 if param.is_prp: |
| 377 return "\n RefPtr<%s> %s = %s;" % (param.inner_type, param.value,
param.name) |
| 378 else: |
| 379 return "" |
374 | 380 |
375 class Parameter: | 381 class Parameter: |
376 def __init__(self, source): | 382 def __init__(self, source): |
377 self.options = [] | 383 self.options = [] |
378 match, source = match_and_consume("\[(\w*)\]", source) | 384 match, source = match_and_consume("\[(\w*)\]", source) |
379 if match: | 385 if match: |
380 self.options.append(match.group(1)) | 386 self.options.append(match.group(1)) |
381 | 387 |
382 parts = map(str.strip, source.split("=")) | 388 parts = map(str.strip, source.split("=")) |
383 if len(parts) == 1: | 389 if len(parts) == 1: |
(...skipping 10 matching lines...) Expand all Loading... |
394 | 400 |
395 if len(param_decl.split(" ")) > min_type_tokens: | 401 if len(param_decl.split(" ")) > min_type_tokens: |
396 parts = param_decl.split(" ") | 402 parts = param_decl.split(" ") |
397 self.type = " ".join(parts[:-1]) | 403 self.type = " ".join(parts[:-1]) |
398 self.name = parts[-1] | 404 self.name = parts[-1] |
399 else: | 405 else: |
400 self.type = param_decl | 406 self.type = param_decl |
401 self.name = generate_param_name(self.type) | 407 self.name = generate_param_name(self.type) |
402 | 408 |
403 if re.match("PassRefPtr<", param_decl): | 409 if re.match("PassRefPtr<", param_decl): |
404 self.value = "%s.get()" % self.name | 410 self.is_prp = True |
| 411 self.value = self.name |
| 412 self.name = "prp" + self.name[0].upper() + self.name[1:] |
| 413 self.inner_type = re.match("PassRefPtr<(.+)>", param_decl).group(1) |
405 else: | 414 else: |
| 415 self.is_prp = False |
406 self.value = self.name | 416 self.value = self.name |
407 | 417 |
408 | 418 |
409 def to_str_full(self): | 419 def to_str_full(self): |
410 if self.default_value is None: | 420 if self.default_value is None: |
411 return self.to_str_class_and_name() | 421 return self.to_str_class_and_name() |
412 return "%s %s = %s" % (self.type, self.name, self.default_value) | 422 return "%s %s = %s" % (self.type, self.name, self.default_value) |
413 | 423 |
414 def to_str_class_and_name(self): | 424 def to_str_class_and_name(self): |
415 return "%s %s" % (self.type, self.name) | 425 return "%s %s" % (self.type, self.name) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 if not output_dirpath: | 552 if not output_dirpath: |
543 raise Exception("Output directory must be specified") | 553 raise Exception("Output directory must be specified") |
544 except Exception: | 554 except Exception: |
545 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html | 555 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
546 exc = sys.exc_info()[1] | 556 exc = sys.exc_info()[1] |
547 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) | 557 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
548 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum
entation.idl\n") | 558 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum
entation.idl\n") |
549 exit(1) | 559 exit(1) |
550 | 560 |
551 generate(input_path, output_dirpath) | 561 generate(input_path, output_dirpath) |
OLD | NEW |