from functools import partial
import os.path
+import re
import module as mojom
import pack
struct.exported = exported
return struct
-def IsStringKind(kind):
- return kind.spec == 's'
-
-def IsEnumKind(kind):
- return isinstance(kind, mojom.Enum)
-
-def IsObjectKind(kind):
- return isinstance(kind, (mojom.Struct, mojom.Array)) or IsStringKind(kind)
-
-def IsHandleKind(kind):
- return kind.spec.startswith('h') or \
- isinstance(kind, mojom.Interface) or \
- isinstance(kind, mojom.InterfaceRequest)
-
-def IsInterfaceKind(kind):
- return isinstance(kind, mojom.Interface)
-
-def IsInterfaceRequestKind(kind):
- return isinstance(kind, mojom.InterfaceRequest)
-
-def IsMoveOnlyKind(kind):
- return IsObjectKind(kind) or IsHandleKind(kind)
+def ExpectedArraySize(kind):
+ if mojom.IsFixedArrayKind(kind):
+ return kind.length
+ return 0
def StudlyCapsToCamel(studly):
return studly[0].lower() + studly[1:]
+def CamelCaseToAllCaps(camel_case):
+ return '_'.join(
+ word for word in re.split(r'([A-Z][^A-Z]+)', camel_case) if word).upper()
+
class Generator(object):
# Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all
# files to stdout.
def GenerateFiles(self, args):
raise NotImplementedError("Subclasses must override/implement this method")
+
+ def GetJinjaParameters(self):
+ """Returns default constructor parameters for the jinja environment."""
+ return {}
+
+ def GetGlobals(self):
+ """Returns global mappings for the template generation."""
+ return {}