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

Side by Side Diff: nacl_bindings_generator/interface_dsl.py

Issue 1086743002: Support pointers in the NaCl bindings generator. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 months 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 class Interface(object): 5 class Interface(object):
6 def __init__(self): 6 def __init__(self):
7 self.functions = [] 7 self.functions = []
8 8
9 def Func(self, name, return_type): 9 def Func(self, name, return_type):
10 f = Function(self, len(self.functions), name, return_type) 10 f = Function(self, len(self.functions), name, return_type)
11 self.functions.append(f) 11 self.functions.append(f)
12 return f 12 return f
13 13
14 def Finalize(self): 14 def Finalize(self):
15 for f in self.functions: 15 for f in self.functions:
16 f.Finalize() 16 f.Finalize()
17 17
18 class Function(object): 18 class Function(object):
19 def __init__(self, parent, uid, name, return_type): 19 def __init__(self, parent, uid, name, return_type):
20 self.parent = parent 20 self.parent = parent
21 self.uid = uid 21 self.uid = uid
22 self.name = name 22 self.name = name
23 self.return_type = return_type 23 self.return_type = return_type
24 self.params = [] 24 self.params = []
25 self.param_by_name = {} 25 self.param_by_name = {}
26 self.result_param = None 26 self.result_param = None
27 self.broken_in_nacl = False
27 28
28 def Param(self, name, param_type=None): 29 def Param(self, name, param_type=None):
29 p = Param(self, len(self.params), name, param_type) 30 p = Param(self, len(self.params), name, param_type)
30 self.params.append(p) 31 self.params.append(p)
31 self.param_by_name[name] = p 32 self.param_by_name[name] = p
32 return p 33 return p
33 34
34 def ParamList(self): 35 def ParamList(self):
35 return [param.param_type + ' ' + param.name for param in self.params] 36 return [param.param_type + ' ' + param.name for param in self.params]
36 37
37 def ParamDecl(self): 38 def ParamDecl(self):
38 if self.params: 39 if self.params:
39 return ', '.join(self.ParamList()) 40 return ', '.join(self.ParamList())
40 else: 41 else:
41 return 'void' 42 return 'void'
42 43
44 def IsBrokenInNaCl(self):
45 self.broken_in_nacl = True
46
43 def Finalize(self): 47 def Finalize(self):
44 self.result_param = Param(self, len(self.params), 'result') 48 self.result_param = Param(self, len(self.params), 'result')
45 self.result_param.Out(self.return_type).AlwaysWritten() 49 self.result_param.Out(self.return_type).AlwaysWritten()
46 50
47 class Param(object): 51 class Param(object):
48 def __init__(self, parent, uid, name, param_type=None): 52 def __init__(self, parent, uid, name, param_type=None):
49 self.parent = parent 53 self.parent = parent
50 self.uid = uid 54 self.uid = uid
51 self.name = name 55 self.name = name
52 self.base_type = param_type 56 self.base_type = param_type
53 self.param_type = param_type 57 self.param_type = param_type
54 self.size = None 58 self.size = None
55 self.is_input = False 59 self.is_input = False
56 self.is_output = False 60 self.is_output = False
57 self.is_array = False 61 self.is_array = False
58 self.is_struct = False 62 self.is_struct = False
59 self.is_extensible = False 63 self.is_extensible = False
60 self.is_optional = False 64 self.is_optional = False
61 self.is_always_written = False 65 self.is_always_written = False
66 self.is_pointer = False
62 67
63 def GetSizeParam(self): 68 def GetSizeParam(self):
64 assert self.size 69 assert self.size
65 return self.parent.param_by_name[self.size] 70 return self.parent.param_by_name[self.size]
66 71
67 def In(self, ty): 72 def In(self, ty):
68 self.base_type = ty 73 self.base_type = ty
69 self.param_type = ty 74 self.param_type = ty
70 self.is_input = True 75 self.is_input = True
76 self.is_pointer = ty.endswith('*')
71 return self 77 return self
72 78
73 def InArray(self, ty, size): 79 def InArray(self, ty, size):
74 self.base_type = ty 80 self.base_type = ty
75 self.param_type = 'const ' + ty + '*' 81 self.param_type = 'const ' + ty + '*'
76 self.size = size 82 self.size = size
77 self.is_input = True 83 self.is_input = True
78 self.is_array = True 84 self.is_array = True
79 return self 85 return self
80 86
81 # An "extensible" struct is one where we don't know the exact size - rather 87 # An "extensible" struct is one where we don't know the exact size - rather
82 # the first 4 bytes of the struct declare the length of the struct. This 88 # the first 4 bytes of the struct declare the length of the struct. This
83 # allows forwards and backwards compatibility with additive changes to the 89 # allows forwards and backwards compatibility with additive changes to the
84 # structure definition. 90 # structure definition.
85 def InExtensibleStruct(self, ty): 91 def InExtensibleStruct(self, ty):
86 self.base_type = ty 92 self.base_type = ty
87 self.param_type = 'const struct ' + ty + '*' 93 self.param_type = 'const struct ' + ty + '*'
88 self.is_input = True 94 self.is_input = True
89 self.is_struct = True 95 self.is_struct = True
90 self.is_extensible = True 96 self.is_extensible = True
91 return self 97 return self
92 98
93 def InOut(self, ty): 99 def InOut(self, ty):
94 self.base_type = ty 100 self.base_type = ty
95 self.param_type = ty + '*' 101 self.param_type = ty + '*'
96 self.is_input = True 102 self.is_input = True
97 self.is_output = True 103 self.is_output = True
104 self.is_pointer = ty.endswith('*')
98 return self 105 return self
99 106
100 def Out(self, ty): 107 def Out(self, ty):
101 self.base_type = ty 108 self.base_type = ty
102 self.param_type = ty + '*' 109 self.param_type = ty + '*'
103 self.is_output = True 110 self.is_output = True
111 self.is_pointer = ty.endswith('*')
104 return self 112 return self
105 113
106 def OutArray(self, ty, size): 114 def OutArray(self, ty, size):
107 self.base_type = ty 115 self.base_type = ty
108 self.param_type = ty + '*' 116 self.param_type = ty + '*'
109 self.size = size 117 self.size = size
110 self.is_array = True 118 self.is_array = True
111 self.is_output = True 119 self.is_output = True
112 return self 120 return self
113 121
(...skipping 23 matching lines...) Expand all
137 def AlwaysWritten(self): 145 def AlwaysWritten(self):
138 assert self.is_output, self 146 assert self.is_output, self
139 self.is_always_written = True 147 self.is_always_written = True
140 return self 148 return self
141 149
142 def IsScalar(self): 150 def IsScalar(self):
143 return not self.is_array and not self.is_struct 151 return not self.is_array and not self.is_struct
144 152
145 def IsPassedByValue(self): 153 def IsPassedByValue(self):
146 return not self.is_output and self.IsScalar() 154 return not self.is_output and self.IsScalar()
OLDNEW
« nacl_bindings_generator/interface.py ('K') | « nacl_bindings_generator/interface.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698