• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

超漢字アプリケーション開発用のProtocol Buffersコンパイラの開発


Commit MetaInfo

Revisão005a77eebbcc87e192d4126f92361d7bb41eaeaa (tree)
Hora2015-02-12 02:15:59
Autorornse01 <ornse01@user...>
Commiterornse01

Mensagem de Log

add c source generater experimentally.

Mudança Sumário

Diff

--- a/src/protobuf/cgenerator.rb
+++ b/src/protobuf/cgenerator.rb
@@ -12,7 +12,12 @@ class Protobuf::CGenerator
1212 erb.result(binding)
1313 end
1414
15- def self.generate_source
15+ def self.generate_source(msg_list)
16+ msg_list = msg_list.map { |msg| Protobuf::CGenerator::Message.new msg }
17+ script = Pathname("../template.c.erb").expand_path(__FILE__).read()
18+
19+ erb = ERB.new(script, nil, '-');
20+ erb.result(binding)
1621 end
1722 end
1823
--- /dev/null
+++ b/src/protobuf/template.c.erb
@@ -0,0 +1,111 @@
1+/* this file is automaticall generated. */
2+
3+#include <basic.h>
4+#include <pb_scalartype.h>
5+
6+<%- msg_list.each do |m| -%>
7+struct <%= m.name %>_ {
8+};
9+
10+<%- end -%>
11+
12+<%- msg_list.each do |m| -%>
13+/* <%= m.name %> */
14+EXPORT <%= m.name %>* <%= m.name %>__new()
15+{
16+}
17+
18+EXPORT VOID <%= m.name %>__delete(<%= m.name %> *m)
19+{
20+}
21+
22+EXPORT Bool <%= m.name %>__isequal(<%= m.name %> *m, <%= m.name %> *other)
23+{
24+}
25+
26+EXPORT VOID <%= m.name %>__swap(<%= m.name %> *m, <%= m.name %> *other)
27+{
28+}
29+
30+ <%- m.each_field do |f| -%>
31+/* <%= m.name %>.<%= f.name %> */
32+ <%- if f.is_singular_numeric? -%>
33+EXPORT Bool <%= m.name %>__has_<%= f.name %>(<%= m.name %> *m)
34+{
35+}
36+
37+EXPORT <%= f.to_c_type %> <%= m.name %>__<%= f.name %>(<%= m.name %> m*)
38+{
39+}
40+
41+EXPORT VOID <%= m.name %>__set_<%= f.name %>(<%= m.name %> *m, <%= f.to_c_type %> value)
42+{
43+}
44+
45+EXPORT VOID <%= m.name %>__clear_<%= f.name %>(<%= m.name %> *m)
46+{
47+}
48+
49+ <%- end -%>
50+ <%- if f.is_singular_string? -%>
51+EXPORT Bool <%= m.name %>__has_<%= f.name %>(<%= m.name %> *m)
52+{
53+}
54+
55+EXPORT pb_str_t* <%= m.name %>__<%= f.name %>(<%= m.name %> *m)
56+{
57+}
58+
59+EXPORT void <%= m.name %>__set_<%= f.name %>(<%= m.name %> *m, const pb_str_t *string)
60+{
61+}
62+
63+EXPORT pb_str_t* <%= m.name %>__mutable_<%= f.name %>(<%= m.name %> *m)
64+{
65+}
66+
67+EXPORT void <%= m.name %>__clear_<%= f.name %>(<%= m.name %> *m)
68+{
69+}
70+
71+EXPORT void <%= m.name %>__set_allocated_<%= f.name %>(<%= m.name %> *m, pb_str_t *value)
72+{
73+}
74+
75+EXPORT pb_str_t* <%= m.name %>__release_<%= f.name %>(<%= m.name %> *m)
76+{
77+}
78+
79+ <%- end -%>
80+ <%- if f.is_singular_bytes? -%>
81+EXPORT Bool <%= m.name %>__has_<%= f.name %>(<%= m.name %> *m)
82+{
83+}
84+
85+EXPORT pb_bytes_t* <%= m.name %>__<%= f.name %>(<%= m.name %> *m)
86+{
87+}
88+
89+EXPORT void <%= m.name %>__set_<%= f.name %>(<%= m.name %> *m, const pb_bytes_t *string)
90+{
91+}
92+
93+EXPORT pb_bytes_t* <%= m.name %>__mutable_<%= f.name %>(<%= m.name %> *m)
94+{
95+}
96+
97+EXPORT void <%= m.name %>__clear_<%= f.name %>(<%= m.name %> *m)
98+{
99+}
100+
101+EXPORT void <%= m.name %>__set_allocated_<%= f.name %>(<%= m.name %> *m, pb_bytes_t *value)
102+{
103+}
104+
105+EXPORT pb_bytes_t* <%= m.name %>__release_<%= f.name %>(<%= m.name %> *m)
106+{
107+}
108+
109+ <%- end -%>
110+ <%- end -%>
111+<%- end -%>
--- a/src/protobufcompiler.rb
+++ b/src/protobufcompiler.rb
@@ -27,6 +27,10 @@ class ProtobufCompiler
2727 def generate_header
2828 Protobuf::CGenerator.generate_header @ir.enum_for(:each_message)
2929 end
30+
31+ def generate_source
32+ Protobuf::CGenerator.generate_source @ir.enum_for(:each_message)
33+ end
3034 end
3135
3236 compiler = ProtobufCompiler.new <<EOS
@@ -51,5 +55,11 @@ option[:src].each { |file|
5155 dest_fname_base.sub_ext('.pb.h').open('w') { |fd|
5256 fd.write dest_header
5357 }
58+
59+ dest_source = compiler.generate_source
60+
61+ dest_fname_base.sub_ext('.pb.c').open('w') { |fd|
62+ fd.write dest_source
63+ }
5464 }
5565 }