[Yunq] Cleanup codegen bugs.

This commit is contained in:
Drew Galbraith 2023-10-24 12:40:15 -07:00
parent d45f831b46
commit 3faa19e4cb
5 changed files with 29 additions and 23 deletions

View File

@ -5,6 +5,8 @@ HEADER_PRELUDE = """
// Generated file - DO NOT MODIFY // Generated file - DO NOT MODIFY
#pragma once #pragma once
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <glacier/string/string.h> #include <glacier/string/string.h>
#include <ztypes.h> #include <ztypes.h>
@ -90,7 +92,7 @@ const uint64_t header_size = 24; // 4x uint32, 1x uint64
struct ExtPointer {{ struct ExtPointer {{
uint32_t offset; uint32_t offset;
uint32_t length; uint32_t length;
}} }};
void CheckHeader(const glcr::ByteBuffer& bytes) {{ void CheckHeader(const glcr::ByteBuffer& bytes) {{
// TODO: Check ident. // TODO: Check ident.
@ -113,12 +115,12 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint32_t core_size, uint32_t extension
IMPL_PARSE_DEF = """ IMPL_PARSE_DEF = """
void {name}::ParseFromBytes(const glcr::ByteBuffer& bytes) {{ void {name}::ParseFromBytes(const glcr::ByteBuffer& bytes) {{
CheckHeader(); CheckHeader(bytes);
""" """
IMPL_PARSE_DEF_CAP = """ IMPL_PARSE_DEF_CAP = """
void {name}::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) {{ void {name}::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) {{
CheckHeader(); CheckHeader(bytes);
""" """
IMPL_PARSE_U64 = """ IMPL_PARSE_U64 = """
@ -142,7 +144,7 @@ IMPL_SET_CAP_EMPTY = """
IMPL_PARSE_CAP = """ IMPL_PARSE_CAP = """
uint64_t {name}_ptr = bytes.At<uint64_t>(header_size + (8 * {offset})); uint64_t {name}_ptr = bytes.At<uint64_t>(header_size + (8 * {offset}));
set_{name}(caps.at({name}_ptr)); set_{name}(caps.At({name}_ptr));
""" """
IMPL_PARSE_DEF_END = """ IMPL_PARSE_DEF_END = """
@ -174,14 +176,14 @@ def _generate_message_parse_impl(message: Message) -> str:
return impl return impl
IMPL_SER_DEF = """ IMPL_SER_DEF = """
{name}::SerializeToBytes(glcr::ByteBuffer& bytes) {{ void {name}::SerializeToBytes(glcr::ByteBuffer& bytes) {{
uint32_t next_extension = header_size + 8 * {num_fields}; uint32_t next_extension = header_size + 8 * {num_fields};
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
""" """
IMPL_SER_CAP_DEF = """ IMPL_SER_CAP_DEF = """
{name}::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {{ void {name}::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {{
uint32_t next_extension = header_size + 8 * {num_fields}; uint32_t next_extension = header_size + 8 * {num_fields};
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
@ -200,7 +202,7 @@ IMPL_SER_STRING = """
ExtPointer {name}_ptr{{ ExtPointer {name}_ptr{{
.offset = next_extension, .offset = next_extension,
// FIXME: Check downcast of str length. // FIXME: Check downcast of str length.
.length = {name}().length(), .length = (uint32_t){name}().length(),
}}; }};
bytes.WriteStringAt(next_extension, {name}()); bytes.WriteStringAt(next_extension, {name}());
@ -214,7 +216,7 @@ IMPL_SER_CAP_EMPTY = """
""" """
IMPL_SER_CAP = """ IMPL_SER_CAP = """
caps.Write(next_cap, {name}()); caps.WriteAt(next_cap, {name}());
bytes.WriteAt<uint64_t>(header_size + (8 * {offset}), next_cap++); bytes.WriteAt<uint64_t>(header_size + (8 * {offset}), next_cap++);
""" """

View File

@ -8,7 +8,7 @@ const uint64_t header_size = 24; // 4x uint32, 1x uint64
struct ExtPointer { struct ExtPointer {
uint32_t offset; uint32_t offset;
uint32_t length; uint32_t length;
} };
void CheckHeader(const glcr::ByteBuffer& bytes) { void CheckHeader(const glcr::ByteBuffer& bytes) {
// TODO: Check ident. // TODO: Check ident.
@ -29,7 +29,7 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint32_t core_size, uint32_t extension
} // namespace } // namespace
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes) { void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes) {
CheckHeader(); CheckHeader(bytes);
auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0)); auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0));
@ -40,7 +40,7 @@ void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes) {
} }
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) { void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) {
CheckHeader(); CheckHeader(bytes);
auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0)); auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0));
@ -50,7 +50,7 @@ void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::
} }
OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) { void OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) {
uint32_t next_extension = header_size + 8 * 2; uint32_t next_extension = header_size + 8 * 2;
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
@ -58,7 +58,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) {
ExtPointer path_ptr{ ExtPointer path_ptr{
.offset = next_extension, .offset = next_extension,
// FIXME: Check downcast of str length. // FIXME: Check downcast of str length.
.length = path().length(), .length = (uint32_t)path().length(),
}; };
bytes.WriteStringAt(next_extension, path()); bytes.WriteStringAt(next_extension, path());
@ -72,7 +72,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes) {
WriteHeader(bytes, core_size, next_extension); WriteHeader(bytes, core_size, next_extension);
} }
OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { void OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {
uint32_t next_extension = header_size + 8 * 2; uint32_t next_extension = header_size + 8 * 2;
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
@ -81,7 +81,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps
ExtPointer path_ptr{ ExtPointer path_ptr{
.offset = next_extension, .offset = next_extension,
// FIXME: Check downcast of str length. // FIXME: Check downcast of str length.
.length = path().length(), .length = (uint32_t)path().length(),
}; };
bytes.WriteStringAt(next_extension, path()); bytes.WriteStringAt(next_extension, path());
@ -96,7 +96,7 @@ OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps
} }
void File::ParseFromBytes(const glcr::ByteBuffer& bytes) { void File::ParseFromBytes(const glcr::ByteBuffer& bytes) {
CheckHeader(); CheckHeader(bytes);
auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0)); auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0));
@ -109,7 +109,7 @@ void File::ParseFromBytes(const glcr::ByteBuffer& bytes) {
} }
void File::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) { void File::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer& caps) {
CheckHeader(); CheckHeader(bytes);
auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0)); auto path_pointer = bytes.At<ExtPointer>(header_size + (8 * 0));
@ -119,11 +119,11 @@ void File::ParseFromBytes(const glcr::ByteBuffer& bytes, const glcr::CapBuffer&
uint64_t mem_cap_ptr = bytes.At<uint64_t>(header_size + (8 * 2)); uint64_t mem_cap_ptr = bytes.At<uint64_t>(header_size + (8 * 2));
set_mem_cap(caps.at(mem_cap_ptr)); set_mem_cap(caps.At(mem_cap_ptr));
} }
File::SerializeToBytes(glcr::ByteBuffer& bytes) { void File::SerializeToBytes(glcr::ByteBuffer& bytes) {
uint32_t next_extension = header_size + 8 * 3; uint32_t next_extension = header_size + 8 * 3;
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
@ -131,7 +131,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes) {
ExtPointer path_ptr{ ExtPointer path_ptr{
.offset = next_extension, .offset = next_extension,
// FIXME: Check downcast of str length. // FIXME: Check downcast of str length.
.length = path().length(), .length = (uint32_t)path().length(),
}; };
bytes.WriteStringAt(next_extension, path()); bytes.WriteStringAt(next_extension, path());
@ -147,7 +147,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes) {
WriteHeader(bytes, core_size, next_extension); WriteHeader(bytes, core_size, next_extension);
} }
File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) { void File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {
uint32_t next_extension = header_size + 8 * 3; uint32_t next_extension = header_size + 8 * 3;
const uint32_t core_size = next_extension; const uint32_t core_size = next_extension;
@ -156,7 +156,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {
ExtPointer path_ptr{ ExtPointer path_ptr{
.offset = next_extension, .offset = next_extension,
// FIXME: Check downcast of str length. // FIXME: Check downcast of str length.
.length = path().length(), .length = (uint32_t)path().length(),
}; };
bytes.WriteStringAt(next_extension, path()); bytes.WriteStringAt(next_extension, path());
@ -166,7 +166,7 @@ File::SerializeToBytes(glcr::ByteBuffer& bytes, glcr::CapBuffer& caps) {
bytes.WriteAt<uint64_t>(header_size + (8 * 1), attrs()); bytes.WriteAt<uint64_t>(header_size + (8 * 1), attrs());
caps.Write(next_cap, mem_cap()); caps.WriteAt(next_cap, mem_cap());
bytes.WriteAt<uint64_t>(header_size + (8 * 2), next_cap++); bytes.WriteAt<uint64_t>(header_size + (8 * 2), next_cap++);
// The next extension pointer is the length of the message. // The next extension pointer is the length of the message.

View File

@ -2,6 +2,8 @@
// Generated file - DO NOT MODIFY // Generated file - DO NOT MODIFY
#pragma once #pragma once
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <glacier/string/string.h> #include <glacier/string/string.h>
#include <ztypes.h> #include <ztypes.h>

View File

@ -1,4 +1,5 @@
from enum import Enum from enum import Enum
import sys
class LexemeType(Enum): class LexemeType(Enum):
NONE = 0 NONE = 0

1
yunq/yunq.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#! /usr/bin/python
import os import os
import sys import sys