From 11dd6c80981a5eb2242d25394abd88bb18496d18 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 2 Sep 2020 18:25:29 +0530 Subject: [PATCH] legacyAST removal --- .../tabs/debugger/debuggerUI/VmDebugger.js | 2 +- .../src/solidity-decoder/astHelper.js | 14 ++++---- .../src/solidity-decoder/decodeInfo.js | 20 ++++++------ .../src/solidity-decoder/internalCallTree.js | 32 +++++++++---------- .../src/solidity-decoder/solidityProxy.js | 2 +- .../src/solidity-decoder/types/util.js | 6 ++-- libs/remix-debug/src/source/astWalker.js | 12 +++---- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/debugger/debuggerUI/VmDebugger.js b/apps/remix-ide/src/app/tabs/debugger/debuggerUI/VmDebugger.js index 5936d1c720..3cd34cdba9 100644 --- a/apps/remix-ide/src/app/tabs/debugger/debuggerUI/VmDebugger.js +++ b/apps/remix-ide/src/app/tabs/debugger/debuggerUI/VmDebugger.js @@ -41,7 +41,7 @@ function VmDebugger (vmDebuggerLogic) { if (stack === null) return let functions = [] for (let func of stack) { - functions.push(func.functionDefinition.attributes.name + '(' + func.inputs.join(', ') + ')') + functions.push(func.functionDefinition.name + '(' + func.inputs.join(', ') + ')') } this.functionPanel.update(functions) }) diff --git a/libs/remix-debug/src/solidity-decoder/astHelper.js b/libs/remix-debug/src/solidity-decoder/astHelper.js index ab9b030879..e281acbf32 100644 --- a/libs/remix-debug/src/solidity-decoder/astHelper.js +++ b/libs/remix-debug/src/solidity-decoder/astHelper.js @@ -15,10 +15,10 @@ function extractContractDefinitions (sourcesList) { } const walker = new AstWalker() for (let k in sourcesList) { - walker.walk(sourcesList[k].legacyAST, { 'ContractDefinition': (node) => { + walker.walk(sourcesList[k].ast, { 'ContractDefinition': (node) => { ret.contractsById[node.id] = node ret.sourcesByContract[node.id] = k - ret.contractsByName[k + ':' + node.attributes.name] = node + ret.contractsByName[k + ':' + node.name] = node return false }}) } @@ -33,7 +33,7 @@ function extractContractDefinitions (sourcesList) { * @return {Array} - array of base contracts in derived to base order as AST nodes. */ function getLinearizedBaseContracts (id, contractsById) { - return contractsById[id].attributes.linearizedBaseContracts.map(function (id) { return contractsById[id] }) + return contractsById[id].linearizedBaseContracts.map(function (id) { return contractsById[id] }) } /** @@ -59,10 +59,10 @@ function extractStateDefinitions (contractName, sourcesList, contracts) { baseContracts.reverse() for (let k in baseContracts) { const ctr = baseContracts[k] - for (let i in ctr.children) { - const item = ctr.children[i] + for (let i in ctr.nodes) { + const item = ctr.nodes[i] stateItems.push(item) - if (item.name === 'VariableDeclaration') { + if (item.nodeType === 'VariableDeclaration') { stateVar.push(item) } } @@ -83,7 +83,7 @@ function extractStatesDefinitions (sourcesList, contracts) { } const ret = {} for (let contract in contracts.contractsById) { - const name = contracts.contractsById[contract].attributes.name + const name = contracts.contractsById[contract].name const source = contracts.sourcesByContract[contract] const fullName = source + ':' + name const state = extractStateDefinitions(fullName, sourcesList, contracts) diff --git a/libs/remix-debug/src/solidity-decoder/decodeInfo.js b/libs/remix-debug/src/solidity-decoder/decodeInfo.js index 52bdac9c47..e377926a60 100644 --- a/libs/remix-debug/src/solidity-decoder/decodeInfo.js +++ b/libs/remix-debug/src/solidity-decoder/decodeInfo.js @@ -216,7 +216,7 @@ function getEnum (type, stateDefinitions, contractName) { const state = stateDefinitions[contractName] if (state) { for (let dec of state.stateDefinitions) { - if (dec.attributes && dec.attributes.name && type === contractName + '.' + dec.attributes.name) { + if (dec && dec.name && type === contractName + '.' + dec.name) { return dec } } @@ -243,7 +243,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) { const state = stateDefinitions[contractName] if (state) { for (let dec of state.stateDefinitions) { - if (dec.name === 'StructDefinition' && type === contractName + '.' + dec.attributes.name) { + if (dec.nodeType === 'StructDefinition' && type === contractName + '.' + dec.name) { const offsets = computeOffsets(dec.children, stateDefinitions, contractName, location) if (!offsets) { return null @@ -332,25 +332,25 @@ function computeOffsets (types, stateDefinitions, contractName, location) { } for (var i in types) { var variable = types[i] - var type = parseType(variable.attributes.type, stateDefinitions, contractName, location) + var type = parseType(variable.typeDescriptions.typeString, stateDefinitions, contractName, location) if (!type) { - console.log('unable to retrieve decode info of ' + variable.attributes.type) + console.log('unable to retrieve decode info of ' + variable.typeDescriptions.typeString) return null } - if (!variable.attributes.constant && storagelocation.offset + type.storageBytes > 32) { + if (!variable.constant && storagelocation.offset + type.storageBytes > 32) { storagelocation.slot++ storagelocation.offset = 0 } ret.push({ - name: variable.attributes.name, + name: variable.name, type: type, - constant: variable.attributes.constant, + constant: variable.constant, storagelocation: { - offset: variable.attributes.constant ? 0 : storagelocation.offset, - slot: variable.attributes.constant ? 0 : storagelocation.slot + offset: variable.constant ? 0 : storagelocation.offset, + slot: variable.constant ? 0 : storagelocation.slot } }) - if (!variable.attributes.constant) { + if (!variable.constant) { if (type.storageSlots === 1 && storagelocation.offset + type.storageBytes <= 32) { storagelocation.offset += type.storageBytes } else { diff --git a/libs/remix-debug/src/solidity-decoder/internalCallTree.js b/libs/remix-debug/src/solidity-decoder/internalCallTree.js index 4c018d89d2..c760eb818e 100644 --- a/libs/remix-debug/src/solidity-decoder/internalCallTree.js +++ b/libs/remix-debug/src/solidity-decoder/internalCallTree.js @@ -216,20 +216,20 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc // using the vm trace step, the current source location and the ast, // we check if the current vm trace step target a new ast node of type VariableDeclaration // that way we know that there is a new local variable from here. - if (variableDeclaration && !tree.scopes[scopeId].locals[variableDeclaration.attributes.name]) { + if (variableDeclaration && !tree.scopes[scopeId].locals[variableDeclaration.name]) { try { const stack = tree.traceManager.getStackAt(step) // the stack length at this point is where the value of the new local variable will be stored. // so, either this is the direct value, or the offset in memory. That depends on the type. tree.solidityProxy.contractNameAt(step).then((contractName) => { - if (variableDeclaration.attributes.name !== '') { + if (variableDeclaration.name !== '') { var states = tree.solidityProxy.extractStatesDefinitions() var location = typesUtil.extractLocationFromAstVariable(variableDeclaration) location = location === 'default' ? 'storage' : location // we push the new local variable in our tree - tree.scopes[scopeId].locals[variableDeclaration.attributes.name] = { - name: variableDeclaration.attributes.name, - type: decodeInfo.parseType(variableDeclaration.attributes.type, states, contractName, location), + tree.scopes[scopeId].locals[variableDeclaration.name] = { + name: variableDeclaration.name, + type: decodeInfo.parseType(variableDeclaration.typeDescriptions.typeString, states, contractName, location), stackDepth: stack.length, sourceLocation: sourceLocation } @@ -242,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc // we check here if we are at the beginning inside a new function. // if that is the case, we have to add to locals tree the inputs and output params const functionDefinition = resolveFunctionDefinition(tree, step, previousSourceLocation) - if (functionDefinition && (newLocation && traceHelper.isJumpDestInstruction(tree.traceManager.trace[step - 1]) || functionDefinition.attributes.isConstructor)) { + if (functionDefinition && (newLocation && traceHelper.isJumpDestInstruction(tree.traceManager.trace[step - 1]) || functionDefinition.kind === 'constructor')) { tree.functionCallStack.push(step) const functionDefinitionAndInputs = {functionDefinition, inputs: []} // means: the previous location was a function definition && JUMPDEST @@ -252,11 +252,11 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc try { const stack = tree.traceManager.getStackAt(step) var states = tree.solidityProxy.extractStatesDefinitions() - if (functionDefinition.children && functionDefinition.children.length) { + if (functionDefinition.parameters && functionDefinition.parameters.length) { let inputs let outputs - for (const element of functionDefinition.children) { - if (element.name === 'ParameterList') { + for (const element of functionDefinition.parameters) { + if (element.nodeType === 'ParameterList') { if (!inputs) inputs = element else { outputs = element @@ -266,7 +266,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc } // input params if (inputs) { - functionDefinitionAndInputs.inputs = addParams(inputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, inputs.children.length, -1) + functionDefinitionAndInputs.inputs = addParams(inputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, inputs.parameters.length, -1) } // output params if (outputs) addParams(outputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, 0, 1) @@ -313,7 +313,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) { function extractVariableDeclarations (ast, astWalker) { const ret = {} astWalker.walk(ast, (node) => { - if (node.name === 'VariableDeclaration') { + if (node.nodeType === 'VariableDeclaration') { ret[node.src] = node } return true @@ -324,7 +324,7 @@ function extractVariableDeclarations (ast, astWalker) { function extractFunctionDefinitions (ast, astWalker) { const ret = {} astWalker.walk(ast, (node) => { - if (node.name === 'FunctionDefinition') { + if (node.nodeType === 'FunctionDefinition') { ret[node.src] = node } return true @@ -334,16 +334,16 @@ function extractFunctionDefinitions (ast, astWalker) { function addParams (parameterList, tree, scopeId, states, contractName, sourceLocation, stackLength, stackPosition, dir) { let params = [] - for (let inputParam in parameterList.children) { - const param = parameterList.children[inputParam] + for (let inputParam in parameterList.parameters) { + const param = parameterList.parameters[inputParam] const stackDepth = stackLength + (dir * stackPosition) if (stackDepth >= 0) { let location = typesUtil.extractLocationFromAstVariable(param) location = location === 'default' ? 'memory' : location - const attributesName = param.attributes.name === '' ? `$${inputParam}` : param.attributes.name + const attributesName = param.name === '' ? `$${inputParam}` : param.name tree.scopes[scopeId].locals[attributesName] = { name: attributesName, - type: decodeInfo.parseType(param.attributes.type, states, contractName, location), + type: decodeInfo.parseType(param.typeDescriptions.typeString, states, contractName, location), stackDepth: stackDepth, sourceLocation: sourceLocation } diff --git a/libs/remix-debug/src/solidity-decoder/solidityProxy.js b/libs/remix-debug/src/solidity-decoder/solidityProxy.js index 8ff81ea4fd..103d6442d9 100644 --- a/libs/remix-debug/src/solidity-decoder/solidityProxy.js +++ b/libs/remix-debug/src/solidity-decoder/solidityProxy.js @@ -99,7 +99,7 @@ class SolidityProxy { ast (sourceLocation) { const file = this.fileNameFromIndex(sourceLocation.file) if (this.sources[file]) { - return this.sources[file].legacyAST + return this.sources[file].ast } return null } diff --git a/libs/remix-debug/src/solidity-decoder/types/util.js b/libs/remix-debug/src/solidity-decoder/types/util.js index 719f082dc5..d7f792185b 100644 --- a/libs/remix-debug/src/solidity-decoder/types/util.js +++ b/libs/remix-debug/src/solidity-decoder/types/util.js @@ -105,9 +105,9 @@ function extractLocation (type) { } function extractLocationFromAstVariable (node) { - if (node.attributes.storageLocation !== 'default') { - return node.attributes.storageLocation - } else if (node.attributes.stateVariable) { + if (node.storageLocation !== 'default') { + return node.storageLocation + } else if (node.stateVariable) { return 'storage' } return 'default' // local variables => storage, function parameters & return values => memory, state => storage diff --git a/libs/remix-debug/src/source/astWalker.js b/libs/remix-debug/src/source/astWalker.js index 53323dfa60..28f247268d 100644 --- a/libs/remix-debug/src/source/astWalker.js +++ b/libs/remix-debug/src/source/astWalker.js @@ -21,9 +21,9 @@ AstWalker.prototype.walk = function (ast, callback) { if (!('*' in callback)) { callback['*'] = function () { return true } } - if (manageCallBack(ast, callback) && ast.children && ast.children.length > 0) { - for (let k in ast.children) { - const child = ast.children[k] + if (manageCallBack(ast, callback) && ast.nodes && ast.nodes.length > 0) { + for (let k in ast.nodes) { + const child = ast.nodes[k] this.walk(child, callback) } } @@ -38,13 +38,13 @@ AstWalker.prototype.walk = function (ast, callback) { AstWalker.prototype.walkAstList = function (sourcesList, callback) { const walker = new AstWalker() for (let k in sourcesList) { - walker.walk(sourcesList[k].legacyAST, callback) + walker.walk(sourcesList[k].ast, callback) } } function manageCallBack (node, callback) { - if (node.name in callback) { - return callback[node.name](node) + if (node.nodeType in callback) { + return callback[node.nodeType](node) } else { return callback['*'](node) }