'use strict'
var util = require('./util')

function Enum (enumDef) {
  this.enumDef = enumDef
  this.typeName = 'enum'
  this.storageSlots = 1
  var length = enumDef.children.length
  this.storageBytes = 0
  while (length > 1) {
    length = length / 256
    this.storageBytes++
  }
}

Enum.prototype.decodeFromStorage = function (location, storageContent) {
  var value = util.extractHexValue(location, storageContent, this.storageBytes)
  value = parseInt(value, 16)
  if (this.enumDef.children.length > value) {
    return this.enumDef.children[value].attributes.name
  } else {
    return 'INVALID_ENUM<' + value + '>'
  }
}

module.exports = Enum

@@ -468,17 +468,454 @@
 )%0A  
-if (this.
+return output(value, this.enumDef)%0A%7D%0A%0AEnum.prototype.decodeLocals = function (stackHeight, stack, memory) %7B%0A  var defaultValue = 0%0A  if (stack.length - 1 %3C stackHeight) %7B%0A    defaultValue = 0%0A  %7D else %7B%0A    defaultValue = util.extractHexByteSlice(stack%5Bstack.length - 1 - stackHeight%5D, this.storageBytes, 0)%0A    defaultValue = parseInt(defaultValue, 16)%0A  %7D%0A  return output(defaultValue, this.enumDef)%0A%7D%0A%0Afunction output (value, enumDef) %7B%0A  if (
 enum
@@ -956,21 +956,16 @@
  return 
-this.
 enumDef.

decode enum