diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e92f57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tags diff --git a/bhl.inc.php b/bhl.inc.php index 9cc138e..d5b5b5e 100644 --- a/bhl.inc.php +++ b/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'"); +} diff --git a/bhl_flt.inc.php b/bhl_flt.inc.php new file mode 100644 index 0000000..c43f8fd --- /dev/null +++ b/bhl_flt.inc.php @@ -0,0 +1,24 @@ +