| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 for param in self.params: | 255 for param in self.params: |
| 256 if "DefaultReturn" in param.options: | 256 if "DefaultReturn" in param.options: |
| 257 self.default_return_value = param.name | 257 self.default_return_value = param.name |
| 258 | 258 |
| 259 self.params_impl = self.params | 259 self.params_impl = self.params |
| 260 if not self.accepts_cookie and not "Inline=Forward" in self.options: | 260 if not self.accepts_cookie and not "Inline=Forward" in self.options: |
| 261 if not "Keep" in self.params_impl[0].options: | 261 if not "Keep" in self.params_impl[0].options: |
| 262 self.params_impl = self.params_impl[1:] | 262 self.params_impl = self.params_impl[1:] |
| 263 self.params_impl = [Parameter("InstrumentingAgents* agents")] + self
.params_impl | 263 self.params_impl = [Parameter("InstrumentingAgents* agents")] + self
.params_impl |
| 264 self.agents_selector_class = re.match("(\w*)", self.params[0].type).
group(1) | |
| 265 | 264 |
| 266 self.agents = filter(lambda option: not "=" in option, self.options) | 265 self.agents = filter(lambda option: not "=" in option, self.options) |
| 267 | 266 |
| 268 def generate_header(self, header_lines): | 267 def generate_header(self, header_lines): |
| 269 if "Inline=Custom" in self.options: | 268 if "Inline=Custom" in self.options: |
| 270 return | 269 return |
| 271 | 270 |
| 272 header_lines.append("%s %sImpl(%s);" % ( | 271 header_lines.append("%s %sImpl(%s);" % ( |
| 273 self.return_type, self.name, ", ".join(map(Parameter.to_str_class, s
elf.params_impl)))) | 272 self.return_type, self.name, ", ".join(map(Parameter.to_str_class, s
elf.params_impl)))) |
| 274 | 273 |
| 275 if "Inline=FastReturn" in self.options or "Inline=Forward" in self.optio
ns: | 274 if "Inline=FastReturn" in self.options or "Inline=Forward" in self.optio
ns: |
| 276 fast_return = "\n FAST_RETURN_IF_NO_FRONTENDS(%s);" % self.defaul
t_return_value | 275 fast_return = "\n FAST_RETURN_IF_NO_FRONTENDS(%s);" % self.defaul
t_return_value |
| 277 else: | 276 else: |
| 278 fast_return = "" | 277 fast_return = "" |
| 279 | 278 |
| 280 for param in self.params: | 279 for param in self.params: |
| 281 if "FastReturn" in param.options: | 280 if "FastReturn" in param.options: |
| 282 fast_return += "\n if (!%s)\n return %s;" % (param.nam
e, self.default_return_value) | 281 fast_return += "\n if (!%s)\n return %s;" % (param.nam
e, self.default_return_value) |
| 283 | 282 |
| 284 if self.accepts_cookie: | 283 if self.accepts_cookie: |
| 285 condition = "%s.isValid()" % self.params_impl[0].name | 284 condition = "%s.isValid()" % self.params_impl[0].name |
| 286 template = template_inline | 285 template = template_inline |
| 287 elif "Inline=Forward" in self.options: | 286 elif "Inline=Forward" in self.options: |
| 288 condition = "" | 287 condition = "" |
| 289 template = template_inline_forward | 288 template = template_inline_forward |
| 290 else: | 289 else: |
| 291 condition = "InstrumentingAgents* agents = instrumentingAgentsFor%s(
%s)" % ( | 290 condition = "InstrumentingAgents* agents = instrumentingAgentsFor(%s
)" % self.params[0].name |
| 292 self.agents_selector_class, self.params[0].name) | |
| 293 | 291 |
| 294 if self.returns_value: | 292 if self.returns_value: |
| 295 template = template_inline_returns_value | 293 template = template_inline_returns_value |
| 296 else: | 294 else: |
| 297 template = template_inline | 295 template = template_inline |
| 298 | 296 |
| 299 header_lines.append(template.substitute( | 297 header_lines.append(template.substitute( |
| 300 None, | 298 None, |
| 301 name=self.name, | 299 name=self.name, |
| 302 fast_return=fast_return, | 300 fast_return=fast_return, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 if not output_dirpath: | 513 if not output_dirpath: |
| 516 raise Exception("Output directory must be specified") | 514 raise Exception("Output directory must be specified") |
| 517 except Exception: | 515 except Exception: |
| 518 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html | 516 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
| 519 exc = sys.exc_info()[1] | 517 exc = sys.exc_info()[1] |
| 520 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) | 518 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
| 521 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum
entation.idl\n") | 519 sys.stderr.write("Usage: <script> --output_dir <output_dir> InspectorInstrum
entation.idl\n") |
| 522 exit(1) | 520 exit(1) |
| 523 | 521 |
| 524 generate(input_path, output_dirpath) | 522 generate(input_path, output_dirpath) |
| OLD | NEW |