MCPcopy Create free account
hub / github.com/argotorg/solidity / writeToLValue

Method writeToLValue

libsolidity/codegen/ir/IRGeneratorForStatements.cpp:3164–3268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3162}
3163
3164void IRGeneratorForStatements::writeToLValue(IRLValue const& _lvalue, IRVariable const& _value)
3165{
3166 std::visit(
3167 util::GenericVisitor{
3168 [&](IRLValue::Storage const& _storage) {
3169 std::string offsetArgument;
3170 std::optional<unsigned> offsetStatic;
3171
3172 std::visit(GenericVisitor{
3173 [&](unsigned _offset) { offsetStatic = _offset; },
3174 [&](std::string const& _offset) { offsetArgument = ", " + _offset; }
3175 }, _storage.offset);
3176
3177 appendCode() <<
3178 m_utils.updateStorageValueFunction(_value.type(), _lvalue.type, VariableDeclaration::Location::Unspecified, offsetStatic) <<
3179 "(" <<
3180 _storage.slot <<
3181 offsetArgument <<
3182 _value.commaSeparatedListPrefixed() <<
3183 ")\n";
3184 },
3185 [&](IRLValue::TransientStorage const& _transientStorage) {
3186 std::string offsetArgument;
3187 std::optional<unsigned> offsetStatic;
3188
3189 std::visit(GenericVisitor{
3190 [&](unsigned _offset) { offsetStatic = _offset; },
3191 [&](std::string const& _offset) { offsetArgument = ", " + _offset; }
3192 }, _transientStorage.offset);
3193
3194 appendCode() <<
3195 m_utils.updateStorageValueFunction(_value.type(), _lvalue.type, VariableDeclaration::Location::Transient, offsetStatic) <<
3196 "(" <<
3197 _transientStorage.slot <<
3198 offsetArgument <<
3199 _value.commaSeparatedListPrefixed() <<
3200 ")\n";
3201 },
3202 [&](IRLValue::Memory const& _memory) {
3203 if (_lvalue.type.isValueType())
3204 {
3205 IRVariable prepared(m_context.newYulVariable(), _lvalue.type);
3206 define(prepared, _value);
3207
3208 if (_memory.byteArrayElement)
3209 {
3210 solAssert(_lvalue.type == *TypeProvider::byte());
3211 appendCode() << "mstore8(" + _memory.address + ", byte(0, " + prepared.commaSeparatedList() + "))\n";
3212 }
3213 else
3214 appendCode() << m_utils.writeToMemoryFunction(_lvalue.type) <<
3215 "(" <<
3216 _memory.address <<
3217 ", " <<
3218 prepared.commaSeparatedList() <<
3219 ")\n";
3220 }
3221 else if (auto const* literalType = dynamic_cast<StringLiteralType const*>(&_value.type()))

Callers

nothing calls this directly

Calls 15

newYulVariableMethod · 0.80
commaSeparatedListMethod · 0.80
writeToMemoryFunctionMethod · 0.80
partMethod · 0.80
conversionFunctionMethod · 0.80
to_stringFunction · 0.50
typeMethod · 0.45
isValueTypeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected