From cc0a06aed6ba869f931f4913bf423eb5afaaa537 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 22 Feb 2023 10:42:09 +1000 Subject: [PATCH] scanner: rename to as_c_arg and c_type for the c-specific functions --- proto/ei-scanner | 26 +++++++++++++------------- src/ei-proto.c.tmpl | 14 +++++++------- src/ei-proto.h.tmpl | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/proto/ei-scanner b/proto/ei-scanner index d75866f..872e548 100755 --- a/proto/ei-scanner +++ b/proto/ei-scanner @@ -77,11 +77,11 @@ class Argument: raise ValueError("Interface may only be set for object types") @property - def as_arg(self) -> str: - return f"{self.ctype} {self.name}" + def as_c_arg(self) -> str: + return f"{self.c_type} {self.name}" @property - def ctype(self) -> str: + def c_type(self) -> str: return { "uint": "uint32_t", "int": "int32_t", @@ -334,12 +334,12 @@ class Interface: ) @property - def ctype(self) -> str: + def c_type(self) -> str: return f"struct {self.name} *" @property - def as_arg(self) -> str: - return f"{self.ctype} {self.name}" + def as_c_arg(self) -> str: + return f"{self.c_type} {self.name}" @property def camel_name(self) -> str: @@ -654,15 +654,15 @@ def generate_source( ) # jinja filter to convert foo into "struct foo *" - def filter_ctype(name): + def filter_c_type(name): return f"struct {name} *" # jinja filter to convert foo into "struct foo *foo" - def filter_as_arg(name): - return f"struct {name} * {name}" + def filter_as_c_arg(name): + return f"struct {name} *{name}" - env.filters["ctype"] = filter_ctype - env.filters["as_arg"] = filter_as_arg + env.filters["c_type"] = filter_c_type + env.filters["as_c_arg"] = filter_as_c_arg env.filters["camel"] = snake2camel jtemplate = env.get_template(template.name) return jtemplate.stream(data) @@ -697,8 +697,8 @@ def main() -> None: string -> "s" ei-scanner adds the following Jinja2 filters for convenience: - {{foo|ctype}} ... resolves to "struct foo *" - {{foo|as_arg}} ... resolves to "struct foo *foo" + {{foo|c_type}} ... resolves to "struct foo *" + {{foo|as_c_arg}} ... resolves to "struct foo *foo" {{foo_bar|camel}} ... resolves to "FooBar" """), diff --git a/src/ei-proto.c.tmpl b/src/ei-proto.c.tmpl index 3896be6..a25d507 100644 --- a/src/ei-proto.c.tmpl +++ b/src/ei-proto.c.tmpl @@ -47,7 +47,7 @@ struct {{target.name}}; * message sending functions (requests for libei, events for libeis). */ extern int {{target.name}}_send_message( - {{target.name|as_arg}}, const struct brei_object *obj, uint32_t opcode, + {{target.name|as_c_arg}}, const struct brei_object *obj, uint32_t opcode, const char *signature, size_t nargs, ... ); @@ -57,14 +57,14 @@ extern int {{target.name}}_send_message( ***************************************************************************/ /* returns the protocol interface from the given struct, see the dispatcher */ -const struct {{interface.name}}_interface *{{interface.name}}_get_interface({{interface.as_arg}}); +const struct {{interface.name}}_interface *{{interface.name}}_get_interface({{interface.as_c_arg}}); /* returns the message sending context from the given struct */ -{{target.name|ctype}} {{interface.name}}_get_{{target.context}}({{interface.as_arg}}); +{{target.name|c_type}} {{interface.name}}_get_{{target.context}}({{interface.as_c_arg}}); /* Returns the protocol object id from the given struct */ const struct brei_object * -{{interface.name}}_get_proto_object({{interface.as_arg}}); +{{interface.name}}_get_proto_object({{interface.as_c_arg}}); /* request opcodes */ {% for request in interface.requests %} @@ -79,13 +79,13 @@ const struct brei_object * /* Message sender functions */ {% for outgoing in interface.outgoing %} int -{{outgoing.fqdn}}({{interface.as_arg}}{%- for arg in outgoing.arguments %}, {{arg.as_arg}}{% endfor %}) +{{outgoing.fqdn}}({{interface.as_c_arg}}{%- for arg in outgoing.arguments %}, {{arg.as_c_arg}}{% endfor %}) { if (!{{interface.name}}) return -ENOENT; const struct brei_object *obj = {{interface.name}}_get_proto_object({{interface.name}}); - {{target.name|ctype}} ctx = {{interface.name}}_get_{{target.context}}({{interface.name}}); + {{target.name|c_type}} ctx = {{interface.name}}_get_{{target.context}}({{interface.name}}); if (obj->version < {{outgoing.fqdn.upper()}}_SINCE_VERSION) return -ENOTSUP; @@ -104,7 +104,7 @@ int */ static struct brei_result * {{interface.name}}_dispatcher( - {{interface.as_arg}}, + {{interface.as_c_arg}}, uint32_t opcode, size_t nargs, union brei_arg *args diff --git a/src/ei-proto.h.tmpl b/src/ei-proto.h.tmpl index 56dc2e0..eb55caa 100644 --- a/src/ei-proto.h.tmpl +++ b/src/ei-proto.h.tmpl @@ -78,7 +78,7 @@ enum {{enum.fqdn}} { /* Message sender functions */ {% for outgoing in interface.outgoing %} extern int -{{outgoing.fqdn}}({{interface.as_arg}}{%- for arg in outgoing.arguments %}, {{arg.as_arg}}{% endfor %}); +{{outgoing.fqdn}}({{interface.as_c_arg}}{%- for arg in outgoing.arguments %}, {{arg.as_c_arg}}{% endfor %}); {% endfor %} @@ -89,7 +89,7 @@ extern int */ struct {{interface.name}}_interface { {% for incoming in interface.incoming %} - struct brei_result * (*{{incoming.name}})({{interface.as_arg}}{%- for arg in incoming.arguments %}, {{arg.as_arg}}{% endfor %}); + struct brei_result * (*{{incoming.name}})({{interface.as_c_arg}}{%- for arg in incoming.arguments %}, {{arg.as_c_arg}}{% endfor %}); {% endfor %} }; {% endfor %}