Chromium Code Reviews| Index: mojo/monacl/generator/interface_dsl.py |
| diff --git a/mojo/monacl/generator/interface_dsl.py b/mojo/monacl/generator/interface_dsl.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2b8ee1c8e88e248d903658958c5fc7e9e163f3e |
| --- /dev/null |
| +++ b/mojo/monacl/generator/interface_dsl.py |
| @@ -0,0 +1,121 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +class Interface(object): |
| + def __init__(self): |
| + self.functions = [] |
| + |
| + 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.
|
| + f = Function(self, len(self.functions), name, returnType) |
| + self.functions.append(f) |
| + return f |
| + |
| + def finalize(self): |
| + for f in self.functions: |
| + f.finalize() |
| + |
| +class Function(object): |
| + def __init__(self, parent, uid, name, returnType): |
| + self.parent = parent |
| + self.uid = uid |
| + self.name = name |
| + self.returnType = returnType |
| + self.params = [] |
| + self.paramLUT = {} |
|
Mark Seaborn
2014/09/09 19:13:11
How about "paramsByName"?
Nick Bray (chromium)
2014/09/09 23:12:33
Done.
|
| + self.resultParam = None |
| + |
| + 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.
|
| + p = Param(self, len(self.params), name, paramType) |
| + self.params.append(p) |
| + self.paramLUT[name] = p |
| + return p |
| + |
| + def paramList(self): |
| + 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.
|
| + |
| + def paramDecl(self): |
| + if self.params: |
| + 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.
|
| + else: |
| + return "void" |
| + |
| + def finalize(self): |
| + for p in self.params: |
| + p.finalize() |
| + self.resultParam = Param(self, len(self.params), "result") |
| + self.resultParam.out(self.returnType) |
| + |
| +class Param(object): |
| + def __init__(self, parent, uid, name, paramType=None): |
| + self.parent = parent |
| + self.uid = uid |
| + self.name = name |
| + self.baseType = paramType |
| + self.paramType = paramType |
| + self.size = None |
| + self.isInput = False |
| + self.isOutput = False |
| + self.isArray = False |
| + self.isStruct = False |
| + self.isOptional = False |
| + |
| + def getSizeParam(self): |
| + assert self.size |
| + return self.parent.paramLUT[self.size] |
| + |
| + 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.
|
| + self.baseType = t |
| + self.paramType = t |
| + self.isInput = True |
| + return self |
| + |
| + def inArray(self, t, size): |
| + self.baseType = t |
| + self.paramType = "const " + t + "*" |
| + self.size = size |
| + self.isInput = True |
| + self.isArray = True |
| + return self |
| + |
| + def inStruct(self, t): |
| + self.baseType = t |
| + self.paramType = "const struct " + t + "*" |
| + self.isInput = True |
| + self.isStruct = True |
| + return self |
| + |
| + def inOut(self, t): |
| + self.baseType = t |
| + self.paramType = t + "*" |
| + self.isInput = True |
| + self.isOutput = True |
| + return self |
| + |
| + def out(self, t): |
| + self.baseType = t |
| + self.paramType = t + "*" |
| + self.isOutput = True |
| + return self |
| + |
| + def outArray(self, t, size): |
| + self.baseType = t |
| + self.paramType = t + "*" |
| + self.size = size |
| + self.isArray = True |
| + self.isOutput = True |
| + return self |
| + |
| + def optional(self): |
| + assert not self.isPassedByValue() |
| + self.isOptional = True |
| + return self |
| + |
| + def isScalar(self): |
| + return not self.isArray and not self.isStruct |
| + |
| + def isPassedByValue(self): |
| + return not self.isOutput and self.isScalar() |
| + |
| + def finalize(self): |
| + pass |