diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-14 21:48:59 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-14 21:52:00 +0800 |
commit | 83b46cbf71abd897b434ff510035171297a51255 (patch) | |
tree | dd2c80a54e6a9bd2f2058afa587f4ad2c0a6b6ce /packages/sol-tracing-utils | |
parent | 4689309857126669563dc9ea0e912ec9cec74157 (diff) | |
download | dexon-0x-contracts-83b46cbf71abd897b434ff510035171297a51255.tar.gz dexon-0x-contracts-83b46cbf71abd897b434ff510035171297a51255.tar.zst dexon-0x-contracts-83b46cbf71abd897b434ff510035171297a51255.zip |
Rename mappins to have a direct naming scheme instead of a reverse one
Diffstat (limited to 'packages/sol-tracing-utils')
-rw-r--r-- | packages/sol-tracing-utils/src/ast_visitor.ts | 12 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/collect_coverage_entries.ts | 6 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/index.ts | 2 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/source_maps.ts | 24 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/types.ts | 2 | ||||
-rw-r--r-- | packages/sol-tracing-utils/test/source_maps_test.ts | 6 |
6 files changed, 26 insertions, 26 deletions
diff --git a/packages/sol-tracing-utils/src/ast_visitor.ts b/packages/sol-tracing-utils/src/ast_visitor.ts index fe71c974b..1ac9cd1de 100644 --- a/packages/sol-tracing-utils/src/ast_visitor.ts +++ b/packages/sol-tracing-utils/src/ast_visitor.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; import * as Parser from 'solidity-parser-antlr'; -import { BranchMap, FnMap, LocationByOffset, SingleFileSourceRange, StatementMap } from './types'; +import { BranchMap, FnMap, OffsetToLocation, SingleFileSourceRange, StatementMap } from './types'; export interface CoverageEntriesDescription { fnMap: FnMap; @@ -22,13 +22,13 @@ export class ASTVisitor { private readonly _branchMap: BranchMap = {}; private readonly _modifiersStatementIds: number[] = []; private readonly _statementMap: StatementMap = {}; - private readonly _locationByOffset: LocationByOffset; + private readonly _offsetToLocation: OffsetToLocation; private readonly _ignoreRangesBeginningAt: number[]; // keep track of contract/function ranges that are to be ignored // so we can also ignore any children nodes within the contract/function private readonly _ignoreRangesWithin: Array<[number, number]> = []; - constructor(locationByOffset: LocationByOffset, ignoreRangesBeginningAt: number[] = []) { - this._locationByOffset = locationByOffset; + constructor(offsetToLocation: OffsetToLocation, ignoreRangesBeginningAt: number[] = []) { + this._offsetToLocation = offsetToLocation; this._ignoreRangesBeginningAt = ignoreRangesBeginningAt; } public getCollectedCoverageEntries(): CoverageEntriesDescription { @@ -169,8 +169,8 @@ export class ASTVisitor { } private _getExpressionRange(ast: Parser.ASTNode): SingleFileSourceRange { const astRange = ast.range as [number, number]; - const start = this._locationByOffset[astRange[0]]; - const end = this._locationByOffset[astRange[1] + 1]; + const start = this._offsetToLocation[astRange[0]]; + const end = this._offsetToLocation[astRange[1] + 1]; const range = { start, end, diff --git a/packages/sol-tracing-utils/src/collect_coverage_entries.ts b/packages/sol-tracing-utils/src/collect_coverage_entries.ts index bdbcd613e..3ca794f8e 100644 --- a/packages/sol-tracing-utils/src/collect_coverage_entries.ts +++ b/packages/sol-tracing-utils/src/collect_coverage_entries.ts @@ -3,7 +3,7 @@ import * as _ from 'lodash'; import * as parser from 'solidity-parser-antlr'; import { ASTVisitor, CoverageEntriesDescription } from './ast_visitor'; -import { getLocationByOffset } from './source_maps'; +import { getOffsetToLocation } from './source_maps'; const IGNORE_RE = /\/\*\s*solcov\s+ignore\s+next\s*\*\/\s*/gm; @@ -14,9 +14,9 @@ export const collectCoverageEntries = (contractSource: string) => { const sourceHash = ethUtil.sha3(contractSource).toString('hex'); if (_.isUndefined(coverageEntriesBySourceHash[sourceHash]) && !_.isUndefined(contractSource)) { const ast = parser.parse(contractSource, { range: true }); - const locationByOffset = getLocationByOffset(contractSource); + const offsetToLocation = getOffsetToLocation(contractSource); const ignoreRangesBegingingAt = gatherRangesToIgnore(contractSource); - const visitor = new ASTVisitor(locationByOffset, ignoreRangesBegingingAt); + const visitor = new ASTVisitor(offsetToLocation, ignoreRangesBegingingAt); parser.visit(ast, visitor); coverageEntriesBySourceHash[sourceHash] = visitor.getCollectedCoverageEntries(); } diff --git a/packages/sol-tracing-utils/src/index.ts b/packages/sol-tracing-utils/src/index.ts index 413e5305e..8e3136046 100644 --- a/packages/sol-tracing-utils/src/index.ts +++ b/packages/sol-tracing-utils/src/index.ts @@ -22,7 +22,7 @@ export { BranchMap, EvmCallStackEntry, FnMap, - LocationByOffset, + OffsetToLocation, StatementMap, TraceInfoBase, TraceInfoExistingContract, diff --git a/packages/sol-tracing-utils/src/source_maps.ts b/packages/sol-tracing-utils/src/source_maps.ts index ae004c2ec..0a2d3c88a 100644 --- a/packages/sol-tracing-utils/src/source_maps.ts +++ b/packages/sol-tracing-utils/src/source_maps.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; import { getPcToInstructionIndexMapping } from './instructions'; -import { LocationByOffset, SourceRange } from './types'; +import { OffsetToLocation, SourceRange } from './types'; const RADIX = 10; @@ -15,19 +15,19 @@ export interface SourceLocation { * Receives a string with newlines and returns a map of byte offset to LineColumn * @param str A string to process */ -export function getLocationByOffset(str: string): LocationByOffset { - const locationByOffset: LocationByOffset = { 0: { line: 1, column: 0 } }; +export function getOffsetToLocation(str: string): OffsetToLocation { + const offsetToLocation: OffsetToLocation = { 0: { line: 1, column: 0 } }; let currentOffset = 0; for (const char of str.split('')) { - const location = locationByOffset[currentOffset]; + const location = offsetToLocation[currentOffset]; const isNewline = char === '\n'; - locationByOffset[currentOffset + 1] = { + offsetToLocation[currentOffset + 1] = { line: location.line + (isNewline ? 1 : 0), column: isNewline ? 0 : location.column + 1, }; currentOffset++; } - return locationByOffset; + return offsetToLocation; } /** @@ -46,9 +46,9 @@ export function parseSourceMap( ): { [programCounter: number]: SourceRange } { const bytecode = Uint8Array.from(Buffer.from(bytecodeHex, 'hex')); const pcToInstructionIndex: { [programCounter: number]: number } = getPcToInstructionIndexMapping(bytecode); - const locationByOffsetByFileIndex: { [fileIndex: number]: LocationByOffset } = {}; + const fileIndexToOffsetToLocation: { [fileIndex: number]: OffsetToLocation } = {}; _.map(sourceCodes, (sourceCode: string, fileIndex: number) => { - locationByOffsetByFileIndex[fileIndex] = _.isUndefined(sourceCode) ? {} : getLocationByOffset(sourceCode); + fileIndexToOffsetToLocation[fileIndex] = _.isUndefined(sourceCode) ? {} : getOffsetToLocation(sourceCode); }); const entries = srcMap.split(';'); let lastParsedEntry: SourceLocation = {} as any; @@ -69,12 +69,12 @@ export function parseSourceMap( length, fileIndex, }; - if (parsedEntry.fileIndex !== -1 && !_.isUndefined(locationByOffsetByFileIndex[parsedEntry.fileIndex])) { - const locationByOffset = locationByOffsetByFileIndex[parsedEntry.fileIndex]; + if (parsedEntry.fileIndex !== -1 && !_.isUndefined(fileIndexToOffsetToLocation[parsedEntry.fileIndex])) { + const offsetToLocation = fileIndexToOffsetToLocation[parsedEntry.fileIndex]; const sourceRange = { location: { - start: locationByOffset[parsedEntry.offset], - end: locationByOffset[parsedEntry.offset + parsedEntry.length], + start: offsetToLocation[parsedEntry.offset], + end: offsetToLocation[parsedEntry.offset + parsedEntry.length], }, fileName: sources[parsedEntry.fileIndex], }; diff --git a/packages/sol-tracing-utils/src/types.ts b/packages/sol-tracing-utils/src/types.ts index 2b305c16e..27568ae03 100644 --- a/packages/sol-tracing-utils/src/types.ts +++ b/packages/sol-tracing-utils/src/types.ts @@ -16,7 +16,7 @@ export interface SingleFileSourceRange { end: LineColumn; } -export interface LocationByOffset { +export interface OffsetToLocation { [offset: number]: LineColumn; } diff --git a/packages/sol-tracing-utils/test/source_maps_test.ts b/packages/sol-tracing-utils/test/source_maps_test.ts index 5820bedd7..330a6a3e1 100644 --- a/packages/sol-tracing-utils/test/source_maps_test.ts +++ b/packages/sol-tracing-utils/test/source_maps_test.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import 'mocha'; import * as path from 'path'; -import { getLocationByOffset, parseSourceMap } from '../src/source_maps'; +import { getOffsetToLocation, parseSourceMap } from '../src/source_maps'; const expect = chai.expect; @@ -15,7 +15,7 @@ const simplestContract = fs.readFileSync(simplestContractFileName).toString(); describe('source maps', () => { describe('#getLocationByOffset', () => { it('correctly computes location by offset', () => { - const locationByOffset = getLocationByOffset(simplestContract); + const offsetToLocation = getOffsetToLocation(simplestContract); const expectedLocationByOffset = { '0': { line: 1, column: 0 }, '1': { line: 1, column: 1 }, @@ -41,7 +41,7 @@ describe('source maps', () => { '21': { line: 2, column: 1 }, '22': { line: 3, column: 0 }, }; - expect(locationByOffset).to.be.deep.equal(expectedLocationByOffset); + expect(offsetToLocation).to.be.deep.equal(expectedLocationByOffset); }); }); describe('#parseSourceMap', () => { |