cvs: pear /CodeGen_PECL/PECL/Element Function.php Method.php
| From: | Hartmut Holzgraefe | Date: | Tue, 17 Oct 2006 11:08:04 +0000 |
| Subject: | cvs: pear /CodeGen_PECL/PECL/Element Function.php Method.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42598@lists.php.net to get a copy of this message | ||
hholzgra Tue Oct 17 11:08:04 2006 UTC
Modified files:
/pear/CodeGen_PECL/PECL/Element Function.php Method.php
Log:
simplified ARG_INFO creation (work in progres)
http://cvs.php.net/viewvc.cgi/pear/CodeGen_PECL/PECL/Element/Function.php?r1=1.39&r2=1.40&diff_format=u
Index: pear/CodeGen_PECL/PECL/Element/Function.php
diff -u pear/CodeGen_PECL/PECL/Element/Function.php:1.39
pear/CodeGen_PECL/PECL/Element/Function.php:1.40
--- pear/CodeGen_PECL/PECL/Element/Function.php:1.39 Thu Oct 12 13:11:58 2006
+++ pear/CodeGen_PECL/PECL/Element/Function.php Tue Oct 17 11:08:04 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005, 2006 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Function.php,v 1.39 2006/10/12 13:11:58 hholzgra Exp $
+ * @version CVS: $Id: Function.php,v 1.40 2006/10/17 11:08:04 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -993,7 +993,6 @@
switch ($this->role) {
case "public":
-
$code .= $this->ifConditionStart();
// function prototype comment
@@ -1448,7 +1447,7 @@
$code.= ";\n";
}
- $code.= $this->argInfoCode();
+ $code.= $this->argInfoCode($this->params);
$code.= $this->ifConditionEnd();
@@ -1459,35 +1458,82 @@
/**
* Code needed ahead of the function table
*
- * Only required for functions that accept parameters by reference
- *
- * @returns string
+ * @param array
+ * @return string
*/
- function argInfoCode()
+ function argInfoCode($params)
{
+ // TODO only generate code for versions actually requested
+ // TODO only allow null on objects/arrays with default=NULL ?
+
+ $argInfoName = $this->argInfoName();
+
$code = "";
// generate refargs mask if needed
+ $code.= "#if (PHP_MAJOR_VERSION >= 5)\n";
+
+ $code.= "ZEND_BEGIN_ARG_INFO($argInfoName, 0)\n";
+
+ foreach ($params as $param) {
+ switch ($param["type"]) {
+ case 'object':
+ $code.= sprintf(" ZEND_ARG_OBJ_INFO(%d, %s, %s, 1)\n",
+ isset($param["byRef"]),
+ $param["name"],
+ $param["subtype"]);
+ break;
+ case 'array':
+ $code.= "#if (PHP_MINOR_VERSION > 0)\n";
+ $code.= sprintf(" ZEND_ARG_ARRAY_INFO(%d, %s, %s, %d)\n",
+ isset($param["byRef"]),
+ $param["name"],
+ $param["subtype"],
+ 1 /*allow NULL*/);
+ $code.= "#else\n";
+ $code.= sprintf(" ZEND_ARG_INFO(%d, %s)\n",
+ isset($param["byRef"]),
+ $param["name"],
+ 1 /*allow NULL*/);
+ $code.= "#endif\n";
+ break;
+ default:
+ $code.= sprintf(" ZEND_ARG_INFO(%d, %s)\n",
+ isset($param["byRef"]),
+ $param["name"]);
+ break;
+ }
+ }
+
+ $code.= "ZEND_END_ARG_INFO()\n";
+
+ $code.= "#else /* PHP 4.x */\n";
+
if ($this->hasRefArgs) {
- $code.="#if (PHP_MAJOR_VERSION < 5)\n";
- $code.="static unsigned char {$this->name}_arg_info[] =
{".count($this->params);
- foreach ($this->params as $param) {
+ $code.= "static unsigned char {$argInfoName}[] = {".count($params);
+ foreach ($params as $param) {
$code.= ", ". (isset($param["byRef"]) ? "BYREF_FORCE"
: "BYREF_NONE");
}
$code.="};\n";
- $code.="#else\n";
- $code.= "ZEND_BEGIN_ARG_INFO({$this->name}_arg_info, 0)\n";
- foreach ($this->params as $param) {
- $code.= sprintf(" ZEND_ARG_INFO(%d, %s)\n",
isset($param["byRef"]), $param["name"]);
- }
- $code.= "ZEND_END_ARG_INFO()\n";
- $code.= "#endif\n\n";
+ } else {
+ $code .= "#define $argInfoName NULL\n";
}
-
+ $code.= "#endif\n\n";
+
return $code;
}
/**
+ * Name for ARG_INFO definition
+ *
+ * @return string
+ */
+ function argInfoName()
+ {
+ return $this->name."_arg_info";
+ }
+
+ /**
* Generate registration entry for extension function table
*
* @return string
http://cvs.php.net/viewvc.cgi/pear/CodeGen_PECL/PECL/Element/Method.php?r1=1.22&r2=1.23&diff_format=u
Index: pear/CodeGen_PECL/PECL/Element/Method.php
diff -u pear/CodeGen_PECL/PECL/Element/Method.php:1.22
pear/CodeGen_PECL/PECL/Element/Method.php:1.23
--- pear/CodeGen_PECL/PECL/Element/Method.php:1.22 Tue Oct 10 07:18:46 2006
+++ pear/CodeGen_PECL/PECL/Element/Method.php Tue Oct 17 11:08:04 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005, 2006 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Method.php,v 1.22 2006/10/10 07:18:46 hholzgra Exp $
+ * @version CVS: $Id: Method.php,v 1.23 2006/10/17 11:08:04 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -434,43 +434,25 @@
* Abstract/Interface methods need to define their argument
* list ahead of the method table
*
+ * @param array
* @returns string
*/
- function argInfoCode()
+ function argInfoCode($params)
{
- $code = "";
-
- if (count($this->params) > 0) {
- $code.= "ZEND_BEGIN_ARG_INFO(".$this->getFullName()."_args,
0)\n";
-
- $params = $this->params;
- array_shift($params);
-
- $useTypeHints = true;
-
- foreach ($params as $param) {
- if ($param['type'] != "object" ||
!isset($param['subtype'])) {
- $useTypeHints = false;
- break;
- }
- }
-
- // TODO optional paramteres?
- foreach ($params as $param) {
- $byRef = empty($param["byRef"]) ? 0 : 1;
- if ($useTypeHints) {
- $code.= " ZEND_ARG_OBJ_INFO(0, $param[name], $param[subtype], 0)\n";
- } else {
- $code.= " ZEND_ARG_INFO($byRef, $param[name])\n";
- }
- }
-
- $code.= "ZEND_END_ARG_INFO()\n";
- }
-
- return $code;
+ array_shift($params);
+ return parent::argInfoCode($params);
}
+ /**
+ * Name for ARG_INFO definition
+ *
+ * @return string
+ */
+ function argInfoName()
+ {
+ return $this->getFullName()."_args";
+ }
+
}
/*