From b9fec81c59af65d6ca8e9934d1126b9915792139 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 21 Sep 2017 12:57:27 +0200 Subject: [PATCH] fix analysis (fn call at contract scope) --- .../staticanalysis/modules/abstractAstView.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/staticanalysis/modules/abstractAstView.js b/src/app/staticanalysis/modules/abstractAstView.js index 0a5fc80831..be4853b6d7 100644 --- a/src/app/staticanalysis/modules/abstractAstView.js +++ b/src/app/staticanalysis/modules/abstractAstView.js @@ -49,6 +49,7 @@ abstractAstView.prototype.build_visit = function (relevantNodeFilter) { setCurrentContract(that, { node: node, functions: [], + relevantNodes: [], modifiers: [], inheritsFrom: [], stateVariables: common.getStateVariableDeclarationsFormContractNode(node) @@ -65,6 +66,12 @@ abstractAstView.prototype.build_visit = function (relevantNodeFilter) { localVariables: getLocalVariables(node), parameters: getLocalParameters(node) }) + // push back relevant nodes to their the current fn if any + getCurrentContract(that).relevantNodes.map((item) => { + if (item.referencedDeclaration === node.id) { + getCurrentFunction(that).relevantNodes.push(item.node) + } + }) } else if (common.isModifierDefinition(node)) { setCurrentModifier(that, { node: node, @@ -76,7 +83,15 @@ abstractAstView.prototype.build_visit = function (relevantNodeFilter) { if (!that.isFunctionNotModifier) throw new Error('abstractAstView.js: Found modifier invocation outside of function scope.') getCurrentFunction(that).modifierInvocations.push(node) } else if (relevantNodeFilter(node)) { - ((that.isFunctionNotModifier) ? getCurrentFunction(that) : getCurrentModifier(that)).relevantNodes.push(node) + var scope = (that.isFunctionNotModifier) ? getCurrentFunction(that) : getCurrentModifier(that) + if (scope) { + scope.relevantNodes.push(node) + } else { + scope = getCurrentContract(that) // if we are not in a function scope, add the node to the contract scope + if (scope && node.children[0] && node.children[0].attributes && node.children[0].attributes.referencedDeclaration) { + scope.relevantNodes.push({ referencedDeclaration: node.children[0].attributes.referencedDeclaration, node: node }) + } + } } } }