Improve source_mapping parsing for old solcs

pull/239/head
Josselin 6 years ago
parent 9341166e9a
commit d981e9a0a7
  1. 11
      slither/core/source_mapping/source_mapping.py
  2. 8
      slither/solc_parsing/slitherSolc.py

@ -125,16 +125,7 @@ class SourceMapping(Context):
@property
def source_mapping_str(self):
# def relative_path(path):
# # Remove absolute path for printing
# # Truffle returns absolutePath
# splited_path = path.split(os.sep)
# if 'contracts' in splited_path:
# idx = splited_path.index('contracts')
# return os.sep.join(splited_path[idx-1:])
# return path
lines = self.source_mapping['lines']
lines = self.source_mapping.get('lines', None)
if not lines:
lines = ''
elif len(lines) == 1:

@ -148,6 +148,14 @@ class SlitherSolc(Slither):
sourceUnit = re.findall('[0-9]*:[0-9]*:([0-9]*)', data['src'])
if len(sourceUnit) == 1:
sourceUnit = int(sourceUnit[0])
if sourceUnit == -1:
# if source unit is not found
# We can still deduce it, by assigning to the last source_code added
# This works only for crytic compile.
# which used --combined-json ast, rather than --ast-json
# As a result -1 is not used as index
if not self.crytic_compile is None:
sourceUnit = len(self.source_code)
self._source_units[sourceUnit] = name
if os.path.isfile(name) and not name in self.source_code:

Loading…
Cancel
Save