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

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

Issue 385983008: Mojo + NaCl prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: BuildFix Created 6 years, 3 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
(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.returnType = return_type
Mark Seaborn 2014/09/11 19:24:02 These don't follow the style guide still. "return
Nick Bray 2014/09/11 20:24:08 Done.
24 self.params = []
25 self.paramByName = {}
Mark Seaborn 2014/09/11 19:24:02 "param_by_name"
Nick Bray 2014/09/11 20:24:09 Done.
26 self.resultParam = 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.paramByName[name] = p
32 return p
33
34 def ParamList(self):
35 return [param.paramType + ' ' + 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 for p in self.params:
45 p.Finalize()
Mark Seaborn 2014/09/11 19:24:02 This is a no-op, right?
Nick Bray 2014/09/11 20:24:09 Done.
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, param_type=None):
51 self.parent = parent
52 self.uid = uid
53 self.name = name
54 self.baseType = param_type
Mark Seaborn 2014/09/11 19:24:02 Ditto: "base_type" etc.?
Nick Bray 2014/09/11 20:24:09 Done.
55 self.paramType = param_type
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.paramByName[self.size]
66
67 def In(self, ty):
68 self.baseType = ty
69 self.paramType = ty
70 self.isInput = True
71 return self
72
73 def InArray(self, ty, size):
74 self.baseType = ty
75 self.paramType = 'const ' + ty + '*'
76 self.size = size
77 self.isInput = True
78 self.isArray = True
79 return self
80
81 def InStruct(self, ty):
82 self.baseType = ty
83 self.paramType = 'const struct ' + ty + '*'
84 self.isInput = True
85 self.isStruct = True
86 return self
87
88 def InOut(self, ty):
89 self.baseType = ty
90 self.paramType = ty + '*'
91 self.isInput = True
92 self.isOutput = True
93 return self
94
95 def Out(self, ty):
96 self.baseType = ty
97 self.paramType = ty + '*'
98 self.isOutput = True
99 return self
100
101 def OutArray(self, ty, size):
102 self.baseType = ty
103 self.paramType = ty + '*'
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698