| 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 23 matching lines...) Expand all Loading... |
| 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 blink { | 42 namespace blink { |
| 43 | 43 |
| 44 ${forward_declarations} |
| 45 |
| 44 namespace InspectorInstrumentation { | 46 namespace InspectorInstrumentation { |
| 45 | 47 |
| 46 $methods | 48 $methods |
| 47 } // namespace InspectorInstrumentation | 49 } // namespace InspectorInstrumentation |
| 48 | 50 |
| 49 } // namespace blink | 51 } // namespace blink |
| 50 | 52 |
| 51 #endif // !defined(${file_name}_h) | 53 #endif // !defined(${file_name}_h) |
| 52 """) | 54 """) |
| 53 | 55 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 model.append(File(match.group(1), match.group(2))) | 197 model.append(File(match.group(1), match.group(2))) |
| 196 | 198 |
| 197 return model | 199 return model |
| 198 | 200 |
| 199 | 201 |
| 200 class File: | 202 class File: |
| 201 def __init__(self, name, source): | 203 def __init__(self, name, source): |
| 202 self.name = name | 204 self.name = name |
| 203 self.header_name = self.name + "Inl" | 205 self.header_name = self.name + "Inl" |
| 204 self.includes = [include_inspector_header("InspectorInstrumentation")] | 206 self.includes = [include_inspector_header("InspectorInstrumentation")] |
| 207 self.forward_declarations = [] |
| 205 self.declarations = [] | 208 self.declarations = [] |
| 206 for line in map(str.strip, source.split("\n")): | 209 for line in map(str.strip, source.split("\n")): |
| 207 line = re.sub("\s{2,}", " ", line).strip() # Collapse whitespace | 210 line = re.sub("\s{2,}", " ", line).strip() # Collapse whitespace |
| 208 if len(line) == 0: | 211 if len(line) == 0: |
| 209 continue | 212 continue |
| 210 if line[0] == "#": | 213 if line[0] == "#": |
| 211 self.includes.append(line) | 214 self.includes.append(line) |
| 215 elif line.startswith("class "): |
| 216 self.forward_declarations.append(line) |
| 212 else: | 217 else: |
| 213 self.declarations.append(Method(line)) | 218 self.declarations.append(Method(line)) |
| 214 self.includes.sort() | 219 self.includes.sort() |
| 220 self.forward_declarations.sort() |
| 215 | 221 |
| 216 def generate(self, cpp_lines, used_agents): | 222 def generate(self, cpp_lines, used_agents): |
| 217 header_lines = [] | 223 header_lines = [] |
| 218 for declaration in self.declarations: | 224 for declaration in self.declarations: |
| 219 for agent in set(declaration.agents): | 225 for agent in set(declaration.agents): |
| 220 used_agents.add(agent) | 226 used_agents.add(agent) |
| 221 declaration.generate_header(header_lines) | 227 declaration.generate_header(header_lines) |
| 222 declaration.generate_cpp(cpp_lines) | 228 declaration.generate_cpp(cpp_lines) |
| 223 | 229 |
| 224 return template_h.substitute(None, | 230 return template_h.substitute(None, |
| 225 file_name=self.header_name, | 231 file_name=self.header_name, |
| 226 includes="\n".join(self.includes), | 232 includes="\n".join(self.includes), |
| 233 forward_declarations="\n".join(self.forward
_declarations), |
| 227 methods="\n".join(header_lines)) | 234 methods="\n".join(header_lines)) |
| 228 | 235 |
| 229 | 236 |
| 230 class Method: | 237 class Method: |
| 231 def __init__(self, source): | 238 def __init__(self, source): |
| 232 match = re.match("(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", sou
rce) | 239 match = re.match("(\[[\w|,|=|\s]*\])?\s?(\w*\*?) (\w*)\((.*)\)\s?;", sou
rce) |
| 233 if not match: | 240 if not match: |
| 234 sys.stderr.write("Cannot parse %s\n" % source) | 241 sys.stderr.write("Cannot parse %s\n" % source) |
| 235 sys.exit(1) | 242 sys.exit(1) |
| 236 | 243 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 if not output_dirpath: | 542 if not output_dirpath: |
| 536 raise Exception("Output directory must be specified") | 543 raise Exception("Output directory must be specified") |
| 537 except Exception: | 544 except Exception: |
| 538 # 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 |
| 539 exc = sys.exc_info()[1] | 546 exc = sys.exc_info()[1] |
| 540 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) |
| 541 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") |
| 542 exit(1) | 549 exit(1) |
| 543 | 550 |
| 544 generate(input_path, output_dirpath) | 551 generate(input_path, output_dirpath) |
| OLD | NEW |