mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add function that retrieves first FunctionDefinition up the scope path
This commit is contained in:
parent
8f2c8daf22
commit
dcd6cb94bf
@ -400,6 +400,21 @@ SourceUnit const& Scopable::sourceUnit() const
|
||||
return dynamic_cast<SourceUnit const&>(*s);
|
||||
}
|
||||
|
||||
CallableDeclaration const* Scopable::functionOrModifierDefinition() const
|
||||
{
|
||||
ASTNode const* s = scope();
|
||||
solAssert(s, "");
|
||||
while (dynamic_cast<Scopable const*>(s))
|
||||
{
|
||||
if (auto funDef = dynamic_cast<FunctionDefinition const*>(s))
|
||||
return funDef;
|
||||
if (auto modDef = dynamic_cast<ModifierDefinition const*>(s))
|
||||
return modDef;
|
||||
s = dynamic_cast<Scopable const*>(s)->scope();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
string Scopable::sourceUnitName() const
|
||||
{
|
||||
return sourceUnit().annotation().path;
|
||||
|
@ -161,6 +161,9 @@ public:
|
||||
/// @returns the source unit this scopable is present in.
|
||||
SourceUnit const& sourceUnit() const;
|
||||
|
||||
/// @returns the function or modifier definition this scopable is present in or nullptr.
|
||||
CallableDeclaration const* functionOrModifierDefinition() const;
|
||||
|
||||
/// @returns the source name this scopable is present in.
|
||||
/// Can be combined with annotation().canonicalName (if present) to form a globally unique name.
|
||||
std::string sourceUnitName() const;
|
||||
|
@ -38,6 +38,7 @@ class SourceUnit;
|
||||
class PragmaDirective;
|
||||
class ImportDirective;
|
||||
class Declaration;
|
||||
class CallableDeclaration;
|
||||
class ContractDefinition;
|
||||
class InheritanceSpecifier;
|
||||
class UsingForDirective;
|
||||
|
Loading…
Reference in New Issue
Block a user