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

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: FinalEdits 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
« 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)
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_optional = False
60
61 def GetSizeParam(self):
62 assert self.size
63 return self.parent.param_by_name[self.size]
64
65 def In(self, ty):
66 self.base_type = ty
67 self.param_type = ty
68 self.is_input = True
69 return self
70
71 def InArray(self, ty, size):
72 self.base_type = ty
73 self.param_type = 'const ' + ty + '*'
74 self.size = size
75 self.is_input = True
76 self.is_array = True
77 return self
78
79 def InStruct(self, ty):
80 self.base_type = ty
81 self.param_type = 'const struct ' + ty + '*'
82 self.is_input = True
83 self.is_struct = True
84 return self
85
86 def InOut(self, ty):
87 self.base_type = ty
88 self.param_type = ty + '*'
89 self.is_input = True
90 self.is_output = True
91 return self
92
93 def Out(self, ty):
94 self.base_type = ty
95 self.param_type = ty + '*'
96 self.is_output = True
97 return self
98
99 def OutArray(self, ty, size):
100 self.base_type = ty
101 self.param_type = ty + '*'
102 self.size = size
103 self.is_array = True
104 self.is_output = True
105 return self
106
107 def Optional(self):
108 assert not self.IsPassedByValue()
109 self.is_optional = True
110 return self
111
112 def IsScalar(self):
113 return not self.is_array and not self.is_struct
114
115 def IsPassedByValue(self):
116 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