ソースを参照

Fix data length sent to client from ruby server. Pad with extra bytes.

tags/v1.0^2
Benjamin Attal 10年前
コミット
d8048a74f0
2個のファイルの変更31行の追加14行の削除
  1. +13
    -2
      parsers/ruby/lib/parse_server.rb
  2. +18
    -12
      parsers/ruby/lib/parser.rb

+ 13
- 2
parsers/ruby/lib/parse_server.rb ファイルの表示

@@ -1,6 +1,17 @@
require 'socket' require 'socket'
require File.expand_path('../parser.rb', __FILE__) require File.expand_path('../parser.rb', __FILE__)


def pack_int(i)
bytes = []; mask = 255

while bytes.length < 4
bytes.unshift (i & mask)
i = i >> 8
end

return bytes.pack('cccc')
end

server = TCPServer.new 5003 server = TCPServer.new 5003


loop do loop do
@@ -11,8 +22,8 @@ loop do
size = (client.readline).to_i size = (client.readline).to_i
p = Bitshift::Parser.new client.read(size) p = Bitshift::Parser.new client.read(size)
# Get the parsed result # Get the parsed result
symbols = p.parse.to_s
client.puts [symbols.length].pack('c')
symbols = p.parse
client.puts pack_int(symbols.length)
client.puts symbols client.puts symbols
ensure ensure
# Close the socket # Close the socket


+ 18
- 12
parsers/ruby/lib/parser.rb ファイルの表示

@@ -12,9 +12,9 @@ module Bitshift
parser = RubyParser.new parser = RubyParser.new
tree = parser.parse(@source) tree = parser.parse(@source)
offset = tree.line - 1 offset = tree.line - 1
processor = NodeVisitor.new offset
processor.process tree
return processor.symbols
processor = NodeVisitor.new offset, tree
processor.process(tree)
return processor.to_s
end end
end end


@@ -22,16 +22,16 @@ module Bitshift
attr_accessor :symbols attr_accessor :symbols
attr_accessor :offset attr_accessor :offset


def initialize(offset)
def initialize(offset, tree)
super() super()
@require_empty = false
@offset = offset


module_hash = Hash.new {|hash, key| hash[key] = Hash.new} module_hash = Hash.new {|hash, key| hash[key] = Hash.new}
class_hash = module_hash.clone class_hash = module_hash.clone
function_hash = Hash.new {|hash, key| hash[key] = { calls: [] } } function_hash = Hash.new {|hash, key| hash[key] = { calls: [] } }
var_hash = Hash.new {|hash, key| hash[key] = [] } var_hash = Hash.new {|hash, key| hash[key] = [] }


@require_empty = false
@offset = offset
@symbols = { @symbols = {
modules: module_hash, modules: module_hash,
classes: class_hash, classes: class_hash,
@@ -68,7 +68,7 @@ module Bitshift
end end


def process_module(exp) def process_module(exp)
pos = block_position exp
pos = block_position(exp)
exp.shift exp.shift
name = exp.shift name = exp.shift
symbols[:modules][name] = pos symbols[:modules][name] = pos
@@ -77,7 +77,7 @@ module Bitshift
end end


def process_class(exp) def process_class(exp)
pos = block_position exp
pos = block_position(exp)
exp.shift exp.shift
name = exp.shift name = exp.shift
symbols[:classes][name] = pos symbols[:classes][name] = pos
@@ -86,7 +86,7 @@ module Bitshift
end end


def process_defn(exp) def process_defn(exp)
pos = block_position exp
pos = block_position(exp)
exp.shift exp.shift
name = exp.shift name = exp.shift
symbols[:functions][name][:declaration] = pos symbols[:functions][name][:declaration] = pos
@@ -95,7 +95,7 @@ module Bitshift
end end


def process_call(exp) def process_call(exp)
pos = statement_position exp
pos = statement_position(exp)
exp.shift exp.shift
exp.shift exp.shift
name = exp.shift name = exp.shift
@@ -105,7 +105,7 @@ module Bitshift
end end


def process_iasgn(exp) def process_iasgn(exp)
pos = statement_position exp
pos = statement_position(exp)
exp.shift exp.shift
name = exp.shift name = exp.shift
symbols[:vars][name] << pos symbols[:vars][name] << pos
@@ -114,12 +114,18 @@ module Bitshift
end end


def process_lasgn(exp) def process_lasgn(exp)
pos = statement_position exp
pos = statement_position(exp)
exp.shift exp.shift
name = exp.shift name = exp.shift
symbols[:vars][name] << pos symbols[:vars][name] << pos
exp.each_sexp {|s| process(s)} exp.each_sexp {|s| process(s)}
return exp.clear return exp.clear
end end

def to_s
str = symbols.to_s
str = str.gsub(/:(\w*)=>/, '"\1":')
return str
end
end end
end end

読み込み中…
キャンセル
保存