|
|
@ -11,6 +11,26 @@ class SourceMapping(Context): |
|
|
|
def source_mapping(self): |
|
|
|
def source_mapping(self): |
|
|
|
return self._source_mapping |
|
|
|
return self._source_mapping |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
|
|
def _compute_line(source_code, start, end): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Compute line(s) number from a start/end offset |
|
|
|
|
|
|
|
Not done in an efficient way |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
total_length = len(source_code) |
|
|
|
|
|
|
|
source_code = source_code.split('\n') |
|
|
|
|
|
|
|
counter = 0 |
|
|
|
|
|
|
|
i = 0 |
|
|
|
|
|
|
|
lines = [] |
|
|
|
|
|
|
|
while counter < total_length: |
|
|
|
|
|
|
|
counter += len(source_code[i]) +1 |
|
|
|
|
|
|
|
i = i+1 |
|
|
|
|
|
|
|
if counter > start: |
|
|
|
|
|
|
|
lines.append(i) |
|
|
|
|
|
|
|
if counter > end: |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
return lines |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
|
def _convert_source_mapping(offset, slither): |
|
|
|
def _convert_source_mapping(offset, slither): |
|
|
|
''' |
|
|
|
''' |
|
|
@ -33,8 +53,26 @@ class SourceMapping(Context): |
|
|
|
if f not in sourceUnits: |
|
|
|
if f not in sourceUnits: |
|
|
|
return {'start':s, 'length':l} |
|
|
|
return {'start':s, 'length':l} |
|
|
|
filename = sourceUnits[f] |
|
|
|
filename = sourceUnits[f] |
|
|
|
return {'start':s, 'length':l, 'filename': filename} |
|
|
|
|
|
|
|
|
|
|
|
lines = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if filename in slither.source_code: |
|
|
|
|
|
|
|
lines = SourceMapping._compute_line(slither.source_code[filename], s, l) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {'start':s, 'length':l, 'filename': filename, 'lines' : lines } |
|
|
|
|
|
|
|
|
|
|
|
def set_offset(self, offset, slither): |
|
|
|
def set_offset(self, offset, slither): |
|
|
|
self._source_mapping = self._convert_source_mapping(offset, slither) |
|
|
|
self._source_mapping = self._convert_source_mapping(offset, slither) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
|
|
def source_mapping_str(self): |
|
|
|
|
|
|
|
lines = self.source_mapping['lines'] |
|
|
|
|
|
|
|
if not lines: |
|
|
|
|
|
|
|
lines = '[source code not found]' |
|
|
|
|
|
|
|
elif len(lines) == 1: |
|
|
|
|
|
|
|
lines = 'line {}'.format(lines[0]) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
lines = 'lines: {}'.format(','.join(lines)) |
|
|
|
|
|
|
|
return '{} {}'.format(self.source_mapping['filename'], lines) |
|
|
|
|
|
|
|
|
|
|
|