author | Claus Gittinger <cg@exept.de> |
Mon, 14 May 2018 02:21:18 +0200 | |
changeset 1048 | 582b3a028cbc |
parent 1035 | fb88d1d65df6 |
permissions | -rw-r--r-- |
1035 | 1 |
"{ Encoding: utf8 }" |
2 |
||
41 | 3 |
"{ Package: 'stx:goodies/monticello' }" |
4 |
||
1035 | 5 |
"{ NameSpace: Smalltalk }" |
6 |
||
41 | 7 |
MCSnapshotReader subclass:#MCStReader |
8 |
instanceVariableNames:'' |
|
9 |
classVariableNames:'' |
|
10 |
poolDictionaries:'' |
|
684 | 11 |
category:'SCM-Monticello-Chunk Format' |
41 | 12 |
! |
13 |
||
796 | 14 |
!MCStReader class methodsFor:'documentation'! |
15 |
||
16 |
documentation |
|
17 |
" |
|
18 |
I read Category/Classes/Methodes/.... definitions from Monticello source.st file format. |
|
19 |
||
20 |
See also MCStWriter. |
|
21 |
||
22 |
Example: |
|
23 |
||
24 |
|source| |
|
25 |
source := String streamContents: [:aStream| |writer| |
|
26 |
writer := MCStWriter on: aStream. |
|
27 |
writer writeDefinitions: {True asClassDefinition. False asClassDefinition}. |
|
28 |
]. |
|
29 |
||
30 |
(MCStReader on: source readStream) definitions explore. |
|
31 |
" |
|
32 |
! ! |
|
41 | 33 |
|
34 |
!MCStReader class methodsFor:'as yet unclassified'! |
|
35 |
||
36 |
extension |
|
37 |
^ 'st' |
|
38 |
! ! |
|
39 |
||
40 |
!MCStReader methodsFor:'as yet unclassified'! |
|
41 |
||
42 |
addDefinitionsFromDoit: aString |
|
209 | 43 |
| parser | |
44 |
(parser := MCDoItParser forDoit: aString) ifNotNil: |
|
45 |
[ |
|
41 | 46 |
parser addDefinitionsTo: definitions] |
47 |
! |
|
48 |
||
49 |
categoryFromDoIt: aString |
|
50 |
| tokens | |
|
209 | 51 |
tokens := Scanner new scanTokens: aString. |
41 | 52 |
tokens size = 3 ifFalse: [self error: 'Unrecognized category definition']. |
53 |
^ tokens at: 3 |
|
54 |
! |
|
55 |
||
56 |
classDefinitionFrom: aPseudoClass |
|
209 | 57 |
| tokens traitCompositionString lastIndex classTraitCompositionString | |
58 |
tokens := Scanner new scanTokens: aPseudoClass definition. |
|
59 |
traitCompositionString := ((ReadStream on: aPseudoClass definition) |
|
60 |
match: 'uses:'; |
|
61 |
upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
62 |
classTraitCompositionString := ((ReadStream on: aPseudoClass metaClass definition asString) |
|
63 |
match: 'uses:'; |
|
64 |
upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
65 |
traitCompositionString isEmpty ifTrue: [traitCompositionString := '{}']. |
|
66 |
classTraitCompositionString isEmpty ifTrue: [classTraitCompositionString := '{}']. |
|
67 |
lastIndex := tokens size. |
|
41 | 68 |
^ MCClassDefinition |
69 |
name: (tokens at: 3) |
|
70 |
superclassName: (tokens at: 1) |
|
209 | 71 |
traitComposition: traitCompositionString |
72 |
classTraitComposition: classTraitCompositionString |
|
73 |
category: (tokens at: lastIndex) |
|
74 |
instVarNames: ((tokens at: lastIndex - 6) findTokens: ' ') |
|
75 |
classVarNames: ((tokens at: lastIndex - 4) findTokens: ' ') |
|
76 |
poolDictionaryNames: ((tokens at: lastIndex - 2) findTokens: ' ') |
|
41 | 77 |
classInstVarNames: (self classInstVarNamesFor: aPseudoClass) |
78 |
type: (self typeOfSubclass: (tokens at: 2)) |
|
79 |
comment: (self commentFor: aPseudoClass) |
|
80 |
commentStamp: (self commentStampFor: aPseudoClass) |
|
81 |
! |
|
82 |
||
83 |
classInstVarNamesFor: aPseudoClass |
|
84 |
| tokens | |
|
209 | 85 |
|
86 |
self flag: #traits. |
|
41 | 87 |
aPseudoClass metaClass hasDefinition ifFalse: [^ #()]. |
209 | 88 |
tokens := Scanner new scanTokens: aPseudoClass metaClass definition. |
89 |
"tokens size = 4 ifFalse: [self error: 'Unrecognized metaclass definition']." |
|
41 | 90 |
^ tokens last findTokens: ' ' |
91 |
! |
|
92 |
||
93 |
commentFor: aPseudoClass |
|
94 |
| comment | |
|
209 | 95 |
comment := aPseudoClass organization classComment. |
41 | 96 |
^ comment asString = '' |
97 |
ifTrue: [comment] |
|
98 |
ifFalse: [comment string] |
|
99 |
! |
|
100 |
||
101 |
commentStampFor: aPseudoClass |
|
102 |
| comment | |
|
209 | 103 |
comment := aPseudoClass organization classComment. |
41 | 104 |
^ [comment stamp] on: MessageNotUnderstood do: [nil] |
105 |
! |
|
106 |
||
107 |
methodDefinitionsFor: aPseudoClass |
|
880 | 108 |
^ aPseudoClass selectors collect: |
109 |
[:ea | |
|
110 |
MCMethodDefinition |
|
111 |
className: aPseudoClass name |
|
112 |
classIsMeta: aPseudoClass isMeta |
|
113 |
selector: ea |
|
114 |
category: (aPseudoClass organization categoryOfElement: ea) |
|
115 |
timeStamp: (aPseudoClass stampAt: ea) |
|
116 |
source: (aPseudoClass sourceCodeAt: ea) string] |
|
41 | 117 |
! |
118 |
||
119 |
systemOrganizationFromRecords: changeRecords |
|
120 |
| categories | |
|
209 | 121 |
categories := changeRecords |
41 | 122 |
select: [:ea | 'SystemOrganization*' match: ea string] |
123 |
thenCollect: [:ea | (self categoryFromDoIt: ea string)]. |
|
124 |
^ categories isEmpty ifFalse: [MCOrganizationDefinition categories: categories asArray] |
|
125 |
! |
|
126 |
||
127 |
typeOfSubclass: aSymbol |
|
128 |
#( |
|
129 |
(subclass: normal) |
|
130 |
(variableSubclass: variable) |
|
131 |
(variableByteSubclass: bytes) |
|
132 |
(variableWordSubclass: words) |
|
133 |
(weakSubclass: weak) |
|
134 |
) do: [:ea | ea first = aSymbol ifTrue: [^ ea second]]. |
|
135 |
self error: 'Unrecognized class definition' |
|
136 |
! ! |
|
137 |
||
138 |
!MCStReader methodsFor:'evaluating'! |
|
139 |
||
140 |
loadDefinitions |
|
519 | 141 |
|changeList| |
142 |
||
143 |
definitions := OrderedCollection new. |
|
144 |
||
145 |
Smalltalk isSmalltalkX ifTrue:[ |
|
146 |
changeList := ChangeSet fromStream:self readStream. |
|
147 |
changeList do:[:eachChange | |
|
148 |
|dfn| |
|
149 |
||
150 |
self addDefinitionFromChange:eachChange. |
|
151 |
]. |
|
152 |
] ifFalse:[ |
|
153 |
| filePackage | |
|
154 |
filePackage := |
|
155 |
FilePackage new |
|
156 |
fullName: 'ReadStream'; |
|
157 |
fileInFrom: self readStream. |
|
158 |
filePackage classes do: |
|
159 |
[:pseudoClass | |
|
160 |
pseudoClass hasDefinition |
|
161 |
ifTrue: [definitions add: |
|
162 |
(self classDefinitionFrom: pseudoClass)]. |
|
163 |
definitions addAll: (self methodDefinitionsFor: pseudoClass). |
|
164 |
definitions addAll: (self methodDefinitionsFor: pseudoClass metaClass)]. |
|
165 |
filePackage doIts do: |
|
166 |
[:ea | |
|
167 |
self addDefinitionsFromDoit: ea string]. |
|
168 |
] |
|
169 |
||
170 |
"Modified: / 25-11-2011 / 17:23:48 / cg" |
|
41 | 171 |
! |
172 |
||
173 |
readStream |
|
174 |
^ ('!!!! |
|
175 |
||
176 |
', stream contents) readStream |
|
177 |
! ! |
|
178 |
||
519 | 179 |
!MCStReader methodsFor:'stx change conversion'! |
180 |
||
181 |
addDefinitionFromChange:aChange |
|
182 |
aChange acceptChangeVisitor:self. |
|
183 |
||
184 |
"Created: / 25-11-2011 / 17:24:08 / cg" |
|
185 |
! |
|
186 |
||
960 | 187 |
visitClassCommentChange:aChange |
188 |
definitions add:(MCClassComment new |
|
189 |
className: aChange className |
|
190 |
comment: aChange comment |
|
191 |
source: aChange source string |
|
192 |
) |
|
193 |
! |
|
194 |
||
519 | 195 |
visitClassDefinitionChange:aChange |
196 |
| tokens traitCompositionString lastIndex classTraitCompositionString | |
|
197 |
||
198 |
tokens := Scanner new scanTokens: aChange source. |
|
199 |
||
200 |
"/ traitCompositionString := ((ReadStream on: aChange source) |
|
201 |
"/ match: 'uses:'; |
|
202 |
"/ upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
203 |
"/ classTraitCompositionString := ((ReadStream on: aPseudoClass metaClass definition asString) |
|
204 |
"/ match: 'uses:'; |
|
205 |
"/ upToAll: 'instanceVariableNames:') withBlanksTrimmed. |
|
206 |
traitCompositionString isEmptyOrNil ifTrue: [traitCompositionString := '{}']. |
|
207 |
classTraitCompositionString isEmptyOrNil ifTrue: [classTraitCompositionString := '{}']. |
|
208 |
lastIndex := tokens size. |
|
209 |
definitions add:( MCClassDefinition |
|
210 |
name: aChange className "/ (tokens at: 3) |
|
211 |
superclassName: aChange superClassName "/ (tokens at: 1) |
|
212 |
traitComposition: traitCompositionString |
|
213 |
classTraitComposition: classTraitCompositionString |
|
214 |
category: aChange category "/ (tokens at: lastIndex) |
|
1035 | 215 |
instVarNames: aChange instanceVariableNames "asCollectionOfWords" "/ ((tokens at: lastIndex - 6) findTokens: ' ') |
216 |
classVarNames: aChange classVariableNames "asCollectionOfWords" "/ ((tokens at: lastIndex - 4) findTokens: ' ') |
|
519 | 217 |
poolDictionaryNames: aChange poolDictionaries asCollectionOfWords "/ ((tokens at: lastIndex - 2) findTokens: ' ') |
1035 | 218 |
classInstVarNames: (aChange classInstanceVariableNames ? #()) "asCollectionOfWords" "/ (self classInstVarNamesFor: aPseudoClass) |
519 | 219 |
type: (self typeOfSubclass: (tokens at: 2)) |
220 |
comment: nil "/ (self commentFor: aPseudoClass) |
|
221 |
commentStamp: nil "/ (self commentStampFor: aPseudoClass) |
|
222 |
) |
|
223 |
||
224 |
"Created: / 25-11-2011 / 17:20:41 / cg" |
|
225 |
! |
|
226 |
||
520
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
227 |
visitClassInstVarDefinitionChange:aChange |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
228 |
"there must be already a definition change for that class" |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
229 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
230 |
|nonMetaName defn| |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
231 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
232 |
self assert:(aChange className endsWith:' class'). |
1035 | 233 |
nonMetaName := aChange className copyButLast:' class' size. |
520
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
234 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
235 |
defn := definitions detectLast:[:def | def isClassDefinition and:[def className = nonMetaName]]. |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
236 |
defn classInstVarNames: (aChange classInstVarNames). |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
237 |
|
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
238 |
"Created: / 25-11-2011 / 17:32:12 / cg" |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
239 |
! |
3eed472bc1ad
category of: #visitClassInstVarDefinitionChange:
Claus Gittinger <cg@exept.de>
parents:
519
diff
changeset
|
240 |
|
519 | 241 |
visitDoItChange:aChange |
242 |
self addDefinitionsFromDoit: aChange source |
|
243 |
||
244 |
"Created: / 25-11-2011 / 17:15:21 / cg" |
|
245 |
! |
|
246 |
||
247 |
visitMethodChange:aChange |
|
248 |
definitions add:(MCMethodDefinition |
|
249 |
className: aChange className |
|
250 |
classIsMeta: aChange isForMeta |
|
251 |
selector: aChange changeSelector |
|
252 |
category: aChange category "/ (aPseudoClass organization categoryOfElement: ea) |
|
253 |
timeStamp: nil "aChange timeStamp" "/ (aPseudoClass stampAt: ea) |
|
880 | 254 |
source: aChange source string"/ (aPseudoClass sourceCodeAt: ea) |
519 | 255 |
) |
256 |
||
257 |
"Created: / 25-11-2011 / 17:15:36 / cg" |
|
258 |
! ! |
|
259 |
||
41 | 260 |
!MCStReader class methodsFor:'documentation'! |
261 |
||
262 |
version |
|
1035 | 263 |
^ '$Header$' |
209 | 264 |
! |
265 |
||
266 |
version_CVS |
|
1035 | 267 |
^ '$Header$' |
209 | 268 |
! |
269 |
||
270 |
version_SVN |
|
1035 | 271 |
^ '$Id$' |
41 | 272 |
! ! |
796 | 273 |