OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Translate parse tree to Mojom IR""" | 6 """Translate parse tree to Mojom IR""" |
7 | 7 |
8 | 8 |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 'string': 's', | 24 'string': 's', |
25 'handle': 'h' } | 25 'handle': 'h' } |
26 if kind.endswith('[]'): | 26 if kind.endswith('[]'): |
27 return 'a:' + MapKind(kind[0:len(kind)-2]) | 27 return 'a:' + MapKind(kind[0:len(kind)-2]) |
28 if kind in map_to_kind: | 28 if kind in map_to_kind: |
29 return map_to_kind[kind] | 29 return map_to_kind[kind] |
30 return 'x:' + kind | 30 return 'x:' + kind |
31 | 31 |
32 | 32 |
33 def MapOrdinal(ordinal): | 33 def MapOrdinal(ordinal): |
| 34 if ordinal == None: |
| 35 return None; |
34 return int(ordinal[1:]) # Strip leading '@' | 36 return int(ordinal[1:]) # Strip leading '@' |
35 | 37 |
36 | 38 |
37 def MapFields(fields): | 39 def MapFields(fields): |
38 out = [] | 40 out = [] |
39 for field in fields: | 41 for field in fields: |
40 if field[0] == 'FIELD': | 42 if field[0] == 'FIELD': |
41 out.append({'name': field[2], | 43 out.append({'name': field[2], |
42 'kind': MapKind(field[1]), | 44 'kind': MapKind(field[1]), |
43 'ordinal': MapOrdinal(field[3])}) | 45 'ordinal': MapOrdinal(field[3])}) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if len(sys.argv) < 2: | 109 if len(sys.argv) < 2: |
108 print("usage: %s filename" % (sys.argv[0])) | 110 print("usage: %s filename" % (sys.argv[0])) |
109 sys.exit(1) | 111 sys.exit(1) |
110 tree = eval(open(sys.argv[1]).read()) | 112 tree = eval(open(sys.argv[1]).read()) |
111 result = Translate(tree) | 113 result = Translate(tree) |
112 print(result) | 114 print(result) |
113 | 115 |
114 | 116 |
115 if __name__ == '__main__': | 117 if __name__ == '__main__': |
116 Main() | 118 Main() |
OLD | NEW |