Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / mojo / public / tools / bindings / pylib / mojom / generate / generator.py
index 7070285..eb433bf 100644 (file)
@@ -6,6 +6,7 @@
 
 from functools import partial
 import os.path
+import re
 
 import module as mojom
 import pack
@@ -34,32 +35,18 @@ def GetDataHeader(exported, struct):
   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.
@@ -88,3 +75,11 @@ class Generator(object):
 
   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 {}