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

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

Issue 63843003: Mojo: Add support for attributes [name=value] on interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 def __init__(self): 69 def __init__(self):
70 self.mojom = {} 70 self.mojom = {}
71 71
72 def AddStruct(self, name, attributes, fields): 72 def AddStruct(self, name, attributes, fields):
73 struct = {} 73 struct = {}
74 struct['name'] = name 74 struct['name'] = name
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, attributes, 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 # TODO(darin): Add support for |attributes|
darin (slow to review) 2013/11/07 06:14:31 This TODO is about adding some way to express attr
84 85
85 def AddModule(self, name, contents): 86 def AddModule(self, name, contents):
86 self.mojom['name'] = name 87 self.mojom['name'] = name
87 self.mojom['namespace'] = name 88 self.mojom['namespace'] = name
88 self.mojom['structs'] = [] 89 self.mojom['structs'] = []
89 self.mojom['interfaces'] = [] 90 self.mojom['interfaces'] = []
90 for item in contents: 91 for item in contents:
91 if item[0] == 'STRUCT': 92 if item[0] == 'STRUCT':
92 self.AddStruct(name=item[1], attributes=item[2], fields=item[3]) 93 self.AddStruct(name=item[1], attributes=item[2], fields=item[3])
93 elif item[0] == 'INTERFACE': 94 elif item[0] == 'INTERFACE':
94 self.AddInterface(name=item[1], methods=item[2]) 95 self.AddInterface(name=item[1], attributes=item[2], methods=item[3])
95 96
96 def Build(self, tree): 97 def Build(self, tree):
97 if tree[0] == 'MODULE': 98 if tree[0] == 'MODULE':
98 self.AddModule(name=tree[1], contents=tree[2]) 99 self.AddModule(name=tree[1], contents=tree[2])
99 return self.mojom 100 return self.mojom
100 101
101 102
102 def Translate(tree): 103 def Translate(tree):
103 return MojomBuilder().Build(tree) 104 return MojomBuilder().Build(tree)
104 105
105 106
106 def Main(): 107 def Main():
107 if len(sys.argv) < 2: 108 if len(sys.argv) < 2:
108 print("usage: %s filename" % (sys.argv[0])) 109 print("usage: %s filename" % (sys.argv[0]))
109 sys.exit(1) 110 sys.exit(1)
110 tree = eval(open(sys.argv[1]).read()) 111 tree = eval(open(sys.argv[1]).read())
111 result = Translate(tree) 112 result = Translate(tree)
112 print(result) 113 print(result)
113 114
114 115
115 if __name__ == '__main__': 116 if __name__ == '__main__':
116 Main() 117 Main()
OLDNEW
« mojo/public/bindings/parser/mojo_parser.py ('K') | « mojo/public/bindings/parser/mojo_parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698