[gobject-introspection/mallard-templates] g-ir-doc-tool: More Mallard work, using experimantal api extension



commit 44b916a56620554237a7c02ca3da1fb96d898a97
Author: Shaun McCance <shaunm gnome org>
Date:   Tue Aug 23 09:12:02 2011 -0400

    g-ir-doc-tool: More Mallard work, using experimantal api extension

 giscanner/ast.py                     |    2 +
 giscanner/girparser.py               |   30 ++++++++++++----------
 giscanner/mallard-C-class.tmpl       |   11 ++++++--
 giscanner/mallard-C-function.tmpl    |    4 +++
 giscanner/mallard-C-method.tmpl      |   46 ++++++++++++++++++++++++++++++++-
 giscanner/mallard-Python-method.tmpl |    5 +--
 6 files changed, 76 insertions(+), 22 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 1433422..99ddf55 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -552,6 +552,7 @@ class Callable(Node):
         self.parameters = parameters
         self.throws = not not throws
         self.instance_parameter = None # Parameter
+        self.parent = None # A Class or Interface
 
     def get_parameter_index(self, name):
         for i, parameter in enumerate(self.parameters):
@@ -999,6 +1000,7 @@ class Property(Node):
             self.transfer = PARAM_TRANSFER_NONE
         else:
             self.transfer = transfer
+        self.parent = None # A Class or Interface
 
 
 class Callback(Callable):
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index d7a59b8..2488a6c 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -248,27 +248,27 @@ class GIRParser(object):
         for iface in self._find_children(node, _corens('prerequisite')):
             obj.prerequisites.append(self._namespace.type_from_name(iface.attrib['name']))
         for func_node in self._find_children(node, _corens('function')):
-            func = self._parse_function_common(func_node, ast.Function)
+            func = self._parse_function_common(func_node, ast.Function, obj)
             obj.static_methods.append(func)
         for method in self._find_children(node, _corens('method')):
-            func = self._parse_function_common(method, ast.Function)
+            func = self._parse_function_common(method, ast.Function, obj)
             func.is_method = True
             obj.methods.append(func)
         for method in self._find_children(node, _corens('virtual-method')):
-            func = self._parse_function_common(method, ast.VFunction)
+            func = self._parse_function_common(method, ast.VFunction, obj)
             self._parse_generic_attribs(method, func)
             func.is_method = True
             func.invoker = method.get('invoker')
             obj.virtual_methods.append(func)
         for ctor in self._find_children(node, _corens('constructor')):
-            func = self._parse_function_common(ctor, ast.Function)
+            func = self._parse_function_common(ctor, ast.Function, obj)
             func.is_constructor = True
             obj.constructors.append(func)
         obj.fields.extend(self._parse_fields(node))
         for prop in self._find_children(node, _corens('property')):
-            obj.properties.append(self._parse_property(prop))
+            obj.properties.append(self._parse_property(prop, obj))
         for signal in self._find_children(node, _glibns('signal')):
-            obj.signals.append(self._parse_function_common(signal, ast.Signal))
+            obj.signals.append(self._parse_function_common(signal, ast.Signal, obj))
 
     def _parse_callback(self, node):
         callback = self._parse_function_common(node, ast.Callback)
@@ -278,7 +278,7 @@ class GIRParser(object):
         function = self._parse_function_common(node, ast.Function)
         self._namespace.append(function)
 
-    def _parse_function_common(self, node, klass):
+    def _parse_function_common(self, node, klass, parent=None):
         name = node.attrib['name']
         returnnode = node.find(_corens('return-value'))
         if not returnnode:
@@ -311,6 +311,7 @@ class GIRParser(object):
         func.shadows = node.attrib.get('shadows', None)
         func.shadowed_by = node.attrib.get('shadowed-by', None)
         func.moved_to = node.attrib.get('moved-to', None)
+        func.parent = parent
 
         parameters_node = node.find(_corens('parameters'))
         if (parameters_node is not None):
@@ -369,13 +370,13 @@ class GIRParser(object):
             compound.fields.extend(self._parse_fields(node))
             for method in self._find_children(node, _corens('method')):
                 compound.methods.append(
-                    self._parse_function_common(method, ast.Function))
+                    self._parse_function_common(method, ast.Function, compound))
             for func in self._find_children(node, _corens('function')):
                 compound.static_methods.append(
-                    self._parse_function_common(func, ast.Function))
+                    self._parse_function_common(func, ast.Function, compound))
             for ctor in self._find_children(node, _corens('constructor')):
                 compound.constructors.append(
-                    self._parse_function_common(ctor, ast.Function))
+                    self._parse_function_common(ctor, ast.Function, compound))
         return compound
 
     def _parse_record(self, node, anonymous=False):
@@ -474,15 +475,15 @@ class GIRParser(object):
         if self._types_only:
             return
         for method in self._find_children(node, _corens('method')):
-            func = self._parse_function_common(method, ast.Function)
+            func = self._parse_function_common(method, ast.Function, obj)
             func.is_method = True
             obj.methods.append(func)
         for ctor in self._find_children(node, _corens('constructor')):
             obj.constructors.append(
-                self._parse_function_common(ctor, ast.Function))
+                self._parse_function_common(ctor, ast.Function, obj))
         for callback in self._find_children(node, _corens('callback')):
             obj.fields.append(
-                self._parse_function_common(callback, ast.Callback))
+                self._parse_function_common(callback, ast.Callback, obj))
 
     def _parse_field(self, node):
         type_node = None
@@ -513,7 +514,7 @@ class GIRParser(object):
         self._parse_generic_attribs(node, field)
         return field
 
-    def _parse_property(self, node):
+    def _parse_property(self, node, parent):
         prop = ast.Property(node.attrib['name'],
                         self._parse_type(node),
                         node.attrib.get('readable') != '0',
@@ -522,6 +523,7 @@ class GIRParser(object):
                         node.attrib.get('construct-only') == '1',
                         node.attrib.get('transfer-ownership'))
         self._parse_generic_attribs(node, prop)
+        prop.parent = parent
         return prop
 
     def _parse_member(self, node):
diff --git a/giscanner/mallard-C-class.tmpl b/giscanner/mallard-C-class.tmpl
index 5dc5922..935146a 100644
--- a/giscanner/mallard-C-class.tmpl
+++ b/giscanner/mallard-C-class.tmpl
@@ -3,11 +3,12 @@
       type="guide"
       style="class"
       xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
       xmlns:ui="http://projectmallard.org/experimental/ui/";>
   <info>
     <link type="guide" xref="index" group="class"/>
   </info>
-  <title>${node.namespace.name}${node.name}</title>
+  <title>${node.ctype}</title>
 ${format(node.doc)}
   <synopsis ui:expanded="no">
     <title>Hierarchy</title>
@@ -17,10 +18,14 @@ ${format(node.doc)}
       </item>
     </tree>
   </synopsis>
-  <links type="topic" ui:expanded="yes" groups="constructor" style="linklist">
+  <links type="topic" ui:expanded="yes"
+         api:type="function" api:mime="text/x-csrc"
+         groups="constructor" style="linklist">
     <title>Constructors</title>
   </links>
-  <links type="topic" ui:expanded="yes" groups="method" style="linklist">
+  <links type="topic" ui:expanded="yes"
+         api:type="function" api:mime="text/x-csrc"
+         groups="method" style="linklist">
     <title>Methods</title>
   </links>
   <links type="topic" ui:expanded="yes" groups="property" style="linklist">
diff --git a/giscanner/mallard-C-function.tmpl b/giscanner/mallard-C-function.tmpl
index fabbe31..8fcd30a 100644
--- a/giscanner/mallard-C-function.tmpl
+++ b/giscanner/mallard-C-function.tmpl
@@ -3,9 +3,13 @@
       type="topic"
       style="function"
       xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
       xmlns:ui="http://projectmallard.org/experimental/ui/";>
   <info>
     <link type="guide" xref="index" group="function"/>
+    <api:function>
+      <api:name>${node.symbol}</api:name>
+    </api:function>
   </info>
   <title>${node.symbol}</title>
 ${format(node.doc)}</page>
diff --git a/giscanner/mallard-C-method.tmpl b/giscanner/mallard-C-method.tmpl
index bf998ab..47f1051 100644
--- a/giscanner/mallard-C-method.tmpl
+++ b/giscanner/mallard-C-method.tmpl
@@ -1,11 +1,53 @@
 <?xml version="1.0"?>
-<page id="${namespace.name}.${parent.name}.${node.name}"
+<page id="${namespace.name}.${node.parent.name}.${node.name}"
       type="topic"
       style="method"
       xmlns="http://projectmallard.org/1.0/";
+      xmlns:api="http://projectmallard.org/experimental/api/";
       xmlns:ui="http://projectmallard.org/experimental/ui/";>
   <info>
-    <link type="guide" xref="${namespace.name}.${parent.name}" group="method"/>
+    <link type="guide" xref="${namespace.name}.${node.parent.name}" group="method"/>
+    <api:function>
+      <api:returns>
+        <api:type>${node.retval.type.ctype}</api:type>
+      </api:returns>
+      <api:name>${node.symbol}</api:name>
+      <api:arg>
+        <api:type>${node.parent.ctype} *</api:type>
+        <api:name>self</api:name>
+      </api:arg>
+% for arg in node.parameters:
+% if arg.type.ctype == '<varargs>':
+      <api:varargs/>
+% else:
+      <api:arg>
+        <api:type>${arg.type.ctype}</api:type>
+        <api:name>${arg.argname}</api:name>
+      </api:arg>
+% endif
+% endfor
+    </api:function>
   </info>
   <title>${node.symbol}</title>
+<synopsis><code>
+${node.retval.type.ctype} ${node.symbol} (${node.parent.ctype} *self\
+% if len(node.parameters) == 0:
+);
+% else:
+,
+% endif
+% for arg, ix in zip(node.parameters, range(len(node.parameters))):
+${' ' * (len(node.retval.type.ctype) + len(node.symbol) + 3)}\
+% if arg.type.ctype == '<varargs>':
+...\
+% else:
+${arg.type.ctype} ${arg.argname}\
+% endif
+% if ix == len(node.parameters) - 1:
+);
+% else:
+,
+%endif
+% endfor
+</code></synopsis>
 ${format(node.doc)}</page>
diff --git a/giscanner/mallard-Python-method.tmpl b/giscanner/mallard-Python-method.tmpl
index 53e58f3..4541725 100644
--- a/giscanner/mallard-Python-method.tmpl
+++ b/giscanner/mallard-Python-method.tmpl
@@ -1,13 +1,12 @@
 <?xml version="1.0"?>
-<page id="${namespace.name}.${parent.name}.${node.name}"
+<page id="${namespace.name}.${node.parent.name}.${node.name}"
       type="topic"
       style="method"
       xmlns="http://projectmallard.org/1.0/";
       xmlns:ui="http://projectmallard.org/experimental/ui/";
       xmlns:c="http://www.gtk.org/introspection/c/1.0";>
   <info>
-    <link type="guide" xref="${namespace.name}.${parent.name}" group="method"/>
-    <c:identifier>${node.symbol}</c:identifier>
+    <link type="guide" xref="${namespace.name}.${node.parent.name}" group="method"/>
   </info>
   <title>${node.symbol}</title>
 ${format(node.doc)}</page>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]