Skip to content

Commit

Permalink
adding start/stop position calculation for the c++ preprocessed source
Browse files Browse the repository at this point in the history
  • Loading branch information
j-brant committed May 7, 2019
1 parent 5bd049e commit d8c77d5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/SmaCC_CPP_Parser/CPPPreprocessedFile.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
8 changes: 8 additions & 0 deletions src/SmaCC_CPP_Parser/CPPPreprocessor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8c77d5

Please sign in to comment.