[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-gtk-cvs
Subject:    [php-gtk-cvs] com gtk/php-gtk: First pass at documentation structure generator.: =?UTF-8?Q?generator
From:       David Soria Parra <dsp () php ! net>
Date:       2001-05-20 1:03:35
Message-ID: php-mail-ffcacc572c55e7edf5ac6b5a53a6ac72484492408 () git ! php ! net
[Download RAW message or body]

Commit:    4601bc515b74e95a4cff49c993e6f1912c3dbc75
Author:    Andrei Zmievski <andrei@php.net>         Sun, 20 May 2001 01:03:35 +0000
Parents:   416da991c9f6db46bc660c691e78ee92105239bd
Branches:  GTK2 PHP_GTK_1 ZE2_PORT devel master

Link:       http://git.php.net/?p=gtk/php-gtk.git;a=commitdiff;h=4601bc515b74e95a4cff49c993e6f1912c3dbc75

Log:
First pass at documentation structure generator.

Changed paths:
  A  generator/doc_templates.php
  A  generator/docgen.php
  M  generator/generator.php
  M  generator/gtk.overrides


["diff_4601bc515b74e95a4cff49c993e6f1912c3dbc75.txt" (text/plain)]

4601bc515b74e95a4cff49c993e6f1912c3dbc75
diff --git a/generator/doc_templates.php b/generator/doc_templates.php
new file mode 100644
index 0000000..5b39561
--- /dev/null
+++ b/generator/doc_templates.php
@@ -0,0 +1,119 @@
+<?php
+/*
+ * PHP-GTK - The PHP language bindings for GTK+
+ *
+ * Copyright (C) 2001 Andrei Zmievski <andrei@php.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/* $Id$ */
+
+$class_start_tpl = <<<EOD
+<classentry id="%s.%s">
+ <classmeta>
+  <classtitle>%s</classtitle>
+  <classparent>%s</classparent>
+  <shortdesc>
+  </shortdesc>
+  <desc>
+   <para>
+   </para>
+  </desc>
+ </classmeta>
+
+EOD;
+
+$class_end_tpl = <<<EOD
+
+</classentry>
+
+EOD;
+
+$methods_start_tpl = <<<EOD
+
+ <methods>
+
+EOD;
+
+$methods_end_tpl = <<<EOD
+
+ </methods>
+
+EOD;
+
+$method_start_tpl = <<<EOD
+
+  <method id="%s.%s.method.%s">
+   <funcsynopsis>
+    <funcprototype>
+
+EOD;
+
+$method_end_tpl = <<<EOD
+    </funcprototype>
+   </funcsynopsis>
+   <shortdesc>
+   </shortdesc>
+   <desc>
+    <para>
+    </para>
+   </desc>
+  </method>
+
+EOD;
+
+$constructor_start_tpl = <<<EOD
+
+ <constructor id="%s.%s.constructor">
+  <funcsynopsis>
+   <funcprototype>
+
+EOD;
+
+$constructor_end_tpl = <<<EOD
+   </funcprototype>
+  </funcsynopsis>
+  <shortdesc>
+  </shortdesc>
+  <desc>
+   <para>
+   </para>
+  </desc>
+ </constructor>
+
+EOD;
+
+$funcproto_tpl = <<<EOD
+     <funcdef>%s <function>%s</function></funcdef>
+%s
+EOD;
+
+$parameter_tpl = <<<EOD
+     <paramdef>%s <parameter>%s</parameter></paramdef>
+
+EOD;
+
+$opt_parameter_tpl = <<<EOD
+     <paramdef>%s <parameter><optional>%s = %s<optional></parameter></paramdef>
+
+EOD;
+
+$no_parameter_tpl = <<<EOD
+     <paramdef>%s</paramdef>
+
+EOD;
+
+?>
diff --git a/generator/docgen.php b/generator/docgen.php
new file mode 100644
index 0000000..6ccab63
--- /dev/null
+++ b/generator/docgen.php
@@ -0,0 +1,302 @@
+<?php
+/*
+ * PHP-GTK - The PHP language bindings for GTK+
+ *
+ * Copyright (C) 2001 Andrei Zmievski <andrei@php.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/* $Id$ */
+
+set_time_limit(300);
+
+require "Getopt.php";
+require "arg_types.php";
+require "override.php";
+require "scheme.php";
+require "doc_templates.php";
+
+class DocGenerator {
+	var $parser 	= null;
+	var $overrides  = null;
+	var $prefix		= null;
+	var $fp			= null;
+
+	function DocGenerator(&$parser, &$overrides, $prefix)
+	{
+		$this->parser 	 = &$parser;
+		$this->overrides = &$overrides;
+		$this->prefix	 = $prefix;
+		$this->fp		 = fopen('php://stdout', 'w');
+	}
+
+	function create_docs($classes)
+	{
+		foreach ($classes as $key => $val)
+			$classes[$key] = strtolower($val);
+								 
+		function sort_objects($a, $b)
+		{
+			return strcmp($a->c_name, $b->c_name);
+		}
+		$parser_objects = $this->parser->objects;
+		usort($parser_objects, 'sort_objects');
+
+		foreach ($parser_objects as $object) {
+			$object_lcname = strtolower($object->c_name);
+			if (count($classes) && !in_array($object_lcname, $classes))
+				continue;
+
+			$this->write_class($object);
+		}
+	}
+	
+	function register_types($parser = null)
+	{
+		global	$matcher;
+
+		if (!$parser)
+			$parser = $this->parser;
+
+		foreach ($parser->objects as $object)
+			$matcher->register_object($object->c_name);
+
+		foreach ($parser->enums as $enum) {
+			if ($enum->def_type == 'flags')
+				$matcher->register_flag($enum->c_name);
+			else
+				$matcher->register_enum($enum->c_name);
+		}
+	}
+
+	function write_class($object)
+	{
+		global	$class_start_tpl,
+				$class_end_tpl;
+
+		$object_name = $object->in_module . $object->name;
+		fwrite($this->fp,
+			   sprintf($class_start_tpl,
+					   $this->prefix,
+					   strtolower($object_name),
+					   $object_name,
+					   $object->parent[1] . $object->parent[0]));
+		$this->write_constructor($object);
+		$this->write_methods($object);
+		fwrite($this->fp, $class_end_tpl);
+	}
+
+	function write_methods($object)
+	{
+		global	$methods_start_tpl,
+				$methods_end_tpl;
+
+		$methods = $this->parser->find_methods($object);
+		if (count($methods))
+			fwrite($this->fp, $methods_start_tpl);
+
+		foreach ($methods as $method) {
+			if ($this->overrides->is_overriden($method->c_name)) {
+				$this->write_method($method, true);
+			} else if (!$this->overrides->is_ignored($method->c_name)) {
+				$this->write_method($method, false);
+			}
+		}
+
+		if (count($methods))
+			fwrite($this->fp, $methods_end_tpl);
+	}
+
+	function write_constructor($object)
+	{
+		global	$constructor_start_tpl,
+				$constructor_end_tpl,
+				$funcproto_tpl,
+				$no_parameter_tpl;
+
+		$constructor = $this->parser->find_constructor($object);
+		
+		if ($constructor) {
+			if ($this->overrides->is_overriden($constructor->c_name)) {
+				$overriden = true;
+			} else if (!$this->overrides->is_ignored($constructor->c_name)) {
+				$overriden = false;
+			} else
+				return;
+		} else
+			return;
+
+		if (!$overriden) {
+			if (($paramdef = $this->get_paramdef($constructor)) === false)
+				return;
+		}
+
+		$object_name = $constructor->is_constructor_of;
+
+		fwrite($this->fp,
+			   sprintf($constructor_start_tpl,
+					   $this->prefix,
+					   strtolower($object_name)));
+
+		$funcdef = sprintf($funcproto_tpl,
+						   '',
+						   $object_name,
+						   $overriden ? sprintf($no_parameter_tpl, 'XXX') : $paramdef);
+		fwrite($this->fp, preg_replace('!^ !m', '', $funcdef));
+
+		fwrite($this->fp, $constructor_end_tpl);
+	}
+
+	function write_method($method, $overriden)
+	{
+		global	$method_start_tpl,
+				$method_end_tpl,
+				$funcproto_tpl,
+				$no_parameter_tpl;
+
+		if (!$overriden) {
+			if (($paramdef = $this->get_paramdef($method)) === false ||
+				($return = $this->get_type($method->return_type)) === false)
+				return;
+		}
+
+		$object_name = $method->of_object[1] . $method->of_object[0];
+
+		fwrite($this->fp,
+			   sprintf($method_start_tpl,
+					   $this->prefix,
+					   strtolower($object_name),
+					   $method->name));
+
+		fwrite($this->fp,
+			   sprintf($funcproto_tpl,
+					   $overriden ? 'XXX' : $return,
+					   $method->name,
+					   $overriden ? sprintf($no_parameter_tpl, 'XXX') : $paramdef));
+		
+		fwrite($this->fp, $method_end_tpl);
+	}
+
+	function get_paramdef($function)
+	{
+		global	$matcher,
+				$parameter_tpl,
+				$no_parameter_tpl,
+				$opt_parameter_tpl;
+
+		if ($function->varargs)
+			return false;
+
+		foreach ($function->params as $params_array) {
+			list($param_type, $param_name, $param_default, $param_null) = $params_array;
+
+			if (($doc_type = $this->get_type($param_type)) === false)
+				return false;
+
+			if (isset($param_default))
+				$paramdef .= sprintf($opt_parameter_tpl, $doc_type, $param_name, $param_default);
+			else
+				$paramdef .= sprintf($parameter_tpl, $doc_type, $param_name);
+		}
+
+		return $paramdef ? $paramdef : sprintf($no_parameter_tpl, 'void');
+	}
+
+	function get_type($in_type)
+	{
+		global	$matcher;
+		static 	$type_map = 
+			array('none'			=> 'void',
+				  
+				  'char*'			=> 'string',
+				  'gchar*'			=> 'string',
+				  'const-char*'		=> 'string',
+				  'const-gchar*'	=> 'string',
+				  'string'			=> 'string',
+				  'static_string'	=> 'string',
+				  'unsigned-char*'	=> 'string',
+				  'guchar*'			=> 'string',
+
+				  'char'			=> 'char',
+				  'gchar'			=> 'char',
+				  'guchar'			=> 'char',
+
+				  'int'				=> 'int',
+				  'gint'			=> 'int',
+				  'guint'			=> 'int',
+				  'short'			=> 'int',
+				  'gshort'			=> 'int',
+				  'gushort'			=> 'int',
+				  'long'			=> 'int',
+				  'glong'			=> 'int',
+				  'gulong'			=> 'int',
+
+				  'guint8'			=> 'int',
+				  'gint8'			=> 'int',
+				  'guint16'			=> 'int',
+				  'gint16'			=> 'int',
+				  'guint32'			=> 'int',
+				  'gint32'			=> 'int',
+				  'GtkType'			=> 'int',
+
+				  'gboolean'		=> 'bool',
+
+				  'double'			=> 'double',
+				  'gdouble'			=> 'double',
+				  'float'			=> 'double',
+				  'gfloat'			=> 'double',
+
+				  'GdkDrawable*'	=> 'GdkWindow');
+
+		$type_handler = &$matcher->get($in_type);
+		if ($type_handler === null)
+			return false;
+
+		if (isset($type_map[$in_type]))
+			return $type_map[$in_type];
+		else
+			return str_replace('*', '', $in_type);
+	}
+}
+
+$argc = $HTTP_SERVER_VARS['argc'];
+$argv = $HTTP_SERVER_VARS['argv'];
+
+$result = Console_Getopt::getopt($argv, 'o:p:');
+if (!$result || count($result[1]) < 2)
+	die("usage: php -q generator.php [-o overridesfile] [-p prefix] defsfile [class]\n");
+
+list($opts, $argv) = $result;
+
+$prefix = 'gtk';
+$overrides = new Overrides();
+
+foreach ($opts as $opt) {
+	list($opt_spec, $opt_arg) = $opt;
+	if ($opt_spec == 'o') {
+		$overrides = new Overrides($opt_arg);
+	} else if ($opt_spec == 'p') {
+		$prefix = $opt_arg;
+	}
+}
+
+$parser = new Defs_Parser($argv[1]);
+$generator = new DocGenerator($parser, $overrides, $prefix);
+$parser->start_parsing();
+$generator->register_types();
+$generator->create_docs(array_slice($argv, 2));
+
+?>
diff --git a/generator/generator.php b/generator/generator.php
index fdc6652..23d67e6 100644
--- a/generator/generator.php
+++ b/generator/generator.php
@@ -42,7 +42,6 @@ class Generator {
 
 	var $constants	= '';
 	var $register_classes = '';
-	var $class_entries = array();
 
 	var $functions_decl_end = "\t{NULL, NULL, NULL}\n};\n\n";
 
diff --git a/generator/gtk.overrides b/generator/gtk.overrides
index 8d20420..97f1d9a 100644
--- a/generator/gtk.overrides
+++ b/generator/gtk.overrides
@@ -1732,7 +1732,7 @@ getprop GtkCTree row_list
 %%
 ignore gtk_ctree_node_set_row_data_full
 %%
-override gtk_ctree_node_set_row_data kwargs
+override gtk_ctree_node_set_row_data
 PHP_FUNCTION(wrap_gtk_ctree_node_set_row_data)
 {
 	zval *node, *data;

-- 
PHP-GTK CVS Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic