latest AST used

pull/5370/head
aniket-engg 5 years ago committed by Aniket
parent 8e64709b42
commit 97eead5bfd
  1. 18
      apps/remix-ide/src/app/editor/contextView.js
  2. 54
      apps/remix-ide/src/app/editor/contextualListener.js

@ -125,7 +125,7 @@ class ContextView {
_render (node, nodeAtCursorPosition) {
if (!node) return yo`<div></div>`
let references = this.contextualListener.referencesOf(node)
const type = (node.attributes && node.attributes.type) ? node.attributes.type : node.name
const type = node && node.typeDescriptions.typeString ? node.typeDescriptions.typeString : node.name
references = `${references ? references.length : '0'} reference(s)`
let ref = 0
@ -155,7 +155,7 @@ class ContextView {
}
const showGasEstimation = () => {
if (node.name === 'FunctionDefinition') {
if (node.nodeType === 'FunctionDefinition') {
const result = this.contextualListener.gasEstimation(node)
const executionCost = ' Execution cost: ' + result.executionCost + ' gas'
const codeDepositCost = 'Code deposit cost: ' + result.codeDepositCost + ' gas'
@ -172,7 +172,7 @@ class ContextView {
return yo`
<div class=${css.line}>${showGasEstimation()}
<div title=${type} class=${css.type}>${type}</div>
<div title=${node.attributes.name} class=${css.name}>${node.attributes.name}</div>
<div title=${node.name} class=${css.name}>${node.name}</div>
<i class="fas fa-share ${css.jump}" aria-hidden="true" onclick=${jumpTo}></i>
<span class=${css.referencesnb}>${references}</span>
<i data-action='previous' class="fas fa-chevron-up ${css.jump}" aria-hidden="true" onclick=${jump}></i>
@ -183,12 +183,12 @@ class ContextView {
}
function isDefinition (node) {
return node.name === 'ContractDefinition' ||
node.name === 'FunctionDefinition' ||
node.name === 'ModifierDefinition' ||
node.name === 'VariableDeclaration' ||
node.name === 'StructDefinition' ||
node.name === 'EventDefinition'
return node.nodeType === 'ContractDefinition' ||
node.nodeType === 'FunctionDefinition' ||
node.nodeType === 'ModifierDefinition' ||
node.nodeType === 'VariableDeclaration' ||
node.nodeType === 'StructDefinition' ||
node.nodeType === 'EventDefinition'
}
module.exports = ContextView

@ -65,8 +65,8 @@ class ContextualListener extends Plugin {
}
declarationOf (node) {
if (node.attributes && node.attributes.referencedDeclaration) {
return this._index['FlatReferences'][node.attributes.referencedDeclaration]
if (node && node.referencedDeclaration) {
return this._index['FlatReferences'][node.referencedDeclaration]
}
return null
}
@ -99,17 +99,17 @@ class ContextualListener extends Plugin {
if (compilationResult && compilationResult.sources) {
const callback = {}
callback['*'] = (node) => {
if (node && node.attributes && node.attributes.referencedDeclaration) {
if (!this._index['Declarations'][node.attributes.referencedDeclaration]) {
this._index['Declarations'][node.attributes.referencedDeclaration] = []
if (node && node.referencedDeclaration) {
if (!this._index['Declarations'][node.referencedDeclaration]) {
this._index['Declarations'][node.referencedDeclaration] = []
}
this._index['Declarations'][node.attributes.referencedDeclaration].push(node)
this._index['Declarations'][node.referencedDeclaration].push(node)
}
this._index['FlatReferences'][node.id] = node
return true
}
for (const s in compilationResult.sources) {
this.astWalker.walk(compilationResult.sources[s].legacyAST, callback)
this.astWalker.walk(compilationResult.sources[s].ast, callback)
}
}
}
@ -136,7 +136,7 @@ class ContextualListener extends Plugin {
background-color: var(--info);
}
`
if (node.children && node.children.length) {
if (node.nodes && node.nodes.length) {
// If node has children, highlight the entire line. if not, just highlight the current source position of the node.
lineColumn = {
start: {
@ -167,9 +167,9 @@ class ContextualListener extends Plugin {
}
}
}
if (node.attributes && node.attributes.referencedDeclaration) {
highlights(node.attributes.referencedDeclaration)
const current = this._index['FlatReferences'][node.attributes.referencedDeclaration]
if (node && node.referencedDeclaration) {
highlights(node.referencedDeclaration)
const current = this._index['FlatReferences'][node.referencedDeclaration]
this._highlight(current, compilationResult)
} else {
highlights(node.id)
@ -190,10 +190,10 @@ class ContextualListener extends Plugin {
gasEstimation (node) {
this._loadContractInfos(node)
let executionCost, codeDepositCost
if (node.name === 'FunctionDefinition') {
const visibility = node.attributes.visibility
if (!node.attributes.isConstructor) {
const fnName = node.attributes.name
if (node.nodeType === 'FunctionDefinition') {
const visibility = node.visibility
if (!node.kind === 'constructor') {
const fnName = node.name
const fn = fnName + this._getInputParams(node)
if (visibility === 'public' || visibility === 'external') {
executionCost = this.estimationObj.external[fn]
@ -212,9 +212,9 @@ class ContextualListener extends Plugin {
_loadContractInfos (node) {
for (const i in this.nodes) {
if (this.nodes[i].id === node.attributes.scope) {
if (this.nodes[i].id === node.scope) {
const contract = this.nodes[i]
this.contract = this.results.data.contracts[this.results.source.target][contract.attributes.name]
this.contract = this.results.data.contracts[this.results.source.target][contract.name]
this.estimationObj = this.contract.evm.gasEstimates
this.creationCost = this.estimationObj.creation.totalCost
this.codeDepositCost = this.estimationObj.creation.codeDepositCost
@ -224,18 +224,18 @@ class ContextualListener extends Plugin {
_getInputParams (node) {
const params = []
let target
for (const i in node.children) {
if (node.children[i].name === 'ParameterList') {
target = node.children[i]
break
}
}
let target = node.parameters
// for (const i in node.children) {
// if (node.children[i].name === 'ParameterList') {
// target = node.children[i]
// break
// }
// }
if (target) {
const children = target.children
const children = target.parameters
for (const j in children) {
if (children[j].name === 'VariableDeclaration') {
params.push(children[j].attributes.type)
if (children[j].nodeType === 'VariableDeclaration') {
params.push(children[j].typeDescriptions.typeString)
}
}
}

Loading…
Cancel
Save