mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
References counter.
This commit is contained in:
parent
5437457f46
commit
3c8b777b9b
@ -71,8 +71,8 @@ protected:
|
|||||||
template <class T>
|
template <class T>
|
||||||
void walkVector(T const& _statements)
|
void walkVector(T const& _statements)
|
||||||
{
|
{
|
||||||
for (auto const& st: _statements)
|
for (auto const& statement: _statements)
|
||||||
visit(st);
|
visit(statement);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,3 +42,28 @@ void NameCollector::operator ()(FunctionDefinition const& _funDef)
|
|||||||
m_names.insert(ret.name);
|
m_names.insert(ret.name);
|
||||||
ASTWalker::operator ()(_funDef);
|
ASTWalker::operator ()(_funDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReferencesCounter::operator()(Identifier const& _identifier)
|
||||||
|
{
|
||||||
|
++m_references[_identifier.name];
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReferencesCounter::operator()(FunctionCall const& _funCall)
|
||||||
|
{
|
||||||
|
++m_references[_funCall.functionName.name];
|
||||||
|
ASTWalker::operator()(_funCall);
|
||||||
|
}
|
||||||
|
|
||||||
|
map<string, size_t> ReferencesCounter::countReferences(Block const& _block)
|
||||||
|
{
|
||||||
|
ReferencesCounter counter;
|
||||||
|
counter(_block);
|
||||||
|
return counter.references();
|
||||||
|
}
|
||||||
|
|
||||||
|
map<string, size_t> ReferencesCounter::countReferences(Expression const& _expression)
|
||||||
|
{
|
||||||
|
ReferencesCounter counter;
|
||||||
|
counter.visit(_expression);
|
||||||
|
return counter.references();
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Specific AST walker that collects all defined names.
|
* Specific AST walkers that collect facts about identifiers and definitions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -48,5 +48,23 @@ private:
|
|||||||
std::map<std::string, FunctionDefinition const*> m_functions;
|
std::map<std::string, FunctionDefinition const*> m_functions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specific AST walker that counts all references to all declarations.
|
||||||
|
*/
|
||||||
|
class ReferencesCounter: public ASTWalker
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using ASTWalker::operator ();
|
||||||
|
virtual void operator()(Identifier const& _identifier);
|
||||||
|
virtual void operator()(FunctionCall const& _funCall);
|
||||||
|
|
||||||
|
static std::map<std::string, size_t> countReferences(Block const& _block);
|
||||||
|
static std::map<std::string, size_t> countReferences(Expression const& _expression);
|
||||||
|
|
||||||
|
std::map<std::string, size_t> const& references() const { return m_references; }
|
||||||
|
private:
|
||||||
|
std::map<std::string, size_t> m_references;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user