Skip to content

Commit

Permalink
dc: fix copies in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Sep 26, 2023
1 parent e40934e commit b924f1d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/DomainCode-Diff/DCChawatheScriptGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ DCChawatheScriptGenerator >> findPosition: aTree dest: destInorder in: aMapping
{ #category : #'as yet unclassified' }
DCChawatheScriptGenerator >> generateFrom: src to: dest in: aMapping do: aBlock [

| actions srcInOrder destInOrder |
actions := DCEditScript new.

| srcInOrder destInOrder inserted |
srcInOrder := Set new.
destInOrder := Set new.
inserted := Set new.

dest allMorphsBreadthFirstDo: [:x | | y z w |
w := nil.
Expand All @@ -65,7 +64,8 @@ DCChawatheScriptGenerator >> generateFrom: src to: dest in: aMapping do: aBlock
ifFalse: [ | k |
k := self findPosition: x dest: destInOrder in: aMapping.
aBlock value: #insert value: {x. z. k}.
w := x copy.
w := x shallowCopyBlock.
inserted add: w.
z addMorph: w asElementNumber: k.
aMapping addMappingFrom: w to: x]
ifTrue: [
Expand All @@ -86,7 +86,7 @@ DCChawatheScriptGenerator >> generateFrom: src to: dest in: aMapping do: aBlock
destInOrder add: x.
self alignChildrenSrc: w dest: x srcInOrder: srcInOrder destInOrder: destInOrder in: aMapping do: aBlock].

src allMorphsDo: [:w | (aMapping isSrcMapped: w) ifFalse: [aBlock value: #delete value: {w}]]
src allMorphsDo: [:w | ((aMapping isSrcMapped: w) not and: [(inserted includes: w) not]) ifTrue: [aBlock value: #delete value: {w}]]
]

{ #category : #'as yet unclassified' }
Expand Down
1 change: 0 additions & 1 deletion packages/DomainCode-Diff/DCMappingStore.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Class {
{ #category : #'as yet unclassified' }
DCMappingStore >> addMappingFrom: src to: dest [

SBToggledCode comment: '' active: 0 do: {[src contents = 'abc' ifTrue: [self halt]]}.
self assert: src rootBlock ~= dest rootBlock.
srcToDest at: src put: dest.
destToSrc at: dest put: src
Expand Down
4 changes: 2 additions & 2 deletions packages/DomainCode-Diff/DCMatchTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ DCMatchTest >> testSimple [

| src dest mappings |
Transcript clear.
src := DCBlock parseBlock: '' language: SBJavascript.
dest := DCBlock parseBlock: 'abc' language: SBJavascript.
src := DCBlock parseBlock: 'ab + 22' language: SBJavascript.
dest := DCBlock parseBlock: 'abc + 2' language: SBJavascript.
mappings := DCMappingStore new.
DCGreedySubtreeMatcher new matchFrom: src to: dest in: mappings.
DCGreedyBottomUpMatcher new matchFrom: src to: dest in: mappings.
Expand Down
8 changes: 7 additions & 1 deletion packages/DomainCode-Diff/DCMatcher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ DCMatcher >> matchFrom: src to: dest [
| mappings |
mappings := DCMappingStore new.
DCGreedySubtreeMatcher new matchFrom: src to: dest in: mappings.
DCGreedyBottomUpMatcher new matchFrom: src to: dest in: mappings
DCGreedyBottomUpMatcher new matchFrom: src to: dest in: mappings.
Array streamContents: [:stream |
DCChawatheScriptGenerator new
generateFrom: src
to: dest
in: mappings
do: [:op :args | stream nextPut: {op. args}]]
]
11 changes: 11 additions & 0 deletions packages/DomainCode-Parser/DCBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,17 @@ DCBlock >> rootBlock [
^ self ownerSatisfying: [:o | o isTSBlock and: [o type = self language rootRuleName]]
]

{ #category : #'as yet unclassified' }
DCBlock >> shallowCopyBlock [

^ DCBlock new
type: type;
language: language;
range: range;
field: field;
highlight: highlight
]

{ #category : #'as yet unclassified' }
DCBlock >> slot [

Expand Down
10 changes: 10 additions & 0 deletions packages/DomainCode-Parser/DCText.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ DCText >> rootBlock [
^ self owner rootBlock
]

{ #category : #'as yet unclassified' }
DCText >> shallowCopyBlock [

^ DCText new
range: range;
contents: contents;
highlight: highlight;
field: field
]

{ #category : #'as yet unclassified' }
DCText >> shownColor [

Expand Down

0 comments on commit b924f1d

Please sign in to comment.