- move some code from parser into compiler

This commit is contained in:
uwetews
2016-02-09 01:15:12 +01:00
parent c1f34b1314
commit c59ca44b9f
5 changed files with 1093 additions and 1336 deletions

View File

@@ -1,4 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)  ===== 3.1.30-dev ===== (xx.xx.xx)
09.02.2016
- move some code from parser into compiler
05.02.2016 05.02.2016
- improvement internal compiler changes - improvement internal compiler changes

View File

@@ -39,13 +39,6 @@ class Smarty_Internal_Templateparser
*/ */
public $retvalue = 0; public $retvalue = 0;
/**
* counter for prefix code
*
* @var int
*/
public static $prefix_number = 0;
/** /**
* @var * @var
*/ */
@@ -811,21 +804,21 @@ value(res) ::= doublequoted_with_quotes(s). {
value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). { value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
self::$prefix_number++; $prefixVar = $this->compiler->getNewPrefixVariable();
if (vi['var'] == '\'smarty\'') { if (vi['var'] == '\'smarty\'') {
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.' = '. $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>'; $this->compiler->appendPrefixCode("<?php $prefixVar" .' = '. $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>');
} else { } else {
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.' = '. $this->compiler->compileVariable(vi['var']).vi['smarty_internal_index'].';?>'; $this->compiler->appendPrefixCode("<?php $prefixVar" .' = '. $this->compiler->compileVariable(vi['var']).vi['smarty_internal_index'].';?>');
} }
res = '$_tmp'.self::$prefix_number.'::'.r[0].r[1]; res = $prefixVar .'::'.r[0].r[1];
} }
// Smarty tag // Smarty tag
value(res) ::= smartytag(st). { value(res) ::= smartytag(st). {
self::$prefix_number++; $prefixVar = $this->compiler->getNewPrefixVariable();
$tmp = $this->compiler->appendCode('<?php ob_start();?>', st); $tmp = $this->compiler->appendCode('<?php ob_start();?>', st);
$this->compiler->prefix_code[] = $this->compiler->appendCode($tmp, '<?php $_tmp'.self::$prefix_number.'=ob_get_clean();?>'); $this->compiler->appendPrefixCode($this->compiler->appendCode($tmp, "<?php $prefixVar" .'=ob_get_clean();?>'));
res = '$_tmp'.self::$prefix_number; res = $prefixVar;
} }
value(res) ::= value(v) modifierlist(l). { value(res) ::= value(v) modifierlist(l). {
@@ -1099,9 +1092,9 @@ function(res) ::= ns1(f) OPENP params(p) CLOSEP. {
} }
$par = implode(',',p); $par = implode(',',p);
if (strncasecmp($par,'$_smarty_tpl->smarty->ext->_config->_getConfigVariable',strlen('$_smarty_tpl->smarty->ext->_config->_getConfigVariable')) === 0) { if (strncasecmp($par,'$_smarty_tpl->smarty->ext->_config->_getConfigVariable',strlen('$_smarty_tpl->smarty->ext->_config->_getConfigVariable')) === 0) {
self::$prefix_number++; $prefixVar = $this->compiler->getNewPrefixVariable();
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.'='.str_replace(')',', false)',$par).';?>'; $this->compiler->appendPrefixCode("<?php $prefixVar" .'='.str_replace(')',', false)',$par).';?>');
$isset_par = '$_tmp'.self::$prefix_number; $isset_par = $prefixVar;
} else { } else {
$isset_par=str_replace("')->value","',null,true,false)->value",$par); $isset_par=str_replace("')->value","',null,true,false)->value",$par);
} }
@@ -1139,9 +1132,9 @@ method(res) ::= DOLLARID(f) OPENP params(p) CLOSEP. {
if ($this->security) { if ($this->security) {
$this->compiler->trigger_template_error (self::Err2); $this->compiler->trigger_template_error (self::Err2);
} }
self::$prefix_number++; $prefixVar = $this->compiler->getNewPrefixVariable();
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.'='.$this->compiler->compileVariable('\''.substr(f,1).'\'').';?>'; $this->compiler->appendPrefixCode("<?php $prefixVar" .'='.$this->compiler->compileVariable('\''.substr(f,1).'\'').';?>');
res = '$_tmp'.self::$prefix_number.'('. implode(',',p) .')'; res = $prefixVar .'('. implode(',',p) .')';
} }
// function/method parameter // function/method parameter

View File

@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.30-dev/29'; const SMARTY_VERSION = '3.1.30-dev/30';
/** /**
* define variable scopes * define variable scopes

View File

@@ -289,6 +289,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
public $_cache = array(); public $_cache = array();
/**
* counter for prefix variable number
*
* @var int
*/
public static $prefixVariableNumber = 0;
/** /**
* method to compile a Smarty template * method to compile a Smarty template
* *
@@ -1250,4 +1257,34 @@ abstract class Smarty_Internal_TemplateCompilerBase
return false; return false;
} }
/**
* Get new prefix variable name
*
* @return string
*/
public function getNewPrefixVariable()
{
self::$prefixVariableNumber ++;
return $this->getPrefixVariable();
}
/**
* Get current prefix variable name
*
* @return string
*/
public function getPrefixVariable()
{
return '$_prefixVariable' . self::$prefixVariableNumber;
}
/**
* append code to prefix buffer
*
* @param string $code
*/
public function appendPrefixCode($code)
{
$this->prefix_code[] = $code;
}
} }

File diff suppressed because it is too large Load Diff