diff --git a/src/SmaCC_CPP_Parser/CPPPreprocessedFile.class.st b/src/SmaCC_CPP_Parser/CPPPreprocessedFile.class.st index 5531aead..00d10f9e 100644 --- a/src/SmaCC_CPP_Parser/CPPPreprocessedFile.class.st +++ b/src/SmaCC_CPP_Parser/CPPPreprocessedFile.class.st @@ -80,3 +80,38 @@ CPPPreprocessedFile >> sourceFor: aFilename [ CPPPreprocessedFile >> sourceString [ ^ source asString ] + +{ #category : #accessing } +CPPPreprocessedFile >> startPositionFor: anInteger [ + | current lastGoodIndex | + lastGoodIndex := 1. + current := 1. + source + intervalsDo: [ :each | + (anInteger between: current and: current + each size - 1) + ifTrue: [ ^ each id = 1 + ifTrue: [ each start + (anInteger - current) ] + ifFalse: [ lastGoodIndex ] ]. + current := current + each size. + each id = 1 + ifTrue: [ lastGoodIndex := each stop + 1 ] ]. + ^ lastGoodIndex +] + +{ #category : #accessing } +CPPPreprocessedFile >> stopPositionFor: anInteger [ + | current haltOnNext | + haltOnNext := false. + current := 1. + source + intervalsDo: [ :each | + haltOnNext + ifTrue: [ each id = 1 + ifTrue: [ ^ each start - 1 ] ] + ifFalse: [ (anInteger between: current and: current + each size - 1) + ifTrue: [ each id = 1 + ifTrue: [ ^ each start + (anInteger - current) ] + ifFalse: [ haltOnNext := true ] ] ]. + current := current + each size ]. + ^ self originalSource size +] diff --git a/src/SmaCC_CPP_Parser/CPPPreprocessor.class.st b/src/SmaCC_CPP_Parser/CPPPreprocessor.class.st index 23161dfe..4079a892 100644 --- a/src/SmaCC_CPP_Parser/CPPPreprocessor.class.st +++ b/src/SmaCC_CPP_Parser/CPPPreprocessor.class.st @@ -199,6 +199,14 @@ CPPPreprocessor >> macroNamed: aString [ ^ macros at: aString ifAbsent: [ ] ] +{ #category : #copying } +CPPPreprocessor >> postCopy [ + super postCopy. + preprocessedFile := CPPPreprocessedFile new. + macros := macros copy. + stack := OrderedCollection new +] + { #category : #accessing } CPPPreprocessor >> preprocessedFile [ ^ preprocessedFile