diff --git a/lm-c99/ig-c99.ysl2 b/lm-c99/ig-c99.ysl2 index e7e93d9..e0b0f39 100644 --- a/lm-c99/ig-c99.ysl2 +++ b/lm-c99/ig-c99.ysl2 @@ -8,6 +8,119 @@ tstylesheet { include standardlib.ysl2 include idl_api.ysl2 + + // ---------------------------------------------------------------------- + // pEpACIDLang LM-C99-API + // The C99 Language mapping API + // ---------------------------------------------------------------------- + + def "func:c99_typename_of_basetype" { + param "idltype"; + + choose { + when "func:idl_type_is_defined($idltype)" + 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:c99_typename_of_basetype - basetype not supported by ig-c99: «$idltype» + } + otherwise + error > func:c99_typename_of_basetype - idltype: «$idltype» is not defined + } + } + + def "func:c99_typename_of_enum" { + param "idl_enum_name"; + result "yml:ucase(concat(func:idl_get_package_name(), '_', $idl_enum_name))"; + } + + def "func:c99_typename_of_struct" { + param "idl_struct_name"; + result > «yml:capit(func:idl_get_package_name())»_«yml:capit($idl_struct_name)»; + } + + def "func:c99_typename_of_idltype" { + param "idltype"; + const "idl_typekind", "func:idl_type_get_typekind_of_type($idltype)"; + + choose { + when "func:idl_type_is_defined($idltype)" + choose { + when "$idl_typekind = 'basetype'" + result "func:c99_typename_of_basetype($idltype)"; + when "$idl_typekind = 'deftype'" + result "$idltype"; + when "$idl_typekind = 'enum'" + result "func:c99_typename_of_enum($idltype)"; + when "$idl_typekind = 'struct'" + result "func:c99_typename_of_struct($idltype)"; + when "$idl_typekind = 'generic'" + error > c99_typename_of_type - idltype «$idltype» is a generic type and can only be used in deftype declarations. + otherwise + error > c99_typename_of_type - cant determine c99 typename for idltype: «$idltype» + } + otherwise + error > c99_typename_of_idltype - is not an idltype: «$idltype» + } + } + + // typeclass is either + // * primitive + // * object + def "func:c99_typeclass_of_idltype" { + param "idltype"; + const "resolved_type", "func:idl_type_get_resolved_type($idltype)"; + const "resolved_typekind", "func:idl_type_get_typekind_of_type($resolved_type)"; + + choose { + when "func:idl_type_is_defined($idltype)" + choose { + when "$resolved_typekind = 'basetype'" + choose { + when "$resolved_type = 'string'" + result > object + when "$resolved_type = 'binary'" + result > object + otherwise + result > primitive + } + when "$resolved_typekind = 'enum'" + result > primitive + when "$resolved_typekind = 'struct'" + result > object + when "$resolved_typekind = 'generic'" + result > object + otherwise + error > c99_typeclass_of_idltype - cant determine typeclass of: «$idltype» + } + otherwise + error > c99_typeclass_of_idltype - is not an idltype: «$idltype» + } + }; + + + def "func:c99_itemname_of_enumitem" { + param "idl_enum_name"; + param "idl_item_name"; + result "yml:ucase(concat($idl_enum_name, '_', $idl_item_name))"; + } + + + + // ---------------------------------------------------------------------- // pEpACIDLang IG-C99 // The C99 Interface Generator for pEpACIDLang @@ -37,46 +150,31 @@ tstylesheet { template "basetypes" { for "*" { const "name", "name()"; - if "func:c99_typename_of_basetype($name) != $name" { - > «func:typedef(func:c99_typename_of_basetype($name), $name)» - } - } + if "func:c99_typename_of_idltype($name) != $name" { + | «func:typedef(func:c99_typename_of_idltype($name), $name)» + } + } } 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» + // «yml:ucase(func:idl_get_package_name())» version «func:idl_get_package_version()» // «$api_name»_api.h - // «$pkg_license» - // «$pkg_copyleft» + // «func:idl_get_package_license()» #pragma once - #ifdef __cplusplus extern "C" { #endif #include "idl_core.h" - // deftypes - // -------- - ``apply "deftype", 0 - + ``call "deftypes" ``call "enums" - - // Structs - // ------- - ``apply "struct", 0 - - // Functions - // --------- - ``apply "method", 0 + ``call "structs" + ``call "methods" #ifdef __cplusplus } // extern "C" @@ -86,110 +184,46 @@ tstylesheet { - def "func:c99_typename_of_basetype" { - param "idltype"; + // DEFTYPE + // ------- - // 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:c99_typename_of_basetype - basetype not supported by ig-c99: «$idltype» - } - } - - def "func:c99_typename_of_enum" { - param "name"; - param "pkg_name"; + function "deftypes" { + || + // Deftypes + // -------- - result "yml:ucase(concat($pkg_name, '_', $name))"; - } + ``apply "deftype" - def "func:c99_itemname_of_enumitem" { - param "enum_name"; - param "idl_item_name"; - - result "yml:ucase(concat($enum_name, '_', $idl_item_name))"; + || } - - def "func:c99_typename_of_struct" { - param "pkg_name"; - param "idl_name"; - result "concat(yml:capit($pkg_name), '_', yml:capit($idl_name))"; + template "deftype" { + call "deftype" + with "new_typename", "@name", + with "aliased_type_or_typekind", "as/@type"; } - // typeclass is either - // * primitive - // * object - def "func:c99_typeclass_of_type" { - param "idltype"; - const "resolved_type", "func:idl_type_get_resolved_type($idltype)"; - const "resolved_typekind", "func:idl_type_get_typekind_of_type($resolved_type)"; - - choose { - when "func:idl_type_is_defined($idltype)" - choose { - when "$resolved_typekind = 'basetype'" - choose { - when "$resolved_type = 'string'" - result > object - when "$resolved_type = 'binary'" - result > object - otherwise - result > primitive - } - when "$resolved_typekind = 'enum'" - result > primitive - when "$resolved_typekind = 'struct'" - result > object - when "$resolved_typekind = 'generic'" - result > object - otherwise - error > c99_typeclass_of_type - cant determine typeclass of: «$idltype» - } - otherwise - error > c99_typeclass_of_type - is not a type: «$idltype» - } - }; - - - // TYPEALIAS - // --------- - - template "deftype" { - const "alias_name", "@name"; - const "type_or_typekind", "as/@type"; + function "deftype" { + param "new_typename"; + param "aliased_type_or_typekind"; choose { - when 'func:idl_typekind_is_generic($type_or_typekind)' + when 'func:idl_typekind_is_generic($aliased_type_or_typekind)' choose { - when "$type_or_typekind = 'list'" - > «func:typedef($type_or_typekind, $alias_name)» + when "$aliased_type_or_typekind = 'list'" + | «func:typedef($aliased_type_or_typekind, $new_typename)» otherwise error > deftype - typekind must be generic «$type_or_typeind» } otherwise - > «func:typedef($type_or_typekind, $alias_name)» + | «func:typedef($aliased_type_or_typekind, $new_typename)» } } def "func:typedef" { param "is_type"; - param "alias_name"; - result > typedef «$is_type» «$alias_name»;\n + param "new_typename"; + result > typedef «$is_type» «$new_typename»; } @@ -203,19 +237,17 @@ tstylesheet { // ----- ``apply "enum" + || } template "enum" { - call "enum" - with "idl_enum_name", "@name", - with "idl_pkg_name", "../../@name"; + call "enum" with "idl_enum_name", "@name"; } function "enum" { param "idl_enum_name"; - param "idl_pkg_name"; - const "enum_name", "func:c99_typename_of_enum($idl_enum_name, $idl_pkg_name)"; + const "enum_name", "func:c99_typename_of_idltype($idl_enum_name)"; || typedef enum _«$enum_name» { ``apply "item" with "enum_name", "$enum_name" @@ -229,13 +261,13 @@ tstylesheet { const "idl_item_name", "@name"; const "c99_item_name", "func:c99_itemname_of_enumitem($enum_name, $idl_item_name)"; const "idl_value", "text()"; - const "c99_value", "func:enum_item_value($idl_value)"; + const "c99_value", "func:c99_enum_item_value($idl_value)"; apply "@doc", 0, mode="multiline"; | «$c99_item_name»«$c99_value»«func:autocomma()»`apply "@doc" , 0, mode="oneline"` } - def "func:enum_item_value" { + def "func:c99_enum_item_value" { param "idl_value"; choose { when "string-length($idl_value) > 0" @@ -243,7 +275,6 @@ tstylesheet { otherwise result > } - } // STRUCT @@ -255,17 +286,22 @@ tstylesheet { // ------- ``apply "struct" + || } template "struct" { - const "idl_name", "@name"; - const "pkg_name", "../../@name"; - const "c_name", "func:c99_typename_of_struct($pkg_name, $idl_name)"; + call "struct" with "idl_struct_name", "@name"; + } + + function "struct" { + param "idl_struct_name"; + const "c99_struct_name", "func:c99_typename_of_idltype($idl_struct_name)"; || - typedef struct _«$c_name» { + typedef struct _«$c99_struct_name» { ``apply "field" - } «$c_name»; + } «$c99_struct_name»; + || } @@ -282,10 +318,25 @@ tstylesheet { // METHOD // ------ + function "methods" { + || + // Functions + // --------- + + ``apply "method" + + || + } + template "method" { - const "name", "@name"; + call "method" + with "idl_method_name", "@name"; + } + + function "method" { + param "idl_method_name"; || - PEP_STATUS «$name»( + PEP_STATUS «$idl_method_name»( ``apply "param", 0 ); @@ -302,7 +353,7 @@ tstylesheet { def "func:idlparam_to_cparam" { param "idltype"; param "mode"; - const "typeclass", "func:c99_typeclass_of_type($idltype)"; + const "typeclass", "func:c99_typeclass_of_idltype($idltype)"; choose { when "$mode = 'borrow'"