1 # $Id: store.rb,v 1.4 2011/12/13 21:37:14 machan Exp $
2
3 require 'stringio'
4
5 require 'tmdoc/tmstd'
6 require 'tmdoc/constant'
7 require 'tmdoc/model/abstraction'
8 require 'tmdoc/model/object/physical'
9 require 'tmdoc/model/object/logical'
10
11
12 module TmDoc
13
14 module Model::Object
15
16 class Store < Model::Abstraction::Store
17 attr_reader :files,
18 :a_toplevel_module,
19 :an_unknown_module,
20 :a_builtin_module,
21 :an_object_class,
22 :map_of_path_to_module,
23 :all_modules,
24 :map_of_above_module_to_below_modules,
25 :map_of_extender_module_to_extendee_modules,
26 :map_of_extendee_module_to_extender_modules,
27 :map_of_includer_module_to_includee_modules,
28 :map_of_includee_module_to_includer_modules,
29 :map_of_superclass_to_subclasses
30
31
32 def initialize(
33 files,
34 a_toplevel_module,
35 an_unknown_module,
36 a_builtin_module,
37 an_object_class
38 )
39 ASSERT.kind_of files, MOP::Files
40 ASSERT.kind_of a_toplevel_module, MOLN::ToplevelModule
41 ASSERT.kind_of an_unknown_module, MOLN::UnknownModule
42 ASSERT.kind_of a_builtin_module, MOLN::BuiltinModule
43 ASSERT.kind_of an_object_class, MOLN::Object
44
45 @files = files
46 @a_toplevel_module = a_toplevel_module
47 @an_unknown_module = an_unknown_module
48 @a_builtin_module = a_builtin_module
49 @an_object_class = an_object_class
50
51 @map_of_path_to_module = nil
52
53 @all_modules =
54 @map_of_above_module_to_below_modules =
55 @map_of_extender_module_to_extendee_modules =
56 @map_of_extendee_module_to_extender_modules =
57 @map_of_includer_module_to_includee_modules =
58 @map_of_includee_module_to_includer_modules =
59 @map_of_superclass_to_subclasses = nil
60 end
61
62
63 def map_of_path_to_module!(map_of_path_to_module)
64 ASSERT.kind_of map_of_path_to_module, MOLA::MapOfPathToModule
65
66 @map_of_path_to_module = map_of_path_to_module
67
68 nil
69 end
70
71
72 def make_indexes!
73 @all_modules =
74 MOLA::SeqOfGenericModule.new([@a_toplevel_module]) +
75 @a_toplevel_module.descendant_modules
76
77 relationship_between_subjects =
78 MOLN::Relationship.make_it_between_subjects(
79 @all_modules, @map_of_path_to_module
80 )
81 ASSERT.kind_of(
82 relationship_between_subjects,
83 MOLN::Relationship::RelationshipBetweenSubjects
84 )
85 @map_of_above_module_to_below_modules =
86 relationship_between_subjects.map_of_above_to_belows
87 @map_of_extender_module_to_extendee_modules =
88 relationship_between_subjects.map_of_extender_to_extendees
89 @map_of_extendee_module_to_extender_modules =
90 relationship_between_subjects.map_of_extendee_to_extenders
91 @map_of_includer_module_to_includee_modules =
92 relationship_between_subjects.map_of_includer_to_includees
93 @map_of_includee_module_to_includer_modules =
94 relationship_between_subjects.map_of_includee_to_includers
95 @map_of_superclass_to_subclasses =
96 relationship_between_subjects.map_of_super_to_subs
97
98 MOP::Relationship.update_files(@all_modules) do
99 |file, map_of_line_num_to_logical_subjects|
100 ASSERT.kind_of file, MOP::File
101 ASSERT.kind_of(
102 map_of_line_num_to_logical_subjects,
103 MOP::MapOfLineNumToLogicalSubjects
104 )
105
106 file.map_of_line_num_to_logical_subjects!(
107 map_of_line_num_to_logical_subjects
108 )
109 end
110
111 nil
112 end
113
114
115 def print
116 LOG::Debug.log '======== Object Model ========'
117 LOG::Debug.log '---- Overview ----'
118 str_io = StringIO.new
119 self.a_toplevel_module.print_tree(str_io)
120 LOG::Debug.log str_io.string
121 LOG::Debug.log
122
123 LOG::Debug.log '---- Map of Path to Module ----'
124 for path in self.map_of_path_to_module.paths.sort
125 a_module = self.map_of_path_to_module.at path
126 LOG::Debug.log "%-30s ==> %s", path.to_s, a_module.to_s
127 end
128 LOG::Debug.log
129
130 LOG::Debug.log '---- Relationships ----'
131
132 LOG::Debug.log "\t---- Map of Above to Belows ----"
133 self.map_of_above_module_to_below_modules.print 1
134 LOG::Debug.log
135
136 LOG::Debug.log "\t---- Map of Extender to Extendees ----"
137 self.map_of_extender_module_to_extendee_modules.print 1
138 LOG::Debug.log
139
140 LOG::Debug.log "\t---- Map of Extendee to Extenders ----"
141 self.map_of_extendee_module_to_extender_modules.print 1
142 LOG::Debug.log
143
144 LOG::Debug.log "\t---- Map of Includer to Includees ----"
145 self.map_of_includer_module_to_includee_modules.print 1
146 LOG::Debug.log
147
148 LOG::Debug.log "\t---- Map of Includee to Includers ----"
149 self.map_of_includee_module_to_includer_modules.print 1
150 LOG::Debug.log
151
152 LOG::Debug.log "\t---- Map of Superclass to Subclasses ----"
153 self.map_of_superclass_to_subclasses.print 1
154 LOG::Debug.log
155
156 LOG::Debug.log '---- Modules and Classes ----'
157 self.a_toplevel_module.print 1
158 LOG::Debug.log
159 for a_module in self.all_modules
160 a_module.print 1
161 LOG::Debug.log
162 end
163 LOG::Debug.log
164
165 LOG::Debug.log '---- Sources ----'
166 for file in self.files.sort
167 file.print 1
168 LOG::Debug.log
169 end
170 LOG::Debug.log
171
172 nil
173 end
174 end
175
176 end # TmDoc::Model::Object
177
178 end # TmDoc