Getting rid of externals deps

This commit is contained in:
Pavel Shevaev 2022-12-05 17:15:19 +03:00
parent e11e5872fa
commit 06346c8351
1 changed files with 55 additions and 5 deletions

View File

@ -54,8 +54,7 @@ function bhl_add_twig_support(\Twig\Environment $twig)
$twig->addFilter(new \Twig\TwigFilter('native_type',
function($type)
{
//TODO: mtgCSCodegen instance is not really needed
return bhl_gen_native_type(new \mtgCSCodegen(), $type);
return bhl_gen_native_type($type);
}
));
$twig->addFilter(new \Twig\TwigFilter('norm_name',
@ -227,7 +226,7 @@ function bhl_gen_type(\mtgType $type = null)
return ''.$type;
}
function bhl_gen_native_type(\mtgCSCodegen $gen, \mtgType $type)
function bhl_gen_native_type(\mtgType $type)
{
//any special case
if($type == "any")
@ -238,7 +237,7 @@ function bhl_gen_native_type(\mtgCSCodegen $gen, \mtgType $type)
if($type->getValue()->getName() == "any")
return "bhl.ValList";
else
return "HList<".bhl_gen_native_type($gen, $type->getValue()).">";
return "HList<".bhl_gen_native_type($type->getValue()).">";
}
//func special case
@ -256,11 +255,62 @@ function bhl_gen_native_type(\mtgCSCodegen $gen, \mtgType $type)
if($alias)
$type->setName($alias);
$ntype = $gen->genNativeType($type);
$ntype = cs_type($type);
//TODO: looks suspicious
if($alias)
$type->setName($orig_name);
return $ntype;
}
function cs_type(\mtgType $type)
{
if($type instanceof \mtgBuiltinType || $type instanceof \mtgUserType)
return cs_simple_type($type);
else if($type instanceof \mtgArrType)
return "List<" . cs_simple_type($type->getValue()) . ">";
else
throw new Exception("Unknown type '{$type}'");
}
function cs_simple_type(\mtgType $type)
{
if($type instanceof \mtgBuiltinType)
{
switch($type->getName())
{
case "int8":
return "sbyte";
case "uint8":
return "byte";
case "int16":
return "short";
case "uint16":
return "ushort";
case "int32":
case "int":
return "int";
case "uint32":
case "uint":
return "uint";
case "float":
return "float";
case "double":
return "double";
case "uint64":
return "ulong";
case "int64":
return "long";
case "string":
return "string";
case "bool":
return "bool";
case "blob":
return "byte[]";
}
throw new Exception("Unknown type '{$type}'");
}
return $type->getName();
}