瀏覽代碼

fixed stuff

master
Ludovic 'Archivist' Lagouardette 5 年之前
父節點
當前提交
32d1895f0b
共有 6 個文件被更改,包括 121 次插入28 次删除
  1. +11
    -9
      src/andrew.cr
  2. +45
    -12
      src/views/class.ecr
  3. +7
    -0
      src/views/file.ecr
  4. +19
    -0
      src/views/repeat.ecr
  5. +24
    -0
      tests/db_file.yml
  6. +15
    -7
      tests/record.yml

+ 11
- 9
src/andrew.cr 查看文件

@ -11,7 +11,11 @@ end
class FileGenerator
YAML.mapping(
classes: Array(ClassGenerator),
includes: Array(String)
includes: Array(String),
namespace: {
type: String,
nilable: true
}
)
def initialize
@ -40,6 +44,10 @@ class ClassGenerator
attributeafters: {
type: Array(AttributeAfterGenerator),
nilable: true
},
size: {
type: Int32,
nilable: true
}
)
@ -50,14 +58,6 @@ class ClassGenerator
@attributeafters = Array(AttributeAfterGenerator).new
end
def push(attr : AttributeGenerator)
attr.class_name = @name
@attributes.push(attr)
end
def push(bitf : BitfieldGenerator)
end
ECR.def_to_s "src/views/class.ecr"
end
@ -112,6 +112,8 @@ class RepeatGenerator
def initialize(@name : String, @out_type : String, @start : Int32, @count_name : String)
@class_name = "no_class"
end
ECR.def_to_s "src/views/repeat.ecr"
end
class AttributeAfterGenerator

+ 45
- 12
src/views/class.ecr 查看文件

@ -1,24 +1,57 @@
class <%= @name %> {
virtual ~<%= @name %>() = 0;
public:
<% if !(@attributes.nil?) %>
<%- @attributes.not_nil!.each do |attr| -%>
<%- attr.class_name = @name -%>
<%= attr.to_s %>
<%- end -%>
<%- @attributes.not_nil!.each do |attr| -%>
<%- attr.class_name = @name -%>
<%-= attr.to_s %>
<%- end -%>
<% end %>
<% if !(@attributeafters.nil?) %>
<%- @attributeafters.not_nil!.each do |attr| -%>
<%- attr.class_name = @name -%>
<%= attr.to_s %>
<%- end -%>
<%- @attributeafters.not_nil!.each do |attr| -%>
<%- attr.class_name = @name -%>
<%-= attr.to_s %>
<%- end -%>
<% end %>
<% if !(@bitfields.nil?) %>
<%- @bitfields.not_nil!.each do |attr| -%>
<%- attr.class_name = @name -%>
<%= attr.to_s %>
<%- end -%>
<%- @bitfields.not_nil!.each do |attr| -%>
<%- attr.class_name = @name -%>
<%-= attr.to_s %>
<%- end -%>
<% end %>
<% if !(@repeats.nil?) %>
<%- @repeats.not_nil!.each do |attr| -%>
<%- attr.class_name = @name -%>
<%-= attr.to_s %>
<%- end -%>
<% end %>
private:
void dummy_function()
{
<% if !@size.nil? %>
<%- sz = @size.not_nil! -%>
<% if !(@attributes.nil?) %>
<%- @attributes.not_nil!.each do |attr|-%>
<%- if attr.start > sz -%>
<%- raise "attribute starts after end: "+attr.name+" in class "+@name -%>
<%- end -%>
static_assert(<%= attr.name %>_end_position()<=<%= sz%>, "attribute past the end");
<%- end -%>
<%- end -%>
<% if !(@bitfields.nil?) %>
<%- @bitfields.not_nil!.each do |attr|-%>
<%- if attr.start > sz -%>
<%- raise "bitfield starts after end: "+attr.name+" in class "+@name -%>
<%- end -%>
static_assert(<%= attr.name %>_end_position()<=<%= sz%>, "attribute past the end");
<%- end -%>
<%- end -%>
<% end %>
}
};

+ 7
- 0
src/views/file.ecr 查看文件

@ -3,7 +3,14 @@
#include <%= v%>
<%- end -%>
<%- if !(@namespace.nil?) -%>
namespace <%= @namespace.to_s %> {
<%- end -%>
<%- @classes.each do |v| -%>
<%= v.to_s %>
<%- end -%>
<%- if !(@namespace.nil?) -%>
}
<%- end -%>

+ 19
- 0
src/views/repeat.ecr 查看文件

@ -0,0 +1,19 @@
static std::span<<%= @out_type %>> get_<%= @name %>(const <%= class_name %>& alter) {
auto ptr = (char*)&alter;
ptr+=<%= @start %>;
return std::span<<%= @out_type %>>((<%= @out_type %>*)ptr, get_<%= @count_name %>(alter));
}
static void set_<%= @name %>(<%= class_name %>& alter, size_t index, const <%= @out_type %>& param) {
auto ptr = (char*)&alter;
ptr+=<%= @start %>;
*(<%= @out_type %>*)ptr = param;
}
static constexpr size_t <%= @name %>_position() {
return <%= @start %>;
}
static size_t <%= @name %>_end_position(<%= class_name %>& alter) {
return <%= @start %>+get_<%= @count_name %>(alter)*sizeof(<%= @out_type %>);
}

+ 24
- 0
tests/db_file.yml 查看文件

@ -0,0 +1,24 @@
includes:
- <array>
- <span>
namespace: db
classes:
-
name: database
attributes:
-
name: metadata
start: 0
out_type: std::array<uint8_t, 4096>
-
name: record_cnt
start: 0
out_type: uint64_t
repeats:
-
name: record_list
start: 4096
out_type: std::array<uint8_t, 64>
count_name: record_cnt

+ 15
- 7
tests/record.yml 查看文件

@ -1,8 +1,10 @@
includes:
- <array>
namespace: db
classes:
-
name: record_identifier
size: 24
attributes:
-
name: uuid
@ -18,6 +20,7 @@ classes:
start: 20
-
name: record
size: 64
attributes:
-
name: record_id
@ -37,35 +40,40 @@ classes:
name: flags
out_type: uint16_t
start: 40
mask: 0b0000000000000111
mask: 0b1110000000000000
-
name: v_flag
out_type: uint16_t
after_name: offset
start: 40
mask: 0b0000000000000100
mask: 0b1000000000000000
-
name: r_flags
out_type: uint16_t
start: 40
mask: 0b0000000000000010
mask: 0b0100000000000000
-
name: c_flags
out_type: uint16_t
start: 40
mask: 0b0000000000000001
mask: 0b0010000000000000
-
name: confirmed
out_type: uint16_t
start: 40
mask: 0b0000000000000001
mask: 0b0010000000000000
-
name: validated
out_type: uint16_t
start: 40
mask: 0b0000000000000101
mask: 0b1010000000000000
-
name: removed
out_type: uint16_t
start: 40
mask: 0b0000000000000010
mask: 0b0100000000000000
-
name: next_jump
out_type: uint16_t
start: 40
mask: 0b0000111111111111

Loading…
取消
儲存