[debug] discard source map step if file equal -1

fix https://github.com/ethereum/remix-ide/issues/2648
pull/7/head
yann300 5 years ago committed by Aniket
parent 09c955ddff
commit 8699877d72
  1. 21
      remix-lib/src/sourceMappingDecoder.js
  2. 68
      remix-lib/test/resources/sourceMapping.js
  3. 10
      remix-lib/test/sourceMappingDecoder.js

@ -188,8 +188,23 @@ function nodesAtPosition (astNodeType, position, ast) {
return found
}
/**
* starts with the given @arg index and move backward until it can find all the values for start, length, file, jump
* if `file === -1` then the value of the sourcemap should be taken from the previous step,
* because some steps are internal subroutine for the compiler and doesn't link to any high level code.
*
* Solidity source maps format is
* - start:length:file:jump
* - jump can be 'i', 'o' or '-' (jump 'in' or 'out' of a function)
* - if no value is specified ( e.g "5:2" - no mention of 'file' and 'jump' ), actual values are the one of the step before
* - if the file (3rd value) has -1, the source maps should be discarded
*
* @param Int index - index in the bytecode to decode source mapping from
* @param Array mapping - source maps returned by the compiler. e.g 121:3741:0:-:0;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;121:3741:0;;;;;;;
* @return Object { start, length, file, jump }
*/
function atIndex (index, mapping) {
const ret = {}
let ret = {}
const map = mapping.split(';')
if (index >= map.length) {
index = map.length - 1
@ -200,6 +215,10 @@ function atIndex (index, mapping) {
continue
}
current = current.split(':')
if (current[2] === '-1') { // if the current step has -1 for the file attribute, we discard it
if (ret.file === undefined) ret = {} // if the file was not already set by a previous (meaning it is -1), we discard the whole step
continue
}
if (ret.start === undefined && current[0] && current[0] !== '-1' && current[0].length) {
ret.start = parseInt(current[0])
}

@ -17,6 +17,74 @@ sourceRuntimeMapping.source = `contract test {
}
}`
sourceRuntimeMapping.ballotSourceMap = '33:1970:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;33:1970:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;712:577;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;712:577:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;1641:360;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;495:164;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;495:164:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;1349:286;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;1349:286:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;712:577;759:20;782:6;:18;789:10;782:18;;;;;;;;;;;;;;;759:41;;835:6;:12;;;;;;;;;;;;831:25;;;849:7;;;831:25;865:115;903:1;872:33;;:6;:10;879:2;872:10;;;;;;;;;;;;;;;:19;;;;;;;;;;;;:33;;;;:70;;;;;932:10;909:33;;:6;:10;916:2;909:10;;;;;;;;;;;;;;;:19;;;;;;;;;;;;:33;;;;872:70;865:115;;;961:6;:10;968:2;961:10;;;;;;;;;;;;;;;:19;;;;;;;;;;;;956:24;;865:115;;;1000:10;994:16;;:2;:16;;;990:29;;;1012:7;;;990:29;1043:4;1028:6;:12;;;:19;;;;;;;;;;;;;;;;;;1075:2;1057:6;:15;;;:20;;;;;;;;;;;;;;;;;;1087:24;1114:6;:10;1121:2;1114:10;;;;;;;;;;;;;;;1087:37;;1138:10;:16;;;;;;;;;;;;1134:148;;;1208:6;:13;;;1168:9;1178:10;:15;;;;;;;;;;;;1168:26;;;;;;;;;;;;;;;;;:36;;;:53;;;;;;;;;;;1134:148;;;1269:6;:13;;;1248:10;:17;;;:34;;;;;;;;;;;1134:148;712:577;;;;:::o;1641:360::-;1689:22;1723:24;1750:1;1723:28;;1766:10;1779:1;1766:14;;1761:234;1789:9;:16;;;;1782:4;:23;;;1761:234;;;1859:16;1831:9;1841:4;1831:15;;;;;;;;;;;;;;;;;:25;;;:44;1827:168;;;1914:9;1924:4;1914:15;;;;;;;;;;;;;;;;;:25;;;1895:44;;1976:4;1957:23;;1827:168;1807:6;;;;;;;1761:234;;;;1641:360;;:::o;495:164::-;572:11;;;;;;;;;;;558:25;;:10;:25;;;;:50;;;;587:6;:15;594:7;587:15;;;;;;;;;;;;;;;:21;;;;;;;;;;;;558:50;554:63;;;610:7;;554:63;651:1;626:6;:15;633:7;626:15;;;;;;;;;;;;;;;:22;;:26;;;;495:164;;:::o;1349:286::-;1398:20;1421:6;:18;1428:10;1421:18;;;;;;;;;;;;;;;1398:41;;1453:6;:12;;;;;;;;;;;;:46;;;;1483:9;:16;;;;1469:10;:30;;;;1453:46;1449:59;;;1501:7;;;1449:59;1532:4;1517:6;:12;;;:19;;;;;;;;;;;;;;;;;;1560:10;1546:6;:11;;;:24;;;;;;;;;;;;;;;;;;1615:6;:13;;;1580:9;1590:10;1580:21;;;;;;;;;;;;;;;;;:31;;;:48;;;;;;;;;;;1349:286;;;:::o'
sourceRuntimeMapping.ballotSource = `
pragma solidity >=0.4.22 <0.6.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
uint voteCount;
}
address chairperson;
mapping(address => Voter) voters;
Proposal[] proposals;
function () external {
}
/// Give $(toVoter) the right to vote on this ballot.
/// May only be called by $(chairperson).
/// @notice something 2
function giveRightToVote(address toVoter) public {
if (msg.sender != chairperson || voters[toVoter].voted) return;
voters[toVoter].weight = 1;
}
/// Delegate your vote to the voter $(to).
function delegate(address to) public {
Voter storage sender = voters[msg.sender]; // assigns reference
if (sender.voted) return;
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
to = voters[to].delegate;
if (to == msg.sender) return;
sender.voted = true;
sender.delegate = to;
Voter storage delegateTo = voters[to];
if (delegateTo.voted)
proposals[delegateTo.vote].voteCount += sender.weight;
else
delegateTo.weight += sender.weight;
}
/// Give a single vote to proposal $(toProposal).
function vote(uint8 toProposal) public {
Voter storage sender = voters[msg.sender];
if (sender.voted || toProposal >= proposals.length) return;
sender.voted = true;
sender.vote = toProposal;
proposals[toProposal].voteCount += sender.weight;
}
function winningProposal() public view returns (uint8 _winningProposal) {
uint256 winningVoteCount = 0;
for (uint8 prop = 0; prop < proposals.length; prop++)
if (proposals[prop].voteCount > winningVoteCount) {
winningVoteCount = proposals[prop].voteCount;
_winningProposal = prop;
}
}
}
`
if (typeof (module) !== 'undefined' && typeof (module.exports) !== 'undefined') {
module.exports = sourceRuntimeMapping
}

@ -22,7 +22,7 @@ tape('SourceMappingDecoder', function (t) {
const testSourceMapping = {}
t.test('sourceMappingDecoder', function (st) {
st.plan(28)
st.plan(32)
const sourceMappingDecoder = new SourceMappingDecoder()
console.log('test decompressAll')
let result = sourceMappingDecoder.decompressAll(sourceMapping.mapping)
@ -73,6 +73,14 @@ tape('SourceMappingDecoder', function (t) {
st.equal(result.file, 4)
st.equal(result.jump, '-')
testSourceMapping[85] = result
// ballot - function deletegate(address)
const delegateSrcMap = sourceMappingDecoder.atIndex(64, sourceMapping.ballotSourceMap)
console.log(delegateSrcMap)
st.equal(delegateSrcMap.start, 712)
st.equal(delegateSrcMap.length, 577)
st.equal(delegateSrcMap.file, 0)
st.equal(delegateSrcMap.jump, '-')
})
t.test('sourceMappingLineColumnConverter', function (st) {

Loading…
Cancel
Save