diff --git a/idl/idl_api.ysl2 b/idl/idl_api.ysl2 new file mode 100644 index 0000000..f452f1a --- /dev/null +++ b/idl/idl_api.ysl2 @@ -0,0 +1,121 @@ +// ---------------------------------------------------------------------- +// stdlib candidates +// ---------------------------------------------------------------------- +def "func:autocomma" { + result if "position()!=last()" > , +} + +def "func:exists" { + param "xpath"; + + choose { + when "$xpath" + result "true()"; + otherwise + result "false()"; + } +} + +// ---------------------------------------------------------------------- +// idl-api (ysl2) +// ---------------------------------------------------------------------- + +def "func:idl_typekind_is_defined" { + param "typekind"; + result "func:exists(/pEpACIDLang/idl/typekinds//*[name()=$typekind])" +} + +def "func:idl_typekind_is_generic" { + param "typekind"; + result "func:exists(/pEpACIDLang/idl/typekinds/generics/*[name()=$typekind])" +} + +def "func:idl_type_is_of_typekind_basetype" { + param "idltype"; + result "func:exists(/pEpACIDLang/idl/basetypes/*[name()=$idltype])"; +} + +def "func:idl_type_is_of_typekind_deftype" { + param "idltype"; + result "func:exists(//deftype[@name=$idltype])"; +} + +def "func:idl_type_is_of_typekind_enum" { + param "idltype"; + result "func:exists(//enum[@name=$idltype])"; +} + +def "func:idl_type_is_of_typekind_struct" { + param "idltype"; + result "func:exists(//struct[@name=$idltype])"; +} + +def "func:idl_type_is_of_typekind_list" { + param "idltype"; + result "false()"; +} + +def "func:idl_type_is_defined" { + param "idltype"; + choose { + when "func:idl_type_get_typekind_of_type($idltype)" + result "true()"; + otherwise + result "false()"; + } +} + +def "func:idl_type_get_typekind_of_type" { + param "idltype"; + choose { + when "func:idl_type_is_of_typekind_basetype($idltype)" + result > basetype + when "func:idl_type_is_of_typekind_deftype($idltype)" + result > deftype + when "func:idl_type_is_of_typekind_enum($idltype)" + result > enum + when "func:idl_type_is_of_typekind_struct($idltype)" + result > struct + when "func:idl_type_is_of_typekind_list($idltype)" + result > list + otherwise + result "false()"; + + } +} + +def "func:idl_type_get_resolved_typekind" { + param "idltype"; + const "idltypekind", "func:idl_type_get_typekind_of_type($idltype)"; + + choose { + when "$idltypekind = 'deftype'" + result "func:idl_type_get_typekind_of_type(func:idl_type_get_type_of_deftype($idltype))"; + otherwise + result "$idltypekind"; + } +} + +def "func:idl_type_get_resolved_type" { + param "idltype"; + const "idltypekind", "func:idl_type_get_typekind_of_type($idltype)"; + + choose { + when "$idltypekind = 'deftype'" + result "func:idl_type_get_type_of_deftype($idltype)"; + otherwise + result "$idltype"; + } +} + +def "func:idl_type_get_type_of_deftype" { + param "idltype"; + choose { + when "func:idl_type_is_of_typekind_deftype($idltype)" + result "//deftype[@name=$idltype]/as/@type"; + otherwise + error > idl_resolve_deftype - is not a deftype: «$idltype»; + } +} + + diff --git a/lm-c99/ig-c99.ysl2 b/lm-c99/ig-c99.ysl2 index d17e2ec..211341c 100644 --- a/lm-c99/ig-c99.ysl2 +++ b/lm-c99/ig-c99.ysl2 @@ -6,123 +6,14 @@ include yslt.yml2 tstylesheet { include standardlib.ysl2 + include idl_api.ysl2 - // stdlib candidates - // ----------------- - def "func:autocomma" { - result if "position()!=last()" > , - } - - def "func:exists" { - param "xpath"; - - choose { - when "$xpath" - result "true()"; - otherwise - result "false()"; - } - } - - // idl-api (ysl2) - // -------------- - def "func:idl_typekind_is_defined" { - param "typekind"; - result "func:exists(/pEpACIDLang/idl/typekinds//*[name()=$typekind])" - } - - def "func:idl_typekind_is_generic" { - param "typekind"; - result "func:exists(/pEpACIDLang/idl/typekinds/generics/*[name()=$typekind])" - } - - def "func:idl_type_is_of_typekind_basetype" { - param "idltype"; - result "func:exists(/pEpACIDLang/idl/basetypes/*[name()=$idltype])"; - } - - def "func:idl_type_is_of_typekind_deftype" { - param "idltype"; - result "func:exists(//deftype[@name=$idltype])"; - } - - def "func:idl_type_is_of_typekind_enum" { - param "idltype"; - result "func:exists(//enum[@name=$idltype])"; - } - - def "func:idl_type_is_of_typekind_struct" { - param "idltype"; - result "func:exists(//struct[@name=$idltype])"; - } - - def "func:idl_type_is_of_typekind_list" { - param "idltype"; - result "false()"; - } - - def "func:idl_type_is_defined" { - param "idltype"; - choose { - when "func:idl_type_get_typekind_of_type($idltype)" - result "true()"; - otherwise - result "false()"; - } - } - - def "func:idl_type_get_typekind_of_type" { - param "idltype"; - choose { - when "func:idl_type_is_of_typekind_basetype($idltype)" - result > basetype - when "func:idl_type_is_of_typekind_deftype($idltype)" - result > deftype - when "func:idl_type_is_of_typekind_enum($idltype)" - result > enum - when "func:idl_type_is_of_typekind_struct($idltype)" - result > struct - when "func:idl_type_is_of_typekind_list($idltype)" - result > list - otherwise - result "false()"; - } - } - - def "func:idl_type_get_resolved_typekind" { - param "idltype"; - const "idltypekind", "func:idl_type_get_typekind_of_type($idltype)"; - - choose { - when "$idltypekind = 'deftype'" - result "func:idl_type_get_typekind_of_type(func:idl_type_get_type_of_deftype($idltype))"; - otherwise - result "$idltypekind"; - } - } - def "func:idl_type_get_resolved_type" { - param "idltype"; - const "idltypekind", "func:idl_type_get_typekind_of_type($idltype)"; - - choose { - when "$idltypekind = 'deftype'" - result "func:idl_type_get_type_of_deftype($idltype)"; - otherwise - result "$idltype"; - } - } - def "func:idl_type_get_type_of_deftype" { - param "idltype"; - choose { - when "func:idl_type_is_of_typekind_deftype($idltype)" - result "//deftype[@name=$idltype]/as/@type"; - otherwise - error > idl_resolve_deftype - is not a deftype: «$idltype»; - } - } + // ---------------------------------------------------------------------- + // IG-C99 + // ---------------------------------------------------------------------- // typeclass is either // * primitive