1 # $Id: leaf.rb,v 1.11 2011/12/09 09:05:42 machan Exp $
2
3 require 'tmdoc/tmstd'
4 require 'tmdoc/model/object/logical/path'
5 require 'tmdoc/model/object/logical/location'
6 require 'tmdoc/model/object/logical/abstraction'
7 require 'tmdoc/constant'
8
9
10 module TmDoc
11
12 module Model::Object::Logical
13
14 module Leaf
15
16 class Constant < Abstraction::Property
17 attr_reader :value
18
19
20 def initialize(location, above_path, name, value)
21 ASSERT.kind_of location, Location
22 ASSERT.kind_of above_path, Path
23 ASSERT.kind_of name, String
24 ASSERT.kind_of value, String
25
26 super(location, above_path, name)
27
28 @value = value
29 end
30
31
32 def to_s
33 str = super('constant', self.name + ' = ' + self.value)
34
35 ASSERT.kind_of str, String
36 end
37 end
38
39 class SetOfConstant < Abstraction::SetOfProperty
40 LSM_ELEMENT_CLASS = Constant
41 end
42
43
44
45 class Alias < Abstraction::Property
46 attr_reader :orig_name
47
48
49 def initialize(
50 location,
51 above_path,
52 name,
53 uniq_num,
54 max_uniq_num,
55 does_attach_to_instance,
56 orig_name
57 )
58 ASSERT.kind_of location, Location
59 ASSERT.kind_of above_path, Path
60 ASSERT.kind_of name, String
61 ASSERT.kind_of uniq_num, Integer
62 ASSERT.kind_of max_uniq_num, Integer
63 ASSERT.boolean does_attach_to_instance
64 ASSERT.kind_of orig_name, String
65
66 super(
67 location, above_path, name, 0, uniq_num, max_uniq_num,
68 does_attach_to_instance
69 )
70
71 @orig_name = orig_name
72 end
73
74
75 def to_s
76 str = super('alias', self.name + ' <-- ' + self.orig_name)
77
78 ASSERT.kind_of str, String
79 end
80 end
81
82
83
84 class Attribute < Abstraction::Property
85 attr_reader :accessor
86
87
88 def initialize(
89 location,
90 above_path,
91 name,
92 uniq_num,
93 max_uniq_num,
94 does_attach_to_instance,
95 seq_num,
96 accessor
97 )
98 ASSERT.kind_of location, Location
99 ASSERT.kind_of above_path, Path
100 ASSERT.kind_of name, String
101 ASSERT.kind_of uniq_num, Integer
102 ASSERT.kind_of max_uniq_num, Integer
103 ASSERT.boolean does_attach_to_instance
104 ASSERT.kind_of seq_num, Integer
105 ASSERT.kind_of accessor, Symbol
106
107 super(
108 location, above_path, name, seq_num, uniq_num, max_uniq_num,
109 does_attach_to_instance
110 )
111
112 @accessor = accessor
113 end
114
115
116 def to_s
117 str = super(
118 'attribute',
119 format("%s[#%d]/[%s]", self.name, self.seq_num, self.accessor)
120 )
121
122 ASSERT.kind_of str, String
123 end
124 end
125
126
127
128 class Method < Abstraction::Property
129 attr_reader :args, :is_module_func
130
131 alias module_func? is_module_func
132
133
134 def initialize(
135 location,
136 above_path,
137 name,
138 uniq_num,
139 max_uniq_num,
140 does_attach_to_instance,
141 args,
142 is_module_func
143 )
144 ASSERT.kind_of location, Location
145 ASSERT.kind_of above_path, Path
146 ASSERT.kind_of name, String
147 ASSERT.kind_of uniq_num, Integer
148 ASSERT.kind_of max_uniq_num, Integer
149 ASSERT.boolean does_attach_to_instance
150 ASSERT.kind_of args, LSM::SeqOfString
151 ASSERT.boolean is_module_func
152
153 super(
154 location, above_path, name, 0, uniq_num, max_uniq_num,
155 does_attach_to_instance
156 )
157
158 @args = args
159 @is_module_func = is_module_func
160 end
161
162
163 def to_s
164 str = super(
165 'method',
166
167 [
168 self.name,
169 unless self.args.empty?
170 format "(%s)", self.args.join(', ')
171 else
172 ''
173 end,
174 if self.module_func?
175 '[F]'
176 else
177 ''
178 end
179 ].join
180 )
181
182 ASSERT.kind_of str, String
183 end
184 end
185
186 end # TmDoc::Model::Object::Logical::Leaf
187
188 end # TmDoc::Model::Object::Logical
189
190 end # TmDoc