|
36 | 36 |
|
37 | 37 | #include <json/json.h> |
38 | 38 |
|
| 39 | +#include <range/v3/view/subrange.hpp> |
| 40 | +#include <range/v3/view/map.hpp> |
| 41 | + |
39 | 42 | #include <memory> |
40 | 43 | #include <optional> |
41 | 44 | #include <string> |
@@ -497,6 +500,13 @@ class ContractDefinition: public Declaration, public StructurallyDocumented, pub |
497 | 500 | std::vector<VariableDeclaration const*> stateVariables() const { return filteredNodes<VariableDeclaration>(m_subNodes); } |
498 | 501 | std::vector<ModifierDefinition const*> functionModifiers() const { return filteredNodes<ModifierDefinition>(m_subNodes); } |
499 | 502 | std::vector<FunctionDefinition const*> definedFunctions() const { return filteredNodes<FunctionDefinition>(m_subNodes); } |
| 503 | + /// @returns a view<FunctionDefinition const*> of all functions |
| 504 | + /// defined in this contract of the given name (excluding inherited functions). |
| 505 | + auto definedFunctions(std::string const& _name) const |
| 506 | + { |
| 507 | + auto&& [b, e] = definedFunctionsByName().equal_range(_name); |
| 508 | + return ranges::subrange<decltype(b)>(b, e) | ranges::views::values; |
| 509 | + } |
500 | 510 | std::vector<EventDefinition const*> events() const { return filteredNodes<EventDefinition>(m_subNodes); } |
501 | 511 | std::vector<EventDefinition const*> const& interfaceEvents() const; |
502 | 512 | /// @returns all errors defined in this contract or any base contract |
@@ -546,13 +556,16 @@ class ContractDefinition: public Declaration, public StructurallyDocumented, pub |
546 | 556 | FunctionDefinition const* nextConstructor(ContractDefinition const& _mostDerivedContract) const; |
547 | 557 |
|
548 | 558 | private: |
| 559 | + std::multimap<std::string, FunctionDefinition const*> const& definedFunctionsByName() const; |
| 560 | + |
549 | 561 | std::vector<ASTPointer<InheritanceSpecifier>> m_baseContracts; |
550 | 562 | std::vector<ASTPointer<ASTNode>> m_subNodes; |
551 | 563 | ContractKind m_contractKind; |
552 | 564 | bool m_abstract{false}; |
553 | 565 |
|
554 | 566 | util::LazyInit<std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList[2]; |
555 | 567 | util::LazyInit<std::vector<EventDefinition const*>> m_interfaceEvents; |
| 568 | + util::LazyInit<std::multimap<std::string, FunctionDefinition const*>> m_definedFunctionsByName; |
556 | 569 | }; |
557 | 570 |
|
558 | 571 | /** |
|
0 commit comments