| 551 | } |
| 552 | |
| 553 | std::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 | )") |
nothing calls this directly
no test coverage detected