// pEpACIDLang - IG-C99 // TODO: Lic. etc... include yslt.yml2 tstylesheet { include standardlib.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»; } } // typeclass is either // * primitive // * object def "func:ig_c99_typeclass" { param "idltype"; choose { when "func:idl_type_is_defined($idltype)" choose { when "func:idl_type_is_of_typekind_basetype($idltype)" result > primitive when "func:idl_type_is_of_typekind_deftype($idltype)" result > primitive when "func:idl_type_is_of_typekind_enum($idltype)" result > primitive when "func:idl_type_is_of_typekind_struct($idltype)" result > primitive } otherwise error > ig_c99_typeclass - is not a type: «$idltype» } }; template "idl" document "ig-c99/idl_core.h", "text" { || #pragma once #ifdef __cplusplus extern "C" { #endif // idl basetypes // ------------- ``apply "basetypes", 0 #ifdef __cplusplus } // extern "C" #endif || } template "api" document "ig-c99/{@name}_api.h", "text" { const "pkg_name", "../@name"; const "pkg_version", "../version/text()"; const "pkg_license", "../license/text()"; const "pkg_copyleft", "../copyleft/text()"; const "api_name", "@name"; || // «yml:ucase($pkg_name)» «$pkg_version» // «$api_name»_api.h // «$pkg_license» // «$pkg_copyleft» #pragma once #ifdef __cplusplus extern "C" { #endif #include "idl_core.h" // deftypes // -------- ``apply "deftype", 0 // Enums // ----- ``apply "enum", 0 // Structs // ------- ``apply "struct", 0 // Functions // --------- ``apply "method", 0 #ifdef __cplusplus } // extern "C" #endif || } // TYPE-TESTING template "test-types" document "ig-c99/test_types.h", "text" { || // basetypes «func:typeinfo('string')» «func:typeinfo('binary')» «func:typeinfo('int')» «func:typeinfo('uint')» «func:typeinfo('size')» «func:typeinfo('bool')» «func:typeinfo('opaque')» // deftype basetype «func:typeinfo('deftype1')» «func:typeinfo('deftype2')» // deftype generic «func:typeinfo('stringlist')» // enum «func:typeinfo('enum1')» // struct «func:typeinfo('struct1')» // undefined «func:typeinfo('undefined')» || } def "func:typeinfo" { param "idltype"; result call "typeinfo" with "idltype", "$idltype"; }; function "typeinfo" { param "idltype"; || idltype: «$idltype» idl_type_is_defined: «func:idl_type_is_defined($idltype)» idl_type_get_typekind_of_type: «func:idl_type_get_typekind_of_type($idltype)» idl_type_get_resolved_typekind: «func:idl_type_get_resolved_typekind($idltype)» idl_type_get_resolved_type: «func:idl_type_get_resolved_type($idltype)» idl_type_is_of_typekind_basetype: «func:idl_type_is_of_typekind_basetype($idltype)» idl_type_is_of_typekind_deftype: «func:idl_type_is_of_typekind_deftype($idltype)» idl_type_is_of_typekind_enum: «func:idl_type_is_of_typekind_enum($idltype)» idl_type_is_of_typekind_struct: «func:idl_type_is_of_typekind_struct($idltype)» || } // TYPEALIAS // --------- def "func:typedef" { param "is_type"; param "alias_name"; result > typedef «$is_type» «$alias_name»;\n } def "func:idltype_to_ctype_basetype" { param "idltype"; // TODO: test for is_basetype choose { when "$idltype = 'string'" result > char* when "$idltype = 'binary'" result > char* when "$idltype = 'uint'" result > unsigned int when "$idltype = 'size'" result > size_t when "$idltype = 'opaque'" result > void* when "$idltype = 'int'" result > int when "$idltype = 'bool'" result > bool otherwise error > func:idltype_to_ctype_basetype - basetype not supported by ig-c99: «$idltype» } } template "deftype" { const "alias_name", "@name"; const "type_or_typekind", "as/@type"; choose { when 'func:idl_typekind_is_generic($type_or_typekind)' choose { when "$type_or_typekind = 'list'" > «func:typedef($type_or_typekind, $alias_name)» otherwise error > deftype - typekind must be generic «$type_or_typeind» } otherwise choose { when 'func:idl_type_is_of_typekind_basetype($type_or_typekind)' > «func:typedef($type_or_typekind, $alias_name)» otherwise error > not a generic or basetype: «$type_or_typekind» } } } template "basetypes" { for "*" { const "name", "name()"; if "func:idltype_to_ctype_basetype($name) != $name" { > «func:typedef(func:idltype_to_ctype_basetype($name), $name)» } } } // ENUM // ---- def "func:idltype_to_ctype_enum" { param "pkg_name"; param "name"; result "yml:ucase(concat($pkg_name, '_', $name))"; } template "enum" { const "idl_name", "@name"; const "pkg_name", "../../@name"; const "enum_name", "func:idltype_to_ctype_enum($pkg_name, $idl_name)"; || typedef enum _«$enum_name» { ``apply "item" with "enum_name", "$enum_name" } «$enum_name»; || } template "item" { param "enum_name"; const "item_name_idl", "@name"; const "item_name", "yml:ucase(concat($enum_name, '_', $item_name_idl))"; apply "@doc", 0, mode="multiline"; choose { when "@output='hex'" | «$item_name»`if "text()" { " = 0x" value "yml:dec2hex(., 2)" }`«func:autocomma()»`apply "@doc" , 0, mode="oneline"` otherwise | «$item_name»`if "text()" { " = " value "." }``apply "@doc" , 0, mode="oneline"` } } // STRUCT // ------ def "func:idltype_to_ctype_struct" { param "pkg_name"; param "idl_name"; result "concat(yml:capit($pkg_name), '_', yml:capit($idl_name))"; } template "struct" { const "idl_name", "@name"; const "pkg_name", "../../@name"; const "c_name", "func:idltype_to_ctype_struct($pkg_name, $idl_name)"; || typedef struct _«$c_name» { ``apply "field" } «$c_name»; || } template "field" { const "field_name", "@name"; const "field_type", "@type"; || ``apply "@doc", 0, mode="multiline" «$field_type» «$field_name»;`apply "@doc" , 0, mode="oneline"` || } // METHOD // ------ template "method" { const "name", "@name"; || PEP_STATUS «$name»( ``apply "param", 0 ); || } template "param" { const "name", "@name"; const "type", "@type"; const "mode", "@mode"; |> «func:idlparam_to_cparam($type, $mode)» «@name»«func:autocomma()» } def "func:idlparam_to_cparam" { param "idltype"; param "mode"; result "'sfd'"; } // DOC // --- template "doc|@doc", mode="oneline" { const "docstring", "."; const "doc_lines_count", "count(str:split($docstring, '\n'))"; if "$doc_lines_count = 1" { const "doc_line", "normalize-space($docstring)"; if "string-length($doc_line) > 0" { > // «$doc_line» } } } template "doc|@doc", mode="multiline" { const "docstring", "."; const "doc_lines_count", "count(str:split($docstring, '\n'))"; if "$doc_lines_count > 1" { if "string-length($docstring) > 0" { | for "str:split($docstring, '\n')" { const "doc_line", "normalize-space(.)"; if "string-length($doc_line) > 0" { | // «$doc_line» } } } } } }