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

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

Issue 66353002: Mojo: RemotePtr<S> + bindings changes for Peer attribute. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + fix error in sample_service.h 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 os
9 import sys 10 import sys
10 11
11 12
12 def MapKind(kind): 13 def MapKind(kind):
13 map_to_kind = { 'bool': 'b', 14 map_to_kind = { 'bool': 'b',
14 'int8': 'i8', 15 'int8': 'i8',
15 'int16': 'i16', 16 'int16': 'i16',
16 'int32': 'i32', 17 'int32': 'i32',
17 'int64': 'i64', 18 'int64': 'i64',
18 'uint8': 'u8', 19 'uint8': 'u8',
(...skipping 10 matching lines...) Expand all
29 return map_to_kind[kind] 30 return map_to_kind[kind]
30 return 'x:' + kind 31 return 'x:' + kind
31 32
32 33
33 def MapOrdinal(ordinal): 34 def MapOrdinal(ordinal):
34 if ordinal == None: 35 if ordinal == None:
35 return None; 36 return None;
36 return int(ordinal[1:]) # Strip leading '@' 37 return int(ordinal[1:]) # Strip leading '@'
37 38
38 39
40 def GetAttribute(attributes, name):
41 out = None
42 for attribute in attributes:
43 if attribute[0] == 'ATTRIBUTE' and attribute[1] == name:
44 out = attribute[2]
45 return out
46
47
39 def MapFields(fields): 48 def MapFields(fields):
40 out = [] 49 out = []
41 for field in fields: 50 for field in fields:
42 if field[0] == 'FIELD': 51 if field[0] == 'FIELD':
43 out.append({'name': field[2], 52 out.append({'name': field[2],
44 'kind': MapKind(field[1]), 53 'kind': MapKind(field[1]),
45 'ordinal': MapOrdinal(field[3])}) 54 'ordinal': MapOrdinal(field[3])})
46 return out 55 return out
47 56
48 57
(...skipping 18 matching lines...) Expand all
67 76
68 77
69 class MojomBuilder(): 78 class MojomBuilder():
70 79
71 def __init__(self): 80 def __init__(self):
72 self.mojom = {} 81 self.mojom = {}
73 82
74 def AddStruct(self, name, attributes, fields): 83 def AddStruct(self, name, attributes, fields):
75 struct = {} 84 struct = {}
76 struct['name'] = name 85 struct['name'] = name
86 # TODO(darin): Add support for |attributes|
87 #struct['attributes'] = MapAttributes(attributes)
77 struct['fields'] = MapFields(fields) 88 struct['fields'] = MapFields(fields)
78 self.mojom['structs'].append(struct) 89 self.mojom['structs'].append(struct)
79 # TODO(darin): Add support for |attributes|
80 90
81 def AddInterface(self, name, attributes, methods): 91 def AddInterface(self, name, attributes, methods):
82 interface = {} 92 interface = {}
83 interface['name'] = name 93 interface['name'] = name
94 interface['peer'] = GetAttribute(attributes, 'Peer')
84 interface['methods'] = MapMethods(methods) 95 interface['methods'] = MapMethods(methods)
85 self.mojom['interfaces'].append(interface) 96 self.mojom['interfaces'].append(interface)
86 # TODO(darin): Add support for |attributes|
87 97
88 def AddModule(self, name, namespace, contents): 98 def AddModule(self, name, namespace, contents):
89 self.mojom['name'] = name 99 self.mojom['name'] = name
90 self.mojom['namespace'] = namespace 100 self.mojom['namespace'] = namespace
91 self.mojom['structs'] = [] 101 self.mojom['structs'] = []
92 self.mojom['interfaces'] = [] 102 self.mojom['interfaces'] = []
93 for item in contents: 103 for item in contents:
94 if item[0] == 'STRUCT': 104 if item[0] == 'STRUCT':
95 self.AddStruct(name=item[1], attributes=item[2], fields=item[3]) 105 self.AddStruct(name=item[1], attributes=item[2], fields=item[3])
96 elif item[0] == 'INTERFACE': 106 elif item[0] == 'INTERFACE':
(...skipping 14 matching lines...) Expand all
111 print("usage: %s filename" % (sys.argv[0])) 121 print("usage: %s filename" % (sys.argv[0]))
112 sys.exit(1) 122 sys.exit(1)
113 tree = eval(open(sys.argv[1]).read()) 123 tree = eval(open(sys.argv[1]).read())
114 name = os.path.splitext(os.path.basename(sys.argv[1]))[0] 124 name = os.path.splitext(os.path.basename(sys.argv[1]))[0]
115 result = Translate(tree, name) 125 result = Translate(tree, name)
116 print(result) 126 print(result)
117 127
118 128
119 if __name__ == '__main__': 129 if __name__ == '__main__':
120 Main() 130 Main()
OLDNEW
« no previous file with comments | « mojo/public/bindings/lib/remote_ptr.h ('k') | mojo/public/bindings/sample/generated/sample_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698