size_t UnionDeclaration::getSize() const { size_t sz = 0; VariableDeclaration *vd; for(int i = 0; i < members.size(); i++){ vd = members[i]->variableDeclaration(); if(vd->getType()->getSize() > sz) sz = vd->getType()->getSize(); } return sz; }
size_t UserTypeDeclaration::getAlign() const { size_t align = 0; VariableDeclaration *vd; for(int i = 0; i < members.size(); i++){ vd = members[i]->variableDeclaration(); assert(vd && "expected variable decl, found something else"); if(vd->getType()->getAlign() > align) align = vd->getType()->getAlign(); } if(align == 0) return 1; // TODO: empty struct, bad! return align; //TODO: handle packed }
size_t ClassDeclaration::getSize() const { size_t sz = base ? base->getDeclaredType()->getSize() : 0; VariableDeclaration *vd; unsigned align = base ? 8 : 1; //TODO: proper padding past base? if(sz % align) sz += (align - (sz % align)); for(int i = 0; i < members.size(); i++) { vd = members[i]->variableDeclaration(); if(!vd) continue; align = vd->getType()->getAlign(); if(sz % align) sz += (align - (sz % align)); //reference types treated as pointers if(vd->getType()->isReference()) sz += 8; else sz += vd->type->getSize(); } return sz; }
void CompilerContext::addAndInitializeVariable(VariableDeclaration const& _declaration) { addVariable(_declaration); unsigned const size = _declaration.getType()->getSizeOnStack(); for (unsigned i = 0; i < size; ++i) *this << u256(0); m_asm.adjustDeposit(-size); }
size_t StructDeclaration::getSize() const { size_t sz = 0; VariableDeclaration *vd; unsigned align; for(int i = 0; i < members.size(); i++) { vd = members[i]->variableDeclaration(); if(!vd) continue; align = vd->getType()->getAlign(); if(!packed && sz % align) sz += (align - (sz % align)); sz += vd->type->getSize(); } return sz; }
void CompilerContext::addVariable(VariableDeclaration const& _declaration) { m_localVariables[&_declaration] = m_localVariablesSize; m_localVariablesSize += _declaration.getType()->getSizeOnStack(); }
void CompilerContext::addStateVariable(VariableDeclaration const& _declaration) { m_stateVariables[&_declaration] = m_stateVariablesSize; m_stateVariablesSize += _declaration.getType()->getStorageSize(); }
void Compiler::appendStackVariableInitialisation(VariableDeclaration const& _variable) { CompilerContext::LocationSetter location(m_context, _variable); m_context.addVariable(_variable); CompilerUtils(m_context).pushZeroValue(*_variable.getType()); }