[Tool][Generator] property assigning move to constructor
authorpius.lee <pius.lee@samsung.com>
Fri, 16 Jan 2015 01:19:46 +0000 (10:19 +0900)
committerpius.lee <pius.lee@samsung.com>
Fri, 16 Jan 2015 01:23:13 +0000 (10:23 +0900)
[Tool][Generator] every used construcutor assigned to tizen and add to loading rule in extension header
[Tool][Generator] add platform object type test

Change-Id: I4a9c46da1010f28b7b8c44bec811ee567747cde2
Signed-off-by: pius.lee <pius.lee@samsung.com>
tools/skeleton_generator/WAPIOven.py
tools/skeleton_generator/tpl/tpl_api.js
tools/skeleton_generator/tpl/tpl_extension.cc
tools/skeleton_generator/tpl/tpl_instance.h

index e214a03..ea00ee6 100644 (file)
@@ -21,7 +21,8 @@ cppPrimitiveMap = {
         'unsigned long': 'double',
         'unsigned long long': 'double',
         'float':'double',
-        'double':'double'}
+        'double':'double'
+        }
 
 class IndentPrintable(object):
     def __init__(self, isIndent=True, tabstep=2, ignoreLF=False):
@@ -85,8 +86,8 @@ class Compiler(IndentPrintable):
         self.ctx['activeObjects'] = set()
         self.ctx['implementOperations'] = dict()
         self.ctx['exportedInterface'] = []
-        self.ctx['Tizen'] = []
-        self.ctx['Window'] = []
+        #self.ctx['Tizen'] = []
+        #self.ctx['Window'] = []
         self.ctx['cmdtable'] = dict()
         self.ctx['exportModule'] = module
 
@@ -98,20 +99,49 @@ class Compiler(IndentPrintable):
         while self.q.qsize()>0:
             self.prepareX(self.q.get())
 
-        for m in self.tree:
+        for m in [m for m in self.tree if m.name.lower() == module.lower()]:
             for iface in m.getTypes('Interface'):
-                #if iface.inherit in [x.name for x in self.ctx['exportedInterface']]:
-                #    iface.exported = True
+                xctor = iface.constructor if hasattr(iface, 'constructor') else None
+                if xctor:
+                    xctor.primitiveArgs = [x for x in xctor.arguments if x.xtype.name in cppPrimitiveMap]
+                    attributes = iface.getTypes('Attribute')
+                    ctorArgs = [arg.name for arg in xctor.arguments] if xctor else []
+                    for attr in attributes:
+                        if attr.name in ctorArgs:
+                            attr.existIn = 'ctor'
+                        if xctor:
+                            for x in xctor.arguments:
+                                if x.xtype.name in self.ctx['interfaces'] or x.xtype.name in self.ctx['dictionary']:
+                                    argtypes = dict(self.ctx['interfaces'].items() + self.ctx['dictionary'].items())
+                                    argtype = argtypes[x.xtype.name]
+                                    for child in argtype.childs:
+                                        if child.name == attr.name:
+                                            attr.existIn = x.name + "." + child.name
+                                    break
+                    if len([x for x in attributes if not hasattr(x, "existIn")]) > 0:
+                        native_function = iface.name + "Constructor"
+                        native_cmd = iface.name + "_constructor"
+                        self.ctx['cmdtable'][native_function] = native_cmd
+                if iface.inherit in [x.name for x in self.ctx['exportedInterface']]:
+                    iface.private = True
                 #if iface.name in self.ctx['callback']:
                     #iface.isListener = True
+
                 for operation in iface.getTypes('Operation'):
                     if hasattr(iface, 'exported') and iface.exported:
-                        operation.native_cmd = iface.name+'_'+operation.name
-                        operation.native_function = iface.name+(operation.name.title())
-                        self.ctx['cmdtable'][operation.native_function] = operation.native_cmd
+                        #operation.native_cmd = iface.name+'_'+operation.name
+                        #operation.native_function = iface.name+(operation.name.title())
+                        #self.ctx['cmdtable'][operation.native_function] = operation.native_cmd
+                        native_cmd = iface.name+'_'+operation.name
+                        native_function = iface.name+(operation.name.title())
+                        self.ctx['cmdtable'][native_function] = native_cmd
                     operation.argnames = [a.name for a in operation.arguments]
                     operation.primitiveArgs = [x for x in operation.arguments if x.xtype.name in cppPrimitiveMap]
                     for arg in operation.arguments:
+                        if arg.xtype.name in self.ctx['interfaces'] and \
+                            hasattr(self.ctx['interfaces'][arg.xtype.name], 'constructor'):
+                            arg.isPlatformObject = True
+
                         if arg.xtype.name in self.ctx['enum']:
                             arg.isEnum = True
                             arg.enums = self.ctx['enum'][arg.xtype.name]
@@ -145,7 +175,7 @@ class Compiler(IndentPrintable):
     def prepareX(self, x):
         if isinstance(x, WebIDL.XImplements) and (x.name in ['Tizen', 'Window']) and x.parent.name.lower() == self.ctx['exportModule'].lower():
             self.ctx['implementedClass'].append(x.impl)
-            self.ctx[x.name].append(x.impl)
+            #self.ctx[x.name].append(x.impl)
             impl = x.parent.get('Interface', x.impl)
             impl.implements = x.name
 
@@ -155,8 +185,8 @@ class Compiler(IndentPrintable):
                 #inheritIface = x.parent.parent.get('Interface', x.xtype.name)
                 inheritIface = self.ctx['interfaces'][x.xtype.name]
                 if inheritIface :
-                    self.ctx[x.parent.implements] = inheritIface.name
-                    inheritIface.exported = True
+                    #self.ctx[x.parent.implements] = inheritIface.name
+                    inheritIface.exported = x.parent.implements
                     self.ctx['exportedInterface'].append(inheritIface)
 
         if isinstance(x, WebIDL.XInterface):
@@ -169,6 +199,7 @@ class Compiler(IndentPrintable):
             xctor = next((c for c in x.getTypes('ExtendedAttribute') if c.name == 'Constructor'), None)
             if xctor:
                 x.constructor = xctor
+                x.exported = x.name
 
         if isinstance(x, WebIDL.XOperation):
             module = x.parent.parent
@@ -178,7 +209,7 @@ class Compiler(IndentPrintable):
                 #inheritIface = module.get('Interface', x.returnType.name)
                 inheritIface = self.ctx['interfaces'][x.returnType.name]
                 if inheritIface :
-                    inheritIface.exported = True
+                    inheritIface.exported = inheritIface.name
                     self.ctx['exportedInterface'].append(inheritIface)
 
         if isinstance(x, WebIDL.XDictionary):
@@ -189,6 +220,7 @@ class Compiler(IndentPrintable):
 
         if isinstance(x, WebIDL.XEnum):
             self.ctx['enum'][x.name] = x.childs
+            cppPrimitiveMap[x.name] = 'std::string'
 
         if isinstance(x, WebIDL.XObject):
             for child in x.childs:
@@ -203,8 +235,8 @@ class Compiler(IndentPrintable):
         modules = self.tree if module == None else [m for m in self.tree if m.name.lower() == module.lower()]
         return tpl.render({'modules':modules,
             'callbacks':self.ctx['callback'],
-            'tizen': self.ctx['Tizen'],
-            'window': self.ctx['Window'],
+            #'tizen': self.ctx['Tizen'],
+            #'window': self.ctx['Window'],
             'cmdtable' : self.ctx['cmdtable'],
             'year' : date.today().year})
 
@@ -239,8 +271,8 @@ class Compiler(IndentPrintable):
         #m = [m for m in self.tree if m.name.lower() == module.lower()]
         m = [m for m in self.tree]
         vals['moduleObj'] = m[0] if len(m)>0 else None
-        vals['tizen'] = self.ctx['Tizen']
-        vals['window'] = self.ctx['Window']
+        #vals['tizen'] = self.ctx['Tizen']
+        #vals['window'] = self.ctx['Window']
         vals['cmdtable'] = self.ctx['cmdtable']
         vals['year'] = date.today().year
 
index 0c66439..819ec08 100644 (file)
@@ -90,7 +90,11 @@ var {{enums.name}} = {
 {% endfor %}
 
 {% for iface in module.getTypes('Interface') %}
-{% if iface.exported %}
+{% if iface.exported  or iface.private %}
+
+{% if iface.private %}
+// private constructor
+{% endif %}
 function {{iface.name}}(
     {%-if iface.constructor -%}
     {%- for arg in iface.constructor.arguments -%}
@@ -98,6 +102,30 @@ function {{iface.name}}(
     {%- endfor -%}
     {%- endif -%}) {
   // constructor of {{iface.name}}
+  {% if iface.constructor %}
+  var nativeParam = {
+    {% for arg in iface.constructor.primitiveArgs %}
+    '{{arg.name}}': args.{{arg.name}}{% if not loop.last %},{% endif %}
+
+    {% endfor %}
+  };
+  var syncResult = callNative('{{iface.name}}_constructor', nativeParam);
+
+  {% for attribute in iface.getTypes('Attribute') %}
+    {% if attribute.existIn == 'ctor' %}
+    {% set attrValue = attribute.name %}
+    {% elif attribute.existIn %}
+    {% set attrValue = attribute.existIn %}
+    {% else %}
+    {% set attrValue = "null" %}
+    {% endif %}
+    {% if attribute.readonly %}
+  SetReadOnlyProperty(this, '{{attribute.name}}', {{attrValue}}); // read only property
+    {% else %}
+  this.{{attribute.name}} = {{attrValue}};
+    {% endif %}
+  {% endfor %}
+  {% endif %}
 }
 
 {% if iface.inherit %}
@@ -139,6 +167,8 @@ function {{iface.name}}(
         ]
       {%- elif arg.xtype.name in type_map -%}
         {{type_map[arg.xtype.name]}}
+      {%- elif arg.isPlatformObject -%}
+        PLATFORM_OBJECT, 'values': tizen.{{arg.xtype.name}}
       {%- else -%}
         DICTIONARY
       {%- endif -%}
@@ -159,7 +189,7 @@ function {{iface.name}}(
   };
 
   {% for arg in operation.primitiveArgs if arg.optional %}
-  if (args['{{arg.name}}']){
+  if (args['{{arg.name}}']) {
     nativeParam['{{arg.name}}'] = args.{{arg.name}};
   }
   {% endfor %}
@@ -202,24 +232,6 @@ function {{iface.name}}(
 
   {% if operation.returnInternal %}
   var returnObject = new {{operation.returnInternal.name}}();
-  {% for attribute in operation.returnInternal.getTypes('Attribute') %}
-  {% if attribute.readonly %}
-  SetReadOnlyProperty(returnObject, '{{attribute.name}}', {% if attribute.name in operation.argnames -%}
-        {{attribute.name}}); // read only property
-      {%- else -%}
-        null); // read only property
-      {%- endif %}
-
-  {% else %}
-  returnObject.{{attribute.name}} = {% if attribute.name in operation.argnames -%}
-        {{attribute.name}};
-      {%- else -%}
-        null;
-      {%- endif %}
-
-  {% endif %}
-  {% endfor %}
-
   return returnObject;
   {% endif %}
 };
@@ -229,9 +241,14 @@ function {{iface.name}}(
 {% endif %}
 {% endfor %}
 
-exports = new {{tizen}}();
-{% if window %}
-window.{{window}} = new {{window}}();
-{% endif %}
+{% for iface in module.getTypes('Interface') %}
+    {% if iface.exported == 'Tizen' %}
+exports = new {{iface.name}}();
+    {% elif iface.exported == 'Window' %}
+window.{{iface.name}} = new {{iface.name}}();
+    {% elif iface.exported %}
+tizen.{{iface.name}} = {{iface.name}};
+    {% endif %}
+{% endfor %}
 
 {% endfor %}
index 9aafa1b..1458f7b 100644 (file)
@@ -16,6 +16,16 @@ common::Extension* CreateExtension() {
 {{module.title}}Extension::{{module.title}}Extension() {
   SetExtensionName("tizen.{{module.lower}}");
   SetJavaScriptAPI(kSource_{{module.lower}}_api);
+
+  const char* entry_points[] = {
+  {% for iface in moduleObj.getTypes('Interface') %}
+    {% if iface.exported and (iface.exported != 'Tizen' or iface.exported != 'Window') %}
+      "tizen.{{iface.name}}",
+    {% endif %}
+  {% endfor %}
+      NULL
+    };
+  SetExtraJSEntryPoints(entry_points);
 }
 
 {{module.title}}Extension::~{{module.title}}Extension() {}
index ab68737..d80d9ad 100644 (file)
@@ -16,12 +16,8 @@ class {{module.title}}Instance : public common::ParsedInstance {
   virtual ~{{module.title}}Instance();
 
  private:
-  {% for iface in moduleObj.getTypes('Interface') %}
-    {% if iface.exported %}
-      {% for operation in iface.getTypes('Operation') %}
-  void {{operation.native_function}}(const picojson::value& args, picojson::object& out);
-      {% endfor %}
-    {% endif %}
+  {% for func in cmdtable %}
+  void {{func}}(const picojson::value& args, picojson::object& out);
   {% endfor %}
 };