RuCodeGen 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/LICENSE +25 -0
  2. data/README +34 -0
  3. data/Rakefile +32 -0
  4. data/docs/Principle +152 -0
  5. data/docs/ValueIncapsulator +195 -0
  6. data/docs/examples/cpp/custom/submit_deliver +909 -0
  7. data/docs/examples/cpp/value_incapsulator/cfg +127 -0
  8. data/docs/examples/cpp/value_incapsulator/host_config +51 -0
  9. data/examples/cpp/custom/submit_deliver/submit_deliver.rb +43 -0
  10. data/examples/cpp/custom/submit_deliver/submit_deliver_gen.rb +326 -0
  11. data/examples/cpp/value_incapsulator/cfg.decl.hpp +51 -0
  12. data/examples/cpp/value_incapsulator/cfg.impl.cpp +63 -0
  13. data/examples/cpp/value_incapsulator/cg-cfg.rb +19 -0
  14. data/examples/cpp/value_incapsulator/cg-cfg.test.cpp +15 -0
  15. data/examples/cpp/value_incapsulator/cg-host_config.rb +12 -0
  16. data/examples/cpp/value_incapsulator/cout.log +4 -0
  17. data/examples/cpp/value_incapsulator/host_config.impl.cpp +21 -0
  18. data/examples/cpp/value_incapsulator/host_config.impl.hpp +21 -0
  19. data/lib/rucodegen/begin_end.rb +26 -0
  20. data/lib/rucodegen/codegen.rb +4 -0
  21. data/lib/rucodegen/filename_producer.rb +57 -0
  22. data/lib/rucodegen/generation_initiator.rb +92 -0
  23. data/lib/rucodegen/generators.rb +36 -0
  24. data/lib/rucodegen/run_mode.rb +89 -0
  25. data/lib/rucodegen/value_incapsulator.rb +331 -0
  26. data/lib/rucodegen.rb +4 -0
  27. data/tests/generators_test_extension.rb +23 -0
  28. data/tests/tc_class_attribute.rb +87 -0
  29. data/tests/tc_codegen_initiator.rb +164 -0
  30. data/tests/tc_filename_producer.rb +54 -0
  31. data/tests/tc_generators.rb +55 -0
  32. data/tests/tc_run_mode.rb +72 -0
  33. data/tests/tc_value_incapsulator.rb +193 -0
  34. data/tests/tc_value_incapsulator_gen.rb +479 -0
  35. data/tests/ts_rucodegen.rb +11 -0
  36. metadata +98 -0
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ #
2
+ # Copyright (c) 2005, Yauheni Akhotnikau
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ # 3. The name of the author may not be used to endorse or promote products derived
14
+ # from this software without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
+ # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
19
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
data/README ADDED
@@ -0,0 +1,34 @@
1
+ = RuCodeGen � ���������� ��� �������������
2
+
3
+ == ��������
4
+
5
+ RuCodeGen � ��� ������� ���������� ��� �������������. RuCodeGen ������� �� ����
6
+ ������ � ���������� ���������� ��� ��������� ���������������, � ���������� ������� ���������������.
7
+
8
+ ��������� ��. {docs/Principle}[link://files/docs/Principle.html].
9
+
10
+ == ������� ��������������
11
+
12
+ * cpp_value_incapsulator (���������� RuCodeGen::ValueIncapsulator).
13
+ ��������� ��. {docs/ValueIncapsulator}[link://files/docs/ValueIncapsulator.html].
14
+
15
+ === ������� ������������� � �������� ���������������
16
+
17
+ * {cpp/value_incapsulator/host_config}[link://files/docs/examples/cpp/value_incapsulator/host_config.html]
18
+ * {cpp/value_incapsulator/cfg}[link://files/docs/examples/cpp/value_incapsulator/cfg.html]
19
+ * {cpp/custom/submit_deliver}[link://files/docs/examples/cpp/custom/submit_deliver.html]
20
+
21
+ == �����������
22
+
23
+ RuCodeGen ���������������� � ���� Gem-�. ��� ��� ����������� ���������� ��������������� ��������:
24
+
25
+ gem install RuCodeGen
26
+
27
+ == ��������
28
+
29
+ RuCodeGen ���������������� ��� BSD ��������� (��. LICENSE[link://files/LICENSE.html]).
30
+
31
+ == �������������
32
+
33
+ Homepage:: http://eao197.narod.ru/projects/rucodegen
34
+ Email:: mailto://eao197@yahoo.com
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ Gem::manage_gems
3
+
4
+ require 'rake/gempackagetask'
5
+
6
+ PKG_NAME =
7
+ RKG_VERSION = '0.1.0'
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = "RuCodeGen"
11
+ s.version = "0.1.0"
12
+ s.author = "Yauheni Akhotnikau"
13
+ s.email = "eao197@yahoo.com"
14
+ s.homepage = "http://eao197.narod.ru/projects"
15
+ s.platform = Gem::Platform::RUBY
16
+ s.summary = "Simple code generation tool"
17
+ s.files = FileList[ "{bin,tests,lib,docs,examples}/**/*" ].
18
+ exclude( "rdoc" ).to_a
19
+ s.require_path = "lib"
20
+ s.autorequire = "rucodegen"
21
+ s.test_file = "tests/ts_rucodegen.rb"
22
+ s.has_rdoc = true
23
+ s.rdoc_options = [ '-c', 'windows-1251', '-S', '--main', 'README' ]
24
+ s.extra_rdoc_files = [ "README", "Rakefile", "LICENSE" ] + FileList[ "docs/**/*" ].to_a
25
+ end
26
+
27
+ gem = Rake::GemPackageTask.new( spec ) do |pkg|
28
+ pkg.need_zip = true
29
+ pkg.need_tar = true
30
+ end
31
+
32
+ task :default => [ gem.package_dir + "/" + gem.name + "-" + gem.version.version + ".gem" ]
data/docs/Principle ADDED
@@ -0,0 +1,152 @@
1
+ = �������� ������ RuCodeGen
2
+
3
+ == ������� �������� ������������� RuCodeGen
4
+
5
+ RuCodeGen �������� �� ������������� ����� Ruby � �������� DSL (Domain
6
+ Specific Language) ��� �������� �����-���� �������������. ��� ��������, ���
7
+ ��� � ��������� ������������� �������� � ���� Ruby-�������. ���� ������ �����
8
+ ����������� �� ���������� (��� ������� Ruby-������) � � ���������� ����������
9
+ ���� ��� ��������� �������������� ������ �� ��������������� �����.
10
+
11
+ ���� �������� �������� ������������� �������
12
+ {RuCodeGen::ValueIncapsulator}[link://files/docs/ValueIncapsulator.html].
13
+
14
+ === �������� ������� � ��������� �������������
15
+
16
+ � ������� ��� ��������� C++ ������ � �������������� RuCodeGen::ValueIncapsulator
17
+ ���������� ������� ��� ����:
18
+ 1. ���������� Gem RuCodeGen.
19
+ 2. ������� �������� ��� ��������� C++ ������.
20
+
21
+ ��������:
22
+
23
+ # �������� Gem RuCodeGen.
24
+ require 'rubygems'
25
+ require_gem 'RuCodeGen'
26
+
27
+ # �������� ��� �������������.
28
+ cpp_value_incapsulator :host_config_t do |c|
29
+ c.decl_file :script_relative => "host_config.impl.hpp"
30
+ c.impl_file :script_relative => "host_config.impl.cpp"
31
+
32
+ c.attr_prefix "m_"
33
+
34
+ c.attr :host, "std::string", :default => "localhost"
35
+ c.attr :post, "short", :default => 8080
36
+ end
37
+
38
+ ����� ����������� ��� ����������� � ����� src/cg-host_config.rb.
39
+
40
+ === ������ ������� �� ����������
41
+
42
+ ����������� ���� ������ ����� ������������ ��� �����: src/host_config.impl.hpp
43
+ � src/host_config.impl.cpp. ��� ����� ����� ���� ���������� ���������
44
+ ������ src/cg-host_config.rb:
45
+
46
+ $ruby src/cg-host_config.rb
47
+
48
+ ����� ���������� ����� ����� �������� � �++ ������.
49
+
50
+ === ������ ������ RuCodeGen
51
+
52
+ �� ���������, ������ � ��������� ������������� ��������� �������������. ��
53
+ ��� ����� ���� ���� �� ��������� ������� ��� ������. ����� ������ ���������
54
+ ��������� ������, ����� ��������� ������ � ���������� <tt>--help</tt>:
55
+
56
+
57
+ $ruby src/cg-host_config.rb --help
58
+ Usage: cg-host_config [options]
59
+ -m, --mode MODE run mode
60
+ (build, rebuild, clean, dry-run)
61
+ -h, --help show this screen
62
+
63
+ ���� �������� <tt>--mode</tt> �� �����, �� ���������������, ���
64
+ ������ ����������� � ���������� <tt>--mode build</tt>. ��, ������ ��������
65
+ <tt>--mode</tt> � ��������� ������ ����, ����� ������� ����� �� ��������������
66
+ �������:
67
+ [_build_] ��������� �������������. ������� ������������� ������������ ������
68
+ � ������� ��������� ��������� ��������� ������ � ��������� ���
69
+ ��� ������ �����-�� �� �������������� ����� ������.
70
+ [_rebuild_] ��������� �������������� �������������, ���� ���� � �������
71
+ ��������� ��������� ������ �� ��������� � �� ����������.
72
+ [_clean_] ������� ��� ���������� ���������� �������������.
73
+ [<i>dry-run</i>] ������ �� ������������. ����� ���� ������� ��� �������� �������������� ������������ ������� � ��������� ���������� �������������.
74
+
75
+ == ���������� �����
76
+
77
+ === ���������� ����
78
+
79
+ ���� RuCodeGen ������� � ���, ����� ��� ������� ���� ������������� ���
80
+ ������ ���� ������ (���, ��������, RuCodeGen::ValueIncapsulator). �������
81
+ � ��������� ���������� ������������� ������������ �� ����������� �����������
82
+ �������. ���� RuCodeGen � ����� ������ ����������� �� � ���������:
83
+ 1. ������������ �������� ������� ��������� ��� ���������� ������������
84
+ �������� (����� ��� �������� ������������� ����������� ����������
85
+ �������������, ������������� ����� �������������, ��������� ����������
86
+ ��������� ������� � ��.).
87
+ 1. ���� ���������� �������� ����������������� � ������������� ���������������.
88
+
89
+ � �������� �������� ���������� ��� ��������� ������������� RuCodeGen
90
+ �������, ����� ������ ������ � ���������� ����� ������ ���������� ���� ���
91
+ ��������� ��������-����������� � ������������� �� � ������
92
+ RuCodeGen::Generators. ���� ������ ��������� ������ ���� ������ � ����������
93
+ ������ ��������������� ����� (�.�. �� ������ ������ ������ ������� ���,
94
+ ����� ��������� ����������� �������������� ���� � ��� �� ����).
95
+
96
+ ���������� ������ ������������ ��������� ���������:
97
+
98
+ def generate(to) ... end
99
+
100
+ ��� � �������� ��������� to ����� ������������ �����-�����, � ������� �����
101
+ ���������� ���������� ���������.
102
+
103
+ ��������� ������� ����������� �������� ������
104
+ RuCodeGen::ValueIncapsulator::Generation::DeclGenerator �
105
+ RuCodeGen::ValueIncapsulator::Generation::ImplGenerator.
106
+
107
+ === ������������� �������������
108
+
109
+ ���� ������ � ��������� ������������� ����������� � ������ +build+, ��
110
+ ��������� ����������� ��� ���������� ������ ������� ��������� �������:
111
+ 1. ����������� ������� ����� � ����������� ������ ��������.
112
+ ��������, ���� �������� ������������� ��������� � �����
113
+ src/cg-host_config.rb, �� ��� ����������� ����� ������ ��������� �
114
+ ����� src/.cg-host_config.rb.md5.
115
+ 2. ���� ����� � ����������� ������ ���, �� ����������� ������
116
+ �������������. ���� ���� ���� �������� �� ���������� � ���������� ���
117
+ ���������� ���������� �������������.
118
+ 3. ���� ���� � ����������� ������ ����, �� ��� ���������� �� ��������� �
119
+ ����������� ������ ������� � ��������� �������������, �� �����������
120
+ ������ ������������� (�.�. ���������, ��� ���������� ��������� ���������).
121
+ 4. ���� ����������� ����� ������� � ��������� ������������� ��������
122
+ ����������, �� ����������� ������� ������-����������� �������������.
123
+ � ���� ������ ��������� ����������� ������ ��� ������������� ������.
124
+
125
+ ���� ������ � ��������� ������������� ����������� � ������ +clean+, �� ���������
126
+ ��� ����� � ������������ ������������� � ���� � ����������� ������.
127
+
128
+ === ������������ ����������� �������������
129
+
130
+ � ��������, ������ ���������������� ������ ����� ��������� �����������
131
+ ������� ������������ ��������������� �� ������. RuCodeGen �������������
132
+ ����� RuCodeGen::FilenameProducer, ������� �������� ����������� �����
133
+ ��� ���� ������� ��������:
134
+ * ����� � �������� ��������������� ����� ����������� ���������� ��� �����.
135
+ � ���� ������ ������� �������������� ��� ��������� ������ ��������� ��
136
+ �����;
137
+ * ����� ����������� ���, �������� ������������ �������� ��������. � ���� ������
138
+ ����������� ������ ���, � ������� ����������� ��� �������� ��������;
139
+ * ����� ����������� ���, ������� ������������ ������� � ���������
140
+ �������������. � ���� ������ ����������� ������ ��� � ������ ������������
141
+ ��������� �������.
142
+
143
+ ��������, � ����������� ���� ������� � src/cg-host_config.rb, �����
144
+ ������������� ������ ������ ������������ ������� cg-host_config.rb. �������,
145
+ ������, ���� ������ ��������� � �������� ~/sandboxes/some_prj/src, � �������
146
+ ��������� �������� ~/sandboxes, �� ������ �������������:
147
+
148
+ ruby some_prj/src/cg-host_config.rb
149
+
150
+ �������� � �������� ������ ~/sandboxes/some_prj/src/host_config.impl.hpp �
151
+ ~/sandboxes/some_prj/src/host_config.impl.cpp.
152
+
@@ -0,0 +1,195 @@
1
+ = ������ ValueIncapsulator [C++]
2
+
3
+ == ����������
4
+
5
+ ������ ValueIncapsulator ������������ ��� ��������� C++ �������, ������� ������
6
+ ������������� � ���� ��������� �������� � ������������� ��������� ������ ���
7
+ ���������/��������� ���� ��������. ��������� ����� ������� ����� ���� ������,
8
+ ���������� ������������ ����������. ��������, ����� ����� �����, �������
9
+ �������� ��� ����� � ����� ����� ��� ����������� � ����� ����� ����� TCP/IP.
10
+ ��� ������������� ������������� �������� �� �������� ��������� C++ ���:
11
+
12
+ class host_config_t
13
+ {
14
+ private :
15
+ std::string m_host;
16
+ short m_port;
17
+ public :
18
+ host_config_t()
19
+ : m_port( 0 )
20
+ {}
21
+
22
+ const std::string & host() const { return m_host; }
23
+ void set_host( const std::string & v ) { m_host = v; }
24
+
25
+ short port() const { return m_port; }
26
+ void set_port( short v ) { m_port = v; }
27
+ };
28
+
29
+ �� ������ �� ���������� ����� ������� � �������������� ������� ValueIncapsulator:
30
+
31
+ cpp_value_incapsulator :host_config_t do |c|
32
+ c.decl_file :script_relative => "host_config.impl.hpp"
33
+ c.impl_file :script_relative => "host_config.impl.cpp"
34
+
35
+ c.attr_prefix "m_"
36
+ c.attr :host, "std::string"
37
+ c.attr :port, "short", default => 0
38
+ end
39
+
40
+ == ������� ������
41
+
42
+ ������ ValueIncapsulator ������������ ����������� ������ cpp_value_incapsulator,
43
+ ������� �������� � �������� ��������� ��� ������������� C++ ������ � �������
44
+ ������� ����� ����, � ������� ����� ���������� ��������� �������������.
45
+ ���� ���� ���� ���������� ������ cpp_value_incapsulator � ����� ����������:
46
+ ����������� ������ RuCodeGen::ValueIncapsulator. � ������� ������ �����
47
+ ���������� � �������� ��������� �������������.
48
+
49
+ ����� ����, ��� ���� ���� ������ cpp_value_incapsulator ����������,
50
+ ������ ������� ��� ���������� ���� -- ���� ��� ��������� �������� ������,
51
+ ������ ��� ��������� ���������� ������. � ������� ������ ValueIncapsulator,
52
+ �������� � ���������� ������ ������ ����������� � ��������� ������,
53
+ ������������ � ����� ������� �������� ����������� �������
54
+ RuCodeGen::ValueIncapsulator#decl_file � RuCodeGen::ValueIncapsulator#impl_file.
55
+ ��������� cpp_value_incapsulator ���������� ����������� �� ����������
56
+ ������� ������� ��� ���������� ������ �������.
57
+
58
+ == ��������� ������� ValueIncapsulator
59
+
60
+ === ����� ��������/���������� ������������� ������.
61
+
62
+ ����� � ������������ ������ �������� ����������� ������� decl_file �
63
+ impl_file:
64
+ c.decl_file <relative> => <name>
65
+ ��� <relative> ���:
66
+ [<tt>:absolute</tt>] �������� ���������� ��� �����;
67
+ [<tt>:script_relative</tt>] ��� ����� �������� ������������ ������������
68
+ ������� � ��������� �������������;
69
+ [<tt>:cwd_relative</tt>] ��� ����� �������� ������������ �������� ��������.
70
+
71
+ ��������:
72
+ c.decl_file :script_relative => "h/decl.hpp"
73
+ c.impl_file :script_relative => "decl.cpp"
74
+
75
+ ��������� ��. RuCodeGen::FilenameProducer#produce.
76
+
77
+ === ��������/�������� ��� ���� ���������
78
+
79
+ �� ���������, ValueIncapsulator ������� �������� ���������������� ������
80
+ � ���� �������, ������� ���� �������� � ����� c.attr. ��������, ���
81
+ ��������:
82
+
83
+ c.attr :host, "std::string"
84
+
85
+ ����� ������������ ������� host ���� std::string. ���� ���������, �����
86
+ � ��������� ������ ���� ������������� �������� ���/� ��������, �� �������
87
+ ������ �� � ������� ������� attr_prefix, attr_suffix. ��������:
88
+
89
+ c.attr_prefix "m_"
90
+ c.attr :host, "std::string"
91
+
92
+ �������� � ���������:
93
+ std::string m_host;
94
+
95
+ � ��������:
96
+
97
+ c.attr_suffix "_"
98
+ c.attr :host, "std::string"
99
+
100
+ �������� � ���������:
101
+ std::string host_;
102
+
103
+ ����� ������ ������������ � �������, � �������.
104
+
105
+ === �������� ��� ������� getter-/setter-��
106
+
107
+ �� ���������, ValueIncapsulator ������� ������ getter-/setter-� � ����
108
+ �������, ������� ���� �������� � ����� c.attr. ��������:
109
+
110
+ c.attr :port, "short"
111
+
112
+ ������������� �:
113
+
114
+ short port() const;
115
+ void port( short v__ );
116
+
117
+ � ������� ������� getter_prefix � setter_prefix ����� ������� �������
118
+ ��� ���������������� ���� �������. ��������:
119
+
120
+ c.getter_prefix "query_"
121
+ c.attr :port, "short"
122
+
123
+ ������������� �:
124
+
125
+ short query_port() const;
126
+ void port( short v__ );
127
+
128
+ ���:
129
+
130
+ c.setter_prefix "set_"
131
+ c.attr :port, "short"
132
+
133
+ �������� �:
134
+
135
+ short port() const;
136
+ void set_port( short v__ );
137
+
138
+ ����� ������ ������������ �������� ��� getter-�� � setter-��.
139
+
140
+ == �������� �� ��������� ��� ���������
141
+
142
+ �� ���������, ��� ���� ��������� ����������� ����� (��.
143
+ RuCodeGen::ClassAttribute::PRIMITIVE_TYPES) � ������������ ��������
144
+ �������� 0. ��� ���������, ��� �������� �� ��������� � ����������� �����
145
+ ��������� �������� ������ �� ��������.
146
+ ���� ��� �� ���������� � ����� ��������� ��������
147
+ ������������� ��������, �� ��� ������� ������� � ������ attr:
148
+
149
+ c.attr :host, "std::string", :default => "localhost"
150
+ c.attr :port, "short", :default => 8080
151
+
152
+ === ������������� ��������������� � �������� ��������� �������� ���������
153
+
154
+ ���� ��������� �������� �������� �������� �����-���� C++ ����������,
155
+ ��������� enum-� ��� ���� ������� C++ �������, �� ��������������� C++
156
+ ������������� ����� ���������� � Ruby-���� � ���� Symbol-� (��������������
157
+ � �������������� ����������):
158
+
159
+ c.attr :host, "std::string", :default => :"get_default_host()"
160
+ c.attr :port, "short", :default => :default_port
161
+
162
+ ����� � ������������ ������������� ��������� ����� ����� ���:
163
+
164
+ host( get_default_host() ),
165
+ port( default_port )
166
+
167
+ == ������ �� ���������� �� ����������� �����
168
+
169
+ ���� ��� �������� �� �������� ����������� (��.
170
+ RuCodeGen::ClassAttribute::PRIMITIVE_TYPES), �� ����� getter ����������
171
+ ����������� ������ �� �������, � ����� setter �������� �����������
172
+ ������ � �������� ���������. ��������:
173
+
174
+ c.attr :host, "std::string"
175
+
176
+ �������� � ���������:
177
+
178
+ const std::string & host() const;
179
+ void host( const std::string & v__ );
180
+
181
+ ���� �� �����-�� �������� ������������ ������ �� ����������, �� ���
182
+ ����� ������� ��� �������� ��������:
183
+
184
+ c.attr :host, "std::string", getter_returns_value => true
185
+
186
+ ��� �������� � ���������:
187
+
188
+ std::string host() const;
189
+ void host( std::string v__ );
190
+
191
+ == ������� ������������� �������������� cpp_value_incapsulator
192
+
193
+ {������ host_config}[link://files/docs/examples/cpp/value_incapsulator/host_config.html]
194
+
195
+ {������ cfg}[link://files/docs/examples/cpp/value_incapsulator/cfg.html]