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

Side by Side Diff: mojo/nacl/generator/interface_dsl.py

Issue 1279133006: Removed unused mojo_nacl code and GYP targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: - -l Created 5 years, 4 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
« no previous file with comments | « mojo/nacl/generator/interface.py ('k') | mojo/nacl/generator/libmojo.cc.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 class Interface(object):
6 def __init__(self):
7 self.functions = []
8
9 def Func(self, name, return_type):
10 f = Function(self, len(self.functions), name, return_type)
11 self.functions.append(f)
12 return f
13
14 def Finalize(self):
15 for f in self.functions:
16 f.Finalize()
17
18 class Function(object):
19 def __init__(self, parent, uid, name, return_type):
20 self.parent = parent
21 self.uid = uid
22 self.name = name
23 self.return_type = return_type
24 self.params = []
25 self.param_by_name = {}
26 self.result_param = None
27
28 def Param(self, name, param_type=None):
29 p = Param(self, len(self.params), name, param_type)
30 self.params.append(p)
31 self.param_by_name[name] = p
32 return p
33
34 def ParamList(self):
35 return [param.param_type + ' ' + param.name for param in self.params]
36
37 def ParamDecl(self):
38 if self.params:
39 return ', '.join(self.ParamList())
40 else:
41 return 'void'
42
43 def Finalize(self):
44 self.result_param = Param(self, len(self.params), 'result')
45 self.result_param.Out(self.return_type).AlwaysWritten()
46
47 class Param(object):
48 def __init__(self, parent, uid, name, param_type=None):
49 self.parent = parent
50 self.uid = uid
51 self.name = name
52 self.base_type = param_type
53 self.param_type = param_type
54 self.size = None
55 self.is_input = False
56 self.is_output = False
57 self.is_array = False
58 self.is_struct = False
59 self.is_extensible = False
60 self.is_optional = False
61 self.is_always_written = False
62
63 def GetSizeParam(self):
64 assert self.size
65 return self.parent.param_by_name[self.size]
66
67 def In(self, ty):
68 self.base_type = ty
69 self.param_type = ty
70 self.is_input = True
71 return self
72
73 def InArray(self, ty, size):
74 self.base_type = ty
75 self.param_type = 'const ' + ty + '*'
76 self.size = size
77 self.is_input = True
78 self.is_array = True
79 return self
80
81 # 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
83 # allows forwards and backwards compatibility with additive changes to the
84 # structure definition.
85 def InExtensibleStruct(self, ty):
86 self.base_type = ty
87 self.param_type = 'const struct ' + ty + '*'
88 self.is_input = True
89 self.is_struct = True
90 self.is_extensible = True
91 return self
92
93 def InOut(self, ty):
94 self.base_type = ty
95 self.param_type = ty + '*'
96 self.is_input = True
97 self.is_output = True
98 return self
99
100 def Out(self, ty):
101 self.base_type = ty
102 self.param_type = ty + '*'
103 self.is_output = True
104 return self
105
106 def OutArray(self, ty, size):
107 self.base_type = ty
108 self.param_type = ty + '*'
109 self.size = size
110 self.is_array = True
111 self.is_output = True
112 return self
113
114 # The size of the struct is fixed by the API, it cannot be extended.
115 def OutFixedStruct(self, ty):
116 self.base_type = ty
117 self.param_type = 'struct ' + ty + '*'
118 self.is_output = True
119 self.is_struct = True
120 self.is_extensible = False
121 return self
122
123 def OutFixedStructArray(self, ty, size):
124 self.base_type = ty
125 self.param_type = 'struct ' + ty + '*'
126 self.size = size
127 self.is_array = True
128 self.is_output = True
129 return self
130
131 # Declares that it is valid to pass a null pointer.
132 def Optional(self):
133 assert not self.IsPassedByValue()
134 self.is_optional = True
135 return self
136
137 def AlwaysWritten(self):
138 assert self.is_output, self
139 self.is_always_written = True
140 return self
141
142 def IsScalar(self):
143 return not self.is_array and not self.is_struct
144
145 def IsPassedByValue(self):
146 return not self.is_output and self.IsScalar()
OLDNEW
« no previous file with comments | « mojo/nacl/generator/interface.py ('k') | mojo/nacl/generator/libmojo.cc.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698