diff options
author | Kevin Chabowski <kevin@kch42.de> | 2014-05-22 14:09:33 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2014-05-22 14:09:33 +0200 |
commit | c4aad7a5216becdb09976f37bcaac1b720a1532d (patch) | |
tree | e262b93133114af1237a54ce6ba6b76c9be46146 | |
parent | d93c3d17b2b94b11f89b00c2bf27b3e246af966a (diff) | |
download | ste-c4aad7a5216becdb09976f37bcaac1b720a1532d.tar.gz ste-c4aad7a5216becdb09976f37bcaac1b720a1532d.tar.bz2 ste-c4aad7a5216becdb09976f37bcaac1b720a1532d.zip |
Added tempvar static function to Transcompiler
-rw-r--r-- | Transcompiler.php | 14 |
1 files changed, 9 insertions, 5 deletions
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 <ste:for>.", $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 <ste:block>.", $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); |