OLD | NEW |
---|---|
(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, returnType): | |
Mark Seaborn
2014/09/09 19:13:11
"return_type"
Nick Bray (chromium)
2014/09/09 23:12:33
Done.
| |
10 f = Function(self, len(self.functions), name, returnType) | |
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, returnType): | |
20 self.parent = parent | |
21 self.uid = uid | |
22 self.name = name | |
23 self.returnType = returnType | |
24 self.params = [] | |
25 self.paramLUT = {} | |
Mark Seaborn
2014/09/09 19:13:11
How about "paramsByName"?
Nick Bray (chromium)
2014/09/09 23:12:33
Done.
| |
26 self.resultParam = None | |
27 | |
28 def param(self, name, paramType=None): | |
Mark Seaborn
2014/09/09 19:13:11
"param_type"
Nick Bray (chromium)
2014/09/09 23:12:33
Done.
| |
29 p = Param(self, len(self.params), name, paramType) | |
30 self.params.append(p) | |
31 self.paramLUT[name] = p | |
32 return p | |
33 | |
34 def paramList(self): | |
35 return [param.paramType + " "+ param.name for param in self.params] | |
Mark Seaborn
2014/09/09 19:13:11
Add space before "+"
Nick Bray (chromium)
2014/09/09 23:12:33
Done.
| |
36 | |
37 def paramDecl(self): | |
38 if self.params: | |
39 return ", ".join(self.paramList()) | |
Mark Seaborn
2014/09/09 19:13:11
Nit: Google Python style is usually '' rather than
Nick Bray (chromium)
2014/09/09 23:12:33
Done.
| |
40 else: | |
41 return "void" | |
42 | |
43 def finalize(self): | |
44 for p in self.params: | |
45 p.finalize() | |
46 self.resultParam = Param(self, len(self.params), "result") | |
47 self.resultParam.out(self.returnType) | |
48 | |
49 class Param(object): | |
50 def __init__(self, parent, uid, name, paramType=None): | |
51 self.parent = parent | |
52 self.uid = uid | |
53 self.name = name | |
54 self.baseType = paramType | |
55 self.paramType = paramType | |
56 self.size = None | |
57 self.isInput = False | |
58 self.isOutput = False | |
59 self.isArray = False | |
60 self.isStruct = False | |
61 self.isOptional = False | |
62 | |
63 def getSizeParam(self): | |
64 assert self.size | |
65 return self.parent.paramLUT[self.size] | |
66 | |
67 def inp(self, t): | |
Mark Seaborn
2014/09/09 19:13:11
't' -> 'ty' for readability?
'inp' -> 'input', or
Nick Bray (chromium)
2014/09/09 23:12:33
"input" is a builtin and "in" is a keyword. Other
Mark Seaborn
2014/09/10 23:19:19
Hmm, if you name it "Input" (for the other naming
Nick Bray (chromium)
2014/09/11 00:56:39
Done.
| |
68 self.baseType = t | |
69 self.paramType = t | |
70 self.isInput = True | |
71 return self | |
72 | |
73 def inArray(self, t, size): | |
74 self.baseType = t | |
75 self.paramType = "const " + t + "*" | |
76 self.size = size | |
77 self.isInput = True | |
78 self.isArray = True | |
79 return self | |
80 | |
81 def inStruct(self, t): | |
82 self.baseType = t | |
83 self.paramType = "const struct " + t + "*" | |
84 self.isInput = True | |
85 self.isStruct = True | |
86 return self | |
87 | |
88 def inOut(self, t): | |
89 self.baseType = t | |
90 self.paramType = t + "*" | |
91 self.isInput = True | |
92 self.isOutput = True | |
93 return self | |
94 | |
95 def out(self, t): | |
96 self.baseType = t | |
97 self.paramType = t + "*" | |
98 self.isOutput = True | |
99 return self | |
100 | |
101 def outArray(self, t, size): | |
102 self.baseType = t | |
103 self.paramType = t + "*" | |
104 self.size = size | |
105 self.isArray = True | |
106 self.isOutput = True | |
107 return self | |
108 | |
109 def optional(self): | |
110 assert not self.isPassedByValue() | |
111 self.isOptional = True | |
112 return self | |
113 | |
114 def isScalar(self): | |
115 return not self.isArray and not self.isStruct | |
116 | |
117 def isPassedByValue(self): | |
118 return not self.isOutput and self.isScalar() | |
119 | |
120 def finalize(self): | |
121 pass | |
OLD | NEW |