Commit e3934b91 authored by yann300's avatar yann300

- renaming

- add comments
parent 0e392522
...@@ -7,15 +7,15 @@ var AstWalker = require('../util/astWalker') ...@@ -7,15 +7,15 @@ var AstWalker = require('../util/astWalker')
* @param {Object} sourcesList - sources list (containing root AST node) * @param {Object} sourcesList - sources list (containing root AST node)
* @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts * @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts
*/ */
function extractContractsDefinition (sourcesList) { function extractContractDefinitions (sourcesList) {
var ret = { var ret = {
contractsIds: {}, contractsById: {},
contractsNames: {} contractsByName: {}
} }
var walker = new AstWalker() var walker = new AstWalker()
walker.walkAstList(sourcesList, { 'ContractDefinition': function (node) { walker.walkAstList(sourcesList, { 'ContractDefinition': function (node) {
ret.contractsIds[node.id] = node ret.contractsById[node.id] = node
ret.contractsNames[node.attributes.name] = node.id ret.contractsByName[node.attributes.name] = node
return false return false
}}) }})
return ret return ret
...@@ -28,8 +28,8 @@ function extractContractsDefinition (sourcesList) { ...@@ -28,8 +28,8 @@ function extractContractsDefinition (sourcesList) {
* @param {Map} contracts - all contracts defined in the current context * @param {Map} contracts - all contracts defined in the current context
* @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, contracts) { function getLinearizedBaseContracts (id, contractsById) {
return contracts[id].attributes.linearizedBaseContracts.map(function (id) { return contracts[id] }) return contractsById[id].attributes.linearizedBaseContracts.map(function (id) { return contractsById[id] })
} }
/** /**
...@@ -40,11 +40,11 @@ function getLinearizedBaseContracts (id, contracts) { ...@@ -40,11 +40,11 @@ function getLinearizedBaseContracts (id, contracts) {
* @return {Array} - return an array of AST node of all state variables (including inherited) (this will include all enum/struct declarations) * @return {Array} - return an array of AST node of all state variables (including inherited) (this will include all enum/struct declarations)
*/ */
function extractStateVariables (contractName, sourcesList) { function extractStateVariables (contractName, sourcesList) {
var contracts = extractContractsDefinition(sourcesList) var contracts = extractContractDefinitions(sourcesList)
var id = contracts.contractsNames[contractName] var node = contracts.contractsByName[contractName]
if (id) { if (node) {
var stateVar = [] var stateVar = []
var baseContracts = getLinearizedBaseContracts(id, contracts.contractsIds) var baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById)
baseContracts.reverse() baseContracts.reverse()
for (var k in baseContracts) { for (var k in baseContracts) {
var ctr = baseContracts[k] var ctr = baseContracts[k]
...@@ -59,6 +59,6 @@ function extractStateVariables (contractName, sourcesList) { ...@@ -59,6 +59,6 @@ function extractStateVariables (contractName, sourcesList) {
module.exports = { module.exports = {
extractStateVariables: extractStateVariables, extractStateVariables: extractStateVariables,
extractContractsDefinition: extractContractsDefinition, extractContractDefinitions: extractContractDefinitions,
getLinearizedBaseContracts: getLinearizedBaseContracts getLinearizedBaseContracts: getLinearizedBaseContracts
} }
'use strict' 'use strict'
/** /**
* Uint decode the given @arg type * Uint decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g uint256, uint32)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/ */
function Uint (type) { function Uint (type) {
if (type.split(' ')) {
type = type.split(' ')[0]
}
return { return {
needsFreeStorageSlot: false, needsFreeStorageSlot: false,
storageBytes: parseInt(type.replace('uint', '')) / 8, storageBytes: parseInt(type.replace('uint', '')) / 8,
...@@ -18,9 +14,23 @@ function Uint (type) { ...@@ -18,9 +14,23 @@ function Uint (type) {
} }
/** /**
* Int decode the given @arg type
*
* @param {String} type - type given by the AST (e.g int256, int32)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function Int (type) {
return {
needsFreeStorageSlot: false,
storageBytes: parseInt(type.replace('int', '')) / 8,
typeName: type
}
}
/**
* Address decode the given @arg type * Address decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g address)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/ */
function Address (type) { function Address (type) {
...@@ -34,7 +44,7 @@ function Address (type) { ...@@ -34,7 +44,7 @@ function Address (type) {
/** /**
* Bool decode the given @arg type * Bool decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g bool)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/ */
function Bool (type) { function Bool (type) {
...@@ -48,7 +58,7 @@ function Bool (type) { ...@@ -48,7 +58,7 @@ function Bool (type) {
/** /**
* DynamicByteArray decode the given @arg type * DynamicByteArray decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g bytes storage ref)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/ */
function DynamicByteArray (type) { function DynamicByteArray (type) {
...@@ -62,7 +72,7 @@ function DynamicByteArray (type) { ...@@ -62,7 +72,7 @@ function DynamicByteArray (type) {
/** /**
* FixedByteArray decode the given @arg type * FixedByteArray decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g bytes16)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/ */
function FixedByteArray (type) { function FixedByteArray (type) {
...@@ -77,26 +87,9 @@ function FixedByteArray (type) { ...@@ -77,26 +87,9 @@ function FixedByteArray (type) {
} }
/** /**
* Int decode the given @arg type
*
* @param {String} type - type given by the AST
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function Int (type) {
if (type.split(' ')) {
type = type.split(' ')[0]
}
return {
needsFreeStorageSlot: false,
storageBytes: parseInt(type.replace('int', '')) / 8,
typeName: type
}
}
/**
* StringType decode the given @arg type * StringType decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g string storage ref)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/ */
function StringType (type) { function StringType (type) {
...@@ -110,7 +103,7 @@ function StringType (type) { ...@@ -110,7 +103,7 @@ function StringType (type) {
/** /**
* ArrayType decode the given @arg type * ArrayType decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g int256[] storage ref, int256[] storage ref[] storage ref)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder, arraySize, subArray} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder, arraySize, subArray}
*/ */
function ArrayType (type, stateDefinitions) { function ArrayType (type, stateDefinitions) {
...@@ -153,7 +146,7 @@ function ArrayType (type, stateDefinitions) { ...@@ -153,7 +146,7 @@ function ArrayType (type, stateDefinitions) {
/** /**
* Enum decode the given @arg type * Enum decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g enum enumDef)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/ */
function Enum (type, stateDefinitions) { function Enum (type, stateDefinitions) {
...@@ -169,7 +162,7 @@ function Enum (type, stateDefinitions) { ...@@ -169,7 +162,7 @@ function Enum (type, stateDefinitions) {
/** /**
* Struct decode the given @arg type * Struct decode the given @arg type
* *
* @param {String} type - type given by the AST * @param {String} type - type given by the AST (e.g struct structDef storage ref)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder, members} * @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder, members}
*/ */
function Struct (type, stateDefinitions) { function Struct (type, stateDefinitions) {
......
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