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

Method generateGetter

libsolidity/codegen/ir/IRGenerator.cpp:553–756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

551}
552
553std::string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
554{
555 std::string functionName = IRNames::function(_varDecl);
556 return m_context.functionCollector().createFunction(functionName, [&]() {
557 Type const* type = _varDecl.annotation().type;
558
559 solAssert(_varDecl.isStateVariable(), "");
560
561 FunctionType accessorType(_varDecl);
562 TypePointers paramTypes = accessorType.parameterTypes();
563 if (_varDecl.immutable())
564 {
565 solAssert(paramTypes.empty(), "");
566 solUnimplementedAssert(type->sizeOnStack() == 1);
567
568 auto t = Whiskers(R"(
569 <astIDComment><sourceLocationComment>
570 function <functionName>() -> rval {
571 <?eof>
572 rval := auxdataloadn(<immutableOffset>)
573 <!eof>
574 rval := loadimmutable("<id>")
575 </eof>
576 }
577 <contractSourceLocationComment>
578 )");
579 t(
580 "astIDComment",
581 m_context.debugInfoSelection().astID ?
582 "/// @ast-id " + std::to_string(_varDecl.id()) + "\n" :
583 ""
584 );
585 t("sourceLocationComment", dispenseLocationComment(_varDecl));
586 t(
587 "contractSourceLocationComment",
588 dispenseLocationComment(m_context.mostDerivedContract())
589 );
590 t("functionName", functionName);
591
592 auto const eof = m_context.eofVersion().has_value();
593 t("eof", eof);
594 if (!eof)
595 t("id", std::to_string(_varDecl.id()));
596 else
597 t("immutableOffset", std::to_string(m_context.immutableMemoryOffsetRelative(_varDecl)));
598
599 return t.render();
600 }
601 else if (_varDecl.isConstant())
602 {
603 solAssert(paramTypes.empty(), "");
604 return Whiskers(R"(
605 <astIDComment><sourceLocationComment>
606 function <functionName>() -> <ret> {
607 <ret> := <constantValueFunction>()
608 }
609 <contractSourceLocationComment>
610 )")

Callers

nothing calls this directly

Calls 15

functionFunction · 0.85
WhiskersClass · 0.85
dispenseLocationCommentFunction · 0.85
IRVariableClass · 0.85
joinHumanReadableFunction · 0.85
parameterTypesMethod · 0.80
immutableMethod · 0.80
renderMethod · 0.80
strMethod · 0.80
stackSlotsMethod · 0.80

Tested by

no test coverage detected