From 9e12531651c14eba5dcddb6863a7cde834036a12 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Thu, 11 Jan 2024 21:00:51 -0800 Subject: [PATCH] [Yunq] Move method numbers to a scheme set by the parser. --- yunq/client.cpp.jinja | 2 +- yunq/parser.py | 3 +++ yunq/server.cpp.jinja | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/yunq/client.cpp.jinja b/yunq/client.cpp.jinja index 63721e0..e4e8102 100644 --- a/yunq/client.cpp.jinja +++ b/yunq/client.cpp.jinja @@ -31,7 +31,7 @@ glcr::Status {{interface.name}}Client::{{method.name}}(const {{method.request}}& const uint32_t kSentinel = 0xBEEFDEAD; buffer_.WriteAt(0, kSentinel); - buffer_.WriteAt(8, {{loop.index0}}); + buffer_.WriteAt(8, {{method.number}}); cap_buffer_.Reset(); {% if method.request == None %} diff --git a/yunq/parser.py b/yunq/parser.py index 5507880..403f27b 100644 --- a/yunq/parser.py +++ b/yunq/parser.py @@ -215,8 +215,11 @@ class Parser(): methods: list[Method] = [] method_names = set() + next_method_number = 0 while self.peektype() != LexemeType.RIGHT_BRACE: m = self.method() + m.number = next_method_number + next_method_number += 1 if m.name in method_names: sys.exit("Method %s declared twice on %s" % (m.name, name)) method_names.add(m.name) diff --git a/yunq/server.cpp.jinja b/yunq/server.cpp.jinja index 734166d..bee46b5 100644 --- a/yunq/server.cpp.jinja +++ b/yunq/server.cpp.jinja @@ -103,7 +103,7 @@ glcr::Status {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& switch(method_select) { {%- for method in interface.methods %} - case {{loop.index0}}: { + case {{method.number}}: { {% if method.request != None %} {{method.request}} yunq_request;