premature start on the salama object files, just for reading the compiled code

This commit is contained in:
Torsten Ruger
2014-08-13 20:05:00 +03:00
parent 200228a33d
commit 90cbeddc0a
5 changed files with 107 additions and 0 deletions

53
lib/sof/members.rb Normal file
View File

@@ -0,0 +1,53 @@
module Sof
class Members
def initialize root
@root = root
@counter = 1
@objects = {}
add(root ,0 )
end
def add object , level
if( @objects.has_key?(object) )
occurence = @objects.get(object)
occurence.level = level if occurence.level > level
else
o = Occurence.new( object , @counter , level )
@objects[object] = o
c = @counter
@counter = @counter + 1
object.attributes.each do a
val = object.send a
add(val , level + 1)
end
end
end
def write
string = ""
output string , @root
end
def output string , object
occurence = @objects[object]
indent = " " * occurence.level
string += indent
if(object.respond_to? :to_sof)
string += object.to_sof + "\n"
else
string += "!" + object.class.name + "\n"
indent += " "
object.attributes.each do a
val = object.send a
output( string , val)
end
end
end
def self.write object
members = Members.new object
members.write
end
end
end