Browse Source

Added attributeafters

master
Ludovic 'Archivist' Lagouardette 5 years ago
parent
commit
8f5047274a
5 changed files with 41 additions and 4 deletions
  1. +3
    -2
      src/andrew.cr
  2. +8
    -0
      src/views/attribute.ecr
  3. +19
    -0
      src/views/attribute_after.ecr
  4. +8
    -0
      src/views/class.ecr
  5. +3
    -2
      tests/record.yml

+ 3
- 2
src/andrew.cr View File

@ -120,12 +120,13 @@ class AttributeAfterGenerator
},
name: String,
out_type: String,
start: Int32,
after_name: String
)
def initialize(@name : String, @out_type : String, @start : Int32, @after_name : String)
def initialize(@name : String, @out_type : String, @after_name : String)
@class_name = "no_class"
end
ECR.def_to_s "src/views/attribute_after.ecr"
end
if(ARGV.size != 0)

+ 8
- 0
src/views/attribute.ecr View File

@ -8,4 +8,12 @@
auto ptr = (char*)&alter;
ptr+=<%= @start %>;
*(<%= @out_type %>*)ptr = param;
}
constexpr size_t <%= @name %>_position() {
return <%= @name %>_position;
}
constexpr size_t <%= @name %>_end_position() {
return <%= @start %>+sizeof(<%= @out_type %>);
}

+ 19
- 0
src/views/attribute_after.ecr View File

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

+ 8
- 0
src/views/class.ecr View File

@ -6,6 +6,14 @@ virtual <%= @name %>() = 0;
<%- 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 -%>
<% end %>
};

+ 3
- 2
tests/record.yml View File

@ -28,11 +28,12 @@ classes:
name: timestamp
out_type: bitops::regulated<uint64_t>
start: 24
attributeafters:
-
name: offset
out_type: bitops::regulated<uint64_t>
start: 32
after_name: timestamp
-
name: flags
out_type: bitops::regulated<uint32_t>
start: 40
after_name: offset

Loading…
Cancel
Save