Commit 54060ecd authored by yann300's avatar yann300

fix struct type

parent 5a833953
......@@ -165,26 +165,41 @@ function getEnum (type, stateDefinitions) {
*/
function getStructMembers (typeName, stateDefinitions) {
var members = []
var storageBytes = 0
for (var k in stateDefinitions) {
var dec = stateDefinitions[k]
if (dec.name === 'StructDefinition' && typeName === dec.attributes.name) {
var location = {
offset: 0,
slot: 0
}
for (var i in dec.children) {
var member = dec.children[i]
var decoded = parseType(member.attributes.type, stateDefinitions)
if (!decoded) {
var type = parseType(member.attributes.type, stateDefinitions)
if (location.offset + type.storageBytes > 32) {
location.slot++
location.offset = 0
}
if (!type) {
console.log('unable to retrieve decode info of ' + member.attributes.type)
return null
}
members.push(decoded)
storageBytes += decoded.storageBytes
members.push(type)
if (type.storageSlots === 1 && location.offset + type.storageBytes <= 32) {
location.offset += type.storageBytes
} else {
location.slot += type.storageSlots
location.offset = 0
}
}
if (location.offset > 0) {
location.slot++
}
break
}
}
return {
members: members,
storageBytes: storageBytes
storageBytes: location.slot
}
}
......
'use strict'
function Struct (memberDetails) {
this.storageSlots = Math.ceil(memberDetails.storageBytes / 32)
this.storageSlots = memberDetails.storageBytes
this.storageBytes = 32
this.members = memberDetails.members
this.typeName = 'struct'
......
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