• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

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


Commit MetaInfo

Revisãof5ae5dcfe6883f239e94b5f0ac3a7caf8090e031 (tree)
Hora2015-03-09 02:29:28
Autorornse01 <ornse01@user...>
Commiterornse01

Mensagem de Log

add singlar embedded message field in struct.

Mudança Sumário

Diff

--- a/src/protobuf/cgenerator.rb
+++ b/src/protobuf/cgenerator.rb
@@ -4,12 +4,15 @@ require 'pathname'
44 module Protobuf end
55
66 class Protobuf::CGenerator
7- def initialize(msg_list)
7+ def initialize(msg_list, type_dict)
88 @msg_list = msg_list
9+ @type_dict= type_dict
910 end
1011
1112 def generate_header
12- msg_list = @msg_list.map { |msg| Protobuf::CGenerator::Message.new msg }
13+ msg_list = @msg_list.map { |msg|
14+ Protobuf::CGenerator::Message.new msg, @type_dict
15+ }
1316 script = Pathname("../template.h.erb").expand_path(__FILE__).read()
1417
1518 erb = ERB.new(script, nil, '-');
@@ -17,7 +20,9 @@ class Protobuf::CGenerator
1720 end
1821
1922 def generate_source(header_file_name)
20- msg_list = @msg_list.map { |msg| Protobuf::CGenerator::Message.new msg }
23+ msg_list = @msg_list.map { |msg|
24+ Protobuf::CGenerator::Message.new msg, @type_dict
25+ }
2126 script = Pathname("../template.c.erb").expand_path(__FILE__).read()
2227
2328 erb = ERB.new(script, nil, '-');
@@ -26,8 +31,9 @@ class Protobuf::CGenerator
2631 end
2732
2833 class Protobuf::CGenerator::Field
29- def initialize(field_node)
34+ def initialize(field_node, type_dict)
3035 @field_node = field_node
36+ @type_dict = type_dict
3137 end
3238
3339 def name
@@ -66,6 +72,9 @@ class Protobuf::CGenerator::Field
6672 nil
6773 when :bytes
6874 nil
75+ when ->t{ t.is_a? Protobuf::ASTReferenceName }
76+ msg = @type_dict.resolve @field_node.owner_message, @field_node.type.to_s
77+ msg.absolute_name
6978 end
7079 end
7180
@@ -115,11 +124,16 @@ class Protobuf::CGenerator::Field
115124 def is_singular_bytes?
116125 ((@field_node.rule == :required)||(@field_node.rule == :optional))&&(@field_node.type == :bytes)
117126 end
127+
128+ def is_singular_embedded_message?
129+ ((@field_node.rule == :required)||(@field_node.rule == :optional))&&(@field_node.type.is_a? Protobuf::ASTReferenceName)
130+ end
118131 end
119132
120133 class Protobuf::CGenerator::Message
121- def initialize(msg_node)
134+ def initialize(msg_node, type_dict)
122135 @msg_node = msg_node
136+ @type_dict = type_dict
123137 end
124138
125139 def name
@@ -134,7 +148,7 @@ class Protobuf::CGenerator::Message
134148 return to_enum(__method__) unless block_given?
135149
136150 @msg_node.each_field { |field|
137- yield Protobuf::CGenerator::Field.new field
151+ yield Protobuf::CGenerator::Field.new field, @type_dict
138152 }
139153 end
140154 end
--- a/src/protobuf/template.c.erb
+++ b/src/protobuf/template.c.erb
@@ -19,6 +19,9 @@ struct <%= m.name %>_ {
1919 <%- if f.is_singular_bytes? -%>
2020 pb_bytes_t *<%= f.name %>;
2121 <%- end -%>
22+ <%- if f.is_singular_embedded_message? -%>
23+ <%= f.to_c_type %> *<%= f.name %>;
24+ <%- end -%>
2225 <%- end -%>
2326 };
2427
@@ -39,6 +42,9 @@ LOCAL VOID <%= m.name %>__initialize(<%= m.name %> *m)
3942 <%- if f.is_singular_bytes? -%>
4043 m-><%= f.name %> = NULL;
4144 <%- end -%>
45+ <%- if f.is_singular_embedded_message? -%>
46+ m-><%= f.name %> = NULL;
47+ <%- end -%>
4248 <%- end -%>
4349 }
4450
--- a/src/protobufcompiler.rb
+++ b/src/protobufcompiler.rb
@@ -4,6 +4,7 @@ require 'pathname'
44
55 require_relative 'protobuf/parser.rb'
66 require_relative 'protobuf/ast'
7+require_relative 'protobuf/typedict'
78 require_relative 'protobuf/cgenerator'
89
910 option = Hash.new
@@ -21,8 +22,12 @@ end
2122
2223 class ProtobufCompiler
2324 def initialize(src)
25+ @dict = Protobuf::TypeDict.new()
2426 @ir = Protobuf::Parser.new().parse_start(src)
25- @cgen = Protobuf::CGenerator.new @ir.enum_for(:each_message)
27+ @ir.enum_for(:each_message).each { |msg|
28+ @dict.store msg
29+ }
30+ @cgen = Protobuf::CGenerator.new @ir.enum_for(:each_message), @dict
2631 end
2732
2833 def generate_header