|
|
|
@ -15,7 +15,9 @@ class SourceMapping(Context): |
|
|
|
|
@staticmethod |
|
|
|
|
def _compute_line(source_code, start, length): |
|
|
|
|
""" |
|
|
|
|
Compute line(s) number from a start/end offset |
|
|
|
|
Compute line(s) numbers and starting/ending columns |
|
|
|
|
from a start/end offset. All results start from 0. |
|
|
|
|
|
|
|
|
|
Not done in an efficient way |
|
|
|
|
""" |
|
|
|
|
total_length = len(source_code) |
|
|
|
@ -23,14 +25,29 @@ class SourceMapping(Context): |
|
|
|
|
counter = 0 |
|
|
|
|
i = 0 |
|
|
|
|
lines = [] |
|
|
|
|
starting_column = None |
|
|
|
|
ending_column = None |
|
|
|
|
while counter < total_length: |
|
|
|
|
counter += len(source_code[i]) |
|
|
|
|
i = i+1 |
|
|
|
|
# Determine the length of the line, and advance the line number |
|
|
|
|
lineLength = len(source_code[i]) |
|
|
|
|
i = i + 1 |
|
|
|
|
|
|
|
|
|
# Determine our column numbers. |
|
|
|
|
if starting_column is None and counter + lineLength > start: |
|
|
|
|
starting_column = (start - counter) + 1 |
|
|
|
|
if starting_column is not None and ending_column is None and counter + lineLength > start + length: |
|
|
|
|
ending_column = ((start + length) - counter) + 1 |
|
|
|
|
|
|
|
|
|
# Advance the current position counter, and determine line numbers. |
|
|
|
|
counter += lineLength |
|
|
|
|
if counter > start: |
|
|
|
|
lines.append(i) |
|
|
|
|
if counter > start+length: |
|
|
|
|
|
|
|
|
|
# If our advanced position for the next line is out of range, stop. |
|
|
|
|
if counter > start + length: |
|
|
|
|
break |
|
|
|
|
return lines |
|
|
|
|
|
|
|
|
|
return (lines, starting_column, ending_column) |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def _convert_source_mapping(offset, slither): |
|
|
|
@ -55,12 +72,13 @@ class SourceMapping(Context): |
|
|
|
|
return {'start':s, 'length':l} |
|
|
|
|
filename = sourceUnits[f] |
|
|
|
|
|
|
|
|
|
lines = [] |
|
|
|
|
|
|
|
|
|
if filename in slither.source_code: |
|
|
|
|
lines = SourceMapping._compute_line(slither.source_code[filename], s, l) |
|
|
|
|
(lines, starting_column, ending_column) = SourceMapping._compute_line(slither.source_code[filename], s, l) |
|
|
|
|
else: |
|
|
|
|
(lines, starting_column, ending_column) = ([], None, None) |
|
|
|
|
|
|
|
|
|
return {'start':s, 'length':l, 'filename': filename, 'lines' : lines } |
|
|
|
|
return {'start': s, 'length': l, 'filename': filename, 'lines': lines, |
|
|
|
|
'starting_column': starting_column, 'ending_column': ending_column} |
|
|
|
|
|
|
|
|
|
def set_offset(self, offset, slither): |
|
|
|
|
if isinstance(offset, dict): |
|
|
|
|