Adding @flt_bhl_ref filter
This commit is contained in:
parent
06e42eb56f
commit
9e3680ff0a
|
@ -0,0 +1 @@
|
|||
tags
|
48
bhl.inc.php
48
bhl.inc.php
|
@ -304,3 +304,51 @@ function bhl_line_row_to_pos($file, $line, $row)
|
|||
$pos += $row;
|
||||
return $pos;
|
||||
}
|
||||
|
||||
function bhl_map_module_to_file($module)
|
||||
{
|
||||
foreach(bhl_proj()->src_dirs as $dir)
|
||||
{
|
||||
$tmp = $dir.'/'.$module.'.bhl';
|
||||
if(file_exists($tmp))
|
||||
return $tmp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function bhl_validate_func_ref($module, $func, array $signature)
|
||||
{
|
||||
if(sizeof($signature) == 0)
|
||||
throw new Exception("Signature is invalid");
|
||||
|
||||
$module_file = bhl_map_module_to_file($module);
|
||||
|
||||
if(!$module_file)
|
||||
throw new Exception("Module not found '{$module}'");
|
||||
|
||||
$module_src = file_get_contents($module_file);
|
||||
|
||||
$signature_pattern = '';
|
||||
$signature_pattern .= '~func\s+';
|
||||
if($signature[0] !== 'void')
|
||||
{
|
||||
$signature_pattern .= preg_quote($signature[0]);
|
||||
$signature_pattern .= '\s+';
|
||||
}
|
||||
$signature_pattern .= $func;
|
||||
$signature_pattern .= '\s*\(';
|
||||
array_shift($signature);
|
||||
foreach($signature as $type)
|
||||
{
|
||||
$signature_pattern .= '\s*';
|
||||
$signature_pattern .= preg_quote($type);
|
||||
$signature_pattern .= '\s*\S+';
|
||||
$signature_pattern .= '\s*,';
|
||||
}
|
||||
$signature_pattern = rtrim($signature_pattern, '\s*,');
|
||||
$signature_pattern .= '\s*\)';
|
||||
$signature_pattern .= '~';
|
||||
|
||||
if(!preg_match($signature_pattern, $module_src))
|
||||
throw new Exception("Func '$func' signature '".implode(',', $signature)."' not found in module '$module'");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
namespace metagen_php;
|
||||
use Exception;
|
||||
|
||||
function flt_bhl_ref($val, $name, $struct, $args)
|
||||
{
|
||||
if(!$val)
|
||||
return $val;
|
||||
|
||||
if(!isset($val['module']))
|
||||
throw new Exception("Missing 'module'");
|
||||
|
||||
if(!isset($val['fn']))
|
||||
throw new Exception("Missing 'fn'");
|
||||
|
||||
$signature = explode(",", $args);
|
||||
if(!$signature)
|
||||
throw new Exception("Invalid signature: $args");
|
||||
|
||||
\taskman\bhl_validate_func_ref($val['module'], $val['fn'], $signature);
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
Loading…
Reference in New Issue