61
61
62
62
import com .oracle .graal .python .pegparser .scope .Scope ;
63
63
import com .oracle .graal .python .pegparser .scope .ScopeEnvironment ;
64
+ import com .oracle .graal .python .pegparser .tokenizer .SourceRange ;
64
65
65
66
public final class CompilationUnit {
66
67
final String name ;
@@ -87,11 +88,11 @@ public final class CompilationUnit {
87
88
Block currentBlock = startBlock ;
88
89
int maxStackSize = 0 ;
89
90
90
- final int startOffset ;
91
- int currentOffset ;
91
+ SourceRange startLocation ;
92
+ SourceRange currentLocation ;
92
93
93
94
CompilationUnit (CompilationScope scopeType , Scope scope , String name , CompilationUnit parent , int scopeDepth , int argCount , int positionalOnlyArgCount , int kwOnlyArgCount , boolean takesVarArgs ,
94
- boolean takesVarKeywordArgs , int startOffset ) {
95
+ boolean takesVarKeywordArgs , SourceRange startLocation ) {
95
96
this .scopeType = scopeType ;
96
97
this .scope = scope ;
97
98
this .name = name ;
@@ -100,8 +101,8 @@ public final class CompilationUnit {
100
101
this .kwOnlyArgCount = kwOnlyArgCount ;
101
102
this .takesVarArgs = takesVarArgs ;
102
103
this .takesVarKeywordArgs = takesVarKeywordArgs ;
103
- this .startOffset = startOffset ;
104
- currentOffset = startOffset ;
104
+ this .startLocation = startLocation ;
105
+ currentLocation = startLocation ;
105
106
106
107
if (scopeType == Class ) {
107
108
privateName = name ;
@@ -168,8 +169,8 @@ private void addImplicitReturn() {
168
169
b = b .next ;
169
170
}
170
171
if (!b .isReturn ()) {
171
- b .instr .add (new Instruction (OpCodes .LOAD_NONE , 0 , null , null , 0 ));
172
- b .instr .add (new Instruction (OpCodes .RETURN_VALUE , 0 , null , null , 0 ));
172
+ b .instr .add (new Instruction (OpCodes .LOAD_NONE , 0 , null , null , currentLocation ));
173
+ b .instr .add (new Instruction (OpCodes .RETURN_VALUE , 0 , null , null , currentLocation ));
173
174
}
174
175
}
175
176
@@ -196,7 +197,7 @@ public CodeUnit assemble(int flags) {
196
197
197
198
Block b = startBlock ;
198
199
HashMap <Block , List <Block >> handlerBlocks = new HashMap <>();
199
- int lastSrcOffset = startOffset ;
200
+ int lastSrcOffset = startLocation . startOffset ;
200
201
while (b != null ) {
201
202
b .startBci = buf .size ();
202
203
BlockInfo .AbstractExceptionHandler handler = b .findExceptionHandler ();
@@ -223,8 +224,8 @@ public CodeUnit assemble(int flags) {
223
224
}
224
225
for (Instruction i : b .instr ) {
225
226
emitBytecode (i , buf );
226
- insertSrcOffsetTable (i .srcOffset , lastSrcOffset , srcOffsets );
227
- lastSrcOffset = i .srcOffset ;
227
+ insertSrcOffsetTable (i .location . startOffset , lastSrcOffset , srcOffsets );
228
+ lastSrcOffset = i .location . startOffset ;
228
229
}
229
230
b .endBci = buf .size ();
230
231
b = b .next ;
@@ -256,7 +257,7 @@ public CodeUnit assemble(int flags) {
256
257
orderedKeys (constants , new Object [0 ]),
257
258
orderedLong (primitiveConstants ),
258
259
exceptionHandlerRanges ,
259
- startOffset );
260
+ startLocation . startOffset );
260
261
}
261
262
262
263
private void addExceptionRange (Collection <short []> finishedExceptionHandlerRanges , int start , int end , int handler , int stackLevel ) {
@@ -343,7 +344,7 @@ private void calculateJumpInstructionArguments() {
343
344
if (target != null ) {
344
345
int targetPos = blockLocationMap .get (target );
345
346
int distance = Math .abs (bci + instr .extensions () * 2 - targetPos );
346
- Instruction newInstr = new Instruction (instr .opcode , distance , instr .followingArgs , instr .target , instr .srcOffset );
347
+ Instruction newInstr = new Instruction (instr .opcode , distance , instr .followingArgs , instr .target , instr .location );
347
348
if (newInstr .extendedLength () != instr .extendedLength ()) {
348
349
repeat = true ;
349
350
}
0 commit comments