Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions codegen/xbot_codegen/xbot_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def loadService(path: str) -> dict:
"base_type": enum["base_type"],
"values": enum["values"],
"bitmask": enum.get("bitmask", False),
"to_string": enum.get("to_string", False),
})

# Transform the input definitions
Expand Down Expand Up @@ -240,3 +241,18 @@ def generateEnums(service):
for id, value in enum["values"].items():
cog.outl(f" {id} = {value},")
cog.outl("};\n")

if enum["to_string"]:
cog.outl(f"inline constexpr size_t {enum['id']}_count = {max(enum['values'].values()) + 1};")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
cog.outl(f"inline const char* {enum['id']}_to_string({enum['id']} v) {{")
cog.outl(" switch (v) {")
seen = set()
for name, value in enum["values"].items():
if value in seen:
continue
seen.add(value)
cog.outl(f" case {enum['id']}::{name}: return \"{name.lower()}\";")
cog.outl(" default: return \"\";")
cog.outl(" }")
cog.outl("}")

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Loading