Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: mojo/public/bindings/parser/mojo_translate.py

Issue 65933002: Mojo: Unify the disparate source and header files into 3 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mistaken /n's Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/mojo_idl.py ('k') | mojo/public/bindings/sample/sample_service.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 struct['fields'] = MapFields(fields) 75 struct['fields'] = MapFields(fields)
76 self.mojom['structs'].append(struct) 76 self.mojom['structs'].append(struct)
77 # TODO(darin): Add support for |attributes| 77 # TODO(darin): Add support for |attributes|
78 78
79 def AddInterface(self, name, methods): 79 def AddInterface(self, name, methods):
80 interface = {} 80 interface = {}
81 interface['name'] = name 81 interface['name'] = name
82 interface['methods'] = MapMethods(methods) 82 interface['methods'] = MapMethods(methods)
83 self.mojom['interfaces'].append(interface) 83 self.mojom['interfaces'].append(interface)
84 84
85 def AddModule(self, name, contents): 85 def AddModule(self, name, namespace, contents):
86 self.mojom['name'] = name 86 self.mojom['name'] = name
87 self.mojom['namespace'] = name 87 self.mojom['namespace'] = namespace
88 self.mojom['structs'] = [] 88 self.mojom['structs'] = []
89 self.mojom['interfaces'] = [] 89 self.mojom['interfaces'] = []
90 for item in contents: 90 for item in contents:
91 if item[0] == 'STRUCT': 91 if item[0] == 'STRUCT':
92 self.AddStruct(name=item[1], attributes=item[2], fields=item[3]) 92 self.AddStruct(name=item[1], attributes=item[2], fields=item[3])
93 elif item[0] == 'INTERFACE': 93 elif item[0] == 'INTERFACE':
94 self.AddInterface(name=item[1], methods=item[2]) 94 self.AddInterface(name=item[1], methods=item[2])
95 95
96 def Build(self, tree): 96 def Build(self, tree, name):
97 if tree[0] == 'MODULE': 97 if tree[0] == 'MODULE':
98 self.AddModule(name=tree[1], contents=tree[2]) 98 self.AddModule(name=name, namespace=tree[1], contents=tree[2])
99 return self.mojom 99 return self.mojom
100 100
101 101
102 def Translate(tree): 102 def Translate(tree, name):
103 return MojomBuilder().Build(tree) 103 return MojomBuilder().Build(tree, name)
104 104
105 105
106 def Main(): 106 def Main():
107 if len(sys.argv) < 2: 107 if len(sys.argv) < 2:
108 print("usage: %s filename" % (sys.argv[0])) 108 print("usage: %s filename" % (sys.argv[0]))
109 sys.exit(1) 109 sys.exit(1)
110 tree = eval(open(sys.argv[1]).read()) 110 tree = eval(open(sys.argv[1]).read())
111 result = Translate(tree) 111 name = os.path.splitext(os.path.basename(sys.argv[1]))[0]
112 result = Translate(tree, name)
112 print(result) 113 print(result)
113 114
114 115
115 if __name__ == '__main__': 116 if __name__ == '__main__':
116 Main() 117 Main()
OLDNEW
« no previous file with comments | « mojo/public/bindings/mojo_idl.py ('k') | mojo/public/bindings/sample/sample_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698