OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Code shared by the various language-specific code generators.""" | 5 """Code shared by the various language-specific code generators.""" |
6 | 6 |
7 import os | 7 import os |
8 import mojom | 8 import mojom |
9 import mojom_pack | 9 import mojom_pack |
10 import re | 10 import re |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 if isinstance(expression, tuple) and expression[0] == 'EXPRESSION': | 57 if isinstance(expression, tuple) and expression[0] == 'EXPRESSION': |
58 result = [] | 58 result = [] |
59 for each in expression[1]: | 59 for each in expression[1]: |
60 result.extend(ExpressionMapper(each, mapper)) | 60 result.extend(ExpressionMapper(each, mapper)) |
61 return result | 61 return result |
62 return [mapper(expression)] | 62 return [mapper(expression)] |
63 | 63 |
64 class Generator(object): | 64 class Generator(object): |
65 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all | 65 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all |
66 # files to stdout. | 66 # files to stdout. |
67 def __init__(self, module, header_dir, output_dir=None): | 67 def __init__(self, module, output_dir=None): |
68 self.module = module | 68 self.module = module |
69 self.header_dir = header_dir | 69 self.header_dir = os.path.dirname(module.path); |
70 self.output_dir = output_dir | 70 self.output_dir = output_dir |
71 | 71 |
72 def GetStructsFromMethods(self): | 72 def GetStructsFromMethods(self): |
73 result = [] | 73 result = [] |
74 for interface in self.module.interfaces: | 74 for interface in self.module.interfaces: |
75 for method in interface.methods: | 75 for method in interface.methods: |
76 result.append(GetStructFromMethod(interface, method)) | 76 result.append(GetStructFromMethod(interface, method)) |
77 return map(partial(GetStructInfo, False), result) | 77 return map(partial(GetStructInfo, False), result) |
78 | 78 |
79 def GetStructs(self): | 79 def GetStructs(self): |
80 return map(partial(GetStructInfo, True), self.module.structs) | 80 return map(partial(GetStructInfo, True), self.module.structs) |
81 | 81 |
82 def Write(self, contents, filename): | 82 def Write(self, contents, filename): |
83 if self.output_dir is None: | 83 if self.output_dir is None: |
84 print contents | 84 print contents |
85 return | 85 return |
86 with open(os.path.join(self.output_dir, filename), "w+") as f: | 86 with open(os.path.join(self.output_dir, filename), "w+") as f: |
87 f.write(contents) | 87 f.write(contents) |
88 | 88 |
89 def GenerateFiles(self): | 89 def GenerateFiles(self): |
90 raise NotImplementedError("Subclasses must override/implement this method") | 90 raise NotImplementedError("Subclasses must override/implement this method") |
OLD | NEW |