Explorar el Código

Added attributeafters

master
Ludovic 'Archivist' Lagouardette hace 5 años
padre
commit
8f5047274a
Se han modificado 5 ficheros con 41 adiciones y 4 borrados
  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 Ver fichero

@ -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 Ver fichero

@ -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 Ver fichero

@ -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 Ver fichero

@ -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 Ver fichero

@ -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

Cargando…
Cancelar
Guardar