Commit 11dd6c80 authored by aniket-engg's avatar aniket-engg Committed by Aniket

legacyAST removal

parent 84d4f276
...@@ -41,7 +41,7 @@ function VmDebugger (vmDebuggerLogic) { ...@@ -41,7 +41,7 @@ function VmDebugger (vmDebuggerLogic) {
if (stack === null) return if (stack === null) return
let functions = [] let functions = []
for (let func of stack) { 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) this.functionPanel.update(functions)
}) })
......
...@@ -15,10 +15,10 @@ function extractContractDefinitions (sourcesList) { ...@@ -15,10 +15,10 @@ function extractContractDefinitions (sourcesList) {
} }
const walker = new AstWalker() const walker = new AstWalker()
for (let k in sourcesList) { 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.contractsById[node.id] = node
ret.sourcesByContract[node.id] = k ret.sourcesByContract[node.id] = k
ret.contractsByName[k + ':' + node.attributes.name] = node ret.contractsByName[k + ':' + node.name] = node
return false return false
}}) }})
} }
...@@ -33,7 +33,7 @@ function extractContractDefinitions (sourcesList) { ...@@ -33,7 +33,7 @@ function extractContractDefinitions (sourcesList) {
* @return {Array} - array of base contracts in derived to base order as AST nodes. * @return {Array} - array of base contracts in derived to base order as AST nodes.
*/ */
function getLinearizedBaseContracts (id, contractsById) { 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) { ...@@ -59,10 +59,10 @@ function extractStateDefinitions (contractName, sourcesList, contracts) {
baseContracts.reverse() baseContracts.reverse()
for (let k in baseContracts) { for (let k in baseContracts) {
const ctr = baseContracts[k] const ctr = baseContracts[k]
for (let i in ctr.children) { for (let i in ctr.nodes) {
const item = ctr.children[i] const item = ctr.nodes[i]
stateItems.push(item) stateItems.push(item)
if (item.name === 'VariableDeclaration') { if (item.nodeType === 'VariableDeclaration') {
stateVar.push(item) stateVar.push(item)
} }
} }
...@@ -83,7 +83,7 @@ function extractStatesDefinitions (sourcesList, contracts) { ...@@ -83,7 +83,7 @@ function extractStatesDefinitions (sourcesList, contracts) {
} }
const ret = {} const ret = {}
for (let contract in contracts.contractsById) { 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 source = contracts.sourcesByContract[contract]
const fullName = source + ':' + name const fullName = source + ':' + name
const state = extractStateDefinitions(fullName, sourcesList, contracts) const state = extractStateDefinitions(fullName, sourcesList, contracts)
......
...@@ -216,7 +216,7 @@ function getEnum (type, stateDefinitions, contractName) { ...@@ -216,7 +216,7 @@ function getEnum (type, stateDefinitions, contractName) {
const state = stateDefinitions[contractName] const state = stateDefinitions[contractName]
if (state) { if (state) {
for (let dec of state.stateDefinitions) { 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 return dec
} }
} }
...@@ -243,7 +243,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) { ...@@ -243,7 +243,7 @@ function getStructMembers (type, stateDefinitions, contractName, location) {
const state = stateDefinitions[contractName] const state = stateDefinitions[contractName]
if (state) { if (state) {
for (let dec of state.stateDefinitions) { 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) const offsets = computeOffsets(dec.children, stateDefinitions, contractName, location)
if (!offsets) { if (!offsets) {
return null return null
...@@ -332,25 +332,25 @@ function computeOffsets (types, stateDefinitions, contractName, location) { ...@@ -332,25 +332,25 @@ function computeOffsets (types, stateDefinitions, contractName, location) {
} }
for (var i in types) { for (var i in types) {
var variable = types[i] var variable = types[i]
var type = parseType(variable.attributes.type, stateDefinitions, contractName, location) var type = parseType(variable.typeDescriptions.typeString, stateDefinitions, contractName, location)
if (!type) { 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 return null
} }
if (!variable.attributes.constant && storagelocation.offset + type.storageBytes > 32) { if (!variable.constant && storagelocation.offset + type.storageBytes > 32) {
storagelocation.slot++ storagelocation.slot++
storagelocation.offset = 0 storagelocation.offset = 0
} }
ret.push({ ret.push({
name: variable.attributes.name, name: variable.name,
type: type, type: type,
constant: variable.attributes.constant, constant: variable.constant,
storagelocation: { storagelocation: {
offset: variable.attributes.constant ? 0 : storagelocation.offset, offset: variable.constant ? 0 : storagelocation.offset,
slot: variable.attributes.constant ? 0 : storagelocation.slot slot: variable.constant ? 0 : storagelocation.slot
} }
}) })
if (!variable.attributes.constant) { if (!variable.constant) {
if (type.storageSlots === 1 && storagelocation.offset + type.storageBytes <= 32) { if (type.storageSlots === 1 && storagelocation.offset + type.storageBytes <= 32) {
storagelocation.offset += type.storageBytes storagelocation.offset += type.storageBytes
} else { } else {
......
...@@ -216,20 +216,20 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -216,20 +216,20 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
// using the vm trace step, the current source location and the ast, // 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 // 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. // 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 { try {
const stack = tree.traceManager.getStackAt(step) const stack = tree.traceManager.getStackAt(step)
// the stack length at this point is where the value of the new local variable will be stored. // 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. // so, either this is the direct value, or the offset in memory. That depends on the type.
tree.solidityProxy.contractNameAt(step).then((contractName) => { tree.solidityProxy.contractNameAt(step).then((contractName) => {
if (variableDeclaration.attributes.name !== '') { if (variableDeclaration.name !== '') {
var states = tree.solidityProxy.extractStatesDefinitions() var states = tree.solidityProxy.extractStatesDefinitions()
var location = typesUtil.extractLocationFromAstVariable(variableDeclaration) var location = typesUtil.extractLocationFromAstVariable(variableDeclaration)
location = location === 'default' ? 'storage' : location location = location === 'default' ? 'storage' : location
// we push the new local variable in our tree // we push the new local variable in our tree
tree.scopes[scopeId].locals[variableDeclaration.attributes.name] = { tree.scopes[scopeId].locals[variableDeclaration.name] = {
name: variableDeclaration.attributes.name, name: variableDeclaration.name,
type: decodeInfo.parseType(variableDeclaration.attributes.type, states, contractName, location), type: decodeInfo.parseType(variableDeclaration.typeDescriptions.typeString, states, contractName, location),
stackDepth: stack.length, stackDepth: stack.length,
sourceLocation: sourceLocation sourceLocation: sourceLocation
} }
...@@ -242,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -242,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
// we check here if we are at the beginning inside a new function. // 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 // if that is the case, we have to add to locals tree the inputs and output params
const functionDefinition = resolveFunctionDefinition(tree, step, previousSourceLocation) 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) tree.functionCallStack.push(step)
const functionDefinitionAndInputs = {functionDefinition, inputs: []} const functionDefinitionAndInputs = {functionDefinition, inputs: []}
// means: the previous location was a function definition && JUMPDEST // means: the previous location was a function definition && JUMPDEST
...@@ -252,11 +252,11 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -252,11 +252,11 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
try { try {
const stack = tree.traceManager.getStackAt(step) const stack = tree.traceManager.getStackAt(step)
var states = tree.solidityProxy.extractStatesDefinitions() var states = tree.solidityProxy.extractStatesDefinitions()
if (functionDefinition.children && functionDefinition.children.length) { if (functionDefinition.parameters && functionDefinition.parameters.length) {
let inputs let inputs
let outputs let outputs
for (const element of functionDefinition.children) { for (const element of functionDefinition.parameters) {
if (element.name === 'ParameterList') { if (element.nodeType === 'ParameterList') {
if (!inputs) inputs = element if (!inputs) inputs = element
else { else {
outputs = element outputs = element
...@@ -266,7 +266,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc ...@@ -266,7 +266,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc
} }
// input params // input params
if (inputs) { 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 // output params
if (outputs) addParams(outputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, 0, 1) if (outputs) addParams(outputs, tree, scopeId, states, contractName, previousSourceLocation, stack.length, 0, 1)
...@@ -313,7 +313,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) { ...@@ -313,7 +313,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) {
function extractVariableDeclarations (ast, astWalker) { function extractVariableDeclarations (ast, astWalker) {
const ret = {} const ret = {}
astWalker.walk(ast, (node) => { astWalker.walk(ast, (node) => {
if (node.name === 'VariableDeclaration') { if (node.nodeType === 'VariableDeclaration') {
ret[node.src] = node ret[node.src] = node
} }
return true return true
...@@ -324,7 +324,7 @@ function extractVariableDeclarations (ast, astWalker) { ...@@ -324,7 +324,7 @@ function extractVariableDeclarations (ast, astWalker) {
function extractFunctionDefinitions (ast, astWalker) { function extractFunctionDefinitions (ast, astWalker) {
const ret = {} const ret = {}
astWalker.walk(ast, (node) => { astWalker.walk(ast, (node) => {
if (node.name === 'FunctionDefinition') { if (node.nodeType === 'FunctionDefinition') {
ret[node.src] = node ret[node.src] = node
} }
return true return true
...@@ -334,16 +334,16 @@ function extractFunctionDefinitions (ast, astWalker) { ...@@ -334,16 +334,16 @@ function extractFunctionDefinitions (ast, astWalker) {
function addParams (parameterList, tree, scopeId, states, contractName, sourceLocation, stackLength, stackPosition, dir) { function addParams (parameterList, tree, scopeId, states, contractName, sourceLocation, stackLength, stackPosition, dir) {
let params = [] let params = []
for (let inputParam in parameterList.children) { for (let inputParam in parameterList.parameters) {
const param = parameterList.children[inputParam] const param = parameterList.parameters[inputParam]
const stackDepth = stackLength + (dir * stackPosition) const stackDepth = stackLength + (dir * stackPosition)
if (stackDepth >= 0) { if (stackDepth >= 0) {
let location = typesUtil.extractLocationFromAstVariable(param) let location = typesUtil.extractLocationFromAstVariable(param)
location = location === 'default' ? 'memory' : location 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] = { tree.scopes[scopeId].locals[attributesName] = {
name: attributesName, name: attributesName,
type: decodeInfo.parseType(param.attributes.type, states, contractName, location), type: decodeInfo.parseType(param.typeDescriptions.typeString, states, contractName, location),
stackDepth: stackDepth, stackDepth: stackDepth,
sourceLocation: sourceLocation sourceLocation: sourceLocation
} }
......
...@@ -99,7 +99,7 @@ class SolidityProxy { ...@@ -99,7 +99,7 @@ class SolidityProxy {
ast (sourceLocation) { ast (sourceLocation) {
const file = this.fileNameFromIndex(sourceLocation.file) const file = this.fileNameFromIndex(sourceLocation.file)
if (this.sources[file]) { if (this.sources[file]) {
return this.sources[file].legacyAST return this.sources[file].ast
} }
return null return null
} }
......
...@@ -105,9 +105,9 @@ function extractLocation (type) { ...@@ -105,9 +105,9 @@ function extractLocation (type) {
} }
function extractLocationFromAstVariable (node) { function extractLocationFromAstVariable (node) {
if (node.attributes.storageLocation !== 'default') { if (node.storageLocation !== 'default') {
return node.attributes.storageLocation return node.storageLocation
} else if (node.attributes.stateVariable) { } else if (node.stateVariable) {
return 'storage' return 'storage'
} }
return 'default' // local variables => storage, function parameters & return values => memory, state => storage return 'default' // local variables => storage, function parameters & return values => memory, state => storage
......
...@@ -21,9 +21,9 @@ AstWalker.prototype.walk = function (ast, callback) { ...@@ -21,9 +21,9 @@ AstWalker.prototype.walk = function (ast, callback) {
if (!('*' in callback)) { if (!('*' in callback)) {
callback['*'] = function () { return true } callback['*'] = function () { return true }
} }
if (manageCallBack(ast, callback) && ast.children && ast.children.length > 0) { if (manageCallBack(ast, callback) && ast.nodes && ast.nodes.length > 0) {
for (let k in ast.children) { for (let k in ast.nodes) {
const child = ast.children[k] const child = ast.nodes[k]
this.walk(child, callback) this.walk(child, callback)
} }
} }
...@@ -38,13 +38,13 @@ AstWalker.prototype.walk = function (ast, callback) { ...@@ -38,13 +38,13 @@ AstWalker.prototype.walk = function (ast, callback) {
AstWalker.prototype.walkAstList = function (sourcesList, callback) { AstWalker.prototype.walkAstList = function (sourcesList, callback) {
const walker = new AstWalker() const walker = new AstWalker()
for (let k in sourcesList) { for (let k in sourcesList) {
walker.walk(sourcesList[k].legacyAST, callback) walker.walk(sourcesList[k].ast, callback)
} }
} }
function manageCallBack (node, callback) { function manageCallBack (node, callback) {
if (node.name in callback) { if (node.nodeType in callback) {
return callback[node.name](node) return callback[node.nodeType](node)
} else { } else {
return callback['*'](node) return callback['*'](node)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment