|
|
@ -29,14 +29,14 @@ export default class CodeParserAntlrService { |
|
|
|
parserThresholdSampleAmount = 3 |
|
|
|
parserThresholdSampleAmount = 3 |
|
|
|
cache: { |
|
|
|
cache: { |
|
|
|
[name: string]: { |
|
|
|
[name: string]: { |
|
|
|
text: string |
|
|
|
text: string, |
|
|
|
ast: antlr.ParseResult | null |
|
|
|
ast: antlr.ParseResult | null, |
|
|
|
duration?: number |
|
|
|
duration?: number, |
|
|
|
parsingEnabled?: boolean |
|
|
|
parsingEnabled?: boolean, |
|
|
|
blocks?: BlockDefinition[] |
|
|
|
blocks?: BlockDefinition[], |
|
|
|
blockDurations?: number[] |
|
|
|
blockDurations?: number[] |
|
|
|
} |
|
|
|
} |
|
|
|
} = {} |
|
|
|
} = {}; |
|
|
|
constructor(plugin: CodeParser) { |
|
|
|
constructor(plugin: CodeParser) { |
|
|
|
this.plugin = plugin |
|
|
|
this.plugin = plugin |
|
|
|
this.createWorker() |
|
|
|
this.createWorker() |
|
|
@ -60,15 +60,14 @@ export default class CodeParserAntlrService { |
|
|
|
ast: ev.data.ast, |
|
|
|
ast: ev.data.ast, |
|
|
|
duration: ev.data.duration, |
|
|
|
duration: ev.data.duration, |
|
|
|
blocks: ev.data.blocks, |
|
|
|
blocks: ev.data.blocks, |
|
|
|
blockDurations: self.cache[ev.data.file].blockDurations |
|
|
|
blockDurations: self.cache[ev.data.file].blockDurations? [...self.cache[ev.data.file].blockDurations.slice(-self.parserThresholdSampleAmount), ev.data.blockDuration]: [ev.data.blockDuration] |
|
|
|
? [...self.cache[ev.data.file].blockDurations.slice(-self.parserThresholdSampleAmount), ev.data.blockDuration] |
|
|
|
|
|
|
|
: [ev.data.blockDuration], |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
self.setFileParsingState(ev.data.file) |
|
|
|
self.setFileParsingState(ev.data.file) |
|
|
|
} |
|
|
|
} |
|
|
|
break |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setFileParsingState(file: string) { |
|
|
|
setFileParsingState(file: string) { |
|
|
@ -105,8 +104,9 @@ export default class CodeParserAntlrService { |
|
|
|
text, |
|
|
|
text, |
|
|
|
timestamp: this.parserStartTime, |
|
|
|
timestamp: this.parserStartTime, |
|
|
|
file, |
|
|
|
file, |
|
|
|
parsingEnabled: (this.cache[file] && this.cache[file].parsingEnabled) || true, |
|
|
|
parsingEnabled: (this.cache[file] && this.cache[file].parsingEnabled) || true |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async parseSolidity(text: string) { |
|
|
|
async parseSolidity(text: string) { |
|
|
@ -124,13 +124,13 @@ export default class CodeParserAntlrService { |
|
|
|
try { |
|
|
|
try { |
|
|
|
this.plugin.currentFile = await this.plugin.call('fileManager', 'file') |
|
|
|
this.plugin.currentFile = await this.plugin.call('fileManager', 'file') |
|
|
|
if (this.plugin.currentFile && this.plugin.currentFile.endsWith('.sol')) { |
|
|
|
if (this.plugin.currentFile && this.plugin.currentFile.endsWith('.sol')) { |
|
|
|
const fileContent = text || (await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile)) |
|
|
|
const fileContent = text || await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile) |
|
|
|
if (!this.cache[this.plugin.currentFile]) { |
|
|
|
if (!this.cache[this.plugin.currentFile]) { |
|
|
|
this.cache[this.plugin.currentFile] = { |
|
|
|
this.cache[this.plugin.currentFile] = { |
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
ast: null, |
|
|
|
ast: null, |
|
|
|
parsingEnabled: true, |
|
|
|
parsingEnabled: true, |
|
|
|
blockDurations: [], |
|
|
|
blockDurations: [] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].text !== fileContent) { |
|
|
|
if (this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].text !== fileContent) { |
|
|
@ -154,8 +154,8 @@ export default class CodeParserAntlrService { |
|
|
|
async listAstNodes() { |
|
|
|
async listAstNodes() { |
|
|
|
this.plugin.currentFile = await this.plugin.call('fileManager', 'file') |
|
|
|
this.plugin.currentFile = await this.plugin.call('fileManager', 'file') |
|
|
|
if (!this.cache[this.plugin.currentFile]) return |
|
|
|
if (!this.cache[this.plugin.currentFile]) return |
|
|
|
const nodes: AstNode[] = [] |
|
|
|
const nodes: AstNode[] = []; |
|
|
|
;(SolidityParser as any).visit(this.cache[this.plugin.currentFile].ast, { |
|
|
|
(SolidityParser as any).visit(this.cache[this.plugin.currentFile].ast, { |
|
|
|
StateVariableDeclaration: (node: antlr.StateVariableDeclaration) => { |
|
|
|
StateVariableDeclaration: (node: antlr.StateVariableDeclaration) => { |
|
|
|
if (node.variables) { |
|
|
|
if (node.variables) { |
|
|
|
for (const variable of node.variables) { |
|
|
|
for (const variable of node.variables) { |
|
|
@ -195,11 +195,13 @@ export default class CodeParserAntlrService { |
|
|
|
}, |
|
|
|
}, |
|
|
|
StructDefinition: function (node: antlr.StructDefinition) { |
|
|
|
StructDefinition: function (node: antlr.StructDefinition) { |
|
|
|
nodes.push({ ...node, nodeType: node.type, id: null, src: null }) |
|
|
|
nodes.push({ ...node, nodeType: node.type, id: null, src: null }) |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
return nodes |
|
|
|
return nodes |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param ast
|
|
|
|
* @param ast
|
|
|
@ -217,13 +219,13 @@ export default class CodeParserAntlrService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
;(SolidityParser as any).visit(ast, { |
|
|
|
(SolidityParser as any).visit(ast, { |
|
|
|
MemberAccess: function (node: antlr.MemberAccess) { |
|
|
|
MemberAccess: function (node: antlr.MemberAccess) { |
|
|
|
checkLastNode(node) |
|
|
|
checkLastNode(node) |
|
|
|
}, |
|
|
|
}, |
|
|
|
Identifier: function (node: antlr.Identifier) { |
|
|
|
Identifier: function (node: antlr.Identifier) { |
|
|
|
checkLastNode(node) |
|
|
|
checkLastNode(node) |
|
|
|
}, |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
if (lastNode && lastNode.expression) { |
|
|
|
if (lastNode && lastNode.expression) { |
|
|
|
return lastNode.expression |
|
|
|
return lastNode.expression |
|
|
@ -241,15 +243,12 @@ export default class CodeParserAntlrService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.plugin.currentFile && this.plugin.currentFile.endsWith('.sol')) { |
|
|
|
if (this.plugin.currentFile && this.plugin.currentFile.endsWith('.sol')) { |
|
|
|
const fileContent = text || (await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile)) |
|
|
|
const fileContent = text || await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile) |
|
|
|
try { |
|
|
|
try { |
|
|
|
const startTime = Date.now() |
|
|
|
const startTime = Date.now() |
|
|
|
const blocks = (SolidityParser as any).parseBlock(fileContent, { loc: true, range: true, tolerant: true }) |
|
|
|
const blocks = (SolidityParser as any).parseBlock(fileContent, { loc: true, range: true, tolerant: true }) |
|
|
|
if(this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].blockDurations){ |
|
|
|
if(this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].blockDurations){ |
|
|
|
this.cache[this.plugin.currentFile].blockDurations = [ |
|
|
|
this.cache[this.plugin.currentFile].blockDurations = [...this.cache[this.plugin.currentFile].blockDurations.slice(-this.parserThresholdSampleAmount), Date.now() - startTime] |
|
|
|
...this.cache[this.plugin.currentFile].blockDurations.slice(-this.parserThresholdSampleAmount), |
|
|
|
|
|
|
|
Date.now() - startTime, |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
this.setFileParsingState(this.plugin.currentFile) |
|
|
|
this.setFileParsingState(this.plugin.currentFile) |
|
|
|
} |
|
|
|
} |
|
|
|
if (blocks) this.cache[this.plugin.currentFile].blocks = blocks |
|
|
|
if (blocks) this.cache[this.plugin.currentFile].blocks = blocks |
|
|
|