|
39 | 39 | #include <boost/algorithm/string.hpp>
|
40 | 40 | #include <boost/algorithm/string/split.hpp>
|
41 | 41 |
|
| 42 | +#include <range/v3/algorithm/find_if.hpp> |
| 43 | + |
42 | 44 | using namespace solidity;
|
43 | 45 | using namespace solidity::langutil;
|
44 | 46 | using namespace solidity::frontend;
|
@@ -504,3 +506,35 @@ void ReferencesResolver::validateYulIdentifierName(yul::YulName _name, SourceLoc
|
504 | 506 | "The identifier name \"" + _name.str() + "\" is reserved."
|
505 | 507 | );
|
506 | 508 | }
|
| 509 | + |
| 510 | +void ReferencesResolver::endVisit(MemberAccess const& _memberAccess) |
| 511 | +{ |
| 512 | + // This is only for specific cases to support ConstantEvaluator. |
| 513 | + std::vector<Declaration const*> candidates; |
| 514 | + if (auto const* identifier = dynamic_cast<Identifier const*>(&_memberAccess.expression())) |
| 515 | + { |
| 516 | + if (auto const* contract = dynamic_cast<ContractDefinition const*>(identifier->annotation().referencedDeclaration)) |
| 517 | + candidates += contract->stateVariables(); |
| 518 | + else if (auto const* importedModule = dynamic_cast<ImportDirective const*>(identifier->annotation().referencedDeclaration)) |
| 519 | + { |
| 520 | + SourceUnit const* sourceUnit = importedModule->annotation().sourceUnit; |
| 521 | + solAssert(sourceUnit); |
| 522 | + candidates += ASTNode::filteredNodes<VariableDeclaration>(sourceUnit->nodes()); |
| 523 | + candidates += ASTNode::filteredNodes<ContractDefinition>(sourceUnit->nodes()); |
| 524 | + } |
| 525 | + } |
| 526 | + else if (auto const* nestedMemberAccess = dynamic_cast<MemberAccess const*>(&_memberAccess.expression())) |
| 527 | + { |
| 528 | + auto const* contract = dynamic_cast<ContractDefinition const*>(nestedMemberAccess->annotation().referencedDeclaration); |
| 529 | + if (!contract) |
| 530 | + return; |
| 531 | + candidates += contract->stateVariables(); |
| 532 | + } |
| 533 | + |
| 534 | + auto declaration = ranges::find_if( |
| 535 | + candidates, |
| 536 | + [&](Declaration const* _declaration) { return _declaration->name() == _memberAccess.memberName(); } |
| 537 | + ); |
| 538 | + if (declaration != ranges::end(candidates)) |
| 539 | + _memberAccess.annotation().referencedDeclaration = *declaration; |
| 540 | +} |
0 commit comments