From 95f68f04afd3895c89455e301e5464c1c9f09b89 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Mon, 18 May 2020 14:01:04 +0530 Subject: [PATCH] variable getter util --- .../src/solidity-analyzer/modules/gasCosts.ts | 4 ++-- .../solidity-analyzer/modules/staticAnalysisCommon.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts b/remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts index 6bedd59a69..81243df847 100644 --- a/remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts +++ b/remix-analyzer/src/solidity-analyzer/modules/gasCosts.ts @@ -1,6 +1,6 @@ import { default as category } from './categories' import { default as algorithm } from './algorithmCategories' -import { getFunctionDefinitionName, helpers } from './staticAnalysisCommon' +import { getFunctionDefinitionName, helpers, isVariableTurnedIntoGetter } from './staticAnalysisCommon' import { ModuleAlgorithm, ModuleCategory, ReportObj, CompilationResult, CompiledContract, AnalyzerModule, FunctionDefinitionAstNode, VariableDeclarationAstNode } from './../../types' @@ -13,7 +13,7 @@ export default class gasCosts implements AnalyzerModule { warningNodes: any[] = [] visit (node: FunctionDefinitionAstNode | VariableDeclarationAstNode): void { if ((node.nodeType === 'FunctionDefinition' && node.kind !== 'constructor' && node.implemented) || - (node.nodeType === 'VariableDeclaration' && node.stateVariable && node.visibility === 'public')) + (node.nodeType === 'VariableDeclaration' && isVariableTurnedIntoGetter(node))) this.warningNodes.push(node) } diff --git a/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts b/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts index e64ffd26b4..21a5a824c8 100644 --- a/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts +++ b/remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.ts @@ -641,6 +641,15 @@ function isConstantFunction (node: FunctionDefinitionAstNode): boolean { return node.stateMutability === 'view' || node.stateMutability === 'pure' } +/** +* True if variable decalaration is converted into a getter method + * @node {ASTNode} variable declaration AstNode + * @return {bool} + */ +function isVariableTurnedIntoGetter (varDeclNode: VariableDeclarationAstNode): boolean { + return varDeclNode.stateVariable && varDeclNode.visibility === 'public'; +} + /** * True if is function defintion has payable modifier * @node {ASTNode} some AstNode @@ -1109,6 +1118,7 @@ export { isDeleteFromDynamicArray, isAbiNamespaceCall, isSpecialVariableAccess, + isVariableTurnedIntoGetter, isDynamicArrayAccess, isDynamicArrayLengthAccess, isMappingIndexAccess,