You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
295 lines
7.4 KiB
295 lines
7.4 KiB
// pEpACIDLang - IG-C99
|
|
// TODO: Lic. etc...
|
|
|
|
include yslt.yml2
|
|
|
|
|
|
tstylesheet {
|
|
include standardlib.ysl2
|
|
include idl_api.ysl2
|
|
|
|
// ----------------------------------------------------------------------
|
|
// IG-C99
|
|
// ----------------------------------------------------------------------
|
|
|
|
// 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
|
|
||
|
|
}
|
|
|
|
|
|
// 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»
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|