fix folded array bug by using object_id, fix ref bug but only counting first

This commit is contained in:
Torsten Ruger 2014-08-21 15:21:20 +03:00
parent 9608e5f626
commit 0677069fc0
3 changed files with 16 additions and 10 deletions

View File

@ -14,15 +14,20 @@ module Sof
def add object , level
return if is_value?(object)
if( occurence = @objects[object] )
if( occurence = @objects[object.object_id] )
#puts "reset level #{level} at #{occurence.level}"
occurence.level = level if occurence.level > level
occurence.referenced = @counter
@counter = @counter + 1
if occurence.level > level
occurence.level = level
end
unless occurence.referenced
#puts "referencing #{@counter} , at level #{level}/#{occurence.level} "
occurence.referenced = @counter
@counter = @counter + 1
end
return
end
o = Occurence.new( object , level )
@objects[object] = o
@objects[object.object_id] = o
attributes = attributes_for(object)
attributes.each do |a|
val = get_value( object , a)

View File

@ -16,12 +16,13 @@ module Sof
end
class SimpleNode < Node
def initialize data
super(nil)
def initialize data , ref = nil
super(ref)
@data = data
end
attr_reader :data
def out io , level
super
io.write(data)
end
end

View File

@ -16,10 +16,10 @@ module Sof
if is_value?(object)
return SimpleNode.new(object.to_sof())
end
occurence = @members.objects[object]
occurence = @members.objects[object.object_id]
raise "no object #{object}" unless occurence
if(level > occurence.level )
#puts "level #{level} at #{occurence.level}"
#puts "ref #{occurence.referenced} level #{level} at #{occurence.level}"
return SimpleNode.new("*#{occurence.referenced}")
end
ref = occurence.referenced
@ -32,7 +32,7 @@ module Sof
def object_sof_node( object , level , ref)
if( object.is_a? Class )
return SimpleNode.new( object.name )
return SimpleNode.new( object.name , ref )
end
head = object.class.name + "("
atts = {}