Ver código fonte

Initial commit

master
Ludovic 'Archivist' Lagouardette 4 anos atrás
commit
9962a1941e
13 arquivos alterados com 291 adições e 0 exclusões
  1. +9
    -0
      .editorconfig
  2. +6
    -0
      .gitignore
  3. +6
    -0
      .travis.yml
  4. +21
    -0
      LICENSE
  5. +27
    -0
      README.md
  6. +13
    -0
      shard.yml
  7. +9
    -0
      spec/andrew_spec.cr
  8. +2
    -0
      spec/spec_helper.cr
  9. +118
    -0
      src/andrew.cr
  10. +11
    -0
      src/views/attribute.ecr
  11. +9
    -0
      src/views/class.ecr
  12. +9
    -0
      src/views/file.ecr
  13. +51
    -0
      tests/record.yml

+ 9
- 0
.editorconfig Ver arquivo

@ -0,0 +1,9 @@
root = true
[*.cr]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

+ 6
- 0
.gitignore Ver arquivo

@ -0,0 +1,6 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf
andrew

+ 6
- 0
.travis.yml Ver arquivo

@ -0,0 +1,6 @@
language: crystal
# Uncomment the following if you'd like Travis to run specs and check code formatting
# script:
# - crystal spec
# - crystal tool format --check

+ 21
- 0
LICENSE Ver arquivo

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 your-name-here
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

+ 27
- 0
README.md Ver arquivo

@ -0,0 +1,27 @@
# andrew
TODO: Write a description here
## Installation
TODO: Write installation instructions here
## Usage
TODO: Write usage instructions here
## Development
TODO: Write development instructions here
## Contributing
1. Fork it (<https://github.com/your-github-user/andrew/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [your-name-here](https://github.com/your-github-user) - creator and maintainer

+ 13
- 0
shard.yml Ver arquivo

@ -0,0 +1,13 @@
name: andrew
version: 0.1.0
authors:
- your-name-here <your-email-here>
targets:
andrew:
main: src/andrew.cr
crystal: 0.30.1
license: MIT

+ 9
- 0
spec/andrew_spec.cr Ver arquivo

@ -0,0 +1,9 @@
require "./spec_helper"
describe Andrew do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end

+ 2
- 0
spec/spec_helper.cr Ver arquivo

@ -0,0 +1,2 @@
require "spec"
require "../src/andrew"

+ 118
- 0
src/andrew.cr Ver arquivo

@ -0,0 +1,118 @@
require "ecr"
require "yaml"
module Andrew
VERSION = "0.1.0"
# TODO: Put your code here
end
class FileGenerator
YAML.mapping(
classes: Array(ClassGenerator),
includes: Array(String)
)
def initialize
@classes = Array(ClassGenerator).new
@includes = Array(String).new
end
ECR.def_to_s "src/views/file.ecr"
end
class ClassGenerator
YAML.mapping(
name: String,
bitfields: Array(BitfieldGenerator),
attributes: Array(AttributeGenerator),
repeats: Array(RepeatGenerator),
attributeafters: Array(AttributeAfterGenerator)
)
def initialize(@name : String)
@bitfields = Array(BitfieldGenerator).new
@attributes = Array(AttributeGenerator).new
@repeats = Array(RepeatGenerator).new
@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
class BitfieldGenerator
YAML.mapping(
class_name: String,
name: String,
out_type: String,
start: Int32,
size: Int32
)
def initialize(@name : String, @out_type : String, @start : Int32, @size : Int32)
@class_name = "no_class"
end
end
class AttributeGenerator
YAML.mapping(
class_name: String,
name: String,
out_type: String,
start: Int32
)
def initialize(@name : String, @out_type : String, @start : Int32)
@class_name = "no_class"
end
ECR.def_to_s "src/views/attribute.ecr"
end
class RepeatGenerator
YAML.mapping(
class_name: String,
name: String,
out_type: String,
start: Int32,
count_name: String
)
def initialize(@name : String, @out_type : String, @start : Int32, @count_name : String)
@class_name = "no_class"
end
end
class AttributeAfterGenerator
YAML.mapping(
class_name: String,
name: String,
out_type: String,
start: Int32,
after_name: String
)
def initialize(@name : String, @out_type : String, @start : Int32, @after_name : String)
@class_name = "no_class"
end
end
#v = ClassGenerator.new("record")
#v.push(AttributeGenerator.new("uuid", "std::array<unsigned char, 16>", 0))
#v.push(AttributeGenerator.new("x", "bitops::regulated<int>", 16))
#v.push(AttributeGenerator.new("y", "bitops::regulated<int>", 20))
#f = FileGenerator.new
#f.classes << v
#f.includes << "<array>"
#f.includes << "\"bitops.hpp\""
#puts f.to_s
File.open(ARGV[0]) do |file|
puts FileGenerator.from_yaml(file).to_s
end

+ 11
- 0
src/views/attribute.ecr Ver arquivo

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

+ 9
- 0
src/views/class.ecr Ver arquivo

@ -0,0 +1,9 @@
class <%= @name %> {
virtual <%= @name %>() = 0;
<%- @attributes.each do |attr| -%>
<%= attr.to_s %>
<%- end -%>
};

+ 9
- 0
src/views/file.ecr Ver arquivo

@ -0,0 +1,9 @@
#pragma once
<%- @includes.each do |v| -%>
#include <%= v%>
<%- end -%>
<%- @classes.each do |v| -%>
<%= v.to_s %>
<%- end -%>

+ 51
- 0
tests/record.yml Ver arquivo

@ -0,0 +1,51 @@
includes:
- <array>
- "\"bitops.hpp\""
classes:
-
name: record_identifier
attributes:
-
name: uuid
out_type: std::array<unsigned char, 16>
start: 0
class_name: record_identifier
-
name: x
out_type: bitops::regulated<uint32_t>
start: 16
class_name: record_identifier
-
name: y
out_type: bitops::regulated<uint32_t>
start: 20
class_name: record_identifier
bitfields: []
repeats: []
attributeafters: []
-
name: record
attributes:
-
name: record_id
out_type: std::array<unsigned char, 24>
start: 0
class_name: record
-
name: timestamp
out_type: bitops::regulated<uint64_t>
start: 24
class_name: record
-
name: offset
out_type: bitops::regulated<uint64_t>
start: 32
class_name: record
-
name: flags
out_type: bitops::regulated<uint32_t>
start: 40
class_name: record
bitfields: []
repeats: []
attributeafters: []

Carregando…
Cancelar
Salvar