From c4aad7a5216becdb09976f37bcaac1b720a1532d Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Thu, 22 May 2014 14:09:33 +0200 Subject: Added tempvar static function to Transcompiler --- Transcompiler.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'Transcompiler.php') diff --git a/Transcompiler.php b/Transcompiler.php index 1af5e88..26011f3 100644 --- a/Transcompiler.php +++ b/Transcompiler.php @@ -9,6 +9,10 @@ namespace kch42\ste; class Transcompiler { private static $builtins = NULL; + public static function tempvar($typ) { + return $typ . '_' . str_replace('.', '_', uniqid('', true)); + } + public static function init_builtins() { if(self::$builtins !== NULL) { return; @@ -126,7 +130,7 @@ class Transcompiler { }, "for" => function($ast) { $code = ""; - $loopname = "forloop_" . str_replace(".", "_", uniqid("",true)); + $loopname = self::tempvar("forloop"); if(empty($ast->params["start"])) { throw new ParseCompileError("self::Transcompile error: Missing 'start' parameter in .", $ast->tpl, $ast->offset); } @@ -182,7 +186,7 @@ class Transcompiler { return $code; }, "foreach" => function($ast) { - $loopname = "foreachloop_" . str_replace(".", "_", uniqid("",true)); + $loopname = self::tempvar("foreachloop"); $code = ""; if(empty($ast->params["array"])) { @@ -260,7 +264,7 @@ class Transcompiler { throw new ParseCompileError("self::Transcompile Error: name missing in .", $ast->tpl, $ast->offset); } - $blknamevar = "blockname_" . str_replace(".", "_", uniqid("", true)); + $blknamevar = self::tempvar("blockname"); list($val, $code) = self::_transcompile($ast->params["name"], true); $code .= "\$${blknamevar} = " . $val . ";\n"; @@ -382,7 +386,7 @@ class Transcompiler { $func = self::$builtins[$node->name]; $code .= $func($node); } else { - $paramarray = "parameters_" . str_replace(".", "_", uniqid("", true)); + $paramarray = self::tempvar("parameters"); $code .= "\$$paramarray = array();\n"; foreach($node->params as $pname => $pcontent) { @@ -406,7 +410,7 @@ class Transcompiler { } if($avoid_outputstack) { - $tmpvar = "tmp_" . str_replace(".", "_", uniqid("",true)); + $tmpvar = self::tempvar("tmp"); $code = "\$outputstack[] = '';\n\$outputstack_i++;" . $code; $code .= "\$$tmpvar = array_pop(\$outputstack);\n\$outputstack_i--;\n"; return array("\$$tmpvar", $code); -- cgit v1.2.3-70-g09d2