Class: Astrapi::ClassDiagramPrinter

Inherits:
Object
  • Object
show all
Includes:
Indent
Defined in:
lib/class_diagram_printer.rb

Constant Summary collapse

DECL_FOR_INSTRINSICS =
{
  :IDENT   => "IDENT[label=\"{IDENT|+kind\n+val\n+pos\n\}\"]",
  :FLOAT   => "FLOAT[label=\"{FLOAT|+kind\n+val\n+pos\n\}\"]",
  :INTEGER => "INTEGER[label=\"{INTEGER|+kind\n+val\n+pos\n\}\"]",
  :STRING  => "STRING[label=\"{STRING|+kind\n+val\n+pos\n\}\"]",
  :FRAC    => "FRAC[label=\"{FRAC|+kind\n+val\n+pos\n\}\"]",
  :NIL     => "NIL[label=\"{NIL|+kind\n+val\n+pos\n\}\"]"
}

Constants included from Indent

Indent::INDENT

Instance Method Summary collapse

Methods included from Indent

#dedent, #indent, #say

Instance Method Details

#is_instrinsic(type) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/class_diagram_printer.rb', line 73

def is_instrinsic type
  if type.respond_to? :type
    str=type.type.name.to_s
    return str==str.upcase
  else
    str=type.name.to_s
    return str==str.upcase
  end
end


20
21
22
# File 'lib/class_diagram_printer.rb', line 20

def print ast
  ast.accept(self)
end

#visitKlass(klass, args = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/class_diagram_printer.rb', line 51

def visitKlass klass,args=nil
  indent "visitKlass"
  code = Code.new
  klass.attrs.each do |attr|
    case type=attr.type
    when ArrayOf
      sink=type.type.name.to_s
      head="label=\"*\""
    when Type
      sink=type.name.to_s
      head="label=1"
      code << DECL_FOR_INSTRINSICS[sink.to_sym] if is_instrinsic(type)
    end
    code << "#{klass.name} -> #{sink}[#{head},arrowtail=diamond]"
  end
  if klass.inheritance
    code << "#{klass.inheritance} -> #{klass.name}"
  end
  dedent
  code
end

#visitModule(modul, args = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/class_diagram_printer.rb', line 24

def visitModule modul,args=nil
  indent "visitModule"

  decl=Code.new # declarations of nodes
  modul.classes.collect do |k|
    attrs_str=k.attrs.collect{|attr| "+ #{attr.name}\\n"}
    decl << "#{k.name}[label = \"{#{k.name}|#{attrs_str.join()}|...}\"]"
  end
  cnx=Code.new  #connexions
  modul.classes.each{|k| cnx << k.accept(self)}
  #................................................................
  code=Code.new
  code << "digraph hierarchy {"
  code << " size=\"5,5\""
  #code << " splines=ortho"
  code << " node[shape=record,style=filled,fillcolor=gray95]"
  code << " edge[dir=back, arrowtail=empty]"
  code.newline
  code.indent=2
  code << decl
  code << cnx
  code.indent=0
  code << "}"
  dedent
  return code
end